• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • 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 "bitstream.h"
00030 #include "bytestream.h"
00031 
00032 
00033 typedef struct vp56_context VP56Context;
00034 typedef struct vp56_mv VP56mv;
00035 
00036 typedef void (*VP56ParseVectorAdjustment)(VP56Context *s,
00037                                           VP56mv *vect);
00038 typedef int  (*VP56Adjust)(int v, int t);
00039 typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src,
00040                            int offset1, int offset2, int stride,
00041                            VP56mv mv, int mask, int select, int luma);
00042 typedef void (*VP56ParseCoeff)(VP56Context *s);
00043 typedef void (*VP56DefaultModelsInit)(VP56Context *s);
00044 typedef void (*VP56ParseVectorModels)(VP56Context *s);
00045 typedef void (*VP56ParseCoeffModels)(VP56Context *s);
00046 typedef int  (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
00047                                 int buf_size, int *golden_frame);
00048 
00049 typedef struct {
00050     int high;
00051     int bits;
00052     const uint8_t *buffer;
00053     unsigned long code_word;
00054 } VP56RangeCoder;
00055 
00056 typedef struct {
00057     uint8_t not_null_dc;
00058     VP56Frame ref_frame;
00059     DCTELEM dc_coeff;
00060 } VP56RefDc;
00061 
00062 struct vp56_mv {
00063     int x;
00064     int y;
00065 };
00066 
00067 typedef struct {
00068     uint8_t type;
00069     VP56mv mv;
00070 } VP56Macroblock;
00071 
00072 typedef struct {
00073     uint8_t coeff_reorder[64];       /* used in vp6 only */
00074     uint8_t coeff_index_to_pos[64];  /* used in vp6 only */
00075     uint8_t vector_sig[2];           /* delta sign */
00076     uint8_t vector_dct[2];           /* delta coding types */
00077     uint8_t vector_pdi[2][2];        /* predefined delta init */
00078     uint8_t vector_pdv[2][7];        /* predefined delta values */
00079     uint8_t vector_fdv[2][8];        /* 8 bit delta value definition */
00080     uint8_t coeff_dccv[2][11];       /* DC coeff value */
00081     uint8_t coeff_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
00082     uint8_t coeff_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
00083     uint8_t coeff_dcct[2][36][5];    /* DC coeff coding type */
00084     uint8_t coeff_runv[2][14];       /* run value (vp6 only) */
00085     uint8_t mb_type[3][10][10];      /* model for decoding MB type */
00086     uint8_t mb_types_stats[3][10][2];/* contextual, next MB type stats */
00087 } VP56Model;
00088 
00089 struct vp56_context {
00090     AVCodecContext *avctx;
00091     DSPContext dsp;
00092     ScanTable scantable;
00093     AVFrame frames[4];
00094     AVFrame *framep[6];
00095     uint8_t *edge_emu_buffer_alloc;
00096     uint8_t *edge_emu_buffer;
00097     VP56RangeCoder c;
00098     VP56RangeCoder cc;
00099     VP56RangeCoder *ccp;
00100     int sub_version;
00101 
00102     /* frame info */
00103     int plane_width[4];
00104     int plane_height[4];
00105     int mb_width;   /* number of horizontal MB */
00106     int mb_height;  /* number of vertical MB */
00107     int block_offset[6];
00108 
00109     int quantizer;
00110     uint16_t dequant_dc;
00111     uint16_t dequant_ac;
00112 
00113     /* DC predictors management */
00114     VP56RefDc *above_blocks;
00115     VP56RefDc left_block[4];
00116     int above_block_idx[6];
00117     DCTELEM prev_dc[3][3];    /* [plan][ref_frame] */
00118 
00119     /* blocks / macroblock */
00120     VP56mb mb_type;
00121     VP56Macroblock *macroblocks;
00122     DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]);
00123 
00124     /* motion vectors */
00125     VP56mv mv[6];  /* vectors for each block in MB */
00126     VP56mv vector_candidate[2];
00127     int vector_candidate_pos;
00128 
00129     /* filtering hints */
00130     int filter_header;               /* used in vp6 only */
00131     int deblock_filtering;
00132     int filter_selection;
00133     int filter_mode;
00134     int max_vector_length;
00135     int sample_variance_threshold;
00136 
00137     uint8_t coeff_ctx[4][64];              /* used in vp5 only */
00138     uint8_t coeff_ctx_last[4];             /* used in vp5 only */
00139 
00140     int has_alpha;
00141 
00142     /* upside-down flipping hints */
00143     int flip;  /* are we flipping ? */
00144     int frbi;  /* first row block index in MB */
00145     int srbi;  /* second row block index in MB */
00146     int stride[4];  /* stride for each plan */
00147 
00148     const uint8_t *vp56_coord_div;
00149     VP56ParseVectorAdjustment parse_vector_adjustment;
00150     VP56Adjust adjust;
00151     VP56Filter filter;
00152     VP56ParseCoeff parse_coeff;
00153     VP56DefaultModelsInit default_models_init;
00154     VP56ParseVectorModels parse_vector_models;
00155     VP56ParseCoeffModels parse_coeff_models;
00156     VP56ParseHeader parse_header;
00157 
00158     VP56Model *modelp;
00159     VP56Model models[2];
00160 
00161     /* huffman decoding */
00162     int use_huffman;
00163     GetBitContext gb;
00164     VLC dccv_vlc[2];
00165     VLC runv_vlc[2];
00166     VLC ract_vlc[2][3][6];
00167     unsigned int nb_null[2][2];       /* number of consecutive NULL DC/AC */
00168 };
00169 
00170 
00171 void vp56_init(AVCodecContext *avctx, int flip, int has_alpha);
00172 int vp56_free(AVCodecContext *avctx);
00173 void vp56_init_dequant(VP56Context *s, int quantizer);
00174 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00175                       const uint8_t *buf, int buf_size);
00176 
00177 
00182 static inline void vp56_init_range_decoder(VP56RangeCoder *c,
00183                                            const uint8_t *buf, int buf_size)
00184 {
00185     c->high = 255;
00186     c->bits = 8;
00187     c->buffer = buf;
00188     c->code_word = bytestream_get_be16(&c->buffer);
00189 }
00190 
00191 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
00192 {
00193     unsigned int low = 1 + (((c->high - 1) * prob) / 256);
00194     unsigned int low_shift = low << 8;
00195     int bit = c->code_word >= low_shift;
00196 
00197     if (bit) {
00198         c->high -= low;
00199         c->code_word -= low_shift;
00200     } else {
00201         c->high = low;
00202     }
00203 
00204     /* normalize */
00205     while (c->high < 128) {
00206         c->high <<= 1;
00207         c->code_word <<= 1;
00208         if (--c->bits == 0) {
00209             c->bits = 8;
00210             c->code_word |= *c->buffer++;
00211         }
00212     }
00213     return bit;
00214 }
00215 
00216 static inline int vp56_rac_get(VP56RangeCoder *c)
00217 {
00218     /* equiprobable */
00219     int low = (c->high + 1) >> 1;
00220     unsigned int low_shift = low << 8;
00221     int bit = c->code_word >= low_shift;
00222     if (bit) {
00223         c->high = (c->high - low) << 1;
00224         c->code_word -= low_shift;
00225     } else {
00226         c->high = low << 1;
00227     }
00228 
00229     /* normalize */
00230     c->code_word <<= 1;
00231     if (--c->bits == 0) {
00232         c->bits = 8;
00233         c->code_word |= *c->buffer++;
00234     }
00235     return bit;
00236 }
00237 
00238 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits)
00239 {
00240     int value = 0;
00241 
00242     while (bits--) {
00243         value = (value << 1) | vp56_rac_get(c);
00244     }
00245 
00246     return value;
00247 }
00248 
00249 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
00250 {
00251     int v = vp56_rac_gets(c, 7) << 1;
00252     return v + !v;
00253 }
00254 
00255 static inline int vp56_rac_get_tree(VP56RangeCoder *c,
00256                                     const VP56Tree *tree,
00257                                     const uint8_t *probs)
00258 {
00259     while (tree->val > 0) {
00260         if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
00261             tree += tree->val;
00262         else
00263             tree++;
00264     }
00265     return -tree->val;
00266 }
00267 
00268 #endif /* AVCODEC_VP56_H */

Generated on Tue Nov 4 2014 12:59:23 for ffmpeg by  doxygen 1.7.1