Mercurial > libavcodec.hg
annotate vp3.c @ 3492:fa3794c46f21 libavcodec
parse all QIS values (we still ignore them though ...)
author | michael |
---|---|
date | Mon, 17 Jul 2006 13:09:45 +0000 |
parents | 6eadb7c9f569 |
children | 3a7844f83df4 |
rev | line source |
---|---|
1224 | 1 /* |
1867
7f7aa6ac3723
cut over to using new VP3 DSP functions and remove the old ones; bring
melanson
parents:
1864
diff
changeset
|
2 * Copyright (C) 2003-2004 the ffmpeg project |
1224 | 3 * |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Lesser General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Lesser General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Lesser General Public | |
15 * License along with this library; if not, write to the Free Software | |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1224 | 17 * |
18 */ | |
19 | |
20 /** | |
21 * @file vp3.c | |
22 * On2 VP3 Video Decoder | |
2702
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
23 * |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
24 * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx) |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
25 * For more information about the VP3 coding process, visit: |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
26 * http://multimedia.cx/ |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
27 * |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
28 * Theora decoder by Alex Beregszaszi |
1224 | 29 */ |
30 | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 #include <unistd.h> | |
35 | |
36 #include "common.h" | |
37 #include "avcodec.h" | |
38 #include "dsputil.h" | |
39 #include "mpegvideo.h" | |
40 | |
41 #include "vp3data.h" | |
42 | |
43 #define FRAGMENT_PIXELS 8 | |
44 | |
2967 | 45 /* |
1224 | 46 * Debugging Variables |
2967 | 47 * |
1224 | 48 * Define one or more of the following compile-time variables to 1 to obtain |
49 * elaborate information about certain aspects of the decoding process. | |
50 * | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
51 * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode) |
1224 | 52 * DEBUG_VP3: high-level decoding flow |
53 * DEBUG_INIT: initialization parameters | |
54 * DEBUG_DEQUANTIZERS: display how the dequanization tables are built | |
55 * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding | |
56 * DEBUG_MODES: unpacking the coding modes for individual fragments | |
57 * DEBUG_VECTORS: display the motion vectors | |
58 * DEBUG_TOKEN: display exhaustive information about each DCT token | |
59 * DEBUG_VLC: display the VLCs as they are extracted from the stream | |
60 * DEBUG_DC_PRED: display the process of reversing DC prediction | |
61 * DEBUG_IDCT: show every detail of the IDCT process | |
62 */ | |
63 | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
64 #define KEYFRAMES_ONLY 0 |
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
65 |
2945 | 66 #define DEBUG_VP3 0 |
1224 | 67 #define DEBUG_INIT 0 |
68 #define DEBUG_DEQUANTIZERS 0 | |
69 #define DEBUG_BLOCK_CODING 0 | |
70 #define DEBUG_MODES 0 | |
71 #define DEBUG_VECTORS 0 | |
72 #define DEBUG_TOKEN 0 | |
73 #define DEBUG_VLC 0 | |
74 #define DEBUG_DC_PRED 0 | |
75 #define DEBUG_IDCT 0 | |
76 | |
77 #if DEBUG_VP3 | |
2866 | 78 #define debug_vp3(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 79 #else |
80 static inline void debug_vp3(const char *format, ...) { } | |
81 #endif | |
82 | |
83 #if DEBUG_INIT | |
2866 | 84 #define debug_init(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 85 #else |
86 static inline void debug_init(const char *format, ...) { } | |
87 #endif | |
88 | |
89 #if DEBUG_DEQUANTIZERS | |
2866 | 90 #define debug_dequantizers(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 91 #else |
2967 | 92 static inline void debug_dequantizers(const char *format, ...) { } |
1224 | 93 #endif |
94 | |
95 #if DEBUG_BLOCK_CODING | |
2866 | 96 #define debug_block_coding(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 97 #else |
2967 | 98 static inline void debug_block_coding(const char *format, ...) { } |
1224 | 99 #endif |
100 | |
101 #if DEBUG_MODES | |
2967 | 102 #define debug_modes(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 103 #else |
2967 | 104 static inline void debug_modes(const char *format, ...) { } |
1224 | 105 #endif |
106 | |
107 #if DEBUG_VECTORS | |
2866 | 108 #define debug_vectors(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 109 #else |
2967 | 110 static inline void debug_vectors(const char *format, ...) { } |
1224 | 111 #endif |
112 | |
2967 | 113 #if DEBUG_TOKEN |
2866 | 114 #define debug_token(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 115 #else |
2967 | 116 static inline void debug_token(const char *format, ...) { } |
1224 | 117 #endif |
118 | |
119 #if DEBUG_VLC | |
2866 | 120 #define debug_vlc(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 121 #else |
2967 | 122 static inline void debug_vlc(const char *format, ...) { } |
1224 | 123 #endif |
124 | |
125 #if DEBUG_DC_PRED | |
2866 | 126 #define debug_dc_pred(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 127 #else |
2967 | 128 static inline void debug_dc_pred(const char *format, ...) { } |
1224 | 129 #endif |
130 | |
131 #if DEBUG_IDCT | |
2866 | 132 #define debug_idct(args...) av_log(NULL, AV_LOG_DEBUG, ## args) |
1224 | 133 #else |
2967 | 134 static inline void debug_idct(const char *format, ...) { } |
1224 | 135 #endif |
136 | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
137 typedef struct Coeff { |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
138 struct Coeff *next; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
139 DCTELEM coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
140 uint8_t index; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
141 } Coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
142 |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
143 //FIXME split things out into their own arrays |
1224 | 144 typedef struct Vp3Fragment { |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
145 Coeff *next_coeff; |
1224 | 146 /* address of first pixel taking into account which plane the fragment |
147 * lives on as well as the plane stride */ | |
148 int first_pixel; | |
149 /* this is the macroblock that the fragment belongs to */ | |
2706 | 150 uint16_t macroblock; |
151 uint8_t coding_method; | |
152 uint8_t coeff_count; | |
153 int8_t motion_x; | |
154 int8_t motion_y; | |
1224 | 155 } Vp3Fragment; |
156 | |
157 #define SB_NOT_CODED 0 | |
158 #define SB_PARTIALLY_CODED 1 | |
159 #define SB_FULLY_CODED 2 | |
160 | |
161 #define MODE_INTER_NO_MV 0 | |
162 #define MODE_INTRA 1 | |
163 #define MODE_INTER_PLUS_MV 2 | |
164 #define MODE_INTER_LAST_MV 3 | |
165 #define MODE_INTER_PRIOR_LAST 4 | |
166 #define MODE_USING_GOLDEN 5 | |
167 #define MODE_GOLDEN_MV 6 | |
168 #define MODE_INTER_FOURMV 7 | |
169 #define CODING_MODE_COUNT 8 | |
170 | |
171 /* special internal mode */ | |
172 #define MODE_COPY 8 | |
173 | |
174 /* There are 6 preset schemes, plus a free-form scheme */ | |
175 static int ModeAlphabet[7][CODING_MODE_COUNT] = | |
176 { | |
177 /* this is the custom scheme */ | |
178 { 0, 0, 0, 0, 0, 0, 0, 0 }, | |
179 | |
180 /* scheme 1: Last motion vector dominates */ | |
2967 | 181 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, |
1224 | 182 MODE_INTER_PLUS_MV, MODE_INTER_NO_MV, |
2967 | 183 MODE_INTRA, MODE_USING_GOLDEN, |
1224 | 184 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
185 | |
186 /* scheme 2 */ | |
2967 | 187 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, |
1224 | 188 MODE_INTER_NO_MV, MODE_INTER_PLUS_MV, |
2967 | 189 MODE_INTRA, MODE_USING_GOLDEN, |
1224 | 190 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
191 | |
192 /* scheme 3 */ | |
2967 | 193 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV, |
1224 | 194 MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV, |
2967 | 195 MODE_INTRA, MODE_USING_GOLDEN, |
1224 | 196 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
197 | |
198 /* scheme 4 */ | |
2967 | 199 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV, |
1224 | 200 MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST, |
2967 | 201 MODE_INTRA, MODE_USING_GOLDEN, |
1224 | 202 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
203 | |
204 /* scheme 5: No motion vector dominates */ | |
2967 | 205 { MODE_INTER_NO_MV, MODE_INTER_LAST_MV, |
1224 | 206 MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV, |
2967 | 207 MODE_INTRA, MODE_USING_GOLDEN, |
1224 | 208 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
209 | |
210 /* scheme 6 */ | |
2967 | 211 { MODE_INTER_NO_MV, MODE_USING_GOLDEN, |
1224 | 212 MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, |
2967 | 213 MODE_INTER_PLUS_MV, MODE_INTRA, |
1224 | 214 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, |
215 | |
216 }; | |
217 | |
218 #define MIN_DEQUANT_VAL 2 | |
219 | |
220 typedef struct Vp3DecodeContext { | |
221 AVCodecContext *avctx; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
222 int theora, theora_tables; |
1664 | 223 int version; |
1224 | 224 int width, height; |
225 AVFrame golden_frame; | |
226 AVFrame last_frame; | |
227 AVFrame current_frame; | |
228 int keyframe; | |
229 DSPContext dsp; | |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
230 int flipped_image; |
1224 | 231 |
3492
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
232 int qis[3]; |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
233 int nqis; |
1224 | 234 int quality_index; |
235 int last_quality_index; | |
236 | |
237 int superblock_count; | |
238 int superblock_width; | |
239 int superblock_height; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
240 int y_superblock_width; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
241 int y_superblock_height; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
242 int c_superblock_width; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
243 int c_superblock_height; |
1224 | 244 int u_superblock_start; |
245 int v_superblock_start; | |
246 unsigned char *superblock_coding; | |
247 | |
248 int macroblock_count; | |
249 int macroblock_width; | |
250 int macroblock_height; | |
251 | |
252 int fragment_count; | |
253 int fragment_width; | |
254 int fragment_height; | |
255 | |
256 Vp3Fragment *all_fragments; | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
257 Coeff *coeffs; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
258 Coeff *next_coeff; |
1224 | 259 int u_fragment_start; |
260 int v_fragment_start; | |
2967 | 261 |
2694 | 262 ScanTable scantable; |
2967 | 263 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
264 /* tables */ |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
265 uint16_t coded_dc_scale_factor[64]; |
1867
7f7aa6ac3723
cut over to using new VP3 DSP functions and remove the old ones; bring
melanson
parents:
1864
diff
changeset
|
266 uint32_t coded_ac_scale_factor[64]; |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
267 uint8_t base_matrix[384][64]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
268 uint8_t qr_count[2][3]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
269 uint8_t qr_size [2][3][64]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
270 uint16_t qr_base[2][3][64]; |
1224 | 271 |
272 /* this is a list of indices into the all_fragments array indicating | |
273 * which of the fragments are coded */ | |
274 int *coded_fragment_list; | |
275 int coded_fragment_list_index; | |
276 int pixel_addresses_inited; | |
277 | |
278 VLC dc_vlc[16]; | |
279 VLC ac_vlc_1[16]; | |
280 VLC ac_vlc_2[16]; | |
281 VLC ac_vlc_3[16]; | |
282 VLC ac_vlc_4[16]; | |
283 | |
2702
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
284 VLC superblock_run_length_vlc; |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
285 VLC fragment_run_length_vlc; |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
286 VLC mode_code_vlc; |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
287 VLC motion_vector_vlc; |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
288 |
1972 | 289 /* these arrays need to be on 16-byte boundaries since SSE2 operations |
290 * index into them */ | |
3488
a647bf3a7fa8
replace *_dequant (2 intra, 1 inter) by qmat (3 intra, 3 inter) (needed for theora according to spec)
michael
parents:
3487
diff
changeset
|
291 DECLARE_ALIGNED_16(int16_t, qmat[2][4][64]); //<qmat[is_inter][plane] |
1224 | 292 |
293 /* This table contains superblock_count * 16 entries. Each set of 16 | |
294 * numbers corresponds to the fragment indices 0..15 of the superblock. | |
295 * An entry will be -1 to indicate that no entry corresponds to that | |
296 * index. */ | |
297 int *superblock_fragments; | |
298 | |
299 /* This table contains superblock_count * 4 entries. Each set of 4 | |
300 * numbers corresponds to the macroblock indices 0..3 of the superblock. | |
301 * An entry will be -1 to indicate that no entry corresponds to that | |
302 * index. */ | |
303 int *superblock_macroblocks; | |
304 | |
305 /* This table contains macroblock_count * 6 entries. Each set of 6 | |
306 * numbers corresponds to the fragment indices 0..5 which comprise | |
307 * the macroblock (4 Y fragments and 2 C fragments). */ | |
308 int *macroblock_fragments; | |
2967 | 309 /* This is an array that indicates how a particular macroblock |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
310 * is coded. */ |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
311 unsigned char *macroblock_coding; |
1224 | 312 |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
313 int first_coded_y_fragment; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
314 int first_coded_c_fragment; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
315 int last_coded_y_fragment; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
316 int last_coded_c_fragment; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
317 |
1406 | 318 uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc |
1407 | 319 uint8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16 |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
320 |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
321 /* Huffman decode */ |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
322 int hti; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
323 unsigned int hbits; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
324 int entries; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
325 int huff_code_size; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
326 uint16_t huffman_table[80][32][2]; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
327 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
328 uint32_t filter_limit_values[64]; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
329 int bounding_values_array[256]; |
1224 | 330 } Vp3DecodeContext; |
331 | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
332 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb); |
1664 | 333 |
1224 | 334 /************************************************************************ |
335 * VP3 specific functions | |
336 ************************************************************************/ | |
337 | |
338 /* | |
339 * This function sets up all of the various blocks mappings: | |
340 * superblocks <-> fragments, macroblocks <-> fragments, | |
341 * superblocks <-> macroblocks | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
342 * |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
343 * Returns 0 is successful; returns 1 if *anything* went wrong. |
1224 | 344 */ |
2967 | 345 static int init_block_mapping(Vp3DecodeContext *s) |
1224 | 346 { |
347 int i, j; | |
348 signed int hilbert_walk_y[16]; | |
349 signed int hilbert_walk_c[16]; | |
350 signed int hilbert_walk_mb[4]; | |
351 | |
352 int current_fragment = 0; | |
353 int current_width = 0; | |
354 int current_height = 0; | |
355 int right_edge = 0; | |
356 int bottom_edge = 0; | |
357 int superblock_row_inc = 0; | |
358 int *hilbert = NULL; | |
359 int mapping_index = 0; | |
360 | |
361 int current_macroblock; | |
362 int c_fragment; | |
363 | |
364 signed char travel_width[16] = { | |
2967 | 365 1, 1, 0, -1, |
1224 | 366 0, 0, 1, 0, |
367 1, 0, 1, 0, | |
368 0, -1, 0, 1 | |
369 }; | |
370 | |
371 signed char travel_height[16] = { | |
372 0, 0, 1, 0, | |
373 1, 1, 0, -1, | |
374 0, 1, 0, -1, | |
375 -1, 0, -1, 0 | |
376 }; | |
377 | |
378 signed char travel_width_mb[4] = { | |
379 1, 0, 1, 0 | |
380 }; | |
381 | |
382 signed char travel_height_mb[4] = { | |
383 0, 1, 0, -1 | |
384 }; | |
385 | |
386 debug_vp3(" vp3: initialize block mapping tables\n"); | |
387 | |
388 /* figure out hilbert pattern per these frame dimensions */ | |
389 hilbert_walk_y[0] = 1; | |
390 hilbert_walk_y[1] = 1; | |
391 hilbert_walk_y[2] = s->fragment_width; | |
392 hilbert_walk_y[3] = -1; | |
393 hilbert_walk_y[4] = s->fragment_width; | |
394 hilbert_walk_y[5] = s->fragment_width; | |
395 hilbert_walk_y[6] = 1; | |
396 hilbert_walk_y[7] = -s->fragment_width; | |
397 hilbert_walk_y[8] = 1; | |
398 hilbert_walk_y[9] = s->fragment_width; | |
399 hilbert_walk_y[10] = 1; | |
400 hilbert_walk_y[11] = -s->fragment_width; | |
401 hilbert_walk_y[12] = -s->fragment_width; | |
402 hilbert_walk_y[13] = -1; | |
403 hilbert_walk_y[14] = -s->fragment_width; | |
404 hilbert_walk_y[15] = 1; | |
405 | |
406 hilbert_walk_c[0] = 1; | |
407 hilbert_walk_c[1] = 1; | |
408 hilbert_walk_c[2] = s->fragment_width / 2; | |
409 hilbert_walk_c[3] = -1; | |
410 hilbert_walk_c[4] = s->fragment_width / 2; | |
411 hilbert_walk_c[5] = s->fragment_width / 2; | |
412 hilbert_walk_c[6] = 1; | |
413 hilbert_walk_c[7] = -s->fragment_width / 2; | |
414 hilbert_walk_c[8] = 1; | |
415 hilbert_walk_c[9] = s->fragment_width / 2; | |
416 hilbert_walk_c[10] = 1; | |
417 hilbert_walk_c[11] = -s->fragment_width / 2; | |
418 hilbert_walk_c[12] = -s->fragment_width / 2; | |
419 hilbert_walk_c[13] = -1; | |
420 hilbert_walk_c[14] = -s->fragment_width / 2; | |
421 hilbert_walk_c[15] = 1; | |
422 | |
423 hilbert_walk_mb[0] = 1; | |
424 hilbert_walk_mb[1] = s->macroblock_width; | |
425 hilbert_walk_mb[2] = 1; | |
426 hilbert_walk_mb[3] = -s->macroblock_width; | |
427 | |
428 /* iterate through each superblock (all planes) and map the fragments */ | |
429 for (i = 0; i < s->superblock_count; i++) { | |
430 debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n", | |
431 i, s->u_superblock_start, s->v_superblock_start); | |
432 | |
433 /* time to re-assign the limits? */ | |
434 if (i == 0) { | |
435 | |
436 /* start of Y superblocks */ | |
437 right_edge = s->fragment_width; | |
438 bottom_edge = s->fragment_height; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
439 current_width = -1; |
1224 | 440 current_height = 0; |
2967 | 441 superblock_row_inc = 3 * s->fragment_width - |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
442 (s->y_superblock_width * 4 - s->fragment_width); |
1224 | 443 hilbert = hilbert_walk_y; |
444 | |
445 /* the first operation for this variable is to advance by 1 */ | |
446 current_fragment = -1; | |
447 | |
448 } else if (i == s->u_superblock_start) { | |
449 | |
450 /* start of U superblocks */ | |
451 right_edge = s->fragment_width / 2; | |
452 bottom_edge = s->fragment_height / 2; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
453 current_width = -1; |
1224 | 454 current_height = 0; |
2967 | 455 superblock_row_inc = 3 * (s->fragment_width / 2) - |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
456 (s->c_superblock_width * 4 - s->fragment_width / 2); |
1224 | 457 hilbert = hilbert_walk_c; |
458 | |
459 /* the first operation for this variable is to advance by 1 */ | |
460 current_fragment = s->u_fragment_start - 1; | |
461 | |
462 } else if (i == s->v_superblock_start) { | |
463 | |
464 /* start of V superblocks */ | |
465 right_edge = s->fragment_width / 2; | |
466 bottom_edge = s->fragment_height / 2; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
467 current_width = -1; |
1224 | 468 current_height = 0; |
2967 | 469 superblock_row_inc = 3 * (s->fragment_width / 2) - |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
470 (s->c_superblock_width * 4 - s->fragment_width / 2); |
1224 | 471 hilbert = hilbert_walk_c; |
472 | |
473 /* the first operation for this variable is to advance by 1 */ | |
474 current_fragment = s->v_fragment_start - 1; | |
475 | |
476 } | |
477 | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
478 if (current_width >= right_edge - 1) { |
1224 | 479 /* reset width and move to next superblock row */ |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
480 current_width = -1; |
1224 | 481 current_height += 4; |
482 | |
483 /* fragment is now at the start of a new superblock row */ | |
484 current_fragment += superblock_row_inc; | |
485 } | |
486 | |
487 /* iterate through all 16 fragments in a superblock */ | |
488 for (j = 0; j < 16; j++) { | |
489 current_fragment += hilbert[j]; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
490 current_width += travel_width[j]; |
1224 | 491 current_height += travel_height[j]; |
492 | |
493 /* check if the fragment is in bounds */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
494 if ((current_width < right_edge) && |
1224 | 495 (current_height < bottom_edge)) { |
496 s->superblock_fragments[mapping_index] = current_fragment; | |
2967 | 497 debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
498 s->superblock_fragments[mapping_index], i, j, |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
499 current_width, right_edge, current_height, bottom_edge); |
1224 | 500 } else { |
501 s->superblock_fragments[mapping_index] = -1; | |
2967 | 502 debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
503 i, j, |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
504 current_width, right_edge, current_height, bottom_edge); |
1224 | 505 } |
506 | |
507 mapping_index++; | |
508 } | |
509 } | |
510 | |
511 /* initialize the superblock <-> macroblock mapping; iterate through | |
512 * all of the Y plane superblocks to build this mapping */ | |
513 right_edge = s->macroblock_width; | |
514 bottom_edge = s->macroblock_height; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
515 current_width = -1; |
1224 | 516 current_height = 0; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
517 superblock_row_inc = s->macroblock_width - |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
518 (s->y_superblock_width * 2 - s->macroblock_width);; |
1224 | 519 hilbert = hilbert_walk_mb; |
520 mapping_index = 0; | |
521 current_macroblock = -1; | |
522 for (i = 0; i < s->u_superblock_start; i++) { | |
523 | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
524 if (current_width >= right_edge - 1) { |
1224 | 525 /* reset width and move to next superblock row */ |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
526 current_width = -1; |
1224 | 527 current_height += 2; |
528 | |
529 /* macroblock is now at the start of a new superblock row */ | |
530 current_macroblock += superblock_row_inc; | |
531 } | |
532 | |
533 /* iterate through each potential macroblock in the superblock */ | |
534 for (j = 0; j < 4; j++) { | |
535 current_macroblock += hilbert_walk_mb[j]; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
536 current_width += travel_width_mb[j]; |
1224 | 537 current_height += travel_height_mb[j]; |
538 | |
539 /* check if the macroblock is in bounds */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
540 if ((current_width < right_edge) && |
1224 | 541 (current_height < bottom_edge)) { |
542 s->superblock_macroblocks[mapping_index] = current_macroblock; | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
543 debug_init(" mapping macroblock %d to superblock %d, position %d (%d/%d x %d/%d)\n", |
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
544 s->superblock_macroblocks[mapping_index], i, j, |
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
545 current_width, right_edge, current_height, bottom_edge); |
1224 | 546 } else { |
547 s->superblock_macroblocks[mapping_index] = -1; | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
548 debug_init(" superblock %d, position %d has no macroblock (%d/%d x %d/%d)\n", |
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
549 i, j, |
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
550 current_width, right_edge, current_height, bottom_edge); |
1224 | 551 } |
552 | |
553 mapping_index++; | |
554 } | |
555 } | |
556 | |
557 /* initialize the macroblock <-> fragment mapping */ | |
558 current_fragment = 0; | |
559 current_macroblock = 0; | |
560 mapping_index = 0; | |
561 for (i = 0; i < s->fragment_height; i += 2) { | |
562 | |
563 for (j = 0; j < s->fragment_width; j += 2) { | |
564 | |
565 debug_init(" macroblock %d contains fragments: ", current_macroblock); | |
566 s->all_fragments[current_fragment].macroblock = current_macroblock; | |
567 s->macroblock_fragments[mapping_index++] = current_fragment; | |
568 debug_init("%d ", current_fragment); | |
569 | |
570 if (j + 1 < s->fragment_width) { | |
571 s->all_fragments[current_fragment + 1].macroblock = current_macroblock; | |
572 s->macroblock_fragments[mapping_index++] = current_fragment + 1; | |
573 debug_init("%d ", current_fragment + 1); | |
574 } else | |
575 s->macroblock_fragments[mapping_index++] = -1; | |
576 | |
577 if (i + 1 < s->fragment_height) { | |
2967 | 578 s->all_fragments[current_fragment + s->fragment_width].macroblock = |
1224 | 579 current_macroblock; |
2967 | 580 s->macroblock_fragments[mapping_index++] = |
1224 | 581 current_fragment + s->fragment_width; |
582 debug_init("%d ", current_fragment + s->fragment_width); | |
583 } else | |
584 s->macroblock_fragments[mapping_index++] = -1; | |
585 | |
586 if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) { | |
2967 | 587 s->all_fragments[current_fragment + s->fragment_width + 1].macroblock = |
1224 | 588 current_macroblock; |
2967 | 589 s->macroblock_fragments[mapping_index++] = |
1224 | 590 current_fragment + s->fragment_width + 1; |
591 debug_init("%d ", current_fragment + s->fragment_width + 1); | |
592 } else | |
593 s->macroblock_fragments[mapping_index++] = -1; | |
594 | |
595 /* C planes */ | |
2967 | 596 c_fragment = s->u_fragment_start + |
1224 | 597 (i * s->fragment_width / 4) + (j / 2); |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
598 s->all_fragments[c_fragment].macroblock = s->macroblock_count; |
1224 | 599 s->macroblock_fragments[mapping_index++] = c_fragment; |
600 debug_init("%d ", c_fragment); | |
601 | |
2967 | 602 c_fragment = s->v_fragment_start + |
1224 | 603 (i * s->fragment_width / 4) + (j / 2); |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
604 s->all_fragments[c_fragment].macroblock = s->macroblock_count; |
1224 | 605 s->macroblock_fragments[mapping_index++] = c_fragment; |
606 debug_init("%d ", c_fragment); | |
607 | |
608 debug_init("\n"); | |
609 | |
610 if (j + 2 <= s->fragment_width) | |
611 current_fragment += 2; | |
2967 | 612 else |
1224 | 613 current_fragment++; |
614 current_macroblock++; | |
615 } | |
616 | |
617 current_fragment += s->fragment_width; | |
618 } | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
619 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
620 return 0; /* successful path out */ |
1224 | 621 } |
622 | |
623 /* | |
624 * This function wipes out all of the fragment data. | |
625 */ | |
626 static void init_frame(Vp3DecodeContext *s, GetBitContext *gb) | |
627 { | |
628 int i; | |
629 | |
630 /* zero out all of the fragment information */ | |
631 s->coded_fragment_list_index = 0; | |
632 for (i = 0; i < s->fragment_count; i++) { | |
633 s->all_fragments[i].coeff_count = 0; | |
2721 | 634 s->all_fragments[i].motion_x = 127; |
635 s->all_fragments[i].motion_y = 127; | |
636 s->all_fragments[i].next_coeff= NULL; | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
637 s->coeffs[i].index= |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
638 s->coeffs[i].coeff=0; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
639 s->coeffs[i].next= NULL; |
1224 | 640 } |
641 } | |
642 | |
643 /* | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
644 * This function sets up the dequantization tables used for a particular |
1224 | 645 * frame. |
646 */ | |
647 static void init_dequantizer(Vp3DecodeContext *s) | |
648 { | |
1867
7f7aa6ac3723
cut over to using new VP3 DSP functions and remove the old ones; bring
melanson
parents:
1864
diff
changeset
|
649 int ac_scale_factor = s->coded_ac_scale_factor[s->quality_index]; |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
650 int dc_scale_factor = s->coded_dc_scale_factor[s->quality_index]; |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
651 int i, j, plane, inter, qri, bmi, bmj, qistart; |
1224 | 652 |
653 debug_vp3(" vp3: initializing dequantization tables\n"); | |
654 | |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
655 for(inter=0; inter<2; inter++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
656 for(plane=0; plane<3; plane++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
657 int sum=0; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
658 for(qri=0; qri<s->qr_count[inter][plane]; qri++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
659 sum+= s->qr_size[inter][plane][qri]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
660 if(s->quality_index <= sum) |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
661 break; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
662 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
663 qistart= sum - s->qr_size[inter][plane][qri]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
664 bmi= s->qr_base[inter][plane][qri ]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
665 bmj= s->qr_base[inter][plane][qri+1]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
666 for(i=0; i<64; i++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
667 int coeff= ( 2*(sum -s->quality_index)*s->base_matrix[bmi][i] |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
668 - 2*(qistart-s->quality_index)*s->base_matrix[bmj][i] |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
669 + s->qr_size[inter][plane][qri]) |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
670 / (2*s->qr_size[inter][plane][qri]); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
671 |
3491 | 672 int qmin= 8<<(inter + !i); |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
673 int qscale= i ? ac_scale_factor : dc_scale_factor; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
674 |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
675 s->qmat[inter][plane][i]= clip((qscale * coeff)/100 * 4, qmin, 4096); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
676 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
677 } |
1224 | 678 } |
2967 | 679 |
3488
a647bf3a7fa8
replace *_dequant (2 intra, 1 inter) by qmat (3 intra, 3 inter) (needed for theora according to spec)
michael
parents:
3487
diff
changeset
|
680 memset(s->qscale_table, (FFMAX(s->qmat[0][0][1], s->qmat[0][1][1])+8)/16, 512); //FIXME finetune |
1224 | 681 } |
682 | |
683 /* | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
684 * This function initializes the loop filter boundary limits if the frame's |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
685 * quality index is different from the previous frame's. |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
686 */ |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
687 static void init_loop_filter(Vp3DecodeContext *s) |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
688 { |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
689 int *bounding_values= s->bounding_values_array+127; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
690 int filter_limit; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
691 int x; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
692 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
693 filter_limit = s->filter_limit_values[s->quality_index]; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
694 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
695 /* set up the bounding values */ |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
696 memset(s->bounding_values_array, 0, 256 * sizeof(int)); |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
697 for (x = 0; x < filter_limit; x++) { |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
698 bounding_values[-x - filter_limit] = -filter_limit + x; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
699 bounding_values[-x] = -x; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
700 bounding_values[x] = x; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
701 bounding_values[x + filter_limit] = filter_limit - x; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
702 } |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
703 } |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
704 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
705 /* |
2967 | 706 * This function unpacks all of the superblock/macroblock/fragment coding |
1224 | 707 * information from the bitstream. |
708 */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
709 static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) |
1224 | 710 { |
711 int bit = 0; | |
712 int current_superblock = 0; | |
713 int current_run = 0; | |
714 int decode_fully_flags = 0; | |
715 int decode_partial_blocks = 0; | |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
716 int first_c_fragment_seen; |
1224 | 717 |
718 int i, j; | |
719 int current_fragment; | |
720 | |
721 debug_vp3(" vp3: unpacking superblock coding\n"); | |
722 | |
723 if (s->keyframe) { | |
724 | |
725 debug_vp3(" keyframe-- all superblocks are fully coded\n"); | |
726 memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count); | |
727 | |
728 } else { | |
729 | |
730 /* unpack the list of partially-coded superblocks */ | |
731 bit = get_bits(gb, 1); | |
2967 | 732 /* toggle the bit because as soon as the first run length is |
1224 | 733 * fetched the bit will be toggled again */ |
734 bit ^= 1; | |
735 while (current_superblock < s->superblock_count) { | |
2705 | 736 if (current_run-- == 0) { |
1224 | 737 bit ^= 1; |
2967 | 738 current_run = get_vlc2(gb, |
2705 | 739 s->superblock_run_length_vlc.table, 6, 2); |
740 if (current_run == 33) | |
2703
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
741 current_run += get_bits(gb, 12); |
1224 | 742 debug_block_coding(" setting superblocks %d..%d to %s\n", |
743 current_superblock, | |
744 current_superblock + current_run - 1, | |
745 (bit) ? "partially coded" : "not coded"); | |
746 | |
747 /* if any of the superblocks are not partially coded, flag | |
748 * a boolean to decode the list of fully-coded superblocks */ | |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
749 if (bit == 0) { |
1224 | 750 decode_fully_flags = 1; |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
751 } else { |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
752 |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
753 /* make a note of the fact that there are partially coded |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
754 * superblocks */ |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
755 decode_partial_blocks = 1; |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
756 } |
1224 | 757 } |
2705 | 758 s->superblock_coding[current_superblock++] = bit; |
1224 | 759 } |
760 | |
761 /* unpack the list of fully coded superblocks if any of the blocks were | |
762 * not marked as partially coded in the previous step */ | |
763 if (decode_fully_flags) { | |
764 | |
765 current_superblock = 0; | |
766 current_run = 0; | |
767 bit = get_bits(gb, 1); | |
2967 | 768 /* toggle the bit because as soon as the first run length is |
1224 | 769 * fetched the bit will be toggled again */ |
770 bit ^= 1; | |
771 while (current_superblock < s->superblock_count) { | |
772 | |
773 /* skip any superblocks already marked as partially coded */ | |
774 if (s->superblock_coding[current_superblock] == SB_NOT_CODED) { | |
775 | |
2705 | 776 if (current_run-- == 0) { |
1224 | 777 bit ^= 1; |
2967 | 778 current_run = get_vlc2(gb, |
2705 | 779 s->superblock_run_length_vlc.table, 6, 2); |
780 if (current_run == 33) | |
2703
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
781 current_run += get_bits(gb, 12); |
1224 | 782 } |
783 | |
784 debug_block_coding(" setting superblock %d to %s\n", | |
785 current_superblock, | |
786 (bit) ? "fully coded" : "not coded"); | |
2705 | 787 s->superblock_coding[current_superblock] = 2*bit; |
1224 | 788 } |
789 current_superblock++; | |
790 } | |
791 } | |
792 | |
793 /* if there were partial blocks, initialize bitstream for | |
794 * unpacking fragment codings */ | |
795 if (decode_partial_blocks) { | |
796 | |
797 current_run = 0; | |
798 bit = get_bits(gb, 1); | |
2967 | 799 /* toggle the bit because as soon as the first run length is |
1224 | 800 * fetched the bit will be toggled again */ |
801 bit ^= 1; | |
802 } | |
803 } | |
804 | |
805 /* figure out which fragments are coded; iterate through each | |
806 * superblock (all planes) */ | |
807 s->coded_fragment_list_index = 0; | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
808 s->next_coeff= s->coeffs + s->fragment_count; |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
809 s->first_coded_y_fragment = s->first_coded_c_fragment = 0; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
810 s->last_coded_y_fragment = s->last_coded_c_fragment = -1; |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
811 first_c_fragment_seen = 0; |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
812 memset(s->macroblock_coding, MODE_COPY, s->macroblock_count); |
1224 | 813 for (i = 0; i < s->superblock_count; i++) { |
814 | |
815 /* iterate through all 16 fragments in a superblock */ | |
816 for (j = 0; j < 16; j++) { | |
817 | |
818 /* if the fragment is in bounds, check its coding status */ | |
819 current_fragment = s->superblock_fragments[i * 16 + j]; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
820 if (current_fragment >= s->fragment_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
821 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_superblocks(): bad fragment number (%d >= %d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
822 current_fragment, s->fragment_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
823 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
824 } |
1224 | 825 if (current_fragment != -1) { |
826 if (s->superblock_coding[i] == SB_NOT_CODED) { | |
827 | |
828 /* copy all the fragments from the prior frame */ | |
2967 | 829 s->all_fragments[current_fragment].coding_method = |
1224 | 830 MODE_COPY; |
831 | |
832 } else if (s->superblock_coding[i] == SB_PARTIALLY_CODED) { | |
833 | |
834 /* fragment may or may not be coded; this is the case | |
835 * that cares about the fragment coding runs */ | |
2705 | 836 if (current_run-- == 0) { |
1224 | 837 bit ^= 1; |
2967 | 838 current_run = get_vlc2(gb, |
2705 | 839 s->fragment_run_length_vlc.table, 5, 2); |
1224 | 840 } |
841 | |
842 if (bit) { | |
2967 | 843 /* default mode; actual mode will be decoded in |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
844 * the next phase */ |
2967 | 845 s->all_fragments[current_fragment].coding_method = |
1224 | 846 MODE_INTER_NO_MV; |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
847 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; |
2967 | 848 s->coded_fragment_list[s->coded_fragment_list_index] = |
1224 | 849 current_fragment; |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
850 if ((current_fragment >= s->u_fragment_start) && |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
851 (s->last_coded_y_fragment == -1) && |
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
852 (!first_c_fragment_seen)) { |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
853 s->first_coded_c_fragment = s->coded_fragment_list_index; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
854 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
855 first_c_fragment_seen = 1; |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
856 } |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
857 s->coded_fragment_list_index++; |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
858 s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV; |
1224 | 859 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n", |
860 i, current_fragment); | |
861 } else { | |
862 /* not coded; copy this fragment from the prior frame */ | |
863 s->all_fragments[current_fragment].coding_method = | |
864 MODE_COPY; | |
865 debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n", | |
866 i, current_fragment); | |
867 } | |
868 | |
869 } else { | |
870 | |
871 /* fragments are fully coded in this superblock; actual | |
872 * coding will be determined in next step */ | |
2967 | 873 s->all_fragments[current_fragment].coding_method = |
1224 | 874 MODE_INTER_NO_MV; |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
875 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; |
2967 | 876 s->coded_fragment_list[s->coded_fragment_list_index] = |
1224 | 877 current_fragment; |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
878 if ((current_fragment >= s->u_fragment_start) && |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
879 (s->last_coded_y_fragment == -1) && |
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
880 (!first_c_fragment_seen)) { |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
881 s->first_coded_c_fragment = s->coded_fragment_list_index; |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
882 s->last_coded_y_fragment = s->first_coded_c_fragment - 1; |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
883 first_c_fragment_seen = 1; |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
884 } |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
885 s->coded_fragment_list_index++; |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
886 s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV; |
1224 | 887 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n", |
888 i, current_fragment); | |
889 } | |
890 } | |
891 } | |
892 } | |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
893 |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
894 if (!first_c_fragment_seen) |
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
895 /* only Y fragments coded in this frame */ |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
896 s->last_coded_y_fragment = s->coded_fragment_list_index - 1; |
2967 | 897 else |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
898 /* end the list of coded C fragments */ |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
899 s->last_coded_c_fragment = s->coded_fragment_list_index - 1; |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
900 |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
901 debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n", |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
902 s->coded_fragment_list_index, |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
903 s->first_coded_y_fragment, |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
904 s->last_coded_y_fragment, |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
905 s->first_coded_c_fragment, |
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
906 s->last_coded_c_fragment); |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
907 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
908 return 0; |
1224 | 909 } |
910 | |
911 /* | |
912 * This function unpacks all the coding mode data for individual macroblocks | |
913 * from the bitstream. | |
914 */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
915 static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb) |
1224 | 916 { |
917 int i, j, k; | |
918 int scheme; | |
919 int current_macroblock; | |
920 int current_fragment; | |
921 int coding_mode; | |
922 | |
923 debug_vp3(" vp3: unpacking encoding modes\n"); | |
924 | |
925 if (s->keyframe) { | |
926 debug_vp3(" keyframe-- all blocks are coded as INTRA\n"); | |
927 | |
928 for (i = 0; i < s->fragment_count; i++) | |
929 s->all_fragments[i].coding_method = MODE_INTRA; | |
930 | |
931 } else { | |
932 | |
933 /* fetch the mode coding scheme for this frame */ | |
934 scheme = get_bits(gb, 3); | |
935 debug_modes(" using mode alphabet %d\n", scheme); | |
936 | |
937 /* is it a custom coding scheme? */ | |
938 if (scheme == 0) { | |
939 debug_modes(" custom mode alphabet ahead:\n"); | |
940 for (i = 0; i < 8; i++) | |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
941 ModeAlphabet[scheme][get_bits(gb, 3)] = i; |
1224 | 942 } |
943 | |
944 for (i = 0; i < 8; i++) | |
2967 | 945 debug_modes(" mode[%d][%d] = %d\n", scheme, i, |
1224 | 946 ModeAlphabet[scheme][i]); |
947 | |
948 /* iterate through all of the macroblocks that contain 1 or more | |
949 * coded fragments */ | |
950 for (i = 0; i < s->u_superblock_start; i++) { | |
951 | |
952 for (j = 0; j < 4; j++) { | |
953 current_macroblock = s->superblock_macroblocks[i * 4 + j]; | |
954 if ((current_macroblock == -1) || | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
955 (s->macroblock_coding[current_macroblock] == MODE_COPY)) |
1224 | 956 continue; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
957 if (current_macroblock >= s->macroblock_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
958 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad macroblock number (%d >= %d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
959 current_macroblock, s->macroblock_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
960 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
961 } |
1224 | 962 |
963 /* mode 7 means get 3 bits for each coding mode */ | |
964 if (scheme == 7) | |
965 coding_mode = get_bits(gb, 3); | |
966 else | |
2702
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
967 coding_mode = ModeAlphabet[scheme] |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
968 [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; |
1224 | 969 |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
970 s->macroblock_coding[current_macroblock] = coding_mode; |
1224 | 971 for (k = 0; k < 6; k++) { |
2967 | 972 current_fragment = |
1224 | 973 s->macroblock_fragments[current_macroblock * 6 + k]; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
974 if (current_fragment == -1) |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
975 continue; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
976 if (current_fragment >= s->fragment_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
977 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad fragment number (%d >= %d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
978 current_fragment, s->fragment_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
979 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
980 } |
2967 | 981 if (s->all_fragments[current_fragment].coding_method != |
1224 | 982 MODE_COPY) |
983 s->all_fragments[current_fragment].coding_method = | |
984 coding_mode; | |
985 } | |
986 | |
987 debug_modes(" coding method for macroblock starting @ fragment %d = %d\n", | |
988 s->macroblock_fragments[current_macroblock * 6], coding_mode); | |
989 } | |
990 } | |
991 } | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
992 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
993 return 0; |
1229
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
994 } |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
995 |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
996 /* |
1224 | 997 * This function unpacks all the motion vectors for the individual |
998 * macroblocks from the bitstream. | |
999 */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1000 static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) |
1224 | 1001 { |
1002 int i, j, k; | |
1003 int coding_mode; | |
1004 int motion_x[6]; | |
1005 int motion_y[6]; | |
1006 int last_motion_x = 0; | |
1007 int last_motion_y = 0; | |
1008 int prior_last_motion_x = 0; | |
1009 int prior_last_motion_y = 0; | |
1010 int current_macroblock; | |
1011 int current_fragment; | |
1012 | |
1013 debug_vp3(" vp3: unpacking motion vectors\n"); | |
1014 if (s->keyframe) { | |
1015 | |
1016 debug_vp3(" keyframe-- there are no motion vectors\n"); | |
1017 | |
1018 } else { | |
1019 | |
1020 memset(motion_x, 0, 6 * sizeof(int)); | |
1021 memset(motion_y, 0, 6 * sizeof(int)); | |
1022 | |
1023 /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */ | |
1024 coding_mode = get_bits(gb, 1); | |
1025 debug_vectors(" using %s scheme for unpacking motion vectors\n", | |
1026 (coding_mode == 0) ? "VLC" : "fixed-length"); | |
1027 | |
1028 /* iterate through all of the macroblocks that contain 1 or more | |
1029 * coded fragments */ | |
1030 for (i = 0; i < s->u_superblock_start; i++) { | |
1031 | |
1032 for (j = 0; j < 4; j++) { | |
1033 current_macroblock = s->superblock_macroblocks[i * 4 + j]; | |
1034 if ((current_macroblock == -1) || | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
1035 (s->macroblock_coding[current_macroblock] == MODE_COPY)) |
1224 | 1036 continue; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1037 if (current_macroblock >= s->macroblock_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
1038 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad macroblock number (%d >= %d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1039 current_macroblock, s->macroblock_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1040 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1041 } |
1224 | 1042 |
1043 current_fragment = s->macroblock_fragments[current_macroblock * 6]; | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1044 if (current_fragment >= s->fragment_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
1045 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1046 current_fragment, s->fragment_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1047 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1048 } |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
1049 switch (s->macroblock_coding[current_macroblock]) { |
1224 | 1050 |
1051 case MODE_INTER_PLUS_MV: | |
1052 case MODE_GOLDEN_MV: | |
1053 /* all 6 fragments use the same motion vector */ | |
1054 if (coding_mode == 0) { | |
2702
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
1055 motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
1056 motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
1224 | 1057 } else { |
2719
5444d77adcbe
another bitstream extraction to optimize: fixed-length motion vectors
melanson
parents:
2718
diff
changeset
|
1058 motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; |
5444d77adcbe
another bitstream extraction to optimize: fixed-length motion vectors
melanson
parents:
2718
diff
changeset
|
1059 motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; |
1224 | 1060 } |
2719
5444d77adcbe
another bitstream extraction to optimize: fixed-length motion vectors
melanson
parents:
2718
diff
changeset
|
1061 |
1224 | 1062 for (k = 1; k < 6; k++) { |
1063 motion_x[k] = motion_x[0]; | |
1064 motion_y[k] = motion_y[0]; | |
1065 } | |
1066 | |
1067 /* vector maintenance, only on MODE_INTER_PLUS_MV */ | |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
1068 if (s->macroblock_coding[current_macroblock] == |
1224 | 1069 MODE_INTER_PLUS_MV) { |
1070 prior_last_motion_x = last_motion_x; | |
1071 prior_last_motion_y = last_motion_y; | |
1072 last_motion_x = motion_x[0]; | |
1073 last_motion_y = motion_y[0]; | |
1074 } | |
1075 break; | |
1076 | |
1077 case MODE_INTER_FOURMV: | |
1078 /* fetch 4 vectors from the bitstream, one for each | |
1079 * Y fragment, then average for the C fragment vectors */ | |
1080 motion_x[4] = motion_y[4] = 0; | |
1081 for (k = 0; k < 4; k++) { | |
1082 if (coding_mode == 0) { | |
2709 | 1083 motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
1084 motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; | |
1224 | 1085 } else { |
2719
5444d77adcbe
another bitstream extraction to optimize: fixed-length motion vectors
melanson
parents:
2718
diff
changeset
|
1086 motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; |
5444d77adcbe
another bitstream extraction to optimize: fixed-length motion vectors
melanson
parents:
2718
diff
changeset
|
1087 motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; |
1224 | 1088 } |
1089 motion_x[4] += motion_x[k]; | |
1090 motion_y[4] += motion_y[k]; | |
1091 } | |
1092 | |
3487 | 1093 motion_x[5]= |
1094 motion_x[4]= RSHIFT(motion_x[4], 2); | |
1095 motion_y[5]= | |
1096 motion_y[4]= RSHIFT(motion_y[4], 2); | |
1224 | 1097 |
1098 /* vector maintenance; vector[3] is treated as the | |
1099 * last vector in this case */ | |
1100 prior_last_motion_x = last_motion_x; | |
1101 prior_last_motion_y = last_motion_y; | |
1102 last_motion_x = motion_x[3]; | |
1103 last_motion_y = motion_y[3]; | |
1104 break; | |
1105 | |
1106 case MODE_INTER_LAST_MV: | |
1107 /* all 6 fragments use the last motion vector */ | |
1108 motion_x[0] = last_motion_x; | |
1109 motion_y[0] = last_motion_y; | |
1110 for (k = 1; k < 6; k++) { | |
1111 motion_x[k] = motion_x[0]; | |
1112 motion_y[k] = motion_y[0]; | |
1113 } | |
1114 | |
1115 /* no vector maintenance (last vector remains the | |
1116 * last vector) */ | |
1117 break; | |
1118 | |
1119 case MODE_INTER_PRIOR_LAST: | |
1120 /* all 6 fragments use the motion vector prior to the | |
1121 * last motion vector */ | |
1122 motion_x[0] = prior_last_motion_x; | |
1123 motion_y[0] = prior_last_motion_y; | |
1124 for (k = 1; k < 6; k++) { | |
1125 motion_x[k] = motion_x[0]; | |
1126 motion_y[k] = motion_y[0]; | |
1127 } | |
1128 | |
1129 /* vector maintenance */ | |
1130 prior_last_motion_x = last_motion_x; | |
1131 prior_last_motion_y = last_motion_y; | |
1132 last_motion_x = motion_x[0]; | |
1133 last_motion_y = motion_y[0]; | |
1134 break; | |
1229
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1135 |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1136 default: |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1137 /* covers intra, inter without MV, golden without MV */ |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1138 memset(motion_x, 0, 6 * sizeof(int)); |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1139 memset(motion_y, 0, 6 * sizeof(int)); |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1140 |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1141 /* no vector maintenance */ |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1142 break; |
1224 | 1143 } |
1144 | |
1145 /* assign the motion vectors to the correct fragments */ | |
1146 debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n", | |
1147 current_fragment, | |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
1148 s->macroblock_coding[current_macroblock]); |
1224 | 1149 for (k = 0; k < 6; k++) { |
2967 | 1150 current_fragment = |
1224 | 1151 s->macroblock_fragments[current_macroblock * 6 + k]; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1152 if (current_fragment == -1) |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1153 continue; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1154 if (current_fragment >= s->fragment_count) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
1155 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d)\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1156 current_fragment, s->fragment_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1157 return 1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1158 } |
1224 | 1159 s->all_fragments[current_fragment].motion_x = motion_x[k]; |
1229
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
1160 s->all_fragments[current_fragment].motion_y = motion_y[k]; |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
1161 debug_vectors(" vector %d: fragment %d = (%d, %d)\n", |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
1162 k, current_fragment, motion_x[k], motion_y[k]); |
1224 | 1163 } |
1164 } | |
1165 } | |
1166 } | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1167 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1168 return 0; |
1224 | 1169 } |
1170 | |
2967 | 1171 /* |
1224 | 1172 * This function is called by unpack_dct_coeffs() to extract the VLCs from |
1173 * the bitstream. The VLCs encode tokens which are used to unpack DCT | |
1174 * data. This function unpacks all the VLCs for either the Y plane or both | |
1175 * C planes, and is called for DC coefficients or different AC coefficient | |
1176 * levels (since different coefficient types require different VLC tables. | |
1177 * | |
1178 * This function returns a residual eob run. E.g, if a particular token gave | |
1179 * instructions to EOB the next 5 fragments and there were only 2 fragments | |
1180 * left in the current fragment range, 3 would be returned so that it could | |
1181 * be passed into the next call to this same function. | |
1182 */ | |
1183 static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, | |
1184 VLC *table, int coeff_index, | |
1185 int first_fragment, int last_fragment, | |
1186 int eob_run) | |
1187 { | |
1188 int i; | |
1189 int token; | |
2712
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1190 int zero_run = 0; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1191 DCTELEM coeff = 0; |
1224 | 1192 Vp3Fragment *fragment; |
2694 | 1193 uint8_t *perm= s->scantable.permutated; |
2712
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1194 int bits_to_get; |
1224 | 1195 |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
1196 if ((first_fragment >= s->fragment_count) || |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
1197 (last_fragment >= s->fragment_count)) { |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
1198 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
1199 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vlcs(): bad fragment number (%d -> %d ?)\n", |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
1200 first_fragment, last_fragment); |
1272
777d4145cdfb
fix subtle logic problem in block unpacker that leads to incorrect token
tmmm
parents:
1244
diff
changeset
|
1201 return 0; |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
1202 } |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
1203 |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1204 for (i = first_fragment; i <= last_fragment; i++) { |
1224 | 1205 |
1206 fragment = &s->all_fragments[s->coded_fragment_list[i]]; | |
1207 if (fragment->coeff_count > coeff_index) | |
1208 continue; | |
1209 | |
1210 if (!eob_run) { | |
1211 /* decode a VLC into a token */ | |
1212 token = get_vlc2(gb, table->table, 5, 3); | |
1213 debug_vlc(" token = %2d, ", token); | |
1214 /* use the token to get a zero run, a coefficient, and an eob run */ | |
2712
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1215 if (token <= 6) { |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1216 eob_run = eob_run_base[token]; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1217 if (eob_run_get_bits[token]) |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1218 eob_run += get_bits(gb, eob_run_get_bits[token]); |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1219 coeff = zero_run = 0; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1220 } else { |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1221 bits_to_get = coeff_get_bits[token]; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1222 if (!bits_to_get) |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1223 coeff = coeff_tables[token][0]; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1224 else |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1225 coeff = coeff_tables[token][get_bits(gb, bits_to_get)]; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1226 |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1227 zero_run = zero_run_base[token]; |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1228 if (zero_run_get_bits[token]) |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1229 zero_run += get_bits(gb, zero_run_get_bits[token]); |
9c1a436dac6b
replace unpack_token() with a series of lookup tables
melanson
parents:
2709
diff
changeset
|
1230 } |
1224 | 1231 } |
1232 | |
1233 if (!eob_run) { | |
1234 fragment->coeff_count += zero_run; | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1235 if (fragment->coeff_count < 64){ |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1236 fragment->next_coeff->coeff= coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1237 fragment->next_coeff->index= perm[fragment->coeff_count++]; //FIXME perm here already? |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1238 fragment->next_coeff->next= s->next_coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1239 s->next_coeff->next=NULL; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1240 fragment->next_coeff= s->next_coeff++; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1241 } |
1224 | 1242 debug_vlc(" fragment %d coeff = %d\n", |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1243 s->coded_fragment_list[i], fragment->next_coeff[coeff_index]); |
1224 | 1244 } else { |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1245 fragment->coeff_count |= 128; |
2967 | 1246 debug_vlc(" fragment %d eob with %d coefficients\n", |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1247 s->coded_fragment_list[i], fragment->coeff_count&127); |
1224 | 1248 eob_run--; |
1249 } | |
1250 } | |
1251 | |
1252 return eob_run; | |
1253 } | |
1254 | |
1255 /* | |
1256 * This function unpacks all of the DCT coefficient data from the | |
1257 * bitstream. | |
1258 */ | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1259 static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) |
1224 | 1260 { |
1261 int i; | |
1262 int dc_y_table; | |
1263 int dc_c_table; | |
1264 int ac_y_table; | |
1265 int ac_c_table; | |
1266 int residual_eob_run = 0; | |
1267 | |
1268 /* fetch the DC table indices */ | |
1269 dc_y_table = get_bits(gb, 4); | |
1270 dc_c_table = get_bits(gb, 4); | |
1271 | |
1272 /* unpack the Y plane DC coefficients */ | |
1273 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n", | |
1274 dc_y_table); | |
2967 | 1275 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1276 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1224 | 1277 |
1278 /* unpack the C plane DC coefficients */ | |
1279 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n", | |
1280 dc_c_table); | |
1281 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, | |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1282 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1224 | 1283 |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
1284 /* fetch the AC table indices */ |
1224 | 1285 ac_y_table = get_bits(gb, 4); |
1286 ac_c_table = get_bits(gb, 4); | |
1287 | |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
1288 /* unpack the group 1 AC coefficients (coeffs 1-5) */ |
1224 | 1289 for (i = 1; i <= 5; i++) { |
1290 | |
1291 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | |
1292 i, ac_y_table); | |
2967 | 1293 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1294 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1224 | 1295 |
1296 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | |
1297 i, ac_c_table); | |
2967 | 1298 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1299 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1224 | 1300 } |
1301 | |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
1302 /* unpack the group 2 AC coefficients (coeffs 6-14) */ |
1224 | 1303 for (i = 6; i <= 14; i++) { |
1304 | |
1305 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | |
1306 i, ac_y_table); | |
2967 | 1307 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1308 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1224 | 1309 |
1310 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | |
1311 i, ac_c_table); | |
2967 | 1312 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1313 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1224 | 1314 } |
1315 | |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
1316 /* unpack the group 3 AC coefficients (coeffs 15-27) */ |
1224 | 1317 for (i = 15; i <= 27; i++) { |
1318 | |
1319 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | |
1320 i, ac_y_table); | |
2967 | 1321 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1322 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1224 | 1323 |
1324 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | |
1325 i, ac_c_table); | |
2967 | 1326 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1327 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1224 | 1328 } |
1329 | |
1233
5d66713e97e2
correct the custom coding mode alphabet, add some validation on the
tmmm
parents:
1230
diff
changeset
|
1330 /* unpack the group 4 AC coefficients (coeffs 28-63) */ |
1224 | 1331 for (i = 28; i <= 63; i++) { |
1332 | |
1333 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", | |
1334 i, ac_y_table); | |
2967 | 1335 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1336 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); |
1224 | 1337 |
1338 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", | |
1339 i, ac_c_table); | |
2967 | 1340 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, |
1236
d6e4784ffc16
dump the shady binary search logic (the part that binary searches
tmmm
parents:
1233
diff
changeset
|
1341 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); |
1224 | 1342 } |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1343 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
1344 return 0; |
1224 | 1345 } |
1346 | |
1347 /* | |
1348 * This function reverses the DC prediction for each coded fragment in | |
2967 | 1349 * the frame. Much of this function is adapted directly from the original |
1224 | 1350 * VP3 source code. |
1351 */ | |
1352 #define COMPATIBLE_FRAME(x) \ | |
1353 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type) | |
1354 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY) | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1355 #define DC_COEFF(u) (s->coeffs[u].index ? 0 : s->coeffs[u].coeff) //FIXME do somethin to simplify this |
1224 | 1356 static inline int iabs (int x) { return ((x < 0) ? -x : x); } |
1357 | |
1358 static void reverse_dc_prediction(Vp3DecodeContext *s, | |
1359 int first_fragment, | |
1360 int fragment_width, | |
2967 | 1361 int fragment_height) |
1224 | 1362 { |
1363 | |
1364 #define PUL 8 | |
1365 #define PU 4 | |
1366 #define PUR 2 | |
1367 #define PL 1 | |
1368 | |
1369 int x, y; | |
1370 int i = first_fragment; | |
1371 | |
1372 /* | |
1373 * Fragment prediction groups: | |
1374 * | |
1375 * 32222222226 | |
1376 * 10000000004 | |
1377 * 10000000004 | |
1378 * 10000000004 | |
1379 * 10000000004 | |
1380 * | |
2967 | 1381 * Note: Groups 5 and 7 do not exist as it would mean that the |
1224 | 1382 * fragment's x coordinate is both 0 and (width - 1) at the same time. |
1383 */ | |
1384 int predictor_group; | |
1385 short predicted_dc; | |
1386 | |
1387 /* validity flags for the left, up-left, up, and up-right fragments */ | |
1388 int fl, ful, fu, fur; | |
1389 | |
1390 /* DC values for the left, up-left, up, and up-right fragments */ | |
1391 int vl, vul, vu, vur; | |
1392 | |
1393 /* indices for the left, up-left, up, and up-right fragments */ | |
1394 int l, ul, u, ur; | |
1395 | |
2967 | 1396 /* |
1224 | 1397 * The 6 fields mean: |
1398 * 0: up-left multiplier | |
1399 * 1: up multiplier | |
1400 * 2: up-right multiplier | |
1401 * 3: left multiplier | |
1402 * 4: mask | |
1403 * 5: right bit shift divisor (e.g., 7 means >>=7, a.k.a. div by 128) | |
1404 */ | |
1405 int predictor_transform[16][6] = { | |
1406 { 0, 0, 0, 0, 0, 0 }, | |
1407 { 0, 0, 0, 1, 0, 0 }, // PL | |
1408 { 0, 0, 1, 0, 0, 0 }, // PUR | |
1409 { 0, 0, 53, 75, 127, 7 }, // PUR|PL | |
1410 { 0, 1, 0, 0, 0, 0 }, // PU | |
1411 { 0, 1, 0, 1, 1, 1 }, // PU|PL | |
1412 { 0, 1, 0, 0, 0, 0 }, // PU|PUR | |
1413 { 0, 0, 53, 75, 127, 7 }, // PU|PUR|PL | |
1414 { 1, 0, 0, 0, 0, 0 }, // PUL | |
1415 { 0, 0, 0, 1, 0, 0 }, // PUL|PL | |
1416 { 1, 0, 1, 0, 1, 1 }, // PUL|PUR | |
1417 { 0, 0, 53, 75, 127, 7 }, // PUL|PUR|PL | |
1418 { 0, 1, 0, 0, 0, 0 }, // PUL|PU | |
1419 {-26, 29, 0, 29, 31, 5 }, // PUL|PU|PL | |
1420 { 3, 10, 3, 0, 15, 4 }, // PUL|PU|PUR | |
1421 {-26, 29, 0, 29, 31, 5 } // PUL|PU|PUR|PL | |
1422 }; | |
1423 | |
1424 /* This table shows which types of blocks can use other blocks for | |
1425 * prediction. For example, INTRA is the only mode in this table to | |
1426 * have a frame number of 0. That means INTRA blocks can only predict | |
2967 | 1427 * from other INTRA blocks. There are 2 golden frame coding types; |
1224 | 1428 * blocks encoding in these modes can only predict from other blocks |
1429 * that were encoded with these 1 of these 2 modes. */ | |
1430 unsigned char compatible_frame[8] = { | |
1431 1, /* MODE_INTER_NO_MV */ | |
1432 0, /* MODE_INTRA */ | |
1433 1, /* MODE_INTER_PLUS_MV */ | |
1434 1, /* MODE_INTER_LAST_MV */ | |
1435 1, /* MODE_INTER_PRIOR_MV */ | |
1436 2, /* MODE_USING_GOLDEN */ | |
1437 2, /* MODE_GOLDEN_MV */ | |
1438 1 /* MODE_INTER_FOUR_MV */ | |
1439 }; | |
1440 int current_frame_type; | |
1441 | |
1442 /* there is a last DC predictor for each of the 3 frame types */ | |
1443 short last_dc[3]; | |
1444 | |
1445 int transform = 0; | |
1446 | |
1447 debug_vp3(" vp3: reversing DC prediction\n"); | |
1448 | |
1449 vul = vu = vur = vl = 0; | |
1450 last_dc[0] = last_dc[1] = last_dc[2] = 0; | |
1451 | |
1452 /* for each fragment row... */ | |
1453 for (y = 0; y < fragment_height; y++) { | |
1454 | |
1455 /* for each fragment in a row... */ | |
1456 for (x = 0; x < fragment_width; x++, i++) { | |
1457 | |
1458 /* reverse prediction if this block was coded */ | |
1459 if (s->all_fragments[i].coding_method != MODE_COPY) { | |
1460 | |
2967 | 1461 current_frame_type = |
1224 | 1462 compatible_frame[s->all_fragments[i].coding_method]; |
1463 predictor_group = (x == 0) + ((y == 0) << 1) + | |
1464 ((x + 1 == fragment_width) << 2); | |
1465 debug_dc_pred(" frag %d: group %d, orig DC = %d, ", | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1466 i, predictor_group, DC_COEFF(i)); |
1224 | 1467 |
1468 switch (predictor_group) { | |
1469 | |
1470 case 0: | |
1471 /* main body of fragments; consider all 4 possible | |
1472 * fragments for prediction */ | |
1473 | |
1474 /* calculate the indices of the predicting fragments */ | |
1475 ul = i - fragment_width - 1; | |
1476 u = i - fragment_width; | |
1477 ur = i - fragment_width + 1; | |
1478 l = i - 1; | |
1479 | |
1480 /* fetch the DC values for the predicting fragments */ | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1481 vul = DC_COEFF(ul); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1482 vu = DC_COEFF(u); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1483 vur = DC_COEFF(ur); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1484 vl = DC_COEFF(l); |
1224 | 1485 |
1486 /* figure out which fragments are valid */ | |
1487 ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul); | |
1488 fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u); | |
1489 fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur); | |
1490 fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l); | |
1491 | |
1492 /* decide which predictor transform to use */ | |
1493 transform = (fl*PL) | (fu*PU) | (ful*PUL) | (fur*PUR); | |
1494 | |
1495 break; | |
1496 | |
1497 case 1: | |
1498 /* left column of fragments, not including top corner; | |
1499 * only consider up and up-right fragments */ | |
1500 | |
1501 /* calculate the indices of the predicting fragments */ | |
1502 u = i - fragment_width; | |
1503 ur = i - fragment_width + 1; | |
1504 | |
1505 /* fetch the DC values for the predicting fragments */ | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1506 vu = DC_COEFF(u); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1507 vur = DC_COEFF(ur); |
1224 | 1508 |
1509 /* figure out which fragments are valid */ | |
1510 fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur); | |
1511 fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u); | |
1512 | |
1513 /* decide which predictor transform to use */ | |
1514 transform = (fu*PU) | (fur*PUR); | |
1515 | |
1516 break; | |
1517 | |
1518 case 2: | |
1519 case 6: | |
1520 /* top row of fragments, not including top-left frag; | |
1521 * only consider the left fragment for prediction */ | |
1522 | |
1523 /* calculate the indices of the predicting fragments */ | |
1524 l = i - 1; | |
1525 | |
1526 /* fetch the DC values for the predicting fragments */ | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1527 vl = DC_COEFF(l); |
1224 | 1528 |
1529 /* figure out which fragments are valid */ | |
1530 fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l); | |
1531 | |
1532 /* decide which predictor transform to use */ | |
1533 transform = (fl*PL); | |
1534 | |
1535 break; | |
1536 | |
1537 case 3: | |
1538 /* top-left fragment */ | |
1539 | |
1540 /* nothing to predict from in this case */ | |
1541 transform = 0; | |
1542 | |
1543 break; | |
1544 | |
1545 case 4: | |
1546 /* right column of fragments, not including top corner; | |
1547 * consider up-left, up, and left fragments for | |
1548 * prediction */ | |
1549 | |
1550 /* calculate the indices of the predicting fragments */ | |
1551 ul = i - fragment_width - 1; | |
1552 u = i - fragment_width; | |
1553 l = i - 1; | |
1554 | |
1555 /* fetch the DC values for the predicting fragments */ | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1556 vul = DC_COEFF(ul); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1557 vu = DC_COEFF(u); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1558 vl = DC_COEFF(l); |
1224 | 1559 |
1560 /* figure out which fragments are valid */ | |
1561 ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul); | |
1562 fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u); | |
1563 fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l); | |
1564 | |
1565 /* decide which predictor transform to use */ | |
1566 transform = (fl*PL) | (fu*PU) | (ful*PUL); | |
1567 | |
1568 break; | |
1569 | |
1570 } | |
1571 | |
1572 debug_dc_pred("transform = %d, ", transform); | |
1573 | |
1574 if (transform == 0) { | |
1575 | |
1576 /* if there were no fragments to predict from, use last | |
1577 * DC saved */ | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1578 predicted_dc = last_dc[current_frame_type]; |
2967 | 1579 debug_dc_pred("from last DC (%d) = %d\n", |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1580 current_frame_type, DC_COEFF(i)); |
1224 | 1581 |
1582 } else { | |
1583 | |
1584 /* apply the appropriate predictor transform */ | |
1585 predicted_dc = | |
1586 (predictor_transform[transform][0] * vul) + | |
1587 (predictor_transform[transform][1] * vu) + | |
1588 (predictor_transform[transform][2] * vur) + | |
1589 (predictor_transform[transform][3] * vl); | |
1590 | |
1591 /* if there is a shift value in the transform, add | |
1592 * the sign bit before the shift */ | |
1593 if (predictor_transform[transform][5] != 0) { | |
2967 | 1594 predicted_dc += ((predicted_dc >> 15) & |
1224 | 1595 predictor_transform[transform][4]); |
1596 predicted_dc >>= predictor_transform[transform][5]; | |
1597 } | |
1598 | |
1599 /* check for outranging on the [ul u l] and | |
1600 * [ul u ur l] predictors */ | |
1601 if ((transform == 13) || (transform == 15)) { | |
1602 if (iabs(predicted_dc - vu) > 128) | |
1603 predicted_dc = vu; | |
1604 else if (iabs(predicted_dc - vl) > 128) | |
1605 predicted_dc = vl; | |
1606 else if (iabs(predicted_dc - vul) > 128) | |
1607 predicted_dc = vul; | |
1608 } | |
1609 | |
2967 | 1610 debug_dc_pred("from pred DC = %d\n", |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1611 DC_COEFF(i)); |
1224 | 1612 } |
1613 | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1614 /* at long last, apply the predictor */ |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1615 if(s->coeffs[i].index){ |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1616 *s->next_coeff= s->coeffs[i]; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1617 s->coeffs[i].index=0; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1618 s->coeffs[i].coeff=0; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1619 s->coeffs[i].next= s->next_coeff++; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1620 } |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1621 s->coeffs[i].coeff += predicted_dc; |
1224 | 1622 /* save the DC */ |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1623 last_dc[current_frame_type] = DC_COEFF(i); |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1624 if(DC_COEFF(i) && !(s->all_fragments[i].coeff_count&127)){ |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1625 s->all_fragments[i].coeff_count= 129; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1626 // s->all_fragments[i].next_coeff= s->next_coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1627 s->coeffs[i].next= s->next_coeff; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1628 (s->next_coeff++)->next=NULL; |
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
1629 } |
1224 | 1630 } |
1631 } | |
1632 } | |
1633 } | |
1634 | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1635 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1636 static void horizontal_filter(unsigned char *first_pixel, int stride, |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1637 int *bounding_values); |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1638 static void vertical_filter(unsigned char *first_pixel, int stride, |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1639 int *bounding_values); |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1640 |
1224 | 1641 /* |
2722 | 1642 * Perform the final rendering for a particular slice of data. |
1643 * The slice number ranges from 0..(macroblock_height - 1). | |
1644 */ | |
1645 static void render_slice(Vp3DecodeContext *s, int slice) | |
1646 { | |
1647 int x, y; | |
1648 int m, n; | |
1649 int i; /* indicates current fragment */ | |
1650 int16_t *dequantizer; | |
3089 | 1651 DECLARE_ALIGNED_16(DCTELEM, block[64]); |
2722 | 1652 unsigned char *output_plane; |
1653 unsigned char *last_plane; | |
1654 unsigned char *golden_plane; | |
1655 int stride; | |
1656 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; | |
1657 int upper_motion_limit, lower_motion_limit; | |
1658 int motion_halfpel_index; | |
1659 uint8_t *motion_source; | |
1660 int plane; | |
1661 int plane_width; | |
1662 int plane_height; | |
1663 int slice_height; | |
1664 int current_macroblock_entry = slice * s->macroblock_width * 6; | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1665 int fragment_width; |
2722 | 1666 |
1667 if (slice >= s->macroblock_height) | |
1668 return; | |
1669 | |
1670 for (plane = 0; plane < 3; plane++) { | |
1671 | |
1672 /* set up plane-specific parameters */ | |
1673 if (plane == 0) { | |
1674 output_plane = s->current_frame.data[0]; | |
1675 last_plane = s->last_frame.data[0]; | |
1676 golden_plane = s->golden_frame.data[0]; | |
1677 stride = s->current_frame.linesize[0]; | |
1678 if (!s->flipped_image) stride = -stride; | |
1679 upper_motion_limit = 7 * s->current_frame.linesize[0]; | |
1680 lower_motion_limit = s->height * s->current_frame.linesize[0] + s->width - 8; | |
1681 y = slice * FRAGMENT_PIXELS * 2; | |
1682 plane_width = s->width; | |
1683 plane_height = s->height; | |
1684 slice_height = y + FRAGMENT_PIXELS * 2; | |
1685 i = s->macroblock_fragments[current_macroblock_entry + 0]; | |
1686 } else if (plane == 1) { | |
1687 output_plane = s->current_frame.data[1]; | |
1688 last_plane = s->last_frame.data[1]; | |
1689 golden_plane = s->golden_frame.data[1]; | |
1690 stride = s->current_frame.linesize[1]; | |
1691 if (!s->flipped_image) stride = -stride; | |
1692 upper_motion_limit = 7 * s->current_frame.linesize[1]; | |
1693 lower_motion_limit = (s->height / 2) * s->current_frame.linesize[1] + (s->width / 2) - 8; | |
1694 y = slice * FRAGMENT_PIXELS; | |
1695 plane_width = s->width / 2; | |
1696 plane_height = s->height / 2; | |
1697 slice_height = y + FRAGMENT_PIXELS; | |
1698 i = s->macroblock_fragments[current_macroblock_entry + 4]; | |
1699 } else { | |
1700 output_plane = s->current_frame.data[2]; | |
1701 last_plane = s->last_frame.data[2]; | |
1702 golden_plane = s->golden_frame.data[2]; | |
1703 stride = s->current_frame.linesize[2]; | |
1704 if (!s->flipped_image) stride = -stride; | |
1705 upper_motion_limit = 7 * s->current_frame.linesize[2]; | |
1706 lower_motion_limit = (s->height / 2) * s->current_frame.linesize[2] + (s->width / 2) - 8; | |
1707 y = slice * FRAGMENT_PIXELS; | |
1708 plane_width = s->width / 2; | |
1709 plane_height = s->height / 2; | |
1710 slice_height = y + FRAGMENT_PIXELS; | |
1711 i = s->macroblock_fragments[current_macroblock_entry + 5]; | |
1712 } | |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1713 fragment_width = plane_width / FRAGMENT_PIXELS; |
2967 | 1714 |
2722 | 1715 if(ABS(stride) > 2048) |
1716 return; //various tables are fixed size | |
1717 | |
1718 /* for each fragment row in the slice (both of them)... */ | |
1719 for (; y < slice_height; y += 8) { | |
1720 | |
1721 /* for each fragment in a row... */ | |
1722 for (x = 0; x < plane_width; x += 8, i++) { | |
1723 | |
1724 if ((i < 0) || (i >= s->fragment_count)) { | |
1725 av_log(s->avctx, AV_LOG_ERROR, " vp3:render_slice(): bad fragment number (%d)\n", i); | |
1726 return; | |
1727 } | |
1728 | |
1729 /* transform if this block was coded */ | |
1730 if ((s->all_fragments[i].coding_method != MODE_COPY) && | |
1731 !((s->avctx->flags & CODEC_FLAG_GRAY) && plane)) { | |
1732 | |
1733 if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || | |
1734 (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) | |
1735 motion_source= golden_plane; | |
2967 | 1736 else |
2722 | 1737 motion_source= last_plane; |
1738 | |
1739 motion_source += s->all_fragments[i].first_pixel; | |
1740 motion_halfpel_index = 0; | |
1741 | |
1742 /* sort out the motion vector if this fragment is coded | |
1743 * using a motion vector method */ | |
1744 if ((s->all_fragments[i].coding_method > MODE_INTRA) && | |
1745 (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) { | |
1746 int src_x, src_y; | |
1747 motion_x = s->all_fragments[i].motion_x; | |
1748 motion_y = s->all_fragments[i].motion_y; | |
1749 if(plane){ | |
1750 motion_x= (motion_x>>1) | (motion_x&1); | |
1751 motion_y= (motion_y>>1) | (motion_y&1); | |
1752 } | |
1753 | |
1754 src_x= (motion_x>>1) + x; | |
1755 src_y= (motion_y>>1) + y; | |
1756 if ((motion_x == 127) || (motion_y == 127)) | |
1757 av_log(s->avctx, AV_LOG_ERROR, " help! got invalid motion vector! (%X, %X)\n", motion_x, motion_y); | |
1758 | |
1759 motion_halfpel_index = motion_x & 0x01; | |
1760 motion_source += (motion_x >> 1); | |
1761 | |
1762 motion_halfpel_index |= (motion_y & 0x01) << 1; | |
1763 motion_source += ((motion_y >> 1) * stride); | |
1764 | |
1765 if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){ | |
1766 uint8_t *temp= s->edge_emu_buffer; | |
1767 if(stride<0) temp -= 9*stride; | |
1768 else temp += 9*stride; | |
1769 | |
1770 ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height); | |
1771 motion_source= temp; | |
1772 } | |
1773 } | |
2967 | 1774 |
2722 | 1775 |
1776 /* first, take care of copying a block from either the | |
1777 * previous or the golden frame */ | |
1778 if (s->all_fragments[i].coding_method != MODE_INTRA) { | |
2967 | 1779 /* Note, it is possible to implement all MC cases with |
1780 put_no_rnd_pixels_l2 which would look more like the | |
1781 VP3 source but this would be slower as | |
2722 | 1782 put_no_rnd_pixels_tab is better optimzed */ |
1783 if(motion_halfpel_index != 3){ | |
1784 s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index]( | |
1785 output_plane + s->all_fragments[i].first_pixel, | |
1786 motion_source, stride, 8); | |
1787 }else{ | |
1788 int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1 | |
1789 s->dsp.put_no_rnd_pixels_l2[1]( | |
1790 output_plane + s->all_fragments[i].first_pixel, | |
2967 | 1791 motion_source - d, |
1792 motion_source + stride + 1 + d, | |
2722 | 1793 stride, 8); |
1794 } | |
3488
a647bf3a7fa8
replace *_dequant (2 intra, 1 inter) by qmat (3 intra, 3 inter) (needed for theora according to spec)
michael
parents:
3487
diff
changeset
|
1795 dequantizer = s->qmat[1][plane]; |
2722 | 1796 }else{ |
3488
a647bf3a7fa8
replace *_dequant (2 intra, 1 inter) by qmat (3 intra, 3 inter) (needed for theora according to spec)
michael
parents:
3487
diff
changeset
|
1797 dequantizer = s->qmat[0][plane]; |
2722 | 1798 } |
1799 | |
1800 /* dequantize the DCT coefficients */ | |
2967 | 1801 debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n", |
1802 i, s->all_fragments[i].coding_method, | |
2722 | 1803 DC_COEFF(i), dequantizer[0]); |
1804 | |
1805 if(s->avctx->idct_algo==FF_IDCT_VP3){ | |
1806 Coeff *coeff= s->coeffs + i; | |
1807 memset(block, 0, sizeof(block)); | |
1808 while(coeff->next){ | |
1809 block[coeff->index]= coeff->coeff * dequantizer[coeff->index]; | |
1810 coeff= coeff->next; | |
1811 } | |
1812 }else{ | |
1813 Coeff *coeff= s->coeffs + i; | |
1814 memset(block, 0, sizeof(block)); | |
1815 while(coeff->next){ | |
1816 block[coeff->index]= (coeff->coeff * dequantizer[coeff->index] + 2)>>2; | |
1817 coeff= coeff->next; | |
1818 } | |
1819 } | |
1820 | |
1821 /* invert DCT and place (or add) in final output */ | |
2967 | 1822 |
2722 | 1823 if (s->all_fragments[i].coding_method == MODE_INTRA) { |
1824 if(s->avctx->idct_algo!=FF_IDCT_VP3) | |
1825 block[0] += 128<<3; | |
1826 s->dsp.idct_put( | |
1827 output_plane + s->all_fragments[i].first_pixel, | |
1828 stride, | |
1829 block); | |
1830 } else { | |
1831 s->dsp.idct_add( | |
1832 output_plane + s->all_fragments[i].first_pixel, | |
1833 stride, | |
1834 block); | |
1835 } | |
1836 | |
1837 debug_idct("block after idct_%s():\n", | |
1838 (s->all_fragments[i].coding_method == MODE_INTRA)? | |
1839 "put" : "add"); | |
1840 for (m = 0; m < 8; m++) { | |
1841 for (n = 0; n < 8; n++) { | |
2967 | 1842 debug_idct(" %3d", *(output_plane + |
2722 | 1843 s->all_fragments[i].first_pixel + (m * stride + n))); |
1844 } | |
1845 debug_idct("\n"); | |
1846 } | |
1847 debug_idct("\n"); | |
1848 | |
1849 } else { | |
1850 | |
1851 /* copy directly from the previous frame */ | |
1852 s->dsp.put_pixels_tab[1][0]( | |
1853 output_plane + s->all_fragments[i].first_pixel, | |
1854 last_plane + s->all_fragments[i].first_pixel, | |
1855 stride, 8); | |
1856 | |
1857 } | |
2724 | 1858 #if 0 |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1859 /* perform the left edge filter if: |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1860 * - the fragment is not on the left column |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1861 * - the fragment is coded in this frame |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1862 * - the fragment is not coded in this frame but the left |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1863 * fragment is coded in this frame (this is done instead |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1864 * of a right edge filter when rendering the left fragment |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1865 * since this fragment is not available yet) */ |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1866 if ((x > 0) && |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1867 ((s->all_fragments[i].coding_method != MODE_COPY) || |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1868 ((s->all_fragments[i].coding_method == MODE_COPY) && |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1869 (s->all_fragments[i - 1].coding_method != MODE_COPY)) )) { |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1870 horizontal_filter( |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1871 output_plane + s->all_fragments[i].first_pixel + 7*stride, |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1872 -stride, bounding_values); |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1873 } |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1874 |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1875 /* perform the top edge filter if: |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1876 * - the fragment is not on the top row |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1877 * - the fragment is coded in this frame |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1878 * - the fragment is not coded in this frame but the above |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1879 * fragment is coded in this frame (this is done instead |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1880 * of a bottom edge filter when rendering the above |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1881 * fragment since this fragment is not available yet) */ |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1882 if ((y > 0) && |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1883 ((s->all_fragments[i].coding_method != MODE_COPY) || |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1884 ((s->all_fragments[i].coding_method == MODE_COPY) && |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1885 (s->all_fragments[i - fragment_width].coding_method != MODE_COPY)) )) { |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1886 vertical_filter( |
2726
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1887 output_plane + s->all_fragments[i].first_pixel - stride, |
77ba1f653619
fix bugs in new loop filter code; also, refrain from filtering against
melanson
parents:
2724
diff
changeset
|
1888 -stride, bounding_values); |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1889 } |
2724 | 1890 #endif |
2722 | 1891 } |
1892 } | |
1893 } | |
1894 | |
1895 /* this looks like a good place for slice dispatch... */ | |
1896 /* algorithm: | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1897 * if (slice == s->macroblock_height - 1) |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1898 * dispatch (both last slice & 2nd-to-last slice); |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1899 * else if (slice > 0) |
2722 | 1900 * dispatch (slice - 1); |
1901 */ | |
1902 | |
1903 emms_c(); | |
1904 } | |
1905 | |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1906 static void horizontal_filter(unsigned char *first_pixel, int stride, |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1907 int *bounding_values) |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1908 { |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1909 unsigned char *end; |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1910 int filter_value; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1911 |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1912 for (end= first_pixel + 8*stride; first_pixel < end; first_pixel += stride) { |
2967 | 1913 filter_value = |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1914 (first_pixel[-2] - first_pixel[ 1]) |
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1915 +3*(first_pixel[ 0] - first_pixel[-1]); |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1916 filter_value = bounding_values[(filter_value + 4) >> 3]; |
2698
fae7fce1a202
SATURATE_U8 -> clip_uint8 (10% faster loop filter)
michael
parents:
2695
diff
changeset
|
1917 first_pixel[-1] = clip_uint8(first_pixel[-1] + filter_value); |
fae7fce1a202
SATURATE_U8 -> clip_uint8 (10% faster loop filter)
michael
parents:
2695
diff
changeset
|
1918 first_pixel[ 0] = clip_uint8(first_pixel[ 0] - filter_value); |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1919 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1920 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1921 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1922 static void vertical_filter(unsigned char *first_pixel, int stride, |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1923 int *bounding_values) |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1924 { |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1925 unsigned char *end; |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1926 int filter_value; |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1927 const int nstride= -stride; |
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1928 |
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1929 for (end= first_pixel + 8; first_pixel < end; first_pixel++) { |
2967 | 1930 filter_value = |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1931 (first_pixel[2 * nstride] - first_pixel[ stride]) |
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1932 +3*(first_pixel[0 ] - first_pixel[nstride]); |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1933 filter_value = bounding_values[(filter_value + 4) >> 3]; |
2699
1b4a3c083f9d
some optimizations gcc should have done (10% faster loop filter)
michael
parents:
2698
diff
changeset
|
1934 first_pixel[nstride] = clip_uint8(first_pixel[nstride] + filter_value); |
2698
fae7fce1a202
SATURATE_U8 -> clip_uint8 (10% faster loop filter)
michael
parents:
2695
diff
changeset
|
1935 first_pixel[0] = clip_uint8(first_pixel[0] - filter_value); |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1936 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1937 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1938 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1939 static void apply_loop_filter(Vp3DecodeContext *s) |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1940 { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1941 int x, y, plane; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1942 int width, height; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1943 int fragment; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1944 int stride; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1945 unsigned char *plane_data; |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1946 int *bounding_values= s->bounding_values_array+127; |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1947 |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1948 #if 0 |
2686 | 1949 int bounding_values_array[256]; |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1950 int filter_limit; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1951 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1952 /* find the right loop limit value */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1953 for (x = 63; x >= 0; x--) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1954 if (vp31_ac_scale_factor[x] >= s->quality_index) |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1955 break; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1956 } |
2686 | 1957 filter_limit = vp31_filter_limit_values[s->quality_index]; |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1958 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1959 /* set up the bounding values */ |
2686 | 1960 memset(bounding_values_array, 0, 256 * sizeof(int)); |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1961 for (x = 0; x < filter_limit; x++) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1962 bounding_values[-x - filter_limit] = -filter_limit + x; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1963 bounding_values[-x] = -x; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1964 bounding_values[x] = x; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1965 bounding_values[x + filter_limit] = filter_limit - x; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1966 } |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
1967 #endif |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1968 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1969 for (plane = 0; plane < 3; plane++) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1970 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1971 if (plane == 0) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1972 /* Y plane parameters */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1973 fragment = 0; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1974 width = s->fragment_width; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1975 height = s->fragment_height; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1976 stride = s->current_frame.linesize[0]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1977 plane_data = s->current_frame.data[0]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1978 } else if (plane == 1) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1979 /* U plane parameters */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1980 fragment = s->u_fragment_start; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1981 width = s->fragment_width / 2; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1982 height = s->fragment_height / 2; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1983 stride = s->current_frame.linesize[1]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1984 plane_data = s->current_frame.data[1]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1985 } else { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1986 /* V plane parameters */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1987 fragment = s->v_fragment_start; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1988 width = s->fragment_width / 2; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1989 height = s->fragment_height / 2; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1990 stride = s->current_frame.linesize[2]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1991 plane_data = s->current_frame.data[2]; |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1992 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1993 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1994 for (y = 0; y < height; y++) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1995 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1996 for (x = 0; x < width; x++) { |
2687 | 1997 START_TIMER |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1998 /* do not perform left edge filter for left columns frags */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
1999 if ((x > 0) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2000 (s->all_fragments[fragment].coding_method != MODE_COPY)) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2001 horizontal_filter( |
2967 | 2002 plane_data + s->all_fragments[fragment].first_pixel - 7*stride, |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2003 stride, bounding_values); |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2004 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2005 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2006 /* do not perform top edge filter for top row fragments */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2007 if ((y > 0) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2008 (s->all_fragments[fragment].coding_method != MODE_COPY)) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2009 vertical_filter( |
2967 | 2010 plane_data + s->all_fragments[fragment].first_pixel + stride, |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2011 stride, bounding_values); |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2012 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2013 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2014 /* do not perform right edge filter for right column |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2015 * fragments or if right fragment neighbor is also coded |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2016 * in this frame (it will be filtered in next iteration) */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2017 if ((x < width - 1) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2018 (s->all_fragments[fragment].coding_method != MODE_COPY) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2019 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2020 horizontal_filter( |
2967 | 2021 plane_data + s->all_fragments[fragment + 1].first_pixel - 7*stride, |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2022 stride, bounding_values); |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2023 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2024 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2025 /* do not perform bottom edge filter for bottom row |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2026 * fragments or if bottom fragment neighbor is also coded |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2027 * in this frame (it will be filtered in the next row) */ |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2028 if ((y < height - 1) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2029 (s->all_fragments[fragment].coding_method != MODE_COPY) && |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2030 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) { |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2031 vertical_filter( |
2967 | 2032 plane_data + s->all_fragments[fragment + width].first_pixel + stride, |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2033 stride, bounding_values); |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2034 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2035 |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2036 fragment++; |
2687 | 2037 STOP_TIMER("loop filter") |
2531
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2038 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2039 } |
eed7d92a1dfc
VP3 post-processing loop filter; disabled until the correct final step
melanson
parents:
2466
diff
changeset
|
2040 } |
1224 | 2041 } |
2042 | |
2967 | 2043 /* |
1224 | 2044 * This function computes the first pixel addresses for each fragment. |
2045 * This function needs to be invoked after the first frame is allocated | |
2046 * so that it has access to the plane strides. | |
2047 */ | |
2967 | 2048 static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s) |
1224 | 2049 { |
2050 | |
2051 int i, x, y; | |
2052 | |
2053 /* figure out the first pixel addresses for each of the fragments */ | |
2054 /* Y plane */ | |
2055 i = 0; | |
2056 for (y = s->fragment_height; y > 0; y--) { | |
2057 for (x = 0; x < s->fragment_width; x++) { | |
2967 | 2058 s->all_fragments[i++].first_pixel = |
1224 | 2059 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - |
2060 s->golden_frame.linesize[0] + | |
2061 x * FRAGMENT_PIXELS; | |
2967 | 2062 debug_init(" fragment %d, first pixel @ %d\n", |
1224 | 2063 i-1, s->all_fragments[i-1].first_pixel); |
2064 } | |
2065 } | |
2066 | |
2067 /* U plane */ | |
2068 i = s->u_fragment_start; | |
2069 for (y = s->fragment_height / 2; y > 0; y--) { | |
2070 for (x = 0; x < s->fragment_width / 2; x++) { | |
2967 | 2071 s->all_fragments[i++].first_pixel = |
1224 | 2072 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - |
2073 s->golden_frame.linesize[1] + | |
2074 x * FRAGMENT_PIXELS; | |
2967 | 2075 debug_init(" fragment %d, first pixel @ %d\n", |
1224 | 2076 i-1, s->all_fragments[i-1].first_pixel); |
2077 } | |
2078 } | |
2079 | |
2080 /* V plane */ | |
2081 i = s->v_fragment_start; | |
2082 for (y = s->fragment_height / 2; y > 0; y--) { | |
2083 for (x = 0; x < s->fragment_width / 2; x++) { | |
2967 | 2084 s->all_fragments[i++].first_pixel = |
1224 | 2085 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - |
2086 s->golden_frame.linesize[2] + | |
2087 x * FRAGMENT_PIXELS; | |
2967 | 2088 debug_init(" fragment %d, first pixel @ %d\n", |
1224 | 2089 i-1, s->all_fragments[i-1].first_pixel); |
2090 } | |
2091 } | |
2092 } | |
2093 | |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2094 /* FIXME: this should be merged with the above! */ |
2967 | 2095 static void theora_calculate_pixel_addresses(Vp3DecodeContext *s) |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2096 { |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2097 |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2098 int i, x, y; |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2099 |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2100 /* figure out the first pixel addresses for each of the fragments */ |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2101 /* Y plane */ |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2102 i = 0; |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2103 for (y = 1; y <= s->fragment_height; y++) { |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2104 for (x = 0; x < s->fragment_width; x++) { |
2967 | 2105 s->all_fragments[i++].first_pixel = |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2106 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2107 s->golden_frame.linesize[0] + |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2108 x * FRAGMENT_PIXELS; |
2967 | 2109 debug_init(" fragment %d, first pixel @ %d\n", |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2110 i-1, s->all_fragments[i-1].first_pixel); |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2111 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2112 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2113 |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2114 /* U plane */ |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2115 i = s->u_fragment_start; |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2116 for (y = 1; y <= s->fragment_height / 2; y++) { |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2117 for (x = 0; x < s->fragment_width / 2; x++) { |
2967 | 2118 s->all_fragments[i++].first_pixel = |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2119 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2120 s->golden_frame.linesize[1] + |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2121 x * FRAGMENT_PIXELS; |
2967 | 2122 debug_init(" fragment %d, first pixel @ %d\n", |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2123 i-1, s->all_fragments[i-1].first_pixel); |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2124 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2125 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2126 |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2127 /* V plane */ |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2128 i = s->v_fragment_start; |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2129 for (y = 1; y <= s->fragment_height / 2; y++) { |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2130 for (x = 0; x < s->fragment_width / 2; x++) { |
2967 | 2131 s->all_fragments[i++].first_pixel = |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2132 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2133 s->golden_frame.linesize[2] + |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2134 x * FRAGMENT_PIXELS; |
2967 | 2135 debug_init(" fragment %d, first pixel @ %d\n", |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2136 i-1, s->all_fragments[i-1].first_pixel); |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2137 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2138 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2139 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2140 |
1224 | 2141 /* |
2142 * This is the ffmpeg/libavcodec API init function. | |
2143 */ | |
2144 static int vp3_decode_init(AVCodecContext *avctx) | |
2145 { | |
2146 Vp3DecodeContext *s = avctx->priv_data; | |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2147 int i, inter, plane; |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2148 int c_width; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2149 int c_height; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2150 int y_superblock_count; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2151 int c_superblock_count; |
1224 | 2152 |
1664 | 2153 if (avctx->codec_tag == MKTAG('V','P','3','0')) |
2979 | 2154 s->version = 0; |
1664 | 2155 else |
2979 | 2156 s->version = 1; |
1664 | 2157 |
1224 | 2158 s->avctx = avctx; |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
2159 s->width = (avctx->width + 15) & 0xFFFFFFF0; |
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
2160 s->height = (avctx->height + 15) & 0xFFFFFFF0; |
1224 | 2161 avctx->pix_fmt = PIX_FMT_YUV420P; |
2162 avctx->has_b_frames = 0; | |
2693 | 2163 if(avctx->idct_algo==FF_IDCT_AUTO) |
2164 avctx->idct_algo=FF_IDCT_VP3; | |
1224 | 2165 dsputil_init(&s->dsp, avctx); |
2967 | 2166 |
2694 | 2167 ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); |
1224 | 2168 |
2169 /* initialize to an impossible value which will force a recalculation | |
2170 * in the first frame decode */ | |
2171 s->quality_index = -1; | |
2172 | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2173 s->y_superblock_width = (s->width + 31) / 32; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2174 s->y_superblock_height = (s->height + 31) / 32; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2175 y_superblock_count = s->y_superblock_width * s->y_superblock_height; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2176 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2177 /* work out the dimensions for the C planes */ |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2178 c_width = s->width / 2; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2179 c_height = s->height / 2; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2180 s->c_superblock_width = (c_width + 31) / 32; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2181 s->c_superblock_height = (c_height + 31) / 32; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2182 c_superblock_count = s->c_superblock_width * s->c_superblock_height; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2183 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2184 s->superblock_count = y_superblock_count + (c_superblock_count * 2); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2185 s->u_superblock_start = y_superblock_count; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2186 s->v_superblock_start = s->u_superblock_start + c_superblock_count; |
1224 | 2187 s->superblock_coding = av_malloc(s->superblock_count); |
2188 | |
2189 s->macroblock_width = (s->width + 15) / 16; | |
2190 s->macroblock_height = (s->height + 15) / 16; | |
2191 s->macroblock_count = s->macroblock_width * s->macroblock_height; | |
2192 | |
2193 s->fragment_width = s->width / FRAGMENT_PIXELS; | |
2194 s->fragment_height = s->height / FRAGMENT_PIXELS; | |
2195 | |
2196 /* fragment count covers all 8x8 blocks for all 3 planes */ | |
2197 s->fragment_count = s->fragment_width * s->fragment_height * 3 / 2; | |
2198 s->u_fragment_start = s->fragment_width * s->fragment_height; | |
2199 s->v_fragment_start = s->fragment_width * s->fragment_height * 5 / 4; | |
2200 | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2201 debug_init(" Y plane: %d x %d\n", s->width, s->height); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2202 debug_init(" C plane: %d x %d\n", c_width, c_height); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2203 debug_init(" Y superblocks: %d x %d, %d total\n", |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2204 s->y_superblock_width, s->y_superblock_height, y_superblock_count); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2205 debug_init(" C superblocks: %d x %d, %d total\n", |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2206 s->c_superblock_width, s->c_superblock_height, c_superblock_count); |
2967 | 2207 debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n", |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2208 s->superblock_count, s->u_superblock_start, s->v_superblock_start); |
1224 | 2209 debug_init(" macroblocks: %d x %d, %d total\n", |
2210 s->macroblock_width, s->macroblock_height, s->macroblock_count); | |
2211 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n", | |
2212 s->fragment_count, | |
2213 s->fragment_width, | |
2214 s->fragment_height, | |
2215 s->u_fragment_start, | |
2216 s->v_fragment_start); | |
2217 | |
2218 s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); | |
2714
b008c78467e6
use O(number of non zero coeffs) instead of O(number of coeffs) storage for the coefficient colleting/reordering
michael
parents:
2712
diff
changeset
|
2219 s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65); |
1224 | 2220 s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); |
2221 s->pixel_addresses_inited = 0; | |
2222 | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2223 if (!s->theora_tables) |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2224 { |
2979 | 2225 for (i = 0; i < 64; i++) |
2226 s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i]; | |
2227 for (i = 0; i < 64; i++) | |
2228 s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i]; | |
2229 for (i = 0; i < 64; i++) | |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2230 s->base_matrix[0][i] = vp31_intra_y_dequant[i]; |
2979 | 2231 for (i = 0; i < 64; i++) |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2232 s->base_matrix[1][i] = vp31_intra_c_dequant[i]; |
2979 | 2233 for (i = 0; i < 64; i++) |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2234 s->base_matrix[2][i] = vp31_inter_dequant[i]; |
2979 | 2235 for (i = 0; i < 64; i++) |
2236 s->filter_limit_values[i] = vp31_filter_limit_values[i]; | |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2237 |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2238 for(inter=0; inter<2; inter++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2239 for(plane=0; plane<3; plane++){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2240 s->qr_count[inter][plane]= 1; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2241 s->qr_size [inter][plane][0]= 63; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2242 s->qr_base [inter][plane][0]= |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2243 s->qr_base [inter][plane][1]= 2*inter + (!!plane)*!inter; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2244 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2245 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2246 |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2247 /* init VLC tables */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2248 for (i = 0; i < 16; i++) { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2249 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2250 /* DC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2251 init_vlc(&s->dc_vlc[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2252 &dc_bias[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2253 &dc_bias[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2254 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2255 /* group 1 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2256 init_vlc(&s->ac_vlc_1[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2257 &ac_bias_0[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2258 &ac_bias_0[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2259 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2260 /* group 2 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2261 init_vlc(&s->ac_vlc_2[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2262 &ac_bias_1[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2263 &ac_bias_1[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2264 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2265 /* group 3 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2266 init_vlc(&s->ac_vlc_3[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2267 &ac_bias_2[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2268 &ac_bias_2[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2269 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2270 /* group 4 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2271 init_vlc(&s->ac_vlc_4[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2272 &ac_bias_3[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2273 &ac_bias_3[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2274 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2275 } else { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2276 for (i = 0; i < 16; i++) { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2277 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2278 /* DC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2279 init_vlc(&s->dc_vlc[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2280 &s->huffman_table[i][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2281 &s->huffman_table[i][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2282 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2283 /* group 1 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2284 init_vlc(&s->ac_vlc_1[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2285 &s->huffman_table[i+16][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2286 &s->huffman_table[i+16][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2287 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2288 /* group 2 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2289 init_vlc(&s->ac_vlc_2[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2290 &s->huffman_table[i+16*2][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2291 &s->huffman_table[i+16*2][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2292 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2293 /* group 3 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2294 init_vlc(&s->ac_vlc_3[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2295 &s->huffman_table[i+16*3][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2296 &s->huffman_table[i+16*3][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2297 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2298 /* group 4 AC histograms */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2299 init_vlc(&s->ac_vlc_4[i], 5, 32, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2300 &s->huffman_table[i+16*4][0][1], 4, 2, |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2301 &s->huffman_table[i+16*4][0][0], 4, 2, 0); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2302 } |
1224 | 2303 } |
2304 | |
2703
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
2305 init_vlc(&s->superblock_run_length_vlc, 6, 34, |
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
2306 &superblock_run_length_vlc_table[0][1], 4, 2, |
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
2307 &superblock_run_length_vlc_table[0][0], 4, 2, 0); |
3817945001ce
replace get_superblock_run_length() with a VLC table
melanson
parents:
2702
diff
changeset
|
2308 |
2942
868c48736d1c
fixed long standing off-by-one bug (fixes playback on ppc)
alex
parents:
2866
diff
changeset
|
2309 init_vlc(&s->fragment_run_length_vlc, 5, 30, |
2702
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2310 &fragment_run_length_vlc_table[0][1], 4, 2, |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2311 &fragment_run_length_vlc_table[0][0], 4, 2, 0); |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2312 |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2313 init_vlc(&s->mode_code_vlc, 3, 8, |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2314 &mode_code_vlc_table[0][1], 2, 1, |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2315 &mode_code_vlc_table[0][0], 2, 1, 0); |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2316 |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2317 init_vlc(&s->motion_vector_vlc, 6, 63, |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2318 &motion_vector_vlc_table[0][1], 2, 1, |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2319 &motion_vector_vlc_table[0][0], 2, 1, 0); |
5a4e5225cbb6
use VLCs for in place of get_fragment_run_length(), get_mode_code(), and
melanson
parents:
2699
diff
changeset
|
2320 |
1224 | 2321 /* work out the block mapping tables */ |
2322 s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); | |
2323 s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int)); | |
2324 s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int)); | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
2325 s->macroblock_coding = av_malloc(s->macroblock_count + 1); |
1224 | 2326 init_block_mapping(s); |
2327 | |
1229
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2328 for (i = 0; i < 3; i++) { |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2329 s->current_frame.data[i] = NULL; |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2330 s->last_frame.data[i] = NULL; |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2331 s->golden_frame.data[i] = NULL; |
1227
184c480cefc3
fix decoder so that ffmpeg does not crash, at least not right away
tmmm
parents:
1224
diff
changeset
|
2332 } |
184c480cefc3
fix decoder so that ffmpeg does not crash, at least not right away
tmmm
parents:
1224
diff
changeset
|
2333 |
1224 | 2334 return 0; |
2335 } | |
2336 | |
2337 /* | |
2338 * This is the ffmpeg/libavcodec API frame decode function. | |
2339 */ | |
2967 | 2340 static int vp3_decode_frame(AVCodecContext *avctx, |
1224 | 2341 void *data, int *data_size, |
2342 uint8_t *buf, int buf_size) | |
2343 { | |
2344 Vp3DecodeContext *s = avctx->priv_data; | |
2345 GetBitContext gb; | |
2346 static int counter = 0; | |
2722 | 2347 int i; |
1224 | 2348 |
2349 init_get_bits(&gb, buf, buf_size * 8); | |
2967 | 2350 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2351 if (s->theora && get_bits1(&gb)) |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2352 { |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2353 #if 1 |
2979 | 2354 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); |
2355 return -1; | |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2356 #else |
2979 | 2357 int ptype = get_bits(&gb, 7); |
2358 | |
2359 skip_bits(&gb, 6*8); /* "theora" */ | |
2360 | |
2361 switch(ptype) | |
2362 { | |
2363 case 1: | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2364 theora_decode_comments(avctx, &gb); |
2979 | 2365 break; |
2366 case 2: | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2367 theora_decode_tables(avctx, &gb); |
2979 | 2368 init_dequantizer(s); |
2369 break; | |
2370 default: | |
2371 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); | |
2372 } | |
2373 return buf_size; | |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2374 #endif |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2375 } |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2376 |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2377 s->keyframe = !get_bits1(&gb); |
1664 | 2378 if (!s->theora) |
2979 | 2379 skip_bits(&gb, 1); |
1664 | 2380 s->last_quality_index = s->quality_index; |
3492
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2381 |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2382 s->nqis=0; |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2383 do{ |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2384 s->qis[s->nqis++]= get_bits(&gb, 6); |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2385 } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb)); |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2386 |
fa3794c46f21
parse all QIS values (we still ignore them though ...)
michael
parents:
3491
diff
changeset
|
2387 s->quality_index= s->qis[0]; |
1224 | 2388 |
1667 | 2389 if (s->avctx->debug & FF_DEBUG_PICT_INFO) |
2979 | 2390 av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", |
2391 s->keyframe?"key":"", counter, s->quality_index); | |
1224 | 2392 counter++; |
2393 | |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
2394 if (s->quality_index != s->last_quality_index) { |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
2395 init_dequantizer(s); |
2723
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
2396 init_loop_filter(s); |
5ae980827158
apply the loop filter to fragments as they are rendered into the final
melanson
parents:
2722
diff
changeset
|
2397 } |
1292
f7b3fa4bb7ae
revising and fixing motion vectors, squished block unpacking bug that
tmmm
parents:
1282
diff
changeset
|
2398 |
1224 | 2399 if (s->keyframe) { |
2979 | 2400 if (!s->theora) |
2401 { | |
2402 skip_bits(&gb, 4); /* width code */ | |
2403 skip_bits(&gb, 4); /* height code */ | |
2404 if (s->version) | |
2405 { | |
2406 s->version = get_bits(&gb, 5); | |
2407 if (counter == 1) | |
2408 av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); | |
2409 } | |
2410 } | |
2411 if (s->version || s->theora) | |
2412 { | |
2413 if (get_bits1(&gb)) | |
2414 av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); | |
2415 skip_bits(&gb, 2); /* reserved? */ | |
2416 } | |
1664 | 2417 |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2418 if (s->last_frame.data[0] == s->golden_frame.data[0]) { |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2419 if (s->golden_frame.data[0]) |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2420 avctx->release_buffer(avctx, &s->golden_frame); |
1405
e69f99ade5b0
fix AVFrame.reference (the frames are used for decoding future frames so it should be !=0)
michaelni
parents:
1355
diff
changeset
|
2421 s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ |
1244
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2422 } else { |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2423 if (s->golden_frame.data[0]) |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2424 avctx->release_buffer(avctx, &s->golden_frame); |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2425 if (s->last_frame.data[0]) |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2426 avctx->release_buffer(avctx, &s->last_frame); |
a02df1ba6c7f
fix image buffer leak on keyframes, add more error condition checks
tmmm
parents:
1240
diff
changeset
|
2427 } |
1224 | 2428 |
1405
e69f99ade5b0
fix AVFrame.reference (the frames are used for decoding future frames so it should be !=0)
michaelni
parents:
1355
diff
changeset
|
2429 s->golden_frame.reference = 3; |
1224 | 2430 if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
2431 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); |
1224 | 2432 return -1; |
2433 } | |
2434 | |
2435 /* golden frame is also the current frame */ | |
3486 | 2436 s->current_frame= s->golden_frame; |
1224 | 2437 |
2438 /* time to figure out pixel addresses? */ | |
2439 if (!s->pixel_addresses_inited) | |
2979 | 2440 { |
2441 if (!s->flipped_image) | |
2442 vp3_calculate_pixel_addresses(s); | |
2443 else | |
2444 theora_calculate_pixel_addresses(s); | |
2445 } | |
1224 | 2446 } else { |
2447 /* allocate a new current frame */ | |
1405
e69f99ade5b0
fix AVFrame.reference (the frames are used for decoding future frames so it should be !=0)
michaelni
parents:
1355
diff
changeset
|
2448 s->current_frame.reference = 3; |
1224 | 2449 if(avctx->get_buffer(avctx, &s->current_frame) < 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1518
diff
changeset
|
2450 av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); |
1224 | 2451 return -1; |
2452 } | |
2453 } | |
2454 | |
1407 | 2455 s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame |
2456 s->current_frame.qstride= 0; | |
2457 | |
2687 | 2458 {START_TIMER |
1224 | 2459 init_frame(s, &gb); |
2687 | 2460 STOP_TIMER("init_frame")} |
1224 | 2461 |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2462 #if KEYFRAMES_ONLY |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2463 if (!s->keyframe) { |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2464 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2465 memcpy(s->current_frame.data[0], s->golden_frame.data[0], |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2466 s->current_frame.linesize[0] * s->height); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2467 memcpy(s->current_frame.data[1], s->golden_frame.data[1], |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2468 s->current_frame.linesize[1] * s->height / 2); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2469 memcpy(s->current_frame.data[2], s->golden_frame.data[2], |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2470 s->current_frame.linesize[2] * s->height / 2); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2471 |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2472 } else { |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2473 #endif |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2474 |
2687 | 2475 {START_TIMER |
2476 if (unpack_superblocks(s, &gb)){ | |
2477 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); | |
2478 return -1; | |
2479 } | |
2480 STOP_TIMER("unpack_superblocks")} | |
2481 {START_TIMER | |
2482 if (unpack_modes(s, &gb)){ | |
2483 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); | |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2484 return -1; |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2485 } |
2687 | 2486 STOP_TIMER("unpack_modes")} |
2487 {START_TIMER | |
2488 if (unpack_vectors(s, &gb)){ | |
2489 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); | |
2490 return -1; | |
2491 } | |
2492 STOP_TIMER("unpack_vectors")} | |
2493 {START_TIMER | |
2494 if (unpack_dct_coeffs(s, &gb)){ | |
2495 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); | |
2496 return -1; | |
2497 } | |
2498 STOP_TIMER("unpack_dct_coeffs")} | |
2499 {START_TIMER | |
1224 | 2500 |
2501 reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); | |
1355
1c05f4290517
added the official VP3 IDCT (C implementation) as well as a grayscale
tmmm
parents:
1292
diff
changeset
|
2502 if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { |
1c05f4290517
added the official VP3 IDCT (C implementation) as well as a grayscale
tmmm
parents:
1292
diff
changeset
|
2503 reverse_dc_prediction(s, s->u_fragment_start, |
1c05f4290517
added the official VP3 IDCT (C implementation) as well as a grayscale
tmmm
parents:
1292
diff
changeset
|
2504 s->fragment_width / 2, s->fragment_height / 2); |
1c05f4290517
added the official VP3 IDCT (C implementation) as well as a grayscale
tmmm
parents:
1292
diff
changeset
|
2505 reverse_dc_prediction(s, s->v_fragment_start, |
1c05f4290517
added the official VP3 IDCT (C implementation) as well as a grayscale
tmmm
parents:
1292
diff
changeset
|
2506 s->fragment_width / 2, s->fragment_height / 2); |
2722 | 2507 } |
2508 STOP_TIMER("reverse_dc_prediction")} | |
2509 {START_TIMER | |
2510 | |
2511 for (i = 0; i < s->macroblock_height; i++) | |
2512 render_slice(s, i); | |
2513 STOP_TIMER("render_fragments")} | |
1224 | 2514 |
2687 | 2515 {START_TIMER |
2724 | 2516 apply_loop_filter(s); |
2687 | 2517 STOP_TIMER("apply_loop_filter")} |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2518 #if KEYFRAMES_ONLY |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2519 } |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2520 #endif |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2521 |
1224 | 2522 *data_size=sizeof(AVFrame); |
2523 *(AVFrame*)data= s->current_frame; | |
2524 | |
1229
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2525 /* release the last frame, if it is allocated and if it is not the |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2526 * golden frame */ |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2527 if ((s->last_frame.data[0]) && |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2528 (s->last_frame.data[0] != s->golden_frame.data[0])) |
cefec170ee46
fixed buffer allocation logic (hopefully) so that decoder does not crash
tmmm
parents:
1227
diff
changeset
|
2529 avctx->release_buffer(avctx, &s->last_frame); |
1224 | 2530 |
1227
184c480cefc3
fix decoder so that ffmpeg does not crash, at least not right away
tmmm
parents:
1224
diff
changeset
|
2531 /* shuffle frames (last = current) */ |
3486 | 2532 s->last_frame= s->current_frame; |
1405
e69f99ade5b0
fix AVFrame.reference (the frames are used for decoding future frames so it should be !=0)
michaelni
parents:
1355
diff
changeset
|
2533 s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ |
1224 | 2534 |
2535 return buf_size; | |
2536 } | |
2537 | |
2538 /* | |
2539 * This is the ffmpeg/libavcodec API module cleanup function. | |
2540 */ | |
2541 static int vp3_decode_end(AVCodecContext *avctx) | |
2542 { | |
2543 Vp3DecodeContext *s = avctx->priv_data; | |
2544 | |
2545 av_free(s->all_fragments); | |
2689
ed0ab6f82167
clear blocks after each idct instead of per picture
michael
parents:
2687
diff
changeset
|
2546 av_free(s->coeffs); |
1224 | 2547 av_free(s->coded_fragment_list); |
2548 av_free(s->superblock_fragments); | |
2549 av_free(s->superblock_macroblocks); | |
2550 av_free(s->macroblock_fragments); | |
1240
c95ff60bc1a1
fix motion vector decoding bug and reinstate interframes
tmmm
parents:
1239
diff
changeset
|
2551 av_free(s->macroblock_coding); |
2967 | 2552 |
1224 | 2553 /* release all frames */ |
1405
e69f99ade5b0
fix AVFrame.reference (the frames are used for decoding future frames so it should be !=0)
michaelni
parents:
1355
diff
changeset
|
2554 if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0]) |
1238
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2555 avctx->release_buffer(avctx, &s->golden_frame); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2556 if (s->last_frame.data[0]) |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2557 avctx->release_buffer(avctx, &s->last_frame); |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2558 /* no need to release the current_frame since it will always be pointing |
6eab0df78d47
squashed a bunch of subtle array indexing bugs, fixed block mapping
tmmm
parents:
1236
diff
changeset
|
2559 * to the same frame as either the golden or last frame */ |
1224 | 2560 |
2561 return 0; | |
2562 } | |
2563 | |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2564 static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2565 { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2566 Vp3DecodeContext *s = avctx->priv_data; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2567 |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2568 if (get_bits(gb, 1)) { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2569 int token; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2570 if (s->entries >= 32) { /* overflow */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2571 av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n"); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2572 return -1; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2573 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2574 token = get_bits(gb, 5); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2575 //av_log(avctx, AV_LOG_DEBUG, "hti %d hbits %x token %d entry : %d size %d\n", s->hti, s->hbits, token, s->entries, s->huff_code_size); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2576 s->huffman_table[s->hti][token][0] = s->hbits; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2577 s->huffman_table[s->hti][token][1] = s->huff_code_size; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2578 s->entries++; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2579 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2580 else { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2581 if (s->huff_code_size >= 32) {/* overflow */ |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2582 av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n"); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2583 return -1; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2584 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2585 s->huff_code_size++; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2586 s->hbits <<= 1; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2587 read_huffman_tree(avctx, gb); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2588 s->hbits |= 1; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2589 read_huffman_tree(avctx, gb); |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2590 s->hbits >>= 1; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2591 s->huff_code_size--; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2592 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2593 return 0; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2594 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2595 |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2596 static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2597 { |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2598 Vp3DecodeContext *s = avctx->priv_data; |
3483 | 2599 |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2600 s->theora = get_bits_long(gb, 24); |
3483 | 2601 av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora); |
1627
a80b15c0b9d5
theora alpha3 support (with maintaining backward compatibility, maybe we should remove all backward compatibility codes after final theora release?)
alex
parents:
1626
diff
changeset
|
2602 |
2678 | 2603 /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */ |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2604 /* but previous versions have the image flipped relative to vp3 */ |
2678 | 2605 if (s->theora < 0x030200) |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2606 { |
2979 | 2607 s->flipped_image = 1; |
1626
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2608 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n"); |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2609 } |
f74ae637ffa9
finally working with old theora bitstream (flipped image), the only sample I have is decoded successfully (theora.ogg)
alex
parents:
1598
diff
changeset
|
2610 |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2611 s->width = get_bits(gb, 16) << 4; |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2612 s->height = get_bits(gb, 16) << 4; |
2967 | 2613 |
2422 | 2614 if(avcodec_check_dimensions(avctx, s->width, s->height)){ |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2615 av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height); |
2422 | 2616 s->width= s->height= 0; |
2617 return -1; | |
2618 } | |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2619 |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2620 if (s->theora >= 0x030400) |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2621 { |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2622 skip_bits(gb, 32); /* total number of superblocks in a frame */ |
2979 | 2623 // fixme, the next field is 36bits long |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2624 skip_bits(gb, 32); /* total number of blocks in a frame */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2625 skip_bits(gb, 4); /* total number of blocks in a frame */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2626 skip_bits(gb, 32); /* total number of macroblocks in a frame */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2627 |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2628 skip_bits(gb, 24); /* frame width */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2629 skip_bits(gb, 24); /* frame height */ |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2630 } |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2631 else |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2632 { |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2633 skip_bits(gb, 24); /* frame width */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2634 skip_bits(gb, 24); /* frame height */ |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2635 } |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2636 |
3490
b43d45362038
fix playback of theora.ogg on mphq patch by (matthieu castet %% castet dat matthieu ot free dat fr %%)
michael
parents:
3489
diff
changeset
|
2637 if (s->theora >= 0x030200) { |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2638 skip_bits(gb, 8); /* offset x */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2639 skip_bits(gb, 8); /* offset y */ |
3490
b43d45362038
fix playback of theora.ogg on mphq patch by (matthieu castet %% castet dat matthieu ot free dat fr %%)
michael
parents:
3489
diff
changeset
|
2640 } |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2641 |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2642 skip_bits(gb, 32); /* fps numerator */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2643 skip_bits(gb, 32); /* fps denumerator */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2644 skip_bits(gb, 24); /* aspect numerator */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2645 skip_bits(gb, 24); /* aspect denumerator */ |
2967 | 2646 |
2678 | 2647 if (s->theora < 0x030200) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2648 skip_bits(gb, 5); /* keyframe frequency force */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2649 skip_bits(gb, 8); /* colorspace */ |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2650 if (s->theora >= 0x030400) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2651 skip_bits(gb, 2); /* pixel format: 420,res,422,444 */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2652 skip_bits(gb, 24); /* bitrate */ |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2653 |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2654 skip_bits(gb, 6); /* quality hint */ |
2967 | 2655 |
2678 | 2656 if (s->theora >= 0x030200) |
1627
a80b15c0b9d5
theora alpha3 support (with maintaining backward compatibility, maybe we should remove all backward compatibility codes after final theora release?)
alex
parents:
1626
diff
changeset
|
2657 { |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2658 skip_bits(gb, 5); /* keyframe frequency force */ |
2979 | 2659 |
2660 if (s->theora < 0x030400) | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2661 skip_bits(gb, 5); /* spare bits */ |
1627
a80b15c0b9d5
theora alpha3 support (with maintaining backward compatibility, maybe we should remove all backward compatibility codes after final theora release?)
alex
parents:
1626
diff
changeset
|
2662 } |
2967 | 2663 |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2664 // align_get_bits(gb); |
2967 | 2665 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2666 avctx->width = s->width; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2667 avctx->height = s->height; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2668 |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2669 return 0; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2670 } |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2671 |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2672 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb) |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2673 { |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2674 Vp3DecodeContext *s = avctx->priv_data; |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2675 int i, n, matrices, inter, plane; |
2678 | 2676 |
2677 if (s->theora >= 0x030200) { | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2678 n = get_bits(gb, 3); |
2731
0b4b57c4a8f5
read loop filter limit values from Theora header, courtesy of Matthieu
melanson
parents:
2726
diff
changeset
|
2679 /* loop filter limit values table */ |
2678 | 2680 for (i = 0; i < 64; i++) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2681 s->filter_limit_values[i] = get_bits(gb, n); |
2678 | 2682 } |
2967 | 2683 |
2678 | 2684 if (s->theora >= 0x030200) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2685 n = get_bits(gb, 4) + 1; |
2678 | 2686 else |
2687 n = 16; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2688 /* quality threshold table */ |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2689 for (i = 0; i < 64; i++) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2690 s->coded_ac_scale_factor[i] = get_bits(gb, n); |
2678 | 2691 |
2692 if (s->theora >= 0x030200) | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2693 n = get_bits(gb, 4) + 1; |
2678 | 2694 else |
2695 n = 16; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2696 /* dc scale factor table */ |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2697 for (i = 0; i < 64; i++) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2698 s->coded_dc_scale_factor[i] = get_bits(gb, n); |
2678 | 2699 |
2700 if (s->theora >= 0x030200) | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2701 matrices = get_bits(gb, 9) + 1; |
2678 | 2702 else |
2944
3785497656c9
Correctly skip unknown matrices (patch by Matthieu Castet) and disable comment reading
alex
parents:
2943
diff
changeset
|
2703 matrices = 3; |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2704 |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2705 if(matrices > 384){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2706 av_log(avctx, AV_LOG_ERROR, "invalid number of base matrixes\n"); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2707 return -1; |
2678 | 2708 } |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2709 |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2710 for(n=0; n<matrices; n++){ |
2979 | 2711 for (i = 0; i < 64; i++) |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2712 s->base_matrix[n][i]= get_bits(gb, 8); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2713 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2714 |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2715 for (inter = 0; inter <= 1; inter++) { |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2716 for (plane = 0; plane <= 2; plane++) { |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2717 int newqr= 1; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2718 if (inter || plane > 0) |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2719 newqr = get_bits(gb, 1); |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2720 if (!newqr) { |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2721 int qtj, plj; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2722 if(inter && get_bits(gb, 1)){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2723 qtj = 0; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2724 plj = plane; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2725 }else{ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2726 qtj= (3*inter + plane - 1) / 3; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2727 plj= (plane + 2) % 3; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2728 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2729 s->qr_count[inter][plane]= s->qr_count[qtj][plj]; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2730 memcpy(s->qr_size[inter][plane], s->qr_size[qtj][plj], sizeof(s->qr_size[0][0])); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2731 memcpy(s->qr_base[inter][plane], s->qr_base[qtj][plj], sizeof(s->qr_base[0][0])); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2732 } else { |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2733 int qri= 0; |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2734 int qi = 0; |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2735 |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2736 for(;;){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2737 i= get_bits(gb, av_log2(matrices-1)+1); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2738 if(i>= matrices){ |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2739 av_log(avctx, AV_LOG_ERROR, "invalid base matrix index\n"); |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2740 return -1; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2741 } |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2742 s->qr_base[inter][plane][qri]= i; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2743 if(qi >= 63) |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2744 break; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2745 i = get_bits(gb, av_log2(63-qi)+1) + 1; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2746 s->qr_size[inter][plane][qri++]= i; |
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2747 qi += i; |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2748 } |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2749 |
2944
3785497656c9
Correctly skip unknown matrices (patch by Matthieu Castet) and disable comment reading
alex
parents:
2943
diff
changeset
|
2750 if (qi > 63) { |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2751 av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi); |
2979 | 2752 return -1; |
2753 } | |
3489
9aacd9410e57
attempt to implement xiphs useless and stupid quantization matrix mess
michael
parents:
3488
diff
changeset
|
2754 s->qr_count[inter][plane]= qri; |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2755 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2756 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2757 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2758 |
2944
3785497656c9
Correctly skip unknown matrices (patch by Matthieu Castet) and disable comment reading
alex
parents:
2943
diff
changeset
|
2759 /* Huffman tables */ |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2760 for (s->hti = 0; s->hti < 80; s->hti++) { |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2761 s->entries = 0; |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2762 s->huff_code_size = 1; |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2763 if (!get_bits(gb, 1)) { |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2764 s->hbits = 0; |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2765 read_huffman_tree(avctx, gb); |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2766 s->hbits = 1; |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2767 read_huffman_tree(avctx, gb); |
2718
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2768 } |
158dc437c783
read Huffman tables from Theora header (patch courtesy of
melanson
parents:
2714
diff
changeset
|
2769 } |
2967 | 2770 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2771 s->theora_tables = 1; |
2967 | 2772 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2773 return 0; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2774 } |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2775 |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2776 static int theora_decode_init(AVCodecContext *avctx) |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2777 { |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2778 Vp3DecodeContext *s = avctx->priv_data; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2779 GetBitContext gb; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2780 int ptype; |
2533 | 2781 uint8_t *p= avctx->extradata; |
2782 int op_bytes, i; | |
2967 | 2783 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2784 s->theora = 1; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2785 |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2786 if (!avctx->extradata_size) |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2787 { |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2788 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n"); |
2979 | 2789 return -1; |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2790 } |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2791 |
2533 | 2792 for(i=0;i<3;i++) { |
2793 op_bytes = *(p++)<<8; | |
2794 op_bytes += *(p++); | |
2795 | |
2796 init_get_bits(&gb, p, op_bytes); | |
2797 p += op_bytes; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2798 |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2799 ptype = get_bits(&gb, 8); |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2800 debug_vp3("Theora headerpacket type: %x\n", ptype); |
2967 | 2801 |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2802 if (!(ptype & 0x80)) |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2803 { |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2804 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n"); |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2805 // return -1; |
2967 | 2806 } |
2943
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2807 |
6bf62c1cf1b6
Fixing theora _again_. DONT BOTHER BREAKING THIS AGAIN. Added support for Theora 3.4 and stream created by Elphel cameras are decodable.
alex
parents:
2942
diff
changeset
|
2808 // FIXME: check for this aswell |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2809 skip_bits(&gb, 6*8); /* "theora" */ |
2967 | 2810 |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2811 switch(ptype) |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2812 { |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2813 case 0x80: |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2814 theora_decode_header(avctx, &gb); |
2979 | 2815 break; |
2816 case 0x81: | |
2944
3785497656c9
Correctly skip unknown matrices (patch by Matthieu Castet) and disable comment reading
alex
parents:
2943
diff
changeset
|
2817 // FIXME: is this needed? it breaks sometimes |
2979 | 2818 // theora_decode_comments(avctx, gb); |
2819 break; | |
2820 case 0x82: | |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2821 theora_decode_tables(avctx, &gb); |
2979 | 2822 break; |
2823 default: | |
2824 av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype&~0x80); | |
2825 break; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2826 } |
3484
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2827 if(8*op_bytes != get_bits_count(&gb)) |
9a70c6d3c653
check how many bits are left after decoding extradata
michael
parents:
3483
diff
changeset
|
2828 av_log(avctx, AV_LOG_ERROR, "%d bits left in packet %X\n", 8*op_bytes - get_bits_count(&gb), ptype); |
3490
b43d45362038
fix playback of theora.ogg on mphq patch by (matthieu castet %% castet dat matthieu ot free dat fr %%)
michael
parents:
3489
diff
changeset
|
2829 if (s->theora < 0x030200) |
b43d45362038
fix playback of theora.ogg on mphq patch by (matthieu castet %% castet dat matthieu ot free dat fr %%)
michael
parents:
3489
diff
changeset
|
2830 break; |
2533 | 2831 } |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2832 |
2678 | 2833 vp3_decode_init(avctx); |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2834 return 0; |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2835 } |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2836 |
1224 | 2837 AVCodec vp3_decoder = { |
2838 "vp3", | |
2839 CODEC_TYPE_VIDEO, | |
2840 CODEC_ID_VP3, | |
2841 sizeof(Vp3DecodeContext), | |
2842 vp3_decode_init, | |
2843 NULL, | |
2844 vp3_decode_end, | |
2845 vp3_decode_frame, | |
2846 0, | |
2847 NULL | |
2848 }; | |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2849 |
2665 | 2850 #ifndef CONFIG_LIBTHEORA |
1516
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2851 AVCodec theora_decoder = { |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2852 "theora", |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2853 CODEC_TYPE_VIDEO, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2854 CODEC_ID_THEORA, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2855 sizeof(Vp3DecodeContext), |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2856 theora_decode_init, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2857 NULL, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2858 vp3_decode_end, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2859 vp3_decode_frame, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2860 0, |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2861 NULL |
0f0e9dfa6723
theora decoding support (only keyframes for now, because by theora the frame isn't flipped so the motion vectors are getting screwed up)
alex
parents:
1463
diff
changeset
|
2862 }; |
2665 | 2863 #endif |