Mercurial > libavcodec.hg
annotate vp56.h @ 4418:4cceb7c877af libavcodec
rename CMOV_IS_FAST to HAVE_FAST_CMOV and simplify configure
author | mru |
---|---|
date | Sat, 27 Jan 2007 14:10:57 +0000 |
parents | d3dcf62d52c5 |
children | 340c876320eb |
rev | line source |
---|---|
3695 | 1 /** |
2 * @file vp56.h | |
3 * VP5 and VP6 compatible video decoder (common features) | |
4 * | |
5 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> | |
6 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3759
diff
changeset
|
7 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3759
diff
changeset
|
8 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3759
diff
changeset
|
9 * FFmpeg is free software; you can redistribute it and/or |
3695 | 10 * modify it under the terms of the GNU Lesser General Public |
11 * License as published by the Free Software Foundation; either | |
12 * version 2.1 of the License, or (at your option) any later version. | |
13 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3759
diff
changeset
|
14 * FFmpeg is distributed in the hope that it will be useful, |
3695 | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Lesser General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3759
diff
changeset
|
20 * License along with FFmpeg; if not, write to the Free Software |
3695 | 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
22 */ | |
23 | |
24 #ifndef VP56_H | |
25 #define VP56_H | |
26 | |
27 #include "vp56data.h" | |
28 #include "dsputil.h" | |
29 #include "mpegvideo.h" | |
30 | |
31 | |
32 typedef struct vp56_context vp56_context_t; | |
33 typedef struct vp56_mv vp56_mv_t; | |
34 | |
35 typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s, | |
3759 | 36 vp56_mv_t *vect); |
3695 | 37 typedef int (*vp56_adjust_t)(int v, int t); |
38 typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src, | |
39 int offset1, int offset2, int stride, | |
40 vp56_mv_t mv, int mask, int select, int luma); | |
41 typedef void (*vp56_parse_coeff_t)(vp56_context_t *s); | |
42 typedef void (*vp56_default_models_init_t)(vp56_context_t *s); | |
43 typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s); | |
44 typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s); | |
45 typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf, | |
46 int buf_size, int *golden_frame); | |
47 | |
48 typedef struct { | |
49 int high; | |
50 int bits; | |
51 const uint8_t *buffer; | |
52 unsigned long code_word; | |
53 } vp56_range_coder_t; | |
54 | |
55 typedef struct { | |
56 uint8_t not_null_dc; | |
57 vp56_frame_t ref_frame; | |
58 DCTELEM dc_coeff; | |
59 } vp56_ref_dc_t; | |
60 | |
61 struct vp56_mv { | |
62 int x; | |
63 int y; | |
64 }; | |
65 | |
66 typedef struct { | |
67 uint8_t type; | |
68 vp56_mv_t mv; | |
69 } vp56_macroblock_t; | |
70 | |
71 struct vp56_context { | |
72 AVCodecContext *avctx; | |
73 DSPContext dsp; | |
74 ScanTable scantable; | |
75 AVFrame frames[3]; | |
76 uint8_t *edge_emu_buffer_alloc; | |
77 uint8_t *edge_emu_buffer; | |
78 vp56_range_coder_t c; | |
4348 | 79 vp56_range_coder_t cc; |
80 vp56_range_coder_t *ccp; | |
4308 | 81 int sub_version; |
3695 | 82 |
83 /* frame info */ | |
84 int plane_width[3]; | |
85 int plane_height[3]; | |
86 int mb_width; /* number of horizontal MB */ | |
87 int mb_height; /* number of vertical MB */ | |
88 int block_offset[6]; | |
89 | |
90 int quantizer; | |
91 uint16_t dequant_dc; | |
92 uint16_t dequant_ac; | |
93 | |
94 /* DC predictors management */ | |
95 vp56_ref_dc_t *above_blocks; | |
96 vp56_ref_dc_t left_block[4]; | |
97 int above_block_idx[6]; | |
98 DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */ | |
99 | |
100 /* blocks / macroblock */ | |
101 vp56_mb_t mb_type; | |
102 vp56_macroblock_t *macroblocks; | |
103 DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]); | |
104 uint8_t coeff_reorder[64]; /* used in vp6 only */ | |
105 uint8_t coeff_index_to_pos[64]; /* used in vp6 only */ | |
106 | |
107 /* motion vectors */ | |
108 vp56_mv_t mv[6]; /* vectors for each block in MB */ | |
109 vp56_mv_t vector_candidate[2]; | |
110 int vector_candidate_pos; | |
111 | |
112 /* filtering hints */ | |
4348 | 113 int filter_header; /* used in vp6 only */ |
3695 | 114 int deblock_filtering; |
115 int filter_selection; | |
116 int filter_mode; | |
117 int max_vector_length; | |
118 int sample_variance_threshold; | |
119 | |
120 /* AC models */ | |
121 uint8_t vector_model_sig[2]; /* delta sign */ | |
122 uint8_t vector_model_dct[2]; /* delta coding types */ | |
123 uint8_t vector_model_pdi[2][2]; /* predefined delta init */ | |
124 uint8_t vector_model_pdv[2][7]; /* predefined delta values */ | |
125 uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */ | |
126 uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */ | |
127 uint8_t coeff_model_dccv[2][11]; /* DC coeff value */ | |
128 uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */ | |
129 uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */ | |
130 uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */ | |
131 uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */ | |
132 uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */ | |
133 uint8_t coeff_ctx[4][64]; /* used in vp5 only */ | |
134 uint8_t coeff_ctx_last[4]; /* used in vp5 only */ | |
135 | |
136 /* upside-down flipping hints */ | |
137 int flip; /* are we flipping ? */ | |
138 int frbi; /* first row block index in MB */ | |
139 int srbi; /* second row block index in MB */ | |
140 int stride[3]; /* stride for each plan */ | |
141 | |
142 const uint8_t *vp56_coord_div; | |
143 vp56_parse_vector_adjustment_t parse_vector_adjustment; | |
144 vp56_adjust_t adjust; | |
145 vp56_filter_t filter; | |
146 vp56_parse_coeff_t parse_coeff; | |
147 vp56_default_models_init_t default_models_init; | |
148 vp56_parse_vector_models_t parse_vector_models; | |
149 vp56_parse_coeff_models_t parse_coeff_models; | |
150 vp56_parse_header_t parse_header; | |
151 }; | |
152 | |
153 | |
154 void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip); | |
155 int vp56_free(AVCodecContext *avctx); | |
156 void vp56_init_dequant(vp56_context_t *s, int quantizer); | |
157 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |
158 uint8_t *buf, int buf_size); | |
159 | |
160 | |
161 /** | |
162 * vp56 specific range coder implementation | |
163 */ | |
164 | |
165 static inline void vp56_init_range_decoder(vp56_range_coder_t *c, | |
166 const uint8_t *buf, int buf_size) | |
167 { | |
168 c->high = 255; | |
169 c->bits = 8; | |
170 c->buffer = buf; | |
171 c->code_word = *c->buffer++ << 8; | |
172 c->code_word |= *c->buffer++; | |
173 } | |
174 | |
175 static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob) | |
176 { | |
177 unsigned int low = 1 + (((c->high - 1) * prob) / 256); | |
178 unsigned int low_shift = low << 8; | |
179 int bit = c->code_word >= low_shift; | |
180 | |
181 if (bit) { | |
182 c->high -= low; | |
183 c->code_word -= low_shift; | |
184 } else { | |
185 c->high = low; | |
186 } | |
187 | |
188 /* normalize */ | |
189 while (c->high < 128) { | |
190 c->high <<= 1; | |
191 c->code_word <<= 1; | |
192 if (--c->bits == 0) { | |
193 c->bits = 8; | |
194 c->code_word |= *c->buffer++; | |
195 } | |
196 } | |
197 return bit; | |
198 } | |
199 | |
200 static inline int vp56_rac_get(vp56_range_coder_t *c) | |
201 { | |
202 /* equiprobable */ | |
203 int low = (c->high + 1) >> 1; | |
204 unsigned int low_shift = low << 8; | |
205 int bit = c->code_word >= low_shift; | |
206 if (bit) { | |
207 c->high = (c->high - low) << 1; | |
208 c->code_word -= low_shift; | |
209 } else { | |
210 c->high = low << 1; | |
211 } | |
212 | |
213 /* normalize */ | |
214 c->code_word <<= 1; | |
215 if (--c->bits == 0) { | |
216 c->bits = 8; | |
217 c->code_word |= *c->buffer++; | |
218 } | |
219 return bit; | |
220 } | |
221 | |
222 static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits) | |
223 { | |
224 int value = 0; | |
225 | |
226 while (bits--) { | |
227 value = (value << 1) | vp56_rac_get(c); | |
228 } | |
229 | |
230 return value; | |
231 } | |
232 | |
233 static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits) | |
234 { | |
235 int v = vp56_rac_gets(c, 7) << 1; | |
236 return v + !v; | |
237 } | |
238 | |
239 static inline int vp56_rac_get_tree(vp56_range_coder_t *c, | |
240 const vp56_tree_t *tree, | |
241 const uint8_t *probs) | |
242 { | |
243 while (tree->val > 0) { | |
244 if (vp56_rac_get_prob(c, probs[tree->prob_idx])) | |
245 tree += tree->val; | |
246 else | |
247 tree++; | |
248 } | |
249 return -tree->val; | |
250 } | |
251 | |
252 #endif /* VP56_H */ |