FFmpeg
Loading...
Searching...
No Matches
cavs.h
Go to the documentation of this file.
1/*
2 * Chinese AVS video (AVS1-P2, JiZhun profile) 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
29#include "libavutil/frame.h"
31
32#include "avcodec.h"
33#include "cavsdsp.h"
34#include "blockdsp.h"
35#include "h264chroma.h"
36#include "get_bits.h"
37#include "videodsp.h"
38
39#define SLICE_MAX_START_CODE 0x000001af
40#define EXT_START_CODE 0x000001b5
41#define USER_START_CODE 0x000001b2
42#define CAVS_START_CODE 0x000001b0
43#define PIC_I_START_CODE 0x000001b3
44#define PIC_PB_START_CODE 0x000001b6
45
46#define A_AVAIL 1
47#define B_AVAIL 2
48#define C_AVAIL 4
49#define D_AVAIL 8
50#define NOT_AVAIL -1
51#define REF_INTRA -2
52#define REF_DIR -3
53
54#define ESCAPE_CODE 59
55
56#define FWD0 0x01
57#define FWD1 0x02
58#define BWD0 0x04
59#define BWD1 0x08
60#define SYM0 0x10
61#define SYM1 0x20
62#define SPLITH 0x40
63#define SPLITV 0x80
64
65#define MV_BWD_OFFS 12
66#define MV_STRIDE 4
67
82
89
100
110
119
126
149
150typedef struct cavs_vector {
151 int16_t x;
152 int16_t y;
153 int16_t dist;
154 int16_t ref;
156
157struct dec_2dvlc {
158 int8_t rltab[59][3];
159 int8_t level_add[27];
162 int8_t max_run;
163};
164
165typedef struct AVSFrame {
167 int poc;
168} AVSFrame;
169
170typedef struct AVSContext {
177 AVSFrame cur; ///< currently decoded frame
178 AVSFrame DPB[2]; ///< reference frames
179 int dist[2]; ///< temporal distances from current frame to ref frames
185 int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
188 int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
192 int mbx, mby, mbidx; ///< macroblock coordinates
193 int flags; ///< availability flags of neighbouring macroblocks
194 int stc; ///< last start code
195 uint8_t *cy, *cu, *cv; ///< current MB sample pointers
197 uint8_t *top_qp;
198
199 /** mv motion vector cache
200 0: D3 B2 B3 C2
201 4: A1 X0 X1 -
202 8: A3 X2 X3 -
203
204 X are the vectors in the current macroblock (5,6,9,10)
205 A is the macroblock to the left (4,8)
206 B is the macroblock to the top (1,2)
207 C is the macroblock to the top-right (3)
208 D is the macroblock to the top-left (0)
209
210 the same is repeated for backward motion vectors */
214
215 /** luma pred mode cache
216 0: -- B2 B3
217 3: A1 X0 X1
218 6: A3 X2 X3 */
219 int pred_mode_Y[3*3];
221 ptrdiff_t l_stride, c_stride;
222 int luma_scan[4];
223 int qp;
226 int cbp;
227 DECLARE_ALIGNED(32, int16_t, block)[64];
229
230 /** intra prediction is done with un-deblocked samples
231 they are saved here before deblocking the MB */
234 uint8_t intern_border_y[26];
236
237 void (*intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
238 void (*intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
240
241 /* scaling factors for MV prediction */
242 int sym_factor; ///< for scaling in symmetrical B block
243 int direct_den[2]; ///< for scaling in direct B block
244 int scale_den[2]; ///< for scaling neighbouring MVs
245
247
249} AVSContext;
250
251extern const uint8_t ff_cavs_chroma_qp[64];
252extern const uint8_t ff_cavs_partition_flags[30];
253
254/** mark block as using intra prediction */
255#define CAVS_DIR_MV (cavs_vector){ 0, 0, 1, REF_DIR }
256/** mark block as "no prediction from this direction"
257 e.g. forward motion vector in BWD partition */
258#define CAVS_INTRA_MV (cavs_vector){ 0, 0, 1, REF_INTRA }
259
260static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
261 switch(size) {
262 case BLK_16X16:
263 mv[MV_STRIDE ] = mv[0];
264 mv[MV_STRIDE+1] = mv[0];
266 case BLK_16X8:
267 mv[1] = mv[0];
268 break;
269 case BLK_8X16:
270 mv[MV_STRIDE] = mv[0];
271 break;
272 }
273}
274
275void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
276void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
277 int block);
279void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
280void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
281void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
282 enum cavs_mv_pred mode, enum cavs_block size, int ref);
287int ff_cavs_init(AVCodecContext *avctx);
288int ff_cavs_end (AVCodecContext *avctx);
289
290#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:65
int ff_cavs_init_pic(AVSContext *h)
Definition cavs.c:722
cavs_sub_mb
Definition cavs.h:83
@ B_SUB_SYM
Definition cavs.h:87
@ B_SUB_DIRECT
Definition cavs.h:84
@ B_SUB_FWD
Definition cavs.h:85
@ B_SUB_BWD
Definition cavs.h:86
cavs_mv_pred
Definition cavs.h:111
@ MV_PRED_MEDIAN
Definition cavs.h:112
@ MV_PRED_TOP
Definition cavs.h:114
@ MV_PRED_BSKIP
Definition cavs.h:117
@ MV_PRED_PSKIP
Definition cavs.h:116
@ MV_PRED_LEFT
Definition cavs.h:113
@ MV_PRED_TOPRIGHT
Definition cavs.h:115
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:677
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
Definition cavs.c:235
cavs_mb
Definition cavs.h:68
@ B_FWD_16X16
Definition cavs.h:77
@ P_SKIP
Definition cavs.h:70
@ P_8X16
Definition cavs.h:73
@ I_8X8
Definition cavs.h:69
@ B_8X8
Definition cavs.h:80
@ P_16X8
Definition cavs.h:72
@ B_DIRECT
Definition cavs.h:76
@ B_SKIP
Definition cavs.h:75
@ B_BWD_16X16
Definition cavs.h:78
@ P_8X8
Definition cavs.h:74
@ P_16X16
Definition cavs.h:71
@ B_SYM_16X16
Definition cavs.h:79
cavs_intra_luma
Definition cavs.h:90
@ INTRA_L_DC_128
Definition cavs.h:98
@ INTRA_L_LP_TOP
Definition cavs.h:97
@ INTRA_L_LP_LEFT
Definition cavs.h:96
@ INTRA_L_DOWN_LEFT
Definition cavs.h:94
@ INTRA_L_LP
Definition cavs.h:93
@ INTRA_L_DOWN_RIGHT
Definition cavs.h:95
@ INTRA_L_HORIZ
Definition cavs.h:92
@ INTRA_L_VERT
Definition cavs.h:91
static void set_mvs(cavs_vector *mv, enum cavs_block size)
Definition cavs.h:260
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block)
Definition cavs.c:184
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:574
cavs_mv_loc
Definition cavs.h:127
@ MV_BWD_D3
Definition cavs.h:138
@ MV_FWD_C2
Definition cavs.h:131
@ MV_BWD_X1
Definition cavs.h:144
@ MV_FWD_X3
Definition cavs.h:137
@ MV_BWD_A1
Definition cavs.h:142
@ MV_FWD_A3
Definition cavs.h:135
@ MV_FWD_X1
Definition cavs.h:134
@ MV_BWD_B2
Definition cavs.h:139
@ MV_BWD_X3
Definition cavs.h:147
@ MV_BWD_B3
Definition cavs.h:140
@ MV_BWD_A3
Definition cavs.h:145
@ MV_FWD_X0
Definition cavs.h:133
@ MV_FWD_D3
Definition cavs.h:128
@ MV_BWD_X2
Definition cavs.h:146
@ MV_FWD_B2
Definition cavs.h:129
@ MV_FWD_B3
Definition cavs.h:130
@ MV_FWD_X2
Definition cavs.h:136
@ MV_FWD_A1
Definition cavs.h:132
@ MV_BWD_X0
Definition cavs.h:143
@ MV_BWD_C2
Definition cavs.h:141
#define MV_STRIDE
Definition cavs.h:66
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type)
Definition cavs.c:493
cavs_intra_chroma
Definition cavs.h:101
@ INTRA_C_PLANE
Definition cavs.h:105
@ INTRA_C_HORIZ
Definition cavs.h:103
@ INTRA_C_VERT
Definition cavs.h:104
@ INTRA_C_DC_128
Definition cavs.h:108
@ INTRA_C_LP_LEFT
Definition cavs.h:106
@ INTRA_C_LP
Definition cavs.h:102
@ INTRA_C_LP_TOP
Definition cavs.h:107
cavs_block
Definition cavs.h:120
@ BLK_16X8
Definition cavs.h:122
@ BLK_16X16
Definition cavs.h:121
@ BLK_8X8
Definition cavs.h:124
@ BLK_8X16
Definition cavs.h:123
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
Definition cavs.c:362
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:758
int ff_cavs_init(AVCodecContext *avctx)
Definition cavs.c:791
int ff_cavs_end(AVCodecContext *avctx)
Definition cavs.c:834
void ff_cavs_init_mb(AVSContext *h)
initialise predictors for motion vectors and intra prediction
Definition cavs.c:636
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
in-loop deblocking filter for a single macroblock
Definition cavs.c:108
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:472
int luma_scan[4]
Definition cavs.h:222
int loop_filter_disable
Definition cavs.h:189
int left_qp
Definition cavs.h:196
GetBitContext gb
Definition cavs.h:176
void(* intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
Definition cavs.h:238
uint8_t * col_type_base
Definition cavs.h:239
int alpha_offset
Definition cavs.h:190
int pic_structure
Definition cavs.h:187
VideoDSPContext vdsp
Definition cavs.h:174
int mby
Definition cavs.h:192
int pic_qp_fixed
Definition cavs.h:225
AVSFrame DPB[2]
reference frames
Definition cavs.h:178
int scale_den[2]
for scaling neighbouring MVs
Definition cavs.h:244
int mbidx
macroblock coordinates
Definition cavs.h:192
int sym_factor
for scaling in symmetrical B block
Definition cavs.h:242
uint8_t permutated_scantable[64]
Definition cavs.h:228
ptrdiff_t c_stride
Definition cavs.h:221
uint8_t * cu
Definition cavs.h:195
int mb_height
Definition cavs.h:183
int qp_fixed
Definition cavs.h:224
uint8_t * cv
current MB sample pointers
Definition cavs.h:195
int direct_den[2]
for scaling in direct B block
Definition cavs.h:243
uint8_t * top_qp
Definition cavs.h:197
AVSFrame cur
currently decoded frame
Definition cavs.h:177
int qp
Definition cavs.h:223
uint8_t topleft_border_y
Definition cavs.h:235
uint8_t left_border_y[26]
Definition cavs.h:233
int level
Definition cavs.h:181
AVCodecContext * avctx
Definition cavs.h:171
int16_t block[64]
Definition cavs.h:227
int stream_revision
0 for samples from 2006, 1 for rm52j encoder
Definition cavs.h:185
uint8_t * top_border_u
Definition cavs.h:232
cavs_vector * top_mv[2]
Definition cavs.h:212
CAVSDSPContext cdsp
Definition cavs.h:175
int progressive
Definition cavs.h:186
int ref_flag
Definition cavs.h:191
int profile
Definition cavs.h:181
uint8_t * top_border_y
intra prediction is done with un-deblocked samples they are saved here before deblocking the MB
Definition cavs.h:232
uint8_t intern_border_y[26]
Definition cavs.h:234
int height
Definition cavs.h:184
int got_keyframe
Definition cavs.h:248
uint8_t * top_border_v
Definition cavs.h:232
void(* intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
Definition cavs.h:237
H264ChromaContext h264chroma
Definition cavs.h:173
uint8_t * edge_emu_buffer
Definition cavs.h:246
int aspect_ratio
Definition cavs.h:182
BlockDSPContext bdsp
Definition cavs.h:172
uint8_t left_border_u[10]
Definition cavs.h:233
int * top_pred_Y
Definition cavs.h:220
uint8_t * cy
Definition cavs.h:195
int mbx
Definition cavs.h:192
int low_delay
Definition cavs.h:180
int stc
last start code
Definition cavs.h:194
uint8_t left_border_v[10]
Definition cavs.h:233
ptrdiff_t l_stride
Definition cavs.h:221
int width
Definition cavs.h:184
int flags
availability flags of neighbouring macroblocks
Definition cavs.h:193
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:211
uint8_t topleft_border_v
Definition cavs.h:235
int beta_offset
Definition cavs.h:190
int dist[2]
temporal distances from current frame to ref frames
Definition cavs.h:179
uint8_t topleft_border_u
Definition cavs.h:235
int pred_mode_Y[3 *3]
luma pred mode cache 0: – B2 B3 3: A1 X0 X1 6: A3 X2 X3
Definition cavs.h:219
int cbp
Definition cavs.h:226
int mb_width
Definition cavs.h:183
cavs_vector * col_mv
Definition cavs.h:213
int skip_mode_flag
select between skip_count or one skip_flag per MB
Definition cavs.h:188
AVFrame * f
Definition cavs.h:166
int poc
Definition cavs.h:167
int16_t x
Definition cavs.h:151
int16_t y
Definition cavs.h:152
int16_t dist
Definition cavs.h:153
int16_t ref
Definition cavs.h:154
int8_t level_add[27]
Definition cavs.h:159
int8_t golomb_order
Definition cavs.h:160
int inc_limit
Definition cavs.h:161
int8_t rltab[59][3]
Definition cavs.h:158
int8_t max_run
Definition cavs.h:162
Definition swscale.c:71
#define stride
static int ref[MAX_W *MAX_W]
int size
Core video DSP helper functions.