52 #define VP3_MV_VLC_BITS 6
53 #define VP4_MV_VLC_BITS 6
54 #define SUPERBLOCK_VLC_BITS 6
56 #define FRAGMENT_PIXELS 8
65 #define SB_NOT_CODED 0
66 #define SB_PARTIALLY_CODED 1
67 #define SB_FULLY_CODED 2
72 #define MAXIMUM_LONG_BIT_RUN 4129
74 #define MODE_INTER_NO_MV 0
76 #define MODE_INTER_PLUS_MV 2
77 #define MODE_INTER_LAST_MV 3
78 #define MODE_INTER_PRIOR_LAST 4
79 #define MODE_USING_GOLDEN 5
80 #define MODE_GOLDEN_MV 6
81 #define MODE_INTER_FOURMV 7
82 #define CODING_MODE_COUNT 8
131 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
132 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
133 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
134 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
161 #define MIN_DEQUANT_VAL 2
255 #define TOKEN_EOB(eob_run) ((eob_run) << 2)
256 #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
257 #define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
334 if (
s->golden_frame.f)
338 if (
s->current_frame.f)
350 s->theora_tables = 0;
366 for (j = 0; j < 2; j++)
367 for (
i = 0;
i < 7;
i++)
370 for (
i = 0;
i < 2;
i++)
384 int sb_x, sb_y, plane;
387 for (plane = 0; plane < 3; plane++) {
388 int sb_width = plane ?
s->c_superblock_width
389 :
s->y_superblock_width;
390 int sb_height = plane ?
s->c_superblock_height
391 :
s->y_superblock_height;
392 int frag_width =
s->fragment_width[!!plane];
393 int frag_height =
s->fragment_height[!!plane];
395 for (sb_y = 0; sb_y < sb_height; sb_y++)
396 for (sb_x = 0; sb_x < sb_width; sb_x++)
397 for (
i = 0;
i < 16;
i++) {
401 if (x < frag_width && y < frag_height)
402 s->superblock_fragments[j++] =
s->fragment_start[plane] +
405 s->superblock_fragments[j++] = -1;
418 int ac_scale_factor =
s->coded_ac_scale_factor[
s->qps[qpi]];
419 int i, plane, inter, qri, bmi, bmj, qistart;
421 for (inter = 0; inter < 2; inter++) {
422 for (plane = 0; plane < 3; plane++) {
423 int dc_scale_factor =
s->coded_dc_scale_factor[!!plane][
s->qps[qpi]];
425 for (qri = 0; qri <
s->qr_count[inter][plane]; qri++) {
426 sum +=
s->qr_size[inter][plane][qri];
427 if (
s->qps[qpi] <= sum)
430 qistart = sum -
s->qr_size[inter][plane][qri];
431 bmi =
s->qr_base[inter][plane][qri];
432 bmj =
s->qr_base[inter][plane][qri + 1];
433 for (
i = 0;
i < 64;
i++) {
434 int coeff = (2 * (sum -
s->qps[qpi]) *
s->base_matrix[bmi][
i] -
435 2 * (qistart -
s->qps[qpi]) *
s->base_matrix[bmj][
i] +
436 s->qr_size[inter][plane][qri]) /
437 (2 *
s->qr_size[inter][plane][qri]);
439 int qmin = 8 << (inter + !
i);
440 int qscale =
i ? ac_scale_factor : dc_scale_factor;
441 int qbias = (1 + inter) * 3;
442 s->qmat[qpi][inter][plane][
s->idct_permutation[
i]] =
443 (
i == 0 ||
s->version < 2) ?
av_clip((qscale *
coeff) / 100 * 4, qmin, 4096)
444 : (qscale * (
coeff - qbias) / 100 + qbias) * 4;
448 s->qmat[qpi][inter][plane][0] =
s->qmat[0][inter][plane][0];
470 int superblock_starts[3] = {
471 0,
s->u_superblock_start,
s->v_superblock_start
474 int current_superblock = 0;
476 int num_partial_superblocks = 0;
479 int current_fragment;
481 int plane0_num_coded_frags = 0;
490 while (current_superblock < s->superblock_count &&
get_bits_left(gb) > 0) {
496 current_run =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
498 if (current_run == 34)
501 if (current_run >
s->superblock_count - current_superblock) {
503 "Invalid partially coded superblock run length\n");
507 memset(
s->superblock_coding + current_superblock,
bit, current_run);
509 current_superblock += current_run;
511 num_partial_superblocks += current_run;
516 if (num_partial_superblocks < s->superblock_count) {
517 int superblocks_decoded = 0;
519 current_superblock = 0;
523 while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
530 current_run =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
532 if (current_run == 34)
535 for (j = 0; j < current_run; current_superblock++) {
536 if (current_superblock >=
s->superblock_count) {
538 "Invalid fully coded superblock run length\n");
543 if (
s->superblock_coding[current_superblock] ==
SB_NOT_CODED) {
544 s->superblock_coding[current_superblock] = 2 *
bit;
548 superblocks_decoded += current_run;
554 if (num_partial_superblocks) {
565 s->total_num_coded_frags = 0;
566 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
568 s->coded_fragment_list[0] =
s->keyframe ?
s->kf_coded_fragment_list
569 :
s->nkf_coded_fragment_list;
571 for (plane = 0; plane < 3; plane++) {
572 int sb_start = superblock_starts[plane];
573 int sb_end = sb_start + (plane ?
s->c_superblock_count
574 :
s->y_superblock_count);
575 int num_coded_frags = 0;
578 if (
s->num_kf_coded_fragment[plane] == -1) {
579 for (
i = sb_start;
i < sb_end;
i++) {
581 for (j = 0; j < 16; j++) {
583 current_fragment =
s->superblock_fragments[
i * 16 + j];
584 if (current_fragment != -1) {
585 s->coded_fragment_list[plane][num_coded_frags++] =
590 s->num_kf_coded_fragment[plane] = num_coded_frags;
592 num_coded_frags =
s->num_kf_coded_fragment[plane];
599 for (j = 0; j < 16; j++) {
601 current_fragment =
s->superblock_fragments[
i * 16 + j];
602 if (current_fragment != -1) {
603 int coded =
s->superblock_coding[
i];
608 if (current_run-- == 0) {
610 current_run =
get_vlc2(gb,
s->fragment_run_length_vlc.table, 5, 2);
618 s->all_fragments[current_fragment].coding_method =
620 s->coded_fragment_list[plane][num_coded_frags++] =
624 s->all_fragments[current_fragment].coding_method =
632 plane0_num_coded_frags = num_coded_frags;
633 s->total_num_coded_frags += num_coded_frags;
634 for (
i = 0;
i < 64;
i++)
635 s->num_coded_frags[plane][
i] = num_coded_frags;
637 s->coded_fragment_list[plane + 1] =
s->coded_fragment_list[plane] +
643 #define BLOCK_X (2 * mb_x + (k & 1))
644 #define BLOCK_Y (2 * mb_y + (k >> 1))
646 #if CONFIG_VP4_DECODER
658 if (v >
s->yuv_macroblock_count) {
664 skip_bits(gb, 2 + n); \
665 v += (1 << n) + get_bits(gb, n); }
666 #define thresh(n) (0x200 - (0x80 >> n))
667 #define else_if(n) else if (bits < thresh(n)) body(n)
670 }
else if (
bits < thresh(0)) {
689 int v =
get_vlc2(gb,
s->block_pattern_vlc[*next_block_pattern_table].table, 3, 2);
697 int next_block_pattern_table;
698 int bit, current_run, has_partial;
700 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
707 for (
i = 0;
i <
s->yuv_macroblock_count;
i += current_run) {
710 current_run = vp4_get_mb_count(
s, gb);
711 if (current_run >
s->yuv_macroblock_count -
i)
713 memset(
s->superblock_coding +
i, 2 *
bit, current_run);
722 current_run = vp4_get_mb_count(
s, gb);
723 for (
i = 0;
i <
s->yuv_macroblock_count;
i++) {
724 if (!
s->superblock_coding[
i]) {
727 current_run = vp4_get_mb_count(
s, gb);
729 s->superblock_coding[
i] =
bit;
737 next_block_pattern_table = 0;
739 for (plane = 0; plane < 3; plane++) {
741 int sb_width = plane ?
s->c_superblock_width :
s->y_superblock_width;
742 int sb_height = plane ?
s->c_superblock_height :
s->y_superblock_height;
743 int mb_width = plane ?
s->c_macroblock_width :
s->macroblock_width;
744 int mb_height = plane ?
s->c_macroblock_height :
s->macroblock_height;
745 int fragment_width =
s->fragment_width[!!plane];
746 int fragment_height =
s->fragment_height[!!plane];
748 for (sb_y = 0; sb_y < sb_height; sb_y++) {
749 for (sb_x = 0; sb_x < sb_width; sb_x++) {
750 for (j = 0; j < 4; j++) {
751 int mb_x = 2 * sb_x + (j >> 1);
752 int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
753 int mb_coded, pattern, coded;
755 if (mb_x >= mb_width || mb_y >= mb_height)
758 mb_coded =
s->superblock_coding[
i++];
763 pattern = vp4_get_block_pattern(
s, gb, &next_block_pattern_table);
767 for (k = 0; k < 4; k++) {
771 coded = pattern & (8 >> k);
790 int i, j, k, sb_x, sb_y;
792 int current_macroblock;
793 int current_fragment;
800 for (
i = 0;
i <
s->fragment_count;
i++)
808 for (
i = 0;
i < 8;
i++)
810 for (
i = 0;
i < 8;
i++)
811 custom_mode_alphabet[
get_bits(gb, 3)] =
i;
812 alphabet = custom_mode_alphabet;
818 for (sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
819 for (sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
823 for (j = 0; j < 4; j++) {
824 int mb_x = 2 * sb_x + (j >> 1);
825 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
826 current_macroblock = mb_y *
s->macroblock_width + mb_x;
828 if (mb_x >=
s->macroblock_width ||
829 mb_y >=
s->macroblock_height)
835 for (k = 0; k < 4; k++) {
838 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY)
850 coding_mode = alphabet[
get_vlc2(gb,
s->mode_code_vlc.table, 3, 3)];
852 s->macroblock_coding[current_macroblock] = coding_mode;
853 for (k = 0; k < 4; k++) {
859 #define SET_CHROMA_MODES \
860 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
861 frag[s->fragment_start[1]].coding_method = coding_mode; \
862 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
863 frag[s->fragment_start[2]].coding_method = coding_mode;
865 if (
s->chroma_y_shift) {
866 frag =
s->all_fragments + mb_y *
867 s->fragment_width[1] + mb_x;
869 }
else if (
s->chroma_x_shift) {
870 frag =
s->all_fragments +
871 2 * mb_y *
s->fragment_width[1] + mb_x;
872 for (k = 0; k < 2; k++) {
874 frag +=
s->fragment_width[1];
877 for (k = 0; k < 4; k++) {
878 frag =
s->all_fragments +
895 return last_motion < 0 ? -v : v;
904 int j, k, sb_x, sb_y;
908 int last_motion_x = 0;
909 int last_motion_y = 0;
910 int prior_last_motion_x = 0;
911 int prior_last_motion_y = 0;
912 int last_gold_motion_x = 0;
913 int last_gold_motion_y = 0;
914 int current_macroblock;
915 int current_fragment;
922 coding_mode =
s->version < 2 ?
get_bits1(gb) : 2;
926 for (sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
927 for (sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
931 for (j = 0; j < 4; j++) {
932 int mb_x = 2 * sb_x + (j >> 1);
933 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
934 current_macroblock = mb_y *
s->macroblock_width + mb_x;
936 if (mb_x >=
s->macroblock_width ||
937 mb_y >=
s->macroblock_height ||
938 s->macroblock_coding[current_macroblock] ==
MODE_COPY)
941 switch (
s->macroblock_coding[current_macroblock]) {
943 if (coding_mode == 2) {
944 last_gold_motion_x = motion_x[0] =
vp4_get_mv(
s, gb, 0, last_gold_motion_x);
945 last_gold_motion_y = motion_y[0] =
vp4_get_mv(
s, gb, 1, last_gold_motion_y);
950 if (coding_mode == 0) {
951 motion_x[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
953 motion_y[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
955 }
else if (coding_mode == 1) {
965 prior_last_motion_x = last_motion_x;
966 prior_last_motion_y = last_motion_y;
967 last_motion_x = motion_x[0];
968 last_motion_y = motion_y[0];
974 prior_last_motion_x = last_motion_x;
975 prior_last_motion_y = last_motion_y;
979 for (k = 0; k < 4; k++) {
981 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY) {
982 if (coding_mode == 0) {
983 motion_x[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
985 motion_y[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
987 }
else if (coding_mode == 1) {
991 motion_x[k] =
vp4_get_mv(
s, gb, 0, prior_last_motion_x);
992 motion_y[k] =
vp4_get_mv(
s, gb, 1, prior_last_motion_y);
994 last_motion_x = motion_x[k];
995 last_motion_y = motion_y[k];
1005 motion_x[0] = last_motion_x;
1006 motion_y[0] = last_motion_y;
1015 motion_x[0] = prior_last_motion_x;
1016 motion_y[0] = prior_last_motion_y;
1019 prior_last_motion_x = last_motion_x;
1020 prior_last_motion_y = last_motion_y;
1021 last_motion_x = motion_x[0];
1022 last_motion_y = motion_y[0];
1035 for (k = 0; k < 4; k++) {
1039 s->motion_val[0][current_fragment][0] = motion_x[k];
1040 s->motion_val[0][current_fragment][1] = motion_y[k];
1042 s->motion_val[0][current_fragment][0] = motion_x[0];
1043 s->motion_val[0][current_fragment][1] = motion_y[0];
1047 if (
s->chroma_y_shift) {
1049 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] +
1050 motion_x[2] + motion_x[3], 2);
1051 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] +
1052 motion_y[2] + motion_y[3], 2);
1054 if (
s->version <= 2) {
1055 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1056 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
1058 frag = mb_y *
s->fragment_width[1] + mb_x;
1059 s->motion_val[1][frag][0] = motion_x[0];
1060 s->motion_val[1][frag][1] = motion_y[0];
1061 }
else if (
s->chroma_x_shift) {
1063 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
1064 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
1065 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
1066 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
1068 motion_x[1] = motion_x[0];
1069 motion_y[1] = motion_y[0];
1071 if (
s->version <= 2) {
1072 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1073 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
1075 frag = 2 * mb_y *
s->fragment_width[1] + mb_x;
1076 for (k = 0; k < 2; k++) {
1077 s->motion_val[1][frag][0] = motion_x[k];
1078 s->motion_val[1][frag][1] = motion_y[k];
1079 frag +=
s->fragment_width[1];
1082 for (k = 0; k < 4; k++) {
1085 s->motion_val[1][frag][0] = motion_x[k];
1086 s->motion_val[1][frag][1] = motion_y[k];
1088 s->motion_val[1][frag][0] = motion_x[0];
1089 s->motion_val[1][frag][1] = motion_y[0];
1102 int qpi,
i, j,
bit, run_length, blocks_decoded, num_blocks_at_qpi;
1103 int num_blocks =
s->total_num_coded_frags;
1105 for (qpi = 0; qpi <
s->nqps - 1 && num_blocks > 0; qpi++) {
1106 i = blocks_decoded = num_blocks_at_qpi = 0;
1117 run_length =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
1119 if (run_length == 34)
1121 blocks_decoded += run_length;
1124 num_blocks_at_qpi += run_length;
1126 for (j = 0; j < run_length;
i++) {
1127 if (
i >=
s->total_num_coded_frags)
1130 if (
s->all_fragments[
s->coded_fragment_list[0][
i]].qpi == qpi) {
1131 s->all_fragments[
s->coded_fragment_list[0][
i]].qpi +=
bit;
1135 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
1137 num_blocks -= num_blocks_at_qpi;
1153 int bits_to_get, zero_run;
1157 bits_to_get =
get_bits(gb, bits_to_get);
1190 int num_coeffs =
s->num_coded_frags[plane][coeff_index];
1191 int16_t *dct_tokens =
s->dct_tokens[plane][coeff_index];
1194 int *coded_fragment_list =
s->coded_fragment_list[plane];
1198 if (num_coeffs < 0) {
1200 "Invalid number of coefficients at level %d\n", coeff_index);
1204 if (eob_run > num_coeffs) {
1206 blocks_ended = num_coeffs;
1207 eob_run -= num_coeffs;
1210 blocks_ended = eob_run;
1216 dct_tokens[j++] = blocks_ended << 2;
1220 token =
get_vlc2(gb, vlc_table, 11, 3);
1222 if ((
unsigned) token <= 6
U) {
1229 if (eob_run > num_coeffs - coeff_i) {
1230 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
1231 blocks_ended += num_coeffs - coeff_i;
1232 eob_run -= num_coeffs - coeff_i;
1233 coeff_i = num_coeffs;
1236 blocks_ended += eob_run;
1240 }
else if (token >= 0) {
1251 all_fragments[coded_fragment_list[coeff_i]].
dc =
coeff;
1256 if (coeff_index + zero_run > 64) {
1258 "Invalid zero run of %d with %d coeffs left\n",
1259 zero_run, 64 - coeff_index);
1260 zero_run = 64 - coeff_index;
1265 for (
i = coeff_index + 1;
i <= coeff_index + zero_run;
i++)
1266 s->num_coded_frags[plane][
i]--;
1274 if (blocks_ended >
s->num_coded_frags[plane][coeff_index])
1280 for (
i = coeff_index + 1;
i < 64;
i++)
1281 s->num_coded_frags[plane][
i] -= blocks_ended;
1285 s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1286 else if (coeff_index < 63)
1287 s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1295 int fragment_height);
1307 int residual_eob_run = 0;
1311 s->dct_tokens[0][0] =
s->dct_tokens_base;
1321 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_y_table], 0,
1322 0, residual_eob_run);
1323 if (residual_eob_run < 0)
1324 return residual_eob_run;
1332 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1333 1, residual_eob_run);
1334 if (residual_eob_run < 0)
1335 return residual_eob_run;
1336 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1337 2, residual_eob_run);
1338 if (residual_eob_run < 0)
1339 return residual_eob_run;
1344 s->fragment_width[1],
s->fragment_height[1]);
1346 s->fragment_width[1],
s->fragment_height[1]);
1356 for (
i = 1;
i <= 5;
i++) {
1358 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 16];
1359 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 16];
1361 for (
i = 6;
i <= 14;
i++) {
1363 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 32];
1364 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 32];
1366 for (
i = 15;
i <= 27;
i++) {
1368 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 48];
1369 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 48];
1371 for (
i = 28;
i <= 63;
i++) {
1373 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 64];
1374 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 64];
1378 for (
i = 1;
i <= 63;
i++) {
1380 0, residual_eob_run);
1381 if (residual_eob_run < 0)
1382 return residual_eob_run;
1385 1, residual_eob_run);
1386 if (residual_eob_run < 0)
1387 return residual_eob_run;
1389 2, residual_eob_run);
1390 if (residual_eob_run < 0)
1391 return residual_eob_run;
1397 #if CONFIG_VP4_DECODER
1406 int plane,
int eob_tracker[64],
int fragment)
1414 while (!eob_tracker[coeff_i]) {
1421 if ((
unsigned) token <= 6
U) {
1423 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1424 eob_tracker[coeff_i] = eob_run - 1;
1426 }
else if (token >= 0) {
1430 if (coeff_i + zero_run > 64) {
1432 "Invalid zero run of %d with %d coeffs left\n",
1433 zero_run, 64 - coeff_i);
1434 zero_run = 64 - coeff_i;
1437 coeff_i += zero_run;
1452 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1453 eob_tracker[coeff_i]--;
1467 for (
i = 0;
i < 4;
i++)
1468 dc_pred[0][
i + 1] =
s->dc_pred_row[sb_x * 4 +
i];
1470 for (j = 1; j < 5; j++)
1471 for (
i = 0;
i < 4;
i++)
1472 vp4_dc_predictor_reset(&dc_pred[j][
i + 1]);
1479 for (
i = 0;
i < 4;
i++)
1480 s->dc_pred_row[sb_x * 4 +
i] = dc_pred[4][
i + 1];
1483 dc_pred[
i][0] = dc_pred[
i][4];
1493 dc += dc_pred[-6].
dc;
1498 dc += dc_pred[6].
dc;
1502 if (count != 2 && dc_pred[-1].
type ==
type) {
1503 dc += dc_pred[-1].
dc;
1507 if (count != 2 && dc_pred[1].
type ==
type) {
1508 dc += dc_pred[1].
dc;
1513 return count == 2 ?
dc / 2 : last_dc[
type];
1519 int16_t *
base =
s->dct_tokens_base;
1520 for (plane = 0; plane < 3; plane++) {
1521 for (
i = 0;
i < 64;
i++) {
1522 s->dct_tokens[plane][
i] =
base;
1523 base +=
s->fragment_width[!!plane] *
s->fragment_height[!!plane];
1536 int plane, sb_y, sb_x;
1537 int eob_tracker[64];
1554 tables[0][0] = &
s->coeff_vlc[dc_y_table];
1555 tables[1][0] = &
s->coeff_vlc[dc_c_table];
1556 for (
i = 1;
i <= 5;
i++) {
1558 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 16];
1559 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 16];
1561 for (
i = 6;
i <= 14;
i++) {
1563 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 32];
1564 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 32];
1566 for (
i = 15;
i <= 27;
i++) {
1568 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 48];
1569 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 48];
1571 for (
i = 28;
i <= 63;
i++) {
1573 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 64];
1574 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 64];
1577 vp4_set_tokens_base(
s);
1579 memset(last_dc, 0,
sizeof(last_dc));
1582 memset(eob_tracker, 0,
sizeof(eob_tracker));
1585 for (
i = 0;
i <
s->fragment_width[!!plane];
i++)
1586 vp4_dc_predictor_reset(&
s->dc_pred_row[
i]);
1588 for (j = 0; j < 6; j++)
1589 for (
i = 0;
i < 6;
i++)
1590 vp4_dc_predictor_reset(&dc_pred[j][
i]);
1592 for (sb_y = 0; sb_y * 4 <
s->fragment_height[!!plane]; sb_y++) {
1593 for (sb_x = 0; sb_x *4 <
s->fragment_width[!!plane]; sb_x++) {
1594 vp4_dc_pred_before(
s, dc_pred, sb_x);
1595 for (j = 0; j < 16; j++) {
1598 int x = 4 * sb_x + hx;
1599 int y = 4 * sb_y + hy;
1603 if (x >=
s->fragment_width[!!plane] || y >=
s->fragment_height[!!plane])
1606 fragment =
s->fragment_start[plane] + y *
s->fragment_width[!!plane] + x;
1611 if (vp4_unpack_vlcs(
s, gb,
tables[!!plane], plane, eob_tracker,
fragment) < 0)
1617 vp4_dc_pred(
s, this_dc_pred, last_dc, dc_block_type, plane);
1619 this_dc_pred->
type = dc_block_type,
1620 this_dc_pred->
dc = last_dc[dc_block_type] =
s->all_fragments[
fragment].dc;
1622 vp4_dc_pred_after(
s, dc_pred, sb_x);
1627 vp4_set_tokens_base(
s);
1638 #define COMPATIBLE_FRAME(x) \
1639 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1640 #define DC_COEFF(u) s->all_fragments[u].dc
1645 int fragment_height)
1653 int i = first_fragment;
1658 int vl, vul, vu, vur;
1670 static const int predictor_transform[16][4] = {
1684 { -104, 116, 0, 116 },
1686 { -104, 116, 0, 116 }
1695 static const unsigned char compatible_frame[9] = {
1706 int current_frame_type;
1722 for (y = 0; y < fragment_height; y++) {
1724 for (x = 0; x < fragment_width; x++,
i++) {
1727 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
1728 current_frame_type =
1729 compatible_frame[
s->all_fragments[
i].coding_method];
1739 u =
i - fragment_width;
1744 ul =
i - fragment_width - 1;
1749 if (x + 1 < fragment_width) {
1750 ur =
i - fragment_width + 1;
1760 predicted_dc = last_dc[current_frame_type];
1764 (predictor_transform[
transform][0] * vul) +
1765 (predictor_transform[
transform][1] * vu) +
1766 (predictor_transform[
transform][2] * vur) +
1767 (predictor_transform[
transform][3] * vl);
1769 predicted_dc /= 128;
1774 if (
FFABS(predicted_dc - vu) > 128)
1776 else if (
FFABS(predicted_dc - vl) > 128)
1778 else if (
FFABS(predicted_dc - vul) > 128)
1786 last_dc[current_frame_type] =
DC_COEFF(
i);
1793 int ystart,
int yend)
1796 int *bounding_values =
s->bounding_values_array + 127;
1798 int width =
s->fragment_width[!!plane];
1799 int height =
s->fragment_height[!!plane];
1801 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
1802 uint8_t *plane_data =
s->current_frame.f->data[plane];
1803 if (!
s->flipped_image)
1805 plane_data +=
s->data_offset[plane] + 8 * ystart *
stride;
1807 for (y = ystart; y < yend; y++) {
1808 for (x = 0; x <
width; x++) {
1816 s->vp3dsp.h_loop_filter(
1818 stride, bounding_values);
1823 s->vp3dsp.v_loop_filter(
1825 stride, bounding_values);
1831 if ((x <
width - 1) &&
1833 s->vp3dsp.h_loop_filter(
1834 plane_data + 8 * x + 8,
1835 stride, bounding_values);
1843 s->vp3dsp.v_loop_filter(
1844 plane_data + 8 * x + 8 *
stride,
1845 stride, bounding_values);
1851 plane_data += 8 *
stride;
1860 int plane,
int inter, int16_t
block[64])
1862 int16_t *dequantizer =
s->qmat[frag->
qpi][inter][plane];
1863 uint8_t *
perm =
s->idct_scantable;
1867 int token = *
s->dct_tokens[plane][
i];
1868 switch (token & 3) {
1871 s->dct_tokens[plane][
i]++;
1873 *
s->dct_tokens[plane][
i] = token & ~3;
1876 s->dct_tokens[plane][
i]++;
1877 i += (token >> 2) & 0x7f;
1887 s->dct_tokens[plane][
i++]++;
1897 block[0] = frag->
dc *
s->qmat[0][inter][plane][0];
1910 int y_flipped =
s->flipped_image ?
s->height - y : y;
1916 y_flipped ==
s->height ? INT_MAX
1921 if (!
s->avctx->draw_horiz_band)
1924 h = y -
s->last_slice_end;
1925 s->last_slice_end = y;
1928 if (!
s->flipped_image)
1929 y =
s->height - y -
h;
1931 cy = y >>
s->chroma_y_shift;
1932 offset[0] =
s->current_frame.f->linesize[0] * y;
1933 offset[1] =
s->current_frame.f->linesize[1] * cy;
1934 offset[2] =
s->current_frame.f->linesize[2] * cy;
1939 s->avctx->draw_horiz_band(
s->avctx,
s->current_frame.f,
offset, y, 3,
h);
1947 int motion_y,
int y)
1951 int border = motion_y & 1;
1955 ref_frame = &
s->golden_frame;
1957 ref_frame = &
s->last_frame;
1959 ref_row = y + (motion_y >> 1);
1960 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1965 #if CONFIG_VP4_DECODER
1969 static int vp4_mc_loop_filter(
Vp3DecodeContext *
s,
int plane,
int motion_x,
int motion_y,
int bx,
int by,
1970 uint8_t * motion_source,
int stride,
int src_x,
int src_y, uint8_t *
temp)
1972 int motion_shift = plane ? 4 : 2;
1973 int subpel_mask = plane ? 3 : 1;
1974 int *bounding_values =
s->bounding_values_array + 127;
1979 int x_subpel, y_subpel;
1980 int x_offset, y_offset;
1982 int block_width = plane ? 8 : 16;
1983 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
1984 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
1986 #define loop_stride 12
1987 uint8_t
loop[12 * loop_stride];
1990 x = 8 * bx + motion_x / motion_shift;
1991 y = 8 * by + motion_y / motion_shift;
1993 x_subpel = motion_x & subpel_mask;
1994 y_subpel = motion_y & subpel_mask;
1996 if (x_subpel || y_subpel) {
2006 x2 = x + block_width;
2007 y2 = y + block_width;
2009 if (x2 < 0 || x2 >= plane_width || y2 < 0 || y2 >= plane_height)
2012 x_offset = (-(x + 2) & 7) + 2;
2013 y_offset = (-(y + 2) & 7) + 2;
2015 if (x_offset > 8 + x_subpel && y_offset > 8 + y_subpel)
2018 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2020 12, 12, src_x - 1, src_y - 1,
2024 if (x_offset <= 8 + x_subpel)
2027 if (y_offset <= 8 + y_subpel)
2035 if (!x_offset && !y_offset)
2038 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2040 12, 12, src_x - 1, src_y - 1,
2044 #define safe_loop_filter(name, ptr, stride, bounding_values) \
2045 if ((uintptr_t)(ptr) & 7) \
2046 s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \
2048 s->vp3dsp.name(ptr, stride, bounding_values);
2051 safe_loop_filter(h_loop_filter,
loop + loop_stride + x_offset + 1, loop_stride, bounding_values);
2054 safe_loop_filter(v_loop_filter,
loop + (y_offset + 1)*loop_stride + 1, loop_stride, bounding_values);
2057 for (
i = 0;
i < 9;
i++)
2071 int16_t *
block =
s->block;
2072 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
2073 int motion_halfpel_index;
2074 uint8_t *motion_source;
2075 int plane, first_pixel;
2077 if (slice >=
s->c_superblock_height)
2080 for (plane = 0; plane < 3; plane++) {
2082 s->data_offset[plane];
2083 uint8_t *last_plane =
s->last_frame.f->data[plane] +
2084 s->data_offset[plane];
2085 uint8_t *golden_plane =
s->golden_frame.f->data[plane] +
2086 s->data_offset[plane];
2087 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
2088 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
2089 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
2090 int8_t(*motion_val)[2] =
s->motion_val[!!plane];
2092 int sb_x, sb_y = slice << (!plane &&
s->chroma_y_shift);
2093 int slice_height = sb_y + 1 + (!plane &&
s->chroma_y_shift);
2094 int slice_width = plane ?
s->c_superblock_width
2095 :
s->y_superblock_width;
2097 int fragment_width =
s->fragment_width[!!plane];
2098 int fragment_height =
s->fragment_height[!!plane];
2099 int fragment_start =
s->fragment_start[plane];
2101 int do_await = !plane && HAVE_THREADS &&
2104 if (!
s->flipped_image)
2110 for (; sb_y < slice_height; sb_y++) {
2112 for (sb_x = 0; sb_x < slice_width; sb_x++) {
2114 for (j = 0; j < 16; j++) {
2122 if (x >= fragment_width || y >= fragment_height)
2125 first_pixel = 8 * y *
stride + 8 * x;
2131 (16 * y) >>
s->chroma_y_shift);
2134 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
2137 motion_source = golden_plane;
2139 motion_source = last_plane;
2141 motion_source += first_pixel;
2142 motion_halfpel_index = 0;
2146 if ((
s->all_fragments[
i].coding_method >
MODE_INTRA) &&
2149 int standard_mc = 1;
2150 motion_x = motion_val[
fragment][0];
2151 motion_y = motion_val[
fragment][1];
2152 #if CONFIG_VP4_DECODER
2153 if (plane &&
s->version >= 2) {
2154 motion_x = (motion_x >> 1) | (motion_x & 1);
2155 motion_y = (motion_y >> 1) | (motion_y & 1);
2159 src_x = (motion_x >> 1) + 8 * x;
2160 src_y = (motion_y >> 1) + 8 * y;
2162 motion_halfpel_index = motion_x & 0x01;
2163 motion_source += (motion_x >> 1);
2165 motion_halfpel_index |= (motion_y & 0x01) << 1;
2166 motion_source += ((motion_y >> 1) *
stride);
2168 #if CONFIG_VP4_DECODER
2169 if (
s->version >= 2) {
2170 uint8_t *
temp =
s->edge_emu_buffer;
2173 if (vp4_mc_loop_filter(
s, plane, motion_val[
fragment][0], motion_val[
fragment][1], x, y, motion_source,
stride, src_x, src_y,
temp)) {
2174 motion_source =
temp;
2180 if (standard_mc && (
2181 src_x < 0 || src_y < 0 ||
2182 src_x + 9 >= plane_width ||
2183 src_y + 9 >= plane_height)) {
2184 uint8_t *
temp =
s->edge_emu_buffer;
2188 s->vdsp.emulated_edge_mc(
temp, motion_source,
2193 motion_source =
temp;
2204 if (motion_halfpel_index != 3) {
2205 s->hdsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
2207 motion_source,
stride, 8);
2211 int d = (motion_x ^ motion_y) >> 31;
2214 motion_source +
stride + 1 +
d,
2240 s->hdsp.put_pixels_tab[1][0](
2242 last_plane + first_pixel,
2249 if (
s->version < 2 && !
s->skip_loop_filter)
2251 FFMIN(4 * sb_y + 3, fragment_height - 1));
2271 int y_fragment_count, c_fragment_count;
2275 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2276 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2279 s->superblock_coding =
av_mallocz(
FFMAX(
s->superblock_count,
s->yuv_macroblock_count));
2280 s->all_fragments =
av_calloc(
s->fragment_count,
sizeof(*
s->all_fragments));
2282 s-> kf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2283 s->nkf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2284 memset(
s-> num_kf_coded_fragment, -1,
sizeof(
s-> num_kf_coded_fragment));
2287 64 *
sizeof(*
s->dct_tokens_base));
2288 s->motion_val[0] =
av_calloc(y_fragment_count,
sizeof(*
s->motion_val[0]));
2289 s->motion_val[1] =
av_calloc(c_fragment_count,
sizeof(*
s->motion_val[1]));
2292 s->superblock_fragments =
av_calloc(
s->superblock_count, 16 *
sizeof(
int));
2293 s->macroblock_coding =
av_mallocz(
s->macroblock_count + 1);
2295 s->dc_pred_row =
av_malloc_array(
s->y_superblock_width * 4,
sizeof(*
s->dc_pred_row));
2297 if (!
s->superblock_coding || !
s->all_fragments ||
2298 !
s->dct_tokens_base || !
s->kf_coded_fragment_list ||
2299 !
s->nkf_coded_fragment_list ||
2300 !
s->superblock_fragments || !
s->macroblock_coding ||
2302 !
s->motion_val[0] || !
s->motion_val[1]) {
2317 if (!
s->current_frame.f || !
s->last_frame.f || !
s->golden_frame.f)
2326 int i, inter, plane,
ret;
2329 int y_fragment_count, c_fragment_count;
2330 #if CONFIG_VP4_DECODER
2340 #if !CONFIG_VP4_DECODER
2359 for (
i = 0;
i < 64;
i++) {
2360 #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
2368 for (
i = 0;
i < 3;
i++)
2375 s->y_superblock_width = (
s->width + 31) / 32;
2376 s->y_superblock_height = (
s->height + 31) / 32;
2377 s->y_superblock_count =
s->y_superblock_width *
s->y_superblock_height;
2380 c_width =
s->width >>
s->chroma_x_shift;
2381 c_height =
s->height >>
s->chroma_y_shift;
2382 s->c_superblock_width = (c_width + 31) / 32;
2383 s->c_superblock_height = (c_height + 31) / 32;
2384 s->c_superblock_count =
s->c_superblock_width *
s->c_superblock_height;
2386 s->superblock_count =
s->y_superblock_count + (
s->c_superblock_count * 2);
2387 s->u_superblock_start =
s->y_superblock_count;
2388 s->v_superblock_start =
s->u_superblock_start +
s->c_superblock_count;
2390 s->macroblock_width = (
s->width + 15) / 16;
2391 s->macroblock_height = (
s->height + 15) / 16;
2392 s->macroblock_count =
s->macroblock_width *
s->macroblock_height;
2393 s->c_macroblock_width = (c_width + 15) / 16;
2394 s->c_macroblock_height = (c_height + 15) / 16;
2395 s->c_macroblock_count =
s->c_macroblock_width *
s->c_macroblock_height;
2396 s->yuv_macroblock_count =
s->macroblock_count + 2 *
s->c_macroblock_count;
2400 s->fragment_width[1] =
s->fragment_width[0] >>
s->chroma_x_shift;
2401 s->fragment_height[1] =
s->fragment_height[0] >>
s->chroma_y_shift;
2404 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2405 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2406 s->fragment_count = y_fragment_count + 2 * c_fragment_count;
2407 s->fragment_start[1] = y_fragment_count;
2408 s->fragment_start[2] = y_fragment_count + c_fragment_count;
2410 if (!
s->theora_tables) {
2411 const uint8_t (*bias_tabs)[32][2];
2413 for (
i = 0;
i < 64;
i++) {
2423 for (inter = 0; inter < 2; inter++) {
2424 for (plane = 0; plane < 3; plane++) {
2425 s->qr_count[inter][plane] = 1;
2426 s->qr_size[inter][plane][0] = 63;
2427 s->qr_base[inter][plane][0] =
2428 s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
2436 &bias_tabs[
i][0][1], 2,
2437 &bias_tabs[
i][0][0], 2, 1,
2447 &
tab->entries[0].len,
sizeof(*
tab->entries),
2448 &
tab->entries[0].sym,
sizeof(*
tab->entries), 1,
2457 NULL, 0, 0, 1, 0, avctx);
2463 NULL, 0, 0, 0, 0, avctx);
2469 NULL, 0, 0, 0, 0, avctx);
2480 #if CONFIG_VP4_DECODER
2481 for (j = 0; j < 2; j++)
2482 for (
i = 0;
i < 7;
i++) {
2492 for (
i = 0;
i < 2;
i++)
2528 if (
src->f->data[0])
2546 int qps_changed = 0,
i, err;
2548 if (!
s1->current_frame.f->data[0] ||
2549 s->width !=
s1->width ||
s->height !=
s1->height) {
2557 if ((err = ref_frames(
s,
s1)) < 0)
2560 s->keyframe =
s1->keyframe;
2563 for (
i = 0;
i < 3;
i++) {
2564 if (
s->qps[
i] !=
s1->qps[1]) {
2566 memcpy(&
s->qmat[
i], &
s1->qmat[
i],
sizeof(
s->qmat[
i]));
2570 if (
s->qps[0] !=
s1->qps[0])
2571 memcpy(&
s->bounding_values_array, &
s1->bounding_values_array,
2572 sizeof(
s->bounding_values_array));
2575 memcpy(
s->qps,
s1->qps,
sizeof(
s->qps));
2576 memcpy(
s->last_qps,
s1->last_qps,
sizeof(
s->last_qps));
2586 void *
data,
int *got_frame,
2590 const uint8_t *buf = avpkt->
data;
2591 int buf_size = avpkt->
size;
2599 #if CONFIG_THEORA_DECODER
2605 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2619 }
else if (
type == 2) {
2632 "Header packet passed to frame decoder, skipping\n");
2638 if (!
s->all_fragments) {
2644 for (
i = 0;
i < 3;
i++)
2645 s->last_qps[
i] =
s->qps[
i];
2650 }
while (
s->theora >= 0x030200 &&
s->nqps < 3 &&
get_bits1(&gb));
2651 for (
i =
s->nqps;
i < 3;
i++)
2656 s->keyframe ?
"key" :
"", avctx->frame_number + 1,
s->qps[0]);
2658 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2662 if (
s->qps[0] !=
s->last_qps[0])
2665 for (
i = 0;
i <
s->nqps;
i++)
2668 if (
s->qps[
i] !=
s->last_qps[
i] ||
s->qps[0] !=
s->last_qps[0])
2676 s->current_frame.f->key_frame =
s->keyframe;
2680 if (!
s->edge_emu_buffer)
2681 s->edge_emu_buffer =
av_malloc(9 *
FFABS(
s->current_frame.f->linesize[0]));
2689 #if !CONFIG_VP4_DECODER
2696 if (avctx->frame_number == 0)
2698 "VP version: %d\n",
s->version);
2701 if (
s->version ||
s->theora) {
2704 "Warning, unsupported keyframe coding type?!\n");
2707 #if CONFIG_VP4_DECODER
2708 if (
s->version >= 2) {
2709 int mb_height, mb_width;
2710 int mb_width_mul, mb_width_div, mb_height_mul, mb_height_div;
2714 if (mb_height !=
s->macroblock_height ||
2715 mb_width !=
s->macroblock_width)
2722 if (mb_width_mul != 1 || mb_width_div != 1 || mb_height_mul != 1 || mb_height_div != 1)
2731 if (!
s->golden_frame.f->data[0]) {
2733 "vp3: first frame not a keyframe\n");
2741 &
s->golden_frame)) < 0)
2747 memset(
s->all_fragments, 0,
s->fragment_count *
sizeof(
Vp3Fragment));
2750 if (
s->version < 2) {
2755 #if CONFIG_VP4_DECODER
2757 if ((
ret = vp4_unpack_macroblocks(
s, &gb)) < 0) {
2776 if (
s->version < 2) {
2781 #if CONFIG_VP4_DECODER
2783 if ((
ret = vp4_unpack_dct_coeffs(
s, &gb)) < 0) {
2790 for (
i = 0;
i < 3;
i++) {
2791 int height =
s->height >> (
i &&
s->chroma_y_shift);
2792 if (
s->flipped_image)
2793 s->data_offset[
i] = 0;
2795 s->data_offset[
i] = (
height - 1) *
s->current_frame.f->linesize[
i];
2798 s->last_slice_end = 0;
2799 for (
i = 0;
i <
s->c_superblock_height;
i++)
2804 for (
i = 0;
i < 3;
i++) {
2805 int row = (
s->height >> (3 + (
i &&
s->chroma_y_shift))) - 1;
2814 frame->crop_left =
s->offset_x;
2815 frame->crop_right = avctx->coded_width - avctx->width -
s->offset_x;
2816 frame->crop_top =
s->offset_y;
2817 frame->crop_bottom = avctx->coded_height - avctx->height -
s->offset_y;
2848 ff_dlog(avctx,
"code length %d, curr entry %d, token %d\n",
2866 #if CONFIG_THEORA_DECODER
2874 int visible_width, visible_height, colorspace;
2875 uint8_t offset_x = 0, offset_y = 0;
2882 s->theora_header = 0;
2892 if (
s->theora < 0x030200) {
2893 s->flipped_image = 1;
2895 "Old (<alpha3) Theora bitstream, flipped image\n");
2903 if (
s->theora >= 0x030200) {
2913 visible_width + offset_x >
s->width ||
2914 visible_height + offset_y >
s->height) {
2916 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2917 visible_width, visible_height, offset_x, offset_y,
2918 s->width,
s->height);
2924 if (fps.
num && fps.
den) {
2925 if (fps.
num < 0 || fps.
den < 0) {
2930 fps.
den, fps.
num, 1 << 30);
2935 if (aspect.
num && aspect.
den) {
2938 aspect.
num, aspect.
den, 1 << 30);
2942 if (
s->theora < 0x030200)
2949 if (
s->theora >= 0x030200) {
2964 avctx->
width = visible_width;
2965 avctx->
height = visible_height;
2968 s->offset_x = offset_x;
2969 s->offset_y =
s->height - visible_height - offset_y;
2972 if (colorspace == 1)
2974 else if (colorspace == 2)
2977 if (colorspace == 1 || colorspace == 2) {
2982 s->theora_header = 1;
2989 int i, n, matrices, inter, plane,
ret;
2991 if (!
s->theora_header)
2994 if (
s->theora >= 0x030200) {
2998 for (
i = 0;
i < 64;
i++)
3002 if (
s->theora >= 0x030200)
3007 for (
i = 0;
i < 64;
i++)
3008 s->coded_ac_scale_factor[
i] =
get_bits(gb, n);
3010 if (
s->theora >= 0x030200)
3015 for (
i = 0;
i < 64;
i++)
3016 s->coded_dc_scale_factor[0][
i] =
3017 s->coded_dc_scale_factor[1][
i] =
get_bits(gb, n);
3019 if (
s->theora >= 0x030200)
3024 if (matrices > 384) {
3029 for (n = 0; n < matrices; n++)
3030 for (
i = 0;
i < 64;
i++)
3033 for (inter = 0; inter <= 1; inter++) {
3034 for (plane = 0; plane <= 2; plane++) {
3036 if (inter || plane > 0)
3044 qtj = (3 * inter + plane - 1) / 3;
3045 plj = (plane + 2) % 3;
3047 s->qr_count[inter][plane] =
s->qr_count[qtj][plj];
3048 memcpy(
s->qr_size[inter][plane],
s->qr_size[qtj][plj],
3049 sizeof(
s->qr_size[0][0]));
3050 memcpy(
s->qr_base[inter][plane],
s->qr_base[qtj][plj],
3051 sizeof(
s->qr_base[0][0]));
3058 if (
i >= matrices) {
3060 "invalid base matrix index\n");
3063 s->qr_base[inter][plane][qri] =
i;
3067 s->qr_size[inter][plane][qri++] =
i;
3075 s->qr_count[inter][plane] = qri;
3082 s->huffman_table[
i].nb_entries = 0;
3087 s->theora_tables = 1;
3097 const uint8_t *header_start[3];
3112 42, header_start, header_len) < 0) {
3117 for (
i = 0;
i < 3;
i++) {
3118 if (header_len[
i] <= 0)
3126 if (!(ptype & 0x80)) {
3149 "Unknown Theora config packet: %d\n", ptype & ~0x80);
3154 "%d bits left in packet %X\n",
3156 if (
s->theora < 0x030200)
3169 .
init = theora_decode_init,
3198 #if CONFIG_VP4_DECODER