33 #include "config_components.h"
57 #define VP3_MV_VLC_BITS 6
58 #define VP4_MV_VLC_BITS 6
59 #define SUPERBLOCK_VLC_BITS 6
61 #define FRAGMENT_PIXELS 8
70 #define SB_NOT_CODED 0
71 #define SB_PARTIALLY_CODED 1
72 #define SB_FULLY_CODED 2
77 #define MAXIMUM_LONG_BIT_RUN 4129
79 #define MODE_INTER_NO_MV 0
81 #define MODE_INTER_PLUS_MV 2
82 #define MODE_INTER_LAST_MV 3
83 #define MODE_INTER_PRIOR_LAST 4
84 #define MODE_USING_GOLDEN 5
85 #define MODE_GOLDEN_MV 6
86 #define MODE_INTER_FOURMV 7
87 #define CODING_MODE_COUNT 8
136 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
137 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
138 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
139 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
166 #define MIN_DEQUANT_VAL 2
260 #define TOKEN_EOB(eob_run) ((eob_run) << 2)
261 #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
262 #define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
339 if (
s->golden_frame.f)
343 if (
s->current_frame.f)
354 s->theora_tables = 0;
370 for (
int j = 0; j < 2; j++)
371 for (
int i = 0;
i < 7;
i++)
374 for (
int i = 0;
i < 2;
i++)
390 for (
int plane = 0; plane < 3; plane++) {
391 int sb_width = plane ?
s->c_superblock_width
392 :
s->y_superblock_width;
393 int sb_height = plane ?
s->c_superblock_height
394 :
s->y_superblock_height;
395 int frag_width =
s->fragment_width[!!plane];
396 int frag_height =
s->fragment_height[!!plane];
398 for (
int sb_y = 0; sb_y < sb_height; sb_y++)
399 for (
int sb_x = 0; sb_x < sb_width; sb_x++)
400 for (
int i = 0;
i < 16;
i++) {
404 if (x < frag_width && y < frag_height)
405 s->superblock_fragments[j++] =
s->fragment_start[plane] +
408 s->superblock_fragments[j++] = -1;
421 int ac_scale_factor =
s->coded_ac_scale_factor[
s->qps[qpi]];
423 for (
int inter = 0; inter < 2; inter++) {
424 for (
int plane = 0; plane < 3; plane++) {
425 int dc_scale_factor =
s->coded_dc_scale_factor[!!plane][
s->qps[qpi]];
426 int sum = 0, bmi, bmj, qistart, qri;
427 for (qri = 0; qri <
s->qr_count[inter][plane]; qri++) {
428 sum +=
s->qr_size[inter][plane][qri];
429 if (
s->qps[qpi] <= sum)
432 qistart = sum -
s->qr_size[inter][plane][qri];
433 bmi =
s->qr_base[inter][plane][qri];
434 bmj =
s->qr_base[inter][plane][qri + 1];
435 for (
int i = 0;
i < 64;
i++) {
436 int coeff = (2 * (sum -
s->qps[qpi]) *
s->base_matrix[bmi][
i] -
437 2 * (qistart -
s->qps[qpi]) *
s->base_matrix[bmj][
i] +
438 s->qr_size[inter][plane][qri]) /
439 (2 *
s->qr_size[inter][plane][qri]);
441 int qmin = 8 << (inter + !
i);
442 int qscale =
i ? ac_scale_factor : dc_scale_factor;
443 int qbias = (1 + inter) * 3;
444 s->qmat[qpi][inter][plane][
s->idct_permutation[
i]] =
445 (
i == 0 ||
s->version < 2) ?
av_clip((qscale *
coeff) / 100 * 4, qmin, 4096)
446 : (qscale * (
coeff - qbias) / 100 + qbias) * 4;
450 s->qmat[qpi][inter][plane][0] =
s->qmat[0][inter][plane][0];
472 const int superblock_starts[3] = {
473 0,
s->u_superblock_start,
s->v_superblock_start
476 int current_superblock = 0;
478 int num_partial_superblocks = 0;
480 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 (
int 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 (
int 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 (
int i = sb_start;
i < sb_end;
i++) {
581 for (
int 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 (
int 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 (
int 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 (
int 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 (
int 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;
738 for (
int plane = 0,
i = 0; plane < 3; plane++) {
739 int sb_width = plane ?
s->c_superblock_width :
s->y_superblock_width;
740 int sb_height = plane ?
s->c_superblock_height :
s->y_superblock_height;
741 int mb_width = plane ?
s->c_macroblock_width :
s->macroblock_width;
742 int mb_height = plane ?
s->c_macroblock_height :
s->macroblock_height;
743 int fragment_width =
s->fragment_width[!!plane];
744 int fragment_height =
s->fragment_height[!!plane];
746 for (
int sb_y = 0; sb_y < sb_height; sb_y++) {
747 for (
int sb_x = 0; sb_x < sb_width; sb_x++) {
748 for (
int j = 0; j < 4; j++) {
749 int mb_x = 2 * sb_x + (j >> 1);
750 int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
751 int mb_coded, pattern, coded;
753 if (mb_x >= mb_width || mb_y >= mb_height)
756 mb_coded =
s->superblock_coding[
i++];
761 pattern = vp4_get_block_pattern(
s, gb, &next_block_pattern_table);
765 for (
int k = 0; k < 4; k++) {
769 coded = pattern & (8 >> k);
789 int current_macroblock;
790 int current_fragment;
797 for (
int i = 0;
i <
s->fragment_count;
i++)
805 for (
int i = 0;
i < 8;
i++)
807 for (
int i = 0;
i < 8;
i++)
808 custom_mode_alphabet[
get_bits(gb, 3)] =
i;
809 alphabet = custom_mode_alphabet;
815 for (
int sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
816 for (
int sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
820 for (
int j = 0; j < 4; j++) {
822 int mb_x = 2 * sb_x + (j >> 1);
823 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
824 current_macroblock = mb_y *
s->macroblock_width + mb_x;
826 if (mb_x >=
s->macroblock_width ||
827 mb_y >=
s->macroblock_height)
833 for (k = 0; k < 4; k++) {
836 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY)
848 coding_mode = alphabet[
get_vlc2(gb,
s->mode_code_vlc.table, 3, 3)];
850 s->macroblock_coding[current_macroblock] = coding_mode;
851 for (k = 0; k < 4; k++) {
857 #define SET_CHROMA_MODES \
858 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
859 frag[s->fragment_start[1]].coding_method = coding_mode; \
860 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
861 frag[s->fragment_start[2]].coding_method = coding_mode;
863 if (
s->chroma_y_shift) {
864 frag =
s->all_fragments + mb_y *
865 s->fragment_width[1] + mb_x;
867 }
else if (
s->chroma_x_shift) {
868 frag =
s->all_fragments +
869 2 * mb_y *
s->fragment_width[1] + mb_x;
870 for (k = 0; k < 2; k++) {
872 frag +=
s->fragment_width[1];
875 for (k = 0; k < 4; k++) {
876 frag =
s->all_fragments +
893 return last_motion < 0 ? -v : v;
905 int last_motion_x = 0;
906 int last_motion_y = 0;
907 int prior_last_motion_x = 0;
908 int prior_last_motion_y = 0;
909 int last_gold_motion_x = 0;
910 int last_gold_motion_y = 0;
911 int current_macroblock;
912 int current_fragment;
919 coding_mode =
s->version < 2 ?
get_bits1(gb) : 2;
923 for (
int sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
924 for (
int sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
928 for (
int j = 0; j < 4; j++) {
929 int mb_x = 2 * sb_x + (j >> 1);
930 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
931 current_macroblock = mb_y *
s->macroblock_width + mb_x;
933 if (mb_x >=
s->macroblock_width ||
934 mb_y >=
s->macroblock_height ||
935 s->macroblock_coding[current_macroblock] ==
MODE_COPY)
938 switch (
s->macroblock_coding[current_macroblock]) {
940 if (coding_mode == 2) {
941 last_gold_motion_x = motion_x[0] =
vp4_get_mv(
s, gb, 0, last_gold_motion_x);
942 last_gold_motion_y = motion_y[0] =
vp4_get_mv(
s, gb, 1, last_gold_motion_y);
947 if (coding_mode == 0) {
948 motion_x[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
950 motion_y[0] =
get_vlc2(gb,
s->motion_vector_vlc.table,
952 }
else if (coding_mode == 1) {
962 prior_last_motion_x = last_motion_x;
963 prior_last_motion_y = last_motion_y;
964 last_motion_x = motion_x[0];
965 last_motion_y = motion_y[0];
971 prior_last_motion_x = last_motion_x;
972 prior_last_motion_y = last_motion_y;
976 for (
int k = 0; k < 4; k++) {
978 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY) {
979 if (coding_mode == 0) {
980 motion_x[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
982 motion_y[k] =
get_vlc2(gb,
s->motion_vector_vlc.table,
984 }
else if (coding_mode == 1) {
988 motion_x[k] =
vp4_get_mv(
s, gb, 0, prior_last_motion_x);
989 motion_y[k] =
vp4_get_mv(
s, gb, 1, prior_last_motion_y);
991 last_motion_x = motion_x[k];
992 last_motion_y = motion_y[k];
1002 motion_x[0] = last_motion_x;
1003 motion_y[0] = last_motion_y;
1012 motion_x[0] = prior_last_motion_x;
1013 motion_y[0] = prior_last_motion_y;
1016 prior_last_motion_x = last_motion_x;
1017 prior_last_motion_y = last_motion_y;
1018 last_motion_x = motion_x[0];
1019 last_motion_y = motion_y[0];
1032 for (
int k = 0; k < 4; k++) {
1036 s->motion_val[0][current_fragment][0] = motion_x[k];
1037 s->motion_val[0][current_fragment][1] = motion_y[k];
1039 s->motion_val[0][current_fragment][0] = motion_x[0];
1040 s->motion_val[0][current_fragment][1] = motion_y[0];
1044 if (
s->chroma_y_shift) {
1046 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] +
1047 motion_x[2] + motion_x[3], 2);
1048 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] +
1049 motion_y[2] + motion_y[3], 2);
1051 if (
s->version <= 2) {
1052 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1053 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
1055 frag = mb_y *
s->fragment_width[1] + mb_x;
1056 s->motion_val[1][frag][0] = motion_x[0];
1057 s->motion_val[1][frag][1] = motion_y[0];
1058 }
else if (
s->chroma_x_shift) {
1060 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
1061 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
1062 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
1063 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
1065 motion_x[1] = motion_x[0];
1066 motion_y[1] = motion_y[0];
1068 if (
s->version <= 2) {
1069 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1070 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
1072 frag = 2 * mb_y *
s->fragment_width[1] + mb_x;
1073 for (
int k = 0; k < 2; k++) {
1074 s->motion_val[1][frag][0] = motion_x[k];
1075 s->motion_val[1][frag][1] = motion_y[k];
1076 frag +=
s->fragment_width[1];
1079 for (
int k = 0; k < 4; k++) {
1082 s->motion_val[1][frag][0] = motion_x[k];
1083 s->motion_val[1][frag][1] = motion_y[k];
1085 s->motion_val[1][frag][0] = motion_x[0];
1086 s->motion_val[1][frag][1] = motion_y[0];
1099 int num_blocks =
s->total_num_coded_frags;
1101 for (
int qpi = 0; qpi <
s->nqps - 1 && num_blocks > 0; qpi++) {
1102 int i = 0, blocks_decoded = 0, num_blocks_at_qpi = 0;
1103 int bit, run_length;
1114 run_length =
get_vlc2(gb,
s->superblock_run_length_vlc.table,
1116 if (run_length == 34)
1118 blocks_decoded += run_length;
1121 num_blocks_at_qpi += run_length;
1123 for (
int j = 0; j < run_length;
i++) {
1124 if (
i >=
s->total_num_coded_frags)
1127 if (
s->all_fragments[
s->coded_fragment_list[0][
i]].qpi == qpi) {
1128 s->all_fragments[
s->coded_fragment_list[0][
i]].qpi +=
bit;
1132 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
1134 num_blocks -= num_blocks_at_qpi;
1150 int bits_to_get, zero_run;
1154 bits_to_get =
get_bits(gb, bits_to_get);
1187 int num_coeffs =
s->num_coded_frags[plane][coeff_index];
1188 int16_t *dct_tokens =
s->dct_tokens[plane][coeff_index];
1191 const int *coded_fragment_list =
s->coded_fragment_list[plane];
1195 if (num_coeffs < 0) {
1197 "Invalid number of coefficients at level %d\n", coeff_index);
1201 if (eob_run > num_coeffs) {
1203 blocks_ended = num_coeffs;
1204 eob_run -= num_coeffs;
1207 blocks_ended = eob_run;
1213 dct_tokens[j++] = blocks_ended << 2;
1217 token =
get_vlc2(gb, vlc_table, 11, 3);
1219 if ((
unsigned) token <= 6
U) {
1226 if (eob_run > num_coeffs - coeff_i) {
1227 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
1228 blocks_ended += num_coeffs - coeff_i;
1229 eob_run -= num_coeffs - coeff_i;
1230 coeff_i = num_coeffs;
1233 blocks_ended += eob_run;
1237 }
else if (token >= 0) {
1248 all_fragments[coded_fragment_list[coeff_i]].
dc =
coeff;
1253 if (coeff_index + zero_run > 64) {
1255 "Invalid zero run of %d with %d coeffs left\n",
1256 zero_run, 64 - coeff_index);
1257 zero_run = 64 - coeff_index;
1262 for (
int i = coeff_index + 1;
i <= coeff_index + zero_run;
i++)
1263 s->num_coded_frags[plane][
i]--;
1271 if (blocks_ended >
s->num_coded_frags[plane][coeff_index])
1277 for (
int i = coeff_index + 1;
i < 64;
i++)
1278 s->num_coded_frags[plane][
i] -= blocks_ended;
1282 s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1283 else if (coeff_index < 63)
1284 s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1292 int fragment_height);
1303 int residual_eob_run = 0;
1307 s->dct_tokens[0][0] =
s->dct_tokens_base;
1317 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_y_table], 0,
1318 0, residual_eob_run);
1319 if (residual_eob_run < 0)
1320 return residual_eob_run;
1328 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1329 1, residual_eob_run);
1330 if (residual_eob_run < 0)
1331 return residual_eob_run;
1332 residual_eob_run =
unpack_vlcs(
s, gb, &
s->coeff_vlc[dc_c_table], 0,
1333 2, residual_eob_run);
1334 if (residual_eob_run < 0)
1335 return residual_eob_run;
1340 s->fragment_width[1],
s->fragment_height[1]);
1342 s->fragment_width[1],
s->fragment_height[1]);
1352 for (
int i = 1;
i <= 5;
i++) {
1354 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 16];
1355 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 16];
1357 for (
int i = 6;
i <= 14;
i++) {
1359 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 32];
1360 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 32];
1362 for (
int i = 15;
i <= 27;
i++) {
1364 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 48];
1365 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 48];
1367 for (
int i = 28;
i <= 63;
i++) {
1369 y_tables[
i] = &
s->coeff_vlc[ac_y_table + 64];
1370 c_tables[
i] = &
s->coeff_vlc[ac_c_table + 64];
1374 for (
int i = 1;
i <= 63;
i++) {
1376 0, residual_eob_run);
1377 if (residual_eob_run < 0)
1378 return residual_eob_run;
1381 1, residual_eob_run);
1382 if (residual_eob_run < 0)
1383 return residual_eob_run;
1385 2, residual_eob_run);
1386 if (residual_eob_run < 0)
1387 return residual_eob_run;
1393 #if CONFIG_VP4_DECODER
1402 int plane,
int eob_tracker[64],
int fragment)
1410 while (!eob_tracker[coeff_i]) {
1417 if ((
unsigned) token <= 6
U) {
1419 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1420 eob_tracker[coeff_i] = eob_run - 1;
1422 }
else if (token >= 0) {
1426 if (coeff_i + zero_run > 64) {
1428 "Invalid zero run of %d with %d coeffs left\n",
1429 zero_run, 64 - coeff_i);
1430 zero_run = 64 - coeff_i;
1433 coeff_i += zero_run;
1448 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1449 eob_tracker[coeff_i]--;
1461 for (
int i = 0;
i < 4;
i++)
1462 dc_pred[0][
i + 1] =
s->dc_pred_row[sb_x * 4 +
i];
1464 for (
int j = 1; j < 5; j++)
1465 for (
int i = 0;
i < 4;
i++)
1466 vp4_dc_predictor_reset(&dc_pred[j][
i + 1]);
1471 for (
int i = 0;
i < 4;
i++)
1472 s->dc_pred_row[sb_x * 4 +
i] = dc_pred[4][
i + 1];
1474 for (
int i = 1;
i < 5;
i++)
1475 dc_pred[
i][0] = dc_pred[
i][4];
1485 dc += dc_pred[-6].
dc;
1490 dc += dc_pred[6].
dc;
1494 if (count != 2 && dc_pred[-1].
type ==
type) {
1495 dc += dc_pred[-1].
dc;
1499 if (count != 2 && dc_pred[1].
type ==
type) {
1500 dc += dc_pred[1].
dc;
1505 return count == 2 ?
dc / 2 : last_dc[
type];
1510 int16_t *
base =
s->dct_tokens_base;
1511 for (
int plane = 0; plane < 3; plane++) {
1512 for (
int i = 0;
i < 64;
i++) {
1513 s->dct_tokens[plane][
i] =
base;
1514 base +=
s->fragment_width[!!plane] *
s->fragment_height[!!plane];
1526 int eob_tracker[64];
1543 tables[0][0] = &
s->coeff_vlc[dc_y_table];
1544 tables[1][0] = &
s->coeff_vlc[dc_c_table];
1545 for (
int i = 1;
i <= 5;
i++) {
1547 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 16];
1548 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 16];
1550 for (
int i = 6;
i <= 14;
i++) {
1552 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 32];
1553 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 32];
1555 for (
int i = 15;
i <= 27;
i++) {
1557 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 48];
1558 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 48];
1560 for (
int i = 28;
i <= 63;
i++) {
1562 tables[0][
i] = &
s->coeff_vlc[ac_y_table + 64];
1563 tables[1][
i] = &
s->coeff_vlc[ac_c_table + 64];
1566 vp4_set_tokens_base(
s);
1568 memset(last_dc, 0,
sizeof(last_dc));
1571 memset(eob_tracker, 0,
sizeof(eob_tracker));
1574 for (
int i = 0;
i <
s->fragment_width[!!plane];
i++)
1575 vp4_dc_predictor_reset(&
s->dc_pred_row[
i]);
1577 for (
int j = 0; j < 6; j++)
1578 for (
int i = 0;
i < 6;
i++)
1579 vp4_dc_predictor_reset(&dc_pred[j][
i]);
1581 for (
int sb_y = 0; sb_y * 4 <
s->fragment_height[!!plane]; sb_y++) {
1582 for (
int sb_x = 0; sb_x *4 <
s->fragment_width[!!plane]; sb_x++) {
1583 vp4_dc_pred_before(
s, dc_pred, sb_x);
1584 for (
int j = 0; j < 16; j++) {
1587 int x = 4 * sb_x + hx;
1588 int y = 4 * sb_y + hy;
1592 if (x >=
s->fragment_width[!!plane] || y >=
s->fragment_height[!!plane])
1595 fragment =
s->fragment_start[plane] + y *
s->fragment_width[!!plane] + x;
1600 if (vp4_unpack_vlcs(
s, gb,
tables[!!plane], plane, eob_tracker,
fragment) < 0)
1606 vp4_dc_pred(
s, this_dc_pred, last_dc, dc_block_type, plane);
1608 this_dc_pred->
type = dc_block_type,
1609 this_dc_pred->
dc = last_dc[dc_block_type] =
s->all_fragments[
fragment].dc;
1611 vp4_dc_pred_after(
s, dc_pred, sb_x);
1616 vp4_set_tokens_base(
s);
1627 #define COMPATIBLE_FRAME(x) \
1628 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1629 #define DC_COEFF(u) s->all_fragments[u].dc
1634 int fragment_height)
1641 int i = first_fragment;
1646 int vl, vul, vu, vur;
1658 static const int predictor_transform[16][4] = {
1672 { -104, 116, 0, 116 },
1674 { -104, 116, 0, 116 }
1683 static const unsigned char compatible_frame[9] = {
1694 int current_frame_type;
1710 for (
int y = 0; y < fragment_height; y++) {
1712 for (
int x = 0; x < fragment_width; x++,
i++) {
1715 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
1716 current_frame_type =
1717 compatible_frame[
s->all_fragments[
i].coding_method];
1727 u =
i - fragment_width;
1732 ul =
i - fragment_width - 1;
1737 if (x + 1 < fragment_width) {
1738 ur =
i - fragment_width + 1;
1748 predicted_dc = last_dc[current_frame_type];
1752 (predictor_transform[
transform][0] * vul) +
1753 (predictor_transform[
transform][1] * vu) +
1754 (predictor_transform[
transform][2] * vur) +
1755 (predictor_transform[
transform][3] * vl);
1757 predicted_dc /= 128;
1762 if (
FFABS(predicted_dc - vu) > 128)
1764 else if (
FFABS(predicted_dc - vl) > 128)
1766 else if (
FFABS(predicted_dc - vul) > 128)
1774 last_dc[current_frame_type] =
DC_COEFF(
i);
1781 int ystart,
int yend)
1783 int *bounding_values =
s->bounding_values_array + 127;
1785 int width =
s->fragment_width[!!plane];
1786 int height =
s->fragment_height[!!plane];
1788 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
1789 uint8_t *plane_data =
s->current_frame.f->data[plane];
1790 if (!
s->flipped_image)
1792 plane_data +=
s->data_offset[plane] + 8 * ystart *
stride;
1794 for (
int y = ystart; y < yend; y++) {
1795 for (
int x = 0; x <
width; x++) {
1803 s->vp3dsp.h_loop_filter(
1805 stride, bounding_values);
1810 s->vp3dsp.v_loop_filter(
1812 stride, bounding_values);
1818 if ((x <
width - 1) &&
1820 s->vp3dsp.h_loop_filter(
1821 plane_data + 8 * x + 8,
1822 stride, bounding_values);
1830 s->vp3dsp.v_loop_filter(
1831 plane_data + 8 * x + 8 *
stride,
1832 stride, bounding_values);
1838 plane_data += 8 *
stride;
1847 int plane,
int inter, int16_t
block[64])
1849 const int16_t *dequantizer =
s->qmat[frag->
qpi][inter][plane];
1850 const uint8_t *
perm =
s->idct_scantable;
1854 int token = *
s->dct_tokens[plane][
i];
1855 switch (token & 3) {
1858 s->dct_tokens[plane][
i]++;
1860 *
s->dct_tokens[plane][
i] = token & ~3;
1863 s->dct_tokens[plane][
i]++;
1864 i += (token >> 2) & 0x7f;
1874 s->dct_tokens[plane][
i++]++;
1884 block[0] = frag->
dc *
s->qmat[0][inter][plane][0];
1897 int y_flipped =
s->flipped_image ?
s->height - y : y;
1903 y_flipped ==
s->height ? INT_MAX
1908 if (!
s->avctx->draw_horiz_band)
1911 h = y -
s->last_slice_end;
1912 s->last_slice_end = y;
1915 if (!
s->flipped_image)
1916 y =
s->height - y -
h;
1918 cy = y >>
s->chroma_y_shift;
1919 offset[0] =
s->current_frame.f->linesize[0] * y;
1920 offset[1] =
s->current_frame.f->linesize[1] * cy;
1921 offset[2] =
s->current_frame.f->linesize[2] * cy;
1926 s->avctx->draw_horiz_band(
s->avctx,
s->current_frame.f,
offset, y, 3,
h);
1934 int motion_y,
int y)
1938 int border = motion_y & 1;
1946 ref_row = y + (motion_y >> 1);
1947 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1952 #if CONFIG_VP4_DECODER
1956 static int vp4_mc_loop_filter(
Vp3DecodeContext *
s,
int plane,
int motion_x,
int motion_y,
int bx,
int by,
1957 const uint8_t *motion_source, ptrdiff_t
stride,
1958 int src_x,
int src_y, uint8_t *
temp)
1960 int motion_shift = plane ? 4 : 2;
1961 int subpel_mask = plane ? 3 : 1;
1962 int *bounding_values =
s->bounding_values_array + 127;
1966 int x_subpel, y_subpel;
1967 int x_offset, y_offset;
1969 int block_width = plane ? 8 : 16;
1970 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
1971 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
1973 #define loop_stride 12
1974 uint8_t
loop[12 * loop_stride];
1977 x = 8 * bx + motion_x / motion_shift;
1978 y = 8 * by + motion_y / motion_shift;
1980 x_subpel = motion_x & subpel_mask;
1981 y_subpel = motion_y & subpel_mask;
1983 if (x_subpel || y_subpel) {
1993 x2 = x + block_width;
1994 y2 = y + block_width;
1996 if (x2 < 0 || x2 >= plane_width || y2 < 0 || y2 >= plane_height)
1999 x_offset = (-(x + 2) & 7) + 2;
2000 y_offset = (-(y + 2) & 7) + 2;
2002 if (x_offset > 8 + x_subpel && y_offset > 8 + y_subpel)
2005 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2007 12, 12, src_x - 1, src_y - 1,
2011 if (x_offset <= 8 + x_subpel)
2014 if (y_offset <= 8 + y_subpel)
2022 if (!x_offset && !y_offset)
2025 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2027 12, 12, src_x - 1, src_y - 1,
2031 #define safe_loop_filter(name, ptr, stride, bounding_values) \
2032 if ((uintptr_t)(ptr) & 7) \
2033 s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \
2035 s->vp3dsp.name(ptr, stride, bounding_values);
2038 safe_loop_filter(h_loop_filter,
loop + loop_stride + x_offset + 1, loop_stride, bounding_values);
2041 safe_loop_filter(v_loop_filter,
loop + (y_offset + 1)*loop_stride + 1, loop_stride, bounding_values);
2044 for (
int i = 0;
i < 9;
i++)
2057 int16_t *
block =
s->block;
2058 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
2063 const AVFrame *last_frame =
s->last_frame.f->data[0] ?
2064 s->last_frame.f :
s->current_frame.f;
2065 const AVFrame *golden_frame =
s->golden_frame.f->data[0] ?
2066 s->golden_frame.f :
s->current_frame.f;
2067 int motion_halfpel_index;
2070 if (slice >=
s->c_superblock_height)
2073 for (
int plane = 0; plane < 3; plane++) {
2075 s->data_offset[plane];
2076 const uint8_t *last_plane = last_frame->
data[plane] +
2077 s->data_offset[plane];
2078 const uint8_t *golden_plane = golden_frame->
data[plane] +
2079 s->data_offset[plane];
2080 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
2081 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
2082 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
2083 const int8_t (*motion_val)[2] =
s->motion_val[!!plane];
2085 int sb_y = slice << (!plane &&
s->chroma_y_shift);
2086 int slice_height = sb_y + 1 + (!plane &&
s->chroma_y_shift);
2087 int slice_width = plane ?
s->c_superblock_width
2088 :
s->y_superblock_width;
2090 int fragment_width =
s->fragment_width[!!plane];
2091 int fragment_height =
s->fragment_height[!!plane];
2092 int fragment_start =
s->fragment_start[plane];
2094 int do_await = !plane && HAVE_THREADS &&
2097 if (!
s->flipped_image)
2103 for (; sb_y < slice_height; sb_y++) {
2105 for (
int sb_x = 0; sb_x < slice_width; sb_x++) {
2107 for (
int j = 0; j < 16; j++) {
2110 int fragment = y * fragment_width + x;
2115 if (x >= fragment_width || y >= fragment_height)
2118 first_pixel = 8 * y *
stride + 8 * x;
2124 (16 * y) >>
s->chroma_y_shift);
2127 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
2128 const uint8_t *motion_source;
2131 motion_source = golden_plane;
2133 motion_source = last_plane;
2135 motion_source += first_pixel;
2136 motion_halfpel_index = 0;
2140 if ((
s->all_fragments[
i].coding_method >
MODE_INTRA) &&
2143 int standard_mc = 1;
2144 motion_x = motion_val[
fragment][0];
2145 motion_y = motion_val[
fragment][1];
2146 #if CONFIG_VP4_DECODER
2147 if (plane &&
s->version >= 2) {
2148 motion_x = (motion_x >> 1) | (motion_x & 1);
2149 motion_y = (motion_y >> 1) | (motion_y & 1);
2153 src_x = (motion_x >> 1) + 8 * x;
2154 src_y = (motion_y >> 1) + 8 * y;
2156 motion_halfpel_index = motion_x & 0x01;
2157 motion_source += (motion_x >> 1);
2159 motion_halfpel_index |= (motion_y & 0x01) << 1;
2160 motion_source += ((motion_y >> 1) *
stride);
2162 #if CONFIG_VP4_DECODER
2163 if (
s->version >= 2) {
2164 uint8_t *
temp =
s->edge_emu_buffer;
2167 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)) {
2168 motion_source =
temp;
2174 if (standard_mc && (
2175 src_x < 0 || src_y < 0 ||
2176 src_x + 9 >= plane_width ||
2177 src_y + 9 >= plane_height)) {
2178 uint8_t *
temp =
s->edge_emu_buffer;
2182 s->vdsp.emulated_edge_mc(
temp, motion_source,
2187 motion_source =
temp;
2198 if (motion_halfpel_index != 3) {
2199 s->hdsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
2201 motion_source,
stride, 8);
2205 int d = (motion_x ^ motion_y) >> 31;
2208 motion_source +
stride + 1 +
d,
2234 s->hdsp.put_pixels_tab[1][0](
2236 last_plane + first_pixel,
2243 if (
s->version < 2 && !
s->skip_loop_filter)
2245 FFMIN(4 * sb_y + 3, fragment_height - 1));
2265 int y_fragment_count, c_fragment_count;
2269 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2270 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2273 s->superblock_coding =
av_mallocz(
FFMAX(
s->superblock_count,
s->yuv_macroblock_count));
2274 s->all_fragments =
av_calloc(
s->fragment_count,
sizeof(*
s->all_fragments));
2276 s-> kf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2277 s->nkf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2278 memset(
s-> num_kf_coded_fragment, -1,
sizeof(
s-> num_kf_coded_fragment));
2281 64 *
sizeof(*
s->dct_tokens_base));
2282 s->motion_val[0] =
av_calloc(y_fragment_count,
sizeof(*
s->motion_val[0]));
2283 s->motion_val[1] =
av_calloc(c_fragment_count,
sizeof(*
s->motion_val[1]));
2286 s->superblock_fragments =
av_calloc(
s->superblock_count, 16 *
sizeof(
int));
2287 s->macroblock_coding =
av_mallocz(
s->macroblock_count + 1);
2289 s->dc_pred_row =
av_malloc_array(
s->y_superblock_width * 4,
sizeof(*
s->dc_pred_row));
2291 if (!
s->superblock_coding || !
s->all_fragments ||
2292 !
s->dct_tokens_base || !
s->kf_coded_fragment_list ||
2293 !
s->nkf_coded_fragment_list ||
2294 !
s->superblock_fragments || !
s->macroblock_coding ||
2296 !
s->motion_val[0] || !
s->motion_val[1]) {
2311 if (!
s->current_frame.f || !
s->last_frame.f || !
s->golden_frame.f)
2323 int y_fragment_count, c_fragment_count;
2331 #if !CONFIG_VP4_DECODER
2352 for (
int i = 0;
i < 64;
i++) {
2353 #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
2361 for (
int i = 0;
i < 3;
i++)
2368 s->y_superblock_width = (
s->width + 31) / 32;
2369 s->y_superblock_height = (
s->height + 31) / 32;
2370 s->y_superblock_count =
s->y_superblock_width *
s->y_superblock_height;
2373 c_width =
s->width >>
s->chroma_x_shift;
2374 c_height =
s->height >>
s->chroma_y_shift;
2375 s->c_superblock_width = (c_width + 31) / 32;
2376 s->c_superblock_height = (c_height + 31) / 32;
2377 s->c_superblock_count =
s->c_superblock_width *
s->c_superblock_height;
2379 s->superblock_count =
s->y_superblock_count + (
s->c_superblock_count * 2);
2380 s->u_superblock_start =
s->y_superblock_count;
2381 s->v_superblock_start =
s->u_superblock_start +
s->c_superblock_count;
2383 s->macroblock_width = (
s->width + 15) / 16;
2384 s->macroblock_height = (
s->height + 15) / 16;
2385 s->macroblock_count =
s->macroblock_width *
s->macroblock_height;
2386 s->c_macroblock_width = (c_width + 15) / 16;
2387 s->c_macroblock_height = (c_height + 15) / 16;
2388 s->c_macroblock_count =
s->c_macroblock_width *
s->c_macroblock_height;
2389 s->yuv_macroblock_count =
s->macroblock_count + 2 *
s->c_macroblock_count;
2393 s->fragment_width[1] =
s->fragment_width[0] >>
s->chroma_x_shift;
2394 s->fragment_height[1] =
s->fragment_height[0] >>
s->chroma_y_shift;
2397 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2398 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2399 s->fragment_count = y_fragment_count + 2 * c_fragment_count;
2400 s->fragment_start[1] = y_fragment_count;
2401 s->fragment_start[2] = y_fragment_count + c_fragment_count;
2403 if (!
s->theora_tables) {
2404 const uint8_t (*bias_tabs)[32][2];
2406 for (
int i = 0;
i < 64;
i++) {
2416 for (
int inter = 0; inter < 2; inter++) {
2417 for (
int plane = 0; plane < 3; plane++) {
2418 s->qr_count[inter][plane] = 1;
2419 s->qr_size[inter][plane][0] = 63;
2420 s->qr_base[inter][plane][0] =
2421 s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
2429 &bias_tabs[
i][0][1], 2,
2430 &bias_tabs[
i][0][0], 2, 1,
2440 &
tab->entries[0].len,
sizeof(*
tab->entries),
2441 &
tab->entries[0].sym,
sizeof(*
tab->entries), 1,
2450 NULL, 0, 0, 1, 0, avctx);
2456 NULL, 0, 0, 0, 0, avctx);
2462 NULL, 0, 0, 0, 0, avctx);
2473 #if CONFIG_VP4_DECODER
2474 for (
int j = 0; j < 2; j++)
2475 for (
int i = 0;
i < 7;
i++) {
2485 for (
int i = 0;
i < 2;
i++)
2516 if (
src->f->data[0])
2535 int qps_changed = 0, err;
2537 if (!
s1->current_frame.f->data[0] ||
2538 s->width !=
s1->width ||
s->height !=
s1->height) {
2546 if ((err = ref_frames(
s,
s1)) < 0)
2549 s->keyframe =
s1->keyframe;
2552 for (
int i = 0;
i < 3;
i++) {
2553 if (
s->qps[
i] !=
s1->qps[1]) {
2555 memcpy(&
s->qmat[
i], &
s1->qmat[
i],
sizeof(
s->qmat[
i]));
2559 if (
s->qps[0] !=
s1->qps[0])
2560 memcpy(&
s->bounding_values_array, &
s1->bounding_values_array,
2561 sizeof(
s->bounding_values_array));
2564 memcpy(
s->qps,
s1->qps,
sizeof(
s->qps));
2565 memcpy(
s->last_qps,
s1->last_qps,
sizeof(
s->last_qps));
2577 const uint8_t *buf = avpkt->
data;
2578 int buf_size = avpkt->
size;
2586 #if CONFIG_THEORA_DECODER
2592 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2606 }
else if (
type == 2) {
2619 "Header packet passed to frame decoder, skipping\n");
2625 if (!
s->all_fragments) {
2631 for (
int i = 0;
i < 3;
i++)
2632 s->last_qps[
i] =
s->qps[
i];
2637 }
while (
s->theora >= 0x030200 &&
s->nqps < 3 &&
get_bits1(&gb));
2638 for (
int i =
s->nqps;
i < 3;
i++)
2643 s->keyframe ?
"key" :
"", avctx->frame_num + 1,
s->qps[0]);
2645 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2649 if (
s->qps[0] !=
s->last_qps[0])
2652 for (
int i = 0;
i <
s->nqps;
i++)
2655 if (
s->qps[
i] !=
s->last_qps[
i] ||
s->qps[0] !=
s->last_qps[0])
2671 if (!
s->edge_emu_buffer) {
2672 s->edge_emu_buffer =
av_malloc(9 *
FFABS(
s->current_frame.f->linesize[0]));
2673 if (!
s->edge_emu_buffer) {
2685 #if !CONFIG_VP4_DECODER
2692 if (avctx->frame_num == 0)
2694 "VP version: %d\n",
s->version);
2697 if (
s->version ||
s->theora) {
2700 "Warning, unsupported keyframe coding type?!\n");
2703 #if CONFIG_VP4_DECODER
2704 if (
s->version >= 2) {
2705 int mb_height, mb_width;
2706 int mb_width_mul, mb_width_div, mb_height_mul, mb_height_div;
2710 if (mb_height !=
s->macroblock_height ||
2711 mb_width !=
s->macroblock_width)
2718 if (mb_width_mul != 1 || mb_width_div != 1 || mb_height_mul != 1 || mb_height_div != 1)
2727 if (!
s->golden_frame.f->data[0]) {
2729 "vp3: first frame not a keyframe\n");
2737 &
s->golden_frame)) < 0)
2744 memset(
s->all_fragments, 0,
s->fragment_count *
sizeof(
Vp3Fragment));
2746 if (
s->version < 2) {
2751 #if CONFIG_VP4_DECODER
2753 if ((
ret = vp4_unpack_macroblocks(
s, &gb)) < 0) {
2772 if (
s->version < 2) {
2777 #if CONFIG_VP4_DECODER
2779 if ((
ret = vp4_unpack_dct_coeffs(
s, &gb)) < 0) {
2786 for (
int i = 0;
i < 3;
i++) {
2787 int height =
s->height >> (
i &&
s->chroma_y_shift);
2788 if (
s->flipped_image)
2789 s->data_offset[
i] = 0;
2791 s->data_offset[
i] = (
height - 1) *
s->current_frame.f->linesize[
i];
2794 s->last_slice_end = 0;
2795 for (
int i = 0;
i <
s->c_superblock_height;
i++)
2800 for (
int i = 0;
i < 3;
i++) {
2801 int row = (
s->height >> (3 + (
i &&
s->chroma_y_shift))) - 1;
2844 ff_dlog(avctx,
"code length %d, curr entry %d, token %d\n",
2862 #if CONFIG_THEORA_DECODER
2870 int visible_width, visible_height, colorspace;
2871 uint8_t offset_x = 0, offset_y = 0;
2878 s->theora_header = 0;
2888 if (
s->theora < 0x030200) {
2889 s->flipped_image = 1;
2891 "Old (<alpha3) Theora bitstream, flipped image\n");
2899 if (
s->theora >= 0x030200) {
2909 visible_width + offset_x >
s->width ||
2910 visible_height + offset_y >
s->height ||
2914 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2915 visible_width, visible_height, offset_x, offset_y,
2916 s->width,
s->height);
2922 if (fps.
num && fps.
den) {
2923 if (fps.
num < 0 || fps.
den < 0) {
2928 fps.
den, fps.
num, 1 << 30);
2933 if (aspect.
num && aspect.
den) {
2936 aspect.
num, aspect.
den, 1 << 30);
2940 if (
s->theora < 0x030200)
2947 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 n, matrices,
ret;
2991 if (!
s->theora_header)
2994 if (
s->theora >= 0x030200) {
2998 for (
int i = 0;
i < 64;
i++)
3002 if (
s->theora >= 0x030200)
3007 for (
int i = 0;
i < 64;
i++)
3008 s->coded_ac_scale_factor[
i] =
get_bits(gb, n);
3010 if (
s->theora >= 0x030200)
3015 for (
int 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 (
int j = 0; j < matrices; j++)
3030 for (
int i = 0;
i < 64;
i++)
3033 for (
int inter = 0; inter <= 1; inter++) {
3034 for (
int 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];
3111 42, header_start, header_len) < 0) {
3116 for (
int i = 0;
i < 3;
i++) {
3117 if (header_len[
i] <= 0)
3125 if (!(ptype & 0x80)) {
3148 "Unknown Theora config packet: %d\n", ptype & ~0x80);
3153 "%d bits left in packet %X\n",
3155 if (
s->theora < 0x030200)
3168 .
init = theora_decode_init,
3197 #if CONFIG_VP4_DECODER