36 #include "libavutil/imgutils.h"
48 #define FRAGMENT_PIXELS 8
57 #define SB_NOT_CODED 0
58 #define SB_PARTIALLY_CODED 1
59 #define SB_FULLY_CODED 2
64 #define MAXIMUM_LONG_BIT_RUN 4129
66 #define MODE_INTER_NO_MV 0
68 #define MODE_INTER_PLUS_MV 2
69 #define MODE_INTER_LAST_MV 3
70 #define MODE_INTER_PRIOR_LAST 4
71 #define MODE_USING_GOLDEN 5
72 #define MODE_GOLDEN_MV 6
73 #define MODE_INTER_FOURMV 7
74 #define CODING_MODE_COUNT 8
125 {0,0}, {1,0}, {1,1}, {0,1},
126 {0,2}, {0,3}, {1,3}, {1,2},
127 {2,2}, {2,3}, {3,3}, {3,2},
128 {3,1}, {2,1}, {2,0}, {3,0}
131 #define MIN_DEQUANT_VAL 2
209 #define TOKEN_EOB(eob_run) ((eob_run) << 2)
210 #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) << 9) + ((zero_run) << 2) + 1)
211 #define TOKEN_COEFF(coeff) (((coeff) << 2) + 2)
303 for (i = 0; i < 16; i++) {
329 int sb_x, sb_y, plane;
332 for (plane = 0; plane < 3; plane++) {
338 for (sb_y = 0; sb_y < sb_height; sb_y++)
339 for (sb_x = 0; sb_x < sb_width; sb_x++)
340 for (i = 0; i < 16; i++) {
342 y = 4*sb_y + hilbert_offset[i][1];
344 if (x < frag_width && y < frag_height)
362 int i, plane, inter, qri, bmi, bmj, qistart;
364 for(inter=0; inter<2; inter++){
365 for(plane=0; plane<3; plane++){
367 for(qri=0; qri<s->
qr_count[inter][plane]; qri++){
368 sum+= s->
qr_size[inter][plane][qri];
369 if(s->
qps[qpi] <= sum)
372 qistart= sum - s->
qr_size[inter][plane][qri];
373 bmi= s->
qr_base[inter][plane][qri ];
374 bmj= s->
qr_base[inter][plane][qri+1];
378 + s->
qr_size[inter][plane][qri])
379 / (2*s->
qr_size[inter][plane][qri]);
381 int qmin= 8<<(inter + !i);
382 int qscale= i ? ac_scale_factor : dc_scale_factor;
385 av_clip((qscale * coeff) / 100 * 4, qmin, 4096);
388 s->
qmat[qpi][inter][plane][0] = s->
qmat[0][inter][plane][0];
411 for (x = 0; x < filter_limit; x++) {
412 bounding_values[-x] = -x;
413 bounding_values[x] = x;
415 for (x = value = filter_limit; x < 128 &&
value; x++, value--) {
416 bounding_values[ x] =
value;
417 bounding_values[-x] = -
value;
420 bounding_values[128] =
value;
421 bounding_values[129] = bounding_values[130] = filter_limit * 0x02020202;
432 int current_superblock = 0;
434 int num_partial_superblocks = 0;
437 int current_fragment;
449 while (current_superblock < s->superblock_count &&
get_bits_left(gb) > 0) {
457 if (current_run == 34)
467 current_superblock += current_run;
469 num_partial_superblocks += current_run;
474 if (num_partial_superblocks < s->superblock_count) {
475 int superblocks_decoded = 0;
477 current_superblock = 0;
481 while (superblocks_decoded < s->superblock_count - num_partial_superblocks
491 if (current_run == 34)
494 for (j = 0; j < current_run; current_superblock++) {
506 superblocks_decoded += current_run;
512 if (num_partial_superblocks) {
527 for (plane = 0; plane < 3; plane++) {
528 int sb_start = superblock_starts[plane];
530 int num_coded_frags = 0;
532 for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
535 for (j = 0; j < 16; j++) {
539 if (current_fragment != -1) {
546 if (current_run-- == 0) {
570 for (i = 0; i < 64; i++)
584 int i, j, k, sb_x, sb_y;
586 int current_macroblock;
587 int current_fragment;
604 for (i = 0; i < 8; i++)
606 for (i = 0; i < 8; i++)
607 custom_mode_alphabet[
get_bits(gb, 3)] = i;
608 alphabet = custom_mode_alphabet;
619 for (j = 0; j < 4; j++) {
620 int mb_x = 2*sb_x + (j>>1);
621 int mb_y = 2*sb_y + (((j>>1)+j)&1);
627 #define BLOCK_X (2*mb_x + (k&1))
628 #define BLOCK_Y (2*mb_y + (k>>1))
631 for (k = 0; k < 4; k++) {
645 coding_mode = alphabet
649 for (k = 0; k < 4; k++) {
655 #define SET_CHROMA_MODES \
656 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
657 frag[s->fragment_start[1]].coding_method = coding_mode;\
658 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
659 frag[s->fragment_start[2]].coding_method = coding_mode;
666 for (k = 0; k < 2; k++) {
671 for (k = 0; k < 4; k++) {
690 int j, k, sb_x, sb_y;
694 int last_motion_x = 0;
695 int last_motion_y = 0;
696 int prior_last_motion_x = 0;
697 int prior_last_motion_y = 0;
698 int current_macroblock;
699 int current_fragment;
715 for (j = 0; j < 4; j++) {
716 int mb_x = 2*sb_x + (j>>1);
717 int mb_y = 2*sb_y + (((j>>1)+j)&1);
729 if (coding_mode == 0) {
740 prior_last_motion_x = last_motion_x;
741 prior_last_motion_y = last_motion_y;
742 last_motion_x = motion_x[0];
743 last_motion_y = motion_y[0];
749 prior_last_motion_x = last_motion_x;
750 prior_last_motion_y = last_motion_y;
754 for (k = 0; k < 4; k++) {
757 if (coding_mode == 0) {
764 last_motion_x = motion_x[k];
765 last_motion_y = motion_y[k];
775 motion_x[0] = last_motion_x;
776 motion_y[0] = last_motion_y;
785 motion_x[0] = prior_last_motion_x;
786 motion_y[0] = prior_last_motion_y;
789 prior_last_motion_x = last_motion_x;
790 prior_last_motion_y = last_motion_y;
791 last_motion_x = motion_x[0];
792 last_motion_y = motion_y[0];
805 for (k = 0; k < 4; k++) {
809 s->
motion_val[0][current_fragment][0] = motion_x[k];
810 s->
motion_val[0][current_fragment][1] = motion_y[k];
812 s->
motion_val[0][current_fragment][0] = motion_x[0];
813 s->
motion_val[0][current_fragment][1] = motion_y[0];
819 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2);
820 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2);
822 motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1);
823 motion_y[0] = (motion_y[0]>>1) | (motion_y[0]&1);
829 motion_x[0] =
RSHIFT(motion_x[0] + motion_x[1], 1);
830 motion_y[0] =
RSHIFT(motion_y[0] + motion_y[1], 1);
831 motion_x[1] =
RSHIFT(motion_x[2] + motion_x[3], 1);
832 motion_y[1] =
RSHIFT(motion_y[2] + motion_y[3], 1);
834 motion_x[1] = motion_x[0];
835 motion_y[1] = motion_y[0];
837 motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1);
838 motion_x[1] = (motion_x[1]>>1) | (motion_x[1]&1);
841 for (k = 0; k < 2; k++) {
847 for (k = 0; k < 4; k++) {
867 int qpi, i, j, bit, run_length, blocks_decoded, num_blocks_at_qpi;
870 for (qpi = 0; qpi < s->
nqps-1 && num_blocks > 0; qpi++) {
871 i = blocks_decoded = num_blocks_at_qpi = 0;
883 if (run_length == 34)
885 blocks_decoded += run_length;
888 num_blocks_at_qpi += run_length;
890 for (j = 0; j < run_length; i++) {
899 }
while (blocks_decoded < num_blocks &&
get_bits_left(gb) > 0);
901 num_blocks -= num_blocks_at_qpi;
932 int16_t *dct_tokens = s->
dct_tokens[plane][coeff_index];
942 if (eob_run > num_coeffs) {
943 coeff_i = blocks_ended = num_coeffs;
944 eob_run -= num_coeffs;
946 coeff_i = blocks_ended = eob_run;
952 dct_tokens[j++] = blocks_ended << 2;
956 token =
get_vlc2(gb, vlc_table, 11, 3);
958 if ((
unsigned) token <= 6
U) {
965 if (eob_run > num_coeffs - coeff_i) {
966 dct_tokens[j++] =
TOKEN_EOB(num_coeffs - coeff_i);
967 blocks_ended += num_coeffs - coeff_i;
968 eob_run -= num_coeffs - coeff_i;
969 coeff_i = num_coeffs;
972 blocks_ended += eob_run;
976 }
else if (token >= 0) {
979 bits_to_get =
get_bits(gb, bits_to_get);
994 all_fragments[coded_fragment_list[coeff_i]].
dc =
coeff;
999 if (coeff_index + zero_run > 64) {
1001 " %d coeffs left\n", zero_run, 64-coeff_index);
1002 zero_run = 64 - coeff_index;
1007 for (i = coeff_index+1; i <= coeff_index+zero_run; i++)
1012 "Invalid token %d\n", token);
1023 for (i = coeff_index+1; i < 64; i++)
1028 s->
dct_tokens[plane+1][coeff_index] = dct_tokens + j;
1029 else if (coeff_index < 63)
1030 s->
dct_tokens[0][coeff_index+1] = dct_tokens + j;
1038 int fragment_height);
1050 int residual_eob_run = 0;
1062 0, residual_eob_run);
1063 if (residual_eob_run < 0)
1064 return residual_eob_run;
1071 1, residual_eob_run);
1072 if (residual_eob_run < 0)
1073 return residual_eob_run;
1075 2, residual_eob_run);
1076 if (residual_eob_run < 0)
1077 return residual_eob_run;
1093 for (i = 1; i <= 5; i++) {
1094 y_tables[i] = &s->
ac_vlc_1[ac_y_table];
1095 c_tables[i] = &s->
ac_vlc_1[ac_c_table];
1097 for (i = 6; i <= 14; i++) {
1098 y_tables[i] = &s->
ac_vlc_2[ac_y_table];
1099 c_tables[i] = &s->
ac_vlc_2[ac_c_table];
1101 for (i = 15; i <= 27; i++) {
1102 y_tables[i] = &s->
ac_vlc_3[ac_y_table];
1103 c_tables[i] = &s->
ac_vlc_3[ac_c_table];
1105 for (i = 28; i <= 63; i++) {
1106 y_tables[i] = &s->
ac_vlc_4[ac_y_table];
1107 c_tables[i] = &s->
ac_vlc_4[ac_c_table];
1111 for (i = 1; i <= 63; i++) {
1112 residual_eob_run =
unpack_vlcs(s, gb, y_tables[i], i,
1113 0, residual_eob_run);
1114 if (residual_eob_run < 0)
1115 return residual_eob_run;
1117 residual_eob_run =
unpack_vlcs(s, gb, c_tables[i], i,
1118 1, residual_eob_run);
1119 if (residual_eob_run < 0)
1120 return residual_eob_run;
1121 residual_eob_run =
unpack_vlcs(s, gb, c_tables[i], i,
1122 2, residual_eob_run);
1123 if (residual_eob_run < 0)
1124 return residual_eob_run;
1135 #define COMPATIBLE_FRAME(x) \
1136 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1137 #define DC_COEFF(u) s->all_fragments[u].dc
1142 int fragment_height)
1151 int i = first_fragment;
1156 int vl, vul, vu, vur;
1168 static const int predictor_transform[16][4] = {
1193 static const unsigned char compatible_frame[9] = {
1204 int current_frame_type;
1211 vul = vu = vur = vl = 0;
1212 last_dc[0] = last_dc[1] = last_dc[2] = 0;
1215 for (y = 0; y < fragment_height; y++) {
1218 for (x = 0; x < fragment_width; x++, i++) {
1223 current_frame_type =
1234 u= i-fragment_width;
1239 ul= i-fragment_width-1;
1244 if(x + 1 < fragment_width){
1245 ur= i-fragment_width+1;
1252 if (transform == 0) {
1256 predicted_dc = last_dc[current_frame_type];
1261 (predictor_transform[
transform][0] * vul) +
1262 (predictor_transform[transform][1] * vu) +
1263 (predictor_transform[
transform][2] * vur) +
1264 (predictor_transform[transform][3] * vl);
1266 predicted_dc /= 128;
1270 if ((transform == 15) || (transform == 13)) {
1271 if (
FFABS(predicted_dc - vu) > 128)
1273 else if (
FFABS(predicted_dc - vl) > 128)
1275 else if (
FFABS(predicted_dc - vul) > 128)
1283 last_dc[current_frame_type] =
DC_COEFF(i);
1302 for (y = ystart; y < yend; y++) {
1304 for (x = 0; x <
width; x++) {
1315 stride, bounding_values);
1322 stride, bounding_values);
1328 if ((x < width - 1) &&
1331 plane_data + 8*x + 8,
1332 stride, bounding_values);
1338 if ((y < height - 1) &&
1341 plane_data + 8*x + 8*stride,
1342 stride, bounding_values);
1357 int plane,
int inter, int16_t
block[64])
1359 int16_t *dequantizer = s->
qmat[frag->
qpi][inter][plane];
1365 switch (token & 3) {
1374 i += (token >> 2) & 0x7f;
1379 block[perm[i]] = (token >> 9) * dequantizer[perm[i]];
1383 block[perm[i]] = (token >> 2) * dequantizer[perm[i]];
1394 block[0] = frag->
dc * s->
qmat[0][inter][plane][0];
1445 int border = motion_y&1;
1453 ref_row = y + (motion_y>>1);
1454 ref_row =
FFMAX(
FFABS(ref_row), ref_row + 8 + border);
1465 int x,
y, i, j, fragment;
1467 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
1468 int motion_halfpel_index;
1470 int plane, first_pixel;
1475 for (plane = 0; plane < 3; plane++) {
1482 int8_t (*motion_val)[2] = s->
motion_val[!!plane];
1498 for (; sb_y < slice_height; sb_y++) {
1501 for (sb_x = 0; sb_x < slice_width; sb_x++) {
1504 for (j = 0; j < 16; j++) {
1506 y = 4*sb_y + hilbert_offset[j][1];
1507 fragment = y*fragment_width + x;
1509 i = fragment_start + fragment;
1512 if (x >= fragment_width || y >= fragment_height)
1515 first_pixel = 8*y*stride + 8*x;
1524 motion_source= golden_plane;
1526 motion_source= last_plane;
1528 motion_source += first_pixel;
1529 motion_halfpel_index = 0;
1536 motion_x = motion_val[fragment][0];
1537 motion_y = motion_val[fragment][1];
1539 src_x= (motion_x>>1) + 8*x;
1540 src_y= (motion_y>>1) + 8*y;
1542 motion_halfpel_index = motion_x & 0x01;
1543 motion_source += (motion_x >> 1);
1545 motion_halfpel_index |= (motion_y & 0x01) << 1;
1546 motion_source += ((motion_y >> 1) * stride);
1548 if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){
1550 if(stride<0) temp -= 8*
stride;
1553 motion_source, stride,
1555 plane_width, plane_height);
1556 motion_source=
temp;
1568 if(motion_halfpel_index != 3){
1570 output_plane + first_pixel,
1571 motion_source,
stride, 8);
1573 int d= (motion_x ^ motion_y)>>31;
1575 output_plane + first_pixel,
1577 motion_source + stride + 1 + d,
1587 output_plane + first_pixel,
1593 output_plane + first_pixel,
1604 output_plane + first_pixel,
1605 last_plane + first_pixel,
1633 int y_fragment_count, c_fragment_count;
1680 int i, inter, plane,
ret;
1683 int y_fragment_count, c_fragment_count;
1706 for (i = 0; i < 64; i++) {
1707 #define T(x) (x >> 3) | ((x & 7) << 3)
1715 for (i = 0; i < 3; i++)
1753 for (i = 0; i < 64; i++) {
1762 for(inter=0; inter<2; inter++){
1763 for(plane=0; plane<3; plane++){
1765 s->
qr_size [inter][plane][0]= 63;
1767 s->
qr_base [inter][plane][1]= 2*inter + (!!plane)*!inter;
1772 for (i = 0; i < 16; i++) {
1801 for (i = 0; i < 16; i++) {
1883 if (src->
f->
data[0])
1901 int qps_changed = 0, i, err;
1903 #define copy_fields(to, from, start_field, end_field) memcpy(&to->start_field, &from->start_field, (char*)&to->end_field - (char*)&to->start_field)
1905 if (!
s1->current_frame.f->data[0]
1916 int y_fragment_count, c_fragment_count;
1934 for (i = 0; i < 3; i++) {
1935 if (s->
qps[i] !=
s1->qps[1]) {
1937 memcpy(&s->
qmat[i], &
s1->qmat[i],
sizeof(s->
qmat[i]));
1941 if (s->
qps[0] !=
s1->qps[0])
1953 void *
data,
int *got_frame,
1957 int buf_size = avpkt->
size;
1964 #if CONFIG_THEORA_DECODER
1971 av_log(avctx,
AV_LOG_ERROR,
"midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
1983 }
else if (type == 2) {
2004 for (i = 0; i < 3; i++)
2010 }
while(
s->theora >= 0x030200 &&
s->nqps<3 &&
get_bits1(&gb));
2011 for (i =
s->nqps; i < 3; i++)
2016 s->keyframe?
"key":
"", avctx->frame_number+1,
s->qps[0]);
2018 s->skip_loop_filter = !
s->filter_limit_values[
s->qps[0]] ||
2021 if (
s->qps[0] !=
s->last_qps[0])
2024 for (i = 0; i <
s->nqps; i++)
2027 if (
s->qps[i] !=
s->last_qps[i] ||
s->qps[0] !=
s->last_qps[0])
2034 s->current_frame.f->key_frame =
s->keyframe;
2038 if (!
s->edge_emu_buffer)
2049 if (avctx->frame_number == 0)
2053 if (
s->version ||
s->theora)
2060 if (!
s->golden_frame.f->data[0]) {
2073 memset(
s->all_fragments, 0,
s->fragment_count *
sizeof(
Vp3Fragment));
2097 for (i = 0; i < 3; i++) {
2098 int height =
s->height >> (i &&
s->chroma_y_shift);
2099 if (
s->flipped_image)
2100 s->data_offset[i] = 0;
2102 s->data_offset[i] = (height-1) *
s->current_frame.f->linesize[i];
2105 s->last_slice_end = 0;
2106 for (i = 0; i <
s->c_superblock_height; i++)
2110 for (i = 0; i < 3; i++) {
2111 int row = (
s->height >> (3+(i &&
s->chroma_y_shift))) - 1;
2148 av_dlog(avctx,
"hti %d hbits %x token %d entry : %d size %d\n",
2189 #if CONFIG_THEORA_DECODER
2197 int visible_width, visible_height,
colorspace;
2198 int offset_x = 0, offset_y = 0;
2206 if (s->
theora < 0x030200)
2221 if (s->
theora >= 0x030200) {
2231 if (fps.
num && fps.
den) {
2232 if (fps.
num < 0 || fps.
den < 0) {
2237 fps.
den, fps.
num, 1<<30);
2242 if (aspect.
num && aspect.
den) {
2245 aspect.
num, aspect.
den, 1<<30);
2248 if (s->
theora < 0x030200)
2255 if (s->
theora >= 0x030200)
2268 if ( visible_width <= s->
width && visible_width > s->
width-16
2269 && visible_height <= s->height && visible_height > s->
height-16
2270 && !offset_x && (offset_y == s->
height - visible_height))
2275 if (colorspace == 1) {
2277 }
else if (colorspace == 2) {
2280 if (colorspace == 1 || colorspace == 2) {
2291 int i,
n, matrices, inter, plane;
2293 if (s->
theora >= 0x030200) {
2297 for (i = 0; i < 64; i++)
2301 if (s->
theora >= 0x030200)
2306 for (i = 0; i < 64; i++)
2309 if (s->
theora >= 0x030200)
2314 for (i = 0; i < 64; i++)
2317 if (s->
theora >= 0x030200)
2327 for(n=0; n<matrices; n++){
2328 for (i = 0; i < 64; i++)
2332 for (inter = 0; inter <= 1; inter++) {
2333 for (plane = 0; plane <= 2; plane++) {
2335 if (inter || plane > 0)
2343 qtj= (3*inter + plane - 1) / 3;
2344 plj= (plane + 2) % 3;
2359 s->
qr_base[inter][plane][qri]= i;
2363 s->
qr_size[inter][plane][qri++]= i;
2377 for (s->
hti = 0; s->
hti < 80; s->
hti++) {
2415 42, header_start, header_len) < 0) {
2421 if (header_len[i] <= 0)
2427 if (!(ptype & 0x80))
2456 if (s->
theora < 0x030200)
2469 .
init = theora_decode_init,
static const int16_t vp31_intra_y_dequant[64]
void(* put_no_rnd_pixels_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
Copy 8xH pixels from source to destination buffer using a bilinear filter with no rounding (i...
uint8_t idct_scantable[64]
discard all frames except keyframes
#define AVERROR_PATCHWELCOME
int16_t qmat[3][2][3][64]
qmat[qpi][is_inter][plane]
static int init_block_mapping(Vp3DecodeContext *s)
This function sets up all of the various blocks mappings: superblocks <-> fragments, macroblocks <-> fragments, superblocks <-> macroblocks.
void(* idct_put)(uint8_t *dest, int line_size, int16_t *block)
void(* h_loop_filter)(uint8_t *src, int stride, int *bounding_values)
#define TOKEN_EOB(eob_run)
static void render_slice(Vp3DecodeContext *s, int slice)
void(* emulated_edge_mc)(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride, int block_w, int block_h, int src_x, int src_y, int w, int h)
Copy a rectangular area of samples to a temporary buffer and replicate the border samples...
int bounding_values_array[256+2]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint16_t qr_base[2][3][64]
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
static struct endianess table[]
static const uint16_t fragment_run_length_vlc_table[30][2]
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define MODE_INTER_PLUS_MV
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
static av_cold int init_frames(Vp3DecodeContext *s)
#define DECLARE_ALIGNED(n, t, v)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_cold int vp3_decode_init(AVCodecContext *avctx)
static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static void reverse_dc_prediction(Vp3DecodeContext *s, int first_fragment, int fragment_width, int fragment_height)
static av_cold int vp3_decode_end(AVCodecContext *avctx)
int * superblock_fragments
VLC superblock_run_length_vlc
static const uint32_t vp31_ac_scale_factor[64]
#define MAXIMUM_LONG_BIT_RUN
static const int motion_vector_table[63]
static const uint16_t ac_bias_3[16][32][2]
static const uint16_t dc_bias[16][32][2]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Vp3Fragment * all_fragments
static void init_loop_filter(Vp3DecodeContext *s)
#define COMPATIBLE_FRAME(x)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
void(* idct_dc_add)(uint8_t *dest, int line_size, int16_t *block)
static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
#define TOKEN_ZERO_RUN(coeff, zero_run)
static const uint8_t offset[511][2]
static int vp3_dequant(Vp3DecodeContext *s, 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...
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
uint8_t idct_permutation[64]
static void init_dequantizer(Vp3DecodeContext *s, int qpi)
const char * name
Name of the codec implementation.
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
static void vp3_decode_flush(AVCodecContext *avctx)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t filter_limit_values[64]
static int get_bits_count(const GetBitContext *s)
struct AVCodecInternal * internal
Private context used for internal data.
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
bitstream reader API header.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_NUM_DATA_POINTERS
static const uint8_t mode_code_vlc_table[8][2]
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
static const int16_t vp31_inter_dequant[64]
static const uint16_t ac_bias_1[16][32][2]
static int ref_frames(Vp3DecodeContext *dst, Vp3DecodeContext *src)
static int get_bits_left(GetBitContext *gb)
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static const uint8_t motion_vector_vlc_table[63][2]
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst, int dst_pitch, int dst_height)
Convert and output the current plane.
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
#define CODING_MODE_COUNT
static const int zero_run_base[32]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int active_thread_type
Which multithreading methods are in use by the codec.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const int8_t fixed_motion_vector_table[64]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Libavcodec external API header.
AVPixelFormat
Pixel format.
static const int ModeAlphabet[6][CODING_MODE_COUNT]
static const int16_t vp31_intra_c_dequant[64]
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
static const int coeff_get_bits[32]
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static const int16_t *const coeff_tables[32]
unsigned char * macroblock_coding
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
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...
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
VLC fragment_run_length_vlc
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
int width
picture width / height.
#define SB_PARTIALLY_CODED
static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, VLC *table, int coeff_index, int plane, int eob_run)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint8_t * edge_emu_buffer
void(* idct_add)(uint8_t *dest, int line_size, int16_t *block)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static const uint16_t ac_bias_2[16][32][2]
static const uint8_t hilbert_offset[16][2]
void avcodec_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.
int total_num_coded_frags
static void flush(AVCodecContext *avctx)
static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend)
static const int8_t transform[32][32]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define AV_LOG_INFO
Standard information.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
static const uint16_t ac_bias_0[16][32][2]
int16_t * dct_tokens[3][64]
This is a list of all tokens in bitstream order.
ThreadFrame current_frame
main external API structure.
static void close(AVCodecParserContext *s)
#define FF_THREAD_FRAME
Decode more than one frame at once.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
uint8_t qr_size[2][3][64]
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
static av_cold int allocate_tables(AVCodecContext *avctx)
Allocate tables for per-frame data in Vp3DecodeContext.
static unsigned int get_bits1(GetBitContext *s)
BYTE int const BYTE int int int height
#define MKTAG(a, b, c, d)
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
static void skip_bits(GetBitContext *s, int n)
enum AVColorSpace colorspace
YUV colorspace type.
rational number numerator/denominator
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, int first_header_size, uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use. ...
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int num_coded_frags[3][64]
number of blocks that contain DCT coefficients at the given level or higher
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
#define TOKEN_COEFF(coeff)
int allocate_progress
Whether to allocate progress for frame threading.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
static int update_frames(AVCodecContext *avctx)
Release and shuffle frames after decode finishes.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
static const uint16_t superblock_run_length_vlc_table[34][2]
#define MODE_USING_GOLDEN
uint32_t huffman_table[80][32][2]
#define FF_DEBUG_PICT_INFO
#define MODE_INTER_FOURMV
#define copy_fields(to, from, start_field, end_field)
int * coded_fragment_list[3]
unsigned char * superblock_coding
common internal api header.
const uint8_t ff_zigzag_direct[64]
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void(* v_loop_filter)(uint8_t *src, int stride, int *bounding_values)
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
int16_t * dct_tokens_base
static int ref_frame(Vp3DecodeContext *s, ThreadFrame *dst, ThreadFrame *src)
static const int eob_run_get_bits[7]
static int vp3_init_thread_copy(AVCodecContext *avctx)
static const int16_t vp31_dc_scale_factor[64]
uint16_t coded_dc_scale_factor[64]
Core video DSP helper functions.
uint8_t base_matrix[384][64]
static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
#define AVERROR_INVALIDDATA
static void await_reference_row(Vp3DecodeContext *s, Vp3Fragment *fragment, int motion_y, int y)
Wait for the reference frame of the current fragment.
VLC_TYPE(* table)[2]
code, bits
static const double coeff[2][5]
#define MODE_INTER_PRIOR_LAST
static const int eob_run_base[7]
static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
static int init_thread_copy(AVCodecContext *avctx)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define MODE_INTER_LAST_MV
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...
enum AVColorSpace colorspace
static const int zero_run_get_bits[32]
av_cold void ff_vp3dsp_init(VP3DSPContext *c, int flags)
static const uint8_t vp31_filter_limit_values[64]
This structure stores compressed data.
static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y)
called when all pixels up to row y are complete
void ff_free_vlc(VLC *vlc)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t coded_ac_scale_factor[64]
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int8_t(*[2] motion_val)[2]