Mercurial > libavcodec.hg
annotate vp56.h @ 4074:861a55e86ef0 libavcodec
factorize update state out
author | michael |
---|---|
date | Tue, 24 Oct 2006 09:34:13 +0000 |
parents | c8c591fe26f8 |
children | 6a10cc9adb8a |
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 <stdint.h> | |
28 | |
29 #include "vp56data.h" | |
30 #include "dsputil.h" | |
31 #include "mpegvideo.h" | |
32 | |
33 | |
34 typedef struct vp56_context vp56_context_t; | |
35 typedef struct vp56_mv vp56_mv_t; | |
36 | |
37 typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s, | |
3759 | 38 vp56_mv_t *vect); |
3695 | 39 typedef int (*vp56_adjust_t)(int v, int t); |
40 typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src, | |
41 int offset1, int offset2, int stride, | |
42 vp56_mv_t mv, int mask, int select, int luma); | |
43 typedef void (*vp56_parse_coeff_t)(vp56_context_t *s); | |
44 typedef void (*vp56_default_models_init_t)(vp56_context_t *s); | |
45 typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s); | |
46 typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s); | |
47 typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf, | |
48 int buf_size, int *golden_frame); | |
49 | |
50 typedef struct { | |
51 int high; | |
52 int bits; | |
53 const uint8_t *buffer; | |
54 unsigned long code_word; | |
55 } vp56_range_coder_t; | |
56 | |
57 typedef struct { | |
58 uint8_t not_null_dc; | |
59 vp56_frame_t ref_frame; | |
60 DCTELEM dc_coeff; | |
61 } vp56_ref_dc_t; | |
62 | |
63 struct vp56_mv { | |
64 int x; | |
65 int y; | |
66 }; | |
67 | |
68 typedef struct { | |
69 uint8_t type; | |
70 vp56_mv_t mv; | |
71 } vp56_macroblock_t; | |
72 | |
73 struct vp56_context { | |
74 AVCodecContext *avctx; | |
75 DSPContext dsp; | |
76 ScanTable scantable; | |
77 AVFrame frames[3]; | |
78 uint8_t *edge_emu_buffer_alloc; | |
79 uint8_t *edge_emu_buffer; | |
80 vp56_range_coder_t c; | |
81 | |
82 /* frame info */ | |
83 int plane_width[3]; | |
84 int plane_height[3]; | |
85 int mb_width; /* number of horizontal MB */ | |
86 int mb_height; /* number of vertical MB */ | |
87 int block_offset[6]; | |
88 | |
89 int quantizer; | |
90 uint16_t dequant_dc; | |
91 uint16_t dequant_ac; | |
92 | |
93 /* DC predictors management */ | |
94 vp56_ref_dc_t *above_blocks; | |
95 vp56_ref_dc_t left_block[4]; | |
96 int above_block_idx[6]; | |
97 DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */ | |
98 | |
99 /* blocks / macroblock */ | |
100 vp56_mb_t mb_type; | |
101 vp56_macroblock_t *macroblocks; | |
102 DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]); | |
103 uint8_t coeff_reorder[64]; /* used in vp6 only */ | |
104 uint8_t coeff_index_to_pos[64]; /* used in vp6 only */ | |
105 | |
106 /* motion vectors */ | |
107 vp56_mv_t mv[6]; /* vectors for each block in MB */ | |
108 vp56_mv_t vector_candidate[2]; | |
109 int vector_candidate_pos; | |
110 | |
111 /* filtering hints */ | |
112 int deblock_filtering; | |
113 int filter_selection; | |
114 int filter_mode; | |
115 int max_vector_length; | |
116 int sample_variance_threshold; | |
117 | |
118 /* AC models */ | |
119 uint8_t vector_model_sig[2]; /* delta sign */ | |
120 uint8_t vector_model_dct[2]; /* delta coding types */ | |
121 uint8_t vector_model_pdi[2][2]; /* predefined delta init */ | |
122 uint8_t vector_model_pdv[2][7]; /* predefined delta values */ | |
123 uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */ | |
124 uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */ | |
125 uint8_t coeff_model_dccv[2][11]; /* DC coeff value */ | |
126 uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */ | |
127 uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */ | |
128 uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */ | |
129 uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */ | |
130 uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */ | |
131 uint8_t coeff_ctx[4][64]; /* used in vp5 only */ | |
132 uint8_t coeff_ctx_last[4]; /* used in vp5 only */ | |
133 | |
134 /* upside-down flipping hints */ | |
135 int flip; /* are we flipping ? */ | |
136 int frbi; /* first row block index in MB */ | |
137 int srbi; /* second row block index in MB */ | |
138 int stride[3]; /* stride for each plan */ | |
139 | |
140 const uint8_t *vp56_coord_div; | |
141 vp56_parse_vector_adjustment_t parse_vector_adjustment; | |
142 vp56_adjust_t adjust; | |
143 vp56_filter_t filter; | |
144 vp56_parse_coeff_t parse_coeff; | |
145 vp56_default_models_init_t default_models_init; | |
146 vp56_parse_vector_models_t parse_vector_models; | |
147 vp56_parse_coeff_models_t parse_coeff_models; | |
148 vp56_parse_header_t parse_header; | |
149 }; | |
150 | |
151 | |
152 void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip); | |
153 int vp56_free(AVCodecContext *avctx); | |
154 void vp56_init_dequant(vp56_context_t *s, int quantizer); | |
155 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |
156 uint8_t *buf, int buf_size); | |
157 | |
158 | |
159 /** | |
160 * vp56 specific range coder implementation | |
161 */ | |
162 | |
163 static inline void vp56_init_range_decoder(vp56_range_coder_t *c, | |
164 const uint8_t *buf, int buf_size) | |
165 { | |
166 c->high = 255; | |
167 c->bits = 8; | |
168 c->buffer = buf; | |
169 c->code_word = *c->buffer++ << 8; | |
170 c->code_word |= *c->buffer++; | |
171 } | |
172 | |
173 static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob) | |
174 { | |
175 unsigned int low = 1 + (((c->high - 1) * prob) / 256); | |
176 unsigned int low_shift = low << 8; | |
177 int bit = c->code_word >= low_shift; | |
178 | |
179 if (bit) { | |
180 c->high -= low; | |
181 c->code_word -= low_shift; | |
182 } else { | |
183 c->high = low; | |
184 } | |
185 | |
186 /* normalize */ | |
187 while (c->high < 128) { | |
188 c->high <<= 1; | |
189 c->code_word <<= 1; | |
190 if (--c->bits == 0) { | |
191 c->bits = 8; | |
192 c->code_word |= *c->buffer++; | |
193 } | |
194 } | |
195 return bit; | |
196 } | |
197 | |
198 static inline int vp56_rac_get(vp56_range_coder_t *c) | |
199 { | |
200 /* equiprobable */ | |
201 int low = (c->high + 1) >> 1; | |
202 unsigned int low_shift = low << 8; | |
203 int bit = c->code_word >= low_shift; | |
204 if (bit) { | |
205 c->high = (c->high - low) << 1; | |
206 c->code_word -= low_shift; | |
207 } else { | |
208 c->high = low << 1; | |
209 } | |
210 | |
211 /* normalize */ | |
212 c->code_word <<= 1; | |
213 if (--c->bits == 0) { | |
214 c->bits = 8; | |
215 c->code_word |= *c->buffer++; | |
216 } | |
217 return bit; | |
218 } | |
219 | |
220 static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits) | |
221 { | |
222 int value = 0; | |
223 | |
224 while (bits--) { | |
225 value = (value << 1) | vp56_rac_get(c); | |
226 } | |
227 | |
228 return value; | |
229 } | |
230 | |
231 static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits) | |
232 { | |
233 int v = vp56_rac_gets(c, 7) << 1; | |
234 return v + !v; | |
235 } | |
236 | |
237 static inline int vp56_rac_get_tree(vp56_range_coder_t *c, | |
238 const vp56_tree_t *tree, | |
239 const uint8_t *probs) | |
240 { | |
241 while (tree->val > 0) { | |
242 if (vp56_rac_get_prob(c, probs[tree->prob_idx])) | |
243 tree += tree->val; | |
244 else | |
245 tree++; | |
246 } | |
247 return -tree->val; | |
248 } | |
249 | |
250 #endif /* VP56_H */ |