00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVCODEC_CAVS_H
00023 #define AVCODEC_CAVS_H
00024
00025 #include "dsputil.h"
00026 #include "mpegvideo.h"
00027
00028 #define SLICE_MAX_START_CODE 0x000001af
00029 #define EXT_START_CODE 0x000001b5
00030 #define USER_START_CODE 0x000001b2
00031 #define CAVS_START_CODE 0x000001b0
00032 #define PIC_I_START_CODE 0x000001b3
00033 #define PIC_PB_START_CODE 0x000001b6
00034
00035 #define A_AVAIL 1
00036 #define B_AVAIL 2
00037 #define C_AVAIL 4
00038 #define D_AVAIL 8
00039 #define NOT_AVAIL -1
00040 #define REF_INTRA -2
00041 #define REF_DIR -3
00042
00043 #define ESCAPE_CODE 59
00044
00045 #define FWD0 0x01
00046 #define FWD1 0x02
00047 #define BWD0 0x04
00048 #define BWD1 0x08
00049 #define SYM0 0x10
00050 #define SYM1 0x20
00051 #define SPLITH 0x40
00052 #define SPLITV 0x80
00053
00054 #define MV_BWD_OFFS 12
00055 #define MV_STRIDE 4
00056
00057 enum cavs_mb {
00058 I_8X8 = 0,
00059 P_SKIP,
00060 P_16X16,
00061 P_16X8,
00062 P_8X16,
00063 P_8X8,
00064 B_SKIP,
00065 B_DIRECT,
00066 B_FWD_16X16,
00067 B_BWD_16X16,
00068 B_SYM_16X16,
00069 B_8X8 = 29
00070 };
00071
00072 enum cavs_sub_mb {
00073 B_SUB_DIRECT,
00074 B_SUB_FWD,
00075 B_SUB_BWD,
00076 B_SUB_SYM
00077 };
00078
00079 enum cavs_intra_luma {
00080 INTRA_L_VERT,
00081 INTRA_L_HORIZ,
00082 INTRA_L_LP,
00083 INTRA_L_DOWN_LEFT,
00084 INTRA_L_DOWN_RIGHT,
00085 INTRA_L_LP_LEFT,
00086 INTRA_L_LP_TOP,
00087 INTRA_L_DC_128
00088 };
00089
00090 enum cavs_intra_chroma {
00091 INTRA_C_LP,
00092 INTRA_C_HORIZ,
00093 INTRA_C_VERT,
00094 INTRA_C_PLANE,
00095 INTRA_C_LP_LEFT,
00096 INTRA_C_LP_TOP,
00097 INTRA_C_DC_128,
00098 };
00099
00100 enum cavs_mv_pred {
00101 MV_PRED_MEDIAN,
00102 MV_PRED_LEFT,
00103 MV_PRED_TOP,
00104 MV_PRED_TOPRIGHT,
00105 MV_PRED_PSKIP,
00106 MV_PRED_BSKIP
00107 };
00108
00109 enum cavs_block {
00110 BLK_16X16,
00111 BLK_16X8,
00112 BLK_8X16,
00113 BLK_8X8
00114 };
00115
00116 enum cavs_mv_loc {
00117 MV_FWD_D3 = 0,
00118 MV_FWD_B2,
00119 MV_FWD_B3,
00120 MV_FWD_C2,
00121 MV_FWD_A1,
00122 MV_FWD_X0,
00123 MV_FWD_X1,
00124 MV_FWD_A3 = 8,
00125 MV_FWD_X2,
00126 MV_FWD_X3,
00127 MV_BWD_D3 = MV_BWD_OFFS,
00128 MV_BWD_B2,
00129 MV_BWD_B3,
00130 MV_BWD_C2,
00131 MV_BWD_A1,
00132 MV_BWD_X0,
00133 MV_BWD_X1,
00134 MV_BWD_A3 = MV_BWD_OFFS+8,
00135 MV_BWD_X2,
00136 MV_BWD_X3
00137 };
00138
00139 DECLARE_ALIGNED_8(typedef, struct) {
00140 int16_t x;
00141 int16_t y;
00142 int16_t dist;
00143 int16_t ref;
00144 } cavs_vector;
00145
00146 struct dec_2dvlc {
00147 int8_t rltab[59][3];
00148 int8_t level_add[27];
00149 int8_t golomb_order;
00150 int inc_limit;
00151 int8_t max_run;
00152 };
00153
00154 typedef struct {
00155 MpegEncContext s;
00156 Picture picture;
00157 Picture DPB[2];
00158 int dist[2];
00159 int profile, level;
00160 int aspect_ratio;
00161 int mb_width, mb_height;
00162 int pic_type;
00163 int progressive;
00164 int pic_structure;
00165 int skip_mode_flag;
00166 int loop_filter_disable;
00167 int alpha_offset, beta_offset;
00168 int ref_flag;
00169 int mbx, mby, mbidx;
00170 int flags;
00171 int stc;
00172 uint8_t *cy, *cu, *cv;
00173 int left_qp;
00174 uint8_t *top_qp;
00175
00188 cavs_vector mv[2*4*3];
00189 cavs_vector *top_mv[2];
00190 cavs_vector *col_mv;
00191
00196 int pred_mode_Y[3*3];
00197 int *top_pred_Y;
00198 int l_stride, c_stride;
00199 int luma_scan[4];
00200 int qp;
00201 int qp_fixed;
00202 int cbp;
00203 ScanTable scantable;
00204
00207 uint8_t *top_border_y, *top_border_u, *top_border_v;
00208 uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
00209 uint8_t intern_border_y[26];
00210 uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
00211
00212 void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
00213 void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
00214 uint8_t *col_type_base;
00215
00216
00217 int sym_factor;
00218 int direct_den[2];
00219 int scale_den[2];
00220
00221 int got_keyframe;
00222 DCTELEM *block;
00223 } AVSContext;
00224
00225 extern const uint8_t ff_cavs_dequant_shift[64];
00226 extern const uint16_t ff_cavs_dequant_mul[64];
00227 extern const struct dec_2dvlc ff_cavs_intra_dec[7];
00228 extern const struct dec_2dvlc ff_cavs_inter_dec[7];
00229 extern const struct dec_2dvlc ff_cavs_chroma_dec[5];
00230 extern const uint8_t ff_cavs_chroma_qp[64];
00231 extern const uint8_t ff_cavs_scan3x3[4];
00232 extern const uint8_t ff_cavs_partition_flags[30];
00233 extern const int_fast8_t ff_left_modifier_l[8];
00234 extern const int_fast8_t ff_top_modifier_l[8];
00235 extern const int_fast8_t ff_left_modifier_c[7];
00236 extern const int_fast8_t ff_top_modifier_c[7];
00237 extern const cavs_vector ff_cavs_intra_mv;
00238 extern const cavs_vector ff_cavs_un_mv;
00239 extern const cavs_vector ff_cavs_dir_mv;
00240
00241 static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
00242 *mode = mod_table[*mode];
00243 if(*mode < 0) {
00244 av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
00245 *mode = 0;
00246 }
00247 }
00248
00249 static inline void set_intra_mode_default(AVSContext *h) {
00250 h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
00251 h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
00252 }
00253
00254 static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
00255 switch(size) {
00256 case BLK_16X16:
00257 mv[MV_STRIDE ] = mv[0];
00258 mv[MV_STRIDE+1] = mv[0];
00259 case BLK_16X8:
00260 mv[1] = mv[0];
00261 break;
00262 case BLK_8X16:
00263 mv[MV_STRIDE] = mv[0];
00264 break;
00265 }
00266 }
00267
00268 static inline void set_mv_intra(AVSContext *h) {
00269 h->mv[MV_FWD_X0] = ff_cavs_intra_mv;
00270 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
00271 h->mv[MV_BWD_X0] = ff_cavs_intra_mv;
00272 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
00273 if(h->pic_type != FF_B_TYPE)
00274 h->col_type_base[h->mbidx] = I_8X8;
00275 }
00276
00277 static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
00278 DCTELEM *dst, int mul, int shift, int coeff_num) {
00279 int round = 1 << (shift - 1);
00280 int pos = -1;
00281 const uint8_t *scantab = h->scantable.permutated;
00282
00283
00284 while(--coeff_num >= 0){
00285 pos += run_buf[coeff_num];
00286 if(pos > 63) {
00287 av_log(h->s.avctx, AV_LOG_ERROR,
00288 "position out of block bounds at pic %d MB(%d,%d)\n",
00289 h->picture.poc, h->mbx, h->mby);
00290 return -1;
00291 }
00292 dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift;
00293 }
00294 return 0;
00295 }
00296
00297 void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
00298 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
00299 int block);
00300 void ff_cavs_load_intra_pred_chroma(AVSContext *h);
00301 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
00302 void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
00303 void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
00304 enum cavs_mv_pred mode, enum cavs_block size, int ref);
00305 void ff_cavs_init_mb(AVSContext *h);
00306 int ff_cavs_next_mb(AVSContext *h);
00307 void ff_cavs_init_pic(AVSContext *h);
00308 void ff_cavs_init_top_lines(AVSContext *h);
00309 int ff_cavs_init(AVCodecContext *avctx);
00310 int ff_cavs_end (AVCodecContext *avctx);
00311
00312 #endif