FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
roqvideoenc.c File Reference

id RoQ encoder by Vitor. More...

#include <string.h>
#include "libavutil/attributes.h"
#include "libavutil/opt.h"
#include "roqvideo.h"
#include "bytestream.h"
#include "elbg.h"
#include "internal.h"
#include "mathops.h"

Go to the source code of this file.

Data Structures

struct  SubcelEvaluation
 
struct  CelEvaluation
 
struct  RoqCodebooks
 
struct  RoqTempdata
 Temporary vars. More...
 
struct  CodingSpool
 

Macros

#define CHROMA_BIAS   1
 
#define MAX_CBS_4x4   256
 Maximum number of generated 4x4 codebooks. More...
 
#define MAX_CBS_2x2   256
 Maximum number of 2x2 codebooks. More...
 
#define ROQ_LAMBDA_SCALE   ((uint64_t) FF_LAMBDA_SCALE)
 
#define EVAL_MOTION(MOTION)
 
#define OFFSET(x)   offsetof(RoqContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void unpack_roq_cell (roq_cell *cell, uint8_t u[4 *3])
 
static void unpack_roq_qcell (uint8_t cb2[], roq_qcell *qcell, uint8_t u[4 *4 *3])
 
static void enlarge_roq_mb4 (uint8_t base[3 *16], uint8_t u[3 *64])
 
static int square (int x)
 
static int eval_sse (const uint8_t *a, const uint8_t *b, int count)
 
static int block_sse (uint8_t *const *buf1, uint8_t *const *buf2, int x1, int y1, int x2, int y2, const int *stride1, const int *stride2, int size)
 
static int eval_motion_dist (RoqContext *enc, int x, int y, motion_vect vect, int size)
 
static int squared_diff_macroblock (uint8_t a[], uint8_t b[], int size)
 
static int create_cel_evals (RoqContext *enc, RoqTempdata *tempData)
 Initialize cel evaluators and set their source coordinates. More...
 
static void get_frame_mb (const AVFrame *frame, int x, int y, uint8_t mb[], int dim)
 Get macroblocks from parts of the image. More...
 
static int index_mb (uint8_t cluster[], uint8_t cb[], int numCB, int *outIndex, int dim)
 Find the codebook with the lowest distortion from an image. More...
 
static void motion_search (RoqContext *enc, int blocksize)
 
static void gather_data_for_subcel (SubcelEvaluation *subcel, int x, int y, RoqContext *enc, RoqTempdata *tempData)
 Get distortion for all options available to a subcel. More...
 
static void gather_data_for_cel (CelEvaluation *cel, RoqContext *enc, RoqTempdata *tempData)
 Get distortion for all options available to a cel. More...
 
static void remap_codebooks (RoqContext *enc, RoqTempdata *tempData)
 
static void write_codebooks (RoqContext *enc, RoqTempdata *tempData)
 Write codebook chunk. More...
 
static uint8_t motion_arg (motion_vect mot)
 
static void write_typecode (CodingSpool *s, uint8_t type)
 
static void reconstruct_and_encode_image (RoqContext *enc, RoqTempdata *tempData, int w, int h, int numBlocks)
 
static void frame_block_to_cell (uint8_t *block, uint8_t *const *data, int top, int left, const int *stride)
 Create a single YUV cell from a 2x2 section of the image. More...
 
static void create_clusters (const AVFrame *frame, int w, int h, uint8_t *yuvClusters)
 Create YUV clusters for the entire image. More...
 
static int generate_codebook (RoqContext *enc, RoqTempdata *tempdata, int *points, int inputCount, roq_cell *results, int size, int cbsize)
 
static int generate_new_codebooks (RoqContext *enc, RoqTempdata *tempData)
 
static int roq_encode_video (RoqContext *enc)
 
static av_cold int roq_encode_end (AVCodecContext *avctx)
 
static av_cold int roq_encode_init (AVCodecContext *avctx)
 
static void roq_write_video_info_chunk (RoqContext *enc)
 
static int roq_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 

Variables

static const AVOption options []
 
static const AVClass roq_class
 
AVCodec ff_roq_encoder
 

Detailed Description

id RoQ encoder by Vitor.

Based on the Switchblade3 library and the Switchblade3 FFmpeg glue by Eric Lasota.

Definition in file roqvideoenc.c.

Macro Definition Documentation

#define CHROMA_BIAS   1
#define MAX_CBS_4x4   256

Maximum number of generated 4x4 codebooks.

Can't be 256 to workaround a Quake 3 bug.

Definition at line 73 of file roqvideoenc.c.

Referenced by generate_new_codebooks(), and remap_codebooks().

#define MAX_CBS_2x2   256

Maximum number of 2x2 codebooks.

Definition at line 75 of file roqvideoenc.c.

Referenced by generate_new_codebooks(), and remap_codebooks().

#define ROQ_LAMBDA_SCALE   ((uint64_t) FF_LAMBDA_SCALE)

Definition at line 78 of file roqvideoenc.c.

Referenced by gather_data_for_cel(), gather_data_for_subcel(), and roq_encode_frame().

#define EVAL_MOTION (   MOTION)
Value:
do { \
diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
if (diff < lowestdiff) { \
lowestdiff = diff; \
bestpick = MOTION; \
} \
} while(0)
static int eval_motion_dist(RoqContext *enc, int x, int y, motion_vect vect, int size)
Definition: roqvideoenc.c:146
if(ret< 0)
Definition: vf_mcdeint.c:282
static av_always_inline int diff(const uint32_t a, const uint32_t b)

Definition at line 300 of file roqvideoenc.c.

Referenced by motion_search().

#define OFFSET (   x)    offsetof(RoqContext, x)

Definition at line 1127 of file roqvideoenc.c.

Definition at line 1128 of file roqvideoenc.c.

Function Documentation

static void unpack_roq_cell ( roq_cell cell,
uint8_t  u[4 *3] 
)
static

Definition at line 81 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

static void unpack_roq_qcell ( uint8_t  cb2[],
roq_qcell qcell,
uint8_t  u[4 *4 *3] 
)
static

Definition at line 88 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

static void enlarge_roq_mb4 ( uint8_t  base[3 *16],
uint8_t  u[3 *64] 
)
static

Definition at line 103 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

static int square ( int  x)
inlinestatic

Definition at line 113 of file roqvideoenc.c.

Referenced by dpcm_decode_init(), eval_sse(), fixed_sqrt(), and iterative_me().

static int eval_sse ( const uint8_t a,
const uint8_t b,
int  count 
)
inlinestatic

Definition at line 118 of file roqvideoenc.c.

Referenced by block_sse(), and squared_diff_macroblock().

static int block_sse ( uint8_t *const *  buf1,
uint8_t *const *  buf2,
int  x1,
int  y1,
int  x2,
int  y2,
const int *  stride1,
const int *  stride2,
int  size 
)
static
static int eval_motion_dist ( RoqContext enc,
int  x,
int  y,
motion_vect  vect,
int  size 
)
static

Definition at line 146 of file roqvideoenc.c.

Referenced by gather_data_for_cel(), gather_data_for_subcel(), and motion_search().

static int squared_diff_macroblock ( uint8_t  a[],
uint8_t  b[],
int  size 
)
inlinestatic
Returns
distortion between two macroblocks

Definition at line 173 of file roqvideoenc.c.

Referenced by gather_data_for_subcel(), and index_mb().

static int create_cel_evals ( RoqContext enc,
RoqTempdata tempData 
)
static

Initialize cel evaluators and set their source coordinates.

Definition at line 245 of file roqvideoenc.c.

Referenced by roq_encode_video().

static void get_frame_mb ( const AVFrame frame,
int  x,
int  y,
uint8_t  mb[],
int  dim 
)
static

Get macroblocks from parts of the image.

Definition at line 267 of file roqvideoenc.c.

Referenced by gather_data_for_cel(), and gather_data_for_subcel().

static int index_mb ( uint8_t  cluster[],
uint8_t  cb[],
int  numCB,
int *  outIndex,
int  dim 
)
static

Find the codebook with the lowest distortion from an image.

Definition at line 282 of file roqvideoenc.c.

Referenced by gather_data_for_cel(), gather_data_for_subcel(), and generate_new_codebooks().

static void motion_search ( RoqContext enc,
int  blocksize 
)
static

Definition at line 310 of file roqvideoenc.c.

Referenced by roq_encode_video().

static void gather_data_for_subcel ( SubcelEvaluation subcel,
int  x,
int  y,
RoqContext enc,
RoqTempdata tempData 
)
static

Get distortion for all options available to a subcel.

Definition at line 402 of file roqvideoenc.c.

Referenced by gather_data_for_cel().

static void gather_data_for_cel ( CelEvaluation cel,
RoqContext enc,
RoqTempdata tempData 
)
static

Get distortion for all options available to a cel.

Definition at line 466 of file roqvideoenc.c.

Referenced by roq_encode_video().

static void remap_codebooks ( RoqContext enc,
RoqTempdata tempData 
)
static

Definition at line 540 of file roqvideoenc.c.

Referenced by roq_encode_video().

static void write_codebooks ( RoqContext enc,
RoqTempdata tempData 
)
static

Write codebook chunk.

Definition at line 572 of file roqvideoenc.c.

Referenced by roq_encode_video().

static uint8_t motion_arg ( motion_vect  mot)
inlinestatic

Definition at line 596 of file roqvideoenc.c.

Referenced by reconstruct_and_encode_image().

static void write_typecode ( CodingSpool s,
uint8_t  type 
)
static

Definition at line 612 of file roqvideoenc.c.

Referenced by reconstruct_and_encode_image().

static void reconstruct_and_encode_image ( RoqContext enc,
RoqTempdata tempData,
int  w,
int  h,
int  numBlocks 
)
static

Definition at line 626 of file roqvideoenc.c.

Referenced by roq_encode_video().

static void frame_block_to_cell ( uint8_t block,
uint8_t *const *  data,
int  top,
int  left,
const int *  stride 
)
inlinestatic

Create a single YUV cell from a 2x2 section of the image.

Definition at line 760 of file roqvideoenc.c.

Referenced by create_clusters().

static void create_clusters ( const AVFrame frame,
int  w,
int  h,
uint8_t yuvClusters 
)
static

Create YUV clusters for the entire image.

Definition at line 781 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

static int generate_codebook ( RoqContext enc,
RoqTempdata tempdata,
int *  points,
int  inputCount,
roq_cell results,
int  size,
int  cbsize 
)
static

Definition at line 795 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

static int generate_new_codebooks ( RoqContext enc,
RoqTempdata tempData 
)
static

Definition at line 843 of file roqvideoenc.c.

Referenced by roq_encode_video().

static int roq_encode_video ( RoqContext enc)
static

Definition at line 911 of file roqvideoenc.c.

Referenced by roq_encode_frame().

static av_cold int roq_encode_end ( AVCodecContext avctx)
static

Definition at line 976 of file roqvideoenc.c.

Referenced by roq_encode_init().

static av_cold int roq_encode_init ( AVCodecContext avctx)
static

Definition at line 992 of file roqvideoenc.c.

static void roq_write_video_info_chunk ( RoqContext enc)
static

Definition at line 1050 of file roqvideoenc.c.

Referenced by roq_encode_frame().

static int roq_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 1075 of file roqvideoenc.c.

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{ "quake3_compat", "Whether to respect known limitations in Quake 3 decoder", OFFSET(quake3_compat), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define VE
Definition: roqvideoenc.c:1128
#define OFFSET(x)
Definition: roqvideoenc.c:1127

Definition at line 1129 of file roqvideoenc.c.

const AVClass roq_class
static
Initial value:
= {
.class_name = "RoQ",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static const AVOption options[]
Definition: roqvideoenc.c:1129
av_default_item_name

Definition at line 1134 of file roqvideoenc.c.

AVCodec ff_roq_encoder
Initial value:
= {
.name = "roqvideo",
.long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
.priv_data_size = sizeof(RoqContext),
.encode2 = roq_encode_frame,
.close = roq_encode_end,
.priv_class = &roq_class,
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static av_cold int roq_encode_end(AVCodecContext *avctx)
Definition: roqvideoenc.c:976
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: roqvideoenc.c:1075
static av_cold int roq_encode_init(AVCodecContext *avctx)
Definition: roqvideoenc.c:992
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
static const AVClass roq_class
Definition: roqvideoenc.c:1134
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60

Definition at line 1141 of file roqvideoenc.c.