23#define UNCHECKED_BITSTREAM_READER 1
25#include "config_components.h"
55#define IS_3IV1 (s->codec_tag == AV_RL32("3IV1"))
64#define SPRITE_TRAJ_VLC_BITS 6
66#define MB_TYPE_B_VLC_BITS 4
67#define STUDIO_INTRA_BITS 9
92 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
93 uint8_t *
const *ref_picture)
96 int src_x, src_y, motion_x, motion_y;
97 ptrdiff_t
offset, linesize, uvlinesize;
100 motion_x =
ctx->sprite_offset[0][0];
101 motion_y =
ctx->sprite_offset[0][1];
102 src_x =
s->mb_x * 16 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
103 src_y =
s->mb_y * 16 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
104 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
105 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
106 src_x =
av_clip(src_x, -16,
s->width);
107 if (src_x ==
s->width)
109 src_y =
av_clip(src_y, -16,
s->height);
110 if (src_y ==
s->height)
113 linesize =
s->linesize;
114 uvlinesize =
s->uvlinesize;
116 ptr = ref_picture[0] + src_y * linesize + src_x;
118 if ((
unsigned)src_x >=
FFMAX(
s->h_edge_pos - 17, 0) ||
119 (
unsigned)src_y >=
FFMAX(
s->v_edge_pos - 17, 0)) {
120 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
124 s->h_edge_pos,
s->v_edge_pos);
125 ptr =
s->sc.edge_emu_buffer;
128 if ((motion_x | motion_y) & 7) {
129 ctx->mdsp.gmc1(dest_y, ptr, linesize, 16,
130 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
131 ctx->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
132 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
136 dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
137 if (
s->no_rounding) {
138 s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
140 s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
147 motion_x =
ctx->sprite_offset[1][0];
148 motion_y =
ctx->sprite_offset[1][1];
149 src_x =
s->mb_x * 8 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
150 src_y =
s->mb_y * 8 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
151 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
152 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
153 src_x =
av_clip(src_x, -8,
s->width >> 1);
154 if (src_x ==
s->width >> 1)
156 src_y =
av_clip(src_y, -8,
s->height >> 1);
157 if (src_y ==
s->height >> 1)
160 offset = (src_y * uvlinesize) + src_x;
161 ptr = ref_picture[1] +
offset;
162 if ((
unsigned)src_x >=
FFMAX((
s->h_edge_pos >> 1) - 9, 0) ||
163 (
unsigned)src_y >=
FFMAX((
s->v_edge_pos >> 1) - 9, 0)) {
164 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
165 uvlinesize, uvlinesize,
168 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
169 ptr =
s->sc.edge_emu_buffer;
172 ctx->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
173 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
175 ptr = ref_picture[2] +
offset;
177 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
178 uvlinesize, uvlinesize,
181 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
182 ptr =
s->sc.edge_emu_buffer;
184 ctx->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
185 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
189 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
190 uint8_t *
const *ref_picture)
193 int linesize, uvlinesize;
194 const int a =
ctx->sprite_warping_accuracy;
197 linesize =
s->linesize;
198 uvlinesize =
s->uvlinesize;
200 ptr = ref_picture[0];
202 ox =
ctx->sprite_offset[0][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 16 +
203 ctx->sprite_delta[0][1] *
s->mb_y * 16;
204 oy =
ctx->sprite_offset[0][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 16 +
205 ctx->sprite_delta[1][1] *
s->mb_y * 16;
207 ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
209 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
210 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
211 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
212 s->h_edge_pos,
s->v_edge_pos);
213 ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
214 ox +
ctx->sprite_delta[0][0] * 8,
215 oy +
ctx->sprite_delta[1][0] * 8,
216 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
217 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
218 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
219 s->h_edge_pos,
s->v_edge_pos);
224 ox =
ctx->sprite_offset[1][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 8 +
225 ctx->sprite_delta[0][1] *
s->mb_y * 8;
226 oy =
ctx->sprite_offset[1][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 8 +
227 ctx->sprite_delta[1][1] *
s->mb_y * 8;
229 ptr = ref_picture[1];
230 ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
232 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
233 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
234 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
235 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
237 ptr = ref_picture[2];
238 ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
240 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
241 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
242 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
243 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
247 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
248 uint8_t *
const *ref_picture)
252 if (
ctx->real_sprite_warping_points == 1) {
262 uint8_t *dest_cr,
int block_size,
int uvlinesize,
263 int dct_linesize,
int dct_offset)
266 const int act_block_size = block_size * 2;
268 if (
ctx->dpcm_direction == 0) {
269 s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)
ctx->block32[0]);
270 s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)
ctx->block32[1]);
271 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)
ctx->block32[2]);
272 s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)
ctx->block32[3]);
274 dct_linesize = uvlinesize <<
s->interlaced_dct;
275 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
277 s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)
ctx->block32[4]);
278 s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)
ctx->block32[5]);
279 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)
ctx->block32[6]);
280 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)
ctx->block32[7]);
281 if (!
s->chroma_x_shift){
282 s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)
ctx->block32[8]);
283 s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)
ctx->block32[9]);
284 s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[10]);
285 s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[11]);
287 }
else if (
ctx->dpcm_direction == 1) {
288 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
289 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
290 for (
int i = 0;
i < 3;
i++) {
291 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
292 int vsub =
i ?
s->chroma_y_shift : 0;
293 int hsub =
i ?
s->chroma_x_shift : 0;
296 for (
int h = 0;
h < (16 >> (vsub +
lowres));
h++){
297 for (
int w = 0, idx = 0;
w < (16 >> (
hsub +
lowres));
w++, idx += step)
298 dest_pcm[
i][
w] =
src[idx];
299 dest_pcm[
i] += linesize[
i] / 2;
304 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
305 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
307 for (
int i = 0;
i < 3;
i++) {
308 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
309 int vsub =
i ?
s->chroma_y_shift : 0;
310 int hsub =
i ?
s->chroma_x_shift : 0;
313 dest_pcm[
i] += (linesize[
i] / 2) * ((16 >> vsub +
lowres) - 1);
314 for (
int h = (16 >> (vsub +
lowres)) - 1;
h >= 0;
h--){
315 for (
int w = (16 >> (
hsub +
lowres)) - 1, idx = 0;
w >= 0;
w--, idx += step)
316 dest_pcm[
i][
w] =
src[idx];
318 dest_pcm[
i] -= linesize[
i] / 2;
332 int16_t *ac_val, *ac_val1;
333 int8_t *
const qscale_table =
h->c.cur_pic.qscale_table;
336 ac_val = &
h->c.ac_val[0][0] +
h->c.block_index[n] * 16;
340 const int xy =
h->c.mb_x - 1 +
h->c.mb_y *
h->c.mb_stride;
344 if (
h->c.mb_x == 0 ||
h->c.qscale == qscale_table[xy] ||
347 for (
i = 1;
i < 8;
i++)
348 block[
h->c.idsp.idct_permutation[
i << 3]] += ac_val[
i];
351 for (
i = 1;
i < 8;
i++)
352 block[
h->c.idsp.idct_permutation[
i << 3]] +=
ROUNDED_DIV(ac_val[
i] * qscale_table[xy],
h->c.qscale);
355 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride -
h->c.mb_stride;
357 ac_val -= 16 *
h->c.block_wrap[n];
359 if (
h->c.mb_y == 0 ||
h->c.qscale == qscale_table[xy] ||
362 for (
i = 1;
i < 8;
i++)
363 block[
h->c.idsp.idct_permutation[
i]] += ac_val[
i + 8];
366 for (
i = 1;
i < 8;
i++)
367 block[
h->c.idsp.idct_permutation[
i]] +=
ROUNDED_DIV(ac_val[
i + 8] * qscale_table[xy],
h->c.qscale);
372 for (
i = 1;
i < 8;
i++)
373 ac_val1[
i] =
block[
h->c.idsp.idct_permutation[
i << 3]];
376 for (
i = 1;
i < 8;
i++)
377 ac_val1[8 +
i] =
block[
h->c.idsp.idct_permutation[
i]];
395 (v >> (8 -
h->c.pict_type) != 1) ||
h->partitioned_frame)
398 bits_count += 8 +
h->c.pict_type;
402 if (bits_count + 8 >=
h->gb.size_in_bits) {
404 v |= 0x7F >> (7 - (bits_count & 7));
409 static const uint16_t mpeg4_resync_prefix[8] = {
410 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
413 if (v == mpeg4_resync_prefix[bits_count & 7]) {
415 int mb_num_bits =
av_log2(
h->c.mb_num - 1) + 1;
426 if (!mb_num || mb_num >
h->c.mb_num ||
get_bits_count(&
h->gb) + 6 >
h->gb.size_in_bits)
441 int a = 2 <<
ctx->sprite_warping_accuracy;
442 int rho = 3 -
ctx->sprite_warping_accuracy;
448 int min_ab,
i, w2, h2, w3, h3;
449 int sprite_ref[4][2];
450 int virtual_ref[2][2];
455 const int vop_ref[4][2] = { { 0, 0 }, {
s->width, 0 },
456 { 0,
s->height }, {
s->width,
s->height } };
457 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
459 if (
w <= 0 ||
h <= 0)
462 for (
i = 0;
i <
ctx->num_sprite_warping_points;
i++) {
470 if (!(
ctx->divx_version == 500 &&
ctx->divx_build == 413))
478 ctx->sprite_traj[
i][0] = d[
i][0] = x;
479 ctx->sprite_traj[
i][1] = d[
i][1] = y;
482 ctx->sprite_traj[
i][0] =
ctx->sprite_traj[
i][1] = 0;
486 while ((1 << beta) <
h)
492 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413) {
493 sprite_ref[0][0] =
a * vop_ref[0][0] + d[0][0];
494 sprite_ref[0][1] =
a * vop_ref[0][1] + d[0][1];
495 sprite_ref[1][0] =
a * vop_ref[1][0] + d[0][0] + d[1][0];
496 sprite_ref[1][1] =
a * vop_ref[1][1] + d[0][1] + d[1][1];
497 sprite_ref[2][0] =
a * vop_ref[2][0] + d[0][0] + d[2][0];
498 sprite_ref[2][1] =
a * vop_ref[2][1] + d[0][1] + d[2][1];
500 sprite_ref[0][0] = (
a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
501 sprite_ref[0][1] = (
a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
502 sprite_ref[1][0] = (
a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
503 sprite_ref[1][1] = (
a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
504 sprite_ref[2][0] = (
a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
505 sprite_ref[2][1] = (
a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
515 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
517 (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
518 w2 * (
r * sprite_ref[1][0] - 16LL * vop_ref[1][0])),
w);
519 virtual_ref[0][1] = 16 * vop_ref[0][1] +
521 (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
522 w2 * (
r * sprite_ref[1][1] - 16LL * vop_ref[1][1])),
w);
523 virtual_ref[1][0] = 16 * vop_ref[0][0] +
524 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
525 h2 * (
r * sprite_ref[2][0] - 16LL * vop_ref[2][0])),
h);
526 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
527 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
528 h2 * (
r * sprite_ref[2][1] - 16LL * vop_ref[2][1])),
h);
530 switch (
ctx->num_sprite_warping_points) {
532 sprite_offset[0][0] =
533 sprite_offset[0][1] =
534 sprite_offset[1][0] =
535 sprite_offset[1][1] = 0;
536 sprite_delta[0][0] =
a;
538 sprite_delta[1][0] = 0;
539 sprite_delta[1][1] =
a;
540 ctx->sprite_shift[0] =
541 ctx->sprite_shift[1] = 0;
544 sprite_offset[0][0] = sprite_ref[0][0] -
a * vop_ref[0][0];
545 sprite_offset[0][1] = sprite_ref[0][1] -
a * vop_ref[0][1];
546 sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
547 a * (vop_ref[0][0] / 2);
548 sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
549 a * (vop_ref[0][1] / 2);
550 sprite_delta[0][0] =
a;
552 sprite_delta[1][0] = 0;
553 sprite_delta[1][1] =
a;
554 ctx->sprite_shift[0] =
555 ctx->sprite_shift[1] = 0;
558 sprite_offset[0][0] = ((
int64_t) sprite_ref[0][0] * (1 <<
alpha + rho)) +
559 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
561 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
563 sprite_offset[0][1] = ((
int64_t) sprite_ref[0][1] * (1 <<
alpha + rho)) +
564 ((
int64_t) -
r * sprite_ref[0][1] + virtual_ref[0][1]) *
566 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
568 sprite_offset[1][0] = (((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
569 ((
int64_t)-2 * vop_ref[0][0] + 1) +
570 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
571 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
572 (
int64_t) sprite_ref[0][0] - 16 * w2 + (1 << (
alpha + rho + 1)));
573 sprite_offset[1][1] = (((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) *
574 ((
int64_t)-2 * vop_ref[0][0] + 1) +
575 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
576 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
577 (
int64_t) sprite_ref[0][1] - 16 * w2 + (1 << (
alpha + rho + 1)));
578 sprite_delta[0][0] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
579 sprite_delta[0][1] = (+
r * sprite_ref[0][1] - virtual_ref[0][1]);
580 sprite_delta[1][0] = (-
r * sprite_ref[0][1] + virtual_ref[0][1]);
581 sprite_delta[1][1] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
584 ctx->sprite_shift[1] =
alpha + rho + 2;
590 sprite_offset[0][0] = ((
int64_t)sprite_ref[0][0] * (1 << (
alpha + beta + rho - min_ab))) +
591 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
592 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
594 sprite_offset[0][1] = ((
int64_t)sprite_ref[0][1] * (1 << (
alpha + beta + rho - min_ab))) +
595 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
596 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
598 sprite_offset[1][0] = ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
599 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
600 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][0] - 16 * w2 * h3 +
602 sprite_offset[1][1] = ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
603 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
604 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][1] - 16 * w2 * h3 +
606 sprite_delta[0][0] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
607 sprite_delta[0][1] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
608 sprite_delta[1][0] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
609 sprite_delta[1][1] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
611 ctx->sprite_shift[0] =
alpha + beta + rho - min_ab;
612 ctx->sprite_shift[1] =
alpha + beta + rho - min_ab + 2;
615 av_unreachable(
"num_sprite_warping_points outside of 0..3 results in an error"
616 "in which num_sprite_warping_points is reset to zero");
619 if (sprite_delta[0][0] ==
a <<
ctx->sprite_shift[0] &&
620 sprite_delta[0][1] == 0 &&
621 sprite_delta[1][0] == 0 &&
622 sprite_delta[1][1] ==
a <<
ctx->sprite_shift[0]) {
623 sprite_offset[0][0] >>=
ctx->sprite_shift[0];
624 sprite_offset[0][1] >>=
ctx->sprite_shift[0];
625 sprite_offset[1][0] >>=
ctx->sprite_shift[1];
626 sprite_offset[1][1] >>=
ctx->sprite_shift[1];
627 sprite_delta[0][0] =
a;
628 sprite_delta[0][1] = 0;
629 sprite_delta[1][0] = 0;
630 sprite_delta[1][1] =
a;
631 ctx->sprite_shift[0] = 0;
632 ctx->sprite_shift[1] = 0;
633 ctx->real_sprite_warping_points = 1;
635 int shift_y = 16 -
ctx->sprite_shift[0];
636 int shift_c = 16 -
ctx->sprite_shift[1];
638 for (
i = 0;
i < 2;
i++) {
639 if (shift_c < 0 || shift_y < 0 ||
640 FFABS( sprite_offset[0][
i]) >= INT_MAX >> shift_y ||
641 FFABS( sprite_offset[1][
i]) >= INT_MAX >> shift_c ||
642 FFABS( sprite_delta[0][
i]) >= INT_MAX >> shift_y ||
643 FFABS( sprite_delta[1][
i]) >= INT_MAX >> shift_y
650 for (
i = 0;
i < 2;
i++) {
651 sprite_offset[0][
i] *= 1 << shift_y;
652 sprite_offset[1][
i] *= 1 << shift_c;
653 sprite_delta[0][
i] *= 1 << shift_y;
654 sprite_delta[1][
i] *= 1 << shift_y;
655 ctx->sprite_shift[
i] = 16;
658 for (
i = 0;
i < 2;
i++) {
660 sprite_delta[
i][0] -
a * (1LL<<16),
661 sprite_delta[
i][1] -
a * (1LL<<16)
664 if (llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
665 llabs(sprite_offset[0][
i] + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
666 llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL) + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
667 llabs(sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
668 llabs(sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
669 llabs(sd[0]) >= INT_MAX ||
670 llabs(sd[1]) >= INT_MAX ||
671 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL)) >= INT_MAX ||
672 llabs(sprite_offset[0][
i] + sd[1] * (
h+16LL)) >= INT_MAX ||
673 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL) + sd[1] * (
h+16LL)) >= INT_MAX
679 ctx->real_sprite_warping_points =
ctx->num_sprite_warping_points;
682 for (
i = 0;
i < 4;
i++) {
683 ctx->sprite_offset[
i&1][
i>>1] = sprite_offset[
i&1][
i>>1];
684 ctx->sprite_delta [
i&1][
i>>1] = sprite_delta [
i&1][
i>>1];
689 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
690 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
713 int mb_num_bits =
av_log2(
h->c.mb_num - 1) + 1;
714 int header_extension = 0, mb_num,
len;
735 if (mb_num >=
h->c.mb_num || !mb_num) {
737 "illegal mb_num in video packet (%d %d) \n", mb_num,
h->c.mb_num);
741 h->c.mb_x = mb_num %
h->c.mb_width;
742 h->c.mb_y = mb_num /
h->c.mb_width;
747 h->c.chroma_qscale =
h->c.qscale = qscale;
753 if (header_extension) {
757 check_marker(
h->c.avctx, &
h->gb,
"before time_increment in video packed header");
759 check_marker(
h->c.avctx, &
h->gb,
"before vop_coding_type in video packed header");
780 "Error, video packet header damaged (f_code=0)\n");
786 "Error, video packet header damaged (b_code=0)\n");
802 h->last_dc[2] = 1 << (
h->c.avctx->bits_per_raw_sample +
ctx->dct_precision +
h->c.intra_dc_precision - 1);
817 vlc_len =
av_log2(
h->c.mb_width *
h->c.mb_height) + 1;
820 if (mb_num >=
h->c.mb_num)
823 h->c.mb_x = mb_num %
h->c.mb_width;
824 h->c.mb_y = mb_num /
h->c.mb_width;
853 MPVContext *
const s = &
ctx->h.c;
854 int x, y, mb_v, sum, dx, dy,
shift;
855 int len = 1 << (
ctx->f_code + 4);
856 const int a =
ctx->sprite_warping_accuracy;
859 len >>=
s->quarter_sample;
861 if (
ctx->real_sprite_warping_points == 1) {
862 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413 &&
a >=
s->quarter_sample)
863 sum =
ctx->sprite_offset[0][n] / (1 << (
a -
s->quarter_sample));
865 sum =
RSHIFT(
ctx->sprite_offset[0][n] * (1 <<
s->quarter_sample),
a);
867 dx =
ctx->sprite_delta[n][0];
868 dy =
ctx->sprite_delta[n][1];
871 dy -= 1 << (
shift +
a + 1);
873 dx -= 1 << (
shift +
a + 1);
874 mb_v =
ctx->sprite_offset[0][n] + dx *
s->mb_x * 16U + dy *
s->mb_y * 16U;
877 for (y = 0; y < 16; y++) {
880 v = mb_v + (unsigned)dy * y;
882 for (x = 0; x < 16; x++) {
887 sum =
RSHIFT(sum,
a + 8 -
s->quarter_sample);
905 const int16_t *
const dc_val =
s->dc_val +
s->block_index[n];
906 const int wrap =
s->block_wrap[n];
915 int b = dc_val[-1 -
wrap];
916 int c = dc_val[-
wrap];
920 if (
s->first_slice_line && n != 3) {
923 if (n != 1 &&
s->mb_x ==
s->resync_mb_x)
926 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1) {
927 if (n == 0 || n == 4 || n == 5)
943 int scale = n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
955 if (
level & (~2047)) {
959 "dc<0 at %dx%d\n",
s->mb_x,
s->mb_y);
964 "dc overflow at %dx%d\n",
s->mb_x,
s->mb_y);
973 s->dc_val[
s->block_index[n]] =
level;
1036 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1039 h->c.first_slice_line = 1;
1040 for (;
h->c.mb_y <
h->c.mb_height;
h->c.mb_y++) {
1042 for (;
h->c.mb_x <
h->c.mb_width;
h->c.mb_x++) {
1043 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1049 if (
h->c.mb_x ==
h->c.resync_mb_x &&
h->c.mb_y ==
h->c.resync_mb_y + 1)
1050 h->c.first_slice_line = 0;
1062 "mcbpc corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1065 }
while (cbpc == 8);
1067 h->c.cbp_table[xy] = cbpc & 3;
1074 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1076 h->c.mbintra_table[xy] = 1;
1077 for (
i = 0;
i < 6;
i++) {
1082 "DC corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1089 h->c.pred_dir_table[xy] = dir;
1092 int16_t *
const mot_val =
h->c.cur_pic.motion_val[0][
h->c.block_index[0]];
1093 const int stride =
h->c.b8_stride * 2;
1101 if (
bits & 0x10000) {
1133 "mcbpc corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1139 h->c.cbp_table[xy] = cbpc & (8 + 3);
1141 h->c.mb_intra = ((cbpc & 4) != 0);
1143 if (
h->c.mb_intra) {
1145 h->c.mbintra_table[xy] = 1;
1164 if ((cbpc & 16) == 0) {
1198 for (
i = 0;
i < 4;
i++) {
1227 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1229 h->c.mb_x =
h->c.resync_mb_x;
1230 h->c.first_slice_line = 1;
1231 for (
h->c.mb_y =
h->c.resync_mb_y; mb_num < mb_count; h->
c.mb_y++) {
1233 for (; mb_num < mb_count &&
h->c.mb_x <
h->c.mb_width;
h->c.mb_x++) {
1234 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1238 if (
h->c.mb_x ==
h->c.resync_mb_x &&
h->c.mb_y ==
h->c.resync_mb_y + 1)
1239 h->c.first_slice_line = 0;
1246 "cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1250 h->c.cbp_table[xy] |= cbpy << 2;
1253 if (
IS_INTRA(
h->c.cur_pic.mb_type[xy])) {
1261 "I cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1265 if (
h->c.cbp_table[xy] & 8)
1267 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1269 for (
i = 0;
i < 6;
i++) {
1274 "DC corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1281 h->c.cbp_table[xy] &= 3;
1282 h->c.cbp_table[xy] |= cbpy << 2;
1284 h->c.pred_dir_table[xy] = dir;
1285 }
else if (
IS_SKIP(
h->c.cur_pic.mb_type[xy])) {
1286 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1287 h->c.cbp_table[xy] = 0;
1293 "P cbpy corrupted at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1297 if (
h->c.cbp_table[xy] & 8)
1299 h->c.cur_pic.qscale_table[xy] =
h->c.qscale;
1301 h->c.cbp_table[xy] &= 3;
1302 h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1306 if (mb_num >= mb_count)
1328 h->c.mb_x,
h->c.mb_y, part_a_error);
1332 if (
h->c.resync_mb_x +
h->c.resync_mb_y *
h->c.mb_width + mb_num >
h->c.mb_num) {
1335 h->c.mb_x,
h->c.mb_y, part_a_error);
1339 h->mb_num_left = mb_num;
1346 "marker missing after first I partition at %d %d\n",
1347 h->c.mb_x,
h->c.mb_y);
1355 "marker missing after first P partition at %d %d\n",
1356 h->c.mb_x,
h->c.mb_y);
1361 h->c.mb_x - 1,
h->c.mb_y, part_a_end);
1383 int n,
int coded,
int intra,
1384 int use_intra_dc_vlc,
int rvlc)
1391 const uint8_t *scan_table;
1397 if (use_intra_dc_vlc) {
1399 if (
h->partitioned_frame) {
1400 level =
h->c.dc_val[
h->c.block_index[n]];
1405 dc_pred_dir = (
h->c.pred_dir_table[
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride] << n) & 32;
1428 if (dc_pred_dir == 0)
1429 scan_table =
h->permutated_intra_v_scantable;
1431 scan_table =
h->permutated_intra_h_scantable;
1433 scan_table =
h->c.intra_scantable.permutated;
1440 h->c.block_last_index[n] =
i;
1448 scan_table =
h->c.intra_scantable.permutated;
1450 if (
ctx->mpeg_quant) {
1458 qmul =
h->c.qscale << 1;
1459 qadd = (
h->c.qscale - 1) | 1;
1476 "1. marker bit missing in rvlc esc\n");
1489 "2. marker bit missing in rvlc esc\n");
1515 cache ^= 0xC0000000;
1517 if (cache & 0x80000000) {
1518 if (cache & 0x40000000) {
1533 "1. marker bit missing in 3. esc\n");
1544 "2. marker bit missing in 3. esc\n");
1553 if (
h->c.error_recognition >= FF_ER_COMPLIANT) {
1556 const int run1=
run - rl->
max_run[last][abs_level] - 1;
1557 if (abs_level <= rl->max_level[last][
run]) {
1561 if (
h->c.error_recognition > FF_ER_COMPLIANT) {
1562 if (abs_level <= rl->max_level[last][
run]*2) {
1566 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1579 if ((
unsigned)(
level + 2048) > 4095) {
1583 "|level| overflow in 3. esc, qp=%d\n",
1617 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);
1622 "ac-tex damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1637 if (!use_intra_dc_vlc) {
1647 h->c.block_last_index[n] =
i;
1658 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1660 const int mb_type =
h->c.cur_pic.mb_type[xy];
1661 int cbp =
h->c.cbp_table[xy];
1663 const int use_intra_dc_vlc =
h->c.qscale <
ctx->intra_dc_threshold;
1665 if (
h->c.cur_pic.qscale_table[xy] !=
h->c.qscale)
1671 for (
i = 0;
i < 4;
i++) {
1672 h->c.mv[0][
i][0] =
h->c.cur_pic.motion_val[0][
h->c.block_index[
i]][0];
1673 h->c.mv[0][
i][1] =
h->c.cur_pic.motion_val[0][
h->c.block_index[
i]][1];
1679 for (
i = 0;
i < 6;
i++)
1680 h->c.block_last_index[
i] = -1;
1686 h->c.mb_skipped = 0;
1687 h->c.cur_pic.mbskip_table[xy] = 0;
1690 h->c.mb_skipped = 1;
1691 h->c.cur_pic.mbskip_table[xy] = 1;
1693 }
else if (
h->c.mb_intra) {
1694 h->c.ac_pred =
IS_ACPRED(
h->c.cur_pic.mb_type[xy]);
1695 }
else if (!
h->c.mb_intra) {
1707 h->c.ac_pred =
IS_ACPRED(
h->c.cur_pic.mb_type[xy]);
1712 h->c.bdsp.clear_blocks(
h->block[0]);
1714 for (
i = 0;
i < 6;
i++) {
1716 use_intra_dc_vlc,
ctx->rvlc) < 0) {
1718 "texture corrupted at %d %d %d\n",
1719 h->c.mb_x,
h->c.mb_y,
h->c.mb_intra);
1727 if (--
h->mb_num_left <= 0) {
1734 const int delta =
h->c.mb_x + 1 ==
h->c.mb_width ? 2 : 1;
1735 if (
h->c.cbp_table[xy +
delta])
1745 int cbpc, cbpy,
i, cbp, pred_x, pred_y,
mx,
my, dquant;
1746 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1747 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
1758 for (
i = 0;
i < 6;
i++)
1759 h->c.block_last_index[
i] = -1;
1771 h->c.cur_pic.mbskip_table[xy] = 0;
1772 h->c.mb_skipped = 0;
1777 h->c.mv[0][0][0] = 0;
1778 h->c.mv[0][0][1] = 0;
1779 h->c.cur_pic.mbskip_table[xy] = 1;
1780 h->c.mb_skipped = 1;
1787 "mcbpc damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1790 }
while (cbpc == 20);
1793 h->c.mb_intra = ((cbpc & 4) != 0);
1796 h->c.bdsp.clear_blocks(
h->block[0]);
1806 "P cbpy damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
1810 cbp = (cbpc & 3) | (cbpy << 2);
1813 if ((!
h->c.progressive_sequence) &&
1818 if ((cbpc & 16) == 0) {
1826 h->c.mv[0][0][0] =
mx;
1827 h->c.mv[0][0][1] =
my;
1828 }
else if ((!
h->c.progressive_sequence) &&
get_bits1(&
h->gb)) {
1839 for (
i = 0;
i < 2;
i++) {
1848 h->c.mv[0][
i][0] =
mx;
1849 h->c.mv[0][
i][1] =
my;
1865 h->c.mv[0][0][0] =
mx;
1866 h->c.mv[0][0][1] =
my;
1871 for (
i = 0;
i < 4;
i++) {
1880 h->c.mv[0][
i][0] =
mx;
1881 h->c.mv[0][
i][1] =
my;
1894 if (
h->c.mb_x == 0) {
1895 for (
i = 0;
i < 2;
i++) {
1896 h->c.last_mv[
i][0][0] =
1897 h->c.last_mv[
i][0][1] =
1898 h->c.last_mv[
i][1][0] =
1899 h->c.last_mv[
i][1][1] = 0;
1906 h->c.mb_skipped =
h->c.next_pic.mbskip_table[
h->c.mb_y *
h->c.mb_stride +
h->c.mb_x];
1908 if (
h->c.mb_skipped) {
1910 for (
i = 0;
i < 6;
i++)
1911 h->c.block_last_index[
i] = -1;
1918 h->c.mv[1][0][1] = 0;
1940 h->c.bdsp.clear_blocks(
h->block[0]);
1949 if (!
h->c.progressive_sequence) {
1977 h->c.last_mv[0][1][0] =
1978 h->c.last_mv[0][0][0] =
1979 h->c.mv[0][0][0] =
mx;
1980 h->c.last_mv[0][1][1] =
1981 h->c.last_mv[0][0][1] =
1982 h->c.mv[0][0][1] =
my;
1990 h->c.last_mv[1][1][0] =
1991 h->c.last_mv[1][0][0] =
1992 h->c.mv[1][0][0] =
mx;
1993 h->c.last_mv[1][1][1] =
1994 h->c.last_mv[1][0][1] =
1995 h->c.mv[1][0][1] =
my;
2003 for (
i = 0;
i < 2;
i++) {
2006 h->c.last_mv[0][
i][0] =
2007 h->c.mv[0][
i][0] =
mx;
2008 h->c.last_mv[0][
i][1] = (
h->c.mv[0][
i][1] =
my) * 2;
2015 for (
i = 0;
i < 2;
i++) {
2018 h->c.last_mv[1][
i][0] =
2019 h->c.mv[1][
i][0] =
mx;
2020 h->c.last_mv[1][
i][1] = (
h->c.mv[1][
i][1] =
my) * 2;
2038 h->c.cur_pic.mb_type[xy] = mb_type;
2040 int use_intra_dc_vlc;
2046 "I cbpc damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
2049 }
while (cbpc == 8);
2064 "I cbpy damaged at %d %d\n",
h->c.mb_x,
h->c.mb_y);
2067 cbp = (cbpc & 3) | (cbpy << 2);
2069 use_intra_dc_vlc =
h->c.qscale <
ctx->intra_dc_threshold;
2074 if (!
h->c.progressive_sequence)
2077 h->c.bdsp.clear_blocks(
h->block[0]);
2079 for (
i = 0;
i < 6;
i++) {
2081 1, use_intra_dc_vlc, 0) < 0)
2089 for (
i = 0;
i < 6;
i++) {
2099 if (
h->c.mb_x +
h->c.mb_y*
h->c.mb_width + 1 > next && (
h->c.avctx->err_recognition &
AV_EF_AGGRESSIVE)) {
2101 }
else if (
h->c.mb_x +
h->c.mb_y*
h->c.mb_width + 1 >= next)
2105 const int delta =
h->c.mb_x + 1 ==
h->c.mb_width ? 2 : 1;
2107 (
h->c.mb_x +
delta >=
h->c.mb_width)
2108 ?
FFMIN(
h->c.mb_y + 1,
h->c.mb_height - 1)
2110 if (
h->c.next_pic.mbskip_table[xy +
delta])
2161 int cc, dct_dc_size, dct_diff,
code, j, idx = 1, group = 0,
run = 0,
2162 additional_code_len, sign, mismatch;
2164 const uint8_t *
const scantable =
h->c.intra_scantable.permutated;
2165 const uint16_t *quant_matrix;
2167 const int min = -1 * (1 << (
h->c.avctx->bits_per_raw_sample + 6));
2168 const int max = ((1 << (
h->c.avctx->bits_per_raw_sample + 6)) - 1);
2169 int shift = 3 -
ctx->dct_precision;
2178 quant_matrix =
h->c.intra_matrix;
2185 quant_matrix =
h->c.chroma_intra_matrix;
2188 if (dct_dc_size == 0) {
2193 if (dct_dc_size > 8) {
2200 h->last_dc[cc] += dct_diff;
2202 if (
ctx->mpeg_quant)
2203 block[0] =
h->last_dc[cc] * (8 >>
h->c.intra_dc_precision);
2205 block[0] =
h->last_dc[cc] * (8 >>
h->c.intra_dc_precision) * (8 >>
ctx->dct_precision);
2209 mismatch ^=
block[0];
2226 }
else if (group >= 1 && group <= 6) {
2228 run = 1 << additional_code_len;
2229 if (additional_code_len)
2233 }
else if (group >= 7 && group <= 12) {
2238 run = (1 << (additional_code_len - 1)) +
code;
2242 j = scantable[idx++];
2243 block[j] = sign ? 1 : -1;
2244 }
else if (group >= 13 && group <= 20) {
2248 j = scantable[idx++];
2250 }
else if (group == 21) {
2254 j = scantable[idx++];
2255 additional_code_len =
h->c.avctx->bits_per_raw_sample +
ctx->dct_precision + 4;
2256 flc =
get_bits(&
h->gb, additional_code_len);
2257 if (flc >> (additional_code_len-1))
2258 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
2262 block[j] = ((
block[j] * quant_matrix[j] *
h->c.qscale) * (1 <<
shift)) / 16;
2264 mismatch ^=
block[j];
2267 block[63] ^= mismatch & 1;
2273 int16_t macroblock[256],
int n)
2277 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
2278 dpcm_residual,
left, top, topleft, min_left_top, max_left_top, p, p2, output;
2279 height = 16 >> (n ?
h->c.chroma_y_shift : 0);
2280 w = 16 >> (n ?
h->c.chroma_x_shift : 0);
2282 block_mean =
get_bits(&
h->gb,
h->c.avctx->bits_per_raw_sample);
2283 if (block_mean == 0){
2287 h->last_dc[n] = block_mean * (1 << (
ctx->dct_precision +
h->c.intra_dc_precision));
2290 if (rice_parameter == 0) {
2295 if (rice_parameter == 15)
2298 if (rice_parameter > 11) {
2304 output = 1 << (
h->c.avctx->bits_per_raw_sample - 1);
2305 top = 1 << (
h->c.avctx->bits_per_raw_sample - 1);
2307 for (j = 0; j <
w; j++) {
2314 if (rice_prefix_code == 11)
2315 dpcm_residual =
get_bits(&
h->gb,
h->c.avctx->bits_per_raw_sample);
2317 if (rice_prefix_code == 12) {
2321 rice_suffix_code =
get_bitsz(&
h->gb, rice_parameter);
2322 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2326 if (dpcm_residual & 1)
2327 dpcm_residual = (-1 * dpcm_residual) >> 1;
2329 dpcm_residual = (dpcm_residual >> 1);
2332 top = macroblock[idx-
w];
2334 p =
left + top - topleft;
2336 if (p < min_left_top)
2340 if (p > max_left_top)
2343 p2 = (
FFMIN(min_left_top, topleft) +
FFMAX(max_left_top, topleft)) >> 1;
2348 dpcm_residual *= -1;
2350 macroblock[idx++] = output = (dpcm_residual + p) & ((1 <<
h->c.avctx->bits_per_raw_sample) - 1);
2362 ctx->dpcm_direction = 0;
2383 for (
i = 0;
i < 3;
i++) {
2407 int hours, minutes, seconds;
2419 s->time_base = seconds + 60*(minutes + 60*hours);
2443 int visual_object_type;
2444 int is_visual_object_identifier =
get_bits1(gb);
2446 if (is_visual_object_identifier) {
2449 visual_object_type =
get_bits(gb, 4);
2454 if (video_signal_type) {
2455 int video_range, color_description;
2462 if (color_description) {
2463 s->avctx->color_primaries =
get_bits(gb, 8);
2491 for (
i = 0;
i < 64;
i++) {
2492 int j =
s->idsp.idct_permutation[
i];
2494 s->intra_matrix[j] = v;
2495 s->chroma_intra_matrix[j] = v;
2498 s->inter_matrix[j] = v;
2499 s->chroma_inter_matrix[j] = v;
2511 for (
i = 0;
i < 64;
i++) {
2514 s->intra_matrix[j] = v;
2515 s->chroma_intra_matrix[j] = v;
2523 for (
i = 0;
i < 64;
i++) {
2532 for (
i = 0;
i < 64;
i++) {
2535 s->chroma_intra_matrix[j] = v;
2543 for (
i = 0;
i < 64;
i++) {
2555 uint8_t extension_type;
2571 MPVContext *
const s = &
ctx->h.c;
2573 int bits_per_raw_sample;
2574 int rgb, chroma_format;
2594 bits_per_raw_sample =
get_bits(gb, 4);
2595 if (bits_per_raw_sample == 10) {
2605 if (
rgb !=
ctx->rgb ||
s->chroma_format != chroma_format)
2606 s->context_reinit = 1;
2607 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
2609 s->chroma_format = chroma_format;
2612 check_marker(
s->avctx, gb,
"before video_object_layer_width");
2614 check_marker(
s->avctx, gb,
"before video_object_layer_height");
2616 check_marker(
s->avctx, gb,
"after video_object_layer_height");
2620 if (
s->width &&
s->height &&
2622 s->context_reinit = 1;
2627 aspect_ratio_info =
get_bits(gb, 4);
2629 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2630 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2640 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2643 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2645 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2673 h->c.studio_profile = 1;
2676 }
else if (
h->c.studio_profile) {
2686 aspect_ratio_info =
get_bits(gb, 4);
2688 h->c.avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2689 h->c.avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2695 int chroma_format =
get_bits(gb, 2);
2706 check_marker(
h->c.avctx, gb,
"after first_half_vbv_buffer_size");
2709 check_marker(
h->c.avctx, gb,
"after first_half_vbv_occupancy");
2711 check_marker(
h->c.avctx, gb,
"after latter_half_vbv_occupancy");
2716 if (
h->picture_number == 0) {
2717 switch (
ctx->vo_type) {
2736 check_marker(
h->c.avctx, gb,
"before time_increment_resolution");
2738 h->c.avctx->framerate.num =
get_bits(gb, 16);
2739 if (!
h->c.avctx->framerate.num) {
2744 ctx->time_increment_bits =
av_log2(
h->c.avctx->framerate.num - 1) + 1;
2745 if (
ctx->time_increment_bits < 1)
2746 ctx->time_increment_bits = 1;
2751 h->c.avctx->framerate.den =
get_bits(gb,
ctx->time_increment_bits);
2753 h->c.avctx->framerate.den = 1;
2765 !(
h->c.width &&
h->c.codec_tag ==
AV_RL32(
"MP4S"))) {
2766 if (
h->c.width &&
h->c.height &&
2768 h->c.context_reinit = 1;
2774 h->c.progressive_sequence =
2776 h->c.interlaced_dct = 0;
2779 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
2800 if (
ctx->num_sprite_warping_points > 3) {
2802 "%d sprite_warping_points\n",
2803 ctx->num_sprite_warping_points);
2804 ctx->num_sprite_warping_points = 0;
2818 if (
ctx->quant_precision != 5)
2820 "quant precision %d\n",
ctx->quant_precision);
2821 if (
ctx->quant_precision < 3 ||
ctx->quant_precision > 9)
2822 ctx->quant_precision = 5;
2824 ctx->quant_precision = 5;
2837 for (
i = 0;
i < 64;
i++) {
2849 h->c.intra_matrix[j] = last;
2853 for (;
i < 64;
i++) {
2855 h->c.intra_matrix[j] = last;
2862 for (
i = 0;
i < 64;
i++) {
2874 h->c.inter_matrix[j] = v;
2878 for (;
i < 64;
i++) {
2880 h->c.inter_matrix[j] = last;
2890 h->c.quarter_sample = 0;
2899 int estimation_method =
get_bits(gb, 2);
2900 if (estimation_method < 2) {
2915 if (!
check_marker(
h->c.avctx, gb,
"in complexity estimation part 1")) {
2933 if (!
check_marker(
h->c.avctx, gb,
"in complexity estimation part 2")) {
2937 if (estimation_method == 1) {
2943 "Invalid Complexity estimation method %d\n",
2948 ctx->cplx_estimation_trash_i =
2949 ctx->cplx_estimation_trash_p =
2950 ctx->cplx_estimation_trash_b = 0;
2956 if (
h->data_partitioning)
2959 if (vo_ver_id != 1) {
2961 if (
ctx->new_pred) {
2968 "reduced resolution VOP not supported\n");
2975 if (
ctx->scalability) {
2977 int h_sampling_factor_n;
2978 int h_sampling_factor_m;
2979 int v_sampling_factor_n;
2980 int v_sampling_factor_m;
2985 h_sampling_factor_n =
get_bits(gb, 5);
2986 h_sampling_factor_m =
get_bits(gb, 5);
2987 v_sampling_factor_n =
get_bits(gb, 5);
2988 v_sampling_factor_m =
get_bits(gb, 5);
2991 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2992 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2995 ctx->scalability = 0;
3005 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",
3006 h->c.avctx->framerate.den,
h->c.avctx->framerate.num,
3007 ctx->time_increment_bits,
3008 ctx->quant_precision,
3009 h->c.progressive_sequence,
3011 ctx->scalability ?
"scalability " :
"" ,
3012 h->c.quarter_sample ?
"qpel " :
"",
3013 h->data_partitioning ?
"partition " :
"",
3014 ctx->rvlc ?
"rvlc " :
""
3031 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
3042 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
3044 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
3046 ctx->divx_version = ver;
3047 ctx->divx_build = build;
3048 h->divx_packed = e == 3 && last ==
'p';
3052 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
3054 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
3056 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
3058 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
3060 "Unknown Lavc version string encountered, %d.%d.%d; "
3061 "clamping sub-version values to 8-bits.\n",
3064 build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
3068 if (strcmp(buf,
"ffmpeg") == 0)
3069 ctx->lavc_build = 4600;
3072 ctx->lavc_build = build;
3075 e = sscanf(buf,
"XviD%d", &build);
3077 ctx->xvid_build = build;
3086 int time_incr, time_increment;
3098 if (
h->partitioned_frame)
3109 if (
ctx->time_increment_bits == 0 ||
3112 "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);
3114 for (
ctx->time_increment_bits = 1;
3115 ctx->time_increment_bits < 16;
3116 ctx->time_increment_bits++) {
3120 if ((
show_bits(gb,
ctx->time_increment_bits + 6) & 0x37) == 0x30)
3122 }
else if ((
show_bits(gb,
ctx->time_increment_bits + 5) & 0x1F) == 0x18)
3127 "time_increment_bits set to %d bits, based on bitstream analysis\n",
ctx->time_increment_bits);
3133 time_increment =
get_bits(gb,
ctx->time_increment_bits);
3136 h->c.last_time_base =
h->c.time_base;
3137 h->c.time_base += time_incr;
3138 h->c.time =
h->c.time_base * (
int64_t)
h->c.avctx->framerate.num + time_increment;
3140 if (
h->c.time <
h->c.last_non_b_time) {
3144 h->c.time +=
h->c.avctx->framerate.num;
3147 h->c.pp_time =
h->c.time -
h->c.last_non_b_time;
3148 h->c.last_non_b_time =
h->c.time;
3150 h->c.time = (
h->c.last_time_base + time_incr) * (
int64_t)
h->c.avctx->framerate.num + time_increment;
3151 h->c.pb_time =
h->c.pp_time - (
h->c.last_non_b_time -
h->c.time);
3152 if (
h->c.pp_time <=
h->c.pb_time ||
3153 h->c.pp_time <=
h->c.pp_time -
h->c.pb_time ||
3154 h->c.pp_time <= 0) {
3160 if (
ctx->t_frame == 0)
3161 ctx->t_frame =
h->c.pb_time;
3162 if (
ctx->t_frame == 0)
3168 if (
h->c.pp_field_time <=
h->c.pb_field_time ||
h->c.pb_field_time <= 1) {
3169 h->c.pb_field_time = 2;
3170 h->c.pp_field_time = 4;
3171 if (!
h->c.progressive_sequence)
3176 if (
h->c.avctx->framerate.den)
3180 ff_dlog(
h->c.avctx,
"MPEG4 PTS: %"PRId64
"\n",
pts);
3188 h->skipped_last_frame = 1;
3201 h->c.no_rounding = 0;
3235 if (!
h->c.progressive_sequence) {
3239 h->c.alternate_scan = 0;
3247 if (
h->c.alternate_scan) {
3250 h->c.idsp.idct_permutation);
3254 h->c.idsp.idct_permutation);
3257 h->c.idsp.idct_permutation);
3264 if (
ctx->sprite_brightness_change)
3266 "sprite_brightness_change not supported\n");
3270 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
3271 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
3278 h->c.chroma_qscale =
h->c.qscale =
get_bits(gb,
ctx->quant_precision);
3279 if (
h->c.qscale == 0) {
3281 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
3287 if (
ctx->f_code == 0) {
3289 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
3297 if (
ctx->b_code == 0) {
3299 "Error, header damaged or not MPEG4 header (b_code=0)\n");
3307 "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",
3308 h->c.qscale,
ctx->f_code,
ctx->b_code,
3311 h->c.top_field_first,
h->c.quarter_sample ?
'q' :
'h',
3312 h->data_partitioning,
ctx->resync_marker,
3313 ctx->num_sprite_warping_points,
ctx->sprite_warping_accuracy,
3314 1 -
h->c.no_rounding,
ctx->vo_type,
3315 ctx->vol_control_parameters ?
" VOLC" :
" ",
ctx->intra_dc_threshold,
3316 ctx->cplx_estimation_trash_i,
ctx->cplx_estimation_trash_p,
3317 ctx->cplx_estimation_trash_b,
3323 if (!
ctx->scalability) {
3327 if (
ctx->enhancement_type) {
3328 int load_backward_shape =
get_bits1(gb);
3329 if (load_backward_shape)
3331 "load backward shape isn't supported\n");
3337 h->c.dct_unquantize_intra =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_intra
3338 :
ctx->dct_unquantize_h263_intra;
3340 h->c.dct_unquantize_inter =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_inter :
NULL;
3346 if (
ctx->vo_type == 0 &&
ctx->vol_control_parameters == 0 &&
3347 ctx->divx_version == -1 &&
h->picture_number == 0) {
3349 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3353 h->picture_number++;
3356 h->c.h_edge_pos =
h->c.width;
3357 h->c.v_edge_pos =
h->c.height;
3388 h->partitioned_frame = 0;
3389 h->c.interlaced_dct = 0;
3412 h->c.intra_dc_precision =
get_bits(gb, 2);
3429 int visual_object_type;
3432 visual_object_type =
get_bits(gb, 4);
3455 int header,
int parse_only)
3457 MPVContext *
const s = &
ctx->h.c;
3458 unsigned startcode, v;
3468 if (!
s->studio_profile &&
s->avctx->bits_per_raw_sample != 8)
3469 s->avctx->bits_per_raw_sample = 0;
3481 (
ctx->divx_version >= 0 ||
ctx->xvid_build >= 0) ||
s->codec_tag ==
AV_RL32(
"QMP4")) {
3492 startcode = ((startcode << 8) | v) & 0xffffffff;
3494 if ((startcode & 0xFFFFFF00) != 0x100)
3499 if (startcode <= 0x11F)
3500 name =
"Video Object Start";
3501 else if (startcode <= 0x12F)
3502 name =
"Video Object Layer Start";
3503 else if (startcode <= 0x13F)
3505 else if (startcode <= 0x15F)
3506 name =
"FGS bp start";
3507 else if (startcode <= 0x1AF)
3509 else if (startcode == 0x1B0)
3510 name =
"Visual Object Seq Start";
3511 else if (startcode == 0x1B1)
3512 name =
"Visual Object Seq End";
3513 else if (startcode == 0x1B2)
3515 else if (startcode == 0x1B3)
3516 name =
"Group of VOP start";
3517 else if (startcode == 0x1B4)
3518 name =
"Video Session Error";
3519 else if (startcode == 0x1B5)
3520 name =
"Visual Object Start";
3521 else if (startcode == 0x1B6)
3522 name =
"Video Object Plane start";
3523 else if (startcode == 0x1B7)
3524 name =
"slice start";
3525 else if (startcode == 0x1B8)
3526 name =
"extension start";
3527 else if (startcode == 0x1B9)
3529 else if (startcode == 0x1BA)
3530 name =
"FBA Object start";
3531 else if (startcode == 0x1BB)
3532 name =
"FBA Object Plane start";
3533 else if (startcode == 0x1BC)
3534 name =
"Mesh Object start";
3535 else if (startcode == 0x1BD)
3536 name =
"Mesh Object Plane start";
3537 else if (startcode == 0x1BE)
3538 name =
"Still Texture Object start";
3539 else if (startcode == 0x1BF)
3540 name =
"Texture Spatial Layer start";
3541 else if (startcode == 0x1C0)
3542 name =
"Texture SNR Layer start";
3543 else if (startcode == 0x1C1)
3544 name =
"Texture Tile start";
3545 else if (startcode == 0x1C2)
3546 name =
"Texture Shape Layer start";
3547 else if (startcode == 0x1C3)
3548 name =
"stuffing start";
3549 else if (startcode <= 0x1C5)
3551 else if (startcode <= 0x1FF)
3552 name =
"System start";
3559 if (startcode >= 0x120 && startcode <= 0x12F) {
3576 s->studio_profile = 1;
3579 }
else if (
s->studio_profile) {
3586 if (
s->studio_profile) {
3603 if (
s->studio_profile) {
3604 if (!
s->avctx->bits_per_raw_sample) {
3613#if CONFIG_MPEG4_DECODER
3614static av_cold void permute_quant_matrix(uint16_t
matrix[64],
3615 const uint8_t new_perm[64],
3616 const uint8_t old_perm[64])
3621 for (
int i = 0;
i < 64; ++
i)
3628 uint8_t old_permutation[64];
3630 memcpy(old_permutation,
h->c.idsp.idct_permutation,
sizeof(old_permutation));
3636 h->c.idsp.idct_permutation);
3638 h->c.idsp.idct_permutation);
3641 permute_quant_matrix(
h->c.inter_matrix,
h->c.idsp.idct_permutation, old_permutation);
3642 permute_quant_matrix(
h->c.intra_matrix,
h->c.idsp.idct_permutation, old_permutation);
3650 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1) {
3651 if (
h->c.codec_tag ==
AV_RL32(
"XVID") ||
3652 h->c.codec_tag ==
AV_RL32(
"XVIX") ||
3653 h->c.codec_tag ==
AV_RL32(
"RMP4") ||
3654 h->c.codec_tag ==
AV_RL32(
"ZMP4") ||
3656 ctx->xvid_build = 0;
3659 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1)
3660 if (
h->c.codec_tag ==
AV_RL32(
"DIVX") &&
ctx->vo_type == 0 &&
3661 ctx->vol_control_parameters == 0)
3662 ctx->divx_version = 400;
3664 if (
ctx->xvid_build >= 0 &&
ctx->divx_version >= 0) {
3666 ctx->divx_build = -1;
3670 if (
h->c.codec_tag ==
AV_RL32(
"XVIX"))
3673 if (
h->c.codec_tag ==
AV_RL32(
"UMP4"))
3676 if (
ctx->divx_version >= 500 &&
ctx->divx_build < 1814)
3679 if (
ctx->divx_version > 502 &&
ctx->divx_build < 1814)
3682 if (
ctx->xvid_build <= 3U)
3683 h->padding_bug_score = 256 * 256 * 256 * 64;
3685 if (
ctx->xvid_build <= 1U)
3688 if (
ctx->xvid_build <= 12U)
3691 if (
ctx->xvid_build <= 32U)
3694#define SET_QPEL_FUNC(postfix1, postfix2) \
3695 h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3696 h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3697 h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
3699 if (
ctx->lavc_build < 4653U)
3702 if (
ctx->lavc_build < 4655U)
3705 if (
ctx->lavc_build < 4670U)
3708 if (
ctx->lavc_build <= 4712U)
3711 if ((
ctx->lavc_build&0xFF) >= 100) {
3712 if (
ctx->lavc_build > 3621476 &&
ctx->lavc_build < 3752552 &&
3713 (
ctx->lavc_build < 3752037 ||
ctx->lavc_build > 3752191)
3718 if (
ctx->divx_version >= 0)
3720 if (
ctx->divx_version == 501 &&
ctx->divx_build == 20020416)
3721 h->padding_bug_score = 256 * 256 * 256 * 64;
3723 if (
ctx->divx_version < 500U)
3726 if (
ctx->divx_version >= 0)
3748 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
3749 h->c.workaround_bugs,
ctx->lavc_build,
ctx->xvid_build,
3750 ctx->divx_version,
ctx->divx_build,
h->divx_packed ?
"p" :
"");
3752 if (
ctx->xvid_build >= 0 &&
3754 switch_to_xvid_idct(avctx,
h);
3762 h->skipped_last_frame = 0;
3764 if (
ctx->bitstream_buffer) {
3766 int bitstream_buffer_size =
ctx->bitstream_buffer->size;
3767 const uint8_t *buf =
h->gb.buffer;
3769 if (
h->divx_packed) {
3770 for (
int i = 0;
i < buf_size - 3;
i++) {
3771 if (buf[
i] == 0 && buf[
i+1] == 0 && buf[
i+2] == 1) {
3772 if (buf[
i+3] == 0xB0) {
3774 bitstream_buffer_size = 0;
3780 ctx->bitstream_buffer->size = 0;
3781 if (bitstream_buffer_size && (
h->divx_packed || buf_size <=
MAX_NVOP_SIZE)) {
3783 bitstream_buffer_size);
3802 if (
h->divx_packed) {
3803 int current_pos =
ctx->bitstream_buffer &&
h->gb.buffer ==
ctx->bitstream_buffer->data ? 0 : (
get_bits_count(&
h->gb) >> 3);
3804 int startcode_found = 0;
3805 uint8_t *buf =
pkt->data;
3806 int buf_size =
pkt->size;
3808 if (buf_size - current_pos > 7) {
3811 for (
i = current_pos;
i < buf_size - 4;
i++)
3816 buf[
i + 3] == 0xB6) {
3817 startcode_found = !(buf[
i + 4] & 0x40);
3822 if (startcode_found) {
3823 if (!
ctx->showed_packed_warning) {
3825 "wasteful way to store B-frames ('packed B-frames'). "
3826 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
3827 ctx->showed_packed_warning = 1;
3833 ctx->bitstream_buffer->data = buf + current_pos;
3834 ctx->bitstream_buffer->size = buf_size - current_pos;
3844 memset(&
s->buffer_pools, 0,
sizeof(
s->buffer_pools));
3845 memset(&
s->next_pic, 0,
sizeof(
s->next_pic));
3846 memset(&
s->last_pic, 0,
sizeof(
s->last_pic));
3847 memset(&
s->cur_pic, 0,
sizeof(
s->cur_pic));
3849 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
3851 s->ac_val_base =
NULL;
3853 memset(&
s->sc, 0,
sizeof(
s->sc));
3855 s->p_field_mv_table_base =
NULL;
3856 for (
int i = 0;
i < 2;
i++)
3857 for (
int j = 0; j < 2; j++)
3858 s->p_field_mv_table[
i][j] =
NULL;
3860 s->dc_val_base =
NULL;
3861 s->coded_block_base =
NULL;
3862 s->mbintra_table =
NULL;
3863 s->cbp_table =
NULL;
3864 s->pred_dir_table =
NULL;
3866 s->mbskip_table =
NULL;
3868 s->er.error_status_table =
NULL;
3869 s->er.er_temp_buffer =
NULL;
3870 s->mb_index2xy =
NULL;
3872 s->context_initialized = 0;
3873 s->context_reinit = 0;
3881 memcpy(
s, s1,
sizeof(*
s));
3899 int init =
s->h.c.context_initialized;
3903 ret = update_mpvctx(&
s->h.c, &s1->
h.
c);
3940 s->h.c.studio_profile = s1->
h.
c.studio_profile;
3959 h->c.quarter_sample = h1->
c.quarter_sample;
3966static av_cold void mpeg4_init_static(
void)
3981 for (
unsigned i = 0;
i < 12;
i++) {
4022 ctx->lavc_build = -1;
4041 h->decode_header = mpeg4_decode_picture_header;
4043 ctx->time_increment_bits = 4;
4044 ctx->quant_precision = 5;
4081#define OFFSET(x) offsetof(H263DecContext, x)
4082#define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
4089static const AVClass mpeg4_class = {
4090 .class_name =
"MPEG4 Video Decoder",
4104 .close = mpeg4_close,
4109 .flush = mpeg4_flush,
4114 .p.priv_class = &mpeg4_class,
4116#if CONFIG_MPEG4_NVDEC_HWACCEL
4119#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
4122#if CONFIG_MPEG4_VAAPI_HWACCEL
4125#if CONFIG_MPEG4_VDPAU_HWACCEL
4128#if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_mpeg4_decoder
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define FF_DEBUG_STARTCODE
#define FF_BUG_XVID_ILACE
#define FF_BUG_HPEL_CHROMA
#define FF_BUG_QPEL_CHROMA2
#define FF_BUG_DIRECT_BLOCKSIZE
#define FF_DEBUG_PICT_INFO
#define FF_BUG_AUTODETECT
autodetection
#define FF_BUG_NO_PADDING
#define FF_BUG_QPEL_CHROMA
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
#define UPDATE_THREAD_CONTEXT(func)
#define UPDATE_THREAD_CONTEXT_FOR_USER(func)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters if all frames are skipped due to the skip_frame setting...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define ROUNDED_DIV(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_MPEG4_SIMPLE_STUDIO
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define AV_EF_IGNORE_ERR
ignore errors and continue
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
int(* init)(AVBSFContext *ctx)
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
static const uint8_t bits[8]
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
#define GET_CACHE(name, gb)
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
#define SKIP_CACHE(name, gb, num)
#define CLOSE_READER(name, gb)
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define SHOW_UBITS(name, gb, num)
static unsigned int get_bits1(GetBitContext *s)
#define SHOW_SBITS(name, gb, num)
#define OPEN_READER(name, gb)
static void skip_bits(GetBitContext *s, int n)
#define SKIP_BITS(name, gb, num)
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
#define UPDATE_CACHE(name, gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define LAST_SKIP_BITS(name, gb, num)
static const uint8_t * align_get_bits(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define SKIP_COUNTER(name, gb, num)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#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.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
static void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
#define FF_ASPECT_EXTENDED
void ff_h263_init_rl_inter(void)
const AVRational ff_h263_pixel_aspect[16]
VLCElem ff_h263_inter_MCBPC_vlc[]
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
#define SLICE_NOEND
no end marker or error found but mb count exceeded
VLCElem ff_h263_cbpy_vlc[]
#define INTRA_MCBPC_VLC_BITS
#define FRAME_SKIPPED
Frame is not coded.
VLCElem ff_h263_intra_MCBPC_vlc[]
#define INTER_MCBPC_VLC_BITS
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
#define HWACCEL_NVDEC_CUARRAY(codec)
#define HWACCEL_VDPAU(codec)
#define HWACCEL_NVDEC(codec)
#define HWACCEL_VAAPI(codec)
#define HWACCEL_VIDEOTOOLBOX(codec)
static const int16_t alpha[]
static av_cold int decode_init(AVCodecContext *avctx)
static int shift(int a, int b)
#define SLICE_END
end marker found
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
common internal api header.
av_cold void ff_mpeg4videodsp_init(Mpeg4VideoDSPContext *c)
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int ff_thread_once(char *control, void(*routine)(void))
const uint8_t ff_zigzag_direct[64]
static const VLCElem * rl_vlc[2]
const uint8_t ff_sprite_trajectory_lens[15]
const uint8_t ff_mpeg4_DCtab_lum[13][2]
const uint8_t ff_mpeg4_studio_intra[12][24][2]
RLTable ff_mpeg4_rl_intra
const uint8_t ff_mb_type_b_tab[4][2]
const int16_t ff_mpeg4_default_intra_matrix[64]
const uint8_t ff_mpeg4_c_dc_scale_table[32]
const uint8_t ff_mpeg4_y_dc_scale_table[32]
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
const uint8_t ff_mpeg4_studio_dc_chroma[19][2]
const int16_t ff_mpeg4_default_non_intra_matrix[64]
const uint8_t ff_mpeg4_studio_dc_luma[19][2]
const uint8_t ff_mpeg4_dc_threshold[8]
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
int ff_mpeg4_get_video_packet_prefix_length(enum AVPictureType pict_type, int f_code, int b_code)
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb, int *profile, int *level)
static int mpeg4_decode_studio_mb(H263DecContext *const h)
static VLCElem sprite_trajectory[128]
static VLCElem dc_lum[512]
static VLCElem mb_type_b_vlc[16]
static int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
Decode the dc value.
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)
#define STUDIO_INTRA_BITS
static const int16_t mb_type_b_map[4]
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb)
static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
Decode first partition.
static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the next studio vop header.
static int mpeg4_decode_partitioned_mb(H263DecContext *const h)
decode partition C of one MB.
static const uint8_t ac_state_tab[22][2]
static Mpeg4DecContext * h263_to_mpeg4(H263DecContext *h)
int ff_mpeg4_decode_partitions(H263DecContext *const h)
Decode the first and second partition.
#define MB_TYPE_B_VLC_BITS
int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header, int parse_only)
Decode MPEG-4 headers.
static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb)
static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id)
int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
Decode the next video packet.
static int mpeg4_decode_mb(H263DecContext *const h)
static void next_start_code_studio(GetBitContext *gb)
static VLCElem studio_luma_dc[528]
static VLCElem studio_chroma_dc[528]
static int mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
Predict the dc.
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 uint8_t mpeg4_block_count[4]
#define SPRITE_TRAJ_VLC_BITS
static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, int16_t macroblock[256], int n)
static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, int parse_only)
void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
Predict the ac.
static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
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.
static void mpeg4_load_default_matrices(MpegEncContext *s)
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)
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
Decode the next video packet.
void ff_mpeg4_mcsel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
static const VLCElem * studio_intra_tab[12]
static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n)
static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
decode second partition.
static VLCElem dc_chrom[512]
static int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int level)
static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
static int mpeg4_is_resync(Mpeg4DecContext *ctx)
check if the next stuff is a resync marker or the end.
static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the user data stuff in the header.
static int get_amv(Mpeg4DecContext *ctx, int n)
Get the average motion vector for a GMC MB.
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
#define QUANT_MATRIX_EXT_ID
#define ADV_SIMPLE_VO_TYPE
#define VOT_STILL_TEXTURE_ID
#define USER_DATA_STARTCODE
#define SIMPLE_STUDIO_VO_TYPE
#define CORE_STUDIO_VO_TYPE
#define VISUAL_OBJ_STARTCODE
#define MB_TYPE_BACKWARD_MV
#define HAS_BACKWARD_MV(a)
#define HAS_FORWARD_MV(a)
#define MB_TYPE_INTERLACED
#define MB_TYPE_FORWARD_MV
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
#define MV_TYPE_FIELD
2 vectors, one per field
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
#define MV_TYPE_16X16
1 vector for the whole mb
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
update_thread_context for mpegvideo-based decoders.
#define ff_mpv_unquantize_init(s, bitexact, q_scale_type)
const uint8_t ff_alternate_horizontal_scan[64]
const uint8_t ff_alternate_vertical_scan[64]
mpegvideo decoder header.
static int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P10
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
const AVProfile ff_mpeg4_video_profiles[]
#define SET_QPEL_FUNC(OP, X, Y, SIZE, CPU, PREFIX)
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 VLC_INIT_RL(rl, static_size)
#define INIT_FIRST_VLC_RL(rl, static_size)
static const uint8_t header[24]
static const float pred[4]
Describe the class of an AVClass context structure.
main external API structure.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
struct AVCodecInternal * internal
Private context used for internal data.
int is_copy
When using frame-threaded decoding, this field is set for the first worker thread (e....
This structure stores compressed data.
int divx_packed
divx specific, used to workaround (many) bugs in divx5
int padding_bug_score
used to detect the VERY common padding bug in MPEG-4
int data_partitioning
data partitioning flag from header
void(* dct_unquantize_mpeg2_intra)(const MPVContext *s, int16_t *block, int n, int qscale)
void(* dct_unquantize_mpeg2_inter)(const MPVContext *s, int16_t *block, int n, int qscale)
void(* dct_unquantize_h263_intra)(const MPVContext *s, int16_t *block, int n, int qscale)
int sprite_brightness_change
int intra_dc_threshold
QP above which the ac VLC should be used for intra dc.
int time_increment_bits
number of bits to represent the fractional part of time
int num_sprite_warping_points
int showed_packed_warning
flag for having shown the warning about invalid Divx B-frames
int sprite_shift[2]
sprite shift [isChroma]
int cplx_estimation_trash_i
int sprite_warping_accuracy
int vol_control_parameters
does the stream contain the low_delay flag, used to work around buggy encoders.
uint16_t sprite_traj[4][2]
sprite trajectory points
int cplx_estimation_trash_p
int t_frame
time distance of first I -> B, used for interlaced B-frames
int cplx_estimation_trash_b
AVBufferRef * bitstream_buffer
Divx 5.01 puts several frames in a single one, this is used to reorder them.
int resync_marker
could this stream contain resync markers
int8_t * max_run[2]
encoding & decoding
int8_t * max_level[2]
encoding & decoding
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
static void clear_context(SwrContext *s)
#define avpriv_request_sample(...)
static struct @232240247175332074307271266321204261331170211232 state
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 int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static const AVOption mpeg4_options[]
av_cold const VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
#define VLC_INIT_STATE(_table)
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
#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)