Go to the documentation of this file.
23 #define UNCHECKED_BITSTREAM_READER 1
25 #include "config_components.h"
53 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
54 #define IS_3IV1 (s->codec_tag == AV_RL32("3IV1"))
63 #define SPRITE_TRAJ_VLC_BITS 6
65 #define MB_TYPE_B_VLC_BITS 4
66 #define STUDIO_INTRA_BITS 9
91 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
92 uint8_t *
const *ref_picture)
95 int src_x, src_y, motion_x, motion_y;
96 ptrdiff_t
offset, linesize, uvlinesize;
99 motion_x =
ctx->sprite_offset[0][0];
100 motion_y =
ctx->sprite_offset[0][1];
101 src_x =
s->mb_x * 16 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
102 src_y =
s->mb_y * 16 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
103 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
104 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
105 src_x =
av_clip(src_x, -16,
s->width);
106 if (src_x ==
s->width)
108 src_y =
av_clip(src_y, -16,
s->height);
109 if (src_y ==
s->height)
112 linesize =
s->linesize;
113 uvlinesize =
s->uvlinesize;
115 ptr = ref_picture[0] + src_y * linesize + src_x;
117 if ((
unsigned)src_x >=
FFMAX(
s->h_edge_pos - 17, 0) ||
118 (
unsigned)src_y >=
FFMAX(
s->v_edge_pos - 17, 0)) {
119 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
123 s->h_edge_pos,
s->v_edge_pos);
124 ptr =
s->sc.edge_emu_buffer;
127 if ((motion_x | motion_y) & 7) {
128 ctx->mdsp.gmc1(dest_y, ptr, linesize, 16,
129 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
130 ctx->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
131 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
135 dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
136 if (
s->no_rounding) {
137 s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
139 s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
146 motion_x =
ctx->sprite_offset[1][0];
147 motion_y =
ctx->sprite_offset[1][1];
148 src_x =
s->mb_x * 8 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
149 src_y =
s->mb_y * 8 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
150 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
151 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
152 src_x =
av_clip(src_x, -8,
s->width >> 1);
153 if (src_x ==
s->width >> 1)
155 src_y =
av_clip(src_y, -8,
s->height >> 1);
156 if (src_y ==
s->height >> 1)
159 offset = (src_y * uvlinesize) + src_x;
160 ptr = ref_picture[1] +
offset;
161 if ((
unsigned)src_x >=
FFMAX((
s->h_edge_pos >> 1) - 9, 0) ||
162 (unsigned)src_y >=
FFMAX((
s->v_edge_pos >> 1) - 9, 0)) {
163 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
164 uvlinesize, uvlinesize,
167 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
168 ptr =
s->sc.edge_emu_buffer;
171 ctx->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
172 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
174 ptr = ref_picture[2] +
offset;
176 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
177 uvlinesize, uvlinesize,
180 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
181 ptr =
s->sc.edge_emu_buffer;
183 ctx->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
184 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
188 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
189 uint8_t *
const *ref_picture)
192 int linesize, uvlinesize;
193 const int a =
ctx->sprite_warping_accuracy;
196 linesize =
s->linesize;
197 uvlinesize =
s->uvlinesize;
199 ptr = ref_picture[0];
201 ox =
ctx->sprite_offset[0][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 16 +
202 ctx->sprite_delta[0][1] *
s->mb_y * 16;
203 oy =
ctx->sprite_offset[0][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 16 +
204 ctx->sprite_delta[1][1] *
s->mb_y * 16;
206 ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
208 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
209 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
210 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
211 s->h_edge_pos,
s->v_edge_pos);
212 ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
213 ox +
ctx->sprite_delta[0][0] * 8,
214 oy +
ctx->sprite_delta[1][0] * 8,
215 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
216 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
217 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
218 s->h_edge_pos,
s->v_edge_pos);
223 ox =
ctx->sprite_offset[1][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 8 +
224 ctx->sprite_delta[0][1] *
s->mb_y * 8;
225 oy =
ctx->sprite_offset[1][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 8 +
226 ctx->sprite_delta[1][1] *
s->mb_y * 8;
228 ptr = ref_picture[1];
229 ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
231 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
232 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
233 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
234 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
236 ptr = ref_picture[2];
237 ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
239 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
240 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
241 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
242 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
246 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
247 uint8_t *
const *ref_picture)
251 if (
ctx->real_sprite_warping_points == 1) {
261 uint8_t *dest_cr,
int block_size,
int uvlinesize,
262 int dct_linesize,
int dct_offset)
265 const int act_block_size = block_size * 2;
267 if (
ctx->dpcm_direction == 0) {
268 s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)
ctx->block32[0]);
269 s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)
ctx->block32[1]);
270 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)
ctx->block32[2]);
271 s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)
ctx->block32[3]);
273 dct_linesize = uvlinesize <<
s->interlaced_dct;
274 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
276 s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)
ctx->block32[4]);
277 s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)
ctx->block32[5]);
278 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)
ctx->block32[6]);
279 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)
ctx->block32[7]);
280 if (!
s->chroma_x_shift){
281 s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)
ctx->block32[8]);
282 s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)
ctx->block32[9]);
283 s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[10]);
284 s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[11]);
286 }
else if (
ctx->dpcm_direction == 1) {
287 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
288 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
289 for (
int i = 0;
i < 3;
i++) {
290 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
291 int vsub =
i ?
s->chroma_y_shift : 0;
292 int hsub =
i ?
s->chroma_x_shift : 0;
295 for (
int h = 0;
h < (16 >> (vsub +
lowres));
h++){
297 dest_pcm[
i][
w] =
src[idx];
298 dest_pcm[
i] += linesize[
i] / 2;
303 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
304 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
306 for (
int i = 0;
i < 3;
i++) {
307 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
308 int vsub =
i ?
s->chroma_y_shift : 0;
309 int hsub =
i ?
s->chroma_x_shift : 0;
312 dest_pcm[
i] += (linesize[
i] / 2) * ((16 >> vsub +
lowres) - 1);
313 for (
int h = (16 >> (vsub +
lowres)) - 1;
h >= 0;
h--){
315 dest_pcm[
i][
w] =
src[idx];
317 dest_pcm[
i] -= linesize[
i] / 2;
331 int16_t *ac_val, *ac_val1;
332 int8_t *
const qscale_table =
h->c.cur_pic.qscale_table;
335 ac_val = &
h->c.ac_val[0][0] +
h->c.block_index[n] * 16;
339 const int xy =
h->c.mb_x - 1 +
h->c.mb_y *
h->c.mb_stride;
343 if (
h->c.mb_x == 0 ||
h->c.qscale == qscale_table[xy] ||
346 for (
i = 1;
i < 8;
i++)
347 block[
h->c.idsp.idct_permutation[
i << 3]] += ac_val[
i];
350 for (
i = 1;
i < 8;
i++)
351 block[
h->c.idsp.idct_permutation[
i << 3]] +=
ROUNDED_DIV(ac_val[
i] * qscale_table[xy],
h->c.qscale);
354 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride -
h->c.mb_stride;
356 ac_val -= 16 *
h->c.block_wrap[n];
358 if (
h->c.mb_y == 0 ||
h->c.qscale == qscale_table[xy] ||
361 for (
i = 1;
i < 8;
i++)
362 block[
h->c.idsp.idct_permutation[
i]] += ac_val[
i + 8];
365 for (
i = 1;
i < 8;
i++)
366 block[
h->c.idsp.idct_permutation[
i]] +=
ROUNDED_DIV(ac_val[
i + 8] * qscale_table[xy],
h->c.qscale);
371 for (
i = 1;
i < 8;
i++)
372 ac_val1[
i] =
block[
h->c.idsp.idct_permutation[
i << 3]];
376 ac_val1[8 +
i] =
block[
h->c.idsp.idct_permutation[
i]];
394 (v >> (8 -
h->c.pict_type) != 1) ||
h->partitioned_frame)
397 bits_count += 8 +
h->c.pict_type;
401 if (bits_count + 8 >=
h->gb.size_in_bits) {
403 v |= 0x7F >> (7 - (bits_count & 7));
408 static const uint16_t mpeg4_resync_prefix[8] = {
409 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
412 if (v == mpeg4_resync_prefix[bits_count & 7]) {
414 int mb_num_bits =
av_log2(
h->c.mb_num - 1) + 1;
425 if (!mb_num || mb_num >
h->c.mb_num ||
get_bits_count(&
h->gb) + 6 >
h->gb.size_in_bits)
440 int a = 2 <<
ctx->sprite_warping_accuracy;
441 int rho = 3 -
ctx->sprite_warping_accuracy;
447 int min_ab,
i, w2, h2, w3, h3;
448 int sprite_ref[4][2];
449 int virtual_ref[2][2];
454 const int vop_ref[4][2] = { { 0, 0 }, {
s->width, 0 },
455 { 0,
s->height }, {
s->width,
s->height } };
456 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
458 if (
w <= 0 ||
h <= 0)
461 for (
i = 0;
i <
ctx->num_sprite_warping_points;
i++) {
469 if (!(
ctx->divx_version == 500 &&
ctx->divx_build == 413))
477 ctx->sprite_traj[
i][0] = d[
i][0] = x;
478 ctx->sprite_traj[
i][1] = d[
i][1] = y;
481 ctx->sprite_traj[
i][0] =
ctx->sprite_traj[
i][1] = 0;
485 while ((1 << beta) <
h)
491 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413) {
492 sprite_ref[0][0] =
a * vop_ref[0][0] + d[0][0];
493 sprite_ref[0][1] =
a * vop_ref[0][1] + d[0][1];
494 sprite_ref[1][0] =
a * vop_ref[1][0] + d[0][0] + d[1][0];
495 sprite_ref[1][1] =
a * vop_ref[1][1] + d[0][1] + d[1][1];
496 sprite_ref[2][0] =
a * vop_ref[2][0] + d[0][0] + d[2][0];
497 sprite_ref[2][1] =
a * vop_ref[2][1] + d[0][1] + d[2][1];
499 sprite_ref[0][0] = (
a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
500 sprite_ref[0][1] = (
a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
501 sprite_ref[1][0] = (
a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
502 sprite_ref[1][1] = (
a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
503 sprite_ref[2][0] = (
a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
504 sprite_ref[2][1] = (
a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
514 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
516 (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
517 w2 * (
r * sprite_ref[1][0] - 16LL * vop_ref[1][0])),
w);
518 virtual_ref[0][1] = 16 * vop_ref[0][1] +
520 (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
521 w2 * (
r * sprite_ref[1][1] - 16LL * vop_ref[1][1])),
w);
522 virtual_ref[1][0] = 16 * vop_ref[0][0] +
523 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
524 h2 * (
r * sprite_ref[2][0] - 16LL * vop_ref[2][0])),
h);
525 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
526 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
527 h2 * (
r * sprite_ref[2][1] - 16LL * vop_ref[2][1])),
h);
529 switch (
ctx->num_sprite_warping_points) {
531 sprite_offset[0][0] =
532 sprite_offset[0][1] =
533 sprite_offset[1][0] =
534 sprite_offset[1][1] = 0;
535 sprite_delta[0][0] =
a;
537 sprite_delta[1][0] = 0;
538 sprite_delta[1][1] =
a;
539 ctx->sprite_shift[0] =
540 ctx->sprite_shift[1] = 0;
543 sprite_offset[0][0] = sprite_ref[0][0] -
a * vop_ref[0][0];
544 sprite_offset[0][1] = sprite_ref[0][1] -
a * vop_ref[0][1];
545 sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
546 a * (vop_ref[0][0] / 2);
547 sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
548 a * (vop_ref[0][1] / 2);
549 sprite_delta[0][0] =
a;
551 sprite_delta[1][0] = 0;
552 sprite_delta[1][1] =
a;
553 ctx->sprite_shift[0] =
554 ctx->sprite_shift[1] = 0;
557 sprite_offset[0][0] = ((
int64_t) sprite_ref[0][0] * (1 <<
alpha + rho)) +
558 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
560 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
562 sprite_offset[0][1] = ((
int64_t) sprite_ref[0][1] * (1 <<
alpha + rho)) +
563 ((
int64_t) -
r * sprite_ref[0][1] + virtual_ref[0][1]) *
565 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
567 sprite_offset[1][0] = (((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
568 ((
int64_t)-2 * vop_ref[0][0] + 1) +
569 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
570 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
571 (
int64_t) sprite_ref[0][0] - 16 * w2 + (1 << (
alpha + rho + 1)));
572 sprite_offset[1][1] = (((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) *
573 ((
int64_t)-2 * vop_ref[0][0] + 1) +
574 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
575 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
576 (
int64_t) sprite_ref[0][1] - 16 * w2 + (1 << (
alpha + rho + 1)));
577 sprite_delta[0][0] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
578 sprite_delta[0][1] = (+
r * sprite_ref[0][1] - virtual_ref[0][1]);
579 sprite_delta[1][0] = (-
r * sprite_ref[0][1] + virtual_ref[0][1]);
580 sprite_delta[1][1] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
583 ctx->sprite_shift[1] =
alpha + rho + 2;
589 sprite_offset[0][0] = ((
int64_t)sprite_ref[0][0] * (1 << (
alpha + beta + rho - min_ab))) +
590 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
591 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
593 sprite_offset[0][1] = ((
int64_t)sprite_ref[0][1] * (1 << (
alpha + beta + rho - min_ab))) +
594 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
595 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
597 sprite_offset[1][0] = ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
598 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
599 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][0] - 16 * w2 * h3 +
601 sprite_offset[1][1] = ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
602 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
603 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][1] - 16 * w2 * h3 +
605 sprite_delta[0][0] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
606 sprite_delta[0][1] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
607 sprite_delta[1][0] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
608 sprite_delta[1][1] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
610 ctx->sprite_shift[0] =
alpha + beta + rho - min_ab;
611 ctx->sprite_shift[1] =
alpha + beta + rho - min_ab + 2;
614 av_unreachable(
"num_sprite_warping_points outside of 0..3 results in an error"
615 "in which num_sprite_warping_points is reset to zero");
618 if (sprite_delta[0][0] ==
a <<
ctx->sprite_shift[0] &&
619 sprite_delta[0][1] == 0 &&
620 sprite_delta[1][0] == 0 &&
621 sprite_delta[1][1] ==
a <<
ctx->sprite_shift[0]) {
622 sprite_offset[0][0] >>=
ctx->sprite_shift[0];
623 sprite_offset[0][1] >>=
ctx->sprite_shift[0];
624 sprite_offset[1][0] >>=
ctx->sprite_shift[1];
625 sprite_offset[1][1] >>=
ctx->sprite_shift[1];
626 sprite_delta[0][0] =
a;
627 sprite_delta[0][1] = 0;
628 sprite_delta[1][0] = 0;
629 sprite_delta[1][1] =
a;
630 ctx->sprite_shift[0] = 0;
631 ctx->sprite_shift[1] = 0;
632 ctx->real_sprite_warping_points = 1;
634 int shift_y = 16 -
ctx->sprite_shift[0];
635 int shift_c = 16 -
ctx->sprite_shift[1];
637 for (
i = 0;
i < 2;
i++) {
638 if (shift_c < 0 || shift_y < 0 ||
639 FFABS( sprite_offset[0][
i]) >= INT_MAX >> shift_y ||
640 FFABS( sprite_offset[1][
i]) >= INT_MAX >> shift_c ||
641 FFABS( sprite_delta[0][
i]) >= INT_MAX >> shift_y ||
642 FFABS( sprite_delta[1][
i]) >= INT_MAX >> shift_y
649 for (
i = 0;
i < 2;
i++) {
650 sprite_offset[0][
i] *= 1 << shift_y;
651 sprite_offset[1][
i] *= 1 << shift_c;
652 sprite_delta[0][
i] *= 1 << shift_y;
653 sprite_delta[1][
i] *= 1 << shift_y;
654 ctx->sprite_shift[
i] = 16;
657 for (
i = 0;
i < 2;
i++) {
659 sprite_delta[
i][0] -
a * (1LL<<16),
660 sprite_delta[
i][1] -
a * (1LL<<16)
663 if (llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
664 llabs(sprite_offset[0][
i] + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
665 llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL) + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
666 llabs(sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
667 llabs(sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
668 llabs(sd[0]) >= INT_MAX ||
669 llabs(sd[1]) >= INT_MAX ||
670 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL)) >= INT_MAX ||
671 llabs(sprite_offset[0][
i] + sd[1] * (
h+16LL)) >= INT_MAX ||
672 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL) + sd[1] * (
h+16LL)) >= INT_MAX
678 ctx->real_sprite_warping_points =
ctx->num_sprite_warping_points;
681 for (
i = 0;
i < 4;
i++) {
682 ctx->sprite_offset[
i&1][
i>>1] = sprite_offset[
i&1][
i>>1];
683 ctx->sprite_delta [
i&1][
i>>1] = sprite_delta [
i&1][
i>>1];
688 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
689 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
712 int mb_num_bits =
av_log2(
h->c.mb_num - 1) + 1;
713 int header_extension = 0, mb_num,
len;
734 if (mb_num >=
h->c.mb_num || !mb_num) {
736 "illegal mb_num in video packet (%d %d) \n", mb_num,
h->c.mb_num);
740 h->c.mb_x = mb_num %
h->c.mb_width;
741 h->c.mb_y = mb_num /
h->c.mb_width;
746 h->c.chroma_qscale =
h->c.qscale = qscale;
752 if (header_extension) {
756 check_marker(
h->c.avctx, &
h->gb,
"before time_increment in video packed header");
758 check_marker(
h->c.avctx, &
h->gb,
"before vop_coding_type in video packed header");
779 "Error, video packet header damaged (f_code=0)\n");
785 "Error, video packet header damaged (b_code=0)\n");
801 s->last_dc[2] = 1 << (
s->avctx->bits_per_raw_sample +
ctx->dct_precision +
s->intra_dc_precision - 1);
816 vlc_len =
av_log2(
h->c.mb_width *
h->c.mb_height) + 1;
819 if (mb_num >=
h->c.mb_num)
822 h->c.mb_x = mb_num %
h->c.mb_width;
823 h->c.mb_y = mb_num /
h->c.mb_width;
853 int x, y, mb_v, sum, dx, dy,
shift;
854 int len = 1 << (
ctx->f_code + 4);
855 const int a =
ctx->sprite_warping_accuracy;
858 len >>=
s->quarter_sample;
860 if (
ctx->real_sprite_warping_points == 1) {
861 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413 &&
a >=
s->quarter_sample)
862 sum =
ctx->sprite_offset[0][n] / (1 << (
a -
s->quarter_sample));
864 sum =
RSHIFT(
ctx->sprite_offset[0][n] * (1 <<
s->quarter_sample),
a);
866 dx =
ctx->sprite_delta[n][0];
867 dy =
ctx->sprite_delta[n][1];
870 dy -= 1 << (
shift +
a + 1);
872 dx -= 1 << (
shift +
a + 1);
873 mb_v =
ctx->sprite_offset[0][n] + dx *
s->mb_x * 16
U + dy *
s->mb_y * 16
U;
876 for (y = 0; y < 16; y++) {
879 v = mb_v + (unsigned)dy * y;
881 for (x = 0; x < 16; x++) {
886 sum =
RSHIFT(sum,
a + 8 -
s->quarter_sample);
904 const int16_t *
const dc_val =
s->dc_val +
s->block_index[n];
905 const int wrap =
s->block_wrap[n];
914 int b = dc_val[-1 -
wrap];
915 int c = dc_val[-
wrap];
919 if (
s->first_slice_line && n != 3) {
922 if (n != 1 &&
s->mb_x ==
s->resync_mb_x)
925 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1) {
926 if (n == 0 || n == 4 || n == 5)
942 int scale = n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
954 if (
level & (~2047)) {
958 "dc<0 at %dx%d\n",
s->mb_x,
s->mb_y);
963 "dc overflow at %dx%d\n",
s->mb_x,
s->mb_y);
972 s->dc_val[
s->block_index[n]] =
level;
1035 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1038 h->c.first_slice_line = 1;
1039 for (;
h->c.mb_y <
h->c.mb_height;
h->c.mb_y++) {
1041 for (;
h->c.mb_x <
h->c.mb_width;
h->c.mb_x++) {
1042 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1048 if (
h->c.mb_x ==
h->c.resync_mb_x &&
h->c.mb_y ==
h->c.resync_mb_y + 1)
1049 h->c.first_slice_line = 0;
1061 "mcbpc corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1064 }
while (cbpc == 8);
1066 h->c.cbp_table[xy] = cbpc & 3;
1073 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1075 h->c.mbintra_table[xy] = 1;
1076 for (
i = 0;
i < 6;
i++) {
1081 "DC corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1088 h->c.pred_dir_table[xy] = dir;
1091 int16_t *
const mot_val =
h->c.cur_pic.motion_val[0][
h->c.block_index[0]];
1092 const int stride =
h->c.b8_stride * 2;
1100 if (
bits & 0x10000) {
1132 "mcbpc corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1138 h->c.cbp_table[xy] = cbpc & (8 + 3);
1140 h->c.mb_intra = ((cbpc & 4) != 0);
1142 if (
h->c.mb_intra) {
1144 h->c.mbintra_table[xy] = 1;
1163 if ((cbpc & 16) == 0) {
1197 for (
i = 0;
i < 4;
i++) {
1226 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1228 h->c.mb_x =
h->c.resync_mb_x;
1229 h->c.first_slice_line = 1;
1230 for (
h->c.mb_y =
h->c.resync_mb_y; mb_num < mb_count; h->
c.mb_y++) {
1232 for (; mb_num < mb_count &&
h->c.mb_x <
h->c.mb_width;
h->c.mb_x++) {
1233 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1237 if (
h->c.mb_x ==
h->c.resync_mb_x &&
h->c.mb_y ==
h->c.resync_mb_y + 1)
1238 h->c.first_slice_line = 0;
1245 "cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1249 h->c.cbp_table[xy] |= cbpy << 2;
1252 if (
IS_INTRA(
h->c.cur_pic.mb_type[xy])) {
1260 "I cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1264 if (
h->c.cbp_table[xy] & 8)
1266 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1268 for (
i = 0;
i < 6;
i++) {
1273 "DC corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1280 h->c.cbp_table[xy] &= 3;
1281 h->c.cbp_table[xy] |= cbpy << 2;
1283 h->c.pred_dir_table[xy] = dir;
1284 }
else if (
IS_SKIP(
h->c.cur_pic.mb_type[xy])) {
1285 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1286 h->c.cbp_table[xy] = 0;
1292 "P cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1296 if (
h->c.cbp_table[xy] & 8)
1298 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1300 h->c.cbp_table[xy] &= 3;
1301 h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1305 if (mb_num >= mb_count)
1327 h->c.mb_x,
h->c.mb_y, part_a_error);
1331 if (
h->c.resync_mb_x +
h->c.resync_mb_y *
h->c.mb_width + mb_num >
h->c.mb_num) {
1334 h->c.mb_x,
h->c.mb_y, part_a_error);
1338 h->mb_num_left = mb_num;
1345 "marker missing after first I partition at %d %d\n",
1346 h->c.mb_x,
h->c.mb_y);
1354 "marker missing after first P partition at %d %d\n",
1355 h->c.mb_x,
h->c.mb_y);
1360 h->c.mb_x - 1,
h->c.mb_y, part_a_end);
1382 int n,
int coded,
int intra,
1383 int use_intra_dc_vlc,
int rvlc)
1390 const uint8_t *scan_table;
1396 if (use_intra_dc_vlc) {
1398 if (
h->partitioned_frame) {
1399 level =
h->c.dc_val[
h->c.block_index[n]];
1404 dc_pred_dir = (
h->c.pred_dir_table[
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride] << n) & 32;
1427 if (dc_pred_dir == 0)
1428 scan_table =
h->c.permutated_intra_v_scantable;
1430 scan_table =
h->c.permutated_intra_h_scantable;
1432 scan_table =
h->c.intra_scantable.permutated;
1439 h->c.block_last_index[n] =
i;
1447 scan_table =
h->c.intra_scantable.permutated;
1449 if (
ctx->mpeg_quant) {
1457 qmul =
h->c.qscale << 1;
1458 qadd = (
h->c.qscale - 1) | 1;
1475 "1. marker bit missing in rvlc esc\n");
1488 "2. marker bit missing in rvlc esc\n");
1514 cache ^= 0xC0000000;
1516 if (cache & 0x80000000) {
1517 if (cache & 0x40000000) {
1532 "1. marker bit missing in 3. esc\n");
1543 "2. marker bit missing in 3. esc\n");
1552 if (
h->c.error_recognition >= FF_ER_COMPLIANT) {
1555 const int run1=
run - rl->
max_run[last][abs_level] - 1;
1556 if (abs_level <= rl->max_level[last][
run]) {
1560 if (
h->c.error_recognition > FF_ER_COMPLIANT) {
1561 if (abs_level <= rl->max_level[last][
run]*2) {
1565 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1578 if ((
unsigned)(
level + 2048) > 4095) {
1582 "|level| overflow in 3. esc, qp=%d\n",
1616 ff_tlog(
h->c.avctx,
"dct[%d][%d] = %- 4d end?:%d\n", scan_table[
i&63]&7, scan_table[
i&63] >> 3,
level,
i>62);
1621 "ac-tex damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1636 if (!use_intra_dc_vlc) {
1646 h->c.block_last_index[n] =
i;
1657 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1659 const int mb_type =
h->c.cur_pic.mb_type[xy];
1660 int cbp =
h->c.cbp_table[xy];
1662 const int use_intra_dc_vlc =
h->c.qscale <
ctx->intra_dc_threshold;
1664 if (
h->c.cur_pic.qscale_table[xy] !=
h->c.qscale)
1670 for (
i = 0;
i < 4;
i++) {
1671 h->c.mv[0][
i][0] =
h->c.cur_pic.motion_val[0][
h->c.block_index[
i]][0];
1672 h->c.mv[0][
i][1] =
h->c.cur_pic.motion_val[0][
h->c.block_index[
i]][1];
1678 for (
i = 0;
i < 6;
i++)
1679 h->c.block_last_index[
i] = -1;
1685 h->c.mb_skipped = 0;
1686 h->c.cur_pic.mbskip_table[xy] = 0;
1689 h->c.mb_skipped = 1;
1690 h->c.cur_pic.mbskip_table[xy] = 1;
1692 }
else if (
h->c.mb_intra) {
1693 h->c.ac_pred =
IS_ACPRED(
h->c.cur_pic.mb_type[xy]);
1694 }
else if (!
h->c.mb_intra) {
1706 h->c.ac_pred =
IS_ACPRED(
h->c.cur_pic.mb_type[xy]);
1711 h->c.bdsp.clear_blocks(
h->block[0]);
1713 for (
i = 0;
i < 6;
i++) {
1715 use_intra_dc_vlc,
ctx->rvlc) < 0) {
1717 "texture corrupted at %d %d %d\n",
1718 h->c.mb_x,
h->c.mb_y,
h->c.mb_intra);
1726 if (--
h->mb_num_left <= 0) {
1733 const int delta =
h->c.mb_x + 1 ==
h->c.mb_width ? 2 : 1;
1734 if (
h->c.cbp_table[xy +
delta])
1744 int cbpc, cbpy,
i, cbp, pred_x, pred_y,
mx,
my, dquant;
1745 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1746 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1757 for (
i = 0;
i < 6;
i++)
1758 h->c.block_last_index[
i] = -1;
1770 h->c.cur_pic.mbskip_table[xy] = 0;
1771 h->c.mb_skipped = 0;
1776 h->c.mv[0][0][0] = 0;
1777 h->c.mv[0][0][1] = 0;
1778 h->c.cur_pic.mbskip_table[xy] = 1;
1779 h->c.mb_skipped = 1;
1786 "mcbpc damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1789 }
while (cbpc == 20);
1792 h->c.mb_intra = ((cbpc & 4) != 0);
1795 h->c.bdsp.clear_blocks(
h->block[0]);
1805 "P cbpy damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1809 cbp = (cbpc & 3) | (cbpy << 2);
1812 if ((!
h->c.progressive_sequence) &&
1817 if ((cbpc & 16) == 0) {
1825 h->c.mv[0][0][0] =
mx;
1826 h->c.mv[0][0][1] =
my;
1827 }
else if ((!
h->c.progressive_sequence) &&
get_bits1(&
h->gb)) {
1838 for (
i = 0;
i < 2;
i++) {
1847 h->c.mv[0][
i][0] =
mx;
1848 h->c.mv[0][
i][1] =
my;
1864 h->c.mv[0][0][0] =
mx;
1865 h->c.mv[0][0][1] =
my;
1870 for (
i = 0;
i < 4;
i++) {
1879 h->c.mv[0][
i][0] =
mx;
1880 h->c.mv[0][
i][1] =
my;
1893 if (
h->c.mb_x == 0) {
1894 for (
i = 0;
i < 2;
i++) {
1895 h->c.last_mv[
i][0][0] =
1896 h->c.last_mv[
i][0][1] =
1897 h->c.last_mv[
i][1][0] =
1898 h->c.last_mv[
i][1][1] = 0;
1905 h->c.mb_skipped =
h->c.next_pic.mbskip_table[
h->c.mb_y *
h->c.mb_stride +
h->c.mb_x];
1907 if (
h->c.mb_skipped) {
1909 for (
i = 0;
i < 6;
i++)
1910 h->c.block_last_index[
i] = -1;
1917 h->c.mv[1][0][1] = 0;
1939 h->c.bdsp.clear_blocks(
h->block[0]);
1948 if (!
h->c.progressive_sequence) {
1976 h->c.last_mv[0][1][0] =
1977 h->c.last_mv[0][0][0] =
1978 h->c.mv[0][0][0] =
mx;
1979 h->c.last_mv[0][1][1] =
1980 h->c.last_mv[0][0][1] =
1981 h->c.mv[0][0][1] =
my;
1989 h->c.last_mv[1][1][0] =
1990 h->c.last_mv[1][0][0] =
1991 h->c.mv[1][0][0] =
mx;
1992 h->c.last_mv[1][1][1] =
1993 h->c.last_mv[1][0][1] =
1994 h->c.mv[1][0][1] =
my;
2002 for (
i = 0;
i < 2;
i++) {
2005 h->c.last_mv[0][
i][0] =
2006 h->c.mv[0][
i][0] =
mx;
2007 h->c.last_mv[0][
i][1] = (
h->c.mv[0][
i][1] =
my) * 2;
2014 for (
i = 0;
i < 2;
i++) {
2017 h->c.last_mv[1][
i][0] =
2018 h->c.mv[1][
i][0] =
mx;
2019 h->c.last_mv[1][
i][1] = (
h->c.mv[1][
i][1] =
my) * 2;
2037 h->c.cur_pic.mb_type[xy] = mb_type;
2039 int use_intra_dc_vlc;
2045 "I cbpc damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
2048 }
while (cbpc == 8);
2063 "I cbpy damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
2066 cbp = (cbpc & 3) | (cbpy << 2);
2068 use_intra_dc_vlc =
h->c.qscale <
ctx->intra_dc_threshold;
2073 if (!
h->c.progressive_sequence)
2076 h->c.bdsp.clear_blocks(
h->block[0]);
2078 for (
i = 0;
i < 6;
i++) {
2080 1, use_intra_dc_vlc, 0) < 0)
2088 for (
i = 0;
i < 6;
i++) {
2098 if (
h->c.mb_x +
h->c.mb_y*
h->c.mb_width + 1 > next && (
h->c.avctx->err_recognition &
AV_EF_AGGRESSIVE)) {
2100 }
else if (
h->c.mb_x +
h->c.mb_y*
h->c.mb_width + 1 >= next)
2104 const int delta =
h->c.mb_x + 1 ==
h->c.mb_width ? 2 : 1;
2106 (
h->c.mb_x +
delta >=
h->c.mb_width)
2107 ?
FFMIN(
h->c.mb_y + 1,
h->c.mb_height - 1)
2109 if (
h->c.next_pic.mbskip_table[xy +
delta])
2160 int cc, dct_dc_size, dct_diff,
code, j, idx = 1, group = 0,
run = 0,
2161 additional_code_len, sign, mismatch;
2163 const uint8_t *
const scantable =
h->c.intra_scantable.permutated;
2164 const uint16_t *quant_matrix;
2166 const int min = -1 * (1 << (
h->c.avctx->bits_per_raw_sample + 6));
2167 const int max = ((1 << (
h->c.avctx->bits_per_raw_sample + 6)) - 1);
2168 int shift = 3 -
ctx->dct_precision;
2177 quant_matrix =
h->c.intra_matrix;
2184 quant_matrix =
h->c.chroma_intra_matrix;
2187 if (dct_dc_size == 0) {
2192 if (dct_dc_size > 8) {
2199 h->c.last_dc[cc] += dct_diff;
2201 if (
ctx->mpeg_quant)
2202 block[0] =
h->c.last_dc[cc] * (8 >>
h->c.intra_dc_precision);
2204 block[0] =
h->c.last_dc[cc] * (8 >>
h->c.intra_dc_precision) * (8 >>
ctx->dct_precision);
2208 mismatch ^=
block[0];
2225 }
else if (group >= 1 && group <= 6) {
2227 run = 1 << additional_code_len;
2228 if (additional_code_len)
2232 }
else if (group >= 7 && group <= 12) {
2237 run = (1 << (additional_code_len - 1)) +
code;
2241 j = scantable[idx++];
2242 block[j] = sign ? 1 : -1;
2243 }
else if (group >= 13 && group <= 20) {
2247 j = scantable[idx++];
2249 }
else if (group == 21) {
2253 j = scantable[idx++];
2254 additional_code_len =
h->c.avctx->bits_per_raw_sample +
ctx->dct_precision + 4;
2255 flc =
get_bits(&
h->gb, additional_code_len);
2256 if (flc >> (additional_code_len-1))
2257 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
2261 block[j] = ((
block[j] * quant_matrix[j] *
h->c.qscale) * (1 <<
shift)) / 16;
2263 mismatch ^=
block[j];
2266 block[63] ^= mismatch & 1;
2272 int16_t macroblock[256],
int n)
2276 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
2277 dpcm_residual,
left, top, topleft, min_left_top, max_left_top, p, p2,
output;
2278 height = 16 >> (n ?
h->c.chroma_y_shift : 0);
2279 w = 16 >> (n ?
h->c.chroma_x_shift : 0);
2281 block_mean =
get_bits(&
h->gb,
h->c.avctx->bits_per_raw_sample);
2282 if (block_mean == 0){
2286 h->c.last_dc[n] = block_mean * (1 << (
ctx->dct_precision +
h->c.intra_dc_precision));
2289 if (rice_parameter == 0) {
2294 if (rice_parameter == 15)
2297 if (rice_parameter > 11) {
2303 output = 1 << (
h->c.avctx->bits_per_raw_sample - 1);
2304 top = 1 << (
h->c.avctx->bits_per_raw_sample - 1);
2306 for (j = 0; j <
w; j++) {
2313 if (rice_prefix_code == 11)
2314 dpcm_residual =
get_bits(&
h->gb,
h->c.avctx->bits_per_raw_sample);
2316 if (rice_prefix_code == 12) {
2320 rice_suffix_code =
get_bitsz(&
h->gb, rice_parameter);
2321 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2325 if (dpcm_residual & 1)
2326 dpcm_residual = (-1 * dpcm_residual) >> 1;
2328 dpcm_residual = (dpcm_residual >> 1);
2331 top = macroblock[idx-
w];
2333 p =
left + top - topleft;
2335 if (p < min_left_top)
2339 if (p > max_left_top)
2342 p2 = (
FFMIN(min_left_top, topleft) +
FFMAX(max_left_top, topleft)) >> 1;
2347 dpcm_residual *= -1;
2349 macroblock[idx++] =
output = (dpcm_residual + p) & ((1 <<
h->c.avctx->bits_per_raw_sample) - 1);
2361 ctx->dpcm_direction = 0;
2382 for (
i = 0;
i < 3;
i++) {
2406 int hours, minutes, seconds;
2418 s->time_base = seconds + 60*(minutes + 60*hours);
2442 int visual_object_type;
2443 int is_visual_object_identifier =
get_bits1(gb);
2445 if (is_visual_object_identifier) {
2448 visual_object_type =
get_bits(gb, 4);
2453 if (video_signal_type) {
2454 int video_range, color_description;
2461 if (color_description) {
2462 s->avctx->color_primaries =
get_bits(gb, 8);
2477 for (
i = 0;
i < 64;
i++) {
2478 int j =
s->idsp.idct_permutation[
i];
2480 s->intra_matrix[j] = v;
2481 s->chroma_intra_matrix[j] = v;
2484 s->inter_matrix[j] = v;
2485 s->chroma_inter_matrix[j] = v;
2497 for (
i = 0;
i < 64;
i++) {
2500 s->intra_matrix[j] = v;
2501 s->chroma_intra_matrix[j] = v;
2509 for (
i = 0;
i < 64;
i++) {
2518 for (
i = 0;
i < 64;
i++) {
2521 s->chroma_intra_matrix[j] = v;
2529 for (
i = 0;
i < 64;
i++) {
2541 uint8_t extension_type;
2559 int bits_per_raw_sample;
2560 int rgb, chroma_format;
2580 bits_per_raw_sample =
get_bits(gb, 4);
2581 if (bits_per_raw_sample == 10) {
2591 if (
rgb !=
ctx->rgb ||
s->chroma_format != chroma_format)
2592 s->context_reinit = 1;
2593 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
2595 s->chroma_format = chroma_format;
2598 check_marker(
s->avctx, gb,
"before video_object_layer_width");
2600 check_marker(
s->avctx, gb,
"before video_object_layer_height");
2602 check_marker(
s->avctx, gb,
"after video_object_layer_height");
2606 if (
s->width &&
s->height &&
2608 s->context_reinit = 1;
2613 aspect_ratio_info =
get_bits(gb, 4);
2615 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2616 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2626 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2629 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2631 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2659 h->c.studio_profile = 1;
2662 }
else if (
h->c.studio_profile) {
2672 aspect_ratio_info =
get_bits(gb, 4);
2674 h->c.avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2675 h->c.avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2681 int chroma_format =
get_bits(gb, 2);
2692 check_marker(
h->c.avctx, gb,
"after first_half_vbv_buffer_size");
2695 check_marker(
h->c.avctx, gb,
"after first_half_vbv_occupancy");
2697 check_marker(
h->c.avctx, gb,
"after latter_half_vbv_occupancy");
2702 if (
h->picture_number == 0) {
2703 switch (
ctx->vo_type) {
2722 check_marker(
h->c.avctx, gb,
"before time_increment_resolution");
2724 h->c.avctx->framerate.num =
get_bits(gb, 16);
2725 if (!
h->c.avctx->framerate.num) {
2730 ctx->time_increment_bits =
av_log2(
h->c.avctx->framerate.num - 1) + 1;
2731 if (
ctx->time_increment_bits < 1)
2732 ctx->time_increment_bits = 1;
2737 h->c.avctx->framerate.den =
get_bits(gb,
ctx->time_increment_bits);
2739 h->c.avctx->framerate.den = 1;
2751 !(
h->c.width &&
h->c.codec_tag ==
AV_RL32(
"MP4S"))) {
2752 if (
h->c.width &&
h->c.height &&
2754 h->c.context_reinit = 1;
2760 h->c.progressive_sequence =
2762 h->c.interlaced_dct = 0;
2765 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
2786 if (
ctx->num_sprite_warping_points > 3) {
2788 "%d sprite_warping_points\n",
2789 ctx->num_sprite_warping_points);
2790 ctx->num_sprite_warping_points = 0;
2804 if (
ctx->quant_precision != 5)
2806 "quant precision %d\n",
ctx->quant_precision);
2807 if (
ctx->quant_precision < 3 ||
ctx->quant_precision > 9)
2808 ctx->quant_precision = 5;
2810 ctx->quant_precision = 5;
2823 for (
i = 0;
i < 64;
i++) {
2835 h->c.intra_matrix[j] = last;
2839 for (;
i < 64;
i++) {
2841 h->c.intra_matrix[j] = last;
2848 for (
i = 0;
i < 64;
i++) {
2860 h->c.inter_matrix[j] = v;
2864 for (;
i < 64;
i++) {
2866 h->c.inter_matrix[j] = last;
2876 h->c.quarter_sample = 0;
2885 int estimation_method =
get_bits(gb, 2);
2886 if (estimation_method < 2) {
2901 if (!
check_marker(
h->c.avctx, gb,
"in complexity estimation part 1")) {
2919 if (!
check_marker(
h->c.avctx, gb,
"in complexity estimation part 2")) {
2923 if (estimation_method == 1) {
2929 "Invalid Complexity estimation method %d\n",
2934 ctx->cplx_estimation_trash_i =
2935 ctx->cplx_estimation_trash_p =
2936 ctx->cplx_estimation_trash_b = 0;
2942 if (
h->data_partitioning)
2945 if (vo_ver_id != 1) {
2947 if (
ctx->new_pred) {
2954 "reduced resolution VOP not supported\n");
2961 if (
ctx->scalability) {
2963 int h_sampling_factor_n;
2964 int h_sampling_factor_m;
2965 int v_sampling_factor_n;
2966 int v_sampling_factor_m;
2971 h_sampling_factor_n =
get_bits(gb, 5);
2972 h_sampling_factor_m =
get_bits(gb, 5);
2973 v_sampling_factor_n =
get_bits(gb, 5);
2974 v_sampling_factor_m =
get_bits(gb, 5);
2977 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2978 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2981 ctx->scalability = 0;
2991 av_log(
h->c.avctx,
AV_LOG_DEBUG,
"tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
2992 h->c.avctx->framerate.den,
h->c.avctx->framerate.num,
2993 ctx->time_increment_bits,
2994 ctx->quant_precision,
2995 h->c.progressive_sequence,
2997 ctx->scalability ?
"scalability " :
"" ,
2998 h->c.quarter_sample ?
"qpel " :
"",
2999 h->data_partitioning ?
"partition " :
"",
3000 ctx->rvlc ?
"rvlc " :
""
3017 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
3028 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
3030 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
3032 ctx->divx_version = ver;
3033 ctx->divx_build = build;
3034 h->divx_packed = e == 3 && last ==
'p';
3038 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
3040 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
3042 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
3044 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
3046 "Unknown Lavc version string encountered, %d.%d.%d; "
3047 "clamping sub-version values to 8-bits.\n",
3050 build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
3054 if (strcmp(buf,
"ffmpeg") == 0)
3055 ctx->lavc_build = 4600;
3058 ctx->lavc_build = build;
3061 e = sscanf(buf,
"XviD%d", &build);
3063 ctx->xvid_build = build;
3069 const uint8_t new_perm[64],
3070 const uint8_t old_perm[64])
3075 for (
int i = 0;
i < 64; ++
i)
3082 uint8_t old_permutation[64];
3084 memcpy(old_permutation,
s->idsp.idct_permutation,
sizeof(old_permutation));
3090 s->idsp.idct_permutation);
3102 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1) {
3103 if (
h->c.codec_tag ==
AV_RL32(
"XVID") ||
3104 h->c.codec_tag ==
AV_RL32(
"XVIX") ||
3105 h->c.codec_tag ==
AV_RL32(
"RMP4") ||
3106 h->c.codec_tag ==
AV_RL32(
"ZMP4") ||
3108 ctx->xvid_build = 0;
3111 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1)
3112 if (
h->c.codec_tag ==
AV_RL32(
"DIVX") &&
ctx->vo_type == 0 &&
3113 ctx->vol_control_parameters == 0)
3114 ctx->divx_version = 400;
3116 if (
ctx->xvid_build >= 0 &&
ctx->divx_version >= 0) {
3118 ctx->divx_build = -1;
3122 if (
h->c.codec_tag ==
AV_RL32(
"XVIX"))
3125 if (
h->c.codec_tag ==
AV_RL32(
"UMP4"))
3128 if (
ctx->divx_version >= 500 &&
ctx->divx_build < 1814)
3131 if (
ctx->divx_version > 502 &&
ctx->divx_build < 1814)
3134 if (
ctx->xvid_build <= 3
U)
3135 h->padding_bug_score = 256 * 256 * 256 * 64;
3137 if (
ctx->xvid_build <= 1
U)
3140 if (
ctx->xvid_build <= 12
U)
3143 if (
ctx->xvid_build <= 32
U)
3146 #define SET_QPEL_FUNC(postfix1, postfix2) \
3147 h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3148 h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3149 h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
3151 if (
ctx->lavc_build < 4653
U)
3154 if (
ctx->lavc_build < 4655
U)
3157 if (
ctx->lavc_build < 4670
U)
3160 if (
ctx->lavc_build <= 4712
U)
3163 if ((
ctx->lavc_build&0xFF) >= 100) {
3164 if (
ctx->lavc_build > 3621476 &&
ctx->lavc_build < 3752552 &&
3165 (
ctx->lavc_build < 3752037 ||
ctx->lavc_build > 3752191)
3170 if (
ctx->divx_version >= 0)
3172 if (
ctx->divx_version == 501 &&
ctx->divx_build == 20020416)
3173 h->padding_bug_score = 256 * 256 * 256 * 64;
3175 if (
ctx->divx_version < 500
U)
3178 if (
ctx->divx_version >= 0)
3200 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
3201 h->c.workaround_bugs,
ctx->lavc_build,
ctx->xvid_build,
3202 ctx->divx_version,
ctx->divx_build,
h->divx_packed ?
"p" :
"");
3204 if (CONFIG_MPEG4_DECODER &&
ctx->xvid_build >= 0 &&
3214 int time_incr, time_increment;
3226 if (
h->partitioned_frame)
3237 if (
ctx->time_increment_bits == 0 ||
3240 "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);
3242 for (
ctx->time_increment_bits = 1;
3243 ctx->time_increment_bits < 16;
3244 ctx->time_increment_bits++) {
3248 if ((
show_bits(gb,
ctx->time_increment_bits + 6) & 0x37) == 0x30)
3250 }
else if ((
show_bits(gb,
ctx->time_increment_bits + 5) & 0x1F) == 0x18)
3255 "time_increment_bits set to %d bits, based on bitstream analysis\n",
ctx->time_increment_bits);
3261 time_increment =
get_bits(gb,
ctx->time_increment_bits);
3264 h->c.last_time_base =
h->c.time_base;
3265 h->c.time_base += time_incr;
3266 h->c.time =
h->c.time_base * (
int64_t)
h->c.avctx->framerate.num + time_increment;
3268 if (
h->c.time <
h->c.last_non_b_time) {
3272 h->c.time +=
h->c.avctx->framerate.num;
3275 h->c.pp_time =
h->c.time -
h->c.last_non_b_time;
3276 h->c.last_non_b_time =
h->c.time;
3278 h->c.time = (
h->c.last_time_base + time_incr) * (
int64_t)
h->c.avctx->framerate.num + time_increment;
3279 h->c.pb_time =
h->c.pp_time - (
h->c.last_non_b_time -
h->c.time);
3280 if (
h->c.pp_time <=
h->c.pb_time ||
3281 h->c.pp_time <=
h->c.pp_time -
h->c.pb_time ||
3282 h->c.pp_time <= 0) {
3288 if (
ctx->t_frame == 0)
3289 ctx->t_frame =
h->c.pb_time;
3290 if (
ctx->t_frame == 0)
3296 if (
h->c.pp_field_time <=
h->c.pb_field_time ||
h->c.pb_field_time <= 1) {
3297 h->c.pb_field_time = 2;
3298 h->c.pp_field_time = 4;
3299 if (!
h->c.progressive_sequence)
3304 if (
h->c.avctx->framerate.den)
3308 ff_dlog(
h->c.avctx,
"MPEG4 PTS: %"PRId64
"\n",
pts);
3316 h->skipped_last_frame = 1;
3329 h->c.no_rounding = 0;
3363 if (!
h->c.progressive_sequence) {
3367 h->c.alternate_scan = 0;
3375 if (
h->c.alternate_scan) {
3378 h->c.idsp.idct_permutation);
3382 h->c.idsp.idct_permutation);
3385 h->c.idsp.idct_permutation);
3392 if (
ctx->sprite_brightness_change)
3394 "sprite_brightness_change not supported\n");
3398 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
3399 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
3406 h->c.chroma_qscale =
h->c.qscale =
get_bits(gb,
ctx->quant_precision);
3407 if (
h->c.qscale == 0) {
3409 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
3415 if (
ctx->f_code == 0) {
3417 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
3425 if (
ctx->b_code == 0) {
3427 "Error, header damaged or not MPEG4 header (b_code=0)\n");
3435 "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",
3436 h->c.qscale,
ctx->f_code,
ctx->b_code,
3439 h->c.top_field_first,
h->c.quarter_sample ?
'q' :
'h',
3440 h->data_partitioning,
ctx->resync_marker,
3441 ctx->num_sprite_warping_points,
ctx->sprite_warping_accuracy,
3442 1 -
h->c.no_rounding,
ctx->vo_type,
3443 ctx->vol_control_parameters ?
" VOLC" :
" ",
ctx->intra_dc_threshold,
3444 ctx->cplx_estimation_trash_i,
ctx->cplx_estimation_trash_p,
3445 ctx->cplx_estimation_trash_b,
3451 if (!
ctx->scalability) {
3455 if (
ctx->enhancement_type) {
3456 int load_backward_shape =
get_bits1(gb);
3457 if (load_backward_shape)
3459 "load backward shape isn't supported\n");
3465 h->c.dct_unquantize_intra =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_intra
3466 :
ctx->dct_unquantize_h263_intra;
3468 h->c.dct_unquantize_inter =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_inter :
NULL;
3474 if (
ctx->vo_type == 0 &&
ctx->vol_control_parameters == 0 &&
3475 ctx->divx_version == -1 &&
h->picture_number == 0) {
3477 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3481 h->picture_number++;
3484 h->c.h_edge_pos =
h->c.width;
3485 h->c.v_edge_pos =
h->c.height;
3516 h->partitioned_frame = 0;
3517 h->c.interlaced_dct = 0;
3540 h->c.intra_dc_precision =
get_bits(gb, 2);
3557 int visual_object_type;
3560 visual_object_type =
get_bits(gb, 4);
3583 int header,
int parse_only)
3586 unsigned startcode, v;
3596 if (!
s->studio_profile &&
s->avctx->bits_per_raw_sample != 8)
3597 s->avctx->bits_per_raw_sample = 0;
3609 (
ctx->divx_version >= 0 ||
ctx->xvid_build >= 0) ||
s->codec_tag ==
AV_RL32(
"QMP4")) {
3620 startcode = ((startcode << 8) | v) & 0xffffffff;
3622 if ((startcode & 0xFFFFFF00) != 0x100)
3627 if (startcode <= 0x11F)
3628 name =
"Video Object Start";
3629 else if (startcode <= 0x12F)
3630 name =
"Video Object Layer Start";
3631 else if (startcode <= 0x13F)
3633 else if (startcode <= 0x15F)
3634 name =
"FGS bp start";
3635 else if (startcode <= 0x1AF)
3637 else if (startcode == 0x1B0)
3638 name =
"Visual Object Seq Start";
3639 else if (startcode == 0x1B1)
3640 name =
"Visual Object Seq End";
3641 else if (startcode == 0x1B2)
3643 else if (startcode == 0x1B3)
3644 name =
"Group of VOP start";
3645 else if (startcode == 0x1B4)
3646 name =
"Video Session Error";
3647 else if (startcode == 0x1B5)
3648 name =
"Visual Object Start";
3649 else if (startcode == 0x1B6)
3650 name =
"Video Object Plane start";
3651 else if (startcode == 0x1B7)
3652 name =
"slice start";
3653 else if (startcode == 0x1B8)
3654 name =
"extension start";
3655 else if (startcode == 0x1B9)
3657 else if (startcode == 0x1BA)
3658 name =
"FBA Object start";
3659 else if (startcode == 0x1BB)
3660 name =
"FBA Object Plane start";
3661 else if (startcode == 0x1BC)
3662 name =
"Mesh Object start";
3663 else if (startcode == 0x1BD)
3664 name =
"Mesh Object Plane start";
3665 else if (startcode == 0x1BE)
3666 name =
"Still Texture Object start";
3667 else if (startcode == 0x1BF)
3668 name =
"Texture Spatial Layer start";
3669 else if (startcode == 0x1C0)
3670 name =
"Texture SNR Layer start";
3671 else if (startcode == 0x1C1)
3672 name =
"Texture Tile start";
3673 else if (startcode == 0x1C2)
3674 name =
"Texture Shape Layer start";
3675 else if (startcode == 0x1C3)
3676 name =
"stuffing start";
3677 else if (startcode <= 0x1C5)
3679 else if (startcode <= 0x1FF)
3680 name =
"System start";
3685 if (startcode >= 0x120 && startcode <= 0x12F) {
3702 s->studio_profile = 1;
3705 }
else if (
s->studio_profile) {
3712 if (
s->studio_profile) {
3729 if (
s->studio_profile) {
3730 if (!
s->avctx->bits_per_raw_sample) {
3743 h->skipped_last_frame = 0;
3745 if (
ctx->bitstream_buffer) {
3747 int bitstream_buffer_size =
ctx->bitstream_buffer->size;
3748 const uint8_t *buf =
h->gb.buffer;
3750 if (
h->divx_packed) {
3751 for (
int i = 0;
i < buf_size - 3;
i++) {
3752 if (buf[
i] == 0 && buf[
i+1] == 0 && buf[
i+2] == 1) {
3753 if (buf[
i+3] == 0xB0) {
3755 bitstream_buffer_size = 0;
3761 ctx->bitstream_buffer->size = 0;
3762 if (bitstream_buffer_size && (
h->divx_packed || buf_size <=
MAX_NVOP_SIZE)) {
3764 bitstream_buffer_size);
3783 if (
h->divx_packed) {
3784 int current_pos =
ctx->bitstream_buffer &&
h->gb.buffer ==
ctx->bitstream_buffer->data ? 0 : (
get_bits_count(&
h->gb) >> 3);
3785 int startcode_found = 0;
3789 if (buf_size - current_pos > 7) {
3792 for (
i = current_pos;
i < buf_size - 4;
i++)
3797 buf[
i + 3] == 0xB6) {
3798 startcode_found = !(buf[
i + 4] & 0x40);
3803 if (startcode_found) {
3804 if (!
ctx->showed_packed_warning) {
3806 "wasteful way to store B-frames ('packed B-frames'). "
3807 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
3808 ctx->showed_packed_warning = 1;
3814 ctx->bitstream_buffer->data = buf + current_pos;
3815 ctx->bitstream_buffer->size = buf_size - current_pos;
3822 #if CONFIG_MPEG4_DECODER
3826 memset(&
s->buffer_pools, 0,
sizeof(
s->buffer_pools));
3827 memset(&
s->next_pic, 0,
sizeof(
s->next_pic));
3828 memset(&
s->last_pic, 0,
sizeof(
s->last_pic));
3829 memset(&
s->cur_pic, 0,
sizeof(
s->cur_pic));
3831 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
3833 s->ac_val_base =
NULL;
3835 memset(&
s->sc, 0,
sizeof(
s->sc));
3837 s->p_field_mv_table_base =
NULL;
3838 for (
int i = 0;
i < 2;
i++)
3839 for (
int j = 0; j < 2; j++)
3840 s->p_field_mv_table[
i][j] =
NULL;
3842 s->dc_val_base =
NULL;
3843 s->coded_block_base =
NULL;
3844 s->mbintra_table =
NULL;
3845 s->cbp_table =
NULL;
3846 s->pred_dir_table =
NULL;
3848 s->mbskip_table =
NULL;
3850 s->er.error_status_table =
NULL;
3851 s->er.er_temp_buffer =
NULL;
3852 s->mb_index2xy =
NULL;
3854 s->context_initialized = 0;
3855 s->context_reinit = 0;
3863 memcpy(
s, s1,
sizeof(*
s));
3881 int init =
s->h.c.context_initialized;
3885 ret = update_mpvctx(&
s->h.c, &s1->
h.
c);
3947 static av_cold void mpeg4_init_static(
void)
3962 for (
unsigned i = 0;
i < 12;
i++) {
4003 ctx->lavc_build = -1;
4024 ctx->time_increment_bits = 4;
4025 ctx->quant_precision = 5;
4062 #define OFFSET(x) offsetof(H263DecContext, x)
4063 #define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
4070 static const AVClass mpeg4_class = {
4085 .close = mpeg4_close,
4090 .flush = mpeg4_flush,
4095 .p.priv_class = &mpeg4_class,
4097 #if CONFIG_MPEG4_NVDEC_HWACCEL
4100 #if CONFIG_MPEG4_VAAPI_HWACCEL
4103 #if CONFIG_MPEG4_VDPAU_HWACCEL
4106 #if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
int padding_bug_score
used to detect the VERY common padding bug in MPEG-4
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
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.
VLCElem ff_h263_cbpy_vlc[]
#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
int sprite_warping_accuracy
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_bits_left(GetBitContext *gb)
int showed_packed_warning
flag for having shown the warning about invalid Divx B-frames
static const uint8_t mpeg4_block_count[4]
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
const uint8_t ff_sprite_trajectory_lens[15]
static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, int parse_only)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
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
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
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_gop_header(MpegEncContext *s, GetBitContext *gb)
#define CORE_STUDIO_VO_TYPE
static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
#define AV_LOG_VERBOSE
Detailed information.
static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx, MpegEncContext *const s)
static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, int16_t macroblock[256], int n)
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 UPDATE_CACHE(name, gb)
int ff_mpeg4_get_video_packet_prefix_length(enum AVPictureType pict_type, int f_code, int b_code)
const FFCodec ff_mpeg4_decoder
#define FF_BUG_HPEL_CHROMA
static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
#define FF_DEBUG_PICT_INFO
static int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int level)
#define GET_CACHE(name, gb)
static void skip_bits(GetBitContext *s, int n)
static VLCElem studio_luma_dc[528]
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
int is_copy
When using frame-threaded decoding, this field is set for the first worker thread (e....
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
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 mpeg4_decode_partitioned_mb(H263DecContext *const h)
decode partition C of one MB.
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
const AVRational ff_h263_pixel_aspect[16]
#define AV_EF_BITSTREAM
detect bitstream specification deviations
static const VLCElem * studio_intra_tab[12]
int flags
AV_CODEC_FLAG_*.
void(* dct_unquantize_h263_intra)(struct MpegEncContext *s, int16_t *block, int n, int qscale)
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 VOT_STILL_TEXTURE_ID
static int mpeg4_decode_picture_header(H263DecContext *const h)
#define AV_PIX_FMT_YUV444P10
#define HAS_FORWARD_MV(a)
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
static int ff_thread_once(char *control, void(*routine)(void))
int sprite_brightness_change
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define INIT_FIRST_VLC_RL(rl, static_size)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_PROFILE_UNKNOWN
static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id)
void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
Predict the ac.
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
static VLCElem sprite_trajectory[128]
#define CLOSE_READER(name, gb)
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
#define FF_CODEC_DECODE_CB(func)
int8_t * max_level[2]
encoding & decoding
void(* dct_unquantize_mpeg2_intra)(struct MpegEncContext *s, int16_t *block, int n, int qscale)
int cplx_estimation_trash_b
#define SHOW_SBITS(name, gb, num)
#define FF_BUG_NO_PADDING
RLTable ff_mpeg4_rl_intra
#define AV_EF_IGNORE_ERR
ignore errors and continue
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define SKIP_BITS(name, gb, num)
int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
Decode the next video packet.
AVBufferRef * bitstream_buffer
Divx 5.01 puts several frames in a single one, this is used to reorder them.
#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.
#define CODEC_LONG_NAME(str)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
static const VLCElem * rl_vlc[2]
#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 AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define LIBAVUTIL_VERSION_INT
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
static void mpeg4_load_default_matrices(MpegEncContext *s)
Describe the class of an AVClass context structure.
static const int16_t mb_type_b_map[4]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_h263_init_rl_inter(void)
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
struct AVCodecInternal * internal
Private context used for internal data.
#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)
static int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
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)
VLCElem ff_h263_intra_MCBPC_vlc[]
static int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
Decode the dc value.
#define SET_QPEL_FUNC(postfix1, postfix2)
#define ff_mpv_unquantize_init(s, bitexact, q_scale_type)
int cplx_estimation_trash_i
#define UPDATE_THREAD_CONTEXT(func)
const uint8_t ff_alternate_horizontal_scan[64]
#define AV_PIX_FMT_YUV422P10
static const AVOption mpeg4_options[]
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
#define VISUAL_OBJ_STARTCODE
const uint8_t ff_mpeg4_dc_threshold[8]
#define HAS_BACKWARD_MV(a)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static Mpeg4DecContext * h263_to_mpeg4(H263DecContext *h)
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)
#define ADV_SIMPLE_VO_TYPE
static void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
Decode first partition.
int t_frame
time distance of first I -> B, used for interlaced B-frames
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
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 shift(int a, int b)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int sprite_shift[2]
sprite shift [isChroma]
#define FRAME_SKIPPED
Frame is not coded.
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
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]
static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define SLICE_NOEND
no end marker or error found but mb count exceeded
#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 data_partitioning
data partitioning flag from header
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
Decode the next video packet.
int quarter_sample
1->qpel, 0->half pel ME/MC
static const uint8_t header[24]
int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header, int parse_only)
Decode MPEG-4 headers.
#define MB_TYPE_INTERLACED
#define OPEN_READER(name, gb)
av_cold void ff_mpeg4videodsp_init(Mpeg4VideoDSPContext *c)
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
static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
const int16_t ff_mpeg4_default_non_intra_matrix[64]
void(* dct_unquantize_mpeg2_inter)(struct MpegEncContext *s, int16_t *block, int n, int qscale)
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)
uint16_t sprite_traj[4][2]
sprite trajectory points
int cplx_estimation_trash_p
#define AV_LOG_INFO
Standard information.
static void gmc_motion(MpegEncContext *s, const Mpeg4DecContext *ctx, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
static av_cold void permute_quant_matrix(uint16_t matrix[64], const uint8_t new_perm[64], const uint8_t old_perm[64])
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
int time_increment_bits
number of bits to represent the fractional part of time
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define SKIP_COUNTER(name, gb, num)
int num_sprite_warping_points
void ff_mpeg4_mcsel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
#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
const uint8_t ff_alternate_vertical_scan[64]
static int mpeg4_decode_studio_mb(H263DecContext *const h)
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
int8_t * max_run[2]
encoding & decoding
#define INTRA_MCBPC_VLC_BITS
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define FF_BUG_AUTODETECT
autodetection
#define MB_TYPE_BACKWARD_MV
#define FF_DEBUG_STARTCODE
static av_cold int decode_init(AVCodecContext *avctx)
static int mpeg4_decode_mb(H263DecContext *const h)
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
const char * name
Name of the codec implementation.
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int vol_control_parameters
does the stream contain the low_delay flag, used to work around buggy encoders.
#define AV_PROFILE_MPEG4_SIMPLE_STUDIO
#define FF_BUG_QPEL_CHROMA
#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, flags)
static void clear_context(SwrContext *s)
@ 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 AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
static const float pred[4]
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
static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
decode second partition.
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
update_thread_context for mpegvideo-based decoders.
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 keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your see the OFFSET() macro
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)
static VLCElem mb_type_b_vlc[16]
main external API structure.
int ff_mpeg4_decode_partitions(H263DecContext *const h)
Decode the first and second partition.
static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n)
#define SHOW_UBITS(name, gb, num)
const uint8_t ff_mb_type_b_tab[4][2]
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define SLICE_END
end marker found
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
int resync_marker
could this stream contain resync markers
#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)
#define USER_DATA_STARTCODE
static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
static int mpeg4_is_resync(Mpeg4DecContext *ctx)
check if the next stuff is a resync marker or the end.
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
static VLCElem studio_chroma_dc[528]
@ AV_PICTURE_TYPE_P
Predicted.
int divx_packed
divx specific, used to workaround (many) bugs in divx5
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 AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define FF_BUG_XVID_ILACE
VLCElem ff_h263_inter_MCBPC_vlc[]
#define avpriv_request_sample(...)
const uint8_t ff_mpeg4_c_dc_scale_table[32]
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
#define VLC_INIT_RL(rl, static_size)
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static void next_start_code_studio(GetBitContext *gb)
#define VLC_INIT_STATE(_table)
static const int16_t alpha[]
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the next studio vop header.
static VLCElem dc_chrom[512]
#define HWACCEL_VAAPI(codec)
static VLCElem dc_lum[512]
static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
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 UPDATE_THREAD_CONTEXT_FOR_USER(func)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb)
static int mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
Predict the dc.
#define QUANT_MATRIX_EXT_ID
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
#define MB_TYPE_FORWARD_MV
RL_VLC_ELEM * rl_vlc[32]
decoding only
int intra_dc_threshold
QP above which the ac VLC should be used for intra dc.
#define INTER_MCBPC_VLC_BITS
#define SIMPLE_STUDIO_VO_TYPE
const uint8_t ff_mpeg4_studio_intra[12][24][2]