33 #include "config_components.h"
56 #define VP3_MV_VLC_BITS 6
57 #define VP4_MV_VLC_BITS 6
58 #define SUPERBLOCK_VLC_BITS 6
60 #define FRAGMENT_PIXELS 8
69 #define SB_NOT_CODED 0
70 #define SB_PARTIALLY_CODED 1
71 #define SB_FULLY_CODED 2
76 #define MAXIMUM_LONG_BIT_RUN 4129
78 #define MODE_INTER_NO_MV 0
80 #define MODE_INTER_PLUS_MV 2
81 #define MODE_INTER_LAST_MV 3
82 #define MODE_INTER_PRIOR_LAST 4
83 #define MODE_USING_GOLDEN 5
84 #define MODE_GOLDEN_MV 6
85 #define MODE_INTER_FOURMV 7
86 #define CODING_MODE_COUNT 8
135 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
136 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
137 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
138 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
165 #define MIN_DEQUANT_VAL 2
259 #define TOKEN_EOB(eob_run) ((eob_run) << 2)
260 #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
261 #define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
338 if (
s->golden_frame.f)
342 if (
s->current_frame.f)
354 s->theora_tables = 0;
370 for (j = 0; j < 2; j++)
371 for (
i = 0;
i < 7;
i++)
374 for (
i = 0;
i < 2;
i++)
388 int sb_x, sb_y, plane;
391 for (plane = 0; plane < 3; plane++) {
392 int sb_width = plane ?
s->c_superblock_width
393 :
s->y_superblock_width;
394 int sb_height = plane ?
s->c_superblock_height
395 :
s->y_superblock_height;
396 int frag_width =
s->fragment_width[!!plane];
397 int frag_height =
s->fragment_height[!!plane];
399 for (sb_y = 0; sb_y < sb_height; sb_y++)
400 for (sb_x = 0; sb_x < sb_width; sb_x++)
401 for (
i = 0;
i < 16;
i++) {
405 if (x < frag_width && y < frag_height)
406 s->superblock_fragments[j++] =
s->fragment_start[plane] +
409 s->superblock_fragments[j++] = -1;
422 int ac_scale_factor =
s->coded_ac_scale_factor[
s->qps[qpi]];
423 int i, plane, inter, qri, bmi, bmj, qistart;
425 for (inter = 0; inter < 2; inter++) {
426 for (plane = 0; plane < 3; plane++) {
427 int dc_scale_factor =
s->coded_dc_scale_factor[!!plane][
s->qps[qpi]];
429 for (qri = 0; qri <
s->qr_count[inter][plane]; qri++) {
430 sum +=
s->qr_size[inter][plane][qri];
431 if (
s->qps[qpi] <= sum)
434 qistart = sum -
s->qr_size[inter][plane][qri];
435 bmi =
s->qr_base[inter][plane][qri];
436 bmj =
s->qr_base[inter][plane][qri + 1];
437 for (
i = 0;
i < 64;
i++) {
438 int coeff = (2 * (sum -
s->qps[qpi]) *
s->base_matrix[bmi][
i] -
439 2 * (qistart -
s->qps[qpi]) *
s->base_matrix[bmj][
i] +
440 s->qr_size[inter][plane][qri]) /
441 (2 *
s->qr_size[inter][plane][qri]);
443 int qmin = 8 << (inter + !
i);
444 int qscale =
i ? ac_scale_factor : dc_scale_factor;
445 int qbias = (1 + inter) * 3;
446 s->qmat[qpi][inter][plane][
s->idct_permutation[
i]] =
447 (
i == 0 ||
s->version < 2) ?
av_clip((qscale *
coeff) / 100 * 4, qmin, 4096)
448 : (qscale * (
coeff - qbias) / 100 + qbias) * 4;
452 s->qmat[qpi][inter][plane][0] =
s->qmat[0][inter][plane][0];
474 int superblock_starts[3] = {
475 0,
s->u_superblock_start,
s->v_superblock_start
478 int current_superblock = 0;
480 int num_partial_superblocks = 0;
483 int current_fragment;
485 int plane0_num_coded_frags = 0;
494 while (current_superblock < s->superblock_count &&
get_bits_left(gb) > 0) {
500 current_run =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
502 if (current_run == 34)
505 if (current_run >
s->superblock_count - current_superblock) {
507 "Invalid partially coded superblock run length\n");
511 memset(
s->superblock_coding + current_superblock,
bit, current_run);
513 current_superblock += current_run;
515 num_partial_superblocks += current_run;
520 if (num_partial_superblocks < s->superblock_count) {
521 int superblocks_decoded = 0;
523 current_superblock = 0;
527 while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
534 current_run =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
536 if (current_run == 34)
539 for (j = 0; j < current_run; current_superblock++) {
540 if (current_superblock >=
s->superblock_count) {
542 "Invalid fully coded superblock run length\n");
547 if (
s->superblock_coding[current_superblock] ==
SB_NOT_CODED) {
548 s->superblock_coding[current_superblock] = 2 *
bit;
552 superblocks_decoded += current_run;
558 if (num_partial_superblocks) {
569 s->total_num_coded_frags = 0;
570 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
572 s->coded_fragment_list[0] =
s->keyframe ?
s->kf_coded_fragment_list
573 :
s->nkf_coded_fragment_list;
575 for (plane = 0; plane < 3; plane++) {
576 int sb_start = superblock_starts[plane];
577 int sb_end = sb_start + (plane ?
s->c_superblock_count
578 :
s->y_superblock_count);
579 int num_coded_frags = 0;
582 if (
s->num_kf_coded_fragment[plane] == -1) {
583 for (
i = sb_start;
i < sb_end;
i++) {
585 for (j = 0; j < 16; j++) {
587 current_fragment =
s->superblock_fragments[
i * 16 + j];
588 if (current_fragment != -1) {
589 s->coded_fragment_list[plane][num_coded_frags++] =
594 s->num_kf_coded_fragment[plane] = num_coded_frags;
596 num_coded_frags =
s->num_kf_coded_fragment[plane];
603 for (j = 0; j < 16; j++) {
605 current_fragment =
s->superblock_fragments[
i * 16 + j];
606 if (current_fragment != -1) {
607 int coded =
s->superblock_coding[
i];
612 if (current_run-- == 0) {
614 current_run =
get_vlc2(gb,
s->fragment_run_length_vlc.table, 5, 2);
622 s->all_fragments[current_fragment].coding_method =
624 s->coded_fragment_list[plane][num_coded_frags++] =
628 s->all_fragments[current_fragment].coding_method =
636 plane0_num_coded_frags = num_coded_frags;
637 s->total_num_coded_frags += num_coded_frags;
638 for (
i = 0;
i < 64;
i++)
639 s->num_coded_frags[plane][
i] = num_coded_frags;
641 s->coded_fragment_list[plane + 1] =
s->coded_fragment_list[plane] +
647 #define BLOCK_X (2 * mb_x + (k & 1))
648 #define BLOCK_Y (2 * mb_y + (k >> 1))
650 #if CONFIG_VP4_DECODER
662 if (v >
s->yuv_macroblock_count) {
668 skip_bits(gb, 2 + n); \
669 v += (1 << n) + get_bits(gb, n); }
670 #define thresh(n) (0x200 - (0x80 >> n))
671 #define else_if(n) else if (bits < thresh(n)) body(n)
674 }
else if (
bits < thresh(0)) {
693 int v =
get_vlc2(gb,
s->block_pattern_vlc[*next_block_pattern_table].table, 3, 2);
701 int next_block_pattern_table;
702 int bit, current_run, has_partial;
704 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
711 for (
i = 0;
i <
s->yuv_macroblock_count;
i += current_run) {
714 current_run = vp4_get_mb_count(
s, gb);
715 if (current_run >
s->yuv_macroblock_count -
i)
717 memset(
s->superblock_coding +
i, 2 *
bit, current_run);
726 current_run = vp4_get_mb_count(
s, gb);
727 for (
i = 0;
i <
s->yuv_macroblock_count;
i++) {
728 if (!
s->superblock_coding[
i]) {
731 current_run = vp4_get_mb_count(
s, gb);
733 s->superblock_coding[
i] =
bit;
741 next_block_pattern_table = 0;
743 for (plane = 0; plane < 3; plane++) {
745 int sb_width = plane ?
s->c_superblock_width :
s->y_superblock_width;
746 int sb_height = plane ?
s->c_superblock_height :
s->y_superblock_height;
747 int mb_width = plane ?
s->c_macroblock_width :
s->macroblock_width;
748 int mb_height = plane ?
s->c_macroblock_height :
s->macroblock_height;
749 int fragment_width =
s->fragment_width[!!plane];
750 int fragment_height =
s->fragment_height[!!plane];
752 for (sb_y = 0; sb_y < sb_height; sb_y++) {
753 for (sb_x = 0; sb_x < sb_width; sb_x++) {
754 for (j = 0; j < 4; j++) {
755 int mb_x = 2 * sb_x + (j >> 1);
756 int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
757 int mb_coded, pattern, coded;
759 if (mb_x >= mb_width || mb_y >= mb_height)
762 mb_coded =
s->superblock_coding[
i++];
767 pattern = vp4_get_block_pattern(
s, gb, &next_block_pattern_table);
771 for (k = 0; k < 4; k++) {
775 coded = pattern & (8 >> k);
794 int i, j, k, sb_x, sb_y;
796 int current_macroblock;
797 int current_fragment;
804 for (
i = 0;
i <
s->fragment_count;
i++)
812 for (
i = 0;
i < 8;
i++)
814 for (
i = 0;
i < 8;
i++)
815 custom_mode_alphabet[
get_bits(gb, 3)] =
i;
816 alphabet = custom_mode_alphabet;
822 for (sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
823 for (sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
827 for (j = 0; j < 4; j++) {
828 int mb_x = 2 * sb_x + (j >> 1);
829 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
830 current_macroblock = mb_y *
s->macroblock_width + mb_x;
832 if (mb_x >=
s->macroblock_width ||
833 mb_y >=
s->macroblock_height)
839 for (k = 0; k < 4; k++) {
842 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY)
854 coding_mode = alphabet[
get_vlc2(gb,
s->mode_code_vlc.table, 3, 3)];
856 s->macroblock_coding[current_macroblock] = coding_mode;
857 for (k = 0; k < 4; k++) {
863 #define SET_CHROMA_MODES \
864 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
865 frag[s->fragment_start[1]].coding_method = coding_mode; \
866 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
867 frag[s->fragment_start[2]].coding_method = coding_mode;
869 if (
s->chroma_y_shift) {
870 frag =
s->all_fragments + mb_y *
871 s->fragment_width[1] + mb_x;
873 }
else if (
s->chroma_x_shift) {
874 frag =
s->all_fragments +
875 2 * mb_y *
s->fragment_width[1] + mb_x;
876 for (k = 0; k < 2; k++) {
878 frag +=
s->fragment_width[1];
881 for (k = 0; k < 4; k++) {
882 frag =
s->all_fragments +
899 return last_motion < 0 ? -v : v;
908 int j, k, sb_x, sb_y;
912 int last_motion_x = 0;
913 int last_motion_y = 0;
914 int prior_last_motion_x = 0;
915 int prior_last_motion_y = 0;
916 int last_gold_motion_x = 0;
917 int last_gold_motion_y = 0;
918 int current_macroblock;
919 int current_fragment;
926 coding_mode =
s->version < 2 ?
get_bits1(gb) : 2;
930 for (sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
931 for (sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
935 for (j = 0; j < 4; j++) {
936 int mb_x = 2 * sb_x + (j >> 1);
937 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
938 current_macroblock = mb_y *
s->macroblock_width + mb_x;
940 if (mb_x >=
s->macroblock_width ||
941 mb_y >=
s->macroblock_height ||
942 s->macroblock_coding[current_macroblock] ==
MODE_COPY)
945 switch (
s->macroblock_coding[current_macroblock]) {
947 if (coding_mode == 2) {
948 last_gold_motion_x = motion_x[0] =
vp4_get_mv(
s, gb, 0, last_gold_motion_x);
949 last_gold_motion_y = motion_y[0] =
vp4_get_mv(
s, gb, 1, last_gold_motion_y);
954 if (coding_mode == 0) {
955 motion_x[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
957 motion_y[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
959 }
else if (coding_mode == 1) {
969 prior_last_motion_x = last_motion_x;
970 prior_last_motion_y = last_motion_y;
971 last_motion_x = motion_x[0];
972 last_motion_y = motion_y[0];
978 prior_last_motion_x = last_motion_x;
979 prior_last_motion_y = last_motion_y;
983 for (k = 0; k < 4; k++) {
985 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY) {
986 if (coding_mode == 0) {
987 motion_x[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
989 motion_y[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
991 }
else if (coding_mode == 1) {
995 motion_x[k] =
vp4_get_mv(
s, gb, 0, prior_last_motion_x);
996 motion_y[k] =
vp4_get_mv(
s, gb, 1, prior_last_motion_y);
998 last_motion_x = motion_x[k];
999 last_motion_y = motion_y[k];
1009 motion_x[0] = last_motion_x;
1010 motion_y[0] = last_motion_y;
1019 motion_x[0] = prior_last_motion_x;
1020 motion_y[0] = prior_last_motion_y;
1023 prior_last_motion_x = last_motion_x;
1024 prior_last_motion_y = last_motion_y;
1025 last_motion_x = motion_x[0];
1026 last_motion_y = motion_y[0];
1039 for (k = 0; k < 4; k++) {
1043 s->motion_val[0][current_fragment][0] = motion_x[k];
1044 s->motion_val[0][current_fragment][1] = motion_y[k];
1046 s->motion_val[0][current_fragment][0] = motion_x[0];
1047 s->motion_val[0][current_fragment][1] = motion_y[0];
1051 if (
s->chroma_y_shift) {
1053 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] +
1054 motion_x[2] + motion_x[3], 2);
1055 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] +
1056 motion_y[2] + motion_y[3], 2);
1058 if (
s->version <= 2) {
1059 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1060 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
1062 frag = mb_y *
s->fragment_width[1] + mb_x;
1063 s->motion_val[1][frag][0] = motion_x[0];
1064 s->motion_val[1][frag][1] = motion_y[0];
1065 }
else if (
s->chroma_x_shift) {
1067 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
1068 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
1069 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
1070 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
1072 motion_x[1] = motion_x[0];
1073 motion_y[1] = motion_y[0];
1075 if (
s->version <= 2) {
1076 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1077 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
1079 frag = 2 * mb_y *
s->fragment_width[1] + mb_x;
1080 for (k = 0; k < 2; k++) {
1081 s->motion_val[1][frag][0] = motion_x[k];
1082 s->motion_val[1][frag][1] = motion_y[k];
1083 frag +=
s->fragment_width[1];
1086 for (k = 0; k < 4; k++) {
1089 s->motion_val[1][frag][0] = motion_x[k];
1090 s->motion_val[1][frag][1] = motion_y[k];
1092 s->motion_val[1][frag][0] = motion_x[0];
1093 s->motion_val[1][frag][1] = motion_y[0];
1106 int qpi,
i, j,
bit, run_length, blocks_decoded, num_blocks_at_qpi;
1107 int num_blocks =
s->total_num_coded_frags;
1109 for (qpi = 0; qpi <
s->nqps - 1 && num_blocks > 0; qpi++) {
1110 i = blocks_decoded = num_blocks_at_qpi = 0;
1121 run_length =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
1123 if (run_length == 34)
1125 blocks_decoded += run_length;
1128 num_blocks_at_qpi += run_length;
1130 for (j = 0; j < run_length;
i++) {
1131 if (
i >=
s->total_num_coded_frags)
1134 if (
s->all_fragments[
s->coded_fragment_list[0][
i]].qpi == qpi) {
1135 s->all_fragments[
s->coded_fragment_list[0][
i]].qpi +=
bit;
1139 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
1141 num_blocks -= num_blocks_at_qpi;
1157 int bits_to_get, zero_run;
1161 bits_to_get =
get_bits(gb, bits_to_get);
1194 int num_coeffs =
s->num_coded_frags[plane][coeff_index];
1195 int16_t *dct_tokens =
s->dct_tokens[plane][coeff_index];
1198 int *coded_fragment_list =
s->coded_fragment_list[plane];
1202 if (num_coeffs < 0) {
1204 "Invalid number of coefficients at level %d\n", coeff_index);
1208 if (eob_run > num_coeffs) {
1210 blocks_ended = num_coeffs;
1211 eob_run -= num_coeffs;
1214 blocks_ended = eob_run;
1220 dct_tokens[j++] = blocks_ended << 2;
1224 token =
get_vlc2(gb, vlc_table, 11, 3);
1226 if ((
unsigned) token <= 6
U) {
1233 if (eob_run > num_coeffs - coeff_i) {
1234 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
1235 blocks_ended += num_coeffs - coeff_i;
1236 eob_run -= num_coeffs - coeff_i;
1237 coeff_i = num_coeffs;
1240 blocks_ended += eob_run;
1244 }
else if (token >= 0) {
1255 all_fragments[coded_fragment_list[coeff_i]].
dc =
coeff;
1260 if (coeff_index + zero_run > 64) {
1262 "Invalid zero run of %d with %d coeffs left\n",
1263 zero_run, 64 - coeff_index);
1264 zero_run = 64 - coeff_index;
1269 for (
i = coeff_index + 1;
i <= coeff_index + zero_run;
i++)
1270 s->num_coded_frags[plane][
i]--;
1278 if (blocks_ended >
s->num_coded_frags[plane][coeff_index])
1284 for (
i = coeff_index + 1;
i < 64;
i++)
1285 s->num_coded_frags[plane][
i] -= blocks_ended;
1289 s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1290 else if (coeff_index < 63)
1291 s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1299 int fragment_height);
1311 int residual_eob_run = 0;
1315 s->dct_tokens[0][0] =
s->dct_tokens_base;
1325 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_y_table], 0,
1326 0, residual_eob_run);
1327 if (residual_eob_run < 0)
1328 return residual_eob_run;
1336 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1337 1, residual_eob_run);
1338 if (residual_eob_run < 0)
1339 return residual_eob_run;
1340 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1341 2, residual_eob_run);
1342 if (residual_eob_run < 0)
1343 return residual_eob_run;
1348 s->fragment_width[1],
s->fragment_height[1]);
1350 s->fragment_width[1],
s->fragment_height[1]);
1360 for (
i = 1;
i <= 5;
i++) {
1362 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 16];
1363 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 16];
1365 for (
i = 6;
i <= 14;
i++) {
1367 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 32];
1368 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 32];
1370 for (
i = 15;
i <= 27;
i++) {
1372 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 48];
1373 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 48];
1375 for (
i = 28;
i <= 63;
i++) {
1377 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 64];
1378 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 64];
1382 for (
i = 1;
i <= 63;
i++) {
1384 0, residual_eob_run);
1385 if (residual_eob_run < 0)
1386 return residual_eob_run;
1389 1, residual_eob_run);
1390 if (residual_eob_run < 0)
1391 return residual_eob_run;
1393 2, residual_eob_run);
1394 if (residual_eob_run < 0)
1395 return residual_eob_run;
1401 #if CONFIG_VP4_DECODER
1410 int plane,
int eob_tracker[64],
int fragment)
1418 while (!eob_tracker[coeff_i]) {
1425 if ((
unsigned) token <= 6
U) {
1427 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1428 eob_tracker[coeff_i] = eob_run - 1;
1430 }
else if (token >= 0) {
1434 if (coeff_i + zero_run > 64) {
1436 "Invalid zero run of %d with %d coeffs left\n",
1437 zero_run, 64 - coeff_i);
1438 zero_run = 64 - coeff_i;
1441 coeff_i += zero_run;
1456 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1457 eob_tracker[coeff_i]--;
1471 for (
i = 0;
i < 4;
i++)
1472 dc_pred[0][
i + 1] =
s->dc_pred_row[sb_x * 4 +
i];
1474 for (j = 1; j < 5; j++)
1475 for (
i = 0;
i < 4;
i++)
1476 vp4_dc_predictor_reset(&dc_pred[j][
i + 1]);
1483 for (
i = 0;
i < 4;
i++)
1484 s->dc_pred_row[sb_x * 4 +
i] = dc_pred[4][
i + 1];
1487 dc_pred[
i][0] = dc_pred[
i][4];
1497 dc += dc_pred[-6].
dc;
1502 dc += dc_pred[6].
dc;
1506 if (count != 2 && dc_pred[-1].
type ==
type) {
1507 dc += dc_pred[-1].
dc;
1511 if (count != 2 && dc_pred[1].
type ==
type) {
1512 dc += dc_pred[1].
dc;
1517 return count == 2 ?
dc / 2 : last_dc[
type];
1523 int16_t *
base =
s->dct_tokens_base;
1524 for (plane = 0; plane < 3; plane++) {
1525 for (
i = 0;
i < 64;
i++) {
1526 s->dct_tokens[plane][
i] =
base;
1527 base +=
s->fragment_width[!!plane] *
s->fragment_height[!!plane];
1540 int plane, sb_y, sb_x;
1541 int eob_tracker[64];
1558 tables[0][0] = &
s->coeff_vlc[dc_y_table];
1559 tables[1][0] = &
s->coeff_vlc[dc_c_table];
1560 for (
i = 1;
i <= 5;
i++) {
1562 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 16];
1563 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 16];
1565 for (
i = 6;
i <= 14;
i++) {
1567 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 32];
1568 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 32];
1570 for (
i = 15;
i <= 27;
i++) {
1572 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 48];
1573 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 48];
1575 for (
i = 28;
i <= 63;
i++) {
1577 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 64];
1578 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 64];
1581 vp4_set_tokens_base(
s);
1583 memset(last_dc, 0,
sizeof(last_dc));
1586 memset(eob_tracker, 0,
sizeof(eob_tracker));
1589 for (
i = 0;
i <
s->fragment_width[!!plane];
i++)
1590 vp4_dc_predictor_reset(&
s->dc_pred_row[
i]);
1592 for (j = 0; j < 6; j++)
1593 for (
i = 0;
i < 6;
i++)
1594 vp4_dc_predictor_reset(&dc_pred[j][
i]);
1596 for (sb_y = 0; sb_y * 4 <
s->fragment_height[!!plane]; sb_y++) {
1597 for (sb_x = 0; sb_x *4 <
s->fragment_width[!!plane]; sb_x++) {
1598 vp4_dc_pred_before(
s, dc_pred, sb_x);
1599 for (j = 0; j < 16; j++) {
1602 int x = 4 * sb_x + hx;
1603 int y = 4 * sb_y + hy;
1607 if (x >=
s->fragment_width[!!plane] || y >=
s->fragment_height[!!plane])
1610 fragment =
s->fragment_start[plane] + y *
s->fragment_width[!!plane] + x;
1615 if (vp4_unpack_vlcs(
s, gb,
tables[!!plane], plane, eob_tracker,
fragment) < 0)
1621 vp4_dc_pred(
s, this_dc_pred, last_dc, dc_block_type, plane);
1623 this_dc_pred->
type = dc_block_type,
1624 this_dc_pred->
dc = last_dc[dc_block_type] =
s->all_fragments[
fragment].dc;
1626 vp4_dc_pred_after(
s, dc_pred, sb_x);
1631 vp4_set_tokens_base(
s);
1642 #define COMPATIBLE_FRAME(x) \
1643 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1644 #define DC_COEFF(u) s->all_fragments[u].dc
1649 int fragment_height)
1657 int i = first_fragment;
1662 int vl, vul, vu, vur;
1674 static const int predictor_transform[16][4] = {
1688 { -104, 116, 0, 116 },
1690 { -104, 116, 0, 116 }
1699 static const unsigned char compatible_frame[9] = {
1710 int current_frame_type;
1726 for (y = 0; y < fragment_height; y++) {
1728 for (x = 0; x < fragment_width; x++,
i++) {
1731 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
1732 current_frame_type =
1733 compatible_frame[
s->all_fragments[
i].coding_method];
1743 u =
i - fragment_width;
1748 ul =
i - fragment_width - 1;
1753 if (x + 1 < fragment_width) {
1754 ur =
i - fragment_width + 1;
1764 predicted_dc = last_dc[current_frame_type];
1768 (predictor_transform[
transform][0] * vul) +
1769 (predictor_transform[
transform][1] * vu) +
1770 (predictor_transform[
transform][2] * vur) +
1771 (predictor_transform[
transform][3] * vl);
1773 predicted_dc /= 128;
1778 if (
FFABS(predicted_dc - vu) > 128)
1780 else if (
FFABS(predicted_dc - vl) > 128)
1782 else if (
FFABS(predicted_dc - vul) > 128)
1790 last_dc[current_frame_type] =
DC_COEFF(
i);
1797 int ystart,
int yend)
1800 int *bounding_values =
s->bounding_values_array + 127;
1802 int width =
s->fragment_width[!!plane];
1803 int height =
s->fragment_height[!!plane];
1805 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
1806 uint8_t *plane_data =
s->current_frame.f->data[plane];
1807 if (!
s->flipped_image)
1809 plane_data +=
s->data_offset[plane] + 8 * ystart *
stride;
1811 for (y = ystart; y < yend; y++) {
1812 for (x = 0; x <
width; x++) {
1820 s->vp3dsp.h_loop_filter(
1822 stride, bounding_values);
1827 s->vp3dsp.v_loop_filter(
1829 stride, bounding_values);
1835 if ((x <
width - 1) &&
1837 s->vp3dsp.h_loop_filter(
1838 plane_data + 8 * x + 8,
1839 stride, bounding_values);
1847 s->vp3dsp.v_loop_filter(
1848 plane_data + 8 * x + 8 *
stride,
1849 stride, bounding_values);
1855 plane_data += 8 *
stride;
1864 int plane,
int inter, int16_t
block[64])
1866 int16_t *dequantizer =
s->qmat[frag->
qpi][inter][plane];
1867 uint8_t *
perm =
s->idct_scantable;
1871 int token = *
s->dct_tokens[plane][
i];
1872 switch (token & 3) {
1875 s->dct_tokens[plane][
i]++;
1877 *
s->dct_tokens[plane][
i] = token & ~3;
1880 s->dct_tokens[plane][
i]++;
1881 i += (token >> 2) & 0x7f;
1891 s->dct_tokens[plane][
i++]++;
1901 block[0] = frag->
dc *
s->qmat[0][inter][plane][0];
1914 int y_flipped =
s->flipped_image ?
s->height - y : y;
1920 y_flipped ==
s->height ? INT_MAX
1925 if (!
s->avctx->draw_horiz_band)
1928 h = y -
s->last_slice_end;
1929 s->last_slice_end = y;
1932 if (!
s->flipped_image)
1933 y =
s->height - y -
h;
1935 cy = y >>
s->chroma_y_shift;
1936 offset[0] =
s->current_frame.f->linesize[0] * y;
1937 offset[1] =
s->current_frame.f->linesize[1] * cy;
1938 offset[2] =
s->current_frame.f->linesize[2] * cy;
1943 s->avctx->draw_horiz_band(
s->avctx,
s->current_frame.f,
offset, y, 3,
h);
1951 int motion_y,
int y)
1955 int border = motion_y & 1;
1959 ref_frame = &
s->golden_frame;
1961 ref_frame = &
s->last_frame;
1963 ref_row = y + (motion_y >> 1);
1964 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1969 #if CONFIG_VP4_DECODER
1973 static int vp4_mc_loop_filter(
Vp3DecodeContext *
s,
int plane,
int motion_x,
int motion_y,
int bx,
int by,
1974 uint8_t * motion_source,
int stride,
int src_x,
int src_y, uint8_t *
temp)
1976 int motion_shift = plane ? 4 : 2;
1977 int subpel_mask = plane ? 3 : 1;
1978 int *bounding_values =
s->bounding_values_array + 127;
1983 int x_subpel, y_subpel;
1984 int x_offset, y_offset;
1986 int block_width = plane ? 8 : 16;
1987 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
1988 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
1990 #define loop_stride 12
1991 uint8_t
loop[12 * loop_stride];
1994 x = 8 * bx + motion_x / motion_shift;
1995 y = 8 * by + motion_y / motion_shift;
1997 x_subpel = motion_x & subpel_mask;
1998 y_subpel = motion_y & subpel_mask;
2000 if (x_subpel || y_subpel) {
2010 x2 = x + block_width;
2011 y2 = y + block_width;
2013 if (x2 < 0 || x2 >= plane_width || y2 < 0 || y2 >= plane_height)
2016 x_offset = (-(x + 2) & 7) + 2;
2017 y_offset = (-(y + 2) & 7) + 2;
2019 if (x_offset > 8 + x_subpel && y_offset > 8 + y_subpel)
2022 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2024 12, 12, src_x - 1, src_y - 1,
2028 if (x_offset <= 8 + x_subpel)
2031 if (y_offset <= 8 + y_subpel)
2039 if (!x_offset && !y_offset)
2042 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2044 12, 12, src_x - 1, src_y - 1,
2048 #define safe_loop_filter(name, ptr, stride, bounding_values) \
2049 if ((uintptr_t)(ptr) & 7) \
2050 s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \
2052 s->vp3dsp.name(ptr, stride, bounding_values);
2055 safe_loop_filter(h_loop_filter,
loop + loop_stride + x_offset + 1, loop_stride, bounding_values);
2058 safe_loop_filter(v_loop_filter,
loop + (y_offset + 1)*loop_stride + 1, loop_stride, bounding_values);
2061 for (
i = 0;
i < 9;
i++)
2075 int16_t *
block =
s->block;
2076 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
2077 int motion_halfpel_index;
2078 uint8_t *motion_source;
2079 int plane, first_pixel;
2081 if (slice >=
s->c_superblock_height)
2084 for (plane = 0; plane < 3; plane++) {
2086 s->data_offset[plane];
2087 uint8_t *last_plane =
s->last_frame.f->data[plane] +
2088 s->data_offset[plane];
2089 uint8_t *golden_plane =
s->golden_frame.f->data[plane] +
2090 s->data_offset[plane];
2091 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
2092 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
2093 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
2094 int8_t(*motion_val)[2] =
s->motion_val[!!plane];
2096 int sb_x, sb_y = slice << (!plane &&
s->chroma_y_shift);
2097 int slice_height = sb_y + 1 + (!plane &&
s->chroma_y_shift);
2098 int slice_width = plane ?
s->c_superblock_width
2099 :
s->y_superblock_width;
2101 int fragment_width =
s->fragment_width[!!plane];
2102 int fragment_height =
s->fragment_height[!!plane];
2103 int fragment_start =
s->fragment_start[plane];
2105 int do_await = !plane && HAVE_THREADS &&
2108 if (!
s->flipped_image)
2114 for (; sb_y < slice_height; sb_y++) {
2116 for (sb_x = 0; sb_x < slice_width; sb_x++) {
2118 for (j = 0; j < 16; j++) {
2126 if (x >= fragment_width || y >= fragment_height)
2129 first_pixel = 8 * y *
stride + 8 * x;
2135 (16 * y) >>
s->chroma_y_shift);
2138 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
2141 motion_source = golden_plane;
2143 motion_source = last_plane;
2145 motion_source += first_pixel;
2146 motion_halfpel_index = 0;
2150 if ((
s->all_fragments[
i].coding_method >
MODE_INTRA) &&
2153 int standard_mc = 1;
2154 motion_x = motion_val[
fragment][0];
2155 motion_y = motion_val[
fragment][1];
2156 #if CONFIG_VP4_DECODER
2157 if (plane &&
s->version >= 2) {
2158 motion_x = (motion_x >> 1) | (motion_x & 1);
2159 motion_y = (motion_y >> 1) | (motion_y & 1);
2163 src_x = (motion_x >> 1) + 8 * x;
2164 src_y = (motion_y >> 1) + 8 * y;
2166 motion_halfpel_index = motion_x & 0x01;
2167 motion_source += (motion_x >> 1);
2169 motion_halfpel_index |= (motion_y & 0x01) << 1;
2170 motion_source += ((motion_y >> 1) *
stride);
2172 #if CONFIG_VP4_DECODER
2173 if (
s->version >= 2) {
2174 uint8_t *
temp =
s->edge_emu_buffer;
2177 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)) {
2178 motion_source =
temp;
2184 if (standard_mc && (
2185 src_x < 0 || src_y < 0 ||
2186 src_x + 9 >= plane_width ||
2187 src_y + 9 >= plane_height)) {
2188 uint8_t *
temp =
s->edge_emu_buffer;
2192 s->vdsp.emulated_edge_mc(
temp, motion_source,
2197 motion_source =
temp;
2208 if (motion_halfpel_index != 3) {
2209 s->hdsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
2211 motion_source,
stride, 8);
2215 int d = (motion_x ^ motion_y) >> 31;
2218 motion_source +
stride + 1 +
d,
2244 s->hdsp.put_pixels_tab[1][0](
2246 last_plane + first_pixel,
2253 if (
s->version < 2 && !
s->skip_loop_filter)
2255 FFMIN(4 * sb_y + 3, fragment_height - 1));
2275 int y_fragment_count, c_fragment_count;
2279 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2280 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2283 s->superblock_coding =
av_mallocz(
FFMAX(
s->superblock_count,
s->yuv_macroblock_count));
2284 s->all_fragments =
av_calloc(
s->fragment_count,
sizeof(*
s->all_fragments));
2286 s-> kf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2287 s->nkf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2288 memset(
s-> num_kf_coded_fragment, -1,
sizeof(
s-> num_kf_coded_fragment));
2291 64 *
sizeof(*
s->dct_tokens_base));
2292 s->motion_val[0] =
av_calloc(y_fragment_count,
sizeof(*
s->motion_val[0]));
2293 s->motion_val[1] =
av_calloc(c_fragment_count,
sizeof(*
s->motion_val[1]));
2296 s->superblock_fragments =
av_calloc(
s->superblock_count, 16 *
sizeof(
int));
2297 s->macroblock_coding =
av_mallocz(
s->macroblock_count + 1);
2299 s->dc_pred_row =
av_malloc_array(
s->y_superblock_width * 4,
sizeof(*
s->dc_pred_row));
2301 if (!
s->superblock_coding || !
s->all_fragments ||
2302 !
s->dct_tokens_base || !
s->kf_coded_fragment_list ||
2303 !
s->nkf_coded_fragment_list ||
2304 !
s->superblock_fragments || !
s->macroblock_coding ||
2306 !
s->motion_val[0] || !
s->motion_val[1]) {
2321 if (!
s->current_frame.f || !
s->last_frame.f || !
s->golden_frame.f)
2330 int i, inter, plane,
ret;
2333 int y_fragment_count, c_fragment_count;
2334 #if CONFIG_VP4_DECODER
2344 #if !CONFIG_VP4_DECODER
2363 for (
i = 0;
i < 64;
i++) {
2364 #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
2372 for (
i = 0;
i < 3;
i++)
2379 s->y_superblock_width = (
s->width + 31) / 32;
2380 s->y_superblock_height = (
s->height + 31) / 32;
2381 s->y_superblock_count =
s->y_superblock_width *
s->y_superblock_height;
2384 c_width =
s->width >>
s->chroma_x_shift;
2385 c_height =
s->height >>
s->chroma_y_shift;
2386 s->c_superblock_width = (c_width + 31) / 32;
2387 s->c_superblock_height = (c_height + 31) / 32;
2388 s->c_superblock_count =
s->c_superblock_width *
s->c_superblock_height;
2390 s->superblock_count =
s->y_superblock_count + (
s->c_superblock_count * 2);
2391 s->u_superblock_start =
s->y_superblock_count;
2392 s->v_superblock_start =
s->u_superblock_start +
s->c_superblock_count;
2394 s->macroblock_width = (
s->width + 15) / 16;
2395 s->macroblock_height = (
s->height + 15) / 16;
2396 s->macroblock_count =
s->macroblock_width *
s->macroblock_height;
2397 s->c_macroblock_width = (c_width + 15) / 16;
2398 s->c_macroblock_height = (c_height + 15) / 16;
2399 s->c_macroblock_count =
s->c_macroblock_width *
s->c_macroblock_height;
2400 s->yuv_macroblock_count =
s->macroblock_count + 2 *
s->c_macroblock_count;
2404 s->fragment_width[1] =
s->fragment_width[0] >>
s->chroma_x_shift;
2405 s->fragment_height[1] =
s->fragment_height[0] >>
s->chroma_y_shift;
2408 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2409 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2410 s->fragment_count = y_fragment_count + 2 * c_fragment_count;
2411 s->fragment_start[1] = y_fragment_count;
2412 s->fragment_start[2] = y_fragment_count + c_fragment_count;
2414 if (!
s->theora_tables) {
2415 const uint8_t (*bias_tabs)[32][2];
2417 for (
i = 0;
i < 64;
i++) {
2427 for (inter = 0; inter < 2; inter++) {
2428 for (plane = 0; plane < 3; plane++) {
2429 s->qr_count[inter][plane] = 1;
2430 s->qr_size[inter][plane][0] = 63;
2431 s->qr_base[inter][plane][0] =
2432 s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
2440 &bias_tabs[
i][0][1], 2,
2441 &bias_tabs[
i][0][0], 2, 1,
2451 &
tab->entries[0].len,
sizeof(*
tab->entries),
2452 &
tab->entries[0].sym,
sizeof(*
tab->entries), 1,
2461 NULL, 0, 0, 1, 0, avctx);
2467 NULL, 0, 0, 0, 0, avctx);
2473 NULL, 0, 0, 0, 0, avctx);
2484 #if CONFIG_VP4_DECODER
2485 for (j = 0; j < 2; j++)
2486 for (
i = 0;
i < 7;
i++) {
2496 for (
i = 0;
i < 2;
i++)
2532 if (
src->f->data[0])
2550 int qps_changed = 0,
i, err;
2552 if (!
s1->current_frame.f->data[0] ||
2553 s->width !=
s1->width ||
s->height !=
s1->height) {
2561 if ((err = ref_frames(
s,
s1)) < 0)
2564 s->keyframe =
s1->keyframe;
2567 for (
i = 0;
i < 3;
i++) {
2568 if (
s->qps[
i] !=
s1->qps[1]) {
2570 memcpy(&
s->qmat[
i], &
s1->qmat[
i],
sizeof(
s->qmat[
i]));
2574 if (
s->qps[0] !=
s1->qps[0])
2575 memcpy(&
s->bounding_values_array, &
s1->bounding_values_array,
2576 sizeof(
s->bounding_values_array));
2579 memcpy(
s->qps,
s1->qps,
sizeof(
s->qps));
2580 memcpy(
s->last_qps,
s1->last_qps,
sizeof(
s->last_qps));
2592 const uint8_t *buf = avpkt->
data;
2593 int buf_size = avpkt->
size;
2601 #if CONFIG_THEORA_DECODER
2607 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2621 }
else if (
type == 2) {
2634 "Header packet passed to frame decoder, skipping\n");
2640 if (!
s->all_fragments) {
2646 for (
i = 0;
i < 3;
i++)
2647 s->last_qps[
i] =
s->qps[
i];
2652 }
while (
s->theora >= 0x030200 &&
s->nqps < 3 &&
get_bits1(&gb));
2653 for (
i =
s->nqps;
i < 3;
i++)
2658 s->keyframe ?
"key" :
"", avctx->frame_number + 1,
s->qps[0]);
2660 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2664 if (
s->qps[0] !=
s->last_qps[0])
2667 for (
i = 0;
i <
s->nqps;
i++)
2670 if (
s->qps[
i] !=
s->last_qps[
i] ||
s->qps[0] !=
s->last_qps[0])
2678 s->current_frame.f->key_frame =
s->keyframe;
2683 if (!
s->edge_emu_buffer) {
2684 s->edge_emu_buffer =
av_malloc(9 *
FFABS(
s->current_frame.f->linesize[0]));
2685 if (!
s->edge_emu_buffer) {
2697 #if !CONFIG_VP4_DECODER
2704 if (avctx->frame_number == 0)
2706 "VP version: %d\n",
s->version);
2709 if (
s->version ||
s->theora) {
2712 "Warning, unsupported keyframe coding type?!\n");
2715 #if CONFIG_VP4_DECODER
2716 if (
s->version >= 2) {
2717 int mb_height, mb_width;
2718 int mb_width_mul, mb_width_div, mb_height_mul, mb_height_div;
2722 if (mb_height !=
s->macroblock_height ||
2723 mb_width !=
s->macroblock_width)
2730 if (mb_width_mul != 1 || mb_width_div != 1 || mb_height_mul != 1 || mb_height_div != 1)
2739 if (!
s->golden_frame.f->data[0]) {
2741 "vp3: first frame not a keyframe\n");
2749 &
s->golden_frame)) < 0)
2755 memset(
s->all_fragments, 0,
s->fragment_count *
sizeof(
Vp3Fragment));
2758 if (
s->version < 2) {
2763 #if CONFIG_VP4_DECODER
2765 if ((
ret = vp4_unpack_macroblocks(
s, &gb)) < 0) {
2784 if (
s->version < 2) {
2789 #if CONFIG_VP4_DECODER
2791 if ((
ret = vp4_unpack_dct_coeffs(
s, &gb)) < 0) {
2798 for (
i = 0;
i < 3;
i++) {
2799 int height =
s->height >> (
i &&
s->chroma_y_shift);
2800 if (
s->flipped_image)
2801 s->data_offset[
i] = 0;
2803 s->data_offset[
i] = (
height - 1) *
s->current_frame.f->linesize[
i];
2806 s->last_slice_end = 0;
2807 for (
i = 0;
i <
s->c_superblock_height;
i++)
2812 for (
i = 0;
i < 3;
i++) {
2813 int row = (
s->height >> (3 + (
i &&
s->chroma_y_shift))) - 1;
2822 frame->crop_left =
s->offset_x;
2823 frame->crop_right = avctx->coded_width - avctx->width -
s->offset_x;
2824 frame->crop_top =
s->offset_y;
2825 frame->crop_bottom = avctx->coded_height - avctx->height -
s->offset_y;
2856 ff_dlog(avctx,
"code length %d, curr entry %d, token %d\n",
2874 #if CONFIG_THEORA_DECODER
2882 int visible_width, visible_height, colorspace;
2883 uint8_t offset_x = 0, offset_y = 0;
2890 s->theora_header = 0;
2900 if (
s->theora < 0x030200) {
2901 s->flipped_image = 1;
2903 "Old (<alpha3) Theora bitstream, flipped image\n");
2911 if (
s->theora >= 0x030200) {
2921 visible_width + offset_x >
s->width ||
2922 visible_height + offset_y >
s->height) {
2924 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2925 visible_width, visible_height, offset_x, offset_y,
2926 s->width,
s->height);
2932 if (fps.
num && fps.
den) {
2933 if (fps.
num < 0 || fps.
den < 0) {
2938 fps.
den, fps.
num, 1 << 30);
2943 if (aspect.
num && aspect.
den) {
2946 aspect.
num, aspect.
den, 1 << 30);
2950 if (
s->theora < 0x030200)
2957 if (
s->theora >= 0x030200) {
2972 avctx->
width = visible_width;
2973 avctx->
height = visible_height;
2976 s->offset_x = offset_x;
2977 s->offset_y =
s->height - visible_height - offset_y;
2980 if (colorspace == 1)
2982 else if (colorspace == 2)
2985 if (colorspace == 1 || colorspace == 2) {
2990 s->theora_header = 1;
2997 int i, n, matrices, inter, plane,
ret;
2999 if (!
s->theora_header)
3002 if (
s->theora >= 0x030200) {
3006 for (
i = 0;
i < 64;
i++)
3010 if (
s->theora >= 0x030200)
3015 for (
i = 0;
i < 64;
i++)
3016 s->coded_ac_scale_factor[
i] =
get_bits(gb, n);
3018 if (
s->theora >= 0x030200)
3023 for (
i = 0;
i < 64;
i++)
3024 s->coded_dc_scale_factor[0][
i] =
3025 s->coded_dc_scale_factor[1][
i] =
get_bits(gb, n);
3027 if (
s->theora >= 0x030200)
3032 if (matrices > 384) {
3037 for (n = 0; n < matrices; n++)
3038 for (
i = 0;
i < 64;
i++)
3041 for (inter = 0; inter <= 1; inter++) {
3042 for (plane = 0; plane <= 2; plane++) {
3044 if (inter || plane > 0)
3052 qtj = (3 * inter + plane - 1) / 3;
3053 plj = (plane + 2) % 3;
3055 s->qr_count[inter][plane] =
s->qr_count[qtj][plj];
3056 memcpy(
s->qr_size[inter][plane],
s->qr_size[qtj][plj],
3057 sizeof(
s->qr_size[0][0]));
3058 memcpy(
s->qr_base[inter][plane],
s->qr_base[qtj][plj],
3059 sizeof(
s->qr_base[0][0]));
3066 if (
i >= matrices) {
3068 "invalid base matrix index\n");
3071 s->qr_base[inter][plane][qri] =
i;
3075 s->qr_size[inter][plane][qri++] =
i;
3083 s->qr_count[inter][plane] = qri;
3090 s->huffman_table[
i].nb_entries = 0;
3095 s->theora_tables = 1;
3105 const uint8_t *header_start[3];
3120 42, header_start, header_len) < 0) {
3125 for (
i = 0;
i < 3;
i++) {
3126 if (header_len[
i] <= 0)
3134 if (!(ptype & 0x80)) {
3157 "Unknown Theora config packet: %d\n", ptype & ~0x80);
3162 "%d bits left in packet %X\n",
3164 if (
s->theora < 0x030200)
3177 .
init = theora_decode_init,
3206 #if CONFIG_VP4_DECODER