Go to the documentation of this file.
23 #define UNCHECKED_BITSTREAM_READER 1
25 #include "config_components.h"
53 #define SPRITE_TRAJ_VLC_BITS 6
55 #define MB_TYPE_B_VLC_BITS 4
56 #define STUDIO_INTRA_BITS 9
75 uint8_t *dest_cr,
int block_size,
int uvlinesize,
76 int dct_linesize,
int dct_offset)
79 const int act_block_size = block_size * 2;
81 if (
ctx->dpcm_direction == 0) {
82 s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)
ctx->block32[0]);
83 s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)
ctx->block32[1]);
84 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)
ctx->block32[2]);
85 s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)
ctx->block32[3]);
87 dct_linesize = uvlinesize <<
s->interlaced_dct;
88 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
90 s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)
ctx->block32[4]);
91 s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)
ctx->block32[5]);
92 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)
ctx->block32[6]);
93 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)
ctx->block32[7]);
94 if (!
s->chroma_x_shift){
95 s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)
ctx->block32[8]);
96 s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)
ctx->block32[9]);
97 s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[10]);
98 s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[11]);
100 }
else if (
ctx->dpcm_direction == 1) {
101 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
102 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
103 for (
int i = 0;
i < 3;
i++) {
104 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
105 int vsub =
i ?
s->chroma_y_shift : 0;
106 int hsub =
i ?
s->chroma_x_shift : 0;
109 for (
int h = 0;
h < (16 >> (vsub +
lowres));
h++){
111 dest_pcm[
i][
w] =
src[idx];
112 dest_pcm[
i] += linesize[
i] / 2;
117 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
118 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
120 for (
int i = 0;
i < 3;
i++) {
121 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
122 int vsub =
i ?
s->chroma_y_shift : 0;
123 int hsub =
i ?
s->chroma_x_shift : 0;
126 dest_pcm[
i] += (linesize[
i] / 2) * ((16 >> vsub) - 1);
127 for (
int h = (16 >> (vsub +
lowres)) - 1;
h >= 0;
h--){
129 dest_pcm[
i][
w] =
src[idx];
131 dest_pcm[
i] -= linesize[
i] / 2;
145 int16_t *ac_val, *ac_val1;
146 int8_t *
const qscale_table =
s->current_picture.qscale_table;
149 ac_val = &
s->ac_val[0][0][0] +
s->block_index[n] * 16;
153 const int xy =
s->mb_x - 1 +
s->mb_y *
s->mb_stride;
157 if (
s->mb_x == 0 ||
s->qscale == qscale_table[xy] ||
160 for (
i = 1;
i < 8;
i++)
161 block[
s->idsp.idct_permutation[
i << 3]] += ac_val[
i];
164 for (
i = 1;
i < 8;
i++)
165 block[
s->idsp.idct_permutation[
i << 3]] +=
ROUNDED_DIV(ac_val[
i] * qscale_table[xy],
s->qscale);
168 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride -
s->mb_stride;
170 ac_val -= 16 *
s->block_wrap[n];
172 if (
s->mb_y == 0 ||
s->qscale == qscale_table[xy] ||
175 for (
i = 1;
i < 8;
i++)
176 block[
s->idsp.idct_permutation[
i]] += ac_val[
i + 8];
179 for (
i = 1;
i < 8;
i++)
185 for (
i = 1;
i < 8;
i++)
186 ac_val1[
i] =
block[
s->idsp.idct_permutation[
i << 3]];
190 ac_val1[8 +
i] =
block[
s->idsp.idct_permutation[
i]];
208 (v >> (8 -
s->pict_type) != 1) ||
s->partitioned_frame)
211 bits_count += 8 +
s->pict_type;
215 if (bits_count + 8 >=
s->gb.size_in_bits) {
217 v |= 0x7F >> (7 - (bits_count & 7));
224 int mb_num_bits =
av_log2(
s->mb_num - 1) + 1;
235 if (!mb_num || mb_num >
s->mb_num ||
get_bits_count(&
s->gb)+6 >
s->gb.size_in_bits)
250 int a = 2 <<
s->sprite_warping_accuracy;
251 int rho = 3 -
s->sprite_warping_accuracy;
257 int min_ab,
i, w2, h2, w3, h3;
258 int sprite_ref[4][2];
259 int virtual_ref[2][2];
260 int64_t sprite_offset[2][2];
261 int64_t sprite_delta[2][2];
264 const int vop_ref[4][2] = { { 0, 0 }, {
s->width, 0 },
265 { 0,
s->height }, {
s->width,
s->height } };
266 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
268 if (
w <= 0 ||
h <= 0)
271 for (
i = 0;
i <
ctx->num_sprite_warping_points;
i++) {
279 if (!(
ctx->divx_version == 500 &&
ctx->divx_build == 413))
287 ctx->sprite_traj[
i][0] =
d[
i][0] = x;
288 ctx->sprite_traj[
i][1] =
d[
i][1] = y;
291 ctx->sprite_traj[
i][0] =
ctx->sprite_traj[
i][1] = 0;
295 while ((1 << beta) <
h)
301 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413) {
302 sprite_ref[0][0] =
a * vop_ref[0][0] +
d[0][0];
303 sprite_ref[0][1] =
a * vop_ref[0][1] +
d[0][1];
304 sprite_ref[1][0] =
a * vop_ref[1][0] +
d[0][0] +
d[1][0];
305 sprite_ref[1][1] =
a * vop_ref[1][1] +
d[0][1] +
d[1][1];
306 sprite_ref[2][0] =
a * vop_ref[2][0] +
d[0][0] +
d[2][0];
307 sprite_ref[2][1] =
a * vop_ref[2][1] +
d[0][1] +
d[2][1];
309 sprite_ref[0][0] = (
a >> 1) * (2 * vop_ref[0][0] +
d[0][0]);
310 sprite_ref[0][1] = (
a >> 1) * (2 * vop_ref[0][1] +
d[0][1]);
311 sprite_ref[1][0] = (
a >> 1) * (2 * vop_ref[1][0] +
d[0][0] +
d[1][0]);
312 sprite_ref[1][1] = (
a >> 1) * (2 * vop_ref[1][1] +
d[0][1] +
d[1][1]);
313 sprite_ref[2][0] = (
a >> 1) * (2 * vop_ref[2][0] +
d[0][0] +
d[2][0]);
314 sprite_ref[2][1] = (
a >> 1) * (2 * vop_ref[2][1] +
d[0][1] +
d[2][1]);
324 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
326 (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
327 w2 * (
r * sprite_ref[1][0] - 16LL * vop_ref[1][0])),
w);
328 virtual_ref[0][1] = 16 * vop_ref[0][1] +
330 (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
331 w2 * (
r * sprite_ref[1][1] - 16LL * vop_ref[1][1])),
w);
332 virtual_ref[1][0] = 16 * vop_ref[0][0] +
333 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
334 h2 * (
r * sprite_ref[2][0] - 16LL * vop_ref[2][0])),
h);
335 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
336 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
337 h2 * (
r * sprite_ref[2][1] - 16LL * vop_ref[2][1])),
h);
339 switch (
ctx->num_sprite_warping_points) {
341 sprite_offset[0][0] =
342 sprite_offset[0][1] =
343 sprite_offset[1][0] =
344 sprite_offset[1][1] = 0;
345 sprite_delta[0][0] =
a;
347 sprite_delta[1][0] = 0;
348 sprite_delta[1][1] =
a;
349 ctx->sprite_shift[0] =
350 ctx->sprite_shift[1] = 0;
353 sprite_offset[0][0] = sprite_ref[0][0] -
a * vop_ref[0][0];
354 sprite_offset[0][1] = sprite_ref[0][1] -
a * vop_ref[0][1];
355 sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
356 a * (vop_ref[0][0] / 2);
357 sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
358 a * (vop_ref[0][1] / 2);
359 sprite_delta[0][0] =
a;
361 sprite_delta[1][0] = 0;
362 sprite_delta[1][1] =
a;
363 ctx->sprite_shift[0] =
364 ctx->sprite_shift[1] = 0;
367 sprite_offset[0][0] = ((int64_t) sprite_ref[0][0] * (1 <<
alpha + rho)) +
368 ((int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
369 ((int64_t) -vop_ref[0][0]) +
370 ((int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
371 ((int64_t) -vop_ref[0][1]) + (1 << (
alpha + rho - 1));
372 sprite_offset[0][1] = ((int64_t) sprite_ref[0][1] * (1 <<
alpha + rho)) +
373 ((int64_t) -
r * sprite_ref[0][1] + virtual_ref[0][1]) *
374 ((int64_t) -vop_ref[0][0]) +
375 ((int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
376 ((int64_t) -vop_ref[0][1]) + (1 << (
alpha + rho - 1));
377 sprite_offset[1][0] = (((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
378 ((int64_t)-2 * vop_ref[0][0] + 1) +
379 ((int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
380 ((int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
381 (int64_t) sprite_ref[0][0] - 16 * w2 + (1 << (
alpha + rho + 1)));
382 sprite_offset[1][1] = (((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) *
383 ((int64_t)-2 * vop_ref[0][0] + 1) +
384 ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
385 ((int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
386 (int64_t) sprite_ref[0][1] - 16 * w2 + (1 << (
alpha + rho + 1)));
387 sprite_delta[0][0] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
388 sprite_delta[0][1] = (+
r * sprite_ref[0][1] - virtual_ref[0][1]);
389 sprite_delta[1][0] = (-
r * sprite_ref[0][1] + virtual_ref[0][1]);
390 sprite_delta[1][1] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
393 ctx->sprite_shift[1] =
alpha + rho + 2;
399 sprite_offset[0][0] = ((int64_t)sprite_ref[0][0] * (1 << (
alpha + beta + rho - min_ab))) +
400 ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
401 ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
402 ((int64_t)1 << (
alpha + beta + rho - min_ab - 1));
403 sprite_offset[0][1] = ((int64_t)sprite_ref[0][1] * (1 << (
alpha + beta + rho - min_ab))) +
404 ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
405 ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
406 ((int64_t)1 << (
alpha + beta + rho - min_ab - 1));
407 sprite_offset[1][0] = ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
408 ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
409 (int64_t)2 * w2 * h3 *
r * sprite_ref[0][0] - 16 * w2 * h3 +
410 ((int64_t)1 << (
alpha + beta + rho - min_ab + 1));
411 sprite_offset[1][1] = ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
412 ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
413 (int64_t)2 * w2 * h3 *
r * sprite_ref[0][1] - 16 * w2 * h3 +
414 ((int64_t)1 << (
alpha + beta + rho - min_ab + 1));
415 sprite_delta[0][0] = (-
r * (int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
416 sprite_delta[0][1] = (-
r * (int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
417 sprite_delta[1][0] = (-
r * (int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
418 sprite_delta[1][1] = (-
r * (int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
420 ctx->sprite_shift[0] =
alpha + beta + rho - min_ab;
421 ctx->sprite_shift[1] =
alpha + beta + rho - min_ab + 2;
425 if (sprite_delta[0][0] ==
a <<
ctx->sprite_shift[0] &&
426 sprite_delta[0][1] == 0 &&
427 sprite_delta[1][0] == 0 &&
428 sprite_delta[1][1] ==
a <<
ctx->sprite_shift[0]) {
429 sprite_offset[0][0] >>=
ctx->sprite_shift[0];
430 sprite_offset[0][1] >>=
ctx->sprite_shift[0];
431 sprite_offset[1][0] >>=
ctx->sprite_shift[1];
432 sprite_offset[1][1] >>=
ctx->sprite_shift[1];
433 sprite_delta[0][0] =
a;
434 sprite_delta[0][1] = 0;
435 sprite_delta[1][0] = 0;
436 sprite_delta[1][1] =
a;
437 ctx->sprite_shift[0] = 0;
438 ctx->sprite_shift[1] = 0;
439 s->real_sprite_warping_points = 1;
441 int shift_y = 16 -
ctx->sprite_shift[0];
442 int shift_c = 16 -
ctx->sprite_shift[1];
444 for (
i = 0;
i < 2;
i++) {
445 if (shift_c < 0 || shift_y < 0 ||
446 FFABS( sprite_offset[0][
i]) >= INT_MAX >> shift_y ||
447 FFABS( sprite_offset[1][
i]) >= INT_MAX >> shift_c ||
448 FFABS( sprite_delta[0][
i]) >= INT_MAX >> shift_y ||
449 FFABS( sprite_delta[1][
i]) >= INT_MAX >> shift_y
456 for (
i = 0;
i < 2;
i++) {
457 sprite_offset[0][
i] *= 1 << shift_y;
458 sprite_offset[1][
i] *= 1 << shift_c;
459 sprite_delta[0][
i] *= 1 << shift_y;
460 sprite_delta[1][
i] *= 1 << shift_y;
461 ctx->sprite_shift[
i] = 16;
464 for (
i = 0;
i < 2;
i++) {
466 sprite_delta[
i][0] -
a * (1LL<<16),
467 sprite_delta[
i][1] -
a * (1LL<<16)
470 if (llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
471 llabs(sprite_offset[0][
i] + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
472 llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL) + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
473 llabs(sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
474 llabs(sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
475 llabs(sd[0]) >= INT_MAX ||
476 llabs(sd[1]) >= INT_MAX ||
477 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL)) >= INT_MAX ||
478 llabs(sprite_offset[0][
i] + sd[1] * (
h+16LL)) >= INT_MAX ||
479 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL) + sd[1] * (
h+16LL)) >= INT_MAX
485 s->real_sprite_warping_points =
ctx->num_sprite_warping_points;
488 for (
i = 0;
i < 4;
i++) {
489 s->sprite_offset[
i&1][
i>>1] = sprite_offset[
i&1][
i>>1];
490 s->sprite_delta [
i&1][
i>>1] = sprite_delta [
i&1][
i>>1];
495 memset(
s->sprite_offset, 0,
sizeof(
s->sprite_offset));
496 memset(
s->sprite_delta, 0,
sizeof(
s->sprite_delta));
520 int mb_num_bits =
av_log2(
s->mb_num - 1) + 1;
521 int header_extension = 0, mb_num,
len;
542 if (mb_num >=
s->mb_num || !mb_num) {
544 "illegal mb_num in video packet (%d %d) \n", mb_num,
s->mb_num);
548 s->mb_x = mb_num %
s->mb_width;
549 s->mb_y = mb_num /
s->mb_width;
552 int qscale =
get_bits(&
s->gb,
s->quant_precision);
554 s->chroma_qscale =
s->qscale = qscale;
560 if (header_extension) {
566 check_marker(
s->avctx, &
s->gb,
"before time_increment in video packed header");
568 check_marker(
s->avctx, &
s->gb,
"before vop_coding_type in video packed header");
589 "Error, video packet header damaged (f_code=0)\n");
595 "Error, video packet header damaged (b_code=0)\n");
610 s->last_dc[2] = 1 << (
s->avctx->bits_per_raw_sample +
s->dct_precision +
s->intra_dc_precision - 1);
625 vlc_len =
av_log2(
s->mb_width *
s->mb_height) + 1;
628 if (mb_num >=
s->mb_num)
631 s->mb_x = mb_num %
s->mb_width;
632 s->mb_y = mb_num /
s->mb_width;
662 int x, y, mb_v, sum, dx, dy,
shift;
663 int len = 1 << (
s->f_code + 4);
664 const int a =
s->sprite_warping_accuracy;
667 len >>=
s->quarter_sample;
669 if (
s->real_sprite_warping_points == 1) {
670 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413 &&
a >=
s->quarter_sample)
671 sum =
s->sprite_offset[0][n] / (1 << (
a -
s->quarter_sample));
673 sum =
RSHIFT(
s->sprite_offset[0][n] * (1 <<
s->quarter_sample),
a);
675 dx =
s->sprite_delta[n][0];
676 dy =
s->sprite_delta[n][1];
679 dy -= 1 << (
shift +
a + 1);
681 dx -= 1 << (
shift +
a + 1);
682 mb_v =
s->sprite_offset[0][n] + dx *
s->mb_x * 16
U + dy *
s->mb_y * 16
U;
685 for (y = 0; y < 16; y++) {
690 for (x = 0; x < 16; x++) {
695 sum =
RSHIFT(sum,
a + 8 -
s->quarter_sample);
721 if (code < 0 || code > 9 ) {
763 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
766 s->first_slice_line = 1;
767 for (;
s->mb_y <
s->mb_height;
s->mb_y++) {
769 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
770 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
776 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1)
777 s->first_slice_line = 0;
789 "mcbpc corrupted at %d %d\n",
s->mb_x,
s->mb_y);
794 s->cbp_table[xy] = cbpc & 3;
801 s->current_picture.qscale_table[xy] =
s->qscale;
803 s->mbintra_table[xy] = 1;
804 for (
i = 0;
i < 6;
i++) {
809 "DC corrupted at %d %d\n",
s->mb_x,
s->mb_y);
816 s->pred_dir_table[xy] = dir;
818 int mx, my, pred_x, pred_y,
bits;
819 int16_t *
const mot_val =
s->current_picture.motion_val[0][
s->block_index[0]];
820 const int stride =
s->b8_stride * 2;
828 if (
bits & 0x10000) {
853 if (
s->mbintra_table[xy])
861 "mcbpc corrupted at %d %d\n",
s->mb_x,
s->mb_y);
867 s->cbp_table[xy] = cbpc & (8 + 3);
869 s->mb_intra = ((cbpc & 4) != 0);
873 s->mbintra_table[xy] = 1;
883 if (
s->mbintra_table[xy])
893 if ((cbpc & 16) == 0) {
927 for (
i = 0;
i < 4;
i++) {
956 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
958 s->mb_x =
s->resync_mb_x;
959 s->first_slice_line = 1;
960 for (
s->mb_y =
s->resync_mb_y; mb_num < mb_count; s->mb_y++) {
962 for (; mb_num < mb_count &&
s->mb_x <
s->mb_width;
s->mb_x++) {
963 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
967 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1)
968 s->first_slice_line = 0;
975 "cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
979 s->cbp_table[xy] |= cbpy << 2;
982 if (
IS_INTRA(
s->current_picture.mb_type[xy])) {
990 "I cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
994 if (
s->cbp_table[xy] & 8)
996 s->current_picture.qscale_table[xy] =
s->qscale;
998 for (
i = 0;
i < 6;
i++) {
1003 "DC corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1010 s->cbp_table[xy] &= 3;
1011 s->cbp_table[xy] |= cbpy << 2;
1013 s->pred_dir_table[xy] = dir;
1014 }
else if (
IS_SKIP(
s->current_picture.mb_type[xy])) {
1015 s->current_picture.qscale_table[xy] =
s->qscale;
1016 s->cbp_table[xy] = 0;
1022 "P cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1026 if (
s->cbp_table[xy] & 8)
1028 s->current_picture.qscale_table[xy] =
s->qscale;
1030 s->cbp_table[xy] &= 3;
1031 s->cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1035 if (mb_num >= mb_count)
1057 s->mb_x,
s->mb_y, part_a_error);
1061 if (
s->resync_mb_x +
s->resync_mb_y *
s->mb_width + mb_num >
s->mb_num) {
1064 s->mb_x,
s->mb_y, part_a_error);
1068 s->mb_num_left = mb_num;
1075 "marker missing after first I partition at %d %d\n",
1084 "marker missing after first P partition at %d %d\n",
1090 s->mb_x - 1,
s->mb_y, part_a_end);
1112 int n,
int coded,
int intra,
1113 int use_intra_dc_vlc,
int rvlc)
1120 const uint8_t *scan_table;
1125 if (use_intra_dc_vlc) {
1127 if (
s->partitioned_frame) {
1128 level =
s->dc_val[0][
s->block_index[n]];
1133 dc_pred_dir = (
s->pred_dir_table[
s->mb_x +
s->mb_y *
s->mb_stride] << n) & 32;
1156 if (dc_pred_dir == 0)
1157 scan_table =
s->intra_v_scantable.permutated;
1159 scan_table =
s->intra_h_scantable.permutated;
1161 scan_table =
s->intra_scantable.permutated;
1168 s->block_last_index[n] =
i;
1176 scan_table =
s->intra_scantable.permutated;
1178 if (
s->mpeg_quant) {
1186 qmul =
s->qscale << 1;
1187 qadd = (
s->qscale - 1) | 1;
1204 "1. marker bit missing in rvlc esc\n");
1217 "2. marker bit missing in rvlc esc\n");
1243 cache ^= 0xC0000000;
1245 if (cache & 0x80000000) {
1246 if (cache & 0x40000000) {
1261 "1. marker bit missing in 3. esc\n");
1272 "2. marker bit missing in 3. esc\n");
1281 if (
s->error_recognition >= FF_ER_COMPLIANT) {
1284 const int run1=
run - rl->
max_run[last][abs_level] - 1;
1285 if (abs_level <= rl->max_level[last][
run]) {
1289 if (
s->error_recognition > FF_ER_COMPLIANT) {
1290 if (abs_level <= rl->max_level[last][
run]*2) {
1294 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1307 if ((
unsigned)(
level + 2048) > 4095) {
1311 "|level| overflow in 3. esc, qp=%d\n",
1345 ff_tlog(
s->avctx,
"dct[%d][%d] = %- 4d end?:%d\n", scan_table[
i&63]&7, scan_table[
i&63] >> 3,
level,
i>62);
1350 "ac-tex damaged at %d %d\n",
s->mb_x,
s->mb_y);
1365 if (!use_intra_dc_vlc) {
1375 s->block_last_index[n] =
i;
1386 int cbp, mb_type, use_intra_dc_vlc;
1387 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1391 mb_type =
s->current_picture.mb_type[xy];
1392 cbp =
s->cbp_table[xy];
1394 use_intra_dc_vlc =
s->qscale <
ctx->intra_dc_threshold;
1396 if (
s->current_picture.qscale_table[xy] !=
s->qscale)
1402 for (
i = 0;
i < 4;
i++) {
1403 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
1404 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
1410 for (
i = 0;
i < 6;
i++)
1411 s->block_last_index[
i] = -1;
1422 }
else if (
s->mb_intra) {
1423 s->ac_pred =
IS_ACPRED(
s->current_picture.mb_type[xy]);
1424 }
else if (!
s->mb_intra) {
1436 s->ac_pred =
IS_ACPRED(
s->current_picture.mb_type[xy]);
1441 s->bdsp.clear_blocks(
s->block[0]);
1443 for (
i = 0;
i < 6;
i++) {
1445 use_intra_dc_vlc,
ctx->rvlc) < 0) {
1447 "texture corrupted at %d %d %d\n",
1448 s->mb_x,
s->mb_y,
s->mb_intra);
1456 if (--
s->mb_num_left <= 0) {
1463 const int delta =
s->mb_x + 1 ==
s->mb_width ? 2 : 1;
1464 if (
s->cbp_table[xy +
delta])
1474 int cbpc, cbpy,
i, cbp, pred_x, pred_y, mx, my, dquant;
1476 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1477 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1488 for (
i = 0;
i < 6;
i++)
1489 s->block_last_index[
i] = -1;
1516 "mcbpc damaged at %d %d\n",
s->mb_x,
s->mb_y);
1519 }
while (cbpc == 20);
1521 s->bdsp.clear_blocks(
s->block[0]);
1523 s->mb_intra = ((cbpc & 4) != 0);
1535 "P cbpy damaged at %d %d\n",
s->mb_x,
s->mb_y);
1539 cbp = (cbpc & 3) | (cbpy << 2);
1542 if ((!
s->progressive_sequence) &&
1547 if ((cbpc & 16) == 0) {
1556 s->mv[0][0][0] = mx;
1557 s->mv[0][0][1] = my;
1558 }
else if ((!
s->progressive_sequence) &&
get_bits1(&
s->gb)) {
1570 for (
i = 0;
i < 2;
i++) {
1579 s->mv[0][
i][0] = mx;
1580 s->mv[0][
i][1] = my;
1596 s->mv[0][0][0] = mx;
1597 s->mv[0][0][1] = my;
1602 for (
i = 0;
i < 4;
i++) {
1611 s->mv[0][
i][0] = mx;
1612 s->mv[0][
i][1] = my;
1626 for (
i = 0;
i < 2;
i++) {
1627 s->last_mv[
i][0][0] =
1628 s->last_mv[
i][0][1] =
1629 s->last_mv[
i][1][0] =
1630 s->last_mv[
i][1][1] = 0;
1637 s->mb_skipped =
s->next_picture.mbskip_table[
s->mb_y *
s->mb_stride +
s->mb_x];
1639 if (
s->mb_skipped) {
1641 for (
i = 0;
i < 6;
i++)
1642 s->block_last_index[
i] = -1;
1672 s->bdsp.clear_blocks(
s->block[0]);
1681 if (!
s->progressive_sequence) {
1709 s->last_mv[0][1][0] =
1710 s->last_mv[0][0][0] =
1711 s->mv[0][0][0] = mx;
1712 s->last_mv[0][1][1] =
1713 s->last_mv[0][0][1] =
1714 s->mv[0][0][1] = my;
1722 s->last_mv[1][1][0] =
1723 s->last_mv[1][0][0] =
1724 s->mv[1][0][0] = mx;
1725 s->last_mv[1][1][1] =
1726 s->last_mv[1][0][1] =
1727 s->mv[1][0][1] = my;
1735 for (
i = 0;
i < 2;
i++) {
1738 s->last_mv[0][
i][0] =
1739 s->mv[0][
i][0] = mx;
1740 s->last_mv[0][
i][1] = (
s->mv[0][
i][1] = my) * 2;
1747 for (
i = 0;
i < 2;
i++) {
1750 s->last_mv[1][
i][0] =
1751 s->mv[1][
i][0] = mx;
1752 s->last_mv[1][
i][1] = (
s->mv[1][
i][1] = my) * 2;
1770 s->current_picture.mb_type[xy] = mb_type;
1772 int use_intra_dc_vlc;
1778 "I cbpc damaged at %d %d\n",
s->mb_x,
s->mb_y);
1781 }
while (cbpc == 8);
1796 "I cbpy damaged at %d %d\n",
s->mb_x,
s->mb_y);
1799 cbp = (cbpc & 3) | (cbpy << 2);
1801 use_intra_dc_vlc =
s->qscale <
ctx->intra_dc_threshold;
1806 if (!
s->progressive_sequence)
1809 s->bdsp.clear_blocks(
s->block[0]);
1811 for (
i = 0;
i < 6;
i++) {
1813 1, use_intra_dc_vlc, 0) < 0)
1821 for (
i = 0;
i < 6;
i++) {
1832 if (
s->mb_x +
s->mb_y*
s->mb_width + 1 > next && (
s->avctx->err_recognition &
AV_EF_AGGRESSIVE)) {
1834 }
else if (
s->mb_x +
s->mb_y*
s->mb_width + 1 >= next)
1838 const int delta=
s->mb_x + 1 ==
s->mb_width ? 2 : 1;
1840 (
s->mb_x +
delta >=
s->mb_width)
1841 ?
FFMIN(
s->mb_y + 1,
s->mb_height - 1)
1843 if (
s->next_picture.mbskip_table[xy +
delta])
1895 int cc, dct_dc_size, dct_diff,
code, j, idx = 1, group = 0,
run = 0,
1896 additional_code_len, sign, mismatch;
1898 uint8_t *
const scantable =
s->intra_scantable.permutated;
1899 const uint16_t *quant_matrix;
1901 const int min = -1 * (1 << (
s->avctx->bits_per_raw_sample + 6));
1902 const int max = ((1 << (
s->avctx->bits_per_raw_sample + 6)) - 1);
1903 int shift = 3 -
s->dct_precision;
1912 quant_matrix =
s->intra_matrix;
1919 quant_matrix =
s->chroma_intra_matrix;
1922 if (dct_dc_size == 0) {
1927 if (dct_dc_size > 8) {
1934 s->last_dc[cc] += dct_diff;
1937 block[0] =
s->last_dc[cc] * (8 >>
s->intra_dc_precision);
1939 block[0] =
s->last_dc[cc] * (8 >>
s->intra_dc_precision) * (8 >>
s->dct_precision);
1943 mismatch ^=
block[0];
1960 }
else if (group >= 1 && group <= 6) {
1962 run = 1 << additional_code_len;
1963 if (additional_code_len)
1967 }
else if (group >= 7 && group <= 12) {
1972 run = (1 << (additional_code_len - 1)) +
code;
1976 j = scantable[idx++];
1977 block[j] = sign ? 1 : -1;
1978 }
else if (group >= 13 && group <= 20) {
1982 j = scantable[idx++];
1984 }
else if (group == 21) {
1988 j = scantable[idx++];
1989 additional_code_len =
s->avctx->bits_per_raw_sample +
s->dct_precision + 4;
1990 flc =
get_bits(&
s->gb, additional_code_len);
1991 if (flc >> (additional_code_len-1))
1992 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
1998 mismatch ^=
block[j];
2001 block[63] ^= mismatch & 1;
2008 int i, j,
w,
h, idx = 0;
2009 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
2010 dpcm_residual,
left, top, topleft, min_left_top, max_left_top, p, p2,
output;
2011 h = 16 >> (n ?
s->chroma_y_shift : 0);
2012 w = 16 >> (n ?
s->chroma_x_shift : 0);
2014 block_mean =
get_bits(&
s->gb,
s->avctx->bits_per_raw_sample);
2015 if (block_mean == 0){
2019 s->last_dc[n] = block_mean * (1 << (
s->dct_precision +
s->intra_dc_precision));
2022 if (rice_parameter == 0) {
2027 if (rice_parameter == 15)
2030 if (rice_parameter > 11) {
2035 for (
i = 0;
i <
h;
i++) {
2036 output = 1 << (
s->avctx->bits_per_raw_sample - 1);
2037 top = 1 << (
s->avctx->bits_per_raw_sample - 1);
2039 for (j = 0; j <
w; j++) {
2046 if (rice_prefix_code == 11)
2047 dpcm_residual =
get_bits(&
s->gb,
s->avctx->bits_per_raw_sample);
2049 if (rice_prefix_code == 12) {
2053 rice_suffix_code =
get_bitsz(&
s->gb, rice_parameter);
2054 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2058 if (dpcm_residual & 1)
2059 dpcm_residual = (-1 * dpcm_residual) >> 1;
2061 dpcm_residual = (dpcm_residual >> 1);
2064 top = macroblock[idx-
w];
2066 p =
left + top - topleft;
2068 if (p < min_left_top)
2072 if (p > max_left_top)
2075 p2 = (
FFMIN(min_left_top, topleft) +
FFMAX(max_left_top, topleft)) >> 1;
2080 dpcm_residual *= -1;
2082 macroblock[idx++] =
output = (dpcm_residual + p) & ((1 <<
s->avctx->bits_per_raw_sample) - 1);
2094 ctx->dpcm_direction = 0;
2115 for (
i = 0;
i < 3;
i++) {
2139 int hours, minutes, seconds;
2151 s->time_base = seconds + 60*(minutes + 60*hours);
2175 int visual_object_type;
2176 int is_visual_object_identifier =
get_bits1(gb);
2178 if (is_visual_object_identifier) {
2181 visual_object_type =
get_bits(gb, 4);
2186 if (video_signal_type) {
2187 int video_range, color_description;
2194 if (color_description) {
2195 s->avctx->color_primaries =
get_bits(gb, 8);
2210 for (
i = 0;
i < 64;
i++) {
2211 int j =
s->idsp.idct_permutation[
i];
2213 s->intra_matrix[j] = v;
2214 s->chroma_intra_matrix[j] = v;
2217 s->inter_matrix[j] = v;
2218 s->chroma_inter_matrix[j] = v;
2230 for (
i = 0;
i < 64;
i++) {
2233 s->intra_matrix[j] = v;
2234 s->chroma_intra_matrix[j] = v;
2242 for (
i = 0;
i < 64;
i++) {
2251 for (
i = 0;
i < 64;
i++) {
2254 s->chroma_intra_matrix[j] = v;
2262 for (
i = 0;
i < 64;
i++) {
2274 uint8_t extension_type;
2292 int bits_per_raw_sample;
2293 int rgb, chroma_format;
2313 bits_per_raw_sample =
get_bits(gb, 4);
2314 if (bits_per_raw_sample == 10) {
2324 if (
rgb !=
ctx->rgb ||
s->chroma_format != chroma_format)
2325 s->context_reinit = 1;
2326 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
2328 s->chroma_format = chroma_format;
2331 check_marker(
s->avctx, gb,
"before video_object_layer_width");
2333 check_marker(
s->avctx, gb,
"before video_object_layer_height");
2335 check_marker(
s->avctx, gb,
"after video_object_layer_height");
2339 if (
s->width &&
s->height &&
2341 s->context_reinit = 1;
2346 aspect_ratio_info =
get_bits(gb, 4);
2348 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2349 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2359 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2362 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2364 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2392 s->studio_profile = 1;
2395 }
else if (
s->studio_profile) {
2405 aspect_ratio_info =
get_bits(gb, 4);
2407 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2408 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2414 int chroma_format =
get_bits(gb, 2);
2425 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2428 check_marker(
s->avctx, gb,
"after first_half_vbv_occupancy");
2430 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2435 if (
s->picture_number == 0) {
2436 switch (
ctx->vo_type) {
2455 check_marker(
s->avctx, gb,
"before time_increment_resolution");
2457 s->avctx->framerate.num =
get_bits(gb, 16);
2458 if (!
s->avctx->framerate.num) {
2463 ctx->time_increment_bits =
av_log2(
s->avctx->framerate.num - 1) + 1;
2464 if (
ctx->time_increment_bits < 1)
2465 ctx->time_increment_bits = 1;
2470 s->avctx->framerate.den =
get_bits(gb,
ctx->time_increment_bits);
2472 s->avctx->framerate.den = 1;
2486 !(
s->width &&
s->codec_tag ==
AV_RL32(
"MP4S"))) {
2487 if (
s->width &&
s->height &&
2489 s->context_reinit = 1;
2495 s->progressive_sequence =
2497 s->interlaced_dct = 0;
2500 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
2521 if (
ctx->num_sprite_warping_points > 3) {
2523 "%d sprite_warping_points\n",
2524 ctx->num_sprite_warping_points);
2525 ctx->num_sprite_warping_points = 0;
2528 s->sprite_warping_accuracy =
get_bits(gb, 2);
2539 if (
s->quant_precision != 5)
2541 "quant precision %d\n",
s->quant_precision);
2542 if (
s->quant_precision<3 ||
s->quant_precision>9) {
2543 s->quant_precision = 5;
2546 s->quant_precision = 5;
2559 for (
i = 0;
i < 64;
i++) {
2571 s->intra_matrix[j] = last;
2572 s->chroma_intra_matrix[j] = last;
2576 for (;
i < 64;
i++) {
2578 s->intra_matrix[j] = last;
2579 s->chroma_intra_matrix[j] = last;
2586 for (
i = 0;
i < 64;
i++) {
2598 s->inter_matrix[j] = v;
2599 s->chroma_inter_matrix[j] = v;
2603 for (;
i < 64;
i++) {
2605 s->inter_matrix[j] = last;
2606 s->chroma_inter_matrix[j] = last;
2616 s->quarter_sample = 0;
2625 int estimation_method =
get_bits(gb, 2);
2626 if (estimation_method < 2) {
2641 if (!
check_marker(
s->avctx, gb,
"in complexity estimation part 1")) {
2659 if (!
check_marker(
s->avctx, gb,
"in complexity estimation part 2")) {
2663 if (estimation_method == 1) {
2669 "Invalid Complexity estimation method %d\n",
2674 ctx->cplx_estimation_trash_i =
2675 ctx->cplx_estimation_trash_p =
2676 ctx->cplx_estimation_trash_b = 0;
2682 if (
s->data_partitioning)
2685 if (vo_ver_id != 1) {
2687 if (
ctx->new_pred) {
2694 "reduced resolution VOP not supported\n");
2701 if (
ctx->scalability) {
2703 int h_sampling_factor_n;
2704 int h_sampling_factor_m;
2705 int v_sampling_factor_n;
2706 int v_sampling_factor_m;
2711 h_sampling_factor_n =
get_bits(gb, 5);
2712 h_sampling_factor_m =
get_bits(gb, 5);
2713 v_sampling_factor_n =
get_bits(gb, 5);
2714 v_sampling_factor_m =
get_bits(gb, 5);
2717 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2718 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2721 ctx->scalability = 0;
2731 av_log(
s->avctx,
AV_LOG_DEBUG,
"tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
2732 s->avctx->framerate.den,
s->avctx->framerate.num,
2733 ctx->time_increment_bits,
2735 s->progressive_sequence,
2737 ctx->scalability ?
"scalability " :
"" ,
s->quarter_sample ?
"qpel " :
"",
2738 s->data_partitioning ?
"partition " :
"",
ctx->rvlc ?
"rvlc " :
""
2755 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
2766 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
2768 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
2770 ctx->divx_version = ver;
2771 ctx->divx_build = build;
2772 s->divx_packed = e == 3 && last ==
'p';
2776 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
2778 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
2780 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
2782 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
2784 "Unknown Lavc version string encountered, %d.%d.%d; "
2785 "clamping sub-version values to 8-bits.\n",
2788 build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
2792 if (strcmp(buf,
"ffmpeg") == 0)
2793 ctx->lavc_build = 4600;
2796 ctx->lavc_build = build;
2799 e = sscanf(buf,
"XviD%d", &build);
2801 ctx->xvid_build = build;
2811 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1) {
2812 if (
s->codec_tag ==
AV_RL32(
"XVID") ||
2817 ctx->xvid_build = 0;
2820 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1)
2821 if (
s->codec_tag ==
AV_RL32(
"DIVX") &&
ctx->vo_type == 0 &&
2822 ctx->vol_control_parameters == 0)
2823 ctx->divx_version = 400;
2825 if (
ctx->xvid_build >= 0 &&
ctx->divx_version >= 0) {
2827 ctx->divx_build = -1;
2831 if (
s->codec_tag ==
AV_RL32(
"XVIX"))
2834 if (
s->codec_tag ==
AV_RL32(
"UMP4"))
2837 if (
ctx->divx_version >= 500 &&
ctx->divx_build < 1814)
2840 if (
ctx->divx_version > 502 &&
ctx->divx_build < 1814)
2843 if (
ctx->xvid_build <= 3
U)
2844 s->padding_bug_score = 256 * 256 * 256 * 64;
2846 if (
ctx->xvid_build <= 1
U)
2849 if (
ctx->xvid_build <= 12
U)
2852 if (
ctx->xvid_build <= 32
U)
2855 #define SET_QPEL_FUNC(postfix1, postfix2) \
2856 s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
2857 s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
2858 s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
2860 if (
ctx->lavc_build < 4653
U)
2863 if (
ctx->lavc_build < 4655
U)
2866 if (
ctx->lavc_build < 4670
U)
2869 if (
ctx->lavc_build <= 4712
U)
2872 if ((
ctx->lavc_build&0xFF) >= 100) {
2873 if (
ctx->lavc_build > 3621476 &&
ctx->lavc_build < 3752552 &&
2874 (
ctx->lavc_build < 3752037 ||
ctx->lavc_build > 3752191)
2879 if (
ctx->divx_version >= 0)
2881 if (
ctx->divx_version == 501 &&
ctx->divx_build == 20020416)
2882 s->padding_bug_score = 256 * 256 * 256 * 64;
2884 if (
ctx->divx_version < 500
U)
2887 if (
ctx->divx_version >= 0)
2909 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
2910 s->workaround_bugs,
ctx->lavc_build,
ctx->xvid_build,
2911 ctx->divx_version,
ctx->divx_build,
s->divx_packed ?
"p" :
"");
2913 if (CONFIG_MPEG4_DECODER &&
ctx->xvid_build >= 0 &&
2928 int time_incr, time_increment;
2940 if (
s->partitioned_frame)
2951 if (
ctx->time_increment_bits == 0 ||
2954 "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n",
ctx->time_increment_bits);
2956 for (
ctx->time_increment_bits = 1;
2957 ctx->time_increment_bits < 16;
2958 ctx->time_increment_bits++) {
2962 if ((
show_bits(gb,
ctx->time_increment_bits + 6) & 0x37) == 0x30)
2964 }
else if ((
show_bits(gb,
ctx->time_increment_bits + 5) & 0x1F) == 0x18)
2969 "time_increment_bits set to %d bits, based on bitstream analysis\n",
ctx->time_increment_bits);
2970 if (
s->avctx->framerate.num && 4*
s->avctx->framerate.num < 1<<
ctx->time_increment_bits) {
2971 s->avctx->framerate.num = 1<<
ctx->time_increment_bits;
2979 time_increment =
get_bits(gb,
ctx->time_increment_bits);
2982 s->last_time_base =
s->time_base;
2983 s->time_base += time_incr;
2984 s->time =
s->time_base * (int64_t)
s->avctx->framerate.num + time_increment;
2986 if (
s->time <
s->last_non_b_time) {
2990 s->time +=
s->avctx->framerate.num;
2993 s->pp_time =
s->time -
s->last_non_b_time;
2994 s->last_non_b_time =
s->time;
2996 s->time = (
s->last_time_base + time_incr) * (int64_t)
s->avctx->framerate.num + time_increment;
2997 s->pb_time =
s->pp_time - (
s->last_non_b_time -
s->time);
2998 if (
s->pp_time <=
s->pb_time ||
2999 s->pp_time <=
s->pp_time -
s->pb_time ||
3006 if (
ctx->t_frame == 0)
3007 ctx->t_frame =
s->pb_time;
3008 if (
ctx->t_frame == 0)
3014 if (
s->pp_field_time <=
s->pb_field_time ||
s->pb_field_time <= 1) {
3015 s->pb_field_time = 2;
3016 s->pp_field_time = 4;
3017 if (!
s->progressive_sequence)
3022 if (
s->avctx->framerate.den)
3080 if (!
s->progressive_sequence) {
3084 s->alternate_scan = 0;
3087 if (
s->alternate_scan) {
3110 if (
ctx->sprite_brightness_change)
3112 "sprite_brightness_change not supported\n");
3116 memset(
s->sprite_offset, 0,
sizeof(
s->sprite_offset));
3117 memset(
s->sprite_delta, 0,
sizeof(
s->sprite_delta));
3122 s->chroma_qscale =
s->qscale =
get_bits(gb,
s->quant_precision);
3123 if (
s->qscale == 0) {
3125 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
3131 if (
s->f_code == 0) {
3133 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
3142 if (
s->b_code == 0) {
3144 "Error, header damaged or not MPEG4 header (b_code=0)\n");
3153 "qp:%d fc:%d,%d %c size:%d pro:%d alt:%d top:%d %cpel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64
" tincr:%d\n",
3154 s->qscale,
s->f_code,
s->b_code,
3157 s->top_field_first,
s->quarter_sample ?
'q' :
'h',
3158 s->data_partitioning,
ctx->resync_marker,
3159 ctx->num_sprite_warping_points,
s->sprite_warping_accuracy,
3160 1 -
s->no_rounding,
ctx->vo_type,
3161 ctx->vol_control_parameters ?
" VOLC" :
" ",
ctx->intra_dc_threshold,
3162 ctx->cplx_estimation_trash_i,
ctx->cplx_estimation_trash_p,
3163 ctx->cplx_estimation_trash_b,
3169 if (!
ctx->scalability) {
3173 if (
ctx->enhancement_type) {
3174 int load_backward_shape =
get_bits1(gb);
3175 if (load_backward_shape)
3177 "load backward shape isn't supported\n");
3187 if (
ctx->vo_type == 0 &&
ctx->vol_control_parameters == 0 &&
3188 ctx->divx_version == -1 &&
s->picture_number == 0) {
3190 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3194 s->picture_number++;
3201 s->h_edge_pos =
s->width;
3202 s->v_edge_pos =
s->height;
3233 s->partitioned_frame = 0;
3234 s->interlaced_dct = 0;
3257 s->intra_dc_precision =
get_bits(gb, 2);
3261 if (
s->alternate_scan) {
3284 int visual_object_type;
3287 visual_object_type =
get_bits(gb, 4);
3310 int header,
int parse_only)
3313 unsigned startcode, v;
3323 if (!
s->studio_profile &&
s->avctx->bits_per_raw_sample != 8)
3324 s->avctx->bits_per_raw_sample = 0;
3336 (
ctx->divx_version >= 0 ||
ctx->xvid_build >= 0) ||
s->codec_tag ==
AV_RL32(
"QMP4")) {
3347 startcode = ((startcode << 8) | v) & 0xffffffff;
3349 if ((startcode & 0xFFFFFF00) != 0x100)
3354 if (startcode <= 0x11F)
3355 name =
"Video Object Start";
3356 else if (startcode <= 0x12F)
3357 name =
"Video Object Layer Start";
3358 else if (startcode <= 0x13F)
3360 else if (startcode <= 0x15F)
3361 name =
"FGS bp start";
3362 else if (startcode <= 0x1AF)
3364 else if (startcode == 0x1B0)
3365 name =
"Visual Object Seq Start";
3366 else if (startcode == 0x1B1)
3367 name =
"Visual Object Seq End";
3368 else if (startcode == 0x1B2)
3370 else if (startcode == 0x1B3)
3371 name =
"Group of VOP start";
3372 else if (startcode == 0x1B4)
3373 name =
"Video Session Error";
3374 else if (startcode == 0x1B5)
3375 name =
"Visual Object Start";
3376 else if (startcode == 0x1B6)
3377 name =
"Video Object Plane start";
3378 else if (startcode == 0x1B7)
3379 name =
"slice start";
3380 else if (startcode == 0x1B8)
3381 name =
"extension start";
3382 else if (startcode == 0x1B9)
3384 else if (startcode == 0x1BA)
3385 name =
"FBA Object start";
3386 else if (startcode == 0x1BB)
3387 name =
"FBA Object Plane start";
3388 else if (startcode == 0x1BC)
3389 name =
"Mesh Object start";
3390 else if (startcode == 0x1BD)
3391 name =
"Mesh Object Plane start";
3392 else if (startcode == 0x1BE)
3393 name =
"Still Texture Object start";
3394 else if (startcode == 0x1BF)
3395 name =
"Texture Spatial Layer start";
3396 else if (startcode == 0x1C0)
3397 name =
"Texture SNR Layer start";
3398 else if (startcode == 0x1C1)
3399 name =
"Texture Tile start";
3400 else if (startcode == 0x1C2)
3401 name =
"Texture Shape Layer start";
3402 else if (startcode == 0x1C3)
3403 name =
"stuffing start";
3404 else if (startcode <= 0x1C5)
3406 else if (startcode <= 0x1FF)
3407 name =
"System start";
3412 if (startcode >= 0x120 && startcode <= 0x12F) {
3429 s->studio_profile = 1;
3432 }
else if (
s->studio_profile) {
3439 if (
s->studio_profile) {
3455 s->avctx->has_b_frames = !
s->low_delay;
3457 if (
s->studio_profile) {
3458 if (!
s->avctx->bits_per_raw_sample) {
3475 if (
s->divx_packed) {
3476 int current_pos =
s->gb.buffer ==
s->bitstream_buffer ? 0 : (
get_bits_count(&
s->gb) >> 3);
3477 int startcode_found = 0;
3479 if (buf_size - current_pos > 7) {
3482 for (
i = current_pos;
i < buf_size - 4;
i++)
3487 buf[
i + 3] == 0xB6) {
3488 startcode_found = !(buf[
i + 4] & 0x40);
3493 if (startcode_found) {
3494 if (!
ctx->showed_packed_warning) {
3496 "wasteful way to store B-frames ('packed B-frames'). "
3497 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
3498 ctx->showed_packed_warning = 1;
3501 &
s->allocated_bitstream_buffer_size,
3502 buf_size - current_pos);
3503 if (!
s->bitstream_buffer) {
3504 s->bitstream_buffer_size = 0;
3507 memcpy(
s->bitstream_buffer, buf + current_pos,
3508 buf_size - current_pos);
3509 s->bitstream_buffer_size = buf_size - current_pos;
3522 int init =
s->m.context_initialized;
3530 s->time_increment_bits =
s1->time_increment_bits;
3531 s->shape =
s1->shape;
3532 s->vol_sprite_usage =
s1->vol_sprite_usage;
3533 s->sprite_brightness_change =
s1->sprite_brightness_change;
3534 s->num_sprite_warping_points =
s1->num_sprite_warping_points;
3536 s->resync_marker =
s1->resync_marker;
3537 s->t_frame =
s1->t_frame;
3538 s->new_pred =
s1->new_pred;
3539 s->enhancement_type =
s1->enhancement_type;
3540 s->scalability =
s1->scalability;
3541 s->intra_dc_threshold =
s1->intra_dc_threshold;
3542 s->divx_version =
s1->divx_version;
3543 s->divx_build =
s1->divx_build;
3544 s->xvid_build =
s1->xvid_build;
3545 s->lavc_build =
s1->lavc_build;
3546 s->vo_type =
s1->vo_type;
3547 s->showed_packed_warning =
s1->showed_packed_warning;
3548 s->vol_control_parameters =
s1->vol_control_parameters;
3549 s->cplx_estimation_trash_i =
s1->cplx_estimation_trash_i;
3550 s->cplx_estimation_trash_p =
s1->cplx_estimation_trash_p;
3551 s->cplx_estimation_trash_b =
s1->cplx_estimation_trash_b;
3554 memcpy(
s->sprite_shift,
s1->sprite_shift,
sizeof(
s1->sprite_shift));
3555 memcpy(
s->sprite_traj,
s1->sprite_traj,
sizeof(
s1->sprite_traj));
3557 if (CONFIG_MPEG4_DECODER && !
init &&
s1->xvid_build >= 0)
3563 static int mpeg4_update_thread_context_for_user(
AVCodecContext *dst,
3590 for (
unsigned i = 0,
offset = 0;
i < 12;
i++) {
3617 NULL, 0, 0, 0, 0, 128);
3633 ctx->lavc_build = -1;
3641 ctx->time_increment_bits = 4;
3650 #define OFFSET(x) offsetof(MpegEncContext, x)
3651 #define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
3675 #if FF_API_FLAG_TRUNCATED
3676 AV_CODEC_CAP_TRUNCATED |
3690 #if CONFIG_MPEG4_NVDEC_HWACCEL
3693 #if CONFIG_MPEG4_VAAPI_HWACCEL
3696 #if CONFIG_MPEG4_VDPAU_HWACCEL
3699 #if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
const AVProfile ff_mpeg4_video_profiles[]
#define MV_TYPE_16X16
1 vector for the whole mb
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVClass mpeg4_class
#define FF_ASPECT_EXTENDED
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
#define VISUAL_OBJ_STARTCODE
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_cold void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx)
static const uint8_t mpeg4_block_count[4]
const uint8_t ff_sprite_trajectory_lens[15]
static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, int parse_only)
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static VLC studio_chroma_dc
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static int get_bits_count(const GetBitContext *s)
static const uint8_t ac_state_tab[22][2]
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
@ AVCOL_RANGE_JPEG
Full range content.
static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64])
#define ADV_SIMPLE_VO_TYPE
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb)
static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
#define AV_LOG_VERBOSE
Detailed information.
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_init_block_index(MpegEncContext *s)
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define UPDATE_CACHE(name, gb)
#define FF_BUG_HPEL_CHROMA
static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
#define FF_PROFILE_MPEG4_SIMPLE_STUDIO
static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
av_cold void ff_mpeg4_init_rl_intra(void)
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_thread_await_progress() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_thread_report_progress() has been called on them. This includes draw_edges(). Porting codecs to frame threading
const uint16_t ff_mpeg4_resync_prefix[8]
#define FF_DEBUG_PICT_INFO
#define GET_CACHE(name, gb)
#define VOT_STILL_TEXTURE_ID
static void skip_bits(GetBitContext *s, int n)
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static VLC studio_intra_tab[12]
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the user data stuff in the header.
#define SKIP_CACHE(name, gb, num)
AVCodec p
The public AVCodec.
static int get_amv(Mpeg4DecContext *ctx, int n)
Get the average motion vector for a GMC MB.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
#define MB_TYPE_B_VLC_BITS
#define STUDIO_INTRA_BITS
#define FF_BUG_QPEL_CHROMA2
#define AV_PIX_FMT_GBRP10
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
const AVRational ff_h263_pixel_aspect[16]
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
#define CORE_STUDIO_VO_TYPE
#define USES_LIST(a, list)
static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb, int *profile, int *level)
#define HWACCEL_VDPAU(codec)
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define SLICE_END
end marker found
#define AV_PIX_FMT_YUV444P10
#define AV_EF_BITSTREAM
detect bitstream specification deviations
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define INIT_FIRST_VLC_RL(rl, static_size)
#define FF_ARRAY_ELEMS(a)
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id)
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
#define CLOSE_READER(name, gb)
#define FF_CODEC_DECODE_CB(func)
int8_t * max_level[2]
encoding & decoding
#define SHOW_SBITS(name, gb, num)
VLC ff_h263_inter_MCBPC_vlc
#define FF_BUG_NO_PADDING
RLTable ff_mpeg4_rl_intra
static VLCElem vlc_buf[16716]
#define FF_PROFILE_UNKNOWN
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
#define SKIP_BITS(name, gb, num)
#define FF_BUG_DIRECT_BLOCKSIZE
av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Initialize index_run, max_level and max_run from n, last, table_vlc, table_run and table_level.
static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const uint8_t ff_mpeg4_DCtab_lum[13][2]
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static const int mb_type_b_map[4]
#define LIBAVUTIL_VERSION_INT
static void mpeg4_load_default_matrices(MpegEncContext *s)
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Rational number (pair of numerator and denominator).
#define INIT_VLC_STATIC_FROM_LENGTHS(vlc, bits, nb_codes, lens, len_wrap, symbols, symbols_wrap, symbols_size, offset, flags, static_size)
static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
decode partition C of one MB.
static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
#define SLICE_NOEND
no end marker or error found but mb count exceeded
#define ROUNDED_DIV(a, b)
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static unsigned int get_bits1(GetBitContext *s)
int ff_init_vlc_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()
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
#define LAST_SKIP_BITS(name, gb, num)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
#define SET_QPEL_FUNC(postfix1, postfix2)
const uint8_t ff_alternate_horizontal_scan[64]
#define AV_PIX_FMT_YUV422P10
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
const uint8_t ff_mpeg4_dc_threshold[8]
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
Decode first partition.
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_EF_IGNORE_ERR
ignore errors and continue
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const uint8_t ff_mpeg4_y_dc_scale_table[32]
static int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level, int *dir_ptr, int encoding)
Predict the dc.
static int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, int n, int coded, int intra, int use_intra_dc_vlc, int rvlc)
Decode a block.
const int16_t ff_mpeg4_default_intra_matrix[64]
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
int quarter_sample
1->qpel, 0->half pel ME/MC
static const uint8_t header[24]
#define MB_TYPE_INTERLACED
#define OPEN_READER(name, gb)
void ff_mpeg_flush(AVCodecContext *avctx)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
const int16_t ff_mpeg4_default_non_intra_matrix[64]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define MV_TYPE_FIELD
2 vectors, one per field
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
static void skip_bits1(GetBitContext *s)
#define HWACCEL_NVDEC(codec)
#define AV_LOG_INFO
Standard information.
static void ff_update_block_index(MpegEncContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
Decode the dc value.
#define SKIP_COUNTER(name, gb, num)
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]
const uint8_t ff_alternate_vertical_scan[64]
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header, int parse_only)
Decode MPEG-4 headers.
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
int8_t * max_run[2]
encoding & decoding
static VLC studio_luma_dc
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
VLC ff_h263_intra_MCBPC_vlc
#define INTRA_MCBPC_VLC_BITS
#define SIMPLE_STUDIO_VO_TYPE
#define FF_BUG_AUTODETECT
autodetection
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define FF_DEBUG_STARTCODE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#define USER_DATA_STARTCODE
#define FF_BUG_QPEL_CHROMA
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define HWACCEL_VIDEOTOOLBOX(codec)
#define SPRITE_TRAJ_VLC_BITS
const uint8_t ff_mpeg4_studio_dc_luma[19][2]
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
const uint8_t ff_zigzag_direct[64]
#define INIT_VLC_STATIC_OVERLONG
static av_cold void mpeg4_init_static(void)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const uint8_t ff_mpeg4_studio_dc_chroma[19][2]
static const uint8_t * align_get_bits(GetBitContext *s)
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int block_size, int uvlinesize, int dct_linesize, int dct_offset)
main external API structure.
static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
decode second partition.
#define SHOW_UBITS(name, gb, num)
const uint8_t ff_mb_type_b_tab[4][2]
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
static const AVOption mpeg4_options[]
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
const FFCodec ff_mpeg4_decoder
static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
static int mpeg4_is_resync(Mpeg4DecContext *ctx)
check if the next stuff is a resync marker or the end.
static int shift(int a, int b)
#define INIT_VLC_RL(rl, static_size)
static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[256], int n)
@ AV_PICTURE_TYPE_P
Predicted.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Undefined Behavior In the C some operations are like signed integer overflow
#define FF_BUG_XVID_ILACE
#define avpriv_request_sample(...)
static void reset_studio_dc_predictors(MpegEncContext *s)
const uint8_t ff_mpeg4_c_dc_scale_table[32]
#define QUANT_MATRIX_EXT_ID
static void next_start_code_studio(GetBitContext *gb)
static const int16_t alpha[]
static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the next studio vop header.
static int mpeg_get_qscale(MpegEncContext *s)
#define HWACCEL_VAAPI(codec)
static const SheerTable rgb[2]
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb)
static av_cold int decode_init(AVCodecContext *avctx)
static VLC sprite_trajectory
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
RL_VLC_ELEM * rl_vlc[32]
decoding only
#define INTER_MCBPC_VLC_BITS
const uint8_t ff_mpeg4_studio_intra[12][24][2]