Libav
|
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 "vp56dsp.h" 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 void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src, 00039 int offset1, int offset2, int stride, 00040 VP56mv mv, int mask, int select, int luma); 00041 typedef void (*VP56ParseCoeff)(VP56Context *s); 00042 typedef void (*VP56DefaultModelsInit)(VP56Context *s); 00043 typedef void (*VP56ParseVectorModels)(VP56Context *s); 00044 typedef void (*VP56ParseCoeffModels)(VP56Context *s); 00045 typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf, 00046 int buf_size, int *golden_frame); 00047 00048 typedef struct { 00049 int high; 00050 int bits; 00051 const uint8_t *buffer; 00052 const uint8_t *end; 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 VP56DSPContext vp56dsp; 00093 ScanTable scantable; 00094 AVFrame frames[4]; 00095 AVFrame *framep[6]; 00096 uint8_t *edge_emu_buffer_alloc; 00097 uint8_t *edge_emu_buffer; 00098 VP56RangeCoder c; 00099 VP56RangeCoder cc; 00100 VP56RangeCoder *ccp; 00101 int sub_version; 00102 00103 /* frame info */ 00104 int plane_width[4]; 00105 int plane_height[4]; 00106 int mb_width; /* number of horizontal MB */ 00107 int mb_height; /* number of vertical MB */ 00108 int block_offset[6]; 00109 00110 int quantizer; 00111 uint16_t dequant_dc; 00112 uint16_t dequant_ac; 00113 int8_t *qscale_table; 00114 00115 /* DC predictors management */ 00116 VP56RefDc *above_blocks; 00117 VP56RefDc left_block[4]; 00118 int above_block_idx[6]; 00119 DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */ 00120 00121 /* blocks / macroblock */ 00122 VP56mb mb_type; 00123 VP56Macroblock *macroblocks; 00124 DECLARE_ALIGNED(16, DCTELEM, block_coeff)[6][64]; 00125 00126 /* motion vectors */ 00127 VP56mv mv[6]; /* vectors for each block in MB */ 00128 VP56mv vector_candidate[2]; 00129 int vector_candidate_pos; 00130 00131 /* filtering hints */ 00132 int filter_header; /* used in vp6 only */ 00133 int deblock_filtering; 00134 int filter_selection; 00135 int filter_mode; 00136 int max_vector_length; 00137 int sample_variance_threshold; 00138 00139 uint8_t coeff_ctx[4][64]; /* used in vp5 only */ 00140 uint8_t coeff_ctx_last[4]; /* used in vp5 only */ 00141 00142 int has_alpha; 00143 00144 /* upside-down flipping hints */ 00145 int flip; /* are we flipping ? */ 00146 int frbi; /* first row block index in MB */ 00147 int srbi; /* second row block index in MB */ 00148 int stride[4]; /* stride for each plan */ 00149 00150 const uint8_t *vp56_coord_div; 00151 VP56ParseVectorAdjustment parse_vector_adjustment; 00152 VP56Filter filter; 00153 VP56ParseCoeff parse_coeff; 00154 VP56DefaultModelsInit default_models_init; 00155 VP56ParseVectorModels parse_vector_models; 00156 VP56ParseCoeffModels parse_coeff_models; 00157 VP56ParseHeader parse_header; 00158 00159 VP56Model *modelp; 00160 VP56Model models[2]; 00161 00162 /* huffman decoding */ 00163 int use_huffman; 00164 GetBitContext gb; 00165 VLC dccv_vlc[2]; 00166 VLC runv_vlc[2]; 00167 VLC ract_vlc[2][3][6]; 00168 unsigned int nb_null[2][2]; /* number of consecutive NULL DC/AC */ 00169 }; 00170 00171 00172 void vp56_init(AVCodecContext *avctx, int flip, int has_alpha); 00173 int vp56_free(AVCodecContext *avctx); 00174 void vp56_init_dequant(VP56Context *s, int quantizer); 00175 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, 00176 AVPacket *avpkt); 00177 00178 00183 static inline void vp56_init_range_decoder(VP56RangeCoder *c, 00184 const uint8_t *buf, int buf_size) 00185 { 00186 c->high = 255; 00187 c->bits = 8; 00188 c->buffer = buf; 00189 c->end = buf + buf_size; 00190 c->code_word = bytestream_get_be16(&c->buffer); 00191 } 00192 00193 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) 00194 { 00195 unsigned int low = 1 + (((c->high - 1) * prob) / 256); 00196 unsigned int low_shift = low << 8; 00197 int bit = c->code_word >= low_shift; 00198 00199 if (bit) { 00200 c->high -= low; 00201 c->code_word -= low_shift; 00202 } else { 00203 c->high = low; 00204 } 00205 00206 /* normalize */ 00207 while (c->high < 128) { 00208 c->high <<= 1; 00209 c->code_word <<= 1; 00210 if (--c->bits == 0 && c->buffer < c->end) { 00211 c->bits = 8; 00212 c->code_word |= *c->buffer++; 00213 } 00214 } 00215 return bit; 00216 } 00217 00218 static inline int vp56_rac_get(VP56RangeCoder *c) 00219 { 00220 /* equiprobable */ 00221 int low = (c->high + 1) >> 1; 00222 unsigned int low_shift = low << 8; 00223 int bit = c->code_word >= low_shift; 00224 if (bit) { 00225 c->high = (c->high - low) << 1; 00226 c->code_word -= low_shift; 00227 } else { 00228 c->high = low << 1; 00229 } 00230 00231 /* normalize */ 00232 c->code_word <<= 1; 00233 if (--c->bits == 0 && c->buffer < c->end) { 00234 c->bits = 8; 00235 c->code_word |= *c->buffer++; 00236 } 00237 return bit; 00238 } 00239 00240 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits) 00241 { 00242 int value = 0; 00243 00244 while (bits--) { 00245 value = (value << 1) | vp56_rac_get(c); 00246 } 00247 00248 return value; 00249 } 00250 00251 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits) 00252 { 00253 int v = vp56_rac_gets(c, 7) << 1; 00254 return v + !v; 00255 } 00256 00257 static inline int vp56_rac_get_tree(VP56RangeCoder *c, 00258 const VP56Tree *tree, 00259 const uint8_t *probs) 00260 { 00261 while (tree->val > 0) { 00262 if (vp56_rac_get_prob(c, probs[tree->prob_idx])) 00263 tree += tree->val; 00264 else 00265 tree++; 00266 } 00267 return -tree->val; 00268 } 00269 00270 #endif /* AVCODEC_VP56_H */