comparison vp3.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 394ea2703387
children bfabfdf9ce55
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
40 40
41 #include "vp3data.h" 41 #include "vp3data.h"
42 42
43 #define FRAGMENT_PIXELS 8 43 #define FRAGMENT_PIXELS 8
44 44
45 /* 45 /*
46 * Debugging Variables 46 * Debugging Variables
47 * 47 *
48 * Define one or more of the following compile-time variables to 1 to obtain 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. 49 * elaborate information about certain aspects of the decoding process.
50 * 50 *
51 * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode) 51 * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode)
52 * DEBUG_VP3: high-level decoding flow 52 * DEBUG_VP3: high-level decoding flow
87 #endif 87 #endif
88 88
89 #if DEBUG_DEQUANTIZERS 89 #if DEBUG_DEQUANTIZERS
90 #define debug_dequantizers(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 90 #define debug_dequantizers(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
91 #else 91 #else
92 static inline void debug_dequantizers(const char *format, ...) { } 92 static inline void debug_dequantizers(const char *format, ...) { }
93 #endif 93 #endif
94 94
95 #if DEBUG_BLOCK_CODING 95 #if DEBUG_BLOCK_CODING
96 #define debug_block_coding(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 96 #define debug_block_coding(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
97 #else 97 #else
98 static inline void debug_block_coding(const char *format, ...) { } 98 static inline void debug_block_coding(const char *format, ...) { }
99 #endif 99 #endif
100 100
101 #if DEBUG_MODES 101 #if DEBUG_MODES
102 #define debug_modes(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 102 #define debug_modes(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
103 #else 103 #else
104 static inline void debug_modes(const char *format, ...) { } 104 static inline void debug_modes(const char *format, ...) { }
105 #endif 105 #endif
106 106
107 #if DEBUG_VECTORS 107 #if DEBUG_VECTORS
108 #define debug_vectors(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 108 #define debug_vectors(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
109 #else 109 #else
110 static inline void debug_vectors(const char *format, ...) { } 110 static inline void debug_vectors(const char *format, ...) { }
111 #endif 111 #endif
112 112
113 #if DEBUG_TOKEN 113 #if DEBUG_TOKEN
114 #define debug_token(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 114 #define debug_token(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
115 #else 115 #else
116 static inline void debug_token(const char *format, ...) { } 116 static inline void debug_token(const char *format, ...) { }
117 #endif 117 #endif
118 118
119 #if DEBUG_VLC 119 #if DEBUG_VLC
120 #define debug_vlc(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 120 #define debug_vlc(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
121 #else 121 #else
122 static inline void debug_vlc(const char *format, ...) { } 122 static inline void debug_vlc(const char *format, ...) { }
123 #endif 123 #endif
124 124
125 #if DEBUG_DC_PRED 125 #if DEBUG_DC_PRED
126 #define debug_dc_pred(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 126 #define debug_dc_pred(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
127 #else 127 #else
128 static inline void debug_dc_pred(const char *format, ...) { } 128 static inline void debug_dc_pred(const char *format, ...) { }
129 #endif 129 #endif
130 130
131 #if DEBUG_IDCT 131 #if DEBUG_IDCT
132 #define debug_idct(args...) av_log(NULL, AV_LOG_DEBUG, ## args) 132 #define debug_idct(args...) av_log(NULL, AV_LOG_DEBUG, ## args)
133 #else 133 #else
134 static inline void debug_idct(const char *format, ...) { } 134 static inline void debug_idct(const char *format, ...) { }
135 #endif 135 #endif
136 136
137 typedef struct Coeff { 137 typedef struct Coeff {
138 struct Coeff *next; 138 struct Coeff *next;
139 DCTELEM coeff; 139 DCTELEM coeff;
176 { 176 {
177 /* this is the custom scheme */ 177 /* this is the custom scheme */
178 { 0, 0, 0, 0, 0, 0, 0, 0 }, 178 { 0, 0, 0, 0, 0, 0, 0, 0 },
179 179
180 /* scheme 1: Last motion vector dominates */ 180 /* scheme 1: Last motion vector dominates */
181 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, 181 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
182 MODE_INTER_PLUS_MV, MODE_INTER_NO_MV, 182 MODE_INTER_PLUS_MV, MODE_INTER_NO_MV,
183 MODE_INTRA, MODE_USING_GOLDEN, 183 MODE_INTRA, MODE_USING_GOLDEN,
184 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 184 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
185 185
186 /* scheme 2 */ 186 /* scheme 2 */
187 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, 187 { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
188 MODE_INTER_NO_MV, MODE_INTER_PLUS_MV, 188 MODE_INTER_NO_MV, MODE_INTER_PLUS_MV,
189 MODE_INTRA, MODE_USING_GOLDEN, 189 MODE_INTRA, MODE_USING_GOLDEN,
190 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 190 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
191 191
192 /* scheme 3 */ 192 /* scheme 3 */
193 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV, 193 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
194 MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV, 194 MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV,
195 MODE_INTRA, MODE_USING_GOLDEN, 195 MODE_INTRA, MODE_USING_GOLDEN,
196 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 196 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
197 197
198 /* scheme 4 */ 198 /* scheme 4 */
199 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV, 199 { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
200 MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST, 200 MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST,
201 MODE_INTRA, MODE_USING_GOLDEN, 201 MODE_INTRA, MODE_USING_GOLDEN,
202 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 202 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
203 203
204 /* scheme 5: No motion vector dominates */ 204 /* scheme 5: No motion vector dominates */
205 { MODE_INTER_NO_MV, MODE_INTER_LAST_MV, 205 { MODE_INTER_NO_MV, MODE_INTER_LAST_MV,
206 MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV, 206 MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV,
207 MODE_INTRA, MODE_USING_GOLDEN, 207 MODE_INTRA, MODE_USING_GOLDEN,
208 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 208 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
209 209
210 /* scheme 6 */ 210 /* scheme 6 */
211 { MODE_INTER_NO_MV, MODE_USING_GOLDEN, 211 { MODE_INTER_NO_MV, MODE_USING_GOLDEN,
212 MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST, 212 MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
213 MODE_INTER_PLUS_MV, MODE_INTRA, 213 MODE_INTER_PLUS_MV, MODE_INTRA,
214 MODE_GOLDEN_MV, MODE_INTER_FOURMV }, 214 MODE_GOLDEN_MV, MODE_INTER_FOURMV },
215 215
216 }; 216 };
217 217
218 #define MIN_DEQUANT_VAL 2 218 #define MIN_DEQUANT_VAL 2
254 Vp3Fragment *all_fragments; 254 Vp3Fragment *all_fragments;
255 Coeff *coeffs; 255 Coeff *coeffs;
256 Coeff *next_coeff; 256 Coeff *next_coeff;
257 int u_fragment_start; 257 int u_fragment_start;
258 int v_fragment_start; 258 int v_fragment_start;
259 259
260 ScanTable scantable; 260 ScanTable scantable;
261 261
262 /* tables */ 262 /* tables */
263 uint16_t coded_dc_scale_factor[64]; 263 uint16_t coded_dc_scale_factor[64];
264 uint32_t coded_ac_scale_factor[64]; 264 uint32_t coded_ac_scale_factor[64];
265 uint16_t coded_intra_y_dequant[64]; 265 uint16_t coded_intra_y_dequant[64];
266 uint16_t coded_intra_c_dequant[64]; 266 uint16_t coded_intra_c_dequant[64];
303 303
304 /* This table contains macroblock_count * 6 entries. Each set of 6 304 /* This table contains macroblock_count * 6 entries. Each set of 6
305 * numbers corresponds to the fragment indices 0..5 which comprise 305 * numbers corresponds to the fragment indices 0..5 which comprise
306 * the macroblock (4 Y fragments and 2 C fragments). */ 306 * the macroblock (4 Y fragments and 2 C fragments). */
307 int *macroblock_fragments; 307 int *macroblock_fragments;
308 /* This is an array that indicates how a particular macroblock 308 /* This is an array that indicates how a particular macroblock
309 * is coded. */ 309 * is coded. */
310 unsigned char *macroblock_coding; 310 unsigned char *macroblock_coding;
311 311
312 int first_coded_y_fragment; 312 int first_coded_y_fragment;
313 int first_coded_c_fragment; 313 int first_coded_c_fragment;
340 * superblocks <-> fragments, macroblocks <-> fragments, 340 * superblocks <-> fragments, macroblocks <-> fragments,
341 * superblocks <-> macroblocks 341 * superblocks <-> macroblocks
342 * 342 *
343 * Returns 0 is successful; returns 1 if *anything* went wrong. 343 * Returns 0 is successful; returns 1 if *anything* went wrong.
344 */ 344 */
345 static int init_block_mapping(Vp3DecodeContext *s) 345 static int init_block_mapping(Vp3DecodeContext *s)
346 { 346 {
347 int i, j; 347 int i, j;
348 signed int hilbert_walk_y[16]; 348 signed int hilbert_walk_y[16];
349 signed int hilbert_walk_c[16]; 349 signed int hilbert_walk_c[16];
350 signed int hilbert_walk_mb[4]; 350 signed int hilbert_walk_mb[4];
360 360
361 int current_macroblock; 361 int current_macroblock;
362 int c_fragment; 362 int c_fragment;
363 363
364 signed char travel_width[16] = { 364 signed char travel_width[16] = {
365 1, 1, 0, -1, 365 1, 1, 0, -1,
366 0, 0, 1, 0, 366 0, 0, 1, 0,
367 1, 0, 1, 0, 367 1, 0, 1, 0,
368 0, -1, 0, 1 368 0, -1, 0, 1
369 }; 369 };
370 370
436 /* start of Y superblocks */ 436 /* start of Y superblocks */
437 right_edge = s->fragment_width; 437 right_edge = s->fragment_width;
438 bottom_edge = s->fragment_height; 438 bottom_edge = s->fragment_height;
439 current_width = -1; 439 current_width = -1;
440 current_height = 0; 440 current_height = 0;
441 superblock_row_inc = 3 * s->fragment_width - 441 superblock_row_inc = 3 * s->fragment_width -
442 (s->y_superblock_width * 4 - s->fragment_width); 442 (s->y_superblock_width * 4 - s->fragment_width);
443 hilbert = hilbert_walk_y; 443 hilbert = hilbert_walk_y;
444 444
445 /* the first operation for this variable is to advance by 1 */ 445 /* the first operation for this variable is to advance by 1 */
446 current_fragment = -1; 446 current_fragment = -1;
450 /* start of U superblocks */ 450 /* start of U superblocks */
451 right_edge = s->fragment_width / 2; 451 right_edge = s->fragment_width / 2;
452 bottom_edge = s->fragment_height / 2; 452 bottom_edge = s->fragment_height / 2;
453 current_width = -1; 453 current_width = -1;
454 current_height = 0; 454 current_height = 0;
455 superblock_row_inc = 3 * (s->fragment_width / 2) - 455 superblock_row_inc = 3 * (s->fragment_width / 2) -
456 (s->c_superblock_width * 4 - s->fragment_width / 2); 456 (s->c_superblock_width * 4 - s->fragment_width / 2);
457 hilbert = hilbert_walk_c; 457 hilbert = hilbert_walk_c;
458 458
459 /* the first operation for this variable is to advance by 1 */ 459 /* the first operation for this variable is to advance by 1 */
460 current_fragment = s->u_fragment_start - 1; 460 current_fragment = s->u_fragment_start - 1;
464 /* start of V superblocks */ 464 /* start of V superblocks */
465 right_edge = s->fragment_width / 2; 465 right_edge = s->fragment_width / 2;
466 bottom_edge = s->fragment_height / 2; 466 bottom_edge = s->fragment_height / 2;
467 current_width = -1; 467 current_width = -1;
468 current_height = 0; 468 current_height = 0;
469 superblock_row_inc = 3 * (s->fragment_width / 2) - 469 superblock_row_inc = 3 * (s->fragment_width / 2) -
470 (s->c_superblock_width * 4 - s->fragment_width / 2); 470 (s->c_superblock_width * 4 - s->fragment_width / 2);
471 hilbert = hilbert_walk_c; 471 hilbert = hilbert_walk_c;
472 472
473 /* the first operation for this variable is to advance by 1 */ 473 /* the first operation for this variable is to advance by 1 */
474 current_fragment = s->v_fragment_start - 1; 474 current_fragment = s->v_fragment_start - 1;
492 492
493 /* check if the fragment is in bounds */ 493 /* check if the fragment is in bounds */
494 if ((current_width < right_edge) && 494 if ((current_width < right_edge) &&
495 (current_height < bottom_edge)) { 495 (current_height < bottom_edge)) {
496 s->superblock_fragments[mapping_index] = current_fragment; 496 s->superblock_fragments[mapping_index] = current_fragment;
497 debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n", 497 debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n",
498 s->superblock_fragments[mapping_index], i, j, 498 s->superblock_fragments[mapping_index], i, j,
499 current_width, right_edge, current_height, bottom_edge); 499 current_width, right_edge, current_height, bottom_edge);
500 } else { 500 } else {
501 s->superblock_fragments[mapping_index] = -1; 501 s->superblock_fragments[mapping_index] = -1;
502 debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n", 502 debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n",
503 i, j, 503 i, j,
504 current_width, right_edge, current_height, bottom_edge); 504 current_width, right_edge, current_height, bottom_edge);
505 } 505 }
506 506
507 mapping_index++; 507 mapping_index++;
573 debug_init("%d ", current_fragment + 1); 573 debug_init("%d ", current_fragment + 1);
574 } else 574 } else
575 s->macroblock_fragments[mapping_index++] = -1; 575 s->macroblock_fragments[mapping_index++] = -1;
576 576
577 if (i + 1 < s->fragment_height) { 577 if (i + 1 < s->fragment_height) {
578 s->all_fragments[current_fragment + s->fragment_width].macroblock = 578 s->all_fragments[current_fragment + s->fragment_width].macroblock =
579 current_macroblock; 579 current_macroblock;
580 s->macroblock_fragments[mapping_index++] = 580 s->macroblock_fragments[mapping_index++] =
581 current_fragment + s->fragment_width; 581 current_fragment + s->fragment_width;
582 debug_init("%d ", current_fragment + s->fragment_width); 582 debug_init("%d ", current_fragment + s->fragment_width);
583 } else 583 } else
584 s->macroblock_fragments[mapping_index++] = -1; 584 s->macroblock_fragments[mapping_index++] = -1;
585 585
586 if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) { 586 if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) {
587 s->all_fragments[current_fragment + s->fragment_width + 1].macroblock = 587 s->all_fragments[current_fragment + s->fragment_width + 1].macroblock =
588 current_macroblock; 588 current_macroblock;
589 s->macroblock_fragments[mapping_index++] = 589 s->macroblock_fragments[mapping_index++] =
590 current_fragment + s->fragment_width + 1; 590 current_fragment + s->fragment_width + 1;
591 debug_init("%d ", current_fragment + s->fragment_width + 1); 591 debug_init("%d ", current_fragment + s->fragment_width + 1);
592 } else 592 } else
593 s->macroblock_fragments[mapping_index++] = -1; 593 s->macroblock_fragments[mapping_index++] = -1;
594 594
595 /* C planes */ 595 /* C planes */
596 c_fragment = s->u_fragment_start + 596 c_fragment = s->u_fragment_start +
597 (i * s->fragment_width / 4) + (j / 2); 597 (i * s->fragment_width / 4) + (j / 2);
598 s->all_fragments[c_fragment].macroblock = s->macroblock_count; 598 s->all_fragments[c_fragment].macroblock = s->macroblock_count;
599 s->macroblock_fragments[mapping_index++] = c_fragment; 599 s->macroblock_fragments[mapping_index++] = c_fragment;
600 debug_init("%d ", c_fragment); 600 debug_init("%d ", c_fragment);
601 601
602 c_fragment = s->v_fragment_start + 602 c_fragment = s->v_fragment_start +
603 (i * s->fragment_width / 4) + (j / 2); 603 (i * s->fragment_width / 4) + (j / 2);
604 s->all_fragments[c_fragment].macroblock = s->macroblock_count; 604 s->all_fragments[c_fragment].macroblock = s->macroblock_count;
605 s->macroblock_fragments[mapping_index++] = c_fragment; 605 s->macroblock_fragments[mapping_index++] = c_fragment;
606 debug_init("%d ", c_fragment); 606 debug_init("%d ", c_fragment);
607 607
608 debug_init("\n"); 608 debug_init("\n");
609 609
610 if (j + 2 <= s->fragment_width) 610 if (j + 2 <= s->fragment_width)
611 current_fragment += 2; 611 current_fragment += 2;
612 else 612 else
613 current_fragment++; 613 current_fragment++;
614 current_macroblock++; 614 current_macroblock++;
615 } 615 }
616 616
617 current_fragment += s->fragment_width; 617 current_fragment += s->fragment_width;
651 int dc_scale_factor = s->coded_dc_scale_factor[s->quality_index]; 651 int dc_scale_factor = s->coded_dc_scale_factor[s->quality_index];
652 int i, j; 652 int i, j;
653 653
654 debug_vp3(" vp3: initializing dequantization tables\n"); 654 debug_vp3(" vp3: initializing dequantization tables\n");
655 655
656 /* 656 /*
657 * Scale dequantizers: 657 * Scale dequantizers:
658 * 658 *
659 * quantizer * sf 659 * quantizer * sf
660 * -------------- 660 * --------------
661 * 100 661 * 100
702 s->inter_dequant[j] = s->coded_inter_dequant[k] * ac_scale_factor / 100; 702 s->inter_dequant[j] = s->coded_inter_dequant[k] * ac_scale_factor / 100;
703 if (s->inter_dequant[j] < MIN_DEQUANT_VAL * 2) 703 if (s->inter_dequant[j] < MIN_DEQUANT_VAL * 2)
704 s->inter_dequant[j] = MIN_DEQUANT_VAL * 2; 704 s->inter_dequant[j] = MIN_DEQUANT_VAL * 2;
705 s->inter_dequant[j] *= SCALER; 705 s->inter_dequant[j] *= SCALER;
706 } 706 }
707 707
708 memset(s->qscale_table, (FFMAX(s->intra_y_dequant[1], s->intra_c_dequant[1])+8)/16, 512); //FIXME finetune 708 memset(s->qscale_table, (FFMAX(s->intra_y_dequant[1], s->intra_c_dequant[1])+8)/16, 512); //FIXME finetune
709 709
710 /* print debug information as requested */ 710 /* print debug information as requested */
711 debug_dequantizers("intra Y dequantizers:\n"); 711 debug_dequantizers("intra Y dequantizers:\n");
712 for (i = 0; i < 8; i++) { 712 for (i = 0; i < 8; i++) {
757 bounding_values[x + filter_limit] = filter_limit - x; 757 bounding_values[x + filter_limit] = filter_limit - x;
758 } 758 }
759 } 759 }
760 760
761 /* 761 /*
762 * This function unpacks all of the superblock/macroblock/fragment coding 762 * This function unpacks all of the superblock/macroblock/fragment coding
763 * information from the bitstream. 763 * information from the bitstream.
764 */ 764 */
765 static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) 765 static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
766 { 766 {
767 int bit = 0; 767 int bit = 0;
783 783
784 } else { 784 } else {
785 785
786 /* unpack the list of partially-coded superblocks */ 786 /* unpack the list of partially-coded superblocks */
787 bit = get_bits(gb, 1); 787 bit = get_bits(gb, 1);
788 /* toggle the bit because as soon as the first run length is 788 /* toggle the bit because as soon as the first run length is
789 * fetched the bit will be toggled again */ 789 * fetched the bit will be toggled again */
790 bit ^= 1; 790 bit ^= 1;
791 while (current_superblock < s->superblock_count) { 791 while (current_superblock < s->superblock_count) {
792 if (current_run-- == 0) { 792 if (current_run-- == 0) {
793 bit ^= 1; 793 bit ^= 1;
794 current_run = get_vlc2(gb, 794 current_run = get_vlc2(gb,
795 s->superblock_run_length_vlc.table, 6, 2); 795 s->superblock_run_length_vlc.table, 6, 2);
796 if (current_run == 33) 796 if (current_run == 33)
797 current_run += get_bits(gb, 12); 797 current_run += get_bits(gb, 12);
798 debug_block_coding(" setting superblocks %d..%d to %s\n", 798 debug_block_coding(" setting superblocks %d..%d to %s\n",
799 current_superblock, 799 current_superblock,
819 if (decode_fully_flags) { 819 if (decode_fully_flags) {
820 820
821 current_superblock = 0; 821 current_superblock = 0;
822 current_run = 0; 822 current_run = 0;
823 bit = get_bits(gb, 1); 823 bit = get_bits(gb, 1);
824 /* toggle the bit because as soon as the first run length is 824 /* toggle the bit because as soon as the first run length is
825 * fetched the bit will be toggled again */ 825 * fetched the bit will be toggled again */
826 bit ^= 1; 826 bit ^= 1;
827 while (current_superblock < s->superblock_count) { 827 while (current_superblock < s->superblock_count) {
828 828
829 /* skip any superblocks already marked as partially coded */ 829 /* skip any superblocks already marked as partially coded */
830 if (s->superblock_coding[current_superblock] == SB_NOT_CODED) { 830 if (s->superblock_coding[current_superblock] == SB_NOT_CODED) {
831 831
832 if (current_run-- == 0) { 832 if (current_run-- == 0) {
833 bit ^= 1; 833 bit ^= 1;
834 current_run = get_vlc2(gb, 834 current_run = get_vlc2(gb,
835 s->superblock_run_length_vlc.table, 6, 2); 835 s->superblock_run_length_vlc.table, 6, 2);
836 if (current_run == 33) 836 if (current_run == 33)
837 current_run += get_bits(gb, 12); 837 current_run += get_bits(gb, 12);
838 } 838 }
839 839
850 * unpacking fragment codings */ 850 * unpacking fragment codings */
851 if (decode_partial_blocks) { 851 if (decode_partial_blocks) {
852 852
853 current_run = 0; 853 current_run = 0;
854 bit = get_bits(gb, 1); 854 bit = get_bits(gb, 1);
855 /* toggle the bit because as soon as the first run length is 855 /* toggle the bit because as soon as the first run length is
856 * fetched the bit will be toggled again */ 856 * fetched the bit will be toggled again */
857 bit ^= 1; 857 bit ^= 1;
858 } 858 }
859 } 859 }
860 860
880 } 880 }
881 if (current_fragment != -1) { 881 if (current_fragment != -1) {
882 if (s->superblock_coding[i] == SB_NOT_CODED) { 882 if (s->superblock_coding[i] == SB_NOT_CODED) {
883 883
884 /* copy all the fragments from the prior frame */ 884 /* copy all the fragments from the prior frame */
885 s->all_fragments[current_fragment].coding_method = 885 s->all_fragments[current_fragment].coding_method =
886 MODE_COPY; 886 MODE_COPY;
887 887
888 } else if (s->superblock_coding[i] == SB_PARTIALLY_CODED) { 888 } else if (s->superblock_coding[i] == SB_PARTIALLY_CODED) {
889 889
890 /* fragment may or may not be coded; this is the case 890 /* fragment may or may not be coded; this is the case
891 * that cares about the fragment coding runs */ 891 * that cares about the fragment coding runs */
892 if (current_run-- == 0) { 892 if (current_run-- == 0) {
893 bit ^= 1; 893 bit ^= 1;
894 current_run = get_vlc2(gb, 894 current_run = get_vlc2(gb,
895 s->fragment_run_length_vlc.table, 5, 2); 895 s->fragment_run_length_vlc.table, 5, 2);
896 } 896 }
897 897
898 if (bit) { 898 if (bit) {
899 /* default mode; actual mode will be decoded in 899 /* default mode; actual mode will be decoded in
900 * the next phase */ 900 * the next phase */
901 s->all_fragments[current_fragment].coding_method = 901 s->all_fragments[current_fragment].coding_method =
902 MODE_INTER_NO_MV; 902 MODE_INTER_NO_MV;
903 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; 903 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment;
904 s->coded_fragment_list[s->coded_fragment_list_index] = 904 s->coded_fragment_list[s->coded_fragment_list_index] =
905 current_fragment; 905 current_fragment;
906 if ((current_fragment >= s->u_fragment_start) && 906 if ((current_fragment >= s->u_fragment_start) &&
907 (s->last_coded_y_fragment == -1) && 907 (s->last_coded_y_fragment == -1) &&
908 (!first_c_fragment_seen)) { 908 (!first_c_fragment_seen)) {
909 s->first_coded_c_fragment = s->coded_fragment_list_index; 909 s->first_coded_c_fragment = s->coded_fragment_list_index;
924 924
925 } else { 925 } else {
926 926
927 /* fragments are fully coded in this superblock; actual 927 /* fragments are fully coded in this superblock; actual
928 * coding will be determined in next step */ 928 * coding will be determined in next step */
929 s->all_fragments[current_fragment].coding_method = 929 s->all_fragments[current_fragment].coding_method =
930 MODE_INTER_NO_MV; 930 MODE_INTER_NO_MV;
931 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; 931 s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment;
932 s->coded_fragment_list[s->coded_fragment_list_index] = 932 s->coded_fragment_list[s->coded_fragment_list_index] =
933 current_fragment; 933 current_fragment;
934 if ((current_fragment >= s->u_fragment_start) && 934 if ((current_fragment >= s->u_fragment_start) &&
935 (s->last_coded_y_fragment == -1) && 935 (s->last_coded_y_fragment == -1) &&
936 (!first_c_fragment_seen)) { 936 (!first_c_fragment_seen)) {
937 s->first_coded_c_fragment = s->coded_fragment_list_index; 937 s->first_coded_c_fragment = s->coded_fragment_list_index;
948 } 948 }
949 949
950 if (!first_c_fragment_seen) 950 if (!first_c_fragment_seen)
951 /* only Y fragments coded in this frame */ 951 /* only Y fragments coded in this frame */
952 s->last_coded_y_fragment = s->coded_fragment_list_index - 1; 952 s->last_coded_y_fragment = s->coded_fragment_list_index - 1;
953 else 953 else
954 /* end the list of coded C fragments */ 954 /* end the list of coded C fragments */
955 s->last_coded_c_fragment = s->coded_fragment_list_index - 1; 955 s->last_coded_c_fragment = s->coded_fragment_list_index - 1;
956 956
957 debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n", 957 debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
958 s->coded_fragment_list_index, 958 s->coded_fragment_list_index,
996 for (i = 0; i < 8; i++) 996 for (i = 0; i < 8; i++)
997 ModeAlphabet[scheme][get_bits(gb, 3)] = i; 997 ModeAlphabet[scheme][get_bits(gb, 3)] = i;
998 } 998 }
999 999
1000 for (i = 0; i < 8; i++) 1000 for (i = 0; i < 8; i++)
1001 debug_modes(" mode[%d][%d] = %d\n", scheme, i, 1001 debug_modes(" mode[%d][%d] = %d\n", scheme, i,
1002 ModeAlphabet[scheme][i]); 1002 ModeAlphabet[scheme][i]);
1003 1003
1004 /* iterate through all of the macroblocks that contain 1 or more 1004 /* iterate through all of the macroblocks that contain 1 or more
1005 * coded fragments */ 1005 * coded fragments */
1006 for (i = 0; i < s->u_superblock_start; i++) { 1006 for (i = 0; i < s->u_superblock_start; i++) {
1023 coding_mode = ModeAlphabet[scheme] 1023 coding_mode = ModeAlphabet[scheme]
1024 [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; 1024 [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];
1025 1025
1026 s->macroblock_coding[current_macroblock] = coding_mode; 1026 s->macroblock_coding[current_macroblock] = coding_mode;
1027 for (k = 0; k < 6; k++) { 1027 for (k = 0; k < 6; k++) {
1028 current_fragment = 1028 current_fragment =
1029 s->macroblock_fragments[current_macroblock * 6 + k]; 1029 s->macroblock_fragments[current_macroblock * 6 + k];
1030 if (current_fragment == -1) 1030 if (current_fragment == -1)
1031 continue; 1031 continue;
1032 if (current_fragment >= s->fragment_count) { 1032 if (current_fragment >= s->fragment_count) {
1033 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad fragment number (%d >= %d)\n", 1033 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad fragment number (%d >= %d)\n",
1034 current_fragment, s->fragment_count); 1034 current_fragment, s->fragment_count);
1035 return 1; 1035 return 1;
1036 } 1036 }
1037 if (s->all_fragments[current_fragment].coding_method != 1037 if (s->all_fragments[current_fragment].coding_method !=
1038 MODE_COPY) 1038 MODE_COPY)
1039 s->all_fragments[current_fragment].coding_method = 1039 s->all_fragments[current_fragment].coding_method =
1040 coding_mode; 1040 coding_mode;
1041 } 1041 }
1042 1042
1144 } 1144 }
1145 motion_x[4] += motion_x[k]; 1145 motion_x[4] += motion_x[k];
1146 motion_y[4] += motion_y[k]; 1146 motion_y[4] += motion_y[k];
1147 } 1147 }
1148 1148
1149 if (motion_x[4] >= 0) 1149 if (motion_x[4] >= 0)
1150 motion_x[4] = (motion_x[4] + 2) / 4; 1150 motion_x[4] = (motion_x[4] + 2) / 4;
1151 else 1151 else
1152 motion_x[4] = (motion_x[4] - 2) / 4; 1152 motion_x[4] = (motion_x[4] - 2) / 4;
1153 motion_x[5] = motion_x[4]; 1153 motion_x[5] = motion_x[4];
1154 1154
1155 if (motion_y[4] >= 0) 1155 if (motion_y[4] >= 0)
1156 motion_y[4] = (motion_y[4] + 2) / 4; 1156 motion_y[4] = (motion_y[4] + 2) / 4;
1157 else 1157 else
1158 motion_y[4] = (motion_y[4] - 2) / 4; 1158 motion_y[4] = (motion_y[4] - 2) / 4;
1159 motion_y[5] = motion_y[4]; 1159 motion_y[5] = motion_y[4];
1160 1160
1208 /* assign the motion vectors to the correct fragments */ 1208 /* assign the motion vectors to the correct fragments */
1209 debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n", 1209 debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
1210 current_fragment, 1210 current_fragment,
1211 s->macroblock_coding[current_macroblock]); 1211 s->macroblock_coding[current_macroblock]);
1212 for (k = 0; k < 6; k++) { 1212 for (k = 0; k < 6; k++) {
1213 current_fragment = 1213 current_fragment =
1214 s->macroblock_fragments[current_macroblock * 6 + k]; 1214 s->macroblock_fragments[current_macroblock * 6 + k];
1215 if (current_fragment == -1) 1215 if (current_fragment == -1)
1216 continue; 1216 continue;
1217 if (current_fragment >= s->fragment_count) { 1217 if (current_fragment >= s->fragment_count) {
1218 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d)\n", 1218 av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d)\n",
1229 } 1229 }
1230 1230
1231 return 0; 1231 return 0;
1232 } 1232 }
1233 1233
1234 /* 1234 /*
1235 * This function is called by unpack_dct_coeffs() to extract the VLCs from 1235 * This function is called by unpack_dct_coeffs() to extract the VLCs from
1236 * the bitstream. The VLCs encode tokens which are used to unpack DCT 1236 * the bitstream. The VLCs encode tokens which are used to unpack DCT
1237 * data. This function unpacks all the VLCs for either the Y plane or both 1237 * data. This function unpacks all the VLCs for either the Y plane or both
1238 * C planes, and is called for DC coefficients or different AC coefficient 1238 * C planes, and is called for DC coefficients or different AC coefficient
1239 * levels (since different coefficient types require different VLC tables. 1239 * levels (since different coefficient types require different VLC tables.
1304 } 1304 }
1305 debug_vlc(" fragment %d coeff = %d\n", 1305 debug_vlc(" fragment %d coeff = %d\n",
1306 s->coded_fragment_list[i], fragment->next_coeff[coeff_index]); 1306 s->coded_fragment_list[i], fragment->next_coeff[coeff_index]);
1307 } else { 1307 } else {
1308 fragment->coeff_count |= 128; 1308 fragment->coeff_count |= 128;
1309 debug_vlc(" fragment %d eob with %d coefficients\n", 1309 debug_vlc(" fragment %d eob with %d coefficients\n",
1310 s->coded_fragment_list[i], fragment->coeff_count&127); 1310 s->coded_fragment_list[i], fragment->coeff_count&127);
1311 eob_run--; 1311 eob_run--;
1312 } 1312 }
1313 } 1313 }
1314 1314
1333 dc_c_table = get_bits(gb, 4); 1333 dc_c_table = get_bits(gb, 4);
1334 1334
1335 /* unpack the Y plane DC coefficients */ 1335 /* unpack the Y plane DC coefficients */
1336 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n", 1336 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
1337 dc_y_table); 1337 dc_y_table);
1338 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, 1338 residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0,
1339 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); 1339 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1340 1340
1341 /* unpack the C plane DC coefficients */ 1341 /* unpack the C plane DC coefficients */
1342 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n", 1342 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
1343 dc_c_table); 1343 dc_c_table);
1351 /* unpack the group 1 AC coefficients (coeffs 1-5) */ 1351 /* unpack the group 1 AC coefficients (coeffs 1-5) */
1352 for (i = 1; i <= 5; i++) { 1352 for (i = 1; i <= 5; i++) {
1353 1353
1354 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", 1354 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1355 i, ac_y_table); 1355 i, ac_y_table);
1356 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, 1356 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i,
1357 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); 1357 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1358 1358
1359 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", 1359 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1360 i, ac_c_table); 1360 i, ac_c_table);
1361 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, 1361 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i,
1362 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); 1362 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1363 } 1363 }
1364 1364
1365 /* unpack the group 2 AC coefficients (coeffs 6-14) */ 1365 /* unpack the group 2 AC coefficients (coeffs 6-14) */
1366 for (i = 6; i <= 14; i++) { 1366 for (i = 6; i <= 14; i++) {
1367 1367
1368 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", 1368 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1369 i, ac_y_table); 1369 i, ac_y_table);
1370 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, 1370 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i,
1371 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); 1371 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1372 1372
1373 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", 1373 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1374 i, ac_c_table); 1374 i, ac_c_table);
1375 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, 1375 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i,
1376 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); 1376 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1377 } 1377 }
1378 1378
1379 /* unpack the group 3 AC coefficients (coeffs 15-27) */ 1379 /* unpack the group 3 AC coefficients (coeffs 15-27) */
1380 for (i = 15; i <= 27; i++) { 1380 for (i = 15; i <= 27; i++) {
1381 1381
1382 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", 1382 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1383 i, ac_y_table); 1383 i, ac_y_table);
1384 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, 1384 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i,
1385 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); 1385 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1386 1386
1387 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", 1387 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1388 i, ac_c_table); 1388 i, ac_c_table);
1389 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, 1389 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i,
1390 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); 1390 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1391 } 1391 }
1392 1392
1393 /* unpack the group 4 AC coefficients (coeffs 28-63) */ 1393 /* unpack the group 4 AC coefficients (coeffs 28-63) */
1394 for (i = 28; i <= 63; i++) { 1394 for (i = 28; i <= 63; i++) {
1395 1395
1396 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n", 1396 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1397 i, ac_y_table); 1397 i, ac_y_table);
1398 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, 1398 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i,
1399 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); 1399 s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
1400 1400
1401 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n", 1401 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1402 i, ac_c_table); 1402 i, ac_c_table);
1403 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, 1403 residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i,
1404 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); 1404 s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
1405 } 1405 }
1406 1406
1407 return 0; 1407 return 0;
1408 } 1408 }
1409 1409
1410 /* 1410 /*
1411 * This function reverses the DC prediction for each coded fragment in 1411 * This function reverses the DC prediction for each coded fragment in
1412 * the frame. Much of this function is adapted directly from the original 1412 * the frame. Much of this function is adapted directly from the original
1413 * VP3 source code. 1413 * VP3 source code.
1414 */ 1414 */
1415 #define COMPATIBLE_FRAME(x) \ 1415 #define COMPATIBLE_FRAME(x) \
1416 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type) 1416 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1417 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY) 1417 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY)
1419 static inline int iabs (int x) { return ((x < 0) ? -x : x); } 1419 static inline int iabs (int x) { return ((x < 0) ? -x : x); }
1420 1420
1421 static void reverse_dc_prediction(Vp3DecodeContext *s, 1421 static void reverse_dc_prediction(Vp3DecodeContext *s,
1422 int first_fragment, 1422 int first_fragment,
1423 int fragment_width, 1423 int fragment_width,
1424 int fragment_height) 1424 int fragment_height)
1425 { 1425 {
1426 1426
1427 #define PUL 8 1427 #define PUL 8
1428 #define PU 4 1428 #define PU 4
1429 #define PUR 2 1429 #define PUR 2
1439 * 10000000004 1439 * 10000000004
1440 * 10000000004 1440 * 10000000004
1441 * 10000000004 1441 * 10000000004
1442 * 10000000004 1442 * 10000000004
1443 * 1443 *
1444 * Note: Groups 5 and 7 do not exist as it would mean that the 1444 * Note: Groups 5 and 7 do not exist as it would mean that the
1445 * fragment's x coordinate is both 0 and (width - 1) at the same time. 1445 * fragment's x coordinate is both 0 and (width - 1) at the same time.
1446 */ 1446 */
1447 int predictor_group; 1447 int predictor_group;
1448 short predicted_dc; 1448 short predicted_dc;
1449 1449
1454 int vl, vul, vu, vur; 1454 int vl, vul, vu, vur;
1455 1455
1456 /* indices for the left, up-left, up, and up-right fragments */ 1456 /* indices for the left, up-left, up, and up-right fragments */
1457 int l, ul, u, ur; 1457 int l, ul, u, ur;
1458 1458
1459 /* 1459 /*
1460 * The 6 fields mean: 1460 * The 6 fields mean:
1461 * 0: up-left multiplier 1461 * 0: up-left multiplier
1462 * 1: up multiplier 1462 * 1: up multiplier
1463 * 2: up-right multiplier 1463 * 2: up-right multiplier
1464 * 3: left multiplier 1464 * 3: left multiplier
1485 }; 1485 };
1486 1486
1487 /* This table shows which types of blocks can use other blocks for 1487 /* This table shows which types of blocks can use other blocks for
1488 * prediction. For example, INTRA is the only mode in this table to 1488 * prediction. For example, INTRA is the only mode in this table to
1489 * have a frame number of 0. That means INTRA blocks can only predict 1489 * have a frame number of 0. That means INTRA blocks can only predict
1490 * from other INTRA blocks. There are 2 golden frame coding types; 1490 * from other INTRA blocks. There are 2 golden frame coding types;
1491 * blocks encoding in these modes can only predict from other blocks 1491 * blocks encoding in these modes can only predict from other blocks
1492 * that were encoded with these 1 of these 2 modes. */ 1492 * that were encoded with these 1 of these 2 modes. */
1493 unsigned char compatible_frame[8] = { 1493 unsigned char compatible_frame[8] = {
1494 1, /* MODE_INTER_NO_MV */ 1494 1, /* MODE_INTER_NO_MV */
1495 0, /* MODE_INTRA */ 1495 0, /* MODE_INTRA */
1519 for (x = 0; x < fragment_width; x++, i++) { 1519 for (x = 0; x < fragment_width; x++, i++) {
1520 1520
1521 /* reverse prediction if this block was coded */ 1521 /* reverse prediction if this block was coded */
1522 if (s->all_fragments[i].coding_method != MODE_COPY) { 1522 if (s->all_fragments[i].coding_method != MODE_COPY) {
1523 1523
1524 current_frame_type = 1524 current_frame_type =
1525 compatible_frame[s->all_fragments[i].coding_method]; 1525 compatible_frame[s->all_fragments[i].coding_method];
1526 predictor_group = (x == 0) + ((y == 0) << 1) + 1526 predictor_group = (x == 0) + ((y == 0) << 1) +
1527 ((x + 1 == fragment_width) << 2); 1527 ((x + 1 == fragment_width) << 2);
1528 debug_dc_pred(" frag %d: group %d, orig DC = %d, ", 1528 debug_dc_pred(" frag %d: group %d, orig DC = %d, ",
1529 i, predictor_group, DC_COEFF(i)); 1529 i, predictor_group, DC_COEFF(i));
1637 if (transform == 0) { 1637 if (transform == 0) {
1638 1638
1639 /* if there were no fragments to predict from, use last 1639 /* if there were no fragments to predict from, use last
1640 * DC saved */ 1640 * DC saved */
1641 predicted_dc = last_dc[current_frame_type]; 1641 predicted_dc = last_dc[current_frame_type];
1642 debug_dc_pred("from last DC (%d) = %d\n", 1642 debug_dc_pred("from last DC (%d) = %d\n",
1643 current_frame_type, DC_COEFF(i)); 1643 current_frame_type, DC_COEFF(i));
1644 1644
1645 } else { 1645 } else {
1646 1646
1647 /* apply the appropriate predictor transform */ 1647 /* apply the appropriate predictor transform */
1652 (predictor_transform[transform][3] * vl); 1652 (predictor_transform[transform][3] * vl);
1653 1653
1654 /* if there is a shift value in the transform, add 1654 /* if there is a shift value in the transform, add
1655 * the sign bit before the shift */ 1655 * the sign bit before the shift */
1656 if (predictor_transform[transform][5] != 0) { 1656 if (predictor_transform[transform][5] != 0) {
1657 predicted_dc += ((predicted_dc >> 15) & 1657 predicted_dc += ((predicted_dc >> 15) &
1658 predictor_transform[transform][4]); 1658 predictor_transform[transform][4]);
1659 predicted_dc >>= predictor_transform[transform][5]; 1659 predicted_dc >>= predictor_transform[transform][5];
1660 } 1660 }
1661 1661
1662 /* check for outranging on the [ul u l] and 1662 /* check for outranging on the [ul u l] and
1668 predicted_dc = vl; 1668 predicted_dc = vl;
1669 else if (iabs(predicted_dc - vul) > 128) 1669 else if (iabs(predicted_dc - vul) > 128)
1670 predicted_dc = vul; 1670 predicted_dc = vul;
1671 } 1671 }
1672 1672
1673 debug_dc_pred("from pred DC = %d\n", 1673 debug_dc_pred("from pred DC = %d\n",
1674 DC_COEFF(i)); 1674 DC_COEFF(i));
1675 } 1675 }
1676 1676
1677 /* at long last, apply the predictor */ 1677 /* at long last, apply the predictor */
1678 if(s->coeffs[i].index){ 1678 if(s->coeffs[i].index){
1772 plane_height = s->height / 2; 1772 plane_height = s->height / 2;
1773 slice_height = y + FRAGMENT_PIXELS; 1773 slice_height = y + FRAGMENT_PIXELS;
1774 i = s->macroblock_fragments[current_macroblock_entry + 5]; 1774 i = s->macroblock_fragments[current_macroblock_entry + 5];
1775 } 1775 }
1776 fragment_width = plane_width / FRAGMENT_PIXELS; 1776 fragment_width = plane_width / FRAGMENT_PIXELS;
1777 1777
1778 if(ABS(stride) > 2048) 1778 if(ABS(stride) > 2048)
1779 return; //various tables are fixed size 1779 return; //various tables are fixed size
1780 1780
1781 /* for each fragment row in the slice (both of them)... */ 1781 /* for each fragment row in the slice (both of them)... */
1782 for (; y < slice_height; y += 8) { 1782 for (; y < slice_height; y += 8) {
1794 !((s->avctx->flags & CODEC_FLAG_GRAY) && plane)) { 1794 !((s->avctx->flags & CODEC_FLAG_GRAY) && plane)) {
1795 1795
1796 if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || 1796 if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) ||
1797 (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) 1797 (s->all_fragments[i].coding_method == MODE_GOLDEN_MV))
1798 motion_source= golden_plane; 1798 motion_source= golden_plane;
1799 else 1799 else
1800 motion_source= last_plane; 1800 motion_source= last_plane;
1801 1801
1802 motion_source += s->all_fragments[i].first_pixel; 1802 motion_source += s->all_fragments[i].first_pixel;
1803 motion_halfpel_index = 0; 1803 motion_halfpel_index = 0;
1804 1804
1832 1832
1833 ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height); 1833 ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height);
1834 motion_source= temp; 1834 motion_source= temp;
1835 } 1835 }
1836 } 1836 }
1837 1837
1838 1838
1839 /* first, take care of copying a block from either the 1839 /* first, take care of copying a block from either the
1840 * previous or the golden frame */ 1840 * previous or the golden frame */
1841 if (s->all_fragments[i].coding_method != MODE_INTRA) { 1841 if (s->all_fragments[i].coding_method != MODE_INTRA) {
1842 /* Note, it is possible to implement all MC cases with 1842 /* Note, it is possible to implement all MC cases with
1843 put_no_rnd_pixels_l2 which would look more like the 1843 put_no_rnd_pixels_l2 which would look more like the
1844 VP3 source but this would be slower as 1844 VP3 source but this would be slower as
1845 put_no_rnd_pixels_tab is better optimzed */ 1845 put_no_rnd_pixels_tab is better optimzed */
1846 if(motion_halfpel_index != 3){ 1846 if(motion_halfpel_index != 3){
1847 s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index]( 1847 s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
1848 output_plane + s->all_fragments[i].first_pixel, 1848 output_plane + s->all_fragments[i].first_pixel,
1849 motion_source, stride, 8); 1849 motion_source, stride, 8);
1850 }else{ 1850 }else{
1851 int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1 1851 int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1
1852 s->dsp.put_no_rnd_pixels_l2[1]( 1852 s->dsp.put_no_rnd_pixels_l2[1](
1853 output_plane + s->all_fragments[i].first_pixel, 1853 output_plane + s->all_fragments[i].first_pixel,
1854 motion_source - d, 1854 motion_source - d,
1855 motion_source + stride + 1 + d, 1855 motion_source + stride + 1 + d,
1856 stride, 8); 1856 stride, 8);
1857 } 1857 }
1858 dequantizer = s->inter_dequant; 1858 dequantizer = s->inter_dequant;
1859 }else{ 1859 }else{
1860 if (plane == 0) 1860 if (plane == 0)
1862 else 1862 else
1863 dequantizer = s->intra_c_dequant; 1863 dequantizer = s->intra_c_dequant;
1864 } 1864 }
1865 1865
1866 /* dequantize the DCT coefficients */ 1866 /* dequantize the DCT coefficients */
1867 debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n", 1867 debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n",
1868 i, s->all_fragments[i].coding_method, 1868 i, s->all_fragments[i].coding_method,
1869 DC_COEFF(i), dequantizer[0]); 1869 DC_COEFF(i), dequantizer[0]);
1870 1870
1871 if(s->avctx->idct_algo==FF_IDCT_VP3){ 1871 if(s->avctx->idct_algo==FF_IDCT_VP3){
1872 Coeff *coeff= s->coeffs + i; 1872 Coeff *coeff= s->coeffs + i;
1873 memset(block, 0, sizeof(block)); 1873 memset(block, 0, sizeof(block));
1883 coeff= coeff->next; 1883 coeff= coeff->next;
1884 } 1884 }
1885 } 1885 }
1886 1886
1887 /* invert DCT and place (or add) in final output */ 1887 /* invert DCT and place (or add) in final output */
1888 1888
1889 if (s->all_fragments[i].coding_method == MODE_INTRA) { 1889 if (s->all_fragments[i].coding_method == MODE_INTRA) {
1890 if(s->avctx->idct_algo!=FF_IDCT_VP3) 1890 if(s->avctx->idct_algo!=FF_IDCT_VP3)
1891 block[0] += 128<<3; 1891 block[0] += 128<<3;
1892 s->dsp.idct_put( 1892 s->dsp.idct_put(
1893 output_plane + s->all_fragments[i].first_pixel, 1893 output_plane + s->all_fragments[i].first_pixel,
1903 debug_idct("block after idct_%s():\n", 1903 debug_idct("block after idct_%s():\n",
1904 (s->all_fragments[i].coding_method == MODE_INTRA)? 1904 (s->all_fragments[i].coding_method == MODE_INTRA)?
1905 "put" : "add"); 1905 "put" : "add");
1906 for (m = 0; m < 8; m++) { 1906 for (m = 0; m < 8; m++) {
1907 for (n = 0; n < 8; n++) { 1907 for (n = 0; n < 8; n++) {
1908 debug_idct(" %3d", *(output_plane + 1908 debug_idct(" %3d", *(output_plane +
1909 s->all_fragments[i].first_pixel + (m * stride + n))); 1909 s->all_fragments[i].first_pixel + (m * stride + n)));
1910 } 1910 }
1911 debug_idct("\n"); 1911 debug_idct("\n");
1912 } 1912 }
1913 debug_idct("\n"); 1913 debug_idct("\n");
1974 { 1974 {
1975 unsigned char *end; 1975 unsigned char *end;
1976 int filter_value; 1976 int filter_value;
1977 1977
1978 for (end= first_pixel + 8*stride; first_pixel < end; first_pixel += stride) { 1978 for (end= first_pixel + 8*stride; first_pixel < end; first_pixel += stride) {
1979 filter_value = 1979 filter_value =
1980 (first_pixel[-2] - first_pixel[ 1]) 1980 (first_pixel[-2] - first_pixel[ 1])
1981 +3*(first_pixel[ 0] - first_pixel[-1]); 1981 +3*(first_pixel[ 0] - first_pixel[-1]);
1982 filter_value = bounding_values[(filter_value + 4) >> 3]; 1982 filter_value = bounding_values[(filter_value + 4) >> 3];
1983 first_pixel[-1] = clip_uint8(first_pixel[-1] + filter_value); 1983 first_pixel[-1] = clip_uint8(first_pixel[-1] + filter_value);
1984 first_pixel[ 0] = clip_uint8(first_pixel[ 0] - filter_value); 1984 first_pixel[ 0] = clip_uint8(first_pixel[ 0] - filter_value);
1991 unsigned char *end; 1991 unsigned char *end;
1992 int filter_value; 1992 int filter_value;
1993 const int nstride= -stride; 1993 const int nstride= -stride;
1994 1994
1995 for (end= first_pixel + 8; first_pixel < end; first_pixel++) { 1995 for (end= first_pixel + 8; first_pixel < end; first_pixel++) {
1996 filter_value = 1996 filter_value =
1997 (first_pixel[2 * nstride] - first_pixel[ stride]) 1997 (first_pixel[2 * nstride] - first_pixel[ stride])
1998 +3*(first_pixel[0 ] - first_pixel[nstride]); 1998 +3*(first_pixel[0 ] - first_pixel[nstride]);
1999 filter_value = bounding_values[(filter_value + 4) >> 3]; 1999 filter_value = bounding_values[(filter_value + 4) >> 3];
2000 first_pixel[nstride] = clip_uint8(first_pixel[nstride] + filter_value); 2000 first_pixel[nstride] = clip_uint8(first_pixel[nstride] + filter_value);
2001 first_pixel[0] = clip_uint8(first_pixel[0] - filter_value); 2001 first_pixel[0] = clip_uint8(first_pixel[0] - filter_value);
2063 START_TIMER 2063 START_TIMER
2064 /* do not perform left edge filter for left columns frags */ 2064 /* do not perform left edge filter for left columns frags */
2065 if ((x > 0) && 2065 if ((x > 0) &&
2066 (s->all_fragments[fragment].coding_method != MODE_COPY)) { 2066 (s->all_fragments[fragment].coding_method != MODE_COPY)) {
2067 horizontal_filter( 2067 horizontal_filter(
2068 plane_data + s->all_fragments[fragment].first_pixel - 7*stride, 2068 plane_data + s->all_fragments[fragment].first_pixel - 7*stride,
2069 stride, bounding_values); 2069 stride, bounding_values);
2070 } 2070 }
2071 2071
2072 /* do not perform top edge filter for top row fragments */ 2072 /* do not perform top edge filter for top row fragments */
2073 if ((y > 0) && 2073 if ((y > 0) &&
2074 (s->all_fragments[fragment].coding_method != MODE_COPY)) { 2074 (s->all_fragments[fragment].coding_method != MODE_COPY)) {
2075 vertical_filter( 2075 vertical_filter(
2076 plane_data + s->all_fragments[fragment].first_pixel + stride, 2076 plane_data + s->all_fragments[fragment].first_pixel + stride,
2077 stride, bounding_values); 2077 stride, bounding_values);
2078 } 2078 }
2079 2079
2080 /* do not perform right edge filter for right column 2080 /* do not perform right edge filter for right column
2081 * fragments or if right fragment neighbor is also coded 2081 * fragments or if right fragment neighbor is also coded
2082 * in this frame (it will be filtered in next iteration) */ 2082 * in this frame (it will be filtered in next iteration) */
2083 if ((x < width - 1) && 2083 if ((x < width - 1) &&
2084 (s->all_fragments[fragment].coding_method != MODE_COPY) && 2084 (s->all_fragments[fragment].coding_method != MODE_COPY) &&
2085 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) { 2085 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) {
2086 horizontal_filter( 2086 horizontal_filter(
2087 plane_data + s->all_fragments[fragment + 1].first_pixel - 7*stride, 2087 plane_data + s->all_fragments[fragment + 1].first_pixel - 7*stride,
2088 stride, bounding_values); 2088 stride, bounding_values);
2089 } 2089 }
2090 2090
2091 /* do not perform bottom edge filter for bottom row 2091 /* do not perform bottom edge filter for bottom row
2092 * fragments or if bottom fragment neighbor is also coded 2092 * fragments or if bottom fragment neighbor is also coded
2093 * in this frame (it will be filtered in the next row) */ 2093 * in this frame (it will be filtered in the next row) */
2094 if ((y < height - 1) && 2094 if ((y < height - 1) &&
2095 (s->all_fragments[fragment].coding_method != MODE_COPY) && 2095 (s->all_fragments[fragment].coding_method != MODE_COPY) &&
2096 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) { 2096 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) {
2097 vertical_filter( 2097 vertical_filter(
2098 plane_data + s->all_fragments[fragment + width].first_pixel + stride, 2098 plane_data + s->all_fragments[fragment + width].first_pixel + stride,
2099 stride, bounding_values); 2099 stride, bounding_values);
2100 } 2100 }
2101 2101
2102 fragment++; 2102 fragment++;
2103 STOP_TIMER("loop filter") 2103 STOP_TIMER("loop filter")
2104 } 2104 }
2105 } 2105 }
2106 } 2106 }
2107 } 2107 }
2108 2108
2109 /* 2109 /*
2110 * This function computes the first pixel addresses for each fragment. 2110 * This function computes the first pixel addresses for each fragment.
2111 * This function needs to be invoked after the first frame is allocated 2111 * This function needs to be invoked after the first frame is allocated
2112 * so that it has access to the plane strides. 2112 * so that it has access to the plane strides.
2113 */ 2113 */
2114 static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s) 2114 static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s)
2115 { 2115 {
2116 2116
2117 int i, x, y; 2117 int i, x, y;
2118 2118
2119 /* figure out the first pixel addresses for each of the fragments */ 2119 /* figure out the first pixel addresses for each of the fragments */
2120 /* Y plane */ 2120 /* Y plane */
2121 i = 0; 2121 i = 0;
2122 for (y = s->fragment_height; y > 0; y--) { 2122 for (y = s->fragment_height; y > 0; y--) {
2123 for (x = 0; x < s->fragment_width; x++) { 2123 for (x = 0; x < s->fragment_width; x++) {
2124 s->all_fragments[i++].first_pixel = 2124 s->all_fragments[i++].first_pixel =
2125 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - 2125 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS -
2126 s->golden_frame.linesize[0] + 2126 s->golden_frame.linesize[0] +
2127 x * FRAGMENT_PIXELS; 2127 x * FRAGMENT_PIXELS;
2128 debug_init(" fragment %d, first pixel @ %d\n", 2128 debug_init(" fragment %d, first pixel @ %d\n",
2129 i-1, s->all_fragments[i-1].first_pixel); 2129 i-1, s->all_fragments[i-1].first_pixel);
2130 } 2130 }
2131 } 2131 }
2132 2132
2133 /* U plane */ 2133 /* U plane */
2134 i = s->u_fragment_start; 2134 i = s->u_fragment_start;
2135 for (y = s->fragment_height / 2; y > 0; y--) { 2135 for (y = s->fragment_height / 2; y > 0; y--) {
2136 for (x = 0; x < s->fragment_width / 2; x++) { 2136 for (x = 0; x < s->fragment_width / 2; x++) {
2137 s->all_fragments[i++].first_pixel = 2137 s->all_fragments[i++].first_pixel =
2138 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - 2138 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS -
2139 s->golden_frame.linesize[1] + 2139 s->golden_frame.linesize[1] +
2140 x * FRAGMENT_PIXELS; 2140 x * FRAGMENT_PIXELS;
2141 debug_init(" fragment %d, first pixel @ %d\n", 2141 debug_init(" fragment %d, first pixel @ %d\n",
2142 i-1, s->all_fragments[i-1].first_pixel); 2142 i-1, s->all_fragments[i-1].first_pixel);
2143 } 2143 }
2144 } 2144 }
2145 2145
2146 /* V plane */ 2146 /* V plane */
2147 i = s->v_fragment_start; 2147 i = s->v_fragment_start;
2148 for (y = s->fragment_height / 2; y > 0; y--) { 2148 for (y = s->fragment_height / 2; y > 0; y--) {
2149 for (x = 0; x < s->fragment_width / 2; x++) { 2149 for (x = 0; x < s->fragment_width / 2; x++) {
2150 s->all_fragments[i++].first_pixel = 2150 s->all_fragments[i++].first_pixel =
2151 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - 2151 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS -
2152 s->golden_frame.linesize[2] + 2152 s->golden_frame.linesize[2] +
2153 x * FRAGMENT_PIXELS; 2153 x * FRAGMENT_PIXELS;
2154 debug_init(" fragment %d, first pixel @ %d\n", 2154 debug_init(" fragment %d, first pixel @ %d\n",
2155 i-1, s->all_fragments[i-1].first_pixel); 2155 i-1, s->all_fragments[i-1].first_pixel);
2156 } 2156 }
2157 } 2157 }
2158 } 2158 }
2159 2159
2160 /* FIXME: this should be merged with the above! */ 2160 /* FIXME: this should be merged with the above! */
2161 static void theora_calculate_pixel_addresses(Vp3DecodeContext *s) 2161 static void theora_calculate_pixel_addresses(Vp3DecodeContext *s)
2162 { 2162 {
2163 2163
2164 int i, x, y; 2164 int i, x, y;
2165 2165
2166 /* figure out the first pixel addresses for each of the fragments */ 2166 /* figure out the first pixel addresses for each of the fragments */
2167 /* Y plane */ 2167 /* Y plane */
2168 i = 0; 2168 i = 0;
2169 for (y = 1; y <= s->fragment_height; y++) { 2169 for (y = 1; y <= s->fragment_height; y++) {
2170 for (x = 0; x < s->fragment_width; x++) { 2170 for (x = 0; x < s->fragment_width; x++) {
2171 s->all_fragments[i++].first_pixel = 2171 s->all_fragments[i++].first_pixel =
2172 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - 2172 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS -
2173 s->golden_frame.linesize[0] + 2173 s->golden_frame.linesize[0] +
2174 x * FRAGMENT_PIXELS; 2174 x * FRAGMENT_PIXELS;
2175 debug_init(" fragment %d, first pixel @ %d\n", 2175 debug_init(" fragment %d, first pixel @ %d\n",
2176 i-1, s->all_fragments[i-1].first_pixel); 2176 i-1, s->all_fragments[i-1].first_pixel);
2177 } 2177 }
2178 } 2178 }
2179 2179
2180 /* U plane */ 2180 /* U plane */
2181 i = s->u_fragment_start; 2181 i = s->u_fragment_start;
2182 for (y = 1; y <= s->fragment_height / 2; y++) { 2182 for (y = 1; y <= s->fragment_height / 2; y++) {
2183 for (x = 0; x < s->fragment_width / 2; x++) { 2183 for (x = 0; x < s->fragment_width / 2; x++) {
2184 s->all_fragments[i++].first_pixel = 2184 s->all_fragments[i++].first_pixel =
2185 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - 2185 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS -
2186 s->golden_frame.linesize[1] + 2186 s->golden_frame.linesize[1] +
2187 x * FRAGMENT_PIXELS; 2187 x * FRAGMENT_PIXELS;
2188 debug_init(" fragment %d, first pixel @ %d\n", 2188 debug_init(" fragment %d, first pixel @ %d\n",
2189 i-1, s->all_fragments[i-1].first_pixel); 2189 i-1, s->all_fragments[i-1].first_pixel);
2190 } 2190 }
2191 } 2191 }
2192 2192
2193 /* V plane */ 2193 /* V plane */
2194 i = s->v_fragment_start; 2194 i = s->v_fragment_start;
2195 for (y = 1; y <= s->fragment_height / 2; y++) { 2195 for (y = 1; y <= s->fragment_height / 2; y++) {
2196 for (x = 0; x < s->fragment_width / 2; x++) { 2196 for (x = 0; x < s->fragment_width / 2; x++) {
2197 s->all_fragments[i++].first_pixel = 2197 s->all_fragments[i++].first_pixel =
2198 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - 2198 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS -
2199 s->golden_frame.linesize[2] + 2199 s->golden_frame.linesize[2] +
2200 x * FRAGMENT_PIXELS; 2200 x * FRAGMENT_PIXELS;
2201 debug_init(" fragment %d, first pixel @ %d\n", 2201 debug_init(" fragment %d, first pixel @ %d\n",
2202 i-1, s->all_fragments[i-1].first_pixel); 2202 i-1, s->all_fragments[i-1].first_pixel);
2203 } 2203 }
2204 } 2204 }
2205 } 2205 }
2206 2206
2227 avctx->pix_fmt = PIX_FMT_YUV420P; 2227 avctx->pix_fmt = PIX_FMT_YUV420P;
2228 avctx->has_b_frames = 0; 2228 avctx->has_b_frames = 0;
2229 if(avctx->idct_algo==FF_IDCT_AUTO) 2229 if(avctx->idct_algo==FF_IDCT_AUTO)
2230 avctx->idct_algo=FF_IDCT_VP3; 2230 avctx->idct_algo=FF_IDCT_VP3;
2231 dsputil_init(&s->dsp, avctx); 2231 dsputil_init(&s->dsp, avctx);
2232 2232
2233 ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); 2233 ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
2234 2234
2235 /* initialize to an impossible value which will force a recalculation 2235 /* initialize to an impossible value which will force a recalculation
2236 * in the first frame decode */ 2236 * in the first frame decode */
2237 s->quality_index = -1; 2237 s->quality_index = -1;
2268 debug_init(" C plane: %d x %d\n", c_width, c_height); 2268 debug_init(" C plane: %d x %d\n", c_width, c_height);
2269 debug_init(" Y superblocks: %d x %d, %d total\n", 2269 debug_init(" Y superblocks: %d x %d, %d total\n",
2270 s->y_superblock_width, s->y_superblock_height, y_superblock_count); 2270 s->y_superblock_width, s->y_superblock_height, y_superblock_count);
2271 debug_init(" C superblocks: %d x %d, %d total\n", 2271 debug_init(" C superblocks: %d x %d, %d total\n",
2272 s->c_superblock_width, s->c_superblock_height, c_superblock_count); 2272 s->c_superblock_width, s->c_superblock_height, c_superblock_count);
2273 debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n", 2273 debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n",
2274 s->superblock_count, s->u_superblock_start, s->v_superblock_start); 2274 s->superblock_count, s->u_superblock_start, s->v_superblock_start);
2275 debug_init(" macroblocks: %d x %d, %d total\n", 2275 debug_init(" macroblocks: %d x %d, %d total\n",
2276 s->macroblock_width, s->macroblock_height, s->macroblock_count); 2276 s->macroblock_width, s->macroblock_height, s->macroblock_count);
2277 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n", 2277 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
2278 s->fragment_count, 2278 s->fragment_count,
2392 } 2392 }
2393 2393
2394 /* 2394 /*
2395 * This is the ffmpeg/libavcodec API frame decode function. 2395 * This is the ffmpeg/libavcodec API frame decode function.
2396 */ 2396 */
2397 static int vp3_decode_frame(AVCodecContext *avctx, 2397 static int vp3_decode_frame(AVCodecContext *avctx,
2398 void *data, int *data_size, 2398 void *data, int *data_size,
2399 uint8_t *buf, int buf_size) 2399 uint8_t *buf, int buf_size)
2400 { 2400 {
2401 Vp3DecodeContext *s = avctx->priv_data; 2401 Vp3DecodeContext *s = avctx->priv_data;
2402 GetBitContext gb; 2402 GetBitContext gb;
2403 static int counter = 0; 2403 static int counter = 0;
2404 int i; 2404 int i;
2405 2405
2406 init_get_bits(&gb, buf, buf_size * 8); 2406 init_get_bits(&gb, buf, buf_size * 8);
2407 2407
2408 if (s->theora && get_bits1(&gb)) 2408 if (s->theora && get_bits1(&gb))
2409 { 2409 {
2410 #if 1 2410 #if 1
2411 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); 2411 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");
2412 return -1; 2412 return -1;
2413 #else 2413 #else
2414 int ptype = get_bits(&gb, 7); 2414 int ptype = get_bits(&gb, 7);
2415 2415
2416 skip_bits(&gb, 6*8); /* "theora" */ 2416 skip_bits(&gb, 6*8); /* "theora" */
2417 2417
2418 switch(ptype) 2418 switch(ptype)
2419 { 2419 {
2420 case 1: 2420 case 1:
2421 theora_decode_comments(avctx, gb); 2421 theora_decode_comments(avctx, gb);
2422 break; 2422 break;
2600 av_free(s->coded_fragment_list); 2600 av_free(s->coded_fragment_list);
2601 av_free(s->superblock_fragments); 2601 av_free(s->superblock_fragments);
2602 av_free(s->superblock_macroblocks); 2602 av_free(s->superblock_macroblocks);
2603 av_free(s->macroblock_fragments); 2603 av_free(s->macroblock_fragments);
2604 av_free(s->macroblock_coding); 2604 av_free(s->macroblock_coding);
2605 2605
2606 /* release all frames */ 2606 /* release all frames */
2607 if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0]) 2607 if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0])
2608 avctx->release_buffer(avctx, &s->golden_frame); 2608 avctx->release_buffer(avctx, &s->golden_frame);
2609 if (s->last_frame.data[0]) 2609 if (s->last_frame.data[0])
2610 avctx->release_buffer(avctx, &s->last_frame); 2610 avctx->release_buffer(avctx, &s->last_frame);
2668 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n"); 2668 av_log(avctx, AV_LOG_DEBUG, "Old (<alpha3) Theora bitstream, flipped image\n");
2669 } 2669 }
2670 2670
2671 s->width = get_bits(&gb, 16) << 4; 2671 s->width = get_bits(&gb, 16) << 4;
2672 s->height = get_bits(&gb, 16) << 4; 2672 s->height = get_bits(&gb, 16) << 4;
2673 2673
2674 if(avcodec_check_dimensions(avctx, s->width, s->height)){ 2674 if(avcodec_check_dimensions(avctx, s->width, s->height)){
2675 av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height); 2675 av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", s->width, s->height);
2676 s->width= s->height= 0; 2676 s->width= s->height= 0;
2677 return -1; 2677 return -1;
2678 } 2678 }
2682 skip_bits(&gb, 32); /* total number of superblocks in a frame */ 2682 skip_bits(&gb, 32); /* total number of superblocks in a frame */
2683 // fixme, the next field is 36bits long 2683 // fixme, the next field is 36bits long
2684 skip_bits(&gb, 32); /* total number of blocks in a frame */ 2684 skip_bits(&gb, 32); /* total number of blocks in a frame */
2685 skip_bits(&gb, 4); /* total number of blocks in a frame */ 2685 skip_bits(&gb, 4); /* total number of blocks in a frame */
2686 skip_bits(&gb, 32); /* total number of macroblocks in a frame */ 2686 skip_bits(&gb, 32); /* total number of macroblocks in a frame */
2687 2687
2688 skip_bits(&gb, 24); /* frame width */ 2688 skip_bits(&gb, 24); /* frame width */
2689 skip_bits(&gb, 24); /* frame height */ 2689 skip_bits(&gb, 24); /* frame height */
2690 } 2690 }
2691 else 2691 else
2692 { 2692 {
2699 2699
2700 skip_bits(&gb, 32); /* fps numerator */ 2700 skip_bits(&gb, 32); /* fps numerator */
2701 skip_bits(&gb, 32); /* fps denumerator */ 2701 skip_bits(&gb, 32); /* fps denumerator */
2702 skip_bits(&gb, 24); /* aspect numerator */ 2702 skip_bits(&gb, 24); /* aspect numerator */
2703 skip_bits(&gb, 24); /* aspect denumerator */ 2703 skip_bits(&gb, 24); /* aspect denumerator */
2704 2704
2705 if (s->theora < 0x030200) 2705 if (s->theora < 0x030200)
2706 skip_bits(&gb, 5); /* keyframe frequency force */ 2706 skip_bits(&gb, 5); /* keyframe frequency force */
2707 skip_bits(&gb, 8); /* colorspace */ 2707 skip_bits(&gb, 8); /* colorspace */
2708 if (s->theora >= 0x030400) 2708 if (s->theora >= 0x030400)
2709 skip_bits(&gb, 2); /* pixel format: 420,res,422,444 */ 2709 skip_bits(&gb, 2); /* pixel format: 420,res,422,444 */
2710 skip_bits(&gb, 24); /* bitrate */ 2710 skip_bits(&gb, 24); /* bitrate */
2711 2711
2712 skip_bits(&gb, 6); /* quality hint */ 2712 skip_bits(&gb, 6); /* quality hint */
2713 2713
2714 if (s->theora >= 0x030200) 2714 if (s->theora >= 0x030200)
2715 { 2715 {
2716 skip_bits(&gb, 5); /* keyframe frequency force */ 2716 skip_bits(&gb, 5); /* keyframe frequency force */
2717 2717
2718 if (s->theora < 0x030400) 2718 if (s->theora < 0x030400)
2719 skip_bits(&gb, 5); /* spare bits */ 2719 skip_bits(&gb, 5); /* spare bits */
2720 } 2720 }
2721 2721
2722 // align_get_bits(&gb); 2722 // align_get_bits(&gb);
2723 2723
2724 avctx->width = s->width; 2724 avctx->width = s->width;
2725 avctx->height = s->height; 2725 avctx->height = s->height;
2726 2726
2727 return 0; 2727 return 0;
2728 } 2728 }
2731 { 2731 {
2732 int ret = get_bits(&gb, 8); 2732 int ret = get_bits(&gb, 8);
2733 ret += get_bits(&gb, 8) << 8; 2733 ret += get_bits(&gb, 8) << 8;
2734 ret += get_bits(&gb, 8) << 16; 2734 ret += get_bits(&gb, 8) << 16;
2735 ret += get_bits(&gb, 8) << 24; 2735 ret += get_bits(&gb, 8) << 24;
2736 2736
2737 return ret; 2737 return ret;
2738 } 2738 }
2739 2739
2740 static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb) 2740 static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb)
2741 { 2741 {
2771 if (len <= 0) 2771 if (len <= 0)
2772 break; 2772 break;
2773 while (len--) 2773 while (len--)
2774 skip_bits(&gb, 8); 2774 skip_bits(&gb, 8);
2775 } while (1); 2775 } while (1);
2776 } 2776 }
2777 return 0; 2777 return 0;
2778 } 2778 }
2779 2779
2780 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb) 2780 static int theora_decode_tables(AVCodecContext *avctx, GetBitContext gb)
2781 { 2781 {
2786 n = get_bits(&gb, 3); 2786 n = get_bits(&gb, 3);
2787 /* loop filter limit values table */ 2787 /* loop filter limit values table */
2788 for (i = 0; i < 64; i++) 2788 for (i = 0; i < 64; i++)
2789 s->filter_limit_values[i] = get_bits(&gb, n); 2789 s->filter_limit_values[i] = get_bits(&gb, n);
2790 } 2790 }
2791 2791
2792 if (s->theora >= 0x030200) 2792 if (s->theora >= 0x030200)
2793 n = get_bits(&gb, 4) + 1; 2793 n = get_bits(&gb, 4) + 1;
2794 else 2794 else
2795 n = 16; 2795 n = 16;
2796 /* quality threshold table */ 2796 /* quality threshold table */
2866 read_huffman_tree(avctx, &gb); 2866 read_huffman_tree(avctx, &gb);
2867 s->hbits = 1; 2867 s->hbits = 1;
2868 read_huffman_tree(avctx, &gb); 2868 read_huffman_tree(avctx, &gb);
2869 } 2869 }
2870 } 2870 }
2871 2871
2872 s->theora_tables = 1; 2872 s->theora_tables = 1;
2873 2873
2874 return 0; 2874 return 0;
2875 } 2875 }
2876 2876
2877 static int theora_decode_init(AVCodecContext *avctx) 2877 static int theora_decode_init(AVCodecContext *avctx)
2878 { 2878 {
2879 Vp3DecodeContext *s = avctx->priv_data; 2879 Vp3DecodeContext *s = avctx->priv_data;
2880 GetBitContext gb; 2880 GetBitContext gb;
2881 int ptype; 2881 int ptype;
2882 uint8_t *p= avctx->extradata; 2882 uint8_t *p= avctx->extradata;
2883 int op_bytes, i; 2883 int op_bytes, i;
2884 2884
2885 s->theora = 1; 2885 s->theora = 1;
2886 2886
2887 if (!avctx->extradata_size) 2887 if (!avctx->extradata_size)
2888 { 2888 {
2889 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n"); 2889 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n");
2897 init_get_bits(&gb, p, op_bytes); 2897 init_get_bits(&gb, p, op_bytes);
2898 p += op_bytes; 2898 p += op_bytes;
2899 2899
2900 ptype = get_bits(&gb, 8); 2900 ptype = get_bits(&gb, 8);
2901 debug_vp3("Theora headerpacket type: %x\n", ptype); 2901 debug_vp3("Theora headerpacket type: %x\n", ptype);
2902 2902
2903 if (!(ptype & 0x80)) 2903 if (!(ptype & 0x80))
2904 { 2904 {
2905 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n"); 2905 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
2906 return -1; 2906 return -1;
2907 } 2907 }
2908 2908
2909 // FIXME: check for this aswell 2909 // FIXME: check for this aswell
2910 skip_bits(&gb, 6*8); /* "theora" */ 2910 skip_bits(&gb, 6*8); /* "theora" */
2911 2911
2912 switch(ptype) 2912 switch(ptype)
2913 { 2913 {
2914 case 0x80: 2914 case 0x80:
2915 theora_decode_header(avctx, gb); 2915 theora_decode_header(avctx, gb);
2916 break; 2916 break;