FFmpeg
Loading...
Searching...
No Matches
cavs.h
Go to the documentation of this file.
1/*
2 * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
3 * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef AVCODEC_CAVS_H
23#define AVCODEC_CAVS_H
24
25#include <stddef.h>
26#include <stdint.h>
27#include <string.h>
28
30#include "libavutil/frame.h"
32
33#include "avcodec.h"
34#include "cavs_aec.h"
35#include "cavsdsp.h"
36#include "blockdsp.h"
37#include "h264chroma.h"
38#include "get_bits.h"
39#include "videodsp.h"
40
41#define SLICE_MAX_START_CODE 0x000001af
42#define EXT_START_CODE 0x000001b5
43#define USER_START_CODE 0x000001b2
44#define CAVS_START_CODE 0x000001b0
45#define PIC_I_START_CODE 0x000001b3
46#define PIC_PB_START_CODE 0x000001b6
47
48#define A_AVAIL 1
49#define B_AVAIL 2
50#define C_AVAIL 4
51#define D_AVAIL 8
52#define NOT_AVAIL -1
53#define REF_INTRA -2
54#define REF_DIR -3
55
56#define ESCAPE_CODE 59
57
58#define FWD0 0x01
59#define FWD1 0x02
60#define BWD0 0x04
61#define BWD1 0x08
62#define SYM0 0x10
63#define SYM1 0x20
64#define SPLITH 0x40
65#define SPLITV 0x80
66
67#define MV_BWD_OFFS 12
68#define MV_STRIDE 4
69
84
91
102
112
121
128
151
152typedef struct cavs_vector {
153 int16_t x;
154 int16_t y;
155 int16_t dist;
156 int16_t ref;
157 /**
158 * mb_reference_index of the block, 0 when it codes none (clause 9.4.5);
159 * ref above is where the reference list puts it
160 */
161 int16_t ref_idx;
163
164struct dec_2dvlc {
165 int8_t rltab[59][3];
166 int8_t level_add[27];
169 int8_t max_run;
170};
171
172typedef struct AVSFrame {
174 int poc;
175} AVSFrame;
176
177typedef struct AVSContext {
184 AVSFrame cur; ///< currently decoded frame
185 AVSFrame DPB[2]; ///< reference frames
186 /**
187 * The reference of every reference index, clause 9.4.5: a frame, or the
188 * field of one starting at parity; both lists share the array.
189 */
190 struct {
191 AVFrame *f; ///< frame the reference belongs to
192 int parity; ///< first line of the reference field inside it
193 } ref[4];
194 int ref_base[2]; ///< first entry of the forward and the backward list
195 int dist[4]; ///< BlockDistance of every reference, clause 9.4.6.1
202 int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
205 int top_field_first; ///< first coded field is the top one, clause 7.2.3
206 int b_field_enhanced; ///< BFieldEnhanced of the picture, clause 9.9.1 b)
207 int p_field_skip; ///< PFieldSkip of the picture, clause 9.9.1 a)
208 int field; ///< field of the current MB, 0 or 1, clause 3.24
209 int field_mby; ///< macroblock row of the current macroblock in it
210 int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
211 int aec_enable; ///< the macroblock layer uses AEC (AVS1-P16)
212 int aec_start; ///< byte offset of the current AEC slice's payload
213 CAVSAECContext aec; ///< AEC decoder state and contexts, clause 8.4
214 int prev_delta_qp; ///< PreviousDeltaQP of clause 9.4.8, an AEC context
215 int left_cbp; ///< MbCBP of the macroblock to the left
216 uint8_t *top_cbp; ///< MbCBP of the macroblock above, one per column
217 int left_mb_type; ///< MbType to the left, clause 8.4.4.2 b)
218 uint8_t *top_mb_type; ///< MbType above, one per column
219 int left_c_pred_mode; ///< IntraChromaPredMode to the left, 8.4.4.2 e)
220 uint8_t *top_c_pred_mode; ///< IntraChromaPredMode above, per column
224 int mbx, mby, mbidx; ///< macroblock coordinates
225 int flags; ///< availability flags of neighbouring macroblocks
226 int stc; ///< last start code
227 int pic_data_end; ///< a unit that is not a slice ended the picture's data
228 uint8_t *cy, *cu, *cv; ///< current MB sample pointers
230 uint8_t *top_qp;
231
232 /** mv motion vector cache
233 0: D3 B2 B3 C2
234 4: A1 X0 X1 -
235 8: A3 X2 X3 -
236
237 X are the vectors in the current macroblock (5,6,9,10)
238 A is the macroblock to the left (4,8)
239 B is the macroblock to the top (1,2)
240 C is the macroblock to the top-right (3)
241 D is the macroblock to the top-left (0)
242
243 the same is repeated for backward motion vectors */
245 /** mv_diff of the same blocks, for the ctxIdxInc of clause 8.4.4.2 g) */
246 int16_t mvd[2*4*3][2];
249
250 /** luma pred mode cache
251 0: -- B2 B3
252 3: A1 X0 X1
253 6: A3 X2 X3 */
254 int pred_mode_Y[3*3];
256 ptrdiff_t l_stride, c_stride;
257 int luma_scan[4];
258 int qp;
261 int cbp;
262 DECLARE_ALIGNED(32, int16_t, block)[64];
264 /** inverse block scan method 2 of clause 9.5.3 c), for field pictures */
266 /** the one of the two the current picture uses, selected in decode_pic() */
267 const uint8_t *scantable;
268
269 /** intra prediction is done with un-deblocked samples
270 they are saved here before deblocking the MB */
273 uint8_t intern_border_y[26];
275
276 void (*intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
277 void (*intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
279
280 /** 512 / dist[], for scaling neighbouring MVs (clause 9.4.6.2 step 3) */
281 int scale_den[4];
282
283 /**
284 * 16384 / BlockDistanceRef of clause 9.9.1 b) 3), indexed by the
285 * co-located block's own distance, which is 9 bits (clause 9.4.6.1)
286 */
287 uint16_t direct_den[512];
288
290
291 /**
292 * picture payload with the annex A pseudo start codes removed,
293 * allocated only for the pictures that carry one
294 */
297 /**
298 * byte offsets in deemulated_buf at which a start code prefix of the
299 * original payload begins
300 */
301 uint32_t *stc_offset;
302 unsigned int stc_offset_size;
304
306} AVSContext;
307
308extern const uint8_t ff_cavs_chroma_qp[64];
309extern const uint8_t ff_cavs_partition_flags[30];
310
311/** mark block as using intra prediction */
312#define CAVS_DIR_MV (cavs_vector){ 0, 0, 1, REF_DIR, 0 }
313/** mark block as "no prediction from this direction"
314 e.g. forward motion vector in BWD partition */
315#define CAVS_INTRA_MV (cavs_vector){ 0, 0, 1, REF_INTRA, 0 }
316
317static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
318 switch(size) {
319 case BLK_16X16:
320 mv[MV_STRIDE ] = mv[0];
321 mv[MV_STRIDE+1] = mv[0];
323 case BLK_16X8:
324 mv[1] = mv[0];
325 break;
326 case BLK_8X16:
327 mv[MV_STRIDE] = mv[0];
328 break;
329 }
330}
331
332/** replicate one partition's mv_diff over the 8x8 blocks it covers */
333static inline void set_mvds(int16_t (*mvd)[2], enum cavs_block size)
334{
335 switch (size) {
336 case BLK_16X16:
337 memcpy(mvd[MV_STRIDE ], mvd[0], sizeof(*mvd));
338 memcpy(mvd[MV_STRIDE+1], mvd[0], sizeof(*mvd));
340 case BLK_16X8:
341 memcpy(mvd[1], mvd[0], sizeof(*mvd));
342 break;
343 case BLK_8X16:
344 memcpy(mvd[MV_STRIDE], mvd[0], sizeof(*mvd));
345 break;
346 }
347}
348
349void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
350void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
351 int block);
353void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
354void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
355void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
356 enum cavs_mv_pred mode, enum cavs_block size, int ref);
362int ff_cavs_init(AVCodecContext *avctx);
363int ff_cavs_end (AVCodecContext *avctx);
364
365#endif /* AVCODEC_CAVS_H */
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define MV_BWD_OFFS
Definition cavs.h:67
int ff_cavs_init_pic(AVSContext *h)
Definition cavs.c:792
cavs_sub_mb
Definition cavs.h:85
@ B_SUB_SYM
Definition cavs.h:89
@ B_SUB_DIRECT
Definition cavs.h:86
@ B_SUB_FWD
Definition cavs.h:87
@ B_SUB_BWD
Definition cavs.h:88
void ff_cavs_set_mb_row(AVSContext *h)
Point the macroblock sample pointers at macroblock row h->mby, addressed inside the macroblock's own ...
Definition cavs.c:676
cavs_mv_pred
Definition cavs.h:113
@ MV_PRED_MEDIAN
Definition cavs.h:114
@ MV_PRED_TOP
Definition cavs.h:116
@ MV_PRED_BSKIP
Definition cavs.h:119
@ MV_PRED_PSKIP
Definition cavs.h:118
@ MV_PRED_LEFT
Definition cavs.h:115
@ MV_PRED_TOPRIGHT
Definition cavs.h:117
const uint8_t ff_cavs_chroma_qp[64]
Definition cavsdata.c:57
int ff_cavs_next_mb(AVSContext *h)
save predictors for later macroblocks and increase macroblock address
Definition cavs.c:745
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
Definition cavs.c:246
static void set_mvds(int16_t(*mvd)[2], enum cavs_block size)
replicate one partition's mv_diff over the 8x8 blocks it covers
Definition cavs.h:333
cavs_mb
Definition cavs.h:70
@ B_FWD_16X16
Definition cavs.h:79
@ P_SKIP
Definition cavs.h:72
@ P_8X16
Definition cavs.h:75
@ I_8X8
Definition cavs.h:71
@ B_8X8
Definition cavs.h:82
@ P_16X8
Definition cavs.h:74
@ B_DIRECT
Definition cavs.h:78
@ B_SKIP
Definition cavs.h:77
@ B_BWD_16X16
Definition cavs.h:80
@ P_8X8
Definition cavs.h:76
@ P_16X16
Definition cavs.h:73
@ B_SYM_16X16
Definition cavs.h:81
cavs_intra_luma
Definition cavs.h:92
@ INTRA_L_DC_128
Definition cavs.h:100
@ INTRA_L_LP_TOP
Definition cavs.h:99
@ INTRA_L_LP_LEFT
Definition cavs.h:98
@ INTRA_L_DOWN_LEFT
Definition cavs.h:96
@ INTRA_L_LP
Definition cavs.h:95
@ INTRA_L_DOWN_RIGHT
Definition cavs.h:97
@ INTRA_L_HORIZ
Definition cavs.h:94
@ INTRA_L_VERT
Definition cavs.h:93
static void set_mvs(cavs_vector *mv, enum cavs_block size)
Definition cavs.h:317
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block)
Definition cavs.c:195
void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, enum cavs_mv_pred mode, enum cavs_block size, int ref)
Definition cavs.c:594
cavs_mv_loc
Definition cavs.h:129
@ MV_BWD_D3
Definition cavs.h:140
@ MV_FWD_C2
Definition cavs.h:133
@ MV_BWD_X1
Definition cavs.h:146
@ MV_FWD_X3
Definition cavs.h:139
@ MV_BWD_A1
Definition cavs.h:144
@ MV_FWD_A3
Definition cavs.h:137
@ MV_FWD_X1
Definition cavs.h:136
@ MV_BWD_B2
Definition cavs.h:141
@ MV_BWD_X3
Definition cavs.h:149
@ MV_BWD_B3
Definition cavs.h:142
@ MV_BWD_A3
Definition cavs.h:147
@ MV_FWD_X0
Definition cavs.h:135
@ MV_FWD_D3
Definition cavs.h:130
@ MV_BWD_X2
Definition cavs.h:148
@ MV_FWD_B2
Definition cavs.h:131
@ MV_FWD_B3
Definition cavs.h:132
@ MV_FWD_X2
Definition cavs.h:138
@ MV_FWD_A1
Definition cavs.h:134
@ MV_BWD_X0
Definition cavs.h:145
@ MV_BWD_C2
Definition cavs.h:143
#define MV_STRIDE
Definition cavs.h:68
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type)
Definition cavs.c:513
cavs_intra_chroma
Definition cavs.h:103
@ INTRA_C_PLANE
Definition cavs.h:107
@ INTRA_C_HORIZ
Definition cavs.h:105
@ INTRA_C_VERT
Definition cavs.h:106
@ INTRA_C_DC_128
Definition cavs.h:110
@ INTRA_C_LP_LEFT
Definition cavs.h:108
@ INTRA_C_LP
Definition cavs.h:104
@ INTRA_C_LP_TOP
Definition cavs.h:109
cavs_block
Definition cavs.h:122
@ BLK_16X8
Definition cavs.h:124
@ BLK_16X16
Definition cavs.h:123
@ BLK_8X8
Definition cavs.h:126
@ BLK_8X16
Definition cavs.h:125
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
Definition cavs.c:373
const uint8_t ff_cavs_partition_flags[30]
Definition cavsdata.c:24
int ff_cavs_init_top_lines(AVSContext *h)
some predictions require data from the top-neighbouring macroblock.
Definition cavs.c:829
int ff_cavs_init(AVCodecContext *avctx)
Definition cavs.c:870
int ff_cavs_end(AVCodecContext *avctx)
Definition cavs.c:918
void ff_cavs_init_mb(AVSContext *h)
initialise predictors for motion vectors and intra prediction
Definition cavs.c:699
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
in-loop deblocking filter for a single macroblock
Definition cavs.c:119
Chinese AVS video (AVS1-P16, Broadcasting profile) AEC decoder.
static int16_t block[64]
Definition dct.c:125
reference-counted frame API
bitstream reader API header.
static const int8_t mv[256][2]
Definition 4xm.c:81
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint16_t direct_den[512]
16384 / BlockDistanceRef of clause 9.9.1 b) 3), indexed by the co-located block's own distance,...
Definition cavs.h:287
int luma_scan[4]
Definition cavs.h:257
int loop_filter_disable
Definition cavs.h:221
int aec_enable
the macroblock layer uses AEC (AVS1-P16)
Definition cavs.h:211
int pic_data_end
a unit that is not a slice ended the picture's data
Definition cavs.h:227
unsigned int stc_offset_size
Definition cavs.h:302
int left_qp
Definition cavs.h:229
GetBitContext gb
Definition cavs.h:183
void(* intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
Definition cavs.h:277
uint8_t * col_type_base
Definition cavs.h:278
int alpha_offset
Definition cavs.h:222
int pic_structure
Definition cavs.h:204
VideoDSPContext vdsp
Definition cavs.h:181
int mby
Definition cavs.h:224
int pic_qp_fixed
Definition cavs.h:260
AVSFrame DPB[2]
reference frames
Definition cavs.h:185
int mbidx
macroblock coordinates
Definition cavs.h:224
int parity
first line of the reference field inside it
Definition cavs.h:192
uint8_t permutated_scantable[64]
Definition cavs.h:263
int16_t mvd[2 *4 *3][2]
mv_diff of the same blocks, for the ctxIdxInc of clause 8.4.4.2 g)
Definition cavs.h:246
ptrdiff_t c_stride
Definition cavs.h:256
uint8_t * cu
Definition cavs.h:228
int mb_height
Definition cavs.h:200
int qp_fixed
Definition cavs.h:259
uint8_t * cv
current MB sample pointers
Definition cavs.h:228
const uint8_t * scantable
the one of the two the current picture uses, selected in decode_pic()
Definition cavs.h:267
int b_field_enhanced
BFieldEnhanced of the picture, clause 9.9.1 b)
Definition cavs.h:206
uint8_t * top_qp
Definition cavs.h:230
AVSFrame cur
currently decoded frame
Definition cavs.h:184
int qp
Definition cavs.h:258
uint8_t topleft_border_y
Definition cavs.h:274
uint8_t left_border_y[26]
Definition cavs.h:272
int field_mby
macroblock row of the current macroblock in it
Definition cavs.h:209
int left_c_pred_mode
IntraChromaPredMode to the left, 8.4.4.2 e)
Definition cavs.h:219
int level
Definition cavs.h:198
AVCodecContext * avctx
Definition cavs.h:178
int16_t block[64]
Definition cavs.h:262
int stream_revision
0 for samples from 2006, 1 for rm52j encoder
Definition cavs.h:202
uint8_t permutated_scantable_field[64]
inverse block scan method 2 of clause 9.5.3 c), for field pictures
Definition cavs.h:265
uint8_t * top_border_u
Definition cavs.h:271
cavs_vector * top_mv[2]
Definition cavs.h:247
CAVSDSPContext cdsp
Definition cavs.h:182
int progressive
Definition cavs.h:203
int ref_flag
Definition cavs.h:223
int profile
Definition cavs.h:198
int ref_base[2]
first entry of the forward and the backward list
Definition cavs.h:194
int progressive_seq
Definition cavs.h:197
int top_field_first
first coded field is the top one, clause 7.2.3
Definition cavs.h:205
uint8_t * top_cbp
MbCBP of the macroblock above, one per column.
Definition cavs.h:216
uint8_t * top_c_pred_mode
IntraChromaPredMode above, per column.
Definition cavs.h:220
uint8_t * top_border_y
intra prediction is done with un-deblocked samples they are saved here before deblocking the MB
Definition cavs.h:271
uint8_t intern_border_y[26]
Definition cavs.h:273
int height
Definition cavs.h:201
int got_keyframe
Definition cavs.h:305
uint8_t * top_border_v
Definition cavs.h:271
CAVSAECContext aec
AEC decoder state and contexts, clause 8.4.
Definition cavs.h:213
void(* intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
Definition cavs.h:276
H264ChromaContext h264chroma
Definition cavs.h:180
int field
field of the current MB, 0 or 1, clause 3.24
Definition cavs.h:208
uint8_t * edge_emu_buffer
Definition cavs.h:289
uint8_t * top_mb_type
MbType above, one per column.
Definition cavs.h:218
int left_cbp
MbCBP of the macroblock to the left.
Definition cavs.h:215
int aspect_ratio
Definition cavs.h:199
int dist[4]
BlockDistance of every reference, clause 9.4.6.1.
Definition cavs.h:195
AVFrame * f
frame the reference belongs to
Definition cavs.h:191
BlockDSPContext bdsp
Definition cavs.h:179
uint8_t left_border_u[10]
Definition cavs.h:272
int * top_pred_Y
Definition cavs.h:255
uint8_t * cy
Definition cavs.h:228
uint32_t * stc_offset
byte offsets in deemulated_buf at which a start code prefix of the original payload begins
Definition cavs.h:301
int mbx
Definition cavs.h:224
int p_field_skip
PFieldSkip of the picture, clause 9.9.1 a)
Definition cavs.h:207
int low_delay
Definition cavs.h:196
int stc
last start code
Definition cavs.h:226
uint8_t left_border_v[10]
Definition cavs.h:272
ptrdiff_t l_stride
Definition cavs.h:256
int width
Definition cavs.h:201
uint8_t * deemulated_buf
picture payload with the annex A pseudo start codes removed, allocated only for the pictures that car...
Definition cavs.h:295
int aec_start
byte offset of the current AEC slice's payload
Definition cavs.h:212
int flags
availability flags of neighbouring macroblocks
Definition cavs.h:225
cavs_vector mv[2 *4 *3]
mv motion vector cache 0: D3 B2 B3 C2 4: A1 X0 X1 - 8: A3 X2 X3 -
Definition cavs.h:244
uint8_t topleft_border_v
Definition cavs.h:274
int beta_offset
Definition cavs.h:222
uint8_t topleft_border_u
Definition cavs.h:274
int left_mb_type
MbType to the left, clause 8.4.4.2 b)
Definition cavs.h:217
int pred_mode_Y[3 *3]
luma pred mode cache 0: – B2 B3 3: A1 X0 X1 6: A3 X2 X3
Definition cavs.h:254
int cbp
Definition cavs.h:261
int mb_width
Definition cavs.h:200
int nb_stc_offset
Definition cavs.h:303
unsigned int deemulated_buf_size
Definition cavs.h:296
int prev_delta_qp
PreviousDeltaQP of clause 9.4.8, an AEC context.
Definition cavs.h:214
cavs_vector * col_mv
Definition cavs.h:248
int skip_mode_flag
select between skip_count or one skip_flag per MB
Definition cavs.h:210
int scale_den[4]
512 / dist[], for scaling neighbouring MVs (clause 9.4.6.2 step 3)
Definition cavs.h:281
AVFrame * f
Definition cavs.h:173
int poc
Definition cavs.h:174
int16_t x
Definition cavs.h:153
int16_t y
Definition cavs.h:154
int16_t dist
Definition cavs.h:155
int16_t ref_idx
mb_reference_index of the block, 0 when it codes none (clause 9.4.5); ref above is where the referenc...
Definition cavs.h:161
int16_t ref
Definition cavs.h:156
int8_t level_add[27]
Definition cavs.h:166
int8_t golomb_order
Definition cavs.h:167
int inc_limit
Definition cavs.h:168
int8_t rltab[59][3]
Definition cavs.h:165
int8_t max_run
Definition cavs.h:169
Definition swscale.c:85
#define stride
static int ref[MAX_W *MAX_W]
int size
Core video DSP helper functions.