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
85 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
86 uint8_t *
const *ref_picture)
89 int src_x, src_y, motion_x, motion_y;
90 ptrdiff_t
offset, linesize, uvlinesize;
93 motion_x =
ctx->sprite_offset[0][0];
94 motion_y =
ctx->sprite_offset[0][1];
95 src_x =
s->mb_x * 16 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
96 src_y =
s->mb_y * 16 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
97 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
98 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
99 src_x =
av_clip(src_x, -16,
s->width);
100 if (src_x ==
s->width)
102 src_y =
av_clip(src_y, -16,
s->height);
103 if (src_y ==
s->height)
106 linesize =
s->linesize;
107 uvlinesize =
s->uvlinesize;
109 ptr = ref_picture[0] + src_y * linesize + src_x;
111 if ((
unsigned)src_x >=
FFMAX(
s->h_edge_pos - 17, 0) ||
112 (
unsigned)src_y >=
FFMAX(
s->v_edge_pos - 17, 0)) {
113 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
117 s->h_edge_pos,
s->v_edge_pos);
118 ptr =
s->sc.edge_emu_buffer;
121 if ((motion_x | motion_y) & 7) {
122 ctx->mdsp.gmc1(dest_y, ptr, linesize, 16,
123 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
124 ctx->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
125 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
129 dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
130 if (
s->no_rounding) {
131 s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
133 s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
140 motion_x =
ctx->sprite_offset[1][0];
141 motion_y =
ctx->sprite_offset[1][1];
142 src_x =
s->mb_x * 8 + (motion_x >> (
ctx->sprite_warping_accuracy + 1));
143 src_y =
s->mb_y * 8 + (motion_y >> (
ctx->sprite_warping_accuracy + 1));
144 motion_x *= 1 << (3 -
ctx->sprite_warping_accuracy);
145 motion_y *= 1 << (3 -
ctx->sprite_warping_accuracy);
146 src_x =
av_clip(src_x, -8,
s->width >> 1);
147 if (src_x ==
s->width >> 1)
149 src_y =
av_clip(src_y, -8,
s->height >> 1);
150 if (src_y ==
s->height >> 1)
153 offset = (src_y * uvlinesize) + src_x;
154 ptr = ref_picture[1] +
offset;
155 if ((
unsigned)src_x >=
FFMAX((
s->h_edge_pos >> 1) - 9, 0) ||
156 (unsigned)src_y >=
FFMAX((
s->v_edge_pos >> 1) - 9, 0)) {
157 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
158 uvlinesize, uvlinesize,
161 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
162 ptr =
s->sc.edge_emu_buffer;
165 ctx->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
166 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
168 ptr = ref_picture[2] +
offset;
170 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
171 uvlinesize, uvlinesize,
174 s->h_edge_pos >> 1,
s->v_edge_pos >> 1);
175 ptr =
s->sc.edge_emu_buffer;
177 ctx->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
178 motion_x & 15, motion_y & 15, 128 -
s->no_rounding);
182 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
183 uint8_t *
const *ref_picture)
186 int linesize, uvlinesize;
187 const int a =
ctx->sprite_warping_accuracy;
190 linesize =
s->linesize;
191 uvlinesize =
s->uvlinesize;
193 ptr = ref_picture[0];
195 ox =
ctx->sprite_offset[0][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 16 +
196 ctx->sprite_delta[0][1] *
s->mb_y * 16;
197 oy =
ctx->sprite_offset[0][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 16 +
198 ctx->sprite_delta[1][1] *
s->mb_y * 16;
200 ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
202 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
203 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
204 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
205 s->h_edge_pos,
s->v_edge_pos);
206 ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
207 ox +
ctx->sprite_delta[0][0] * 8,
208 oy +
ctx->sprite_delta[1][0] * 8,
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);
217 ox =
ctx->sprite_offset[1][0] +
ctx->sprite_delta[0][0] *
s->mb_x * 8 +
218 ctx->sprite_delta[0][1] *
s->mb_y * 8;
219 oy =
ctx->sprite_offset[1][1] +
ctx->sprite_delta[1][0] *
s->mb_x * 8 +
220 ctx->sprite_delta[1][1] *
s->mb_y * 8;
222 ptr = ref_picture[1];
223 ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
225 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
226 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
227 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
228 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
230 ptr = ref_picture[2];
231 ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
233 ctx->sprite_delta[0][0],
ctx->sprite_delta[0][1],
234 ctx->sprite_delta[1][0],
ctx->sprite_delta[1][1],
235 a + 1, (1 << (2 *
a + 1)) -
s->no_rounding,
236 (
s->h_edge_pos + 1) >> 1, (
s->v_edge_pos + 1) >> 1);
240 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
241 uint8_t *
const *ref_picture)
245 if (
ctx->real_sprite_warping_points == 1) {
255 uint8_t *dest_cr,
int block_size,
int uvlinesize,
256 int dct_linesize,
int dct_offset)
259 const int act_block_size = block_size * 2;
261 if (
ctx->dpcm_direction == 0) {
262 s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)
ctx->block32[0]);
263 s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)
ctx->block32[1]);
264 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)
ctx->block32[2]);
265 s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)
ctx->block32[3]);
267 dct_linesize = uvlinesize <<
s->interlaced_dct;
268 dct_offset =
s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
270 s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)
ctx->block32[4]);
271 s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)
ctx->block32[5]);
272 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)
ctx->block32[6]);
273 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)
ctx->block32[7]);
274 if (!
s->chroma_x_shift){
275 s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)
ctx->block32[8]);
276 s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)
ctx->block32[9]);
277 s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[10]);
278 s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)
ctx->block32[11]);
280 }
else if (
ctx->dpcm_direction == 1) {
281 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
282 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
283 for (
int i = 0;
i < 3;
i++) {
284 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
285 int vsub =
i ?
s->chroma_y_shift : 0;
286 int hsub =
i ?
s->chroma_x_shift : 0;
289 for (
int h = 0;
h < (16 >> (vsub +
lowres));
h++){
291 dest_pcm[
i][
w] =
src[idx];
292 dest_pcm[
i] += linesize[
i] / 2;
297 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
298 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
300 for (
int i = 0;
i < 3;
i++) {
301 const uint16_t *
src =
ctx->dpcm_macroblock[
i];
302 int vsub =
i ?
s->chroma_y_shift : 0;
303 int hsub =
i ?
s->chroma_x_shift : 0;
306 dest_pcm[
i] += (linesize[
i] / 2) * ((16 >> vsub +
lowres) - 1);
307 for (
int h = (16 >> (vsub +
lowres)) - 1;
h >= 0;
h--){
309 dest_pcm[
i][
w] =
src[idx];
311 dest_pcm[
i] -= linesize[
i] / 2;
325 int16_t *ac_val, *ac_val1;
326 int8_t *
const qscale_table =
s->cur_pic.qscale_table;
329 ac_val = &
s->ac_val[0][0] +
s->block_index[n] * 16;
333 const int xy =
s->mb_x - 1 +
s->mb_y *
s->mb_stride;
337 if (
s->mb_x == 0 ||
s->qscale == qscale_table[xy] ||
340 for (
i = 1;
i < 8;
i++)
341 block[
s->idsp.idct_permutation[
i << 3]] += ac_val[
i];
344 for (
i = 1;
i < 8;
i++)
345 block[
s->idsp.idct_permutation[
i << 3]] +=
ROUNDED_DIV(ac_val[
i] * qscale_table[xy],
s->qscale);
348 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride -
s->mb_stride;
350 ac_val -= 16 *
s->block_wrap[n];
352 if (
s->mb_y == 0 ||
s->qscale == qscale_table[xy] ||
355 for (
i = 1;
i < 8;
i++)
356 block[
s->idsp.idct_permutation[
i]] += ac_val[
i + 8];
359 for (
i = 1;
i < 8;
i++)
365 for (
i = 1;
i < 8;
i++)
366 ac_val1[
i] =
block[
s->idsp.idct_permutation[
i << 3]];
370 ac_val1[8 +
i] =
block[
s->idsp.idct_permutation[
i]];
388 (v >> (8 -
s->pict_type) != 1) ||
s->partitioned_frame)
391 bits_count += 8 +
s->pict_type;
395 if (bits_count + 8 >=
s->gb.size_in_bits) {
397 v |= 0x7F >> (7 - (bits_count & 7));
402 static const uint16_t mpeg4_resync_prefix[8] = {
403 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
406 if (v == mpeg4_resync_prefix[bits_count & 7]) {
408 int mb_num_bits =
av_log2(
s->mb_num - 1) + 1;
419 if (!mb_num || mb_num >
s->mb_num ||
get_bits_count(&
s->gb)+6 >
s->gb.size_in_bits)
434 int a = 2 <<
ctx->sprite_warping_accuracy;
435 int rho = 3 -
ctx->sprite_warping_accuracy;
441 int min_ab,
i, w2, h2, w3, h3;
442 int sprite_ref[4][2];
443 int virtual_ref[2][2];
448 const int vop_ref[4][2] = { { 0, 0 }, {
s->width, 0 },
449 { 0,
s->height }, {
s->width,
s->height } };
450 int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
452 if (
w <= 0 ||
h <= 0)
455 for (
i = 0;
i <
ctx->num_sprite_warping_points;
i++) {
463 if (!(
ctx->divx_version == 500 &&
ctx->divx_build == 413))
471 ctx->sprite_traj[
i][0] = d[
i][0] = x;
472 ctx->sprite_traj[
i][1] = d[
i][1] = y;
475 ctx->sprite_traj[
i][0] =
ctx->sprite_traj[
i][1] = 0;
479 while ((1 << beta) <
h)
485 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413) {
486 sprite_ref[0][0] =
a * vop_ref[0][0] + d[0][0];
487 sprite_ref[0][1] =
a * vop_ref[0][1] + d[0][1];
488 sprite_ref[1][0] =
a * vop_ref[1][0] + d[0][0] + d[1][0];
489 sprite_ref[1][1] =
a * vop_ref[1][1] + d[0][1] + d[1][1];
490 sprite_ref[2][0] =
a * vop_ref[2][0] + d[0][0] + d[2][0];
491 sprite_ref[2][1] =
a * vop_ref[2][1] + d[0][1] + d[2][1];
493 sprite_ref[0][0] = (
a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
494 sprite_ref[0][1] = (
a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
495 sprite_ref[1][0] = (
a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
496 sprite_ref[1][1] = (
a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
497 sprite_ref[2][0] = (
a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
498 sprite_ref[2][1] = (
a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
508 virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
510 (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
511 w2 * (
r * sprite_ref[1][0] - 16LL * vop_ref[1][0])),
w);
512 virtual_ref[0][1] = 16 * vop_ref[0][1] +
514 (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
515 w2 * (
r * sprite_ref[1][1] - 16LL * vop_ref[1][1])),
w);
516 virtual_ref[1][0] = 16 * vop_ref[0][0] +
517 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
518 h2 * (
r * sprite_ref[2][0] - 16LL * vop_ref[2][0])),
h);
519 virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
520 ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
521 h2 * (
r * sprite_ref[2][1] - 16LL * vop_ref[2][1])),
h);
523 switch (
ctx->num_sprite_warping_points) {
525 sprite_offset[0][0] =
526 sprite_offset[0][1] =
527 sprite_offset[1][0] =
528 sprite_offset[1][1] = 0;
529 sprite_delta[0][0] =
a;
531 sprite_delta[1][0] = 0;
532 sprite_delta[1][1] =
a;
533 ctx->sprite_shift[0] =
534 ctx->sprite_shift[1] = 0;
537 sprite_offset[0][0] = sprite_ref[0][0] -
a * vop_ref[0][0];
538 sprite_offset[0][1] = sprite_ref[0][1] -
a * vop_ref[0][1];
539 sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
540 a * (vop_ref[0][0] / 2);
541 sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
542 a * (vop_ref[0][1] / 2);
543 sprite_delta[0][0] =
a;
545 sprite_delta[1][0] = 0;
546 sprite_delta[1][1] =
a;
547 ctx->sprite_shift[0] =
548 ctx->sprite_shift[1] = 0;
551 sprite_offset[0][0] = ((
int64_t) sprite_ref[0][0] * (1 <<
alpha + rho)) +
552 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
554 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
556 sprite_offset[0][1] = ((
int64_t) sprite_ref[0][1] * (1 <<
alpha + rho)) +
557 ((
int64_t) -
r * sprite_ref[0][1] + virtual_ref[0][1]) *
559 ((
int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
561 sprite_offset[1][0] = (((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
562 ((
int64_t)-2 * vop_ref[0][0] + 1) +
563 ((
int64_t)
r * sprite_ref[0][1] - virtual_ref[0][1]) *
564 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
565 (
int64_t) sprite_ref[0][0] - 16 * w2 + (1 << (
alpha + rho + 1)));
566 sprite_offset[1][1] = (((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) *
567 ((
int64_t)-2 * vop_ref[0][0] + 1) +
568 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
569 ((
int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 *
r *
570 (
int64_t) sprite_ref[0][1] - 16 * w2 + (1 << (
alpha + rho + 1)));
571 sprite_delta[0][0] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
572 sprite_delta[0][1] = (+
r * sprite_ref[0][1] - virtual_ref[0][1]);
573 sprite_delta[1][0] = (-
r * sprite_ref[0][1] + virtual_ref[0][1]);
574 sprite_delta[1][1] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
577 ctx->sprite_shift[1] =
alpha + rho + 2;
583 sprite_offset[0][0] = ((
int64_t)sprite_ref[0][0] * (1 << (
alpha + beta + rho - min_ab))) +
584 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
585 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
587 sprite_offset[0][1] = ((
int64_t)sprite_ref[0][1] * (1 << (
alpha + beta + rho - min_ab))) +
588 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
589 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
591 sprite_offset[1][0] = ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
592 ((
int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
593 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][0] - 16 * w2 * h3 +
595 sprite_offset[1][1] = ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
596 ((
int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
597 (
int64_t)2 * w2 * h3 *
r * sprite_ref[0][1] - 16 * w2 * h3 +
599 sprite_delta[0][0] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
600 sprite_delta[0][1] = (-
r * (
int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
601 sprite_delta[1][0] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
602 sprite_delta[1][1] = (-
r * (
int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
604 ctx->sprite_shift[0] =
alpha + beta + rho - min_ab;
605 ctx->sprite_shift[1] =
alpha + beta + rho - min_ab + 2;
608 av_unreachable(
"num_sprite_warping_points outside of 0..3 results in an error"
609 "in which num_sprite_warping_points is reset to zero");
612 if (sprite_delta[0][0] ==
a <<
ctx->sprite_shift[0] &&
613 sprite_delta[0][1] == 0 &&
614 sprite_delta[1][0] == 0 &&
615 sprite_delta[1][1] ==
a <<
ctx->sprite_shift[0]) {
616 sprite_offset[0][0] >>=
ctx->sprite_shift[0];
617 sprite_offset[0][1] >>=
ctx->sprite_shift[0];
618 sprite_offset[1][0] >>=
ctx->sprite_shift[1];
619 sprite_offset[1][1] >>=
ctx->sprite_shift[1];
620 sprite_delta[0][0] =
a;
621 sprite_delta[0][1] = 0;
622 sprite_delta[1][0] = 0;
623 sprite_delta[1][1] =
a;
624 ctx->sprite_shift[0] = 0;
625 ctx->sprite_shift[1] = 0;
626 ctx->real_sprite_warping_points = 1;
628 int shift_y = 16 -
ctx->sprite_shift[0];
629 int shift_c = 16 -
ctx->sprite_shift[1];
631 for (
i = 0;
i < 2;
i++) {
632 if (shift_c < 0 || shift_y < 0 ||
633 FFABS( sprite_offset[0][
i]) >= INT_MAX >> shift_y ||
634 FFABS( sprite_offset[1][
i]) >= INT_MAX >> shift_c ||
635 FFABS( sprite_delta[0][
i]) >= INT_MAX >> shift_y ||
636 FFABS( sprite_delta[1][
i]) >= INT_MAX >> shift_y
643 for (
i = 0;
i < 2;
i++) {
644 sprite_offset[0][
i] *= 1 << shift_y;
645 sprite_offset[1][
i] *= 1 << shift_c;
646 sprite_delta[0][
i] *= 1 << shift_y;
647 sprite_delta[1][
i] *= 1 << shift_y;
648 ctx->sprite_shift[
i] = 16;
651 for (
i = 0;
i < 2;
i++) {
653 sprite_delta[
i][0] -
a * (1LL<<16),
654 sprite_delta[
i][1] -
a * (1LL<<16)
657 if (llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
658 llabs(sprite_offset[0][
i] + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
659 llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL) + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
660 llabs(sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
661 llabs(sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
662 llabs(sd[0]) >= INT_MAX ||
663 llabs(sd[1]) >= INT_MAX ||
664 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL)) >= INT_MAX ||
665 llabs(sprite_offset[0][
i] + sd[1] * (
h+16LL)) >= INT_MAX ||
666 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL) + sd[1] * (
h+16LL)) >= INT_MAX
672 ctx->real_sprite_warping_points =
ctx->num_sprite_warping_points;
675 for (
i = 0;
i < 4;
i++) {
676 ctx->sprite_offset[
i&1][
i>>1] = sprite_offset[
i&1][
i>>1];
677 ctx->sprite_delta [
i&1][
i>>1] = sprite_delta [
i&1][
i>>1];
682 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
683 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
707 int mb_num_bits =
av_log2(
s->mb_num - 1) + 1;
708 int header_extension = 0, mb_num,
len;
729 if (mb_num >=
s->mb_num || !mb_num) {
731 "illegal mb_num in video packet (%d %d) \n", mb_num,
s->mb_num);
735 s->mb_x = mb_num %
s->mb_width;
736 s->mb_y = mb_num /
s->mb_width;
741 s->chroma_qscale =
s->qscale = qscale;
747 if (header_extension) {
751 check_marker(
s->avctx, &
s->gb,
"before time_increment in video packed header");
753 check_marker(
s->avctx, &
s->gb,
"before vop_coding_type in video packed header");
774 "Error, video packet header damaged (f_code=0)\n");
780 "Error, video packet header damaged (b_code=0)\n");
795 s->last_dc[2] = 1 << (
s->avctx->bits_per_raw_sample +
s->dct_precision +
s->intra_dc_precision - 1);
810 vlc_len =
av_log2(
s->mb_width *
s->mb_height) + 1;
813 if (mb_num >=
s->mb_num)
816 s->mb_x = mb_num %
s->mb_width;
817 s->mb_y = mb_num /
s->mb_width;
847 int x, y, mb_v, sum, dx, dy,
shift;
848 int len = 1 << (
ctx->f_code + 4);
849 const int a =
ctx->sprite_warping_accuracy;
852 len >>=
s->quarter_sample;
854 if (
ctx->real_sprite_warping_points == 1) {
855 if (
ctx->divx_version == 500 &&
ctx->divx_build == 413 &&
a >=
s->quarter_sample)
856 sum =
ctx->sprite_offset[0][n] / (1 << (
a -
s->quarter_sample));
858 sum =
RSHIFT(
ctx->sprite_offset[0][n] * (1 <<
s->quarter_sample),
a);
860 dx =
ctx->sprite_delta[n][0];
861 dy =
ctx->sprite_delta[n][1];
864 dy -= 1 << (
shift +
a + 1);
866 dx -= 1 << (
shift +
a + 1);
867 mb_v =
ctx->sprite_offset[0][n] + dx *
s->mb_x * 16
U + dy *
s->mb_y * 16
U;
870 for (y = 0; y < 16; y++) {
873 v = mb_v + (unsigned)dy * y;
875 for (x = 0; x < 16; x++) {
880 sum =
RSHIFT(sum,
a + 8 -
s->quarter_sample);
898 const int16_t *
const dc_val =
s->dc_val +
s->block_index[n];
899 const int wrap =
s->block_wrap[n];
908 int b = dc_val[-1 -
wrap];
909 int c = dc_val[-
wrap];
913 if (
s->first_slice_line && n != 3) {
916 if (n != 1 &&
s->mb_x ==
s->resync_mb_x)
919 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1) {
920 if (n == 0 || n == 4 || n == 5)
936 int scale = n < 4 ?
s->y_dc_scale :
s->c_dc_scale;
948 if (
level & (~2047)) {
952 "dc<0 at %dx%d\n",
s->mb_x,
s->mb_y);
957 "dc overflow at %dx%d\n",
s->mb_x,
s->mb_y);
966 s->dc_val[
s->block_index[n]] =
level;
1029 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1032 s->first_slice_line = 1;
1033 for (;
s->mb_y <
s->mb_height;
s->mb_y++) {
1035 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
1036 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1042 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1)
1043 s->first_slice_line = 0;
1055 "mcbpc corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1058 }
while (cbpc == 8);
1060 s->cbp_table[xy] = cbpc & 3;
1067 s->cur_pic.qscale_table[xy] =
s->qscale;
1069 s->mbintra_table[xy] = 1;
1070 for (
i = 0;
i < 6;
i++) {
1075 "DC corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1082 s->pred_dir_table[xy] = dir;
1085 int16_t *
const mot_val =
s->cur_pic.motion_val[0][
s->block_index[0]];
1086 const int stride =
s->b8_stride * 2;
1094 if (
bits & 0x10000) {
1126 "mcbpc corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1132 s->cbp_table[xy] = cbpc & (8 + 3);
1134 s->mb_intra = ((cbpc & 4) != 0);
1138 s->mbintra_table[xy] = 1;
1157 if ((cbpc & 16) == 0) {
1191 for (
i = 0;
i < 4;
i++) {
1220 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1222 s->mb_x =
s->resync_mb_x;
1223 s->first_slice_line = 1;
1224 for (
s->mb_y =
s->resync_mb_y; mb_num < mb_count; s->mb_y++) {
1226 for (; mb_num < mb_count &&
s->mb_x <
s->mb_width;
s->mb_x++) {
1227 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1231 if (
s->mb_x ==
s->resync_mb_x &&
s->mb_y ==
s->resync_mb_y + 1)
1232 s->first_slice_line = 0;
1239 "cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1243 s->cbp_table[xy] |= cbpy << 2;
1254 "I cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1258 if (
s->cbp_table[xy] & 8)
1260 s->cur_pic.qscale_table[xy] =
s->qscale;
1262 for (
i = 0;
i < 6;
i++) {
1267 "DC corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1274 s->cbp_table[xy] &= 3;
1275 s->cbp_table[xy] |= cbpy << 2;
1277 s->pred_dir_table[xy] = dir;
1278 }
else if (
IS_SKIP(
s->cur_pic.mb_type[xy])) {
1279 s->cur_pic.qscale_table[xy] =
s->qscale;
1280 s->cbp_table[xy] = 0;
1286 "P cbpy corrupted at %d %d\n",
s->mb_x,
s->mb_y);
1290 if (
s->cbp_table[xy] & 8)
1292 s->cur_pic.qscale_table[xy] =
s->qscale;
1294 s->cbp_table[xy] &= 3;
1295 s->cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1299 if (mb_num >= mb_count)
1321 s->mb_x,
s->mb_y, part_a_error);
1325 if (
s->resync_mb_x +
s->resync_mb_y *
s->mb_width + mb_num >
s->mb_num) {
1328 s->mb_x,
s->mb_y, part_a_error);
1332 s->mb_num_left = mb_num;
1339 "marker missing after first I partition at %d %d\n",
1348 "marker missing after first P partition at %d %d\n",
1354 s->mb_x - 1,
s->mb_y, part_a_end);
1376 int n,
int coded,
int intra,
1377 int use_intra_dc_vlc,
int rvlc)
1384 const uint8_t *scan_table;
1390 if (use_intra_dc_vlc) {
1392 if (
s->partitioned_frame) {
1393 level =
s->dc_val[
s->block_index[n]];
1398 dc_pred_dir = (
s->pred_dir_table[
s->mb_x +
s->mb_y *
s->mb_stride] << n) & 32;
1421 if (dc_pred_dir == 0)
1422 scan_table =
s->permutated_intra_v_scantable;
1424 scan_table =
s->permutated_intra_h_scantable;
1426 scan_table =
s->intra_scantable.permutated;
1433 s->block_last_index[n] =
i;
1441 scan_table =
s->intra_scantable.permutated;
1443 if (
ctx->mpeg_quant) {
1451 qmul =
s->qscale << 1;
1452 qadd = (
s->qscale - 1) | 1;
1469 "1. marker bit missing in rvlc esc\n");
1482 "2. marker bit missing in rvlc esc\n");
1508 cache ^= 0xC0000000;
1510 if (cache & 0x80000000) {
1511 if (cache & 0x40000000) {
1526 "1. marker bit missing in 3. esc\n");
1537 "2. marker bit missing in 3. esc\n");
1546 if (
s->error_recognition >= FF_ER_COMPLIANT) {
1549 const int run1=
run - rl->
max_run[last][abs_level] - 1;
1550 if (abs_level <= rl->max_level[last][
run]) {
1554 if (
s->error_recognition > FF_ER_COMPLIANT) {
1555 if (abs_level <= rl->max_level[last][
run]*2) {
1559 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1572 if ((
unsigned)(
level + 2048) > 4095) {
1576 "|level| overflow in 3. esc, qp=%d\n",
1610 ff_tlog(
s->avctx,
"dct[%d][%d] = %- 4d end?:%d\n", scan_table[
i&63]&7, scan_table[
i&63] >> 3,
level,
i>62);
1615 "ac-tex damaged at %d %d\n",
s->mb_x,
s->mb_y);
1630 if (!use_intra_dc_vlc) {
1640 s->block_last_index[n] =
i;
1651 int cbp, mb_type, use_intra_dc_vlc;
1652 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1656 mb_type =
s->cur_pic.mb_type[xy];
1657 cbp =
s->cbp_table[xy];
1659 use_intra_dc_vlc =
s->qscale <
ctx->intra_dc_threshold;
1661 if (
s->cur_pic.qscale_table[xy] !=
s->qscale)
1667 for (
i = 0;
i < 4;
i++) {
1668 s->mv[0][
i][0] =
s->cur_pic.motion_val[0][
s->block_index[
i]][0];
1669 s->mv[0][
i][1] =
s->cur_pic.motion_val[0][
s->block_index[
i]][1];
1675 for (
i = 0;
i < 6;
i++)
1676 s->block_last_index[
i] = -1;
1683 s->cur_pic.mbskip_table[xy] = 0;
1687 s->cur_pic.mbskip_table[xy] = 1;
1689 }
else if (
s->mb_intra) {
1691 }
else if (!
s->mb_intra) {
1708 s->bdsp.clear_blocks(
s->block[0]);
1710 for (
i = 0;
i < 6;
i++) {
1712 use_intra_dc_vlc,
ctx->rvlc) < 0) {
1714 "texture corrupted at %d %d %d\n",
1715 s->mb_x,
s->mb_y,
s->mb_intra);
1723 if (--
s->mb_num_left <= 0) {
1730 const int delta =
s->mb_x + 1 ==
s->mb_width ? 2 : 1;
1731 if (
s->cbp_table[xy +
delta])
1741 int cbpc, cbpy,
i, cbp, pred_x, pred_y,
mx,
my, dquant;
1742 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1743 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1755 for (
i = 0;
i < 6;
i++)
1756 s->block_last_index[
i] = -1;
1768 s->cur_pic.mbskip_table[xy] = 0;
1776 s->cur_pic.mbskip_table[xy] = 1;
1784 "mcbpc damaged at %d %d\n",
s->mb_x,
s->mb_y);
1787 }
while (cbpc == 20);
1790 s->mb_intra = ((cbpc & 4) != 0);
1793 s->bdsp.clear_blocks(
s->block[0]);
1803 "P cbpy damaged at %d %d\n",
s->mb_x,
s->mb_y);
1807 cbp = (cbpc & 3) | (cbpy << 2);
1810 if ((!
s->progressive_sequence) &&
1815 if ((cbpc & 16) == 0) {
1823 s->mv[0][0][0] =
mx;
1824 s->mv[0][0][1] =
my;
1825 }
else if ((!
s->progressive_sequence) &&
get_bits1(&
s->gb)) {
1836 for (
i = 0;
i < 2;
i++) {
1845 s->mv[0][
i][0] =
mx;
1846 s->mv[0][
i][1] =
my;
1862 s->mv[0][0][0] =
mx;
1863 s->mv[0][0][1] =
my;
1868 for (
i = 0;
i < 4;
i++) {
1877 s->mv[0][
i][0] =
mx;
1878 s->mv[0][
i][1] =
my;
1892 for (
i = 0;
i < 2;
i++) {
1893 s->last_mv[
i][0][0] =
1894 s->last_mv[
i][0][1] =
1895 s->last_mv[
i][1][0] =
1896 s->last_mv[
i][1][1] = 0;
1903 s->mb_skipped =
s->next_pic.mbskip_table[
s->mb_y *
s->mb_stride +
s->mb_x];
1905 if (
s->mb_skipped) {
1907 for (
i = 0;
i < 6;
i++)
1908 s->block_last_index[
i] = -1;
1937 s->bdsp.clear_blocks(
s->block[0]);
1946 if (!
s->progressive_sequence) {
1974 s->last_mv[0][1][0] =
1975 s->last_mv[0][0][0] =
1976 s->mv[0][0][0] =
mx;
1977 s->last_mv[0][1][1] =
1978 s->last_mv[0][0][1] =
1979 s->mv[0][0][1] =
my;
1987 s->last_mv[1][1][0] =
1988 s->last_mv[1][0][0] =
1989 s->mv[1][0][0] =
mx;
1990 s->last_mv[1][1][1] =
1991 s->last_mv[1][0][1] =
1992 s->mv[1][0][1] =
my;
2000 for (
i = 0;
i < 2;
i++) {
2003 s->last_mv[0][
i][0] =
2004 s->mv[0][
i][0] =
mx;
2005 s->last_mv[0][
i][1] = (
s->mv[0][
i][1] =
my) * 2;
2012 for (
i = 0;
i < 2;
i++) {
2015 s->last_mv[1][
i][0] =
2016 s->mv[1][
i][0] =
mx;
2017 s->last_mv[1][
i][1] = (
s->mv[1][
i][1] =
my) * 2;
2035 s->cur_pic.mb_type[xy] = mb_type;
2037 int use_intra_dc_vlc;
2043 "I cbpc damaged at %d %d\n",
s->mb_x,
s->mb_y);
2046 }
while (cbpc == 8);
2061 "I cbpy damaged at %d %d\n",
s->mb_x,
s->mb_y);
2064 cbp = (cbpc & 3) | (cbpy << 2);
2066 use_intra_dc_vlc =
s->qscale <
ctx->intra_dc_threshold;
2071 if (!
s->progressive_sequence)
2074 s->bdsp.clear_blocks(
s->block[0]);
2076 for (
i = 0;
i < 6;
i++) {
2078 1, use_intra_dc_vlc, 0) < 0)
2086 for (
i = 0;
i < 6;
i++) {
2096 if (
s->mb_x +
s->mb_y*
s->mb_width + 1 > next && (
s->avctx->err_recognition &
AV_EF_AGGRESSIVE)) {
2098 }
else if (
s->mb_x +
s->mb_y*
s->mb_width + 1 >= next)
2102 const int delta =
s->mb_x + 1 ==
s->mb_width ? 2 : 1;
2104 (
s->mb_x +
delta >=
s->mb_width)
2105 ?
FFMIN(
s->mb_y + 1,
s->mb_height - 1)
2107 if (
s->next_pic.mbskip_table[xy +
delta])
2158 int cc, dct_dc_size, dct_diff,
code, j, idx = 1, group = 0,
run = 0,
2159 additional_code_len, sign, mismatch;
2161 const uint8_t *
const scantable =
s->intra_scantable.permutated;
2162 const uint16_t *quant_matrix;
2164 const int min = -1 * (1 << (
s->avctx->bits_per_raw_sample + 6));
2165 const int max = ((1 << (
s->avctx->bits_per_raw_sample + 6)) - 1);
2166 int shift = 3 -
s->dct_precision;
2175 quant_matrix =
s->intra_matrix;
2182 quant_matrix =
s->chroma_intra_matrix;
2185 if (dct_dc_size == 0) {
2190 if (dct_dc_size > 8) {
2197 s->last_dc[cc] += dct_diff;
2199 if (
ctx->mpeg_quant)
2200 block[0] =
s->last_dc[cc] * (8 >>
s->intra_dc_precision);
2202 block[0] =
s->last_dc[cc] * (8 >>
s->intra_dc_precision) * (8 >>
s->dct_precision);
2206 mismatch ^=
block[0];
2223 }
else if (group >= 1 && group <= 6) {
2225 run = 1 << additional_code_len;
2226 if (additional_code_len)
2230 }
else if (group >= 7 && group <= 12) {
2235 run = (1 << (additional_code_len - 1)) +
code;
2239 j = scantable[idx++];
2240 block[j] = sign ? 1 : -1;
2241 }
else if (group >= 13 && group <= 20) {
2245 j = scantable[idx++];
2247 }
else if (group == 21) {
2251 j = scantable[idx++];
2252 additional_code_len =
s->avctx->bits_per_raw_sample +
s->dct_precision + 4;
2253 flc =
get_bits(&
s->gb, additional_code_len);
2254 if (flc >> (additional_code_len-1))
2255 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
2261 mismatch ^=
block[j];
2264 block[63] ^= mismatch & 1;
2271 int i, j,
w,
h, idx = 0;
2272 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
2273 dpcm_residual,
left, top, topleft, min_left_top, max_left_top, p, p2,
output;
2274 h = 16 >> (n ?
s->chroma_y_shift : 0);
2275 w = 16 >> (n ?
s->chroma_x_shift : 0);
2277 block_mean =
get_bits(&
s->gb,
s->avctx->bits_per_raw_sample);
2278 if (block_mean == 0){
2282 s->last_dc[n] = block_mean * (1 << (
s->dct_precision +
s->intra_dc_precision));
2285 if (rice_parameter == 0) {
2290 if (rice_parameter == 15)
2293 if (rice_parameter > 11) {
2298 for (
i = 0;
i <
h;
i++) {
2299 output = 1 << (
s->avctx->bits_per_raw_sample - 1);
2300 top = 1 << (
s->avctx->bits_per_raw_sample - 1);
2302 for (j = 0; j <
w; j++) {
2309 if (rice_prefix_code == 11)
2310 dpcm_residual =
get_bits(&
s->gb,
s->avctx->bits_per_raw_sample);
2312 if (rice_prefix_code == 12) {
2316 rice_suffix_code =
get_bitsz(&
s->gb, rice_parameter);
2317 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2321 if (dpcm_residual & 1)
2322 dpcm_residual = (-1 * dpcm_residual) >> 1;
2324 dpcm_residual = (dpcm_residual >> 1);
2327 top = macroblock[idx-
w];
2329 p =
left + top - topleft;
2331 if (p < min_left_top)
2335 if (p > max_left_top)
2338 p2 = (
FFMIN(min_left_top, topleft) +
FFMAX(max_left_top, topleft)) >> 1;
2343 dpcm_residual *= -1;
2345 macroblock[idx++] =
output = (dpcm_residual + p) & ((1 <<
s->avctx->bits_per_raw_sample) - 1);
2357 ctx->dpcm_direction = 0;
2378 for (
i = 0;
i < 3;
i++) {
2402 int hours, minutes, seconds;
2414 s->time_base = seconds + 60*(minutes + 60*hours);
2438 int visual_object_type;
2439 int is_visual_object_identifier =
get_bits1(gb);
2441 if (is_visual_object_identifier) {
2444 visual_object_type =
get_bits(gb, 4);
2449 if (video_signal_type) {
2450 int video_range, color_description;
2457 if (color_description) {
2458 s->avctx->color_primaries =
get_bits(gb, 8);
2473 for (
i = 0;
i < 64;
i++) {
2474 int j =
s->idsp.idct_permutation[
i];
2476 s->intra_matrix[j] = v;
2477 s->chroma_intra_matrix[j] = v;
2480 s->inter_matrix[j] = v;
2481 s->chroma_inter_matrix[j] = v;
2493 for (
i = 0;
i < 64;
i++) {
2496 s->intra_matrix[j] = v;
2497 s->chroma_intra_matrix[j] = v;
2505 for (
i = 0;
i < 64;
i++) {
2514 for (
i = 0;
i < 64;
i++) {
2517 s->chroma_intra_matrix[j] = v;
2525 for (
i = 0;
i < 64;
i++) {
2537 uint8_t extension_type;
2555 int bits_per_raw_sample;
2556 int rgb, chroma_format;
2576 bits_per_raw_sample =
get_bits(gb, 4);
2577 if (bits_per_raw_sample == 10) {
2587 if (
rgb !=
ctx->rgb ||
s->chroma_format != chroma_format)
2588 s->context_reinit = 1;
2589 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
2591 s->chroma_format = chroma_format;
2594 check_marker(
s->avctx, gb,
"before video_object_layer_width");
2596 check_marker(
s->avctx, gb,
"before video_object_layer_height");
2598 check_marker(
s->avctx, gb,
"after video_object_layer_height");
2602 if (
s->width &&
s->height &&
2604 s->context_reinit = 1;
2609 aspect_ratio_info =
get_bits(gb, 4);
2611 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2612 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2622 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2625 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2627 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2655 s->studio_profile = 1;
2658 }
else if (
s->studio_profile) {
2668 aspect_ratio_info =
get_bits(gb, 4);
2670 s->avctx->sample_aspect_ratio.num =
get_bits(gb, 8);
2671 s->avctx->sample_aspect_ratio.den =
get_bits(gb, 8);
2677 int chroma_format =
get_bits(gb, 2);
2688 check_marker(
s->avctx, gb,
"after first_half_vbv_buffer_size");
2691 check_marker(
s->avctx, gb,
"after first_half_vbv_occupancy");
2693 check_marker(
s->avctx, gb,
"after latter_half_vbv_occupancy");
2698 if (
s->picture_number == 0) {
2699 switch (
ctx->vo_type) {
2718 check_marker(
s->avctx, gb,
"before time_increment_resolution");
2720 s->avctx->framerate.num =
get_bits(gb, 16);
2721 if (!
s->avctx->framerate.num) {
2726 ctx->time_increment_bits =
av_log2(
s->avctx->framerate.num - 1) + 1;
2727 if (
ctx->time_increment_bits < 1)
2728 ctx->time_increment_bits = 1;
2733 s->avctx->framerate.den =
get_bits(gb,
ctx->time_increment_bits);
2735 s->avctx->framerate.den = 1;
2747 !(
s->width &&
s->codec_tag ==
AV_RL32(
"MP4S"))) {
2748 if (
s->width &&
s->height &&
2750 s->context_reinit = 1;
2756 s->progressive_sequence =
2758 s->interlaced_dct = 0;
2761 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
2782 if (
ctx->num_sprite_warping_points > 3) {
2784 "%d sprite_warping_points\n",
2785 ctx->num_sprite_warping_points);
2786 ctx->num_sprite_warping_points = 0;
2800 if (
ctx->quant_precision != 5)
2802 "quant precision %d\n",
ctx->quant_precision);
2803 if (
ctx->quant_precision < 3 ||
ctx->quant_precision > 9)
2804 ctx->quant_precision = 5;
2806 ctx->quant_precision = 5;
2819 for (
i = 0;
i < 64;
i++) {
2831 s->intra_matrix[j] = last;
2835 for (;
i < 64;
i++) {
2837 s->intra_matrix[j] = last;
2844 for (
i = 0;
i < 64;
i++) {
2856 s->inter_matrix[j] = v;
2860 for (;
i < 64;
i++) {
2862 s->inter_matrix[j] = last;
2872 s->quarter_sample = 0;
2881 int estimation_method =
get_bits(gb, 2);
2882 if (estimation_method < 2) {
2897 if (!
check_marker(
s->avctx, gb,
"in complexity estimation part 1")) {
2915 if (!
check_marker(
s->avctx, gb,
"in complexity estimation part 2")) {
2919 if (estimation_method == 1) {
2925 "Invalid Complexity estimation method %d\n",
2930 ctx->cplx_estimation_trash_i =
2931 ctx->cplx_estimation_trash_p =
2932 ctx->cplx_estimation_trash_b = 0;
2938 if (
s->data_partitioning)
2941 if (vo_ver_id != 1) {
2943 if (
ctx->new_pred) {
2950 "reduced resolution VOP not supported\n");
2957 if (
ctx->scalability) {
2959 int h_sampling_factor_n;
2960 int h_sampling_factor_m;
2961 int v_sampling_factor_n;
2962 int v_sampling_factor_m;
2967 h_sampling_factor_n =
get_bits(gb, 5);
2968 h_sampling_factor_m =
get_bits(gb, 5);
2969 v_sampling_factor_n =
get_bits(gb, 5);
2970 v_sampling_factor_m =
get_bits(gb, 5);
2973 if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2974 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2977 ctx->scalability = 0;
2987 av_log(
s->avctx,
AV_LOG_DEBUG,
"tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
2988 s->avctx->framerate.den,
s->avctx->framerate.num,
2989 ctx->time_increment_bits,
2990 ctx->quant_precision,
2991 s->progressive_sequence,
2993 ctx->scalability ?
"scalability " :
"" ,
s->quarter_sample ?
"qpel " :
"",
2994 s->data_partitioning ?
"partition " :
"",
ctx->rvlc ?
"rvlc " :
""
3011 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
3022 e = sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
3024 e = sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
3026 ctx->divx_version = ver;
3027 ctx->divx_build = build;
3028 s->divx_packed = e == 3 && last ==
'p';
3032 e = sscanf(buf,
"FFmpe%*[^b]b%d", &build) + 3;
3034 e = sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
3036 e = sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
3038 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
3040 "Unknown Lavc version string encountered, %d.%d.%d; "
3041 "clamping sub-version values to 8-bits.\n",
3044 build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
3048 if (strcmp(buf,
"ffmpeg") == 0)
3049 ctx->lavc_build = 4600;
3052 ctx->lavc_build = build;
3055 e = sscanf(buf,
"XviD%d", &build);
3057 ctx->xvid_build = build;
3063 const uint8_t new_perm[64],
3064 const uint8_t old_perm[64])
3069 for (
int i = 0;
i < 64; ++
i)
3076 uint8_t old_permutation[64];
3078 memcpy(old_permutation,
s->idsp.idct_permutation,
sizeof(old_permutation));
3084 s->idsp.idct_permutation);
3096 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1) {
3097 if (
s->codec_tag ==
AV_RL32(
"XVID") ||
3102 ctx->xvid_build = 0;
3105 if (
ctx->xvid_build == -1 &&
ctx->divx_version == -1 &&
ctx->lavc_build == -1)
3106 if (
s->codec_tag ==
AV_RL32(
"DIVX") &&
ctx->vo_type == 0 &&
3107 ctx->vol_control_parameters == 0)
3108 ctx->divx_version = 400;
3110 if (
ctx->xvid_build >= 0 &&
ctx->divx_version >= 0) {
3112 ctx->divx_build = -1;
3116 if (
s->codec_tag ==
AV_RL32(
"XVIX"))
3119 if (
s->codec_tag ==
AV_RL32(
"UMP4"))
3122 if (
ctx->divx_version >= 500 &&
ctx->divx_build < 1814)
3125 if (
ctx->divx_version > 502 &&
ctx->divx_build < 1814)
3128 if (
ctx->xvid_build <= 3
U)
3129 s->padding_bug_score = 256 * 256 * 256 * 64;
3131 if (
ctx->xvid_build <= 1
U)
3134 if (
ctx->xvid_build <= 12
U)
3137 if (
ctx->xvid_build <= 32
U)
3140 #define SET_QPEL_FUNC(postfix1, postfix2) \
3141 s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3142 s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3143 s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
3145 if (
ctx->lavc_build < 4653
U)
3148 if (
ctx->lavc_build < 4655
U)
3151 if (
ctx->lavc_build < 4670
U)
3154 if (
ctx->lavc_build <= 4712
U)
3157 if ((
ctx->lavc_build&0xFF) >= 100) {
3158 if (
ctx->lavc_build > 3621476 &&
ctx->lavc_build < 3752552 &&
3159 (
ctx->lavc_build < 3752037 ||
ctx->lavc_build > 3752191)
3164 if (
ctx->divx_version >= 0)
3166 if (
ctx->divx_version == 501 &&
ctx->divx_build == 20020416)
3167 s->padding_bug_score = 256 * 256 * 256 * 64;
3169 if (
ctx->divx_version < 500
U)
3172 if (
ctx->divx_version >= 0)
3194 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
3195 s->workaround_bugs,
ctx->lavc_build,
ctx->xvid_build,
3196 ctx->divx_version,
ctx->divx_build,
s->divx_packed ?
"p" :
"");
3198 if (CONFIG_MPEG4_DECODER &&
ctx->xvid_build >= 0 &&
3208 int time_incr, time_increment;
3220 if (
s->partitioned_frame)
3231 if (
ctx->time_increment_bits == 0 ||
3234 "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);
3236 for (
ctx->time_increment_bits = 1;
3237 ctx->time_increment_bits < 16;
3238 ctx->time_increment_bits++) {
3242 if ((
show_bits(gb,
ctx->time_increment_bits + 6) & 0x37) == 0x30)
3244 }
else if ((
show_bits(gb,
ctx->time_increment_bits + 5) & 0x1F) == 0x18)
3249 "time_increment_bits set to %d bits, based on bitstream analysis\n",
ctx->time_increment_bits);
3255 time_increment =
get_bits(gb,
ctx->time_increment_bits);
3258 s->last_time_base =
s->time_base;
3259 s->time_base += time_incr;
3260 s->time =
s->time_base * (
int64_t)
s->avctx->framerate.num + time_increment;
3262 if (
s->time <
s->last_non_b_time) {
3266 s->time +=
s->avctx->framerate.num;
3269 s->pp_time =
s->time -
s->last_non_b_time;
3270 s->last_non_b_time =
s->time;
3272 s->time = (
s->last_time_base + time_incr) * (
int64_t)
s->avctx->framerate.num + time_increment;
3273 s->pb_time =
s->pp_time - (
s->last_non_b_time -
s->time);
3274 if (
s->pp_time <=
s->pb_time ||
3275 s->pp_time <=
s->pp_time -
s->pb_time ||
3282 if (
ctx->t_frame == 0)
3283 ctx->t_frame =
s->pb_time;
3284 if (
ctx->t_frame == 0)
3290 if (
s->pp_field_time <=
s->pb_field_time ||
s->pb_field_time <= 1) {
3291 s->pb_field_time = 2;
3292 s->pp_field_time = 4;
3293 if (!
s->progressive_sequence)
3298 if (
s->avctx->framerate.den)
3310 s->skipped_last_frame = 1;
3357 if (!
s->progressive_sequence) {
3361 s->alternate_scan = 0;
3369 if (
s->alternate_scan) {
3372 s->idsp.idct_permutation);
3376 s->idsp.idct_permutation);
3379 s->idsp.idct_permutation);
3386 if (
ctx->sprite_brightness_change)
3388 "sprite_brightness_change not supported\n");
3392 memset(
ctx->sprite_offset, 0,
sizeof(
ctx->sprite_offset));
3393 memset(
ctx->sprite_delta, 0,
sizeof(
ctx->sprite_delta));
3400 s->chroma_qscale =
s->qscale =
get_bits(gb,
ctx->quant_precision);
3401 if (
s->qscale == 0) {
3403 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
3409 if (
ctx->f_code == 0) {
3411 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
3419 if (
ctx->b_code == 0) {
3421 "Error, header damaged or not MPEG4 header (b_code=0)\n");
3429 "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",
3430 s->qscale,
ctx->f_code,
ctx->b_code,
3433 s->top_field_first,
s->quarter_sample ?
'q' :
'h',
3434 s->data_partitioning,
ctx->resync_marker,
3435 ctx->num_sprite_warping_points,
ctx->sprite_warping_accuracy,
3436 1 -
s->no_rounding,
ctx->vo_type,
3437 ctx->vol_control_parameters ?
" VOLC" :
" ",
ctx->intra_dc_threshold,
3438 ctx->cplx_estimation_trash_i,
ctx->cplx_estimation_trash_p,
3439 ctx->cplx_estimation_trash_b,
3445 if (!
ctx->scalability) {
3449 if (
ctx->enhancement_type) {
3450 int load_backward_shape =
get_bits1(gb);
3451 if (load_backward_shape)
3453 "load backward shape isn't supported\n");
3459 s->dct_unquantize_intra =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_intra
3460 :
ctx->dct_unquantize_h263_intra;
3462 s->dct_unquantize_inter =
ctx->mpeg_quant ?
ctx->dct_unquantize_mpeg2_inter :
NULL;
3468 if (
ctx->vo_type == 0 &&
ctx->vol_control_parameters == 0 &&
3469 ctx->divx_version == -1 &&
s->picture_number == 0) {
3471 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3475 s->picture_number++;
3478 s->h_edge_pos =
s->width;
3479 s->v_edge_pos =
s->height;
3510 s->partitioned_frame = 0;
3511 s->interlaced_dct = 0;
3534 s->intra_dc_precision =
get_bits(gb, 2);
3552 int visual_object_type;
3555 visual_object_type =
get_bits(gb, 4);
3578 int header,
int parse_only)
3581 unsigned startcode, v;
3591 if (!
s->studio_profile &&
s->avctx->bits_per_raw_sample != 8)
3592 s->avctx->bits_per_raw_sample = 0;
3604 (
ctx->divx_version >= 0 ||
ctx->xvid_build >= 0) ||
s->codec_tag ==
AV_RL32(
"QMP4")) {
3615 startcode = ((startcode << 8) | v) & 0xffffffff;
3617 if ((startcode & 0xFFFFFF00) != 0x100)
3622 if (startcode <= 0x11F)
3623 name =
"Video Object Start";
3624 else if (startcode <= 0x12F)
3625 name =
"Video Object Layer Start";
3626 else if (startcode <= 0x13F)
3628 else if (startcode <= 0x15F)
3629 name =
"FGS bp start";
3630 else if (startcode <= 0x1AF)
3632 else if (startcode == 0x1B0)
3633 name =
"Visual Object Seq Start";
3634 else if (startcode == 0x1B1)
3635 name =
"Visual Object Seq End";
3636 else if (startcode == 0x1B2)
3638 else if (startcode == 0x1B3)
3639 name =
"Group of VOP start";
3640 else if (startcode == 0x1B4)
3641 name =
"Video Session Error";
3642 else if (startcode == 0x1B5)
3643 name =
"Visual Object Start";
3644 else if (startcode == 0x1B6)
3645 name =
"Video Object Plane start";
3646 else if (startcode == 0x1B7)
3647 name =
"slice start";
3648 else if (startcode == 0x1B8)
3649 name =
"extension start";
3650 else if (startcode == 0x1B9)
3652 else if (startcode == 0x1BA)
3653 name =
"FBA Object start";
3654 else if (startcode == 0x1BB)
3655 name =
"FBA Object Plane start";
3656 else if (startcode == 0x1BC)
3657 name =
"Mesh Object start";
3658 else if (startcode == 0x1BD)
3659 name =
"Mesh Object Plane start";
3660 else if (startcode == 0x1BE)
3661 name =
"Still Texture Object start";
3662 else if (startcode == 0x1BF)
3663 name =
"Texture Spatial Layer start";
3664 else if (startcode == 0x1C0)
3665 name =
"Texture SNR Layer start";
3666 else if (startcode == 0x1C1)
3667 name =
"Texture Tile start";
3668 else if (startcode == 0x1C2)
3669 name =
"Texture Shape Layer start";
3670 else if (startcode == 0x1C3)
3671 name =
"stuffing start";
3672 else if (startcode <= 0x1C5)
3674 else if (startcode <= 0x1FF)
3675 name =
"System start";
3680 if (startcode >= 0x120 && startcode <= 0x12F) {
3697 s->studio_profile = 1;
3700 }
else if (
s->studio_profile) {
3707 if (
s->studio_profile) {
3724 if (
s->studio_profile) {
3725 if (!
s->avctx->bits_per_raw_sample) {
3738 s->skipped_last_frame = 0;
3740 if (
ctx->bitstream_buffer) {
3742 int bitstream_buffer_size =
ctx->bitstream_buffer->size;
3743 const uint8_t *buf =
s->gb.buffer;
3745 if (
s->divx_packed) {
3746 for (
int i = 0;
i < buf_size - 3;
i++) {
3747 if (buf[
i] == 0 && buf[
i+1] == 0 && buf[
i+2] == 1) {
3748 if (buf[
i+3] == 0xB0) {
3750 bitstream_buffer_size = 0;
3756 ctx->bitstream_buffer->size = 0;
3757 if (bitstream_buffer_size && (
s->divx_packed || buf_size <=
MAX_NVOP_SIZE)) {
3759 bitstream_buffer_size);
3778 if (
s->divx_packed) {
3779 int current_pos =
ctx->bitstream_buffer &&
s->gb.buffer ==
ctx->bitstream_buffer->data ? 0 : (
get_bits_count(&
s->gb) >> 3);
3780 int startcode_found = 0;
3784 if (buf_size - current_pos > 7) {
3787 for (
i = current_pos;
i < buf_size - 4;
i++)
3792 buf[
i + 3] == 0xB6) {
3793 startcode_found = !(buf[
i + 4] & 0x40);
3798 if (startcode_found) {
3799 if (!
ctx->showed_packed_warning) {
3801 "wasteful way to store B-frames ('packed B-frames'). "
3802 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
3803 ctx->showed_packed_warning = 1;
3809 ctx->bitstream_buffer->data = buf + current_pos;
3810 ctx->bitstream_buffer->size = buf_size - current_pos;
3817 #if CONFIG_MPEG4_DECODER
3821 memset(&
s->buffer_pools, 0,
sizeof(
s->buffer_pools));
3822 memset(&
s->next_pic, 0,
sizeof(
s->next_pic));
3823 memset(&
s->last_pic, 0,
sizeof(
s->last_pic));
3824 memset(&
s->cur_pic, 0,
sizeof(
s->cur_pic));
3826 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
3830 s->ac_val_base =
NULL;
3832 memset(&
s->sc, 0,
sizeof(
s->sc));
3834 s->p_field_mv_table_base =
NULL;
3835 for (
int i = 0;
i < 2;
i++)
3836 for (
int j = 0; j < 2; j++)
3837 s->p_field_mv_table[
i][j] =
NULL;
3839 s->dc_val_base =
NULL;
3840 s->coded_block_base =
NULL;
3841 s->mbintra_table =
NULL;
3842 s->cbp_table =
NULL;
3843 s->pred_dir_table =
NULL;
3845 s->mbskip_table =
NULL;
3847 s->er.error_status_table =
NULL;
3848 s->er.er_temp_buffer =
NULL;
3849 s->mb_index2xy =
NULL;
3851 s->context_initialized = 0;
3852 s->context_reinit = 0;
3860 memcpy(
s, s1,
sizeof(*
s));
3878 int init =
s->m.context_initialized;
3882 ret = update_mpvctx(&
s->m, &s1->
m);
3940 static av_cold void mpeg4_init_static(
void)
3955 for (
unsigned i = 0;
i < 12;
i++) {
3995 ctx->lavc_build = -1;
4015 ctx->time_increment_bits = 4;
4016 ctx->quant_precision = 5;
4053 #define OFFSET(x) offsetof(MpegEncContext, x)
4054 #define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
4061 static const AVClass mpeg4_class = {
4076 .close = mpeg4_close,
4081 .flush = mpeg4_flush,
4086 .p.priv_class = &mpeg4_class,
4088 #if CONFIG_MPEG4_NVDEC_HWACCEL
4091 #if CONFIG_MPEG4_VAAPI_HWACCEL
4094 #if CONFIG_MPEG4_VDPAU_HWACCEL
4097 #if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
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
int data_partitioning
data partitioning flag from header
#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_studio_mb(MpegEncContext *s, int16_t block_[12][64])
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
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)
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 get_amv(Mpeg4DecContext *ctx, int n)
Get the average motion vector for a GMC MB.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
#define MB_TYPE_B_VLC_BITS
#define STUDIO_INTRA_BITS
#define FF_BUG_QPEL_CHROMA2
#define AV_PIX_FMT_GBRP10
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
const AVRational ff_h263_pixel_aspect[16]
#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
#define SLICE_END
end marker found
#define AV_PIX_FMT_YUV444P10
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
#define HAS_FORWARD_MV(a)
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)
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
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)
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.
static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
#define SKIP_BITS(name, gb, num)
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)
@ 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.
static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
decode partition C of one MB.
static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
struct AVCodecInternal * internal
Private context used for internal data.
#define SLICE_NOEND
no end marker or error found but mb count exceeded
#define ROUNDED_DIV(a, b)
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static unsigned int get_bits1(GetBitContext *s)
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[]
#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 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)
int ff_mpeg4_decode_picture_header(MpegEncContext *s)
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
Return value for header parsers if 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 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
int quarter_sample
1->qpel, 0->half pel ME/MC
static const uint8_t header[24]
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
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.
static int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
Decode the dc value.
#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]
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
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
#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)
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
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.
static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
decode second partition.
#define SHOW_UBITS(name, gb, num)
const uint8_t ff_mb_type_b_tab[4][2]
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#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]
static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[256], int n)
@ AV_PICTURE_TYPE_P
Predicted.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Undefined Behavior In the C some operations are like signed integer overflow
#define 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(...)
static void reset_studio_dc_predictors(MpegEncContext *s)
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]
static int mpeg_get_qscale(MpegEncContext *s)
#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]