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