FFmpeg
Macros | Functions | Variables
h264_cabac.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "config.h"
#include "cabac.h"
#include "cabac_functions.h"
#include "h264dec.h"
#include "h264data.h"
#include "h264_mvpred.h"
#include "mpegutils.h"

Go to the source code of this file.

Macros

#define CABAC(h)   1
 
#define UNCHECKED_BITSTREAM_READER   1
 
#define INT_BIT   (CHAR_BIT * sizeof(int))
 
#define DECODE_CABAC_MB_MVD(sl, list, n)
 
#define CABAC_ON_STACK
 
#define CC   &cc
 
#define DECODE_SIGNIFICANCE(coefs, sig_off, last_off)
 
#define STORE_BLOCK(type)
 

Functions

void ff_h264_init_cabac_states (const H264Context *h, H264SliceContext *sl)
 
static av_always_inline uint16_t pack8to16 (unsigned a, unsigned b)
 
static int decode_cabac_field_decoding_flag (const H264Context *h, H264SliceContext *sl)
 
static int decode_cabac_intra_mb_type (H264SliceContext *sl, int ctx_base, int intra_slice)
 
static int decode_cabac_mb_skip (const H264Context *h, H264SliceContext *sl, int mb_x, int mb_y)
 
static int decode_cabac_mb_intra4x4_pred_mode (H264SliceContext *sl, int pred_mode)
 
static int decode_cabac_mb_chroma_pre_mode (const H264Context *h, H264SliceContext *sl)
 
static int decode_cabac_mb_cbp_luma (H264SliceContext *sl)
 
static int decode_cabac_mb_cbp_chroma (H264SliceContext *sl)
 
static int decode_cabac_p_mb_sub_type (H264SliceContext *sl)
 
static int decode_cabac_b_mb_sub_type (H264SliceContext *sl)
 
static int decode_cabac_mb_ref (H264SliceContext *sl, int list, int n)
 
static int decode_cabac_mb_mvd (H264SliceContext *sl, int ctxbase, int amvd, int *mvda)
 
static av_always_inline int get_cabac_cbf_ctx (H264SliceContext *sl, int cat, int idx, int max_coeff, int is_dc)
 
static av_always_inline void decode_cabac_residual_internal (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc, int chroma422)
 
static av_noinline void decode_cabac_residual_dc_internal (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff)
 
static av_noinline void decode_cabac_residual_dc_internal_422 (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff)
 
static av_noinline void decode_cabac_residual_nondc_internal (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff)
 
static av_always_inline void decode_cabac_residual_dc (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff)
 
static av_always_inline void decode_cabac_residual_dc_422 (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, int max_coeff)
 
static av_always_inline void decode_cabac_residual_nondc (const H264Context *h, H264SliceContext *sl, int16_t *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff)
 
static av_always_inline void decode_cabac_luma_residual (const H264Context *h, H264SliceContext *sl, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p)
 
int ff_h264_decode_mb_cabac (const H264Context *h, H264SliceContext *sl)
 Decode a macroblock. More...
 

Variables

static const int8_t cabac_context_init_I [1024][2]
 
static const int8_t cabac_context_init_PB [3][1024][2]
 

Detailed Description

H.264 / AVC / MPEG-4 part10 cabac decoding.

Author
Michael Niedermayer micha.nosp@m.elni.nosp@m.@gmx..nosp@m.at

Definition in file h264_cabac.c.

Macro Definition Documentation

◆ CABAC

#define CABAC (   h)    1

Definition at line 28 of file h264_cabac.c.

◆ UNCHECKED_BITSTREAM_READER

#define UNCHECKED_BITSTREAM_READER   1

Definition at line 29 of file h264_cabac.c.

◆ INT_BIT

#define INT_BIT   (CHAR_BIT * sizeof(int))

Definition at line 30 of file h264_cabac.c.

◆ DECODE_CABAC_MB_MVD

#define DECODE_CABAC_MB_MVD (   sl,
  list,
 
)
Value:
{\
int amvd0 = sl->mvd_cache[list][scan8[n] - 1][0] +\
sl->mvd_cache[list][scan8[n] - 8][0];\
int amvd1 = sl->mvd_cache[list][scan8[n] - 1][1] +\
sl->mvd_cache[list][scan8[n] - 8][1];\
\
int mxd = decode_cabac_mb_mvd(sl, 40, amvd0, &mpx);\
int myd = decode_cabac_mb_mvd(sl, 47, amvd1, &mpy);\
if (mxd == INT_MIN || myd == INT_MIN) \
mx += mxd;\
my += myd;\
}

Definition at line 1543 of file h264_cabac.c.

◆ CABAC_ON_STACK

#define CABAC_ON_STACK

◆ CC

#define CC   &cc

◆ DECODE_SIGNIFICANCE

#define DECODE_SIGNIFICANCE (   coefs,
  sig_off,
  last_off 
)
Value:
for(last= 0; last < coefs; last++) { \
uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \
if( get_cabac( CC, sig_ctx )) { \
uint8_t *last_ctx = last_coeff_ctx_base + last_off; \
index[coeff_count++] = last; \
if( get_cabac( CC, last_ctx ) ) { \
last= max_coeff; \
break; \
} \
} \
}\
if( last == max_coeff -1 ) {\
index[coeff_count++] = last;\
}

◆ STORE_BLOCK

#define STORE_BLOCK (   type)

Function Documentation

◆ ff_h264_init_cabac_states()

void ff_h264_init_cabac_states ( const H264Context h,
H264SliceContext sl 
)

Definition at line 1262 of file h264_cabac.c.

Referenced by decode_slice().

◆ pack8to16()

static av_always_inline uint16_t pack8to16 ( unsigned  a,
unsigned  b 
)
static

Definition at line 1283 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_field_decoding_flag()

static int decode_cabac_field_decoding_flag ( const H264Context h,
H264SliceContext sl 
)
static

Definition at line 1292 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_intra_mb_type()

static int decode_cabac_intra_mb_type ( H264SliceContext sl,
int  ctx_base,
int  intra_slice 
)
static

Definition at line 1304 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_skip()

static int decode_cabac_mb_skip ( const H264Context h,
H264SliceContext sl,
int  mb_x,
int  mb_y 
)
static

Definition at line 1336 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_intra4x4_pred_mode()

static int decode_cabac_mb_intra4x4_pred_mode ( H264SliceContext sl,
int  pred_mode 
)
static

Definition at line 1373 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_chroma_pre_mode()

static int decode_cabac_mb_chroma_pre_mode ( const H264Context h,
H264SliceContext sl 
)
static

Definition at line 1387 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_cbp_luma()

static int decode_cabac_mb_cbp_luma ( H264SliceContext sl)
static

Definition at line 1412 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_cbp_chroma()

static int decode_cabac_mb_cbp_chroma ( H264SliceContext sl)
static

Definition at line 1429 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_p_mb_sub_type()

static int decode_cabac_p_mb_sub_type ( H264SliceContext sl)
static

Definition at line 1449 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_b_mb_sub_type()

static int decode_cabac_b_mb_sub_type ( H264SliceContext sl)
static

Definition at line 1459 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_ref()

static int decode_cabac_mb_ref ( H264SliceContext sl,
int  list,
int  n 
)
static

Definition at line 1477 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_mb_mvd()

static int decode_cabac_mb_mvd ( H264SliceContext sl,
int  ctxbase,
int  amvd,
int mvda 
)
static

Definition at line 1506 of file h264_cabac.c.

◆ get_cabac_cbf_ctx()

static av_always_inline int get_cabac_cbf_ctx ( H264SliceContext sl,
int  cat,
int  idx,
int  max_coeff,
int  is_dc 
)
static

◆ decode_cabac_residual_internal()

static av_always_inline void decode_cabac_residual_internal ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
const uint32_t *  qmul,
int  max_coeff,
int  is_dc,
int  chroma422 
)
static

◆ decode_cabac_residual_dc_internal()

static av_noinline void decode_cabac_residual_dc_internal ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
int  max_coeff 
)
static

Definition at line 1778 of file h264_cabac.c.

Referenced by decode_cabac_residual_dc().

◆ decode_cabac_residual_dc_internal_422()

static av_noinline void decode_cabac_residual_dc_internal_422 ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
int  max_coeff 
)
static

Definition at line 1788 of file h264_cabac.c.

Referenced by decode_cabac_residual_dc_422().

◆ decode_cabac_residual_nondc_internal()

static av_noinline void decode_cabac_residual_nondc_internal ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
const uint32_t *  qmul,
int  max_coeff 
)
static

Definition at line 1798 of file h264_cabac.c.

Referenced by decode_cabac_residual_nondc().

◆ decode_cabac_residual_dc()

static av_always_inline void decode_cabac_residual_dc ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
int  max_coeff 
)
static

Definition at line 1821 of file h264_cabac.c.

Referenced by decode_cabac_luma_residual(), and ff_h264_decode_mb_cabac().

◆ decode_cabac_residual_dc_422()

static av_always_inline void decode_cabac_residual_dc_422 ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
int  max_coeff 
)
static

Definition at line 1837 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ decode_cabac_residual_nondc()

static av_always_inline void decode_cabac_residual_nondc ( const H264Context h,
H264SliceContext sl,
int16_t *  block,
int  cat,
int  n,
const uint8_t *  scantable,
const uint32_t *  qmul,
int  max_coeff 
)
static

Definition at line 1850 of file h264_cabac.c.

Referenced by decode_cabac_luma_residual(), and ff_h264_decode_mb_cabac().

◆ decode_cabac_luma_residual()

static av_always_inline void decode_cabac_luma_residual ( const H264Context h,
H264SliceContext sl,
const uint8_t *  scan,
const uint8_t *  scan8x8,
int  pixel_shift,
int  mb_type,
int  cbp,
int  p 
)
static

Definition at line 1870 of file h264_cabac.c.

Referenced by ff_h264_decode_mb_cabac().

◆ ff_h264_decode_mb_cabac()

int ff_h264_decode_mb_cabac ( const H264Context h,
H264SliceContext sl 
)

Decode a macroblock.

Decode a CABAC coded macroblock.

Returns
0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed

Definition at line 1920 of file h264_cabac.c.

Referenced by decode_slice().

Variable Documentation

◆ cabac_context_init_I

const int8_t cabac_context_init_I[1024][2]
static

Definition at line 50 of file h264_cabac.c.

Referenced by ff_h264_init_cabac_states().

◆ cabac_context_init_PB

const int8_t cabac_context_init_PB[3][1024][2]
static

Definition at line 362 of file h264_cabac.c.

Referenced by ff_h264_init_cabac_states().

get_cabac
static int av_unused get_cabac(CABACContext *c, uint8_t *const state)
Definition: cabac_functions.h:144
scan8
static const uint8_t scan8[16 *3+3]
Definition: h264_parse.h:40
list
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
decode_cabac_mb_mvd
static int decode_cabac_mb_mvd(H264SliceContext *sl, int ctxbase, int amvd, int *mvda)
Definition: h264_cabac.c:1506
CC
#define CC
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61