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

libavcodec/vp56.h

Go to the documentation of this file.
00001 
00024 #ifndef AVCODEC_VP56_H
00025 #define AVCODEC_VP56_H
00026 
00027 #include "vp56data.h"
00028 #include "dsputil.h"
00029 #include "get_bits.h"
00030 #include "bytestream.h"
00031 #include "cabac.h"
00032 #include "vp56dsp.h"
00033 
00034 typedef struct vp56_context VP56Context;
00035 
00036 typedef struct {
00037     int16_t x;
00038     int16_t y;
00039 } DECLARE_ALIGNED(4, , VP56mv);
00040 
00041 #define VP56_SIZE_CHANGE 1
00042 
00043 typedef void (*VP56ParseVectorAdjustment)(VP56Context *s,
00044                                           VP56mv *vect);
00045 typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src,
00046                            int offset1, int offset2, int stride,
00047                            VP56mv mv, int mask, int select, int luma);
00048 typedef void (*VP56ParseCoeff)(VP56Context *s);
00049 typedef void (*VP56DefaultModelsInit)(VP56Context *s);
00050 typedef void (*VP56ParseVectorModels)(VP56Context *s);
00051 typedef int  (*VP56ParseCoeffModels)(VP56Context *s);
00052 typedef int  (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
00053                                 int buf_size, int *golden_frame);
00054 
00055 typedef struct {
00056     int high;
00057     int bits; /* stored negated (i.e. negative "bits" is a positive number of
00058                  bits left) in order to eliminate a negate in cache refilling */
00059     const uint8_t *buffer;
00060     const uint8_t *end;
00061     unsigned int code_word;
00062 } VP56RangeCoder;
00063 
00064 typedef struct {
00065     uint8_t not_null_dc;
00066     VP56Frame ref_frame;
00067     DCTELEM dc_coeff;
00068 } VP56RefDc;
00069 
00070 typedef struct {
00071     uint8_t type;
00072     VP56mv mv;
00073 } VP56Macroblock;
00074 
00075 typedef struct {
00076     uint8_t coeff_reorder[64];       /* used in vp6 only */
00077     uint8_t coeff_index_to_pos[64];  /* used in vp6 only */
00078     uint8_t vector_sig[2];           /* delta sign */
00079     uint8_t vector_dct[2];           /* delta coding types */
00080     uint8_t vector_pdi[2][2];        /* predefined delta init */
00081     uint8_t vector_pdv[2][7];        /* predefined delta values */
00082     uint8_t vector_fdv[2][8];        /* 8 bit delta value definition */
00083     uint8_t coeff_dccv[2][11];       /* DC coeff value */
00084     uint8_t coeff_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
00085     uint8_t coeff_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
00086     uint8_t coeff_dcct[2][36][5];    /* DC coeff coding type */
00087     uint8_t coeff_runv[2][14];       /* run value (vp6 only) */
00088     uint8_t mb_type[3][10][10];      /* model for decoding MB type */
00089     uint8_t mb_types_stats[3][10][2];/* contextual, next MB type stats */
00090 } VP56Model;
00091 
00092 struct vp56_context {
00093     AVCodecContext *avctx;
00094     DSPContext dsp;
00095     VP56DSPContext vp56dsp;
00096     ScanTable scantable;
00097     AVFrame frames[4];
00098     AVFrame *framep[6];
00099     uint8_t *edge_emu_buffer_alloc;
00100     uint8_t *edge_emu_buffer;
00101     VP56RangeCoder c;
00102     VP56RangeCoder cc;
00103     VP56RangeCoder *ccp;
00104     int sub_version;
00105 
00106     /* frame info */
00107     int plane_width[4];
00108     int plane_height[4];
00109     int mb_width;   /* number of horizontal MB */
00110     int mb_height;  /* number of vertical MB */
00111     int block_offset[6];
00112 
00113     int quantizer;
00114     uint16_t dequant_dc;
00115     uint16_t dequant_ac;
00116     int8_t *qscale_table;
00117 
00118     /* DC predictors management */
00119     VP56RefDc *above_blocks;
00120     VP56RefDc left_block[4];
00121     int above_block_idx[6];
00122     DCTELEM prev_dc[3][3];    /* [plan][ref_frame] */
00123 
00124     /* blocks / macroblock */
00125     VP56mb mb_type;
00126     VP56Macroblock *macroblocks;
00127     DECLARE_ALIGNED(16, DCTELEM, block_coeff)[6][64];
00128 
00129     /* motion vectors */
00130     VP56mv mv[6];  /* vectors for each block in MB */
00131     VP56mv vector_candidate[2];
00132     int vector_candidate_pos;
00133 
00134     /* filtering hints */
00135     int filter_header;               /* used in vp6 only */
00136     int deblock_filtering;
00137     int filter_selection;
00138     int filter_mode;
00139     int max_vector_length;
00140     int sample_variance_threshold;
00141 
00142     uint8_t coeff_ctx[4][64];              /* used in vp5 only */
00143     uint8_t coeff_ctx_last[4];             /* used in vp5 only */
00144 
00145     int has_alpha;
00146 
00147     /* upside-down flipping hints */
00148     int flip;  /* are we flipping ? */
00149     int frbi;  /* first row block index in MB */
00150     int srbi;  /* second row block index in MB */
00151     int stride[4];  /* stride for each plan */
00152 
00153     const uint8_t *vp56_coord_div;
00154     VP56ParseVectorAdjustment parse_vector_adjustment;
00155     VP56Filter filter;
00156     VP56ParseCoeff parse_coeff;
00157     VP56DefaultModelsInit default_models_init;
00158     VP56ParseVectorModels parse_vector_models;
00159     VP56ParseCoeffModels parse_coeff_models;
00160     VP56ParseHeader parse_header;
00161 
00162     VP56Model *modelp;
00163     VP56Model models[2];
00164 
00165     /* huffman decoding */
00166     int use_huffman;
00167     GetBitContext gb;
00168     VLC dccv_vlc[2];
00169     VLC runv_vlc[2];
00170     VLC ract_vlc[2][3][6];
00171     unsigned int nb_null[2][2];       /* number of consecutive NULL DC/AC */
00172 };
00173 
00174 
00175 void ff_vp56_init(AVCodecContext *avctx, int flip, int has_alpha);
00176 int ff_vp56_free(AVCodecContext *avctx);
00177 void ff_vp56_init_dequant(VP56Context *s, int quantizer);
00178 int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00179                          AVPacket *avpkt);
00180 
00181 
00186 extern const uint8_t ff_vp56_norm_shift[256];
00187 void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
00188 
00189 static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
00190 {
00191     int shift = ff_vp56_norm_shift[c->high];
00192     int bits = c->bits;
00193     unsigned int code_word = c->code_word;
00194 
00195     c->high   <<= shift;
00196     code_word <<= shift;
00197     bits       += shift;
00198     if(bits >= 0 && c->buffer < c->end) {
00199         code_word |= bytestream_get_be16(&c->buffer) << bits;
00200         bits -= 16;
00201     }
00202     c->bits = bits;
00203     return code_word;
00204 }
00205 
00206 #if   ARCH_ARM
00207 #include "arm/vp56_arith.h"
00208 #elif ARCH_X86
00209 #include "x86/vp56_arith.h"
00210 #endif
00211 
00212 #ifndef vp56_rac_get_prob
00213 #define vp56_rac_get_prob vp56_rac_get_prob
00214 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
00215 {
00216     unsigned int code_word = vp56_rac_renorm(c);
00217     unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
00218     unsigned int low_shift = low << 16;
00219     int bit = code_word >= low_shift;
00220 
00221     c->high = bit ? c->high - low : low;
00222     c->code_word = bit ? code_word - low_shift : code_word;
00223 
00224     return bit;
00225 }
00226 #endif
00227 
00228 #ifndef vp56_rac_get_prob_branchy
00229 // branchy variant, to be used where there's a branch based on the bit decoded
00230 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
00231 {
00232     unsigned long code_word = vp56_rac_renorm(c);
00233     unsigned low = 1 + (((c->high - 1) * prob) >> 8);
00234     unsigned low_shift = low << 16;
00235 
00236     if (code_word >= low_shift) {
00237         c->high     -= low;
00238         c->code_word = code_word - low_shift;
00239         return 1;
00240     }
00241 
00242     c->high = low;
00243     c->code_word = code_word;
00244     return 0;
00245 }
00246 #endif
00247 
00248 static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
00249 {
00250     unsigned int code_word = vp56_rac_renorm(c);
00251     /* equiprobable */
00252     int low = (c->high + 1) >> 1;
00253     unsigned int low_shift = low << 16;
00254     int bit = code_word >= low_shift;
00255     if (bit) {
00256         c->high   -= low;
00257         code_word -= low_shift;
00258     } else {
00259         c->high = low;
00260     }
00261 
00262     c->code_word = code_word;
00263     return bit;
00264 }
00265 
00266 // rounding is different than vp56_rac_get, is vp56_rac_get wrong?
00267 static av_always_inline int vp8_rac_get(VP56RangeCoder *c)
00268 {
00269     return vp56_rac_get_prob(c, 128);
00270 }
00271 
00272 static av_unused int vp56_rac_gets(VP56RangeCoder *c, int bits)
00273 {
00274     int value = 0;
00275 
00276     while (bits--) {
00277         value = (value << 1) | vp56_rac_get(c);
00278     }
00279 
00280     return value;
00281 }
00282 
00283 static av_unused int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
00284 {
00285     int value = 0;
00286 
00287     while (bits--) {
00288         value = (value << 1) | vp8_rac_get(c);
00289     }
00290 
00291     return value;
00292 }
00293 
00294 // fixme: add 1 bit to all the calls to this?
00295 static av_unused int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
00296 {
00297     int v;
00298 
00299     if (!vp8_rac_get(c))
00300         return 0;
00301 
00302     v = vp8_rac_get_uint(c, bits);
00303 
00304     if (vp8_rac_get(c))
00305         v = -v;
00306 
00307     return v;
00308 }
00309 
00310 // P(7)
00311 static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
00312 {
00313     int v = vp56_rac_gets(c, 7) << 1;
00314     return v + !v;
00315 }
00316 
00317 static av_unused int vp8_rac_get_nn(VP56RangeCoder *c)
00318 {
00319     int v = vp8_rac_get_uint(c, 7) << 1;
00320     return v + !v;
00321 }
00322 
00323 static av_always_inline
00324 int vp56_rac_get_tree(VP56RangeCoder *c,
00325                       const VP56Tree *tree,
00326                       const uint8_t *probs)
00327 {
00328     while (tree->val > 0) {
00329         if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
00330             tree += tree->val;
00331         else
00332             tree++;
00333     }
00334     return -tree->val;
00335 }
00336 
00342 static av_always_inline
00343 int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2],
00344                                  const uint8_t *probs, int i)
00345 {
00346     do {
00347         i = tree[i][vp56_rac_get_prob(c, probs[i])];
00348     } while (i > 0);
00349 
00350     return -i;
00351 }
00352 
00353 // how probabilities are associated with decisions is different I think
00354 // well, the new scheme fits in the old but this way has one fewer branches per decision
00355 static av_always_inline
00356 int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
00357                      const uint8_t *probs)
00358 {
00359     return vp8_rac_get_tree_with_offset(c, tree, probs, 0);
00360 }
00361 
00362 // DCTextra
00363 static av_always_inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob)
00364 {
00365     int v = 0;
00366 
00367     do {
00368         v = (v<<1) + vp56_rac_get_prob(c, *prob++);
00369     } while (*prob);
00370 
00371     return v;
00372 }
00373 
00374 #endif /* AVCODEC_VP56_H */

Generated on Fri Feb 22 2013 07:24:29 for FFmpeg by  doxygen 1.7.1