• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • 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 Libav.
00006  *
00007  * Libav 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  * Libav 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 Libav; 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 #include "cavsdsp.h"
00028 
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 cavs_mb {
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 cavs_sub_mb {
00074   B_SUB_DIRECT,
00075   B_SUB_FWD,
00076   B_SUB_BWD,
00077   B_SUB_SYM
00078 };
00079 
00080 enum cavs_intra_luma {
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 cavs_intra_chroma {
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 cavs_mv_pred {
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 cavs_block {
00111   BLK_16X16,
00112   BLK_16X8,
00113   BLK_8X16,
00114   BLK_8X8
00115 };
00116 
00117 enum cavs_mv_loc {
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 } cavs_vector;
00146 
00147 struct dec_2dvlc {
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 };
00154 
00155 typedef struct {
00156     MpegEncContext s;
00157     CAVSDSPContext cdsp;
00158     Picture picture; 
00159     Picture DPB[2];  
00160     int dist[2];     
00161     int profile, level;
00162     int aspect_ratio;
00163     int mb_width, mb_height;
00164     int pic_type;
00165     int stream_revision; 
00166     int progressive;
00167     int pic_structure;
00168     int skip_mode_flag; 
00169     int loop_filter_disable;
00170     int alpha_offset, beta_offset;
00171     int ref_flag;
00172     int mbx, mby, mbidx; 
00173     int flags;         
00174     int stc;           
00175     uint8_t *cy, *cu, *cv; 
00176     int left_qp;
00177     uint8_t *top_qp;
00178 
00191     cavs_vector mv[2*4*3];
00192     cavs_vector *top_mv[2];
00193     cavs_vector *col_mv;
00194 
00199     int pred_mode_Y[3*3];
00200     int *top_pred_Y;
00201     int l_stride, c_stride;
00202     int luma_scan[4];
00203     int qp;
00204     int qp_fixed;
00205     int cbp;
00206     ScanTable scantable;
00207 
00210     uint8_t *top_border_y, *top_border_u, *top_border_v;
00211     uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
00212     uint8_t intern_border_y[26];
00213     uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
00214 
00215     void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
00216     void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
00217     uint8_t *col_type_base;
00218 
00219     /* scaling factors for MV prediction */
00220     int sym_factor;    
00221     int direct_den[2]; 
00222     int scale_den[2];  
00223 
00224     int got_keyframe;
00225     DCTELEM *block;
00226 } AVSContext;
00227 
00228 extern const uint8_t     ff_cavs_dequant_shift[64];
00229 extern const uint16_t    ff_cavs_dequant_mul[64];
00230 extern const struct dec_2dvlc ff_cavs_intra_dec[7];
00231 extern const struct dec_2dvlc ff_cavs_inter_dec[7];
00232 extern const struct dec_2dvlc ff_cavs_chroma_dec[5];
00233 extern const uint8_t     ff_cavs_chroma_qp[64];
00234 extern const uint8_t     ff_cavs_scan3x3[4];
00235 extern const uint8_t     ff_cavs_partition_flags[30];
00236 extern const int8_t      ff_left_modifier_l[8];
00237 extern const int8_t      ff_top_modifier_l[8];
00238 extern const int8_t      ff_left_modifier_c[7];
00239 extern const int8_t      ff_top_modifier_c[7];
00240 extern const cavs_vector ff_cavs_intra_mv;
00241 extern const cavs_vector ff_cavs_un_mv;
00242 extern const cavs_vector ff_cavs_dir_mv;
00243 
00244 static inline void modify_pred(const int8_t *mod_table, int *mode)
00245 {
00246     *mode = mod_table[*mode];
00247     if(*mode < 0) {
00248         av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
00249         *mode = 0;
00250     }
00251 }
00252 
00253 static inline void set_intra_mode_default(AVSContext *h) {
00254     if(h->stream_revision > 0) {
00255         h->pred_mode_Y[3] =  h->pred_mode_Y[6] = NOT_AVAIL;
00256         h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = NOT_AVAIL;
00257     } else {
00258         h->pred_mode_Y[3] =  h->pred_mode_Y[6] = INTRA_L_LP;
00259         h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
00260     }
00261 }
00262 
00263 static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
00264     switch(size) {
00265     case BLK_16X16:
00266         mv[MV_STRIDE  ] = mv[0];
00267         mv[MV_STRIDE+1] = mv[0];
00268     case BLK_16X8:
00269         mv[1] = mv[0];
00270         break;
00271     case BLK_8X16:
00272         mv[MV_STRIDE] = mv[0];
00273         break;
00274     }
00275 }
00276 
00277 static inline void set_mv_intra(AVSContext *h) {
00278     h->mv[MV_FWD_X0] = ff_cavs_intra_mv;
00279     set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
00280     h->mv[MV_BWD_X0] = ff_cavs_intra_mv;
00281     set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
00282     if(h->pic_type != AV_PICTURE_TYPE_B)
00283         h->col_type_base[h->mbidx] = I_8X8;
00284 }
00285 
00286 static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
00287                           DCTELEM *dst, int mul, int shift, int coeff_num) {
00288     int round = 1 << (shift - 1);
00289     int pos = -1;
00290     const uint8_t *scantab = h->scantable.permutated;
00291 
00292     /* inverse scan and dequantization */
00293     while(--coeff_num >= 0){
00294         pos += run_buf[coeff_num];
00295         if(pos > 63) {
00296             av_log(h->s.avctx, AV_LOG_ERROR,
00297                 "position out of block bounds at pic %d MB(%d,%d)\n",
00298                 h->picture.poc, h->mbx, h->mby);
00299             return -1;
00300         }
00301         dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift;
00302     }
00303     return 0;
00304 }
00305 
00306 void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
00307 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
00308                                   int block);
00309 void ff_cavs_load_intra_pred_chroma(AVSContext *h);
00310 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
00311 void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
00312 void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
00313                 enum cavs_mv_pred mode, enum cavs_block size, int ref);
00314 void ff_cavs_init_mb(AVSContext *h);
00315 int  ff_cavs_next_mb(AVSContext *h);
00316 void ff_cavs_init_pic(AVSContext *h);
00317 void ff_cavs_init_top_lines(AVSContext *h);
00318 int ff_cavs_init(AVCodecContext *avctx);
00319 int ff_cavs_end (AVCodecContext *avctx);
00320 
00321 #endif /* AVCODEC_CAVS_H */
Generated on Thu Jul 11 2013 15:38:18 for Libav by doxygen 1.7.1