1 /*
2 * Copyright (c) 2003-2004 The FFmpeg Project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * On2 VP3 Video Decoder
24 *
25 * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
26 * For more information about the VP3 coding process, visit:
27 * http://wiki.multimedia.cx/index.php?title=On2_VP3
28 *
29 * Theora decoder by Alex Beregszaszi
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
37
48
49 #define FRAGMENT_PIXELS 8
50
51 // FIXME split things out into their own arrays
57
58 #define SB_NOT_CODED 0
59 #define SB_PARTIALLY_CODED 1
60 #define SB_FULLY_CODED 2
61
62 // This is the maximum length of a single long bit run that can be encoded
63 // for superblock coding or block qps. Theora special-cases this to read a
64 // bit instead of flipping the current bit to allow for runs longer than 4129.
65 #define MAXIMUM_LONG_BIT_RUN 4129
66
67 #define MODE_INTER_NO_MV 0
69 #define MODE_INTER_PLUS_MV 2
70 #define MODE_INTER_LAST_MV 3
71 #define MODE_INTER_PRIOR_LAST 4
72 #define MODE_USING_GOLDEN 5
73 #define MODE_GOLDEN_MV 6
74 #define MODE_INTER_FOURMV 7
75 #define CODING_MODE_COUNT 8
76
77 /* special internal mode */
79
82
83
84 /* There are 6 preset schemes, plus a free-form scheme */
86 /* scheme 1: Last motion vector dominates */
91
92 /* scheme 2 */
97
98 /* scheme 3 */
103
104 /* scheme 4 */
109
110 /* scheme 5: No motion vector dominates */
115
116 /* scheme 6 */
121 };
122
124 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
125 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
126 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
127 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
128 };
129
130 #define MIN_DEQUANT_VAL 2
131
151
155
166
170
174
181
183
184 /* tables */
191
192 /**
193 * This is a list of all tokens in bitstream order. Reordering takes place
194 * by pulling from each level during IDCT. As a consequence, IDCT must be
195 * in Hilbert order, making the minimum slice height 64 for 4:2:0 and 32
196 * otherwise. The 32 different tokens with up to 12 bits of extradata are
197 * collapsed into 3 types, packed as follows:
198 * (from the low to high bits)
199 *
200 * 2 bits: type (0,1,2)
201 * 0: EOB run, 14 bits for run length (12 needed)
202 * 1: zero run, 7 bits for run length
203 * 7 bits for the next coefficient (3 needed)
204 * 2: coefficient, 14 bits (11 needed)
205 *
206 * Coefficients are signed, so are packed in the highest bits for automatic
207 * sign extension.
208 */
211 #define TOKEN_EOB(eob_run) ((eob_run) << 2)
212 #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) << 9) + ((zero_run) << 2) + 1)
213 #define TOKEN_COEFF(coeff) (((coeff) << 2) + 2)
214
215 /**
216 * number of blocks that contain DCT coefficients at
217 * the given level or higher
218 */
221
222 /* this is a list of indexes into the all_fragments array indicating
223 * which of the fragments are coded */
225
231
236
237 /* these arrays need to be on 16-byte boundaries since SSE2 operations
238 * index into them */
240
241 /* This table contains superblock_count * 16 entries. Each set of 16
242 * numbers corresponds to the fragment indexes 0..15 of the superblock.
243 * An entry will be -1 to indicate that no entry corresponds to that
244 * index. */
246
247 /* This is an array that indicates how a particular macroblock
248 * is coded. */
250
252
253 /* Huffman decode */
259
263
264 /************************************************************************
265 * VP3 specific functions
266 ************************************************************************/
267
269 {
271
280 }
281
283 {
285
292 }
293
295 {
297 int i;
298
301
303
304 /* release all frames */
309
311 return 0;
312
313 for (i = 0; i < 16; i++) {
319 }
320
325
326 return 0;
327 }
328
329 /**
330 * This function sets up all of the various blocks mappings:
331 * superblocks <-> fragments, macroblocks <-> fragments,
332 * superblocks <-> macroblocks
333 *
334 * @return 0 is successful; returns 1 if *anything* went wrong.
335 */
337 {
338 int sb_x, sb_y, plane;
340
341 for (plane = 0; plane < 3; plane++) {
348
349 for (sb_y = 0; sb_y < sb_height; sb_y++)
350 for (sb_x = 0; sb_x < sb_width; sb_x++)
351 for (i = 0; i < 16; i++) {
353 y = 4 * sb_y + hilbert_offset[i][1];
354
355 if (x < frag_width && y < frag_height)
357 y * frag_width + x;
358 else
360 }
361 }
362
363 return 0; /* successful path out */
364 }
365
366 /*
367 * This function sets up the dequantization tables used for a particular
368 * frame.
369 */
371 {
374 int i, plane, inter, qri, bmi, bmj, qistart;
375
376 for (inter = 0; inter < 2; inter++) {
377 for (plane = 0; plane < 3; plane++) {
378 int sum = 0;
379 for (qri = 0; qri < s->
qr_count[inter][plane]; qri++) {
380 sum += s->
qr_size[inter][plane][qri];
381 if (s->
qps[qpi] <= sum)
382 break;
383 }
384 qistart = sum - s->
qr_size[inter][plane][qri];
385 bmi = s->
qr_base[inter][plane][qri];
386 bmj = s->
qr_base[inter][plane][qri + 1];
387 for (i = 0; i < 64; i++) {
390 s->
qr_size[inter][plane][qri]) /
391 (2 * s->
qr_size[inter][plane][qri]);
392
393 int qmin = 8 << (inter + !i);
394 int qscale = i ? ac_scale_factor : dc_scale_factor;
395
397 av_clip((qscale * coeff) / 100 * 4, qmin, 4096);
398 }
399 /* all DC coefficients use the same quant so as not to interfere
400 * with DC prediction */
401 s->
qmat[qpi][inter][plane][0] = s->
qmat[0][inter][plane][0];
402 }
403 }
404 }
405
406 /*
407 * This function initializes the loop filter boundary limits if the frame's
408 * quality index is different from the previous frame's.
409 *
410 * The filter_limit_values may not be larger than 127.
411 */
413 {
415 int filter_limit;
416 int x;
418
421
422 /* set up the bounding values */
424 for (x = 0; x < filter_limit; x++) {
425 bounding_values[-x] = -x;
426 bounding_values[x] = x;
427 }
428 for (x = value = filter_limit; x < 128 &&
value; x++, value--) {
429 bounding_values[ x] =
value;
430 bounding_values[-x] = -
value;
431 }
432 if (value)
433 bounding_values[128] =
value;
434 bounding_values[129] = bounding_values[130] = filter_limit * 0x02020202;
435 }
436
437 /*
438 * This function unpacks all of the superblock/macroblock/fragment coding
439 * information from the bitstream.
440 */
442 {
443 int superblock_starts[3] = {
445 };
446 int bit = 0;
447 int current_superblock = 0;
448 int current_run = 0;
449 int num_partial_superblocks = 0;
450
451 int i, j;
452 int current_fragment;
453 int plane;
454
457 } else {
458 /* unpack the list of partially-coded superblocks */
460 current_run = 0;
461
462 while (current_superblock < s->superblock_count &&
get_bits_left(gb) > 0) {
465 else
466 bit ^= 1;
467
469 6, 2) + 1;
470 if (current_run == 34)
472
475 "Invalid partially coded superblock run length\n");
476 return -1;
477 }
478
480
481 current_superblock += current_run;
482 if (bit)
483 num_partial_superblocks += current_run;
484 }
485
486 /* unpack the list of fully coded superblocks if any of the blocks were
487 * not marked as partially coded in the previous step */
488 if (num_partial_superblocks < s->superblock_count) {
489 int superblocks_decoded = 0;
490
491 current_superblock = 0;
493 current_run = 0;
494
495 while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
499 else
500 bit ^= 1;
501
503 6, 2) + 1;
504 if (current_run == 34)
506
507 for (j = 0; j < current_run; current_superblock++) {
510 "Invalid fully coded superblock run length\n");
511 return -1;
512 }
513
514 /* skip any superblocks already marked as partially coded */
517 j++;
518 }
519 }
520 superblocks_decoded += current_run;
521 }
522 }
523
524 /* if there were partial blocks, initialize bitstream for
525 * unpacking fragment codings */
526 if (num_partial_superblocks) {
527 current_run = 0;
529 /* toggle the bit because as soon as the first run length is
530 * fetched the bit will be toggled again */
531 bit ^= 1;
532 }
533 }
534
535 /* figure out which fragments are coded; iterate through each
536 * superblock (all planes) */
539
540 for (plane = 0; plane < 3; plane++) {
541 int sb_start = superblock_starts[plane];
544 int num_coded_frags = 0;
545
546 for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
547 /* iterate through all 16 fragments in a superblock */
548 for (j = 0; j < 16; j++) {
549 /* if the fragment is in bounds, check its coding status */
551 if (current_fragment != -1) {
553
555 /* fragment may or may not be coded; this is the case
556 * that cares about the fragment coding runs */
557 if (current_run-- == 0) {
558 bit ^= 1;
560 }
561 coded = bit;
562 }
563
564 if (coded) {
565 /* default mode; actual mode will be decoded in
566 * the next phase */
570 current_fragment;
571 } else {
572 /* not coded; copy this fragment from the prior frame */
575 }
576 }
577 }
578 }
580 for (i = 0; i < 64; i++)
584 num_coded_frags;
585 }
586 return 0;
587 }
588
589 /*
590 * This function unpacks all the coding mode data for individual macroblocks
591 * from the bitstream.
592 */
594 {
595 int i, j, k, sb_x, sb_y;
596 int scheme;
597 int current_macroblock;
598 int current_fragment;
599 int coding_mode;
601 const int *alphabet;
603
607 } else {
608 /* fetch the mode coding scheme for this frame */
610
611 /* is it a custom coding scheme? */
612 if (scheme == 0) {
613 for (i = 0; i < 8; i++)
615 for (i = 0; i < 8; i++)
616 custom_mode_alphabet[
get_bits(gb, 3)] = i;
617 alphabet = custom_mode_alphabet;
618 } else
620
621 /* iterate through all of the macroblocks that contain 1 or more
622 * coded fragments */
626 return -1;
627
628 for (j = 0; j < 4; j++) {
629 int mb_x = 2 * sb_x + (j >> 1);
630 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
632
635 continue;
636
637 #define BLOCK_X (2 * mb_x + (k & 1))
638 #define BLOCK_Y (2 * mb_y + (k >> 1))
639 /* coding modes are only stored if the macroblock has
640 * at least one luma block coded, otherwise it must be
641 * INTER_NO_MV */
642 for (k = 0; k < 4; k++) {
646 break;
647 }
648 if (k == 4) {
650 continue;
651 }
652
653 /* mode 7 means get 3 bits for each coding mode */
654 if (scheme == 7)
656 else
658
660 for (k = 0; k < 4; k++) {
664 }
665
666 #define SET_CHROMA_MODES \
667 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
668 frag[s->fragment_start[1]].coding_method = coding_mode; \
669 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
670 frag[s->fragment_start[2]].coding_method = coding_mode;
671
679 for (k = 0; k < 2; k++) {
682 }
683 } else {
684 for (k = 0; k < 4; k++) {
688 }
689 }
690 }
691 }
692 }
693 }
694
695 return 0;
696 }
697
698 /*
699 * This function unpacks all the motion vectors for the individual
700 * macroblocks from the bitstream.
701 */
703 {
704 int j, k, sb_x, sb_y;
705 int coding_mode;
706 int motion_x[4];
707 int motion_y[4];
708 int last_motion_x = 0;
709 int last_motion_y = 0;
710 int prior_last_motion_x = 0;
711 int prior_last_motion_y = 0;
712 int current_macroblock;
713 int current_fragment;
714 int frag;
715
717 return 0;
718
719 /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */
721
722 /* iterate through all of the macroblocks that contain 1 or more
723 * coded fragments */
727 return -1;
728
729 for (j = 0; j < 4; j++) {
730 int mb_x = 2 * sb_x + (j >> 1);
731 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
733
737 continue;
738
742 /* all 6 fragments use the same motion vector */
743 if (coding_mode == 0) {
746 } else {
749 }
750
751 /* vector maintenance, only on MODE_INTER_PLUS_MV */
753 prior_last_motion_x = last_motion_x;
754 prior_last_motion_y = last_motion_y;
755 last_motion_x = motion_x[0];
756 last_motion_y = motion_y[0];
757 }
758 break;
759
761 /* vector maintenance */
762 prior_last_motion_x = last_motion_x;
763 prior_last_motion_y = last_motion_y;
764
765 /* fetch 4 vectors from the bitstream, one for each
766 * Y fragment, then average for the C fragment vectors */
767 for (k = 0; k < 4; k++) {
770 if (coding_mode == 0) {
773 } else {
776 }
777 last_motion_x = motion_x[k];
778 last_motion_y = motion_y[k];
779 } else {
780 motion_x[k] = 0;
781 motion_y[k] = 0;
782 }
783 }
784 break;
785
787 /* all 6 fragments use the last motion vector */
788 motion_x[0] = last_motion_x;
789 motion_y[0] = last_motion_y;
790
791 /* no vector maintenance (last vector remains the
792 * last vector) */
793 break;
794
796 /* all 6 fragments use the motion vector prior to the
797 * last motion vector */
798 motion_x[0] = prior_last_motion_x;
799 motion_y[0] = prior_last_motion_y;
800
801 /* vector maintenance */
802 prior_last_motion_x = last_motion_x;
803 prior_last_motion_y = last_motion_y;
804 last_motion_x = motion_x[0];
805 last_motion_y = motion_y[0];
806 break;
807
808 default:
809 /* covers intra, inter without MV, golden without MV */
810 motion_x[0] = 0;
811 motion_y[0] = 0;
812
813 /* no vector maintenance */
814 break;
815 }
816
817 /* assign the motion vectors to the correct fragments */
818 for (k = 0; k < 4; k++) {
819 current_fragment =
822 s->
motion_val[0][current_fragment][0] = motion_x[k];
823 s->
motion_val[0][current_fragment][1] = motion_y[k];
824 } else {
825 s->
motion_val[0][current_fragment][0] = motion_x[0];
826 s->
motion_val[0][current_fragment][1] = motion_y[0];
827 }
828 }
829
832 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] +
833 motion_x[2] + motion_x[3], 2);
834 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] +
835 motion_y[2] + motion_y[3], 2);
836 }
837 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
838 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
844 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
845 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
846 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
847 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
848 } else {
849 motion_x[1] = motion_x[0];
850 motion_y[1] = motion_y[0];
851 }
852 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
853 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
854
856 for (k = 0; k < 2; k++) {
860 }
861 } else {
862 for (k = 0; k < 4; k++) {
867 } else {
870 }
871 }
872 }
873 }
874 }
875 }
876
877 return 0;
878 }
879
881 {
882 int qpi, i, j, bit, run_length, blocks_decoded, num_blocks_at_qpi;
884
885 for (qpi = 0; qpi < s->
nqps - 1 && num_blocks > 0; qpi++) {
886 i = blocks_decoded = num_blocks_at_qpi = 0;
887
889 run_length = 0;
890
891 do {
894 else
895 bit ^= 1;
896
898 if (run_length == 34)
900 blocks_decoded += run_length;
901
902 if (!bit)
903 num_blocks_at_qpi += run_length;
904
905 for (j = 0; j < run_length; i++) {
907 return -1;
908
911 j++;
912 }
913 }
914 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
915
916 num_blocks -= num_blocks_at_qpi;
917 }
918
919 return 0;
920 }
921
922 /*
923 * This function is called by unpack_dct_coeffs() to extract the VLCs from
924 * the bitstream. The VLCs encode tokens which are used to unpack DCT
925 * data. This function unpacks all the VLCs for either the Y plane or both
926 * C planes, and is called for DC coefficients or different AC coefficient
927 * levels (since different coefficient types require different VLC tables.
928 *
929 * This function returns a residual eob run. E.g, if a particular token gave
930 * instructions to EOB the next 5 fragments and there were only 2 fragments
931 * left in the current fragment range, 3 would be returned so that it could
932 * be passed into the next call to this same function.
933 */
936 int plane,
937 int eob_run)
938 {
939 int i, j = 0;
940 int token;
941 int zero_run = 0;
943 int bits_to_get;
944 int blocks_ended;
945 int coeff_i = 0;
947 int16_t *dct_tokens = s->
dct_tokens[plane][coeff_index];
948
949 /* local references to structure members to avoid repeated deferences */
953
954 if (num_coeffs < 0)
956 "Invalid number of coefficents at level %d\n", coeff_index);
957
958 if (eob_run > num_coeffs) {
959 coeff_i =
960 blocks_ended = num_coeffs;
961 eob_run -= num_coeffs;
962 } else {
963 coeff_i =
964 blocks_ended = eob_run;
965 eob_run = 0;
966 }
967
968 // insert fake EOB token to cover the split between planes or zzi
969 if (blocks_ended)
970 dct_tokens[j++] = blocks_ended << 2;
971
973 /* decode a VLC into a token */
974 token =
get_vlc2(gb, vlc_table, 11, 3);
975 /* use the token to get a zero run, a coefficient, and an eob run */
976 if ((
unsigned) token <= 6
U) {
980
981 // record only the number of blocks ended in this plane,
982 // any spill will be recorded in the next plane.
983 if (eob_run > num_coeffs - coeff_i) {
984 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
985 blocks_ended += num_coeffs - coeff_i;
986 eob_run -= num_coeffs - coeff_i;
987 coeff_i = num_coeffs;
988 } else {
990 blocks_ended += eob_run;
991 coeff_i += eob_run;
992 eob_run = 0;
993 }
994 } else if (token >= 0) {
996 if (bits_to_get)
997 bits_to_get =
get_bits(gb, bits_to_get);
999
1003
1004 if (zero_run) {
1006 } else {
1007 // Save DC into the fragment structure. DC prediction is
1008 // done in raster order, so the actual DC can't be in with
1009 // other tokens. We still need the token in dct_tokens[]
1010 // however, or else the structure collapses on itself.
1011 if (!coeff_index)
1012 all_fragments[coded_fragment_list[coeff_i]].
dc =
coeff;
1013
1015 }
1016
1017 if (coeff_index + zero_run > 64) {
1019 "Invalid zero run of %d with %d coeffs left\n",
1020 zero_run, 64 - coeff_index);
1021 zero_run = 64 - coeff_index;
1022 }
1023
1024 // zero runs code multiple coefficients,
1025 // so don't try to decode coeffs for those higher levels
1026 for (i = coeff_index + 1; i <= coeff_index + zero_run; i++)
1028 coeff_i++;
1029 } else {
1031 return -1;
1032 }
1033 }
1034
1037
1038 // decrement the number of blocks that have higher coefficients for each
1039 // EOB run at this level
1040 if (blocks_ended)
1041 for (i = coeff_index + 1; i < 64; i++)
1043
1044 // setup the next buffer
1046 s->
dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1047 else if (coeff_index < 63)
1048 s->
dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1049
1050 return eob_run;
1051 }
1052
1054 int first_fragment,
1055 int fragment_width,
1056 int fragment_height);
1057 /*
1058 * This function unpacks all of the DCT coefficient data from the
1059 * bitstream.
1060 */
1062 {
1063 int i;
1064 int dc_y_table;
1065 int dc_c_table;
1066 int ac_y_table;
1067 int ac_c_table;
1068 int residual_eob_run = 0;
1071
1073
1074 /* fetch the DC table indexes */
1077
1078 /* unpack the Y plane DC coefficients */
1080 0, residual_eob_run);
1081 if (residual_eob_run < 0)
1082 return residual_eob_run;
1083
1084 /* reverse prediction of the Y-plane DC coefficients */
1086
1087 /* unpack the C plane DC coefficients */
1089 1, residual_eob_run);
1090 if (residual_eob_run < 0)
1091 return residual_eob_run;
1093 2, residual_eob_run);
1094 if (residual_eob_run < 0)
1095 return residual_eob_run;
1096
1097 /* reverse prediction of the C-plane DC coefficients */
1103 }
1104
1105 /* fetch the AC table indexes */
1108
1109 /* build tables of AC VLC tables */
1110 for (i = 1; i <= 5; i++) {
1111 y_tables[i] = &s->
ac_vlc_1[ac_y_table];
1112 c_tables[i] = &s->
ac_vlc_1[ac_c_table];
1113 }
1114 for (i = 6; i <= 14; i++) {
1115 y_tables[i] = &s->
ac_vlc_2[ac_y_table];
1116 c_tables[i] = &s->
ac_vlc_2[ac_c_table];
1117 }
1118 for (i = 15; i <= 27; i++) {
1119 y_tables[i] = &s->
ac_vlc_3[ac_y_table];
1120 c_tables[i] = &s->
ac_vlc_3[ac_c_table];
1121 }
1122 for (i = 28; i <= 63; i++) {
1123 y_tables[i] = &s->
ac_vlc_4[ac_y_table];
1124 c_tables[i] = &s->
ac_vlc_4[ac_c_table];
1125 }
1126
1127 /* decode all AC coefficents */
1128 for (i = 1; i <= 63; i++) {
1129 residual_eob_run =
unpack_vlcs(s, gb, y_tables[i], i,
1130 0, residual_eob_run);
1131 if (residual_eob_run < 0)
1132 return residual_eob_run;
1133
1134 residual_eob_run =
unpack_vlcs(s, gb, c_tables[i], i,
1135 1, residual_eob_run);
1136 if (residual_eob_run < 0)
1137 return residual_eob_run;
1138 residual_eob_run =
unpack_vlcs(s, gb, c_tables[i], i,
1139 2, residual_eob_run);
1140 if (residual_eob_run < 0)
1141 return residual_eob_run;
1142 }
1143
1144 return 0;
1145 }
1146
1147 /*
1148 * This function reverses the DC prediction for each coded fragment in
1149 * the frame. Much of this function is adapted directly from the original
1150 * VP3 source code.
1151 */
1152 #define COMPATIBLE_FRAME(x) \
1153 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1154 #define DC_COEFF(u) s->all_fragments[u].dc
1155
1157 int first_fragment,
1158 int fragment_width,
1159 int fragment_height)
1160 {
1161 #define PUL 8
1162 #define PU 4
1163 #define PUR 2
1164 #define PL 1
1165
1167 int i = first_fragment;
1168
1169 int predicted_dc;
1170
1171 /* DC values for the left, up-left, up, and up-right fragments */
1172 int vl, vul, vu, vur;
1173
1174 /* indexes for the left, up-left, up, and up-right fragments */
1176
1177 /*
1178 * The 6 fields mean:
1179 * 0: up-left multiplier
1180 * 1: up multiplier
1181 * 2: up-right multiplier
1182 * 3: left multiplier
1183 */
1184 static const int predictor_transform[16][4] = {
1185 { 0, 0, 0, 0 },
1186 { 0, 0, 0, 128 }, // PL
1187 { 0, 0, 128, 0 }, // PUR
1188 { 0, 0, 53, 75 }, // PUR|PL
1189 { 0, 128, 0, 0 }, // PU
1190 { 0, 64, 0, 64 }, // PU |PL
1191 { 0, 128, 0, 0 }, // PU |PUR
1192 { 0, 0, 53, 75 }, // PU |PUR|PL
1193 { 128, 0, 0, 0 }, // PUL
1194 { 0, 0, 0, 128 }, // PUL|PL
1195 { 64, 0, 64, 0 }, // PUL|PUR
1196 { 0, 0, 53, 75 }, // PUL|PUR|PL
1197 { 0, 128, 0, 0 }, // PUL|PU
1198 { -104, 116, 0, 116 }, // PUL|PU |PL
1199 { 24, 80, 24, 0 }, // PUL|PU |PUR
1200 { -104, 116, 0, 116 } // PUL|PU |PUR|PL
1201 };
1202
1203 /* This table shows which types of blocks can use other blocks for
1204 * prediction. For example, INTRA is the only mode in this table to
1205 * have a frame number of 0. That means INTRA blocks can only predict
1206 * from other INTRA blocks. There are 2 golden frame coding types;
1207 * blocks encoding in these modes can only predict from other blocks
1208 * that were encoded with these 1 of these 2 modes. */
1209 static const unsigned char compatible_frame[9] = {
1210 1, /* MODE_INTER_NO_MV */
1211 0, /* MODE_INTRA */
1212 1, /* MODE_INTER_PLUS_MV */
1213 1, /* MODE_INTER_LAST_MV */
1214 1, /* MODE_INTER_PRIOR_MV */
1215 2, /* MODE_USING_GOLDEN */
1216 2, /* MODE_GOLDEN_MV */
1217 1, /* MODE_INTER_FOUR_MV */
1218 3 /* MODE_COPY */
1219 };
1220 int current_frame_type;
1221
1222 /* there is a last DC predictor for each of the 3 frame types */
1223 short last_dc[3];
1224
1226
1227 vul =
1228 vu =
1229 vur =
1230 vl = 0;
1231 last_dc[0] =
1232 last_dc[1] =
1233 last_dc[2] = 0;
1234
1235 /* for each fragment row... */
1236 for (y = 0; y < fragment_height; y++) {
1237 /* for each fragment in a row... */
1238 for (x = 0; x < fragment_width; x++, i++) {
1239
1240 /* reverse prediction if this block was coded */
1242 current_frame_type =
1244
1245 transform = 0;
1246 if (x) {
1247 l = i - 1;
1251 }
1252 if (y) {
1253 u = i - fragment_width;
1257 if (x) {
1258 ul = i - fragment_width - 1;
1262 }
1263 if (x + 1 < fragment_width) {
1264 ur = i - fragment_width + 1;
1268 }
1269 }
1270
1271 if (transform == 0) {
1272 /* if there were no fragments to predict from, use last
1273 * DC saved */
1274 predicted_dc = last_dc[current_frame_type];
1275 } else {
1276 /* apply the appropriate predictor transform */
1277 predicted_dc =
1278 (predictor_transform[
transform][0] * vul) +
1279 (predictor_transform[transform][1] * vu) +
1280 (predictor_transform[
transform][2] * vur) +
1281 (predictor_transform[transform][3] * vl);
1282
1283 predicted_dc /= 128;
1284
1285 /* check for outranging on the [ul u l] and
1286 * [ul u ur l] predictors */
1287 if ((transform == 15) || (transform == 13)) {
1288 if (
FFABS(predicted_dc - vu) > 128)
1289 predicted_dc = vu;
1290 else if (
FFABS(predicted_dc - vl) > 128)
1291 predicted_dc = vl;
1292 else if (
FFABS(predicted_dc - vul) > 128)
1293 predicted_dc = vul;
1294 }
1295 }
1296
1297 /* at long last, apply the predictor */
1299 /* save the DC */
1300 last_dc[current_frame_type] =
DC_COEFF(i);
1301 }
1302 }
1303 }
1304 }
1305
1307 int ystart, int yend)
1308 {
1311
1318 stride = -stride;
1319 plane_data += s->
data_offset[plane] + 8 * ystart * stride;
1320
1321 for (y = ystart; y < yend; y++) {
1322 for (x = 0; x <
width; x++) {
1323 /* This code basically just deblocks on the edges of coded blocks.
1324 * However, it has to be much more complicated because of the
1325 * braindamaged deblock ordering used in VP3/Theora. Order matters
1326 * because some pixels get filtered twice. */
1328 /* do not perform left edge filter for left columns frags */
1329 if (x > 0) {
1331 plane_data + 8 * x,
1332 stride, bounding_values);
1333 }
1334
1335 /* do not perform top edge filter for top row fragments */
1336 if (y > 0) {
1338 plane_data + 8 * x,
1339 stride, bounding_values);
1340 }
1341
1342 /* do not perform right edge filter for right column
1343 * fragments or if right fragment neighbor is also coded
1344 * in this frame (it will be filtered in next iteration) */
1345 if ((x < width - 1) &&
1348 plane_data + 8 * x + 8,
1349 stride, bounding_values);
1350 }
1351
1352 /* do not perform bottom edge filter for bottom row
1353 * fragments or if bottom fragment neighbor is also coded
1354 * in this frame (it will be filtered in the next row) */
1355 if ((y < height - 1) &&
1358 plane_data + 8 * x + 8 * stride,
1359 stride, bounding_values);
1360 }
1361 }
1362
1363 fragment++;
1364 }
1365 plane_data += 8 * stride;
1366 }
1367 }
1368
1369 /**
1370 * Pull DCT tokens from the 64 levels to decode and dequant the coefficients
1371 * for the next block in coding order
1372 */
1374 int plane,
int inter, int16_t
block[64])
1375 {
1376 int16_t *dequantizer = s->
qmat[frag->
qpi][inter][plane];
1378 int i = 0;
1379
1380 do {
1382 switch (token & 3) {
1383 case 0: // EOB
1384 if (--token < 4) // 0-3 are token types so the EOB run must now be 0
1386 else
1389 case 1: // zero run
1391 i += (token >> 2) & 0x7f;
1392 if (i > 63) {
1394 return i;
1395 }
1396 block[perm[i]] = (token >> 9) * dequantizer[perm[i]];
1397 i++;
1398 break;
1399 case 2: // coeff
1400 block[perm[i]] = (token >> 2) * dequantizer[perm[i]];
1402 break;
1403 default: // shouldn't happen
1404 return i;
1405 }
1406 } while (i < 64);
1407 // return value is expected to be a valid level
1408 i--;
1410 // the actual DC+prediction is in the fragment structure
1411 block[0] = frag->
dc * s->
qmat[0][inter][plane][0];
1412 return i;
1413 }
1414
1415 /**
1416 * called when all pixels up to row y are complete
1417 */
1419 {
1420 int h, cy, i;
1422
1425
1426 /* At the end of the frame, report INT_MAX instead of the height of
1427 * the frame. This makes the other threads' ff_thread_await_progress()
1428 * calls cheaper, because they don't have to clip their values. */
1430 y_flipped == s->
height ? INT_MAX
1431 : y_flipped - 1,
1432 0);
1433 }
1434
1436 return;
1437
1440 y -= h;
1441
1444
1450 offset[i] = 0;
1451
1452 emms_c();
1454 }
1455
1456 /**
1457 * Wait for the reference frame of the current fragment.
1458 * The progress value is in luma pixel rows.
1459 */
1461 int motion_y,
int y)
1462 {
1464 int ref_row;
1465 int border = motion_y & 1;
1466
1470 else
1472
1473 ref_row = y + (motion_y >> 1);
1474 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1475
1477 }
1478
1479 /*
1480 * Perform the final rendering for a particular slice of data.
1481 * The slice number ranges from 0..(c_superblock_height - 1).
1482 */
1484 {
1485 int x,
y, i, j, fragment;
1487 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
1488 int motion_halfpel_index;
1490 int plane, first_pixel;
1491
1493 return;
1494
1495 for (plane = 0; plane < 3; plane++) {
1505 int8_t(*motion_val)[2] = s->
motion_val[!!plane];
1506
1511
1515
1516 int do_await = !plane && HAVE_THREADS &&
1518
1520 stride = -stride;
1522 continue;
1523
1524 /* for each superblock row in the slice (both of them)... */
1525 for (; sb_y < slice_height; sb_y++) {
1526 /* for each superblock in a row... */
1527 for (sb_x = 0; sb_x < slice_width; sb_x++) {
1528 /* for each block in a superblock... */
1529 for (j = 0; j < 16; j++) {
1531 y = 4 * sb_y + hilbert_offset[j][1];
1532 fragment = y * fragment_width + x;
1533
1534 i = fragment_start + fragment;
1535
1536 // bounds check
1537 if (x >= fragment_width || y >= fragment_height)
1538 continue;
1539
1540 first_pixel = 8 * y * stride + 8 * x;
1541
1542 if (do_await &&
1545 motion_val[fragment][1],
1547
1548 /* transform if this block was coded */
1552 motion_source = golden_plane;
1553 else
1554 motion_source = last_plane;
1555
1556 motion_source += first_pixel;
1557 motion_halfpel_index = 0;
1558
1559 /* sort out the motion vector if this fragment is coded
1560 * using a motion vector method */
1563 int src_x, src_y;
1564 motion_x = motion_val[fragment][0];
1565 motion_y = motion_val[fragment][1];
1566
1567 src_x = (motion_x >> 1) + 8 * x;
1568 src_y = (motion_y >> 1) + 8 * y;
1569
1570 motion_halfpel_index = motion_x & 0x01;
1571 motion_source += (motion_x >> 1);
1572
1573 motion_halfpel_index |= (motion_y & 0x01) << 1;
1574 motion_source += ((motion_y >> 1) * stride);
1575
1576 if (src_x < 0 || src_y < 0 ||
1577 src_x + 9 >= plane_width ||
1578 src_y + 9 >= plane_height) {
1580 if (stride < 0)
1581 temp -= 8 * stride;
1582
1584 stride, stride,
1585 9, 9, src_x, src_y,
1586 plane_width,
1587 plane_height);
1588 motion_source =
temp;
1589 }
1590 }
1591
1592 /* first, take care of copying a block from either the
1593 * previous or the golden frame */
1595 /* Note, it is possible to implement all MC cases
1596 * with put_no_rnd_pixels_l2 which would look more
1597 * like the VP3 source but this would be slower as
1598 * put_no_rnd_pixels_tab is better optimzed */
1599 if (motion_halfpel_index != 3) {
1601 output_plane + first_pixel,
1602 motion_source, stride, 8);
1603 } else {
1604 /* d is 0 if motion_x and _y have the same sign,
1605 * else -1 */
1606 int d = (motion_x ^ motion_y) >> 31;
1608 motion_source - d,
1609 motion_source + stride + 1 + d,
1610 stride, 8);
1611 }
1612 }
1613
1614 /* invert DCT and place (or add) in final output */
1615
1618 plane, 0, block);
1620 stride,
1621 block);
1622 } else {
1624 plane, 1, block)) {
1626 stride,
1627 block);
1628 } else {
1630 stride, block);
1631 }
1632 }
1633 } else {
1634 /* copy directly from the previous frame */
1636 output_plane + first_pixel,
1637 last_plane + first_pixel,
1638 stride, 8);
1639 }
1640 }
1641 }
1642
1643 // Filter up to the last row in the superblock row
1646 FFMIN(4 * sb_y + 3, fragment_height - 1));
1647 }
1648 }
1649
1650 /* this looks like a good place for slice dispatch... */
1651 /* algorithm:
1652 * if (slice == s->macroblock_height - 1)
1653 * dispatch (both last slice & 2nd-to-last slice);
1654 * else if (slice > 0)
1655 * dispatch (slice - 1);
1656 */
1657
1660 }
1661
1662 /// Allocate tables for per-frame data in Vp3DecodeContext
1664 {
1666 int y_fragment_count, c_fragment_count;
1667
1669
1672
1675
1677
1682
1683 /* work out the block mapping tables */
1686
1692 return -1;
1693 }
1694
1696
1697 return 0;
1698 }
1699
1701 {
1705
1711 }
1712
1713 return 0;
1714 }
1715
1717 {
1719 int i, inter, plane,
ret;
1720 int c_width;
1721 int c_height;
1722 int y_fragment_count, c_fragment_count;
1723
1725 if (ret < 0)
1727
1729
1732 else
1734
1744
1745 for (i = 0; i < 64; i++) {
1746 #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
1749 #undef TRANSPOSE
1750 }
1751
1752 /* initialize to an impossible value which will force a recalculation
1753 * in the first frame decode */
1754 for (i = 0; i < 3; i++)
1756
1758
1762
1763 /* work out the dimensions for the C planes */
1769
1773
1777
1782
1783 /* fragment count covers all 8x8 blocks for all 3 planes */
1789
1791 for (i = 0; i < 64; i++) {
1798 }
1799
1800 for (inter = 0; inter < 2; inter++) {
1801 for (plane = 0; plane < 3; plane++) {
1803 s->
qr_size[inter][plane][0] = 63;
1805 s->
qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
1806 }
1807 }
1808
1809 /* init VLC tables */
1810 for (i = 0; i < 16; i++) {
1811 /* DC histograms */
1815
1816 /* group 1 AC histograms */
1820
1821 /* group 2 AC histograms */
1825
1826 /* group 3 AC histograms */
1830
1831 /* group 4 AC histograms */
1835 }
1836 } else {
1837 for (i = 0; i < 16; i++) {
1838 /* DC histograms */
1842 goto vlc_fail;
1843
1844 /* group 1 AC histograms */
1848 goto vlc_fail;
1849
1850 /* group 2 AC histograms */
1854 goto vlc_fail;
1855
1856 /* group 3 AC histograms */
1860 goto vlc_fail;
1861
1862 /* group 4 AC histograms */
1866 goto vlc_fail;
1867 }
1868 }
1869
1873
1877
1881
1885
1887
1888 vlc_fail:
1890 return -1;
1891 }
1892
1893 /// Release and shuffle frames after decode finishes
1895 {
1898
1899 /* shuffle frames (last = current) */
1902 if (ret < 0)
1903 goto fail;
1904
1908 }
1909
1910 fail:
1913 }
1914
1916 {
1918 if (src->
f->
data[0])
1920 return 0;
1921 }
1922
1924 {
1930 return 0;
1931 }
1932
1934 {
1936 int qps_changed = 0, i, err;
1937
1938 #define copy_fields(to, from, start_field, end_field) \
1939 memcpy(&to->start_field, &from->start_field, \
1940 (char *) &to->end_field - (char *) &to->start_field)
1941
1942 if (!
s1->current_frame.f->data[0] ||
1946 return -1;
1947 }
1948
1950 // init tables if the first frame hasn't been decoded
1952 int y_fragment_count, c_fragment_count;
1955 if (err)
1956 return err;
1960 y_fragment_count *
sizeof(*s->
motion_val[0]));
1962 c_fragment_count *
sizeof(*s->
motion_val[1]));
1963 }
1964
1965 // copy previous frame data
1967 return err;
1968
1970
1971 // copy qscale data if necessary
1972 for (i = 0; i < 3; i++) {
1973 if (s->
qps[i] !=
s1->qps[1]) {
1974 qps_changed = 1;
1975 memcpy(&s->
qmat[i], &
s1->qmat[i],
sizeof(s->
qmat[i]));
1976 }
1977 }
1978
1979 if (s->
qps[0] !=
s1->qps[0])
1982
1983 if (qps_changed)
1985 #undef copy_fields
1986 }
1987
1989 }
1990
1992 void *
data,
int *got_frame,
1994 {
1996 int buf_size = avpkt->
size;
2000
2003
2004 #if CONFIG_THEORA_DECODER
2008
2010 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2012 }
2013 if (type == 0) {
2016
2017 if (ret < 0) {
2019 } else
2022 } else if (type == 2) {
2024 if (ret < 0) {
2026 } else
2029 }
2030
2032 "Header packet passed to frame decoder, skipping\n");
2033 return -1;
2034 }
2035 #endif
2036
2040 return -1;
2041 }
2044 for (i = 0; i < 3; i++)
2046
2048 do {
2050 }
while (
s->theora >= 0x030200 &&
s->nqps < 3 &&
get_bits1(&gb));
2051 for (i =
s->nqps; i < 3; i++)
2053
2056 s->keyframe ?
"key" :
"", avctx->frame_number + 1,
s->qps[0]);
2057
2058 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2061
2062 if (
s->qps[0] !=
s->last_qps[0])
2064
2065 for (i = 0; i <
s->nqps; i++)
2066 // reinit all dequantizers if the first one changed, because
2067 // the DC of the first quantizer must be used for all matrices
2068 if (
s->qps[i] !=
s->last_qps[i] ||
s->qps[0] !=
s->last_qps[0])
2070
2072 return buf_size;
2073
2076 s->current_frame.f->key_frame =
s->keyframe;
2078 goto error;
2079
2080 if (!
s->edge_emu_buffer)
2081 s->edge_emu_buffer =
av_malloc(9 *
FFABS(
s->current_frame.f->linesize[0]));
2082
2089 if (avctx->frame_number == 0)
2091 "VP version: %d\n",
s->version);
2092 }
2093 }
2094 if (
s->version ||
s->theora) {
2097 "Warning, unsupported keyframe coding type?!\n");
2099 }
2100 } else {
2101 if (!
s->golden_frame.f->data[0]) {
2103 "vp3: first frame not a keyframe\n");
2104
2108 goto error;
2111 &
s->golden_frame)) < 0)
2112 goto error;
2114 }
2115 }
2116
2117 memset(
s->all_fragments, 0,
s->fragment_count *
sizeof(
Vp3Fragment));
2119
2122 goto error;
2123 }
2126 goto error;
2127 }
2130 goto error;
2131 }
2134 goto error;
2135 }
2138 goto error;
2139 }
2140
2141 for (i = 0; i < 3; i++) {
2142 int height =
s->height >> (i &&
s->chroma_y_shift);
2143 if (
s->flipped_image)
2144 s->data_offset[i] = 0;
2145 else
2146 s->data_offset[i] = (height - 1) *
s->current_frame.f->linesize[i];
2147 }
2148
2149 s->last_slice_end = 0;
2150 for (i = 0; i <
s->c_superblock_height; i++)
2152
2153 // filter the last row
2154 for (i = 0; i < 3; i++) {
2155 int row = (
s->height >> (3 + (i &&
s->chroma_y_shift))) - 1;
2157 }
2159
2160 /* output frame, offset as needed */
2163 for (i = 0; i < 3; i++) {
2165 int off = (
s->offset_x >> (i &&
s->chroma_y_shift)) +
2166 (
s->offset_y >> (i &&
s->chroma_y_shift)) * dst->
linesize[i];
2167 dst->
data[i] += off;
2168 }
2169 *got_frame = 1;
2170
2175 }
2176
2177 return buf_size;
2178
2179 error:
2181
2184
2185 return -1;
2186 }
2187
2189 {
2191
2193 int token;
2194 if (s->
entries >= 32) {
/* overflow */
2196 return -1;
2197 }
2199 av_dlog(avctx,
"hti %d hbits %x token %d entry : %d size %d\n",
2204 } else {
2207 return -1;
2208 }
2212 return -1;
2215 return -1;
2218 }
2219 return 0;
2220 }
2221
2223 {
2225
2235
2237 }
2238
2239 #if CONFIG_THEORA_DECODER
2242 };
2243
2245 {
2247 int visible_width, visible_height,
colorspace;
2248 uint8_t offset_x = 0, offset_y = 0;
2251
2254
2255 /* 3.2.0 aka alpha3 has the same frame orientation as original vp3
2256 * but previous versions have the image flipped relative to vp3 */
2257 if (s->
theora < 0x030200) {
2260 "Old (<alpha3) Theora bitstream, flipped image\n");
2261 }
2262
2263 visible_width =
2265 visible_height =
2267
2268 if (s->
theora >= 0x030200) {
2271
2272 offset_x =
get_bits(gb, 8);
/* offset x */
2273 offset_y =
get_bits(gb, 8);
/* offset y, from bottom */
2274 }
2275
2276 /* sanity check */
2278 visible_width + offset_x > s->
width ||
2279 visible_height + offset_y > s->
height) {
2281 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2282 visible_width, visible_height, offset_x, offset_y,
2285 }
2286
2289 if (fps.
num && fps.
den) {
2290 if (fps.
num < 0 || fps.
den < 0) {
2293 }
2295 fps.
den, fps.
num, 1 << 30);
2296 }
2297
2300 if (aspect.
num && aspect.
den) {
2303 aspect.
num, aspect.
den, 1 << 30);
2305 }
2306
2307 if (s->
theora < 0x030200)
2308 skip_bits(gb, 5);
/* keyframe frequency force */
2311
2313
2314 if (s->
theora >= 0x030200) {
2315 skip_bits(gb, 5);
/* keyframe frequency force */
2320 }
2322 }
2323
2325 if (ret < 0)
2328 avctx->
width = visible_width;
2329 avctx->
height = visible_height;
2330 // translate offsets from theora axis ([0,0] lower left)
2331 // to normal axis ([0,0] upper left)
2334
2340 "chroma samples to preserve alignment.\n",
2342 }
2343 }
2344 }
2345
2346 if (colorspace == 1)
2348 else if (colorspace == 2)
2350
2351 if (colorspace == 1 || colorspace == 2) {
2354 }
2355
2356 return 0;
2357 }
2358
2360 {
2362 int i,
n, matrices, inter, plane;
2363
2364 if (s->
theora >= 0x030200) {
2366 /* loop filter limit values table */
2367 if (n)
2368 for (i = 0; i < 64; i++)
2370 }
2371
2372 if (s->
theora >= 0x030200)
2374 else
2375 n = 16;
2376 /* quality threshold table */
2377 for (i = 0; i < 64; i++)
2379
2380 if (s->
theora >= 0x030200)
2382 else
2383 n = 16;
2384 /* dc scale factor table */
2385 for (i = 0; i < 64; i++)
2387
2388 if (s->
theora >= 0x030200)
2390 else
2391 matrices = 3;
2392
2393 if (matrices > 384) {
2395 return -1;
2396 }
2397
2398 for (n = 0; n < matrices; n++)
2399 for (i = 0; i < 64; i++)
2401
2402 for (inter = 0; inter <= 1; inter++) {
2403 for (plane = 0; plane <= 2; plane++) {
2404 int newqr = 1;
2405 if (inter || plane > 0)
2407 if (!newqr) {
2408 int qtj, plj;
2410 qtj = 0;
2411 plj = plane;
2412 } else {
2413 qtj = (3 * inter + plane - 1) / 3;
2414 plj = (plane + 2) % 3;
2415 }
2421 } else {
2422 int qri = 0;
2423 int qi = 0;
2424
2425 for (;;) {
2427 if (i >= matrices) {
2429 "invalid base matrix index\n");
2430 return -1;
2431 }
2432 s->
qr_base[inter][plane][qri] = i;
2433 if (qi >= 63)
2434 break;
2436 s->
qr_size[inter][plane][qri++] = i;
2437 qi += i;
2438 }
2439
2440 if (qi > 63) {
2442 return -1;
2443 }
2445 }
2446 }
2447 }
2448
2449 /* Huffman tables */
2450 for (s->
hti = 0; s->
hti < 80; s->
hti++) {
2456 return -1;
2459 return -1;
2460 }
2461 }
2462
2464
2465 return 0;
2466 }
2467
2469 {
2472 int ptype;
2473 const uint8_t *header_start[3];
2474 int header_len[3];
2475 int i;
2476
2478
2480
2483 return -1;
2484 }
2485
2487 42, header_start, header_len) < 0) {
2489 return -1;
2490 }
2491
2492 for (i = 0; i < 3; i++) {
2493 if (header_len[i] <= 0)
2494 continue;
2496
2498
2499 if (!(ptype & 0x80)) {
2501 // return -1;
2502 }
2503
2504 // FIXME: Check for this as well.
2506
2507 switch (ptype) {
2508 case 0x80:
2510 return -1;
2511 break;
2512 case 0x81:
2513 // FIXME: is this needed? it breaks sometimes
2514 // theora_decode_comments(avctx, gb);
2515 break;
2516 case 0x82:
2518 return -1;
2519 break;
2520 default:
2522 "Unknown Theora config packet: %d\n", ptype & ~0x80);
2523 break;
2524 }
2527 "%d bits left in packet %X\n",
2529 if (s->
theora < 0x030200)
2530 break;
2531 }
2532
2534 }
2535
2542 .
init = theora_decode_init,
2550 };
2551 #endif
2552
2567 };