FFmpeg
Data Structures | Macros | Functions | Variables
roqvideoenc.c File Reference
#include <string.h>
#include "libavutil/attributes.h"
#include "libavutil/lfg.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "roqvideo.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "elbg.h"
#include "encode.h"
#include "mathops.h"

Go to the source code of this file.

Data Structures

struct  RoqCodebooks
 
struct  RoqTempData
 Temporary vars. More...
 
struct  SubcelEvaluation
 
struct  CelEvaluation
 
struct  RoqEncContext
 
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(RoqEncContext, 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 (RoqEncContext *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 (RoqEncContext *enc)
 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 (RoqEncContext *enc, int blocksize)
 
static void gather_data_for_subcel (SubcelEvaluation *subcel, int x, int y, RoqEncContext *enc)
 Get distortion for all options available to a subcel. More...
 
static void gather_data_for_cel (CelEvaluation *cel, RoqEncContext *enc)
 Get distortion for all options available to a cel. More...
 
static void remap_codebooks (RoqEncContext *enc)
 
static void write_codebooks (RoqEncContext *enc)
 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 (RoqEncContext *enc, int w, int h, int numBlocks)
 
static void frame_block_to_cell (int *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, int *points)
 Create YUV clusters for the entire image. More...
 
static int generate_codebook (RoqEncContext *enc, int *points, int inputCount, roq_cell *results, int size, int cbsize)
 
static int generate_new_codebooks (RoqEncContext *enc)
 
static int roq_encode_video (RoqEncContext *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 (RoqEncContext *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
 
const FFCodec 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

◆ CHROMA_BIAS

#define CHROMA_BIAS   1

Definition at line 70 of file roqvideoenc.c.

◆ MAX_CBS_4x4

#define MAX_CBS_4x4   256

Maximum number of generated 4x4 codebooks.

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

Definition at line 76 of file roqvideoenc.c.

◆ MAX_CBS_2x2

#define MAX_CBS_2x2   256

Maximum number of 2x2 codebooks.

Definition at line 78 of file roqvideoenc.c.

◆ ROQ_LAMBDA_SCALE

#define ROQ_LAMBDA_SCALE   ((uint64_t) FF_LAMBDA_SCALE)

Definition at line 81 of file roqvideoenc.c.

◆ EVAL_MOTION

#define EVAL_MOTION (   MOTION)
Value:
do { \
diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
if (diff < lowestdiff) { \
lowestdiff = diff; \
bestpick = MOTION; \
} \
} while(0)

Definition at line 329 of file roqvideoenc.c.

◆ OFFSET

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

Definition at line 1105 of file roqvideoenc.c.

◆ VE

Definition at line 1106 of file roqvideoenc.c.

Function Documentation

◆ unpack_roq_cell()

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

Definition at line 164 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

◆ unpack_roq_qcell()

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

Definition at line 171 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

◆ enlarge_roq_mb4()

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

Definition at line 186 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

◆ square()

static int square ( int  x)
inlinestatic

◆ eval_sse()

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

Definition at line 201 of file roqvideoenc.c.

Referenced by block_sse(), and squared_diff_macroblock().

◆ block_sse()

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

Definition at line 213 of file roqvideoenc.c.

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

◆ eval_motion_dist()

static int eval_motion_dist ( RoqEncContext enc,
int  x,
int  y,
motion_vect  vect,
int  size 
)
static

Definition at line 229 of file roqvideoenc.c.

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

◆ squared_diff_macroblock()

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

Definition at line 257 of file roqvideoenc.c.

Referenced by gather_data_for_subcel(), and index_mb().

◆ create_cel_evals()

static int create_cel_evals ( RoqEncContext enc)
static

Initialize cel evaluators and set their source coordinates.

Definition at line 274 of file roqvideoenc.c.

Referenced by roq_encode_init().

◆ get_frame_mb()

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 296 of file roqvideoenc.c.

Referenced by gather_data_for_cel(), and gather_data_for_subcel().

◆ index_mb()

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 311 of file roqvideoenc.c.

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

◆ motion_search()

static void motion_search ( RoqEncContext enc,
int  blocksize 
)
static

Definition at line 339 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ gather_data_for_subcel()

static void gather_data_for_subcel ( SubcelEvaluation subcel,
int  x,
int  y,
RoqEncContext enc 
)
static

Get distortion for all options available to a subcel.

Definition at line 431 of file roqvideoenc.c.

Referenced by gather_data_for_cel().

◆ gather_data_for_cel()

static void gather_data_for_cel ( CelEvaluation cel,
RoqEncContext enc 
)
static

Get distortion for all options available to a cel.

Definition at line 497 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ remap_codebooks()

static void remap_codebooks ( RoqEncContext enc)
static

Definition at line 572 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ write_codebooks()

static void write_codebooks ( RoqEncContext enc)
static

Write codebook chunk.

Definition at line 606 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ motion_arg()

static uint8_t motion_arg ( motion_vect  mot)
inlinestatic

Definition at line 632 of file roqvideoenc.c.

Referenced by reconstruct_and_encode_image().

◆ write_typecode()

static void write_typecode ( CodingSpool s,
uint8_t  type 
)
static

Definition at line 648 of file roqvideoenc.c.

Referenced by reconstruct_and_encode_image().

◆ reconstruct_and_encode_image()

static void reconstruct_and_encode_image ( RoqEncContext enc,
int  w,
int  h,
int  numBlocks 
)
static

Definition at line 662 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ frame_block_to_cell()

static void frame_block_to_cell ( int *  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 782 of file roqvideoenc.c.

Referenced by create_clusters().

◆ create_clusters()

static void create_clusters ( const AVFrame frame,
int  w,
int  h,
int *  points 
)
static

Create YUV clusters for the entire image.

Definition at line 803 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

◆ generate_codebook()

static int generate_codebook ( RoqEncContext enc,
int *  points,
int  inputCount,
roq_cell results,
int  size,
int  cbsize 
)
static

Definition at line 817 of file roqvideoenc.c.

Referenced by generate_new_codebooks().

◆ generate_new_codebooks()

static int generate_new_codebooks ( RoqEncContext enc)
static

Definition at line 845 of file roqvideoenc.c.

Referenced by roq_encode_video().

◆ roq_encode_video()

static int roq_encode_video ( RoqEncContext enc)
static

Definition at line 891 of file roqvideoenc.c.

Referenced by roq_encode_frame().

◆ roq_encode_end()

static av_cold int roq_encode_end ( AVCodecContext avctx)
static

Definition at line 950 of file roqvideoenc.c.

◆ roq_encode_init()

static av_cold int roq_encode_init ( AVCodecContext avctx)
static

Definition at line 969 of file roqvideoenc.c.

◆ roq_write_video_info_chunk()

static void roq_write_video_info_chunk ( RoqEncContext enc)
static

Definition at line 1029 of file roqvideoenc.c.

Referenced by roq_encode_frame().

◆ roq_encode_frame()

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

Definition at line 1054 of file roqvideoenc.c.

Variable Documentation

◆ options

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 },
}

Definition at line 1107 of file roqvideoenc.c.

◆ roq_class

const AVClass roq_class
static
Initial value:
= {
.class_name = "RoQ",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1112 of file roqvideoenc.c.

◆ ff_roq_encoder

const FFCodec ff_roq_encoder
Initial value:
= {
.p.name = "roqvideo",
CODEC_LONG_NAME("id RoQ video"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_ROQ,
.priv_data_size = sizeof(RoqEncContext),
.close = roq_encode_end,
.p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVJ444P,
.color_ranges = AVCOL_RANGE_JPEG,
.p.priv_class = &roq_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1119 of file roqvideoenc.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
VE
#define VE
Definition: roqvideoenc.c:1106
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:717
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
RoqEncContext
Definition: roqvideoenc.c:135
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
if
if(ret)
Definition: filter_design.txt:179
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
roq_encode_init
static av_cold int roq_encode_init(AVCodecContext *avctx)
Definition: roqvideoenc.c:969
AV_CODEC_ID_ROQ
@ AV_CODEC_ID_ROQ
Definition: codec_id.h:90
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
roq_encode_end
static av_cold int roq_encode_end(AVCodecContext *avctx)
Definition: roqvideoenc.c:950
options
static const AVOption options[]
Definition: roqvideoenc.c:1107
eval_motion_dist
static int eval_motion_dist(RoqEncContext *enc, int x, int y, motion_vect vect, int size)
Definition: roqvideoenc.c:229
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
roq_encode_frame
static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: roqvideoenc.c:1054
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
OFFSET
#define OFFSET(x)
Definition: roqvideoenc.c:1105
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
roq_class
static const AVClass roq_class
Definition: roqvideoenc.c:1112