33#include "config_components.h"
60#define VP3_MV_VLC_BITS 6
61#define VP4_MV_VLC_BITS 6
62#define SUPERBLOCK_VLC_BITS 6
64#define FRAGMENT_PIXELS 8
74#define SB_PARTIALLY_CODED 1
75#define SB_FULLY_CODED 2
80#define MAXIMUM_LONG_BIT_RUN 4129
82#define MODE_INTER_NO_MV 0
84#define MODE_INTER_PLUS_MV 2
85#define MODE_INTER_LAST_MV 3
86#define MODE_INTER_PRIOR_LAST 4
87#define MODE_USING_GOLDEN 5
88#define MODE_GOLDEN_MV 6
89#define MODE_INTER_FOURMV 7
90#define CODING_MODE_COUNT 8
141 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
142 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
143 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
144 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
173#if CONFIG_VP4_DECODER
174static const VLCElem *vp4_mv_vlc_table[2][7];
175static const VLCElem *block_pattern_vlc[2];
183#define MIN_DEQUANT_VAL 2
281#define TOKEN_EOB(eob_run) ((eob_run) << 2)
282#define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
283#define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
375 s->theora_tables = 0;
397 for (
int plane = 0; plane < 3; plane++) {
398 int sb_width = plane ?
s->c_superblock_width
399 :
s->y_superblock_width;
400 int sb_height = plane ?
s->c_superblock_height
401 :
s->y_superblock_height;
402 int frag_width =
s->fragment_width[!!plane];
403 int frag_height =
s->fragment_height[!!plane];
405 for (
int sb_y = 0; sb_y < sb_height; sb_y++)
406 for (
int sb_x = 0; sb_x < sb_width; sb_x++)
407 for (
int i = 0;
i < 16;
i++) {
411 if (x < frag_width && y < frag_height)
412 s->superblock_fragments[j++] =
s->fragment_start[plane] +
415 s->superblock_fragments[j++] = -1;
428 int ac_scale_factor =
s->coded_ac_scale_factor[
s->qps[qpi]];
430 for (
int inter = 0; inter < 2; inter++) {
431 for (
int plane = 0; plane < 3; plane++) {
432 int dc_scale_factor =
s->coded_dc_scale_factor[!!plane][
s->qps[qpi]];
433 int sum = 0, bmi, bmj, qistart, qri;
434 for (qri = 0; qri <
s->qr_count[inter][plane]; qri++) {
435 sum +=
s->qr_size[inter][plane][qri];
436 if (
s->qps[qpi] <= sum)
439 qistart = sum -
s->qr_size[inter][plane][qri];
440 bmi =
s->qr_base[inter][plane][qri];
441 bmj =
s->qr_base[inter][plane][qri + 1];
442 for (
int i = 0;
i < 64;
i++) {
443 int coeff = (2 * (sum -
s->qps[qpi]) *
s->base_matrix[bmi][
i] -
444 2 * (qistart -
s->qps[qpi]) *
s->base_matrix[bmj][
i] +
445 s->qr_size[inter][plane][qri]) /
446 (2 *
s->qr_size[inter][plane][qri]);
448 int qmin = 8 << (inter + !
i);
449 int qscale =
i ? ac_scale_factor : dc_scale_factor;
450 int qbias = (1 + inter) * 3;
451 s->qmat[qpi][inter][plane][
s->idct_permutation[
i]] =
452 (
i == 0 ||
s->version < 2) ?
av_clip((qscale * coeff) / 100 * 4, qmin, 4096)
453 : (qscale * (coeff - qbias) / 100 + qbias) * 4;
457 s->qmat[qpi][inter][plane][0] =
s->qmat[0][inter][plane][0];
479 const int superblock_starts[3] = {
480 0,
s->u_superblock_start,
s->v_superblock_start
483 int current_superblock = 0;
485 int num_partial_superblocks = 0;
487 int current_fragment;
488 int plane0_num_coded_frags = 0;
497 while (current_superblock < s->superblock_count &&
get_bits_left(gb) > 0) {
505 if (current_run == 34)
508 if (current_run >
s->superblock_count - current_superblock) {
510 "Invalid partially coded superblock run length\n");
514 memset(
s->superblock_coding + current_superblock,
bit, current_run);
516 current_superblock += current_run;
518 num_partial_superblocks += current_run;
523 if (num_partial_superblocks < s->superblock_count) {
524 int superblocks_decoded = 0;
526 current_superblock = 0;
530 while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
539 if (current_run == 34)
542 for (
int j = 0; j < current_run; current_superblock++) {
543 if (current_superblock >=
s->superblock_count) {
545 "Invalid fully coded superblock run length\n");
550 if (
s->superblock_coding[current_superblock] ==
SB_NOT_CODED) {
551 s->superblock_coding[current_superblock] = 2 *
bit;
555 superblocks_decoded += current_run;
561 if (num_partial_superblocks) {
572 s->total_num_coded_frags = 0;
573 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
575 s->coded_fragment_list[0] =
s->keyframe ?
s->kf_coded_fragment_list
576 :
s->nkf_coded_fragment_list;
578 for (
int plane = 0; plane < 3; plane++) {
579 int sb_start = superblock_starts[plane];
580 int sb_end = sb_start + (plane ?
s->c_superblock_count
581 :
s->y_superblock_count);
582 int num_coded_frags = 0;
585 if (
s->num_kf_coded_fragment[plane] == -1) {
586 for (
int i = sb_start;
i < sb_end;
i++) {
588 for (
int j = 0; j < 16; j++) {
590 current_fragment =
s->superblock_fragments[
i * 16 + j];
591 if (current_fragment != -1) {
592 s->coded_fragment_list[plane][num_coded_frags++] =
597 s->num_kf_coded_fragment[plane] = num_coded_frags;
599 num_coded_frags =
s->num_kf_coded_fragment[plane];
606 for (
int j = 0; j < 16; j++) {
608 current_fragment =
s->superblock_fragments[
i * 16 + j];
609 if (current_fragment != -1) {
610 int coded =
s->superblock_coding[
i];
615 if (current_run-- == 0) {
625 s->all_fragments[current_fragment].coding_method =
627 s->coded_fragment_list[plane][num_coded_frags++] =
631 s->all_fragments[current_fragment].coding_method =
639 plane0_num_coded_frags = num_coded_frags;
640 s->total_num_coded_frags += num_coded_frags;
641 for (
int i = 0;
i < 64;
i++)
642 s->num_coded_frags[plane][
i] = num_coded_frags;
644 s->coded_fragment_list[plane + 1] =
s->coded_fragment_list[plane] +
650#define BLOCK_X (2 * mb_x + (k & 1))
651#define BLOCK_Y (2 * mb_y + (k >> 1))
653#if CONFIG_VP4_DECODER
665 if (v >
s->yuv_macroblock_count) {
671 skip_bits(gb, 2 + n); \
672 v += (1 << n) + get_bits(gb, n); }
673#define thresh(n) (0x200 - (0x80 >> n))
674#define else_if(n) else if (bits < thresh(n)) body(n)
677 }
else if (
bits < thresh(0)) {
694static int vp4_get_block_pattern(
GetBitContext *gb,
int *next_block_pattern_table)
696 int v =
get_vlc2(gb, block_pattern_vlc[*next_block_pattern_table], 5, 1);
704 int next_block_pattern_table;
705 int bit, current_run, has_partial;
707 memset(
s->macroblock_coding,
MODE_COPY,
s->macroblock_count);
714 for (
int i = 0;
i <
s->yuv_macroblock_count;
i += current_run) {
717 current_run = vp4_get_mb_count(
s, gb);
718 if (current_run >
s->yuv_macroblock_count -
i)
720 memset(
s->superblock_coding +
i, 2 *
bit, current_run);
729 current_run = vp4_get_mb_count(
s, gb);
730 for (
int i = 0;
i <
s->yuv_macroblock_count;
i++) {
731 if (!
s->superblock_coding[
i]) {
734 current_run = vp4_get_mb_count(
s, gb);
736 s->superblock_coding[
i] =
bit;
744 next_block_pattern_table = 0;
745 for (
int plane = 0,
i = 0; plane < 3; plane++) {
746 int sb_width = plane ?
s->c_superblock_width :
s->y_superblock_width;
747 int sb_height = plane ?
s->c_superblock_height :
s->y_superblock_height;
748 int mb_width = plane ?
s->c_macroblock_width :
s->macroblock_width;
749 int mb_height = plane ?
s->c_macroblock_height :
s->macroblock_height;
750 int fragment_width =
s->fragment_width[!!plane];
751 int fragment_height =
s->fragment_height[!!plane];
753 for (
int sb_y = 0; sb_y < sb_height; sb_y++) {
754 for (
int sb_x = 0; sb_x < sb_width; sb_x++) {
755 for (
int j = 0; j < 4; j++) {
756 int mb_x = 2 * sb_x + (j >> 1);
757 int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
758 int mb_coded, pattern, coded;
760 if (mb_x >= mb_width || mb_y >= mb_height)
763 mb_coded =
s->superblock_coding[
i++];
768 pattern = vp4_get_block_pattern(gb, &next_block_pattern_table);
772 for (
int k = 0; k < 4; k++) {
776 coded = pattern & (8 >> k);
796 int current_macroblock;
797 int current_fragment;
804 for (
int i = 0;
i <
s->fragment_count;
i++)
812 for (
int i = 0;
i < 8;
i++)
814 for (
int i = 0;
i < 8;
i++)
815 custom_mode_alphabet[
get_bits(gb, 3)] =
i;
816 alphabet = custom_mode_alphabet;
822 for (
int sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
823 for (
int sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
827 for (
int j = 0; j < 4; j++) {
829 int mb_x = 2 * sb_x + (j >> 1);
830 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
831 current_macroblock = mb_y *
s->macroblock_width + mb_x;
833 if (mb_x >=
s->macroblock_width ||
834 mb_y >=
s->macroblock_height)
840 for (k = 0; k < 4; k++) {
843 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY)
857 s->macroblock_coding[current_macroblock] = coding_mode;
858 for (k = 0; k < 4; k++) {
864#define SET_CHROMA_MODES \
865 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
866 frag[s->fragment_start[1]].coding_method = coding_mode; \
867 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
868 frag[s->fragment_start[2]].coding_method = coding_mode;
870 if (
s->chroma_y_shift) {
871 frag =
s->all_fragments + mb_y *
872 s->fragment_width[1] + mb_x;
874 }
else if (
s->chroma_x_shift) {
875 frag =
s->all_fragments +
876 2 * mb_y *
s->fragment_width[1] + mb_x;
877 for (k = 0; k < 2; k++) {
879 frag +=
s->fragment_width[1];
882 for (k = 0; k < 4; k++) {
883 frag =
s->all_fragments +
898#if CONFIG_VP4_DECODER
901 return last_motion < 0 ? -v : v;
916 int last_motion_x = 0;
917 int last_motion_y = 0;
918 int prior_last_motion_x = 0;
919 int prior_last_motion_y = 0;
920 int last_gold_motion_x = 0;
921 int last_gold_motion_y = 0;
922 int current_macroblock;
923 int current_fragment;
930 coding_mode =
s->version < 2 ?
get_bits1(gb) : 2;
934 for (
int sb_y = 0; sb_y <
s->y_superblock_height; sb_y++) {
935 for (
int sb_x = 0; sb_x <
s->y_superblock_width; sb_x++) {
939 for (
int j = 0; j < 4; j++) {
940 int mb_x = 2 * sb_x + (j >> 1);
941 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
942 current_macroblock = mb_y *
s->macroblock_width + mb_x;
944 if (mb_x >=
s->macroblock_width ||
945 mb_y >=
s->macroblock_height ||
946 s->macroblock_coding[current_macroblock] ==
MODE_COPY)
949 switch (
s->macroblock_coding[current_macroblock]) {
951 if (coding_mode == 2) {
952 last_gold_motion_x = motion_x[0] =
vp4_get_mv(gb, 0, last_gold_motion_x);
953 last_gold_motion_y = motion_y[0] =
vp4_get_mv(gb, 1, last_gold_motion_y);
959 if (coding_mode == 0) {
964 }
else if (coding_mode == 1) {
968 motion_x[0] =
vp4_get_mv(gb, 0, last_motion_x);
969 motion_y[0] =
vp4_get_mv(gb, 1, last_motion_y);
974 prior_last_motion_x = last_motion_x;
975 prior_last_motion_y = last_motion_y;
976 last_motion_x = motion_x[0];
977 last_motion_y = motion_y[0];
983 prior_last_motion_x = last_motion_x;
984 prior_last_motion_y = last_motion_y;
988 for (
int k = 0; k < 4; k++) {
990 if (
s->all_fragments[current_fragment].coding_method !=
MODE_COPY) {
991 if (coding_mode == 0) {
996 }
else if (coding_mode == 1) {
1000 motion_x[k] =
vp4_get_mv(gb, 0, prior_last_motion_x);
1001 motion_y[k] =
vp4_get_mv(gb, 1, prior_last_motion_y);
1003 last_motion_x = motion_x[k];
1004 last_motion_y = motion_y[k];
1014 motion_x[0] = last_motion_x;
1015 motion_y[0] = last_motion_y;
1024 motion_x[0] = prior_last_motion_x;
1025 motion_y[0] = prior_last_motion_y;
1028 prior_last_motion_x = last_motion_x;
1029 prior_last_motion_y = last_motion_y;
1030 last_motion_x = motion_x[0];
1031 last_motion_y = motion_y[0];
1044 for (
int k = 0; k < 4; k++) {
1048 s->motion_val[0][current_fragment][0] = motion_x[k];
1049 s->motion_val[0][current_fragment][1] = motion_y[k];
1051 s->motion_val[0][current_fragment][0] = motion_x[0];
1052 s->motion_val[0][current_fragment][1] = motion_y[0];
1056 if (
s->chroma_y_shift) {
1058 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] +
1059 motion_x[2] + motion_x[3], 2);
1060 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] +
1061 motion_y[2] + motion_y[3], 2);
1063 if (
s->version <= 2) {
1064 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1065 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
1067 frag = mb_y *
s->fragment_width[1] + mb_x;
1068 s->motion_val[1][frag][0] = motion_x[0];
1069 s->motion_val[1][frag][1] = motion_y[0];
1070 }
else if (
s->chroma_x_shift) {
1072 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
1073 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
1074 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
1075 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
1077 motion_x[1] = motion_x[0];
1078 motion_y[1] = motion_y[0];
1080 if (
s->version <= 2) {
1081 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1082 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
1084 frag = 2 * mb_y *
s->fragment_width[1] + mb_x;
1085 for (
int k = 0; k < 2; k++) {
1086 s->motion_val[1][frag][0] = motion_x[k];
1087 s->motion_val[1][frag][1] = motion_y[k];
1088 frag +=
s->fragment_width[1];
1091 for (
int k = 0; k < 4; k++) {
1094 s->motion_val[1][frag][0] = motion_x[k];
1095 s->motion_val[1][frag][1] = motion_y[k];
1097 s->motion_val[1][frag][0] = motion_x[0];
1098 s->motion_val[1][frag][1] = motion_y[0];
1111 int num_blocks =
s->total_num_coded_frags;
1113 for (
int qpi = 0; qpi <
s->nqps - 1 && num_blocks > 0; qpi++) {
1114 int i = 0, blocks_decoded = 0, num_blocks_at_qpi = 0;
1115 int bit, run_length;
1128 if (run_length == 34)
1130 blocks_decoded += run_length;
1133 num_blocks_at_qpi += run_length;
1135 for (
int j = 0; j < run_length;
i++) {
1136 if (
i >=
s->total_num_coded_frags)
1139 if (
s->all_fragments[
s->coded_fragment_list[0][
i]].qpi == qpi) {
1140 s->all_fragments[
s->coded_fragment_list[0][
i]].qpi +=
bit;
1144 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
1146 num_blocks -= num_blocks_at_qpi;
1162 int bits_to_get, zero_run;
1166 bits_to_get =
get_bits(gb, bits_to_get);
1189 const VLCElem *vlc_table,
int coeff_index,
1199 int num_coeffs =
s->num_coded_frags[plane][coeff_index];
1200 int16_t *dct_tokens =
s->dct_tokens[plane][coeff_index];
1203 const int *coded_fragment_list =
s->coded_fragment_list[plane];
1206 if (num_coeffs < 0) {
1208 "Invalid number of coefficients at level %d\n", coeff_index);
1212 if (eob_run > num_coeffs) {
1214 blocks_ended = num_coeffs;
1215 eob_run -= num_coeffs;
1218 blocks_ended = eob_run;
1224 dct_tokens[j++] = blocks_ended << 2;
1228 token =
get_vlc2(gb, vlc_table, 11, 3);
1230 if ((
unsigned) token <= 6U) {
1237 if (eob_run > num_coeffs - coeff_i) {
1238 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
1239 blocks_ended += num_coeffs - coeff_i;
1240 eob_run -= num_coeffs - coeff_i;
1241 coeff_i = num_coeffs;
1244 blocks_ended += eob_run;
1248 }
else if (token >= 0) {
1249 zero_run =
get_coeff(gb, token, &coeff);
1259 all_fragments[coded_fragment_list[coeff_i]].
dc = coeff;
1264 if (coeff_index + zero_run > 64) {
1266 "Invalid zero run of %d with %d coeffs left\n",
1267 zero_run, 64 - coeff_index);
1268 zero_run = 64 - coeff_index;
1273 for (
int i = coeff_index + 1;
i <= coeff_index + zero_run;
i++)
1274 s->num_coded_frags[plane][
i]--;
1282 if (blocks_ended >
s->num_coded_frags[plane][coeff_index])
1288 for (
int i = coeff_index + 1;
i < 64;
i++)
1289 s->num_coded_frags[plane][
i] -= blocks_ended;
1293 s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1294 else if (coeff_index < 63)
1295 s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1303 int fragment_height);
1315 int residual_eob_run = 0;
1316 const VLCElem *y_tables[64], *c_tables[64];
1318 s->dct_tokens[0][0] =
s->dct_tokens_base;
1329 0, residual_eob_run);
1330 if (residual_eob_run < 0)
1331 return residual_eob_run;
1340 1, residual_eob_run);
1341 if (residual_eob_run < 0)
1342 return residual_eob_run;
1344 2, residual_eob_run);
1345 if (residual_eob_run < 0)
1346 return residual_eob_run;
1351 s->fragment_width[1],
s->fragment_height[1]);
1353 s->fragment_width[1],
s->fragment_height[1]);
1363 for (
int i = 1;
i <= 5;
i++) {
1368 for (
int i = 6;
i <= 14;
i++) {
1373 for (
int i = 15;
i <= 27;
i++) {
1378 for (
int i = 28;
i <= 63;
i++) {
1385 for (
int i = 1;
i <= 63;
i++) {
1387 0, residual_eob_run);
1388 if (residual_eob_run < 0)
1389 return residual_eob_run;
1392 1, residual_eob_run);
1393 if (residual_eob_run < 0)
1394 return residual_eob_run;
1396 2, residual_eob_run);
1397 if (residual_eob_run < 0)
1398 return residual_eob_run;
1404#if CONFIG_VP4_DECODER
1413 int plane,
int eob_tracker[64],
int fragment)
1421 while (!eob_tracker[coeff_i]) {
1428 if ((
unsigned) token <= 6U) {
1430 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1431 eob_tracker[coeff_i] = eob_run - 1;
1433 }
else if (token >= 0) {
1434 zero_run =
get_coeff(gb, token, &coeff);
1437 if (coeff_i + zero_run > 64) {
1439 "Invalid zero run of %d with %d coeffs left\n",
1440 zero_run, 64 - coeff_i);
1441 zero_run = 64 - coeff_i;
1444 coeff_i += zero_run;
1459 *
s->dct_tokens[plane][coeff_i]++ =
TOKEN_EOB(0);
1460 eob_tracker[coeff_i]--;
1472 for (
int i = 0;
i < 4;
i++)
1473 dc_pred[0][
i + 1] =
s->dc_pred_row[sb_x * 4 +
i];
1475 for (
int j = 1; j < 5; j++)
1476 for (
int i = 0;
i < 4;
i++)
1477 vp4_dc_predictor_reset(&dc_pred[j][
i + 1]);
1482 for (
int i = 0;
i < 4;
i++)
1483 s->dc_pred_row[sb_x * 4 +
i] = dc_pred[4][
i + 1];
1485 for (
int i = 1;
i < 5;
i++)
1486 dc_pred[
i][0] = dc_pred[
i][4];
1496 dc += dc_pred[-6].
dc;
1501 dc += dc_pred[6].
dc;
1505 if (count != 2 && dc_pred[-1].
type ==
type) {
1506 dc += dc_pred[-1].
dc;
1510 if (count != 2 && dc_pred[1].
type ==
type) {
1511 dc += dc_pred[1].
dc;
1516 return count == 2 ? dc / 2 : last_dc[
type];
1521 int16_t *
base =
s->dct_tokens_base;
1522 for (
int plane = 0; plane < 3; plane++) {
1523 for (
int i = 0;
i < 64;
i++) {
1524 s->dct_tokens[plane][
i] =
base;
1525 base +=
s->fragment_width[!!plane] *
s->fragment_height[!!plane];
1538 int eob_tracker[64];
1557 for (
int i = 1;
i <= 5;
i++) {
1562 for (
int i = 6;
i <= 14;
i++) {
1567 for (
int i = 15;
i <= 27;
i++) {
1572 for (
int i = 28;
i <= 63;
i++) {
1578 vp4_set_tokens_base(
s);
1580 memset(last_dc, 0,
sizeof(last_dc));
1583 memset(eob_tracker, 0,
sizeof(eob_tracker));
1586 for (
int i = 0;
i <
s->fragment_width[!!plane];
i++)
1587 vp4_dc_predictor_reset(&
s->dc_pred_row[
i]);
1589 for (
int j = 0; j < 6; j++)
1590 for (
int i = 0;
i < 6;
i++)
1591 vp4_dc_predictor_reset(&dc_pred[j][
i]);
1593 for (
int sb_y = 0; sb_y * 4 <
s->fragment_height[!!plane]; sb_y++) {
1594 for (
int sb_x = 0; sb_x *4 <
s->fragment_width[!!plane]; sb_x++) {
1595 vp4_dc_pred_before(
s, dc_pred, sb_x);
1596 for (
int j = 0; j < 16; j++) {
1599 int x = 4 * sb_x + hx;
1600 int y = 4 * sb_y + hy;
1604 if (x >=
s->fragment_width[!!plane] || y >=
s->fragment_height[!!plane])
1607 fragment =
s->fragment_start[plane] + y *
s->fragment_width[!!plane] + x;
1612 if (vp4_unpack_vlcs(
s, gb,
tables[!!plane], plane, eob_tracker,
fragment) < 0)
1618 vp4_dc_pred(
s, this_dc_pred, last_dc, dc_block_type, plane);
1620 this_dc_pred->
type = dc_block_type,
1621 this_dc_pred->
dc = last_dc[dc_block_type] =
s->all_fragments[
fragment].dc;
1623 vp4_dc_pred_after(
s, dc_pred, sb_x);
1628 vp4_set_tokens_base(
s);
1639#define COMPATIBLE_FRAME(x) \
1640 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1641#define DC_COEFF(u) s->all_fragments[u].dc
1646 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 (
int y = 0; y < fragment_height; y++) {
1724 for (
int 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)
1795 int *bounding_values =
s->bounding_values_array + 127;
1797 int width =
s->fragment_width[!!plane];
1798 int height =
s->fragment_height[!!plane];
1800 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
1801 uint8_t *plane_data =
s->current_frame.f->data[plane];
1802 if (!
s->flipped_image)
1804 plane_data +=
s->data_offset[plane] + 8 * ystart *
stride;
1806 for (
int y = ystart; y < yend; y++) {
1807 for (
int x = 0; x <
width; x++) {
1815 s->vp3dsp.h_loop_filter(
1817 stride, bounding_values);
1822 s->vp3dsp.v_loop_filter(
1824 stride, bounding_values);
1830 if ((x <
width - 1) &&
1832 s->vp3dsp.h_loop_filter(
1833 plane_data + 8 * x + 8,
1834 stride, bounding_values);
1842 s->vp3dsp.v_loop_filter(
1843 plane_data + 8 * x + 8 *
stride,
1844 stride, bounding_values);
1850 plane_data += 8 *
stride;
1859 int plane,
int inter, int16_t
block[64])
1861 const int16_t *dequantizer =
s->qmat[frag->
qpi][inter][plane];
1862 const uint8_t *
perm =
s->idct_scantable;
1866 int token = *
s->dct_tokens[plane][
i];
1867 switch (token & 3) {
1870 s->dct_tokens[plane][
i]++;
1872 *
s->dct_tokens[plane][
i] = token & ~3;
1875 s->dct_tokens[plane][
i]++;
1876 i += (token >> 2) & 0x7f;
1886 s->dct_tokens[plane][
i++]++;
1896 block[0] = frag->
dc *
s->qmat[0][inter][plane][0];
1913 y ==
s->height ? INT_MAX : y - 1);
1916 if (!
s->avctx->draw_horiz_band)
1919 h = y -
s->last_slice_end;
1920 s->last_slice_end = y;
1923 if (!
s->flipped_image)
1924 y =
s->height - y -
h;
1926 cy = y >>
s->chroma_y_shift;
1927 offset[0] =
s->current_frame.f->linesize[0] * y;
1928 offset[1] =
s->current_frame.f->linesize[1] * cy;
1929 offset[2] =
s->current_frame.f->linesize[2] * cy;
1933 s->avctx->draw_horiz_band(
s->avctx,
s->current_frame.f,
offset, y, 3,
h);
1941 int motion_y,
int y)
1945 int border = motion_y & 1;
1953 ref_row = y + (motion_y >> 1);
1954 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1959#if CONFIG_VP4_DECODER
1963static int vp4_mc_loop_filter(
Vp3DecodeContext *
s,
int plane,
int motion_x,
int motion_y,
int bx,
int by,
1964 const uint8_t *motion_source, ptrdiff_t
stride,
1965 int src_x,
int src_y, uint8_t *
temp)
1967 int motion_shift = plane ? 4 : 2;
1968 int subpel_mask = plane ? 3 : 1;
1969 int *bounding_values =
s->bounding_values_array + 127;
1973 int x_subpel, y_subpel;
1974 int x_offset, y_offset;
1976 int block_width = plane ? 8 : 16;
1977 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
1978 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
1980#define loop_stride 12
1981 uint8_t
loop[12 * loop_stride];
1984 x = 8 * bx + motion_x / motion_shift;
1985 y = 8 * by + motion_y / motion_shift;
1987 x_subpel = motion_x & subpel_mask;
1988 y_subpel = motion_y & subpel_mask;
1990 if (x_subpel || y_subpel) {
2000 x2 = x + block_width;
2001 y2 = y + block_width;
2003 if (x2 < 0 || x2 >= plane_width || y2 < 0 || y2 >= plane_height)
2006 x_offset = (-(x + 2) & 7) + 2;
2007 y_offset = (-(y + 2) & 7) + 2;
2009 av_assert1(!(x_offset > 8 + x_subpel && y_offset > 8 + y_subpel));
2011 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2013 12, 12, src_x - 1, src_y - 1,
2017 if (x_offset <= 8 + x_subpel)
2020 if (y_offset <= 8 + y_subpel)
2028 if (!x_offset && !y_offset)
2031 s->vdsp.emulated_edge_mc(
loop, motion_source -
stride - 1,
2033 12, 12, src_x - 1, src_y - 1,
2037#define safe_loop_filter(name, ptr, stride, bounding_values) \
2038 if (VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT && (uintptr_t)(ptr) & 7) \
2039 s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \
2041 s->vp3dsp.name(ptr, stride, bounding_values);
2044 safe_loop_filter(h_loop_filter,
loop + loop_stride + x_offset + 1, loop_stride, bounding_values);
2047 safe_loop_filter(v_loop_filter,
loop + (y_offset + 1)*loop_stride + 1, loop_stride, bounding_values);
2050 for (
int i = 0;
i < 9;
i++)
2063 int16_t *
block =
s->block;
2064 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
2069 const AVFrame *last_frame =
s->last_frame.f ?
2070 s->last_frame.f :
s->current_frame.f;
2071 const AVFrame *golden_frame =
s->golden_frame.f ?
2072 s->golden_frame.f :
s->current_frame.f;
2073 int motion_halfpel_index;
2076 if (slice >=
s->c_superblock_height)
2079 for (
int plane = 0; plane < 3; plane++) {
2081 s->data_offset[plane];
2082 const uint8_t *last_plane = last_frame->
data[plane] +
2083 s->data_offset[plane];
2084 const uint8_t *golden_plane = golden_frame->
data[plane] +
2085 s->data_offset[plane];
2086 ptrdiff_t
stride =
s->current_frame.f->linesize[plane];
2087 int plane_width =
s->width >> (plane &&
s->chroma_x_shift);
2088 int plane_height =
s->height >> (plane &&
s->chroma_y_shift);
2089 const int8_t (*motion_val)[2] =
s->motion_val[!!plane];
2091 int sb_y = slice << (!plane &&
s->chroma_y_shift);
2092 int slice_height = sb_y + 1 + (!plane &&
s->chroma_y_shift);
2093 int slice_width = plane ?
s->c_superblock_width
2094 :
s->y_superblock_width;
2096 int fragment_width =
s->fragment_width[!!plane];
2097 int fragment_height =
s->fragment_height[!!plane];
2098 int fragment_start =
s->fragment_start[plane];
2100 int do_await = !plane && HAVE_THREADS &&
2103 if (!
s->flipped_image)
2109 for (; sb_y < slice_height; sb_y++) {
2111 for (
int sb_x = 0; sb_x < slice_width; sb_x++) {
2113 for (
int j = 0; j < 16; j++) {
2116 int fragment = y * fragment_width + x;
2121 if (x >= fragment_width || y >= fragment_height)
2124 first_pixel = 8 * y *
stride + 8 * x;
2130 (16 * y) >>
s->chroma_y_shift);
2133 if (
s->all_fragments[
i].coding_method !=
MODE_COPY) {
2134 const uint8_t *motion_source;
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));
2289#if CONFIG_VP4_DECODER
2290 for (
int j = 0; j < 2; j++)
2291 for (
int i = 0;
i < 7;
i++) {
2292 vp4_mv_vlc_table[j][
i] =
2300 for (
int i = 0;
i < 2;
i++) {
2301 block_pattern_vlc[
i] =
2313 int y_fragment_count, c_fragment_count;
2317 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2318 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2321 s->superblock_coding =
av_mallocz(
FFMAX(
s->superblock_count,
s->yuv_macroblock_count));
2322 s->all_fragments =
av_calloc(
s->fragment_count,
sizeof(*
s->all_fragments));
2324 s-> kf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2325 s->nkf_coded_fragment_list =
av_calloc(
s->fragment_count,
sizeof(
int));
2326 memset(
s-> num_kf_coded_fragment, -1,
sizeof(
s-> num_kf_coded_fragment));
2329 64 *
sizeof(*
s->dct_tokens_base));
2330 s->motion_val[0] =
av_calloc(y_fragment_count,
sizeof(*
s->motion_val[0]));
2331 s->motion_val[1] =
av_calloc(c_fragment_count,
sizeof(*
s->motion_val[1]));
2334 s->superblock_fragments =
av_calloc(
s->superblock_count, 16 *
sizeof(
int));
2335 s->macroblock_coding =
av_mallocz(
s->macroblock_count + 1);
2337 s->dc_pred_row =
av_malloc_array(
s->y_superblock_width * 4,
sizeof(*
s->dc_pred_row));
2339 if (!
s->superblock_coding || !
s->all_fragments ||
2340 !
s->dct_tokens_base || !
s->kf_coded_fragment_list ||
2341 !
s->nkf_coded_fragment_list ||
2342 !
s->superblock_fragments || !
s->macroblock_coding ||
2344 !
s->motion_val[0] || !
s->motion_val[1]) {
2369 int y_fragment_count, c_fragment_count;
2373#if !CONFIG_VP4_DECODER
2394 for (
int i = 0;
i < 64;
i++) {
2395#define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
2403 for (
int i = 0;
i < 3;
i++)
2410 s->y_superblock_width = (
s->width + 31) / 32;
2411 s->y_superblock_height = (
s->height + 31) / 32;
2412 s->y_superblock_count =
s->y_superblock_width *
s->y_superblock_height;
2415 c_width =
s->width >>
s->chroma_x_shift;
2416 c_height =
s->height >>
s->chroma_y_shift;
2417 s->c_superblock_width = (c_width + 31) / 32;
2418 s->c_superblock_height = (c_height + 31) / 32;
2419 s->c_superblock_count =
s->c_superblock_width *
s->c_superblock_height;
2421 s->superblock_count =
s->y_superblock_count + (
s->c_superblock_count * 2);
2422 s->u_superblock_start =
s->y_superblock_count;
2423 s->v_superblock_start =
s->u_superblock_start +
s->c_superblock_count;
2425 s->macroblock_width = (
s->width + 15) / 16;
2426 s->macroblock_height = (
s->height + 15) / 16;
2427 s->macroblock_count =
s->macroblock_width *
s->macroblock_height;
2428 s->c_macroblock_width = (c_width + 15) / 16;
2429 s->c_macroblock_height = (c_height + 15) / 16;
2430 s->c_macroblock_count =
s->c_macroblock_width *
s->c_macroblock_height;
2431 s->yuv_macroblock_count =
s->macroblock_count + 2 *
s->c_macroblock_count;
2435 s->fragment_width[1] =
s->fragment_width[0] >>
s->chroma_x_shift;
2436 s->fragment_height[1] =
s->fragment_height[0] >>
s->chroma_y_shift;
2439 y_fragment_count =
s->fragment_width[0] *
s->fragment_height[0];
2440 c_fragment_count =
s->fragment_width[1] *
s->fragment_height[1];
2441 s->fragment_count = y_fragment_count + 2 * c_fragment_count;
2442 s->fragment_start[1] = y_fragment_count;
2443 s->fragment_start[2] = y_fragment_count + c_fragment_count;
2445 if (!
s->theora_tables) {
2446 for (
int i = 0;
i < 64;
i++) {
2456 for (
int inter = 0; inter < 2; inter++) {
2457 for (
int plane = 0; plane < 3; plane++) {
2458 s->qr_count[inter][plane] = 1;
2459 s->qr_size[inter][plane][0] = 63;
2460 s->qr_base[inter][plane][0] =
2461 s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
2474 s->coeff_vlc = vlcs;
2476 if (!
s->theora_tables) {
2477 const uint8_t (*bias_tabs)[32][2];
2483 &bias_tabs[
i][0][1], 2,
2484 &bias_tabs[
i][0][0], 2, 1,
2495 &
tab->entries[0].len,
sizeof(*
tab->entries),
2496 &
tab->entries[0].sym,
sizeof(*
tab->entries), 1,
2521 int qps_changed = 0;
2523#if CONFIG_THEORA_DECODER
2536 for (
int i = 0;
i < 3;
i++) {
2537 if (
s->qps[
i] != s1->
qps[
i]) {
2539 memcpy(&
s->qmat[
i], &s1->
qmat[
i],
sizeof(
s->qmat[
i]));
2543 if (
s->qps[0] != s1->
qps[0])
2545 sizeof(
s->bounding_values_array));
2548 memcpy(
s->qps, s1->
qps,
sizeof(
s->qps));
2559 const uint8_t *buf = avpkt->
data;
2560 int buf_size = avpkt->
size;
2565#if CONFIG_THEORA_DECODER
2567 size_t new_headers_size;
2580 memcpy(headers, new_headers, new_headers_size);
2592#if CONFIG_THEORA_DECODER
2598 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2612 }
else if (
type == 2) {
2625 "Header packet passed to frame decoder, skipping\n");
2631 if (!
s->all_fragments) {
2639 for (
int i = 0;
i < 3;
i++)
2640 last_qps[
i] =
s->qps[
i];
2645 }
while (
s->theora >= 0x030200 &&
s->nqps < 3 &&
get_bits1(&gb));
2646 for (
int i =
s->nqps;
i < 3;
i++)
2651 s->keyframe ?
"key" :
"", avctx->
frame_num + 1,
s->qps[0]);
2653 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2657 if (
s->qps[0] != last_qps[0])
2660 for (
int i = 0;
i <
s->nqps;
i++)
2663 if (
s->qps[
i] != last_qps[
i] ||
s->qps[0] != last_qps[0])
2684 if (!
s->edge_emu_buffer) {
2685 s->edge_emu_buffer =
av_malloc(9 *
FFABS(
s->current_frame.f->linesize[0]));
2686 if (!
s->edge_emu_buffer) {
2698#if !CONFIG_VP4_DECODER
2708 "VP version: %d\n",
s->version);
2711 if (
s->version ||
s->theora) {
2714 "Warning, unsupported keyframe coding type?!\n");
2717#if CONFIG_VP4_DECODER
2718 if (
s->version >= 2) {
2719 int mb_height, mb_width;
2720 int mb_width_mul, mb_width_div, mb_height_mul, mb_height_div;
2724 if (mb_height !=
s->macroblock_height ||
2725 mb_width !=
s->macroblock_width)
2732 if (mb_width_mul != 1 || mb_width_div != 1 || mb_height_mul != 1 || mb_height_div != 1)
2742 if (!
s->golden_frame.f) {
2744 "vp3: first frame not a keyframe\n");
2756 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 (
int 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 (
int i = 0;
i <
s->c_superblock_height;
i++)
2812 for (
int i = 0;
i < 3;
i++) {
2813 int row = (
s->height >> (3 + (
i &&
s->chroma_y_shift))) - 1;
2824 frame->crop_left =
s->offset_x;
2826 frame->crop_top =
s->offset_y;
2850 ff_dlog(avctx,
"code length %d, curr entry %d, token %d\n",
2868#if CONFIG_THEORA_DECODER
2876 int visible_width, visible_height, colorspace;
2877 uint8_t offset_x = 0, offset_y = 0;
2884 s->theora_header = 0;
2894 if (
s->theora < 0x030200) {
2895 s->flipped_image = 1;
2897 "Old (<alpha3) Theora bitstream, flipped image\n");
2905 if (
s->theora >= 0x030200) {
2915 visible_width + offset_x >
s->width ||
2916 visible_height + offset_y >
s->height ||
2917 visible_width + 512 <
s->width ||
2918 visible_height + 512 <
s->height ||
2922 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2923 visible_width, visible_height, offset_x, offset_y,
2924 s->width,
s->height);
2930 if (fps.
num && fps.
den) {
2931 if (fps.
num < 0 || fps.
den < 0) {
2936 fps.
den, fps.
num, 1 << 30);
2941 if (aspect.
num && aspect.
den) {
2944 aspect.
num, aspect.
den, 1 << 30);
2948 if (
s->theora < 0x030200)
2955 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 n, matrices,
ret;
2999 if (!
s->theora_header)
3002 if (
s->theora >= 0x030200) {
3006 for (
int i = 0;
i < 64;
i++)
3010 if (
s->theora >= 0x030200)
3015 for (
int i = 0;
i < 64;
i++)
3016 s->coded_ac_scale_factor[
i] =
get_bits(gb, n);
3018 if (
s->theora >= 0x030200)
3023 for (
int 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 (
int j = 0; j < matrices; j++)
3038 for (
int i = 0;
i < 64;
i++)
3041 for (
int inter = 0; inter <= 1; inter++) {
3042 for (
int 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;
3101 const uint8_t *headers,
3107 const uint8_t *header_start[3];
3115 if (!headers_size) {
3121 42, header_start, header_len) < 0) {
3126 for (
int i = 0;
i < 3;
i++) {
3127 if (header_len[
i] <= 0)
3135 if (!(ptype & 0x80)) {
3158 "Unknown Theora config packet: %d\n", ptype & ~0x80);
3163 "%d bits left in packet %X\n",
3165 if (
s->theora < 0x030200)
3174 return theora_init_from_headers(avctx, avctx->
extradata,
3190 s->headers_size = headers_size;
3191 ret = theora_init_from_headers(avctx,
s->headers,
s->headers_size);
3207 .
init = theora_decode_init,
3237#if CONFIG_VP4_DECODER
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_theora_decoder
const FFCodec ff_vp3_decoder
const FFCodec ff_vp4_decoder
static const VLCElem * coeff_vlc[2][8][4]
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Libavcodec external API header.
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define FF_DEBUG_PICT_INFO
#define i(width, name, range_min, range_max)
#define bit(string, value)
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AV_NUM_DATA_POINTERS
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define AV_CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static const int8_t transform[32][32]
static VLCElem vlc_tables[VLC_TABLES_SIZE]
static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst, ptrdiff_t dst_pitch, int dst_height)
Convert and output the current plane.
const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
#define u(width, name, range_min, range_max)
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
Multithreading API for decoders.
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
void ff_vp3dsp_set_bounding_values(int *bounding_values_array, int filter_limit)
av_cold void ff_vp3dsp_init(VP3DSPContext *c)
Macro definitions for various function/variable attributes.
static int ff_thread_once(char *control, void(*routine)(void))
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
const uint8_t ff_zigzag_direct[64]
static void body(uint32_t ABCD[4], const uint8_t *src, size_t nblocks)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AVCOL_TRC_BT709
also ITU-R BT1361
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int flags2
AV_CODEC_FLAG2_*.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int64_t frame_num
Frame counter, set by libavcodec.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
const VLCElem * vlc_tabs[80]
The ProgressFrame structure.
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
uint16_t coded_dc_scale_factor[2][64]
int num_coded_frags[3][64]
number of blocks that contain DCT coefficients at the given level or higher
CoeffVLCs * coeff_vlc
The first 16 of the following VLCs are for the dc coefficients; the others are four groups of 16 VLCs...
ProgressFrame golden_frame
int8_t(*[2] motion_val)[2]
uint8_t base_matrix[384][64]
int * kf_coded_fragment_list
VP4Predictor * dc_pred_row
uint32_t coded_ac_scale_factor[64]
int16_t * dct_tokens_base
uint8_t idct_permutation[64]
uint8_t * headers
Headers taken from packet side data, NULL while the codec extradata applies; a RefStruct reference,...
ProgressFrame current_frame
unsigned char * macroblock_coding
uint8_t * edge_emu_buffer
int num_kf_coded_fragment[3]
int * coded_fragment_list[3]
int bounding_values_array[256+4]
int total_num_coded_frags
HuffTable huffman_table[5 *16]
uint8_t filter_limit_values[64]
int16_t * dct_tokens[3][64]
This is a list of all tokens in bitstream order.
Vp3Fragment * all_fragments
unsigned char * superblock_coding
int * nkf_coded_fragment_list
uint8_t qr_size[2][3][64]
int16_t qmat[3][2][3][64]
qmat[qpi][is_inter][plane]
uint8_t idct_scantable[64]
uint16_t qr_base[2][3][64]
int * superblock_fragments
#define av_malloc_array(a, b)
#define avpriv_request_sample(...)
static void error(const char *err)
static struct @232240247175332074307271266321204261331170211232 state
static const uint8_t *const tables[]
static const struct twinvq_data tab
RefStruct is an API for creating reference-counted objects with minimal overhead.
Core video DSP helper functions.
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
av_cold const VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
void ff_vlc_free(VLC *vlc)
#define VLC_INIT_STATE(_table)
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
static const VLCElem * ff_vlc_init_tables(VLCInitState *state, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, int flags)
static int vp4_get_mv(GetBitContext *gb, int axis, int last_motion)
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
#define CODING_MODE_COUNT
static av_cold int vp3_decode_init(AVCodecContext *avctx)
#define COMPATIBLE_FRAME(x)
static void init_loop_filter(Vp3DecodeContext *s)
#define MODE_INTER_PRIOR_LAST
static int get_eob_run(GetBitContext *gb, int token)
static void reverse_dc_prediction(Vp3DecodeContext *s, int first_fragment, int fragment_width, int fragment_height)
#define TOKEN_EOB(eob_run)
static void init_dequantizer(Vp3DecodeContext *s, int qpi)
static VLCElem motion_vector_vlc[112]
static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
static av_cold int allocate_tables(AVCodecContext *avctx)
Allocate tables for per-frame data in Vp3DecodeContext.
static av_cold void free_vlc_tables(AVRefStructOpaque unused, void *obj)
static VLCElem mode_code_vlc[24+2108 *CONFIG_VP4_DECODER]
static av_cold void free_tables(AVCodecContext *avctx)
static int vp3_dequant(Vp3DecodeContext *s, const Vp3Fragment *frag, int plane, int inter, int16_t block[64])
Pull DCT tokens from the 64 levels to decode and dequant the coefficients for the next block in codin...
#define MODE_INTER_LAST_MV
static av_cold void vp3_decode_flush(AVCodecContext *avctx)
#define MAXIMUM_LONG_BIT_RUN
static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, const VLCElem *vlc_table, int coeff_index, int plane, int eob_run)
static void render_slice(Vp3DecodeContext *s, int slice)
#define MODE_INTER_FOURMV
#define SB_PARTIALLY_CODED
static void await_reference_row(Vp3DecodeContext *s, const Vp3Fragment *fragment, int motion_y, int y)
Wait for the reference frame of the current fragment.
static int read_huffman_tree(HuffTable *huff, GetBitContext *gb, int length, AVCodecContext *avctx)
static VLCElem superblock_run_length_vlc[88]
static const uint8_t vp4_pred_block_type_map[8]
#define SUPERBLOCK_VLC_BITS
static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
static av_cold int vp3_decode_end(AVCodecContext *avctx)
static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
#define MODE_USING_GOLDEN
static int init_block_mapping(Vp3DecodeContext *s)
This function sets up all of the various blocks mappings: superblocks <-> fragments,...
static int theora_reinit(AVCodecContext *avctx, uint8_t *headers, int headers_size)
#define MODE_INTER_PLUS_MV
static const int ModeAlphabet[6][CODING_MODE_COUNT]
static av_cold void init_tables_once(void)
static int get_coeff(GetBitContext *gb, int token, int16_t *coeff)
static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend)
static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
#define TOKEN_COEFF(coeff)
static const uint8_t hilbert_offset[16][2]
#define TOKEN_ZERO_RUN(coeff, zero_run)
static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y)
called when all pixels up to row y are complete
static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
static VLCElem fragment_run_length_vlc[56]
static const uint8_t zero_run_get_bits[32]
static const uint8_t vp31_filter_limit_values[64]
static const uint16_t vp31_ac_scale_factor[64]
static const uint8_t mode_code_vlc_len[8]
static const uint8_t zero_run_base[32]
static const int8_t fixed_motion_vector_table[64]
static const int16_t *const coeff_tables[32]
static const uint8_t vp31_dc_scale_factor[64]
static const uint8_t vp3_bias[5 *16][32][2]
static const uint8_t fragment_run_length_vlc_len[30]
static const uint8_t vp31_intra_y_dequant[64]
static const struct @370321105316032037314210141206274253244133335364 eob_run_table[7]
static const uint8_t vp31_inter_dequant[64]
static const uint8_t coeff_get_bits[32]
static const uint8_t motion_vector_vlc_table[63][2]
static const uint8_t superblock_run_length_vlc_lens[34]
void ff_vp3dsp_h_loop_filter_12(uint8_t *first_pixel, ptrdiff_t stride, int *bounding_values)
void ff_vp3dsp_v_loop_filter_12(uint8_t *first_pixel, ptrdiff_t stride, int *bounding_values)
static const uint8_t vp4_mv_vlc[2][7][63][2]
static const uint8_t vp4_filter_limit_values[64]
static const uint8_t vp4_uv_dc_scale_factor[64]
static const uint8_t vp4_block_pattern_table_selector[14]
static const uint8_t vp4_mv_table_selector[32]
static const uint8_t vp4_block_pattern_vlc[2][14][2]
static const uint16_t vp4_ac_scale_factor[64]
static const uint8_t vp4_bias[5 *16][32][2]
static const uint8_t vp4_generic_dequant[64]
static const uint8_t vp4_y_dc_scale_factor[64]
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.