FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
bink.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/emms.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "binkdata.h"
#include "binkdsp.h"
#include "blockdsp.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"
#include "hpeldsp.h"

Go to the source code of this file.

Data Structures

struct  Tree
 data needed to decode 4-bit Huffman-coded value More...
 
struct  Bundle
 data structure used for decoding single Bink data type More...
 
struct  BinkContext
 

Macros

#define BITSTREAM_READER_LE
 
#define BINK_FLAG_ALPHA   0x00100000
 
#define BINK_FLAG_GRAY   0x00020000
 
#define GET_HUFF(gb, tree)
 
#define CHECK_READ_VAL(gb, b, t)
 common check before starting decoding bundle data More...
 
#define DC_START_BITS   11
 number of bits used to store first DC value in bundle More...
 
#define C   (1LL<<30)
 

Enumerations

enum  OldSources {
  BINKB_SRC_BLOCK_TYPES = 0, BINKB_SRC_COLORS, BINKB_SRC_PATTERN, BINKB_SRC_X_OFF,
  BINKB_SRC_Y_OFF, BINKB_SRC_INTRA_DC, BINKB_SRC_INTER_DC, BINKB_SRC_INTRA_Q,
  BINKB_SRC_INTER_Q, BINKB_SRC_INTER_COEFS, BINKB_NB_SRC
}
 IDs for different data types used in old version of Bink video codec. More...
 
enum  Sources {
  BINK_SRC_BLOCK_TYPES = 0, BINK_SRC_SUB_BLOCK_TYPES, BINK_SRC_COLORS, BINK_SRC_PATTERN,
  BINK_SRC_X_OFF, BINK_SRC_Y_OFF, BINK_SRC_INTRA_DC, BINK_SRC_INTER_DC,
  BINK_SRC_RUN, BINK_NB_SRC
}
 IDs for different data types used in Bink video codec. More...
 
enum  BlockTypes {
  SKIP_BLOCK = 0, SCALED_BLOCK, MOTION_BLOCK, RUN_BLOCK,
  RESIDUE_BLOCK, INTRA_BLOCK, FILL_BLOCK, INTER_BLOCK,
  PATTERN_BLOCK, RAW_BLOCK
}
 Bink video block types. More...
 

Functions

static void init_lengths (BinkContext *c, int width, int bw)
 Initialize length in all bundles. More...
 
static av_cold int init_bundles (BinkContext *c)
 Allocate memory for bundles. More...
 
static av_cold void free_bundles (BinkContext *c)
 Free memory used by bundles. More...
 
static void merge (GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
 Merge two consequent lists of equal size depending on bits read. More...
 
static int read_tree (GetBitContext *gb, Tree *tree)
 Read information about Huffman tree used to decode data. More...
 
static int read_bundle (GetBitContext *gb, BinkContext *c, int bundle_num)
 Prepare bundle for decoding data. More...
 
static int read_runs (AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
 
static int read_motion_values (AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
 
static int read_block_types (AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
 
static int read_patterns (AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
 
static int read_colors (GetBitContext *gb, Bundle *b, BinkContext *c)
 
static int read_dcs (AVCodecContext *avctx, GetBitContext *gb, Bundle *b, int start_bits, int has_sign)
 
static int get_value (BinkContext *c, int bundle)
 Retrieve next value from bundle. More...
 
static av_cold void binkb_init_bundle (BinkContext *c, int bundle_num)
 
static av_cold void binkb_init_bundles (BinkContext *c)
 
static int binkb_read_bundle (BinkContext *c, GetBitContext *gb, int bundle_num)
 
static int binkb_get_value (BinkContext *c, int bundle_num)
 
static int read_dct_coeffs (BinkContext *c, GetBitContext *gb, int32_t block[64], const uint8_t *scan, int *coef_count_, int coef_idx[64], int q)
 Read 8x8 block of DCT coefficients. More...
 
static void unquantize_dct_coeffs (int32_t block[64], const uint32_t quant[64], int coef_count, int coef_idx[64], const uint8_t *scan)
 
static int read_residue (GetBitContext *gb, int16_t block[64], int masks_count)
 Read 8x8 block with residue after motion compensation. More...
 
static void put_pixels8x8_overlapped (uint8_t *dst, uint8_t *src, int stride)
 Copy 8x8 block from source to destination, where src and dst may be overlapped. More...
 
static int binkb_decode_plane (BinkContext *c, AVFrame *frame, GetBitContext *gb, int plane_idx, int is_key, int is_chroma)
 
static int bink_put_pixels (BinkContext *c, uint8_t *dst, uint8_t *prev, int stride, uint8_t *ref_start, uint8_t *ref_end)
 
static int bink_decode_plane (BinkContext *c, AVFrame *frame, GetBitContext *gb, int plane_idx, int is_chroma)
 
static int decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
 
static av_cold void bink_init_vlcs (void)
 
static av_cold void binkb_calc_quant (void)
 Calculate quantization tables for version b. More...
 
static av_cold int decode_init (AVCodecContext *avctx)
 
static av_cold int decode_end (AVCodecContext *avctx)
 
static void flush (AVCodecContext *avctx)
 

Variables

static VLC bink_trees [16]
 
static const uint8_t binkb_bundle_sizes [BINKB_NB_SRC]
 
static const uint8_t binkb_bundle_signed [BINKB_NB_SRC]
 
static int32_t binkb_intra_quant [16][64]
 
static int32_t binkb_inter_quant [16][64]
 
static const uint8_t bink_rlelens [4] = { 4, 8, 12, 32 }
 
const FFCodec ff_bink_decoder
 

Macro Definition Documentation

◆ BITSTREAM_READER_LE

#define BITSTREAM_READER_LE

Definition at line 30 of file bink.c.

◆ BINK_FLAG_ALPHA

#define BINK_FLAG_ALPHA   0x00100000

Definition at line 40 of file bink.c.

◆ BINK_FLAG_GRAY

#define BINK_FLAG_GRAY   0x00020000

Definition at line 41 of file bink.c.

◆ GET_HUFF

#define GET_HUFF (   gb,
  tree 
)
Value:
(tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\
bink_trees[(tree).vlc_num].bits, 1)]

Definition at line 99 of file bink.c.

◆ CHECK_READ_VAL

#define CHECK_READ_VAL (   gb,
  b,
 
)
Value:
if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
return 0; \
t = get_bits(gb, b->len); \
if (!t) { \
b->cur_dec = NULL; \
return 0; \
} \

common check before starting decoding bundle data

Parameters
gbcontext for reading bits
bbundle
tvariable where number of elements to decode will be stored

Definition at line 323 of file bink.c.

◆ DC_START_BITS

#define DC_START_BITS   11

number of bits used to store first DC value in bundle

Definition at line 502 of file bink.c.

◆ C

#define C   (1LL<<30)

Enumeration Type Documentation

◆ OldSources

enum OldSources

IDs for different data types used in old version of Bink video codec.

Enumerator
BINKB_SRC_BLOCK_TYPES 

8x8 block types

BINKB_SRC_COLORS 

pixel values used for different block types

BINKB_SRC_PATTERN 

8-bit values for 2-colour pattern fill

BINKB_SRC_X_OFF 

X components of motion value.

BINKB_SRC_Y_OFF 

Y components of motion value.

BINKB_SRC_INTRA_DC 

DC values for intrablocks with DCT.

BINKB_SRC_INTER_DC 

DC values for interblocks with DCT.

BINKB_SRC_INTRA_Q 

quantizer values for intrablocks with DCT

BINKB_SRC_INTER_Q 

quantizer values for interblocks with DCT

BINKB_SRC_INTER_COEFS 

number of coefficients for residue blocks

BINKB_NB_SRC 

Definition at line 48 of file bink.c.

◆ Sources

enum Sources

IDs for different data types used in Bink video codec.

Enumerator
BINK_SRC_BLOCK_TYPES 

8x8 block types

BINK_SRC_SUB_BLOCK_TYPES 

16x16 block types (a subset of 8x8 block types)

BINK_SRC_COLORS 

pixel values used for different block types

BINK_SRC_PATTERN 

8-bit values for 2-colour pattern fill

BINK_SRC_X_OFF 

X components of motion value.

BINK_SRC_Y_OFF 

Y components of motion value.

BINK_SRC_INTRA_DC 

DC values for intrablocks with DCT.

BINK_SRC_INTER_DC 

DC values for interblocks with DCT.

BINK_SRC_RUN 

run lengths for special fill block

BINK_NB_SRC 

Definition at line 77 of file bink.c.

◆ BlockTypes

enum BlockTypes

Bink video block types.

Enumerator
SKIP_BLOCK 

skipped block

SCALED_BLOCK 

block has size 16x16

MOTION_BLOCK 

block is copied from previous frame with some offset

RUN_BLOCK 

block is composed from runs of colours with custom scan order

RESIDUE_BLOCK 

motion block with some difference added

INTRA_BLOCK 

intra DCT block

FILL_BLOCK 

block is filled with single colour

INTER_BLOCK 

motion block with DCT applied to the difference

PATTERN_BLOCK 

block is filled with two colours following custom pattern

RAW_BLOCK 

uncoded 8x8 block

Definition at line 136 of file bink.c.

Function Documentation

◆ init_lengths()

static void init_lengths ( BinkContext c,
int  width,
int  bw 
)
static

Initialize length in all bundles.

Parameters
cdecoder context
widthplane width
bwplane width in 8x8 blocks

Definition at line 156 of file bink.c.

Referenced by bink_decode_plane().

◆ init_bundles()

static av_cold int init_bundles ( BinkContext c)
static

Allocate memory for bundles.

Parameters
cdecoder context

Definition at line 181 of file bink.c.

Referenced by decode_init().

◆ free_bundles()

static av_cold void free_bundles ( BinkContext c)
static

Free memory used by bundles.

Parameters
cdecoder context

Definition at line 208 of file bink.c.

Referenced by decode_end().

◆ merge()

static void merge ( GetBitContext gb,
uint8_t *  dst,
uint8_t *  src,
int  size 
)
static

Merge two consequent lists of equal size depending on bits read.

Parameters
gbcontext for reading bits
dstbuffer where merged list will be written to
srcpointer to the head of the first list (the second lists starts at src+size)
sizeinput lists size

Definition at line 221 of file bink.c.

Referenced by ff_subtitles_queue_insert(), ff_subtitles_queue_insert_bprint(), read_tree(), and realtext_read_header().

◆ read_tree()

static int read_tree ( GetBitContext gb,
Tree tree 
)
static

Read information about Huffman tree used to decode data.

Parameters
gbcontext for reading bits
treepointer for storing tree data

Definition at line 248 of file bink.c.

Referenced by read_bundle().

◆ read_bundle()

static int read_bundle ( GetBitContext gb,
BinkContext c,
int  bundle_num 
)
static

Prepare bundle for decoding data.

Parameters
gbcontext for reading bits
cdecoder context
bundle_numnumber of the bundle to initialize

Definition at line 293 of file bink.c.

Referenced by bink_decode_plane().

◆ read_runs()

static int read_runs ( AVCodecContext avctx,
GetBitContext gb,
Bundle b 
)
static

Definition at line 332 of file bink.c.

Referenced by bink_decode_plane().

◆ read_motion_values()

static int read_motion_values ( AVCodecContext avctx,
GetBitContext gb,
Bundle b 
)
static

Definition at line 356 of file bink.c.

Referenced by bink_decode_plane().

◆ read_block_types()

static int read_block_types ( AVCodecContext avctx,
GetBitContext gb,
Bundle b 
)
static

Definition at line 392 of file bink.c.

Referenced by bink_decode_plane().

◆ read_patterns()

static int read_patterns ( AVCodecContext avctx,
GetBitContext gb,
Bundle b 
)
static

Definition at line 437 of file bink.c.

Referenced by bink_decode_plane().

◆ read_colors()

static int read_colors ( GetBitContext gb,
Bundle b,
BinkContext c 
)
static

Definition at line 459 of file bink.c.

Referenced by bink_decode_plane().

◆ read_dcs()

static int read_dcs ( AVCodecContext avctx,
GetBitContext gb,
Bundle b,
int  start_bits,
int  has_sign 
)
static

Definition at line 504 of file bink.c.

Referenced by bink_decode_plane().

◆ get_value()

static int get_value ( BinkContext c,
int  bundle 
)
inlinestatic

Retrieve next value from bundle.

Parameters
cdecoder context
bundlebundle number

Definition at line 558 of file bink.c.

Referenced by bink_decode_plane(), and bink_put_pixels().

◆ binkb_init_bundle()

static av_cold void binkb_init_bundle ( BinkContext c,
int  bundle_num 
)
static

Definition at line 571 of file bink.c.

Referenced by binkb_init_bundles().

◆ binkb_init_bundles()

static av_cold void binkb_init_bundles ( BinkContext c)
static

Definition at line 578 of file bink.c.

Referenced by binkb_decode_plane().

◆ binkb_read_bundle()

static int binkb_read_bundle ( BinkContext c,
GetBitContext gb,
int  bundle_num 
)
static

Definition at line 585 of file bink.c.

Referenced by binkb_decode_plane().

◆ binkb_get_value()

static int binkb_get_value ( BinkContext c,
int  bundle_num 
)
inlinestatic

Definition at line 619 of file bink.c.

Referenced by binkb_decode_plane().

◆ read_dct_coeffs()

static int read_dct_coeffs ( BinkContext c,
GetBitContext gb,
int32_t  block[64],
const uint8_t *  scan,
int coef_count_,
int  coef_idx[64],
int  q 
)
static

Read 8x8 block of DCT coefficients.

Parameters
gbcontext for reading bits
blockplace for storing coefficients
scanscan order table
quant_matricesquantization matrices
Returns
0 for success, negative value in other cases

Definition at line 642 of file bink.c.

Referenced by bink_decode_plane(), and binkb_decode_plane().

◆ unquantize_dct_coeffs()

static void unquantize_dct_coeffs ( int32_t  block[64],
const uint32_t  quant[64],
int  coef_count,
int  coef_idx[64],
const uint8_t *  scan 
)
static

Definition at line 738 of file bink.c.

Referenced by bink_decode_plane(), and binkb_decode_plane().

◆ read_residue()

static int read_residue ( GetBitContext gb,
int16_t  block[64],
int  masks_count 
)
static

Read 8x8 block with residue after motion compensation.

Parameters
gbcontext for reading bits
blockplace to store read data
masks_countnumber of masks to decode
Returns
0 on success, negative value in other cases

Definition at line 758 of file bink.c.

Referenced by bink_decode_plane(), and binkb_decode_plane().

◆ put_pixels8x8_overlapped()

static void put_pixels8x8_overlapped ( uint8_t *  dst,
uint8_t *  src,
int  stride 
)
inlinestatic

Copy 8x8 block from source to destination, where src and dst may be overlapped.

Definition at line 843 of file bink.c.

Referenced by binkb_decode_plane().

◆ binkb_decode_plane()

static int binkb_decode_plane ( BinkContext c,
AVFrame frame,
GetBitContext gb,
int  plane_idx,
int  is_key,
int  is_chroma 
)
static

Definition at line 853 of file bink.c.

Referenced by decode_frame().

◆ bink_put_pixels()

static int bink_put_pixels ( BinkContext c,
uint8_t *  dst,
uint8_t *  prev,
int  stride,
uint8_t *  ref_start,
uint8_t *  ref_end 
)
static

Definition at line 1003 of file bink.c.

Referenced by bink_decode_plane().

◆ bink_decode_plane()

static int bink_decode_plane ( BinkContext c,
AVFrame frame,
GetBitContext gb,
int  plane_idx,
int  is_chroma 
)
static

Definition at line 1021 of file bink.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
AVFrame frame,
int got_frame,
AVPacket pkt 
)
static

Definition at line 1256 of file bink.c.

◆ bink_init_vlcs()

static av_cold void bink_init_vlcs ( void  )
static

Definition at line 1313 of file bink.c.

Referenced by decode_init().

◆ binkb_calc_quant()

static av_cold void binkb_calc_quant ( void  )
static

Calculate quantization tables for version b.

Definition at line 1330 of file bink.c.

Referenced by decode_init().

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 1359 of file bink.c.

◆ decode_end()

static av_cold int decode_end ( AVCodecContext avctx)
static

Definition at line 1404 of file bink.c.

◆ flush()

static void flush ( AVCodecContext avctx)
static

Definition at line 1414 of file bink.c.

Variable Documentation

◆ bink_trees

VLC bink_trees[16]
static

Definition at line 43 of file bink.c.

Referenced by bink_init_vlcs().

◆ binkb_bundle_sizes

const uint8_t binkb_bundle_sizes[BINKB_NB_SRC]
static
Initial value:
= {
4, 8, 8, 5, 5, 11, 11, 4, 4, 7
}

Definition at line 63 of file bink.c.

Referenced by binkb_get_value(), and binkb_read_bundle().

◆ binkb_bundle_signed

const uint8_t binkb_bundle_signed[BINKB_NB_SRC]
static
Initial value:
= {
0, 0, 0, 1, 1, 0, 1, 0, 0, 0
}

Definition at line 67 of file bink.c.

Referenced by binkb_get_value(), and binkb_read_bundle().

◆ binkb_intra_quant

int32_t binkb_intra_quant[16][64]
static

Definition at line 71 of file bink.c.

Referenced by binkb_calc_quant(), and binkb_decode_plane().

◆ binkb_inter_quant

int32_t binkb_inter_quant[16][64]
static

Definition at line 72 of file bink.c.

Referenced by binkb_calc_quant(), and binkb_decode_plane().

◆ bink_rlelens

const uint8_t bink_rlelens[4] = { 4, 8, 12, 32 }
static

Definition at line 390 of file bink.c.

Referenced by read_block_types().

◆ ff_bink_decoder

const FFCodec ff_bink_decoder
Initial value:
= {
.p.name = "binkvideo",
CODEC_LONG_NAME("Bink video"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(BinkContext),
.close = decode_end,
.flush = flush,
.p.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1421 of file bink.c.

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:42
flush
static void flush(AVCodecContext *avctx)
Definition: bink.c:1414
b
#define b
Definition: input.c:41
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
bink_trees
static VLC bink_trees[16]
Definition: bink.c:43
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
bits
uint8_t bits
Definition: vp3data.h:128
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
NULL
#define NULL
Definition: coverity.c:32
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: bink.c:1256
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
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
decode_end
static av_cold int decode_end(AVCodecContext *avctx)
Definition: bink.c:1404
BinkContext
Definition: bink.c:117
AV_CODEC_ID_BINKVIDEO
@ AV_CODEC_ID_BINKVIDEO
Definition: codec_id.h:187
VLC::table
VLCElem * table
Definition: vlc.h:35
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: bink.c:1359