• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/cavs.h

Go to the documentation of this file.
00001 /*
00002  * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
00003  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 stream_revision; 
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, mbidx; 
00171     int flags;         
00172     int stc;           
00173     uint8_t *cy, *cu, *cv; 
00174     int left_qp;
00175     uint8_t *top_qp;
00176 
00189     cavs_vector mv[2*4*3];
00190     cavs_vector *top_mv[2];
00191     cavs_vector *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 
00217     /* scaling factors for MV prediction */
00218     int sym_factor;    
00219     int direct_den[2]; 
00220     int scale_den[2];  
00221 
00222     int got_keyframe;
00223     DCTELEM *block;
00224 } AVSContext;
00225 
00226 extern const uint8_t     ff_cavs_dequant_shift[64];
00227 extern const uint16_t    ff_cavs_dequant_mul[64];
00228 extern const struct dec_2dvlc ff_cavs_intra_dec[7];
00229 extern const struct dec_2dvlc ff_cavs_inter_dec[7];
00230 extern const struct dec_2dvlc ff_cavs_chroma_dec[5];
00231 extern const uint8_t     ff_cavs_chroma_qp[64];
00232 extern const uint8_t     ff_cavs_scan3x3[4];
00233 extern const uint8_t     ff_cavs_partition_flags[30];
00234 extern const int_fast8_t ff_left_modifier_l[8];
00235 extern const int_fast8_t ff_top_modifier_l[8];
00236 extern const int_fast8_t ff_left_modifier_c[7];
00237 extern const int_fast8_t ff_top_modifier_c[7];
00238 extern const cavs_vector ff_cavs_intra_mv;
00239 extern const cavs_vector ff_cavs_un_mv;
00240 extern const cavs_vector ff_cavs_dir_mv;
00241 
00242 static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
00243     *mode = mod_table[*mode];
00244     if(*mode < 0) {
00245         av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
00246         *mode = 0;
00247     }
00248 }
00249 
00250 static inline void set_intra_mode_default(AVSContext *h) {
00251     if(h->stream_revision > 0) {
00252         h->pred_mode_Y[3] =  h->pred_mode_Y[6] = NOT_AVAIL;
00253         h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = NOT_AVAIL;
00254     } else {
00255         h->pred_mode_Y[3] =  h->pred_mode_Y[6] = INTRA_L_LP;
00256         h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
00257     }
00258 }
00259 
00260 static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
00261     switch(size) {
00262     case BLK_16X16:
00263         mv[MV_STRIDE  ] = mv[0];
00264         mv[MV_STRIDE+1] = mv[0];
00265     case BLK_16X8:
00266         mv[1] = mv[0];
00267         break;
00268     case BLK_8X16:
00269         mv[MV_STRIDE] = mv[0];
00270         break;
00271     }
00272 }
00273 
00274 static inline void set_mv_intra(AVSContext *h) {
00275     h->mv[MV_FWD_X0] = ff_cavs_intra_mv;
00276     set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
00277     h->mv[MV_BWD_X0] = ff_cavs_intra_mv;
00278     set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
00279     if(h->pic_type != FF_B_TYPE)
00280         h->col_type_base[h->mbidx] = I_8X8;
00281 }
00282 
00283 static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
00284                           DCTELEM *dst, int mul, int shift, int coeff_num) {
00285     int round = 1 << (shift - 1);
00286     int pos = -1;
00287     const uint8_t *scantab = h->scantable.permutated;
00288 
00289     /* inverse scan and dequantization */
00290     while(--coeff_num >= 0){
00291         pos += run_buf[coeff_num];
00292         if(pos > 63) {
00293             av_log(h->s.avctx, AV_LOG_ERROR,
00294                 "position out of block bounds at pic %d MB(%d,%d)\n",
00295                 h->picture.poc, h->mbx, h->mby);
00296             return -1;
00297         }
00298         dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift;
00299     }
00300     return 0;
00301 }
00302 
00303 void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
00304 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
00305                                   int block);
00306 void ff_cavs_load_intra_pred_chroma(AVSContext *h);
00307 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
00308 void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
00309 void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
00310                 enum cavs_mv_pred mode, enum cavs_block size, int ref);
00311 void ff_cavs_init_mb(AVSContext *h);
00312 int  ff_cavs_next_mb(AVSContext *h);
00313 void ff_cavs_init_pic(AVSContext *h);
00314 void ff_cavs_init_top_lines(AVSContext *h);
00315 int ff_cavs_init(AVCodecContext *avctx);
00316 int ff_cavs_end (AVCodecContext *avctx);
00317 
00318 #endif /* AVCODEC_CAVS_H */

Generated on Fri Sep 16 2011 17:17:34 for FFmpeg by  doxygen 1.7.1