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