FFmpeg
Loading...
Searching...
No Matches
cavsdec.c File Reference

Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder. More...

#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/intmath.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "get_bits.h"
#include "golomb.h"
#include "idctdsp.h"
#include "cavs.h"
#include "codec_internal.h"
#include "profiles.h"
#include "decode.h"
#include "mathops.h"
#include "mpeg12data.h"
#include "put_bits.h"
#include "startcode.h"

Go to the source code of this file.

Macros

#define EOB   0, 0, 0
 
#define AEC_MB_SKIP_RUN   0
 
#define AEC_MB_TYPE   4
 
#define AEC_MB_PART_TYPE   19
 
#define AEC_INTRA_LUMA_PRED_MODE   22
 
#define AEC_INTRA_CHROMA_PRED_MODE   26
 
#define AEC_MB_REFERENCE_INDEX   30
 
#define AEC_MV_DIFF_X   36
 
#define AEC_MV_DIFF_Y   42
 
#define AEC_CBP   48
 
#define AEC_MB_QP_DELTA   54
 
#define AEC_COEFF_FRAME_LUMA   58
 
#define AEC_COEFF_FRAME_CHROMA   124
 
#define AEC_COEFF_FIELD_LUMA   190
 
#define AEC_COEFF_FIELD_CHROMA   256
 
#define CAVS_MAX_ABS_LEVEL   2048
 
#define AEC_COEFF_NUM_CTX   66
 
#define AEC_COEFF_RUN   46
 
#define AEC_COEFF_RUN_NUM_CTX   20
 
#define MV(nP, nC, mode, size, ref)
 
#define REF(dst, list, nP)
 
#define TMP_UNUSED_INX   7
 
#define SET_REF(idx, frame, par, distance)
 

Functions

static void store_mvs (AVSContext *h)
 
static int scale_direct (unsigned den, int mv, int dist)
 Scale one component of the co-located motion vector, den being 16384 / BlockDistanceRef (clause 9.9.1 b) 3)).
 
static int field_parity (AVSContext *h, int distance_index)
 The parity of a field is the parity of its distance index: a first coded field has an even one, a second field an odd one (clause 9.4.6.1).
 
static void mv_pred_direct (AVSContext *h, cavs_vector *pmv_fw, cavs_vector *col_mv)
 Direct mode: scale the co-located motion vector by its own BlockDistance, carried in the mv cache (clause 9.9.1 b)).
 
static void mv_pred_sym (AVSContext *h, cavs_vector *src, enum cavs_block size)
 Symmetric mode: derive the backward mv from the forward one, scaled by the block's own pair of distances (clause 9.9.1 c)).
 
static int get_ue_code (GetBitContext *gb, int order)
 kth-order exponential golomb code
 
static av_always_inline int dequant_internal (AVSContext *h, int16_t *level_buf, uint8_t *run_buf, int16_t *dst, int mul, int shift, int coeff_num, int weighted)
 Inverse scan and dequantize the level/run pairs of one block into dst.
 
static int dequant (AVSContext *h, int16_t *level_buf, uint8_t *run_buf, int16_t *dst, int mul, int shift, int coeff_num)
 
static int decode_residual_block (AVSContext *h, GetBitContext *gb, const struct dec_2dvlc *r, int esc_golomb_order, int qp, uint8_t *dst, ptrdiff_t stride)
 decode coefficients from one 8x8 block, dequantize, inverse transform and add them to sample block
 
static int aec_mb_skip_run (AVSContext *h)
 Decode mb_skip_run, table 44 unary (8.4.4.2 a)).
 
static int aec_mb_type_p (AVSContext *h)
 Decode mb_type, table 44 unary mapped by tables 54 and 55 (9.4.2 a) 2))
 
static int aec_mb_type_b (AVSContext *h)
 Decode mb_type in a B picture (table 45, 8.4.4.2 b)); see table 56.
 
static int aec_mb_part_type (AVSContext *h)
 Decode mb_part_type (tables 46 and 57, 8.4.4.2 c)).
 
static int aec_ref_index (AVSContext *h, int ctx_inc, int max)
 Decode mb_reference_index, table 44 unary (8.4.3 j), 8.4.4.2 f)).
 
static int aec_mv_diff (AVSContext *h, int base, int mvda, int *diff)
 Decode one mv_diff_x or mv_diff_y (table 49, 8.4.4.2 g)); mvda is the magnitude of the same component of the left block's mv_diff.
 
static int aec_mv (AVSContext *h, enum cavs_mv_loc nP)
 Decode a motion vector's mv_diff pair into the cache that ff_cavs_mv() reads and the next block takes its mvda from.
 
static int aec_intra_luma_pred_mode (AVSContext *h, int pred)
 Decode intra_luma_pred_mode (table 47) and derive IntraLumaPredMode from predIntraPredMode per clause 9.4.4.2 a).
 
static int aec_intra_chroma_pred_mode (AVSContext *h)
 Decode intra_chroma_pred_mode (table 48, 8.4.4.2 e)).
 
static int aec_cbp (AVSContext *h)
 Decode cbp (table 50, 8.4.4.2 h), clause 9.4.7).
 
static int aec_mb_qp_delta (AVSContext *h, int *delta)
 Decode mb_qp_delta (table 44 unary, 8.4.4.2 i)) and map the code number to the signed delta of clause 9.4.8.
 
static int decode_residual_block_aec (AVSContext *h, int chroma, int qp, uint8_t *dst, ptrdiff_t stride)
 Decode the trans_coefficient pairs of one 8x8 block (8.4.4.2 j) and k)).
 
static int is_start_code_offset (AVSContext *h, int offset)
 Tell whether the byte aligned 00 00 01 at offset is a start code: in a de-emulated payload it may be a coincidence (annex A).
 
static int seek_to_start_code (AVSContext *h, int offset)
 Position the reader on the first start code prefix at or after offset, or near the end of the buffer when there is none.
 
static void aec_end_of_slice (AVSContext *h)
 Position the reader on the start code that ends an AEC slice: the first one at or after the slice's own payload.
 
static int decode_mb_qp_delta (AVSContext *h)
 Read mb_qp_delta when the macroblock has coefficients and the picture's qp is not fixed, and keep PreviousDeltaQP for the AEC contexts (clause 9.4.8).
 
static int decode_residual (AVSContext *h, const struct dec_2dvlc *r, int esc_golomb_order, int chroma, int qp, uint8_t *dst, ptrdiff_t stride)
 Decode one 8x8 block's residual with the picture's entropy coder.
 
static int decode_residual_chroma (AVSContext *h)
 
static int decode_residual_inter (AVSContext *h)
 
static void set_mv_intra (AVSContext *h)
 
static int decode_mb_i (AVSContext *h, int cbp_code)
 
static void set_intra_mode_default (AVSContext *h)
 
static int decode_ref_index (AVSContext *h, int list, enum cavs_mv_loc nP)
 Read one mb_reference_index and turn it into a reference list index (table 26, clauses 7.2.5 and 9.4.5).
 
static int decode_mv (AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, enum cavs_mv_pred mode, enum cavs_block size, int ref)
 Decode one motion vector: under AEC its mv_diff must be read before ff_cavs_mv() overwrites the cache its context comes from.
 
static void set_inter_mb_ctx (AVSContext *h, enum cavs_mb mb_type, int skip)
 
static int decode_mb_p (AVSContext *h, enum cavs_mb mb_type)
 
static int decode_mb_b (AVSContext *h, enum cavs_mb mb_type)
 
static int decode_mb_pb_layer (AVSContext *h, int *skip_count)
 Decode one macroblock of a P or B coded macroblock layer, table 25.
 
static int decode_slice_header (AVSContext *h, GetBitContext *gb)
 
static int check_for_slice (AVSContext *h)
 
static int set_ref_list (AVSContext *h)
 Build the reference list and the temporal distances of the current frame or field (clause 9.4.5 figures 14 to 20, clause 9.4.6.1).
 
static int decode_weighting_quant (AVSContext *h)
 Read the weighted quantization parameters of a picture header (tables 21 and 22) and build WeightingQuantMatrix8x8 (9.2, 9.4.9).
 
static int decode_pic (AVSContext *h)
 
static int decode_seq_header (AVSContext *h)
 
static int annex_a_applies (int stc)
 annex A applies to picture headers and slices, not to other units
 
static int deemulate_region (PutBitContext *pb, const uint8_t *buf, int size, int deemulated)
 Copy one region of a picture payload, removing the annex A pseudo start codes; the clause 5.8.2.4 stuffing is rewritten to keep the next start code aligned.
 
static int deemulate_picture (AVSContext *h, PutBitContext *pb, const uint8_t *buf, int size)
 Walk the payload region by region, removing the annex A pseudo start codes; on the writing pass, record every start code prefix offset in h->stc_offset.
 
static int remove_pseudo_start_codes (AVSContext *h, const uint8_t *buf, int size)
 Remove the annex A pseudo start codes from a payload: a byte forming 00 00 02 with the two before it loses its two least significant bits.
 
static av_cold void cavs_flush (AVCodecContext *avctx)
 
static int cavs_decode_frame (AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
 

Variables

static const uint8_t mv_scan [4]
 
static const uint8_t cbp_tab [64][2]
 
static const uint8_t scan3x3 [4] = { 4, 5, 7, 8 }
 
static const uint8_t dequant_shift [64]
 
static const uint16_t dequant_mul [64]
 
static const struct dec_2dvlc intra_dec [7]
 
static const struct dec_2dvlc inter_dec [7]
 
static const struct dec_2dvlc chroma_dec [5]
 
static const uint8_t cavs_aec_pri_idx [6] = { 0, 1, 2, 3, 3, 4 }
 Table 52, priIdx as a function of lMax, which saturates at 5.
 
const FFCodec ff_cavs_decoder
 

Detailed Description

Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.

Author
Stefan Gehrer stefa.nosp@m.n.ge.nosp@m.hrer@.nosp@m.gmx..nosp@m.de

Clause, table and figure numbers refer to GY/T 257.1-2012.

Definition in file cavsdec.c.

Macro Definition Documentation

◆ EOB

#define EOB   0, 0, 0

Definition at line 87 of file cavsdec.c.

◆ AEC_MB_SKIP_RUN

#define AEC_MB_SKIP_RUN   0

Definition at line 699 of file cavsdec.c.

Referenced by aec_mb_skip_run().

◆ AEC_MB_TYPE

#define AEC_MB_TYPE   4

Definition at line 700 of file cavsdec.c.

Referenced by aec_mb_type_b(), and aec_mb_type_p().

◆ AEC_MB_PART_TYPE

#define AEC_MB_PART_TYPE   19

Definition at line 701 of file cavsdec.c.

Referenced by aec_mb_part_type().

◆ AEC_INTRA_LUMA_PRED_MODE

#define AEC_INTRA_LUMA_PRED_MODE   22

Definition at line 702 of file cavsdec.c.

Referenced by aec_intra_luma_pred_mode().

◆ AEC_INTRA_CHROMA_PRED_MODE

#define AEC_INTRA_CHROMA_PRED_MODE   26

Definition at line 703 of file cavsdec.c.

Referenced by aec_intra_chroma_pred_mode().

◆ AEC_MB_REFERENCE_INDEX

#define AEC_MB_REFERENCE_INDEX   30

Definition at line 704 of file cavsdec.c.

Referenced by aec_ref_index().

◆ AEC_MV_DIFF_X

#define AEC_MV_DIFF_X   36

Definition at line 705 of file cavsdec.c.

Referenced by aec_mv().

◆ AEC_MV_DIFF_Y

#define AEC_MV_DIFF_Y   42

Definition at line 706 of file cavsdec.c.

Referenced by aec_mv().

◆ AEC_CBP

#define AEC_CBP   48

Definition at line 707 of file cavsdec.c.

Referenced by aec_cbp().

◆ AEC_MB_QP_DELTA

#define AEC_MB_QP_DELTA   54

Definition at line 708 of file cavsdec.c.

Referenced by aec_mb_qp_delta().

◆ AEC_COEFF_FRAME_LUMA

#define AEC_COEFF_FRAME_LUMA   58

Definition at line 709 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_FRAME_CHROMA

#define AEC_COEFF_FRAME_CHROMA   124

Definition at line 710 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_FIELD_LUMA

#define AEC_COEFF_FIELD_LUMA   190

Definition at line 711 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_FIELD_CHROMA

#define AEC_COEFF_FIELD_CHROMA   256

Definition at line 712 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ CAVS_MAX_ABS_LEVEL

#define CAVS_MAX_ABS_LEVEL   2048

Definition at line 716 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_NUM_CTX

#define AEC_COEFF_NUM_CTX   66

Definition at line 719 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_RUN

#define AEC_COEFF_RUN   46

Definition at line 720 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ AEC_COEFF_RUN_NUM_CTX

#define AEC_COEFF_RUN_NUM_CTX   20

Definition at line 721 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ MV

#define MV ( nP,
nC,
mode,
size,
ref )
Value:
do { \
ret = decode_mv(h, nP, nC, mode, size, ref); \
if (ret < 0) \
return ret; \
} while (0)
static int decode_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, enum cavs_mv_pred mode, enum cavs_block size, int ref)
Decode one motion vector: under AEC its mv_diff must be read before ff_cavs_mv() overwrites the cache...
Definition cavsdec.c:1377
int ret
Definition ffplay.c:391
Definition swscale.c:85
static int ref[MAX_W *MAX_W]
int size

Definition at line 1403 of file cavsdec.c.

Referenced by clv_decode_frame(), decode_mb_b(), decode_mb_p(), decode_tile(), ff_vc1_pred_b_mv(), ff_vc1_pred_mv(), mc(), mv_pred(), mvi_predict(), mvi_reset(), mvi_update_prediction(), predict_mv(), and read_mv().

◆ REF

#define REF ( dst,
list,
nP )
Value:
do { \
if (ret < 0) \
return ret; \
dst = ret; \
} while (0)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static int decode_ref_index(AVSContext *h, int list, enum cavs_mv_loc nP)
Read one mb_reference_index and turn it into a reference list index (table 26, clauses 7....
Definition cavsdec.c:1344
static ListView * list
Definition ffplay.c:377

Definition at line 1410 of file cavsdec.c.

Referenced by decode_mb_b(), and decode_mb_p().

◆ TMP_UNUSED_INX

#define TMP_UNUSED_INX   7

Referenced by decode_mb_b().

◆ SET_REF

#define SET_REF ( idx,
frame,
par,
distance )
Value:
do { \
h->ref[idx].f = (frame); \
h->ref[idx].parity = (par); \
h->dist[idx] = (distance) & 511; \
} while (0)
static AVFrame * frame
static float distance(float x, float y, int band)

Referenced by set_ref_list().

Function Documentation

◆ store_mvs()

static void store_mvs ( AVSContext * h)
inlinestatic

Definition at line 467 of file cavsdec.c.

Referenced by decode_mb_p().

◆ scale_direct()

static int scale_direct ( unsigned den,
int mv,
int dist )
inlinestatic

Scale one component of the co-located motion vector, den being 16384 / BlockDistanceRef (clause 9.9.1 b) 3)).

The intermediate products stay unsigned, they can overflow an int.

Definition at line 480 of file cavsdec.c.

Referenced by mv_pred_direct().

◆ field_parity()

static int field_parity ( AVSContext * h,
int distance_index )
inlinestatic

The parity of a field is the parity of its distance index: a first coded field has an even one, a second field an odd one (clause 9.4.6.1).

Definition at line 491 of file cavsdec.c.

Referenced by mv_pred_direct(), and slice_to_vbi_lines().

◆ mv_pred_direct()

static void mv_pred_direct ( AVSContext * h,
cavs_vector * pmv_fw,
cavs_vector * col_mv )
inlinestatic

Direct mode: scale the co-located motion vector by its own BlockDistance, carried in the mv cache (clause 9.9.1 b)).

Annex B fixes PictureStructure over a sequence, so the frame and field conversion of step 2 cannot arise.

Definition at line 502 of file cavsdec.c.

Referenced by decode_mb_b().

◆ mv_pred_sym()

static void mv_pred_sym ( AVSContext * h,
cavs_vector * src,
enum cavs_block size )
inlinestatic

Symmetric mode: derive the backward mv from the forward one, scaled by the block's own pair of distances (clause 9.9.1 c)).

Definition at line 549 of file cavsdec.c.

Referenced by decode_mb_b().

◆ get_ue_code()

static int get_ue_code ( GetBitContext * gb,
int order )
inlinestatic

kth-order exponential golomb code

Definition at line 575 of file cavsdec.c.

Referenced by decode_residual_block().

◆ dequant_internal()

static av_always_inline int dequant_internal ( AVSContext * h,
int16_t * level_buf,
uint8_t * run_buf,
int16_t * dst,
int mul,
int shift,
int coeff_num,
int weighted )
static

Inverse scan and dequantize the level/run pairs of one block into dst.

Parameters
weightedscale by WeightingQuantMatrix8x8 as well; a constant in both callers, so each gets its own loop

Definition at line 593 of file cavsdec.c.

Referenced by dequant().

◆ dequant()

static int dequant ( AVSContext * h,
int16_t * level_buf,
uint8_t * run_buf,
int16_t * dst,
int mul,
int shift,
int coeff_num )
inlinestatic

◆ decode_residual_block()

static int decode_residual_block ( AVSContext * h,
GetBitContext * gb,
const struct dec_2dvlc * r,
int esc_golomb_order,
int qp,
uint8_t * dst,
ptrdiff_t stride )
static

decode coefficients from one 8x8 block, dequantize, inverse transform and add them to sample block

Parameters
rpointer to 2D VLC table
esc_golomb_orderescape codes are k-golomb with this order k
qpquantizer
dstlocation of sample block
strideline stride in frame buffer

Definition at line 643 of file cavsdec.c.

Referenced by decode_residual().

◆ aec_mb_skip_run()

static int aec_mb_skip_run ( AVSContext * h)
static

Decode mb_skip_run, table 44 unary (8.4.4.2 a)).

Returns
SkipMbCount

Definition at line 727 of file cavsdec.c.

Referenced by decode_mb_pb_layer().

◆ aec_mb_type_p()

static int aec_mb_type_p ( AVSContext * h)
static

Decode mb_type, table 44 unary mapped by tables 54 and 55 (9.4.2 a) 2))

Definition at line 742 of file cavsdec.c.

Referenced by decode_mb_pb_layer().

◆ aec_mb_type_b()

static int aec_mb_type_b ( AVSContext * h)
static

Decode mb_type in a B picture (table 45, 8.4.4.2 b)); see table 56.

Definition at line 756 of file cavsdec.c.

Referenced by decode_mb_pb_layer().

◆ aec_mb_part_type()

static int aec_mb_part_type ( AVSContext * h)
static

Decode mb_part_type (tables 46 and 57, 8.4.4.2 c)).

Returns
MbPartType, 0 to 3

Definition at line 781 of file cavsdec.c.

Referenced by decode_mb_b().

◆ aec_ref_index()

static int aec_ref_index ( AVSContext * h,
int ctx_inc,
int max )
static

Decode mb_reference_index, table 44 unary (8.4.3 j), 8.4.4.2 f)).

Definition at line 791 of file cavsdec.c.

Referenced by decode_ref_index().

◆ aec_mv_diff()

static int aec_mv_diff ( AVSContext * h,
int base,
int mvda,
int * diff )
static

Decode one mv_diff_x or mv_diff_y (table 49, 8.4.4.2 g)); mvda is the magnitude of the same component of the left block's mv_diff.

Definition at line 811 of file cavsdec.c.

Referenced by aec_mv().

◆ aec_mv()

static int aec_mv ( AVSContext * h,
enum cavs_mv_loc nP )
static

Decode a motion vector's mv_diff pair into the cache that ff_cavs_mv() reads and the next block takes its mvda from.

Definition at line 854 of file cavsdec.c.

Referenced by decode_mv().

◆ aec_intra_luma_pred_mode()

static int aec_intra_luma_pred_mode ( AVSContext * h,
int pred )
static

Decode intra_luma_pred_mode (table 47) and derive IntraLumaPredMode from predIntraPredMode per clause 9.4.4.2 a).

Definition at line 872 of file cavsdec.c.

Referenced by decode_mb_i().

◆ aec_intra_chroma_pred_mode()

static int aec_intra_chroma_pred_mode ( AVSContext * h)
static

Decode intra_chroma_pred_mode (table 48, 8.4.4.2 e)).

Returns
IntraChromaPredMode, 0 to 3 (table 60)

Definition at line 891 of file cavsdec.c.

Referenced by decode_mb_i().

◆ aec_cbp()

static int aec_cbp ( AVSContext * h)
static

Decode cbp (table 50, 8.4.4.2 h), clause 9.4.7).

Returns
MbCBP, a six bit mask over the block order numbers

Definition at line 919 of file cavsdec.c.

Referenced by decode_mb_i(), and decode_residual_inter().

◆ aec_mb_qp_delta()

static int aec_mb_qp_delta ( AVSContext * h,
int * delta )
static

Decode mb_qp_delta (table 44 unary, 8.4.4.2 i)) and map the code number to the signed delta of clause 9.4.8.

Definition at line 958 of file cavsdec.c.

Referenced by decode_mb_qp_delta().

◆ decode_residual_block_aec()

static int decode_residual_block_aec ( AVSContext * h,
int chroma,
int qp,
uint8_t * dst,
ptrdiff_t stride )
static

Decode the trans_coefficient pairs of one 8x8 block (8.4.4.2 j) and k)).

Parameters
chromaselects the chroma half of the context sets of table 51

Definition at line 986 of file cavsdec.c.

Referenced by decode_residual().

◆ is_start_code_offset()

static int is_start_code_offset ( AVSContext * h,
int offset )
static

Tell whether the byte aligned 00 00 01 at offset is a start code: in a de-emulated payload it may be a coincidence (annex A).

Definition at line 1087 of file cavsdec.c.

Referenced by check_for_slice(), and seek_to_start_code().

◆ seek_to_start_code()

static int seek_to_start_code ( AVSContext * h,
int offset )
static

Position the reader on the first start code prefix at or after offset, or near the end of the buffer when there is none.

Returns
1 if a start code prefix was found

Definition at line 1112 of file cavsdec.c.

Referenced by aec_end_of_slice(), and check_for_slice().

◆ aec_end_of_slice()

static void aec_end_of_slice ( AVSContext * h)
static

Position the reader on the start code that ends an AEC slice: the first one at or after the slice's own payload.

The reader position is not reliable: the arithmetic decoder's look ahead has run past it.

Definition at line 1133 of file cavsdec.c.

Referenced by decode_mb_pb_layer(), and decode_pic().

◆ decode_mb_qp_delta()

static int decode_mb_qp_delta ( AVSContext * h)
static

Read mb_qp_delta when the macroblock has coefficients and the picture's qp is not fixed, and keep PreviousDeltaQP for the AEC contexts (clause 9.4.8).

Definition at line 1145 of file cavsdec.c.

Referenced by decode_mb_i(), and decode_residual_inter().

◆ decode_residual()

static int decode_residual ( AVSContext * h,
const struct dec_2dvlc * r,
int esc_golomb_order,
int chroma,
int qp,
uint8_t * dst,
ptrdiff_t stride )
static

Decode one 8x8 block's residual with the picture's entropy coder.

Definition at line 1164 of file cavsdec.c.

Referenced by decode_mb_i(), decode_residual_chroma(), and decode_residual_inter().

◆ decode_residual_chroma()

static int decode_residual_chroma ( AVSContext * h)
inlinestatic

Definition at line 1174 of file cavsdec.c.

Referenced by decode_mb_i(), and decode_residual_inter().

◆ decode_residual_inter()

static int decode_residual_inter ( AVSContext * h)
inlinestatic

Definition at line 1193 of file cavsdec.c.

Referenced by decode_mb_b(), and decode_mb_p().

◆ set_mv_intra()

static void set_mv_intra ( AVSContext * h)
inlinestatic

Definition at line 1228 of file cavsdec.c.

Referenced by decode_mb_i().

◆ decode_mb_i()

static int decode_mb_i ( AVSContext * h,
int cbp_code )
static

Definition at line 1238 of file cavsdec.c.

Referenced by decode_mb_pb_layer(), and decode_pic().

◆ set_intra_mode_default()

static void set_intra_mode_default ( AVSContext * h)
inlinestatic

Definition at line 1327 of file cavsdec.c.

Referenced by decode_mb_b(), and decode_mb_p().

◆ decode_ref_index()

static int decode_ref_index ( AVSContext * h,
int list,
enum cavs_mv_loc nP )
static

Read one mb_reference_index and turn it into a reference list index (table 26, clauses 7.2.5 and 9.4.5).

Table 26 misprints the presence predicate's brackets; GB/T 20090.2-2013 table 27 and IEEE 1857-2023 clause 7.1.5 both print it as implemented here.

Definition at line 1344 of file cavsdec.c.

◆ decode_mv()

static int decode_mv ( AVSContext * h,
enum cavs_mv_loc nP,
enum cavs_mv_loc nC,
enum cavs_mv_pred mode,
enum cavs_block size,
int ref )
static

Decode one motion vector: under AEC its mv_diff must be read before ff_cavs_mv() overwrites the cache its context comes from.

Definition at line 1377 of file cavsdec.c.

◆ set_inter_mb_ctx()

static void set_inter_mb_ctx ( AVSContext * h,
enum cavs_mb mb_type,
int skip )
static

Definition at line 1390 of file cavsdec.c.

Referenced by decode_mb_b(), and decode_mb_p().

◆ decode_mb_p()

static int decode_mb_p ( AVSContext * h,
enum cavs_mb mb_type )
static

Definition at line 1418 of file cavsdec.c.

Referenced by decode_mb_pb_layer().

◆ decode_mb_b()

static int decode_mb_b ( AVSContext * h,
enum cavs_mb mb_type )
static

Definition at line 1477 of file cavsdec.c.

Referenced by decode_mb_pb_layer().

◆ decode_mb_pb_layer()

static int decode_mb_pb_layer ( AVSContext * h,
int * skip_count )
static

Decode one macroblock of a P or B coded macroblock layer, table 25.

Parameters
skip_countwhat is left of the current mb_skip_run, or -1 when the next macroblock position starts a new one

Definition at line 1664 of file cavsdec.c.

Referenced by decode_pic().

◆ decode_slice_header()

static int decode_slice_header ( AVSContext * h,
GetBitContext * gb )
inlinestatic

Definition at line 1715 of file cavsdec.c.

Referenced by check_for_slice().

◆ check_for_slice()

static int check_for_slice ( AVSContext * h)
inlinestatic

Definition at line 1749 of file cavsdec.c.

Referenced by decode_pic().

◆ set_ref_list()

static int set_ref_list ( AVSContext * h)
static

Build the reference list and the temporal distances of the current frame or field (clause 9.4.5 figures 14 to 20, clause 9.4.6.1).

Definition at line 1818 of file cavsdec.c.

Referenced by decode_pic().

◆ decode_weighting_quant()

static int decode_weighting_quant ( AVSContext * h)
static

Read the weighted quantization parameters of a picture header (tables 21 and 22) and build WeightingQuantMatrix8x8 (9.2, 9.4.9).

Definition at line 1900 of file cavsdec.c.

Referenced by decode_pic().

◆ decode_pic()

static int decode_pic ( AVSContext * h)
static

Definition at line 2001 of file cavsdec.c.

Referenced by cavs_decode_frame().

◆ decode_seq_header()

static int decode_seq_header ( AVSContext * h)
static

Definition at line 2208 of file cavsdec.c.

Referenced by cavs_decode_frame().

◆ annex_a_applies()

static int annex_a_applies ( int stc)
static

annex A applies to picture headers and slices, not to other units

Definition at line 2306 of file cavsdec.c.

Referenced by deemulate_picture().

◆ deemulate_region()

static int deemulate_region ( PutBitContext * pb,
const uint8_t * buf,
int size,
int deemulated )
static

Copy one region of a picture payload, removing the annex A pseudo start codes; the clause 5.8.2.4 stuffing is rewritten to keep the next start code aligned.

With pb NULL they are only counted.

Returns
the number of pseudo start codes found

Definition at line 2319 of file cavsdec.c.

Referenced by deemulate_picture().

◆ deemulate_picture()

static int deemulate_picture ( AVSContext * h,
PutBitContext * pb,
const uint8_t * buf,
int size )
static

Walk the payload region by region, removing the annex A pseudo start codes; on the writing pass, record every start code prefix offset in h->stc_offset.

Returns
the number of pseudo start codes found

Definition at line 2373 of file cavsdec.c.

Referenced by remove_pseudo_start_codes().

◆ remove_pseudo_start_codes()

static int remove_pseudo_start_codes ( AVSContext * h,
const uint8_t * buf,
int size )
static

Remove the annex A pseudo start codes from a payload: a byte forming 00 00 02 with the two before it loses its two least significant bits.

buf runs from just after a picture start code to the packet end.

Returns
the size of h->deemulated_buf, 0 if buf needs no copy, or < 0

Definition at line 2420 of file cavsdec.c.

Referenced by cavs_decode_frame().

◆ cavs_flush()

static av_cold void cavs_flush ( AVCodecContext * avctx)
static

Definition at line 2449 of file cavsdec.c.

◆ cavs_decode_frame()

static int cavs_decode_frame ( AVCodecContext * avctx,
AVFrame * rframe,
int * got_frame,
AVPacket * avpkt )
static

Definition at line 2455 of file cavsdec.c.

Variable Documentation

◆ mv_scan

const uint8_t mv_scan[4]
static
Initial value:
= {
}
@ MV_FWD_X3
Definition cavs.h:140
@ MV_FWD_X1
Definition cavs.h:137
@ MV_FWD_X0
Definition cavs.h:136
@ MV_FWD_X2
Definition cavs.h:139

Definition at line 47 of file cavsdec.c.

Referenced by decode_mb_b().

◆ cbp_tab

const uint8_t cbp_tab[64][2]
static
Initial value:
= {
{ 63, 0 }, { 15, 15 }, { 31, 63 }, { 47, 31 }, { 0, 16 }, { 14, 32 }, { 13, 47 }, { 11, 13 },
{ 7, 14 }, { 5, 11 }, { 10, 12 }, { 8, 5 }, { 12, 10 }, { 61, 7 }, { 4, 48 }, { 55, 3 },
{ 1, 2 }, { 2, 8 }, { 59, 4 }, { 3, 1 }, { 62, 61 }, { 9, 55 }, { 6, 59 }, { 29, 62 },
{ 45, 29 }, { 51, 27 }, { 23, 23 }, { 39, 19 }, { 27, 30 }, { 46, 28 }, { 53, 9 }, { 30, 6 },
{ 43, 60 }, { 37, 21 }, { 60, 44 }, { 16, 26 }, { 21, 51 }, { 28, 35 }, { 19, 18 }, { 35, 20 },
{ 42, 24 }, { 26, 53 }, { 44, 17 }, { 32, 37 }, { 58, 39 }, { 24, 45 }, { 20, 58 }, { 17, 43 },
{ 18, 42 }, { 48, 46 }, { 22, 36 }, { 33, 33 }, { 25, 34 }, { 49, 40 }, { 40, 52 }, { 36, 49 },
{ 34, 50 }, { 50, 56 }, { 52, 25 }, { 54, 22 }, { 41, 54 }, { 56, 57 }, { 38, 41 }, { 57, 38 }
}

Definition at line 52 of file cavsdec.c.

Referenced by decode_coeffs(), decode_mb_i(), decode_residual_inter(), and init_static_data().

◆ scan3x3

const uint8_t scan3x3[4] = { 4, 5, 7, 8 }
static

Definition at line 63 of file cavsdec.c.

Referenced by decode_mb_i().

◆ dequant_shift

const uint8_t dequant_shift[64]
static
Initial value:
= {
14, 14, 14, 14, 14, 14, 14, 14,
13, 13, 13, 13, 13, 13, 13, 13,
13, 12, 12, 12, 12, 12, 12, 12,
11, 11, 11, 11, 11, 11, 11, 11,
11, 10, 10, 10, 10, 10, 10, 10,
10, 9, 9, 9, 9, 9, 9, 9,
9, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7
}

Definition at line 65 of file cavsdec.c.

Referenced by decode_residual_block(), and decode_residual_block_aec().

◆ dequant_mul

const uint16_t dequant_mul[64]
static
Initial value:
= {
32768, 36061, 38968, 42495, 46341, 50535, 55437, 60424,
32932, 35734, 38968, 42495, 46177, 50535, 55109, 59933,
65535, 35734, 38968, 42577, 46341, 50617, 55027, 60097,
32809, 35734, 38968, 42454, 46382, 50576, 55109, 60056,
65535, 35734, 38968, 42495, 46320, 50515, 55109, 60076,
65535, 35744, 38968, 42495, 46341, 50535, 55099, 60087,
65535, 35734, 38973, 42500, 46341, 50535, 55109, 60097,
32771, 35734, 38965, 42497, 46341, 50535, 55109, 60099
}

Definition at line 76 of file cavsdec.c.

Referenced by decode_residual_block(), and decode_residual_block_aec().

◆ intra_dec

const struct dec_2dvlc intra_dec[7]
static

Definition at line 89 of file cavsdec.c.

Referenced by decode_mb_i().

◆ inter_dec

const struct dec_2dvlc inter_dec[7]
static

Definition at line 225 of file cavsdec.c.

Referenced by decode_residual_inter().

◆ chroma_dec

const struct dec_2dvlc chroma_dec[5]
static

Definition at line 361 of file cavsdec.c.

Referenced by decode_residual_chroma().

◆ cavs_aec_pri_idx

const uint8_t cavs_aec_pri_idx[6] = { 0, 1, 2, 3, 3, 4 }
static

Table 52, priIdx as a function of lMax, which saturates at 5.

Definition at line 724 of file cavsdec.c.

Referenced by decode_residual_block_aec().

◆ ff_cavs_decoder

const FFCodec ff_cavs_decoder
Initial value:
= {
.p.name = "cavs",
CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2/P16)"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(AVSContext),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = cavs_flush,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
av_cold int ff_cavs_end(AVCodecContext *avctx)
Definition cavs.c:936
av_cold int ff_cavs_init(AVCodecContext *avctx)
Definition cavs.c:888
static av_cold void cavs_flush(AVCodecContext *avctx)
Definition cavsdec.c:2449
static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition cavsdec.c:2455
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_CAVS
Definition codec_id.h:137
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:98
const AVProfile ff_cavs_profiles[]
Definition profiles.c:70

Definition at line 2547 of file cavsdec.c.