Go to the documentation of this file.
28 #include "config_components.h"
30 #define UNCHECKED_BITSTREAM_READER 1
32 #include <stdatomic.h>
63 #define A53_MAX_CC_COUNT 2000
131 #define MAX_INDEX (64 - 1)
132 #define check_scantable_index(ctx, x) \
134 if ((x) > MAX_INDEX) { \
135 av_log(ctx->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
136 ctx->c.mb_x, ctx->c.mb_y); \
137 return AVERROR_INVALIDDATA; \
142 int16_t *
block,
int n)
145 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
146 const uint16_t *quant_matrix =
s->c.inter_matrix;
147 const int qscale =
s->c.qscale;
155 level = (3 * qscale * quant_matrix[0]) >> 5;
175 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
190 }
else if (
level == 0) {
200 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
204 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
221 s->c.block_last_index[n] =
i;
226 int16_t *
block,
int n)
229 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
230 const uint16_t *quant_matrix;
231 const int qscale =
s->c.qscale;
240 quant_matrix =
s->c.inter_matrix;
242 quant_matrix =
s->c.chroma_inter_matrix;
247 level = (3 * qscale * quant_matrix[0]) >> 5;
268 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
285 level = ((-
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
288 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
302 block[63] ^= (mismatch & 1);
306 s->c.block_last_index[n] =
i;
311 int16_t *
block,
int n)
316 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
317 const uint16_t *quant_matrix;
318 const int qscale =
s->c.qscale;
323 quant_matrix =
s->c.intra_matrix;
326 quant_matrix =
s->c.chroma_intra_matrix;
327 component = (n & 1) + 1;
330 dc =
s->c.last_dc[component];
332 s->c.last_dc[component] =
dc;
333 block[0] =
dc * (1 << (3 -
s->c.intra_dc_precision));
335 mismatch =
block[0] ^ 1;
337 if (
s->c.intra_vlc_format)
352 }
else if (
level != 0) {
357 level = (
level * qscale * quant_matrix[j]) >> 4;
372 level = (-
level * qscale * quant_matrix[j]) >> 4;
375 level = (
level * qscale * quant_matrix[j]) >> 4;
384 block[63] ^= mismatch & 1;
407 int i, j, k, cbp,
val, mb_type, motion_type;
408 const int mb_block_count = 4 + (1 <<
s->c.chroma_format);
411 ff_tlog(
s->c.avctx,
"decode_mb: x=%d y=%d\n",
s->c.mb_x,
s->c.mb_y);
415 if ((*mb_skip_run)-- != 0) {
418 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] =
424 mb_type =
s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride - 1];
427 mb_type =
s->c.cur_pic.mb_type[
s->c.mb_width + (
s->c.mb_y - 1) *
s->c.mb_stride - 1];
432 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] =
435 if ((
s->c.mv[0][0][0] |
s->c.mv[0][0][1] |
s->c.mv[1][0][0] |
s->c.mv[1][0][1]) == 0)
442 switch (
s->c.pict_type) {
448 "Invalid mb type in I-frame at %d %d\n",
449 s->c.mb_x,
s->c.mb_y);
461 "Invalid mb type in P-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
469 "Invalid mb type in B-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
474 ff_tlog(
s->c.avctx,
"mb_type=%x\n", mb_type);
477 s->c.bdsp.clear_blocks(
s->block[0]);
479 if (!
s->c.chroma_y_shift)
480 s->c.bdsp.clear_blocks(
s->block[6]);
485 !
s->c.frame_pred_frame_dct)
491 if (
s->c.concealment_motion_vectors) {
497 s->c.last_mv[0][0][0] =
499 s->c.last_mv[0][0][0]);
501 s->c.last_mv[0][0][1] =
503 s->c.last_mv[0][0][1]);
505 check_marker(
s->c.avctx, &
s->gb,
"after concealment_motion_vectors");
508 memset(
s->c.last_mv, 0,
sizeof(
s->c.last_mv));
513 for (
i = 0;
i < mb_block_count;
i++)
517 for (
i = 0;
i < 6;
i++) {
520 s->c.intra_scantable.permutated,
521 s->c.last_dc,
s->block[
i],
525 s->c.mb_x,
s->c.mb_y);
537 && !
s->c.frame_pred_frame_dct)
543 s->c.field_select[0][0] =
s->c.picture_structure - 1;
549 s->c.last_mv[0][0][0] = 0;
550 s->c.last_mv[0][0][1] = 0;
551 s->c.last_mv[0][1][0] = 0;
552 s->c.last_mv[0][1][1] = 0;
553 s->c.mv[0][0][0] = 0;
554 s->c.mv[0][0][1] = 0;
559 if (
s->c.picture_structure ==
PICT_FRAME &&
s->c.frame_pred_frame_dct) {
572 ff_tlog(
s->c.avctx,
"motion_type=%d\n", motion_type);
573 switch (motion_type) {
578 for (
i = 0;
i < 2;
i++) {
582 s->c.last_mv[
i][0][0] =
583 s->c.last_mv[
i][1][0] =
585 s->c.last_mv[
i][0][0]);
587 s->c.last_mv[
i][0][1] =
588 s->c.last_mv[
i][1][1] =
590 s->c.last_mv[
i][0][1]);
592 if (
s->c.full_pel[
i]) {
593 s->c.mv[
i][0][0] *= 2;
594 s->c.mv[
i][0][1] *= 2;
601 for (
i = 0;
i < 2;
i++) {
604 for (j = 0; j < 2; j++) {
606 for (k = 0; k < 2; k++) {
608 s->c.last_mv[
i][j][k]);
609 s->c.last_mv[
i][j][k] =
val;
610 s->c.mv[
i][j][k] =
val;
621 for (
i = 0;
i < 2;
i++) {
623 for (j = 0; j < 2; j++) {
626 s->c.last_mv[
i][j][0]);
627 s->c.last_mv[
i][j][0] =
val;
628 s->c.mv[
i][j][0] =
val;
631 s->c.last_mv[
i][j][1] >> 1);
632 s->c.last_mv[
i][j][1] = 2 *
val;
633 s->c.mv[
i][j][1] =
val;
641 for (
i = 0;
i < 2;
i++) {
644 for (k = 0; k < 2; k++) {
646 s->c.last_mv[
i][0][k]);
647 s->c.last_mv[
i][0][k] =
val;
648 s->c.last_mv[
i][1][k] =
val;
649 s->c.mv[
i][0][k] =
val;
656 if (
s->c.progressive_sequence){
661 for (
i = 0;
i < 2;
i++) {
663 int dmx, dmy,
mx,
my, m;
664 const int my_shift =
s->c.picture_structure ==
PICT_FRAME;
667 s->c.last_mv[
i][0][0]);
668 s->c.last_mv[
i][0][0] =
mx;
669 s->c.last_mv[
i][1][0] =
mx;
672 s->c.last_mv[
i][0][1] >> my_shift);
676 s->c.last_mv[
i][0][1] =
my * (1 << my_shift);
677 s->c.last_mv[
i][1][1] =
my * (1 << my_shift);
679 s->c.mv[
i][0][0] =
mx;
680 s->c.mv[
i][0][1] =
my;
681 s->c.mv[
i][1][0] =
mx;
682 s->c.mv[
i][1][1] =
my;
688 m =
s->c.top_field_first ? 1 : 3;
691 s->c.mv[
i][2][0] = ((
mx * m + (
mx > 0)) >> 1) + dmx;
692 s->c.mv[
i][2][1] = ((
my * m + (
my > 0)) >> 1) + dmy - 1;
694 s->c.mv[
i][3][0] = ((
mx * m + (
mx > 0)) >> 1) + dmx;
695 s->c.mv[
i][3][1] = ((
my * m + (
my > 0)) >> 1) + dmy + 1;
699 s->c.mv[
i][2][0] = ((
mx + (
mx > 0)) >> 1) + dmx;
700 s->c.mv[
i][2][1] = ((
my + (
my > 0)) >> 1) + dmy;
711 "00 motion_type at %d %d\n",
s->c.mb_x,
s->c.mb_y);
717 s->c.last_dc[0] =
s->c.last_dc[1] =
s->c.last_dc[2] = 128 <<
s->c.intra_dc_precision;
719 s->c.bdsp.clear_blocks(
s->block[0]);
722 if (mb_block_count > 6) {
723 cbp *= 1 << mb_block_count - 6;
724 cbp |=
get_bits(&
s->gb, mb_block_count - 6);
725 s->c.bdsp.clear_blocks(
s->block[6]);
729 "invalid cbp %d at %d %d\n", cbp,
s->c.mb_x,
s->c.mb_y);
734 cbp <<= 12 - mb_block_count;
736 for (
i = 0;
i < mb_block_count;
i++) {
737 if (cbp & (1 << 11)) {
741 s->c.block_last_index[
i] = -1;
746 for (
i = 0;
i < 6;
i++) {
751 s->c.block_last_index[
i] = -1;
757 for (
i = 0;
i < 12;
i++)
758 s->c.block_last_index[
i] = -1;
762 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] = mb_type;
791 #if CONFIG_MPEG1_NVDEC_HWACCEL
794 #if CONFIG_MPEG1_VDPAU_HWACCEL
802 #if CONFIG_MPEG2_NVDEC_HWACCEL
805 #if CONFIG_MPEG2_VDPAU_HWACCEL
808 #if CONFIG_MPEG2_DXVA2_HWACCEL
811 #if CONFIG_MPEG2_D3D11VA_HWACCEL
815 #if CONFIG_MPEG2_D3D12VA_HWACCEL
818 #if CONFIG_MPEG2_VAAPI_HWACCEL
821 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
877 s1->pan_scan.height }),
887 s->avctx->sample_aspect_ratio =
891 s->avctx->sample_aspect_ratio =
893 (
AVRational) { s1->pan_scan.width, s1->pan_scan.height });
898 ff_dlog(avctx,
"aspect A %d/%d\n",
901 ff_dlog(avctx,
"aspect B %d/%d\n",
s->avctx->sample_aspect_ratio.num,
902 s->avctx->sample_aspect_ratio.den);
905 s->avctx->sample_aspect_ratio =
918 if (!
s->context_initialized ||
924 if (
s->context_initialized)
952 &
s->avctx->framerate.den,
957 switch (
s->chroma_format) {
969 if (!
s->avctx->lowres)
970 for (
int i = 0;
i <
s->slice_context_count;
i++)
982 int ref, f_code, vbv_delay,
ret;
990 if (
s->pict_type == 0 ||
s->pict_type > 3)
1002 s->mpeg_f_code[0][0] = f_code;
1003 s->mpeg_f_code[0][1] = f_code;
1011 s->mpeg_f_code[1][0] = f_code;
1012 s->mpeg_f_code[1][1] = f_code;
1017 "vbv_delay %d, ref %d type:%d\n", vbv_delay,
ref,
s->pict_type);
1026 int horiz_size_ext, vert_size_ext;
1035 if (!
s->chroma_format) {
1042 s->width |= (horiz_size_ext << 12);
1043 s->height |= (vert_size_ext << 12);
1045 s1->
bit_rate += (bit_rate_ext << 18) * 400LL;
1047 s->avctx->rc_buffer_size +=
get_bits(gb, 8) * 1024 * 16 << 10;
1056 ff_dlog(
s->avctx,
"sequence extension\n");
1061 "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64
"\n",
1062 s->avctx->profile,
s->avctx->level,
s->progressive_sequence,
s->chroma_format,
1063 s->avctx->rc_buffer_size, s1->
bit_rate);
1070 int color_description,
w,
h;
1074 if (color_description) {
1075 s->avctx->color_primaries =
get_bits(gb, 8);
1098 if (
s->progressive_sequence) {
1099 if (
s->repeat_first_field) {
1101 if (
s->top_field_first)
1107 if (
s->repeat_first_field)
1111 for (
i = 0;
i < nofco;
i++) {
1120 "pde (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
")\n",
1127 uint16_t matrix0[64], uint16_t matrix1[64],
int intra)
1131 for (
i = 0;
i < 64;
i++) {
1138 if (intra &&
i == 0 && v != 8) {
1139 av_log(
s->avctx,
AV_LOG_DEBUG,
"intra matrix specifies invalid DC quantizer %d, ignoring\n", v);
1152 ff_dlog(
s->avctx,
"matrix extension\n");
1169 s->full_pel[0] =
s->full_pel[1] = 0;
1174 s->mpeg_f_code[0][0] += !
s->mpeg_f_code[0][0];
1175 s->mpeg_f_code[0][1] += !
s->mpeg_f_code[0][1];
1176 s->mpeg_f_code[1][0] += !
s->mpeg_f_code[1][0];
1177 s->mpeg_f_code[1][1] += !
s->mpeg_f_code[1][1];
1178 if (!
s->pict_type &&
s->context_initialized) {
1183 if (
s->mpeg_f_code[1][0] == 15 &&
s->mpeg_f_code[1][1] == 15) {
1184 if (
s->mpeg_f_code[0][0] == 15 &&
s->mpeg_f_code[0][1] == 15)
1192 s->intra_dc_precision =
get_bits(gb, 2);
1196 s->concealment_motion_vectors =
get_bits1(gb);
1207 s->idsp.idct_permutation);
1210 ff_dlog(
s->avctx,
"intra_dc_precision=%d\n",
s->intra_dc_precision);
1211 ff_dlog(
s->avctx,
"picture_structure=%d\n",
s->picture_structure);
1212 ff_dlog(
s->avctx,
"top field first=%d\n",
s->top_field_first);
1213 ff_dlog(
s->avctx,
"repeat first field=%d\n",
s->repeat_first_field);
1214 ff_dlog(
s->avctx,
"conceal=%d\n",
s->concealment_motion_vectors);
1215 ff_dlog(
s->avctx,
"intra_vlc_format=%d\n",
s->intra_vlc_format);
1216 ff_dlog(
s->avctx,
"alternate_scan=%d\n",
s->alternate_scan);
1217 ff_dlog(
s->avctx,
"frame_pred_frame_dct=%d\n",
s->frame_pred_frame_dct);
1218 ff_dlog(
s->avctx,
"progressive_frame=%d\n",
s->progressive_frame);
1227 int second_field = 0;
1231 if (
s->mb_width *
s->mb_height * 11LL / (33 * 2 * 8) > buf_size)
1236 if (
s->first_field ||
s->picture_structure ==
PICT_FRAME) {
1246 for (
int i = 0;
i < 3;
i++) {
1249 s->cur_pic.linesize[
i]);
1251 s->cur_pic.linesize[
i] *= 2;
1258 s->cur_pic.ptr->f->repeat_pict = 0;
1259 if (
s->repeat_first_field) {
1260 if (
s->progressive_sequence) {
1261 if (
s->top_field_first)
1262 s->cur_pic.ptr->f->repeat_pict = 4;
1264 s->cur_pic.ptr->f->repeat_pict = 2;
1265 }
else if (
s->progressive_frame) {
1266 s->cur_pic.ptr->f->repeat_pict = 1;
1307 if (!
s->cur_pic.ptr) {
1312 if (
s->avctx->hwaccel) {
1315 "hardware accelerator failed to decode first field\n");
1323 for (
int i = 0;
i < 3;
i++) {
1324 s->cur_pic.data[
i] =
s->cur_pic.ptr->f->data[
i];
1326 s->cur_pic.data[
i] +=
1327 s->cur_pic.ptr->f->linesize[
i];
1334 }
else if (
s->codec_tag ==
MKTAG(
'V',
'C',
'R',
'2')) {
1336 FFSWAP(uint8_t*,
s->cur_pic.data[1],
s->cur_pic.data[2]);
1337 FFSWAP(ptrdiff_t,
s->cur_pic.linesize[1],
s->cur_pic.linesize[2]);
1338 if (!second_field) {
1339 FFSWAP(uint8_t*,
s->next_pic.data[1],
s->next_pic.data[2]);
1340 FFSWAP(ptrdiff_t,
s->next_pic.linesize[1],
s->next_pic.linesize[2]);
1341 FFSWAP(uint8_t*,
s->last_pic.data[1],
s->last_pic.data[2]);
1342 FFSWAP(ptrdiff_t,
s->last_pic.linesize[1],
s->last_pic.linesize[2]);
1349 #define DECODE_SLICE_ERROR -1
1350 #define DECODE_SLICE_OK 0
1359 const uint8_t **buf,
int buf_size)
1362 const int lowres =
s->c.avctx->lowres;
1363 const int field_pic =
s->c.picture_structure !=
PICT_FRAME;
1367 s->c.resync_mb_y = -1;
1379 s->c.interlaced_dct = 0;
1383 if (
s->c.qscale == 0) {
1394 if (mb_y == 0 &&
s->c.codec_tag ==
AV_RL32(
"SLIF")) {
1415 if (
s->c.mb_x >= (
unsigned)
s->c.mb_width) {
1421 const uint8_t *buf_end, *buf_start = *buf - 4;
1424 if (buf_end < *buf + buf_size)
1433 s->c.resync_mb_x =
s->c.mb_x;
1434 s->c.resync_mb_y =
s->c.mb_y = mb_y;
1437 if (
s->c.mb_y == 0 &&
s->c.mb_x == 0 && (
s->c.first_field ||
s->c.picture_structure ==
PICT_FRAME)) {
1440 "qp:%d fc:%2d%2d%2d%2d %c %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
1442 s->c.mpeg_f_code[0][0],
s->c.mpeg_f_code[0][1],
1443 s->c.mpeg_f_code[1][0],
s->c.mpeg_f_code[1][1],
1447 s->c.progressive_sequence ?
"ps" :
"",
1448 s->c.progressive_frame ?
"pf" :
"",
1449 s->c.alternate_scan ?
"alt" :
"",
1450 s->c.top_field_first ?
"top" :
"",
1451 s->c.intra_dc_precision,
s->c.picture_structure,
1452 s->c.frame_pred_frame_dct,
s->c.concealment_motion_vectors,
1453 s->c.q_scale_type,
s->c.intra_vlc_format,
1454 s->c.repeat_first_field,
s->c.chroma_420_type ?
"420" :
"");
1458 for (
int mb_skip_run = 0;;) {
1464 if (
s->c.cur_pic.motion_val[0]) {
1465 const int wrap =
s->c.b8_stride;
1466 int xy =
s->c.mb_x * 2 +
s->c.mb_y * 2 *
wrap;
1467 int b8_xy = 4 * (
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride);
1468 int motion_x, motion_y, dir,
i;
1470 for (
i = 0;
i < 2;
i++) {
1471 for (dir = 0; dir < 2; dir++) {
1472 if (
s->c.mb_intra ||
1474 motion_x = motion_y = 0;
1477 motion_x =
s->c.mv[dir][0][0];
1478 motion_y =
s->c.mv[dir][0][1];
1480 motion_x =
s->c.mv[dir][
i][0];
1481 motion_y =
s->c.mv[dir][
i][1];
1484 s->c.cur_pic.motion_val[dir][xy][0] = motion_x;
1485 s->c.cur_pic.motion_val[dir][xy][1] = motion_y;
1486 s->c.cur_pic.motion_val[dir][xy + 1][0] = motion_x;
1487 s->c.cur_pic.motion_val[dir][xy + 1][1] = motion_y;
1488 s->c.cur_pic.ref_index [dir][b8_xy] =
1489 s->c.cur_pic.ref_index [dir][b8_xy + 1] =
s->c.field_select[dir][
i];
1491 s->c.field_select[dir][
i] == 1);
1499 s->c.dest[1] +=(16 >>
lowres) >>
s->c.chroma_x_shift;
1500 s->c.dest[2] +=(16 >>
lowres) >>
s->c.chroma_x_shift;
1504 if (++
s->c.mb_x >=
s->c.mb_width) {
1505 const int mb_size = 16 >>
s->c.avctx->lowres;
1511 s->c.mb_y += 1 << field_pic;
1513 if (
s->c.mb_y >=
s->c.mb_height) {
1518 s->c.intra_dc_precision == 2 &&
1519 s->c.q_scale_type == 1 &&
s->c.alternate_scan == 0 &&
1520 s->c.progressive_frame == 0
1523 if (
left >= 32 && !is_d10) {
1550 if (
s->c.mb_y >= ((
s->c.height + 15) >> 4) &&
1551 !
s->c.progressive_sequence &&
1554 mb_skip_run == -1 &&
1562 if (mb_skip_run == -1) {
1575 }
else if (
code == 35) {
1576 if (mb_skip_run != 0 ||
show_bits(&
s->gb, 15) != 0) {
1584 mb_skip_run +=
code;
1592 "skipped MB in I-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
1598 for (
i = 0;
i < 12;
i++)
1599 s->c.block_last_index[
i] = -1;
1600 s->c.last_dc[0] =
s->c.last_dc[1] =
s->c.last_dc[2] = 128 <<
s->c.intra_dc_precision;
1608 s->c.mv[0][0][0] =
s->c.mv[0][0][1] = 0;
1609 s->c.last_mv[0][0][0] =
s->c.last_mv[0][0][1] = 0;
1610 s->c.last_mv[0][1][0] =
s->c.last_mv[0][1][1] = 0;
1611 s->c.field_select[0][0] = (
s->c.picture_structure - 1) & 1;
1614 s->c.mv[0][0][0] =
s->c.last_mv[0][0][0];
1615 s->c.mv[0][0][1] =
s->c.last_mv[0][0][1];
1616 s->c.mv[1][0][0] =
s->c.last_mv[1][0][0];
1617 s->c.mv[1][0][1] =
s->c.last_mv[1][0][1];
1618 s->c.field_select[0][0] = (
s->c.picture_structure - 1) & 1;
1619 s->c.field_select[1][0] = (
s->c.picture_structure - 1) & 1;
1630 ff_dlog(
s->c.avctx,
"Slice start:%d %d end:%d %d\n",
s->c.resync_mb_x,
s->c.resync_mb_y,
s->c.mb_x,
s->c.mb_y);
1637 const uint8_t *buf =
s->gb.buffer;
1639 int mb_y =
s->c.start_mb_y;
1640 const int field_pic =
s->c.picture_structure !=
PICT_FRAME;
1642 s->c.er.error_count = (3 * (
s->c.end_mb_y -
s->c.start_mb_y) *
s->c.mb_width) >> field_pic;
1650 ff_dlog(
c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1651 ret,
s->c.resync_mb_x,
s->c.resync_mb_y,
s->c.mb_x,
s->c.mb_y,
1652 s->c.start_mb_y,
s->c.end_mb_y,
s->c.er.error_count);
1656 if (
s->c.resync_mb_x >= 0 &&
s->c.resync_mb_y >= 0)
1658 s->c.mb_x,
s->c.mb_y,
1662 s->c.mb_x - 1,
s->c.mb_y,
1666 if (
s->c.mb_y ==
s->c.end_mb_y)
1675 mb_y += (*buf&0xE0)<<2;
1679 if (mb_y >=
s->c.end_mb_y)
1693 if (!
s->context_initialized || !
s->cur_pic.ptr)
1696 if (
s->avctx->hwaccel) {
1700 "hardware accelerator failed to decode picture\n");
1722 if (
s->last_pic.ptr && !
s->last_pic.ptr->dummy) {
1739 const uint8_t *buf,
int buf_size)
1755 "Invalid horizontal or vertical size value.\n");
1772 if (
check_marker(
s->avctx, gb,
"in sequence header") == 0) {
1776 s->avctx->rc_buffer_size =
get_bits(gb, 10) * 1024 * 16;
1783 for (
i = 0;
i < 64;
i++) {
1784 j =
s->idsp.idct_permutation[
i];
1786 s->intra_matrix[j] = v;
1787 s->chroma_intra_matrix[j] = v;
1793 for (
i = 0;
i < 64;
i++) {
1794 int j =
s->idsp.idct_permutation[
i];
1796 s->inter_matrix[j] = v;
1797 s->chroma_inter_matrix[j] = v;
1810 s->progressive_sequence = 1;
1811 s->progressive_frame = 1;
1814 s->frame_pred_frame_dct = 1;
1822 av_log(
s->avctx,
AV_LOG_DEBUG,
"vbv buffer: %d, bitrate:%"PRId64
", aspect_ratio_info: %d \n",
1835 if (
s->context_initialized)
1847 if (!
s->avctx->lowres)
1848 for (
int i = 0;
i <
s->slice_context_count;
i++)
1851 for (
i = 0;
i < 64;
i++) {
1852 int j =
s->idsp.idct_permutation[
i];
1854 s->intra_matrix[j] = v;
1855 s->chroma_intra_matrix[j] = v;
1858 s->inter_matrix[j] = v;
1859 s->chroma_inter_matrix[j] = v;
1862 s->progressive_sequence = 1;
1863 s->progressive_frame = 1;
1866 s->frame_pred_frame_dct = 1;
1868 if (
s->codec_tag ==
AV_RL32(
"BW10")) {
1891 #if FF_API_CODEC_PROPS
1899 const uint8_t *p,
int buf_size)
1905 p[0] ==
'G' && p[1] ==
'A' && p[2] ==
'9' && p[3] ==
'4' &&
1906 p[4] == 3 && (p[5] & 0x40)) {
1908 int cc_count = p[5] & 0x1f;
1909 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
1911 const uint64_t new_size = (old_size + cc_count
1920 memcpy(s1->
a53_buf_ref->
data + old_size, p + 7, cc_count * UINT64_C(3));
1927 p[0] == 0x03 && (p[1]&0x7f) == 0x01) {
1939 const uint64_t new_size = (old_size + cc_count
1946 uint8_t
field, cc1, cc2;
1949 memset(cap, 0, cc_count * 3);
1959 cap[0] = cap[1] = cap[2] = 0x00;
1963 cap[0] = 0x04 |
field;
1976 p[0] ==
'C' && p[1] ==
'C' && p[2] == 0x01 && p[3] == 0xf8) {
2006 for (
i = 5;
i + 6 <= buf_size && ((p[
i] & 0xfe) == 0xfe);
i += 6)
2011 const uint64_t new_size = (old_size + cc_count
2018 uint8_t field1 = !!(p[4] & 0x80);
2021 for (
i = 0;
i < cc_count;
i++) {
2022 cap[0] = (p[0] == 0xff && field1) ? 0xfc : 0xfd;
2025 cap[3] = (p[3] == 0xff && !field1) ? 0xfc : 0xfd;
2038 p[0] == 0x05 && p[1] == 0x02) {
2040 const uint8_t cc_header = 0xf8 | 0x04 | 0x00 ;
2041 uint8_t cc_data[4] = {0};
2043 uint8_t cc_type = p[7];
2047 if (cc_type == 0x05 && buf_size >= 7) {
2053 if (cc_type == 0x02 && buf_size >= 4) {
2063 if (cc_type == 0x04 && (cc_data[0] & 0x7f) < 32) {
2065 cc_data[2] = cc_data[0];
2066 cc_data[3] = cc_data[1];
2068 }
else if (cc_type == 0x04 && buf_size >= 5) {
2079 const uint64_t new_size = (old_size + cc_count * UINT64_C(3));
2087 cap[1] = cc_data[0];
2088 cap[2] = cc_data[1];
2089 if (cc_count == 2) {
2091 cap[4] = cc_data[2];
2092 cap[5] = cc_data[3];
2104 const uint8_t *p,
int buf_size)
2106 const uint8_t *buf_end = p + buf_size;
2111 for(
i=0; !(!p[
i-2] && !p[
i-1] && p[
i]==1) &&
i<buf_size;
i++){
2120 if (!memcmp(p+
i,
"\0TMPGEXS\0", 9)){
2125 if (buf_end - p >= 5 &&
2126 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2134 if (buf_end - p < 1)
2137 s1->
afd = p[0] & 0x0f;
2139 }
else if (buf_end - p >= 6 &&
2140 p[0] ==
'J' && p[1] ==
'P' && p[2] ==
'3' && p[3] ==
'D' &&
2143 const uint8_t S3D_video_format_type = p[5] & 0x7F;
2145 if (S3D_video_format_type == 0x03 ||
2146 S3D_video_format_type == 0x04 ||
2147 S3D_video_format_type == 0x08 ||
2148 S3D_video_format_type == 0x23) {
2152 switch (S3D_video_format_type) {
2173 const uint8_t *buf,
int buf_size)
2197 "GOP (%s) closed_gop=%d broken_link=%d\n",
2210 int error_count = 0;
2216 for (
int i = 0;
i <
s->slice_count;
i++) {
2219 memory_order_relaxed);
2222 if ((
unsigned)slice_err > INT_MAX - error_count) {
2223 error_count = INT_MAX;
2226 error_count += slice_err;
2229 memory_order_relaxed);
2234 int *got_output,
const uint8_t *buf,
int buf_size)
2238 const uint8_t *buf_ptr = buf;
2239 const uint8_t *buf_end = buf + buf_size;
2240 int ret, input_size;
2241 int last_code = 0, skip_frame = 0;
2242 int picture_start_code_seen = 0;
2261 return FFMAX(0, buf_ptr - buf);
2264 input_size = buf_end - buf_ptr;
2273 if (last_code == 0) {
2279 "ignoring SEQ_START_CODE after %X\n", last_code);
2292 picture_start_code_seen = 1;
2309 if (
s->slice_count) {
2317 "mpeg_decode_postinit() failure\n");
2328 "ignoring pic after %X\n", last_code);
2342 if (last_code == 0) {
2346 "ignoring seq ext after %X\n", last_code);
2367 "ignoring pic cod ext after %X\n", last_code);
2379 if (last_code == 0) {
2387 "ignoring GOP_START_CODE after %X\n", last_code);
2398 "interlaced frame in progressive sequence, ignoring\n");
2404 "picture_structure %d invalid, ignoring\n",
2427 mb_y += (*buf_ptr&0xE0)<<2;
2433 if (buf_end - buf_ptr < 2) {
2440 "slice below image (%d >= %d)\n", mb_y, s2->
mb_height);
2448 if (!
s->closed_gop) {
2451 "Skipping B slice due to open GOP\n");
2464 "Skipping P slice due to !sync\n");
2481 if (mb_y < avctx->skip_top ||
2493 if (
s->first_slice) {
2501 "current_picture not initialized\n");
2508 int threshold = (s2->
mb_height *
s->slice_count +
2511 if (threshold <= mb_y) {
2516 if (
s->slice_count) {
2554 const uint8_t *buf = avpkt->
data;
2556 int buf_size = avpkt->
size;
2580 if (avctx->
extradata && !
s->extradata_decoded) {
2588 s->extradata_decoded = 1;
2596 if (
ret<0 || *got_output) {
2599 if (
s->timecode_frame_start != -1 && *got_output) {
2606 memcpy(tcside->
data, &
s->timecode_frame_start,
sizeof(
int64_t));
2611 s->timecode_frame_start = -1;
2638 .
p.
name =
"mpeg1video",
2652 #if CONFIG_MPEG1_NVDEC_HWACCEL
2655 #if CONFIG_MPEG1_VDPAU_HWACCEL
2658 #if CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL
2665 #define M2V_OFFSET(x) offsetof(Mpeg1Context, x)
2666 #define M2V_PARAM AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2669 {
"cc_format",
"extract a specific Closed Captions format",
2695 .
p.
name =
"mpeg2video",
2711 #if CONFIG_MPEG2_DXVA2_HWACCEL
2714 #if CONFIG_MPEG2_D3D11VA_HWACCEL
2717 #if CONFIG_MPEG2_D3D11VA2_HWACCEL
2720 #if CONFIG_MPEG2_D3D12VA_HWACCEL
2723 #if CONFIG_MPEG2_NVDEC_HWACCEL
2726 #if CONFIG_MPEG2_VAAPI_HWACCEL
2729 #if CONFIG_MPEG2_VDPAU_HWACCEL
2732 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
2741 .
p.
name =
"mpegvideo",
2768 int16_t (*
const block)[64] =
s->m.block;
2772 if (avpkt->
size*8LL < (avctx->
width+15)/16 * ((avctx->
height+15)/16) * (2LL + 3*4 + 2*2 + 2*6))
2796 for (
int y = 0; y < avctx->
height; y += 16) {
2799 for (
int x = 0; x < avctx->
width; x += 16) {
2820 for (
int n = 0; n < 6; n++) {
2821 if (
s->flags & 0x80) {
2870 for (
int i = 0;
i < 64;
i++) {
static int vcr2_init_sequence(AVCodecContext *avctx)
#define HWACCEL_D3D12VA(codec)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define MV_TYPE_16X16
1 vector for the whole mb
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_TIMECODE_STR_SIZE
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
VLCElem ff_mb_pat_vlc[512]
#define AV_EF_EXPLODE
abort decoding on minor error detection
AVBufferRef * a53_buf_ref
const AVRational ff_mpeg2_aspect[16]
int16_t position[3][2]
position of the top left corner in 1/16 pel for up to 3 fields/frames
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int mpeg_decode_a53_cc(AVCodecContext *avctx, const uint8_t *p, int buf_size)
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int decode_slice(AVCodecContext *c, void *arg)
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
@ AV_CLASS_CATEGORY_DECODER
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
#define FF_MPV_QSCALE_TYPE_MPEG2
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_output, AVPacket *avpkt)
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
#define check_scantable_index(ctx, x)
uint8_t * data
The data buffer.
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
#define MV_TYPE_16X8
2 vectors, one per 16x8 block
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define SLICE_MAX_START_CODE
static int get_bits_count(const GetBitContext *s)
static av_cold int ipu_decode_init(AVCodecContext *avctx)
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
This structure describes decoded (raw) audio or video data.
#define HWACCEL_DXVA2(codec)
const FFCodec ff_mpegvideo_decoder
#define HWACCEL_D3D11VA2(codec)
const uint8_t ff_reverse[256]
int last_dc[3]
last DC values for MPEG-1
static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
static void ff_mpv_framesize_disable(ScratchpadContext *sc)
Disable allocating the ScratchpadContext's buffers in future calls to ff_mpv_framesize_alloc().
#define PICT_BOTTOM_FIELD
#define FF_HW_SIMPLE_CALL(avctx, function)
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)
struct AVCodecContext * avctx
#define UPDATE_CACHE(name, gb)
static int mpeg_decode_postinit(AVCodecContext *avctx)
int height
picture size. must be a multiple of 16
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static void mpeg_decode_quant_matrix_extension(MPVContext *const s, GetBitContext *const gb)
#define FF_DEBUG_PICT_INFO
#define MV_TYPE_DMV
2 vectors, special mpeg2 Dual Prime Vectors
enum OutputFormat out_format
output format
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define GET_CACHE(name, gb)
static void skip_bits(GetBitContext *s, int n)
RL_VLC_ELEM ff_mpeg2_rl_vlc[674]
ScanTable intra_scantable
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
static av_cold void close(AVCodecParserContext *s)
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
int mb_height
number of MBs horizontally & vertically
VLCElem ff_mbincr_vlc[538]
AVCodec p
The public AVCodec.
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int *got_output, const uint8_t *buf, int buf_size)
enum AVDiscard skip_frame
Skip decoding for selected frames.
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
#define AV_EF_BITSTREAM
detect bitstream specification deviations
int width
width and height in 1/16 pel
static int slice_decode_thread(AVCodecContext *c, void *arg)
int flags
AV_CODEC_FLAG_*.
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
static double val(void *priv, double ch)
#define HWACCEL_VDPAU(codec)
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
static enum AVPixelFormat mpeg12_pixfmt_list_444[]
static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y, const uint8_t **buf, int buf_size)
Decode a slice.
static int mpeg1_decode_sequence(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static void mpeg_decode_sequence_display_extension(Mpeg1Context *const s1, GetBitContext *const gb)
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
static enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[]
unsigned slice_ctx_size
If set, ff_mpv_common_init() will allocate slice contexts of this size.
const FFCodec ff_mpeg2video_decoder
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
unsigned frame_rate_index
static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[]
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define CLOSE_READER(name, gb)
int has_b_frames
Size of the frame reordering buffer in the decoder.
enum AVStereo3DType stereo3d_type
void ff_er_frame_end(ERContext *s, int *decode_error_flags)
Indicate that a frame has finished decoding and perform error concealment in case it has been enabled...
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
#define FF_CODEC_DECODE_CB(func)
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
MPVPicture * ptr
RefStruct reference.
const float ff_mpeg1_aspect[16]
#define SHOW_SBITS(name, gb, num)
void ff_mpeg_er_frame_start(MpegEncContext *s)
static av_cold void flush(AVCodecContext *avctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
unsigned aspect_ratio_info
static enum AVPixelFormat pix_fmts[]
static int get_sbits(GetBitContext *s, int n)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s, int16_t *block, int n)
static enum AVPixelFormat mpeg12_pixfmt_list_422[]
#define SKIP_BITS(name, gb, num)
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 field
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int64_t rc_max_rate
maximum bitrate
MPVWorkPicture cur_pic
copy of the current picture structure.
#define CODEC_LONG_NAME(str)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
static const VLCElem * rl_vlc[2]
av_cold void ff_mpv_common_end(MpegEncContext *s)
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
void ff_mpv_unref_picture(MPVWorkPicture *pic)
int low_delay
no reordering needed / has no B-frames
@ AVDISCARD_ALL
discard all
#define MB_PTYPE_VLC_BITS
#define LIBAVUTIL_VERSION_INT
struct Mpeg12SliceContext * mpeg12_contexts[MAX_THREADS]
Describe the class of an AVClass context structure.
#define PTRDIFF_SPECIFIER
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define SLICE_MIN_START_CODE
static void mpeg12_execute_slice_threads(AVCodecContext *avctx, Mpeg1Context *const s)
MPVWorkPicture next_pic
copy of the next picture structure.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Rational number (pair of numerator and denominator).
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static unsigned int get_bits1(GetBitContext *s)
static int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
#define FF_PTR_ADD(ptr, off)
#define LAST_SKIP_BITS(name, gb, num)
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
RL_VLC_ELEM ff_mpeg1_rl_vlc[680]
#define MB_BTYPE_VLC_BITS
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int slice_context_count
number of used thread_contexts
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
int level
Encoding level descriptor.
#define atomic_load_explicit(object, order)
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_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
int ff_mpv_alloc_dummy_frames(MpegEncContext *s)
Ensure that the dummy frames are allocated according to pict_type if necessary.
@ AVDISCARD_NONKEY
discard all frames except keyframes
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
int flags2
AV_CODEC_FLAG2_*.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
static const AVOption mpeg2video_options[]
#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.
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int shift(int a, int b)
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size)
void ff_mpeg1_clean_buffers(MpegEncContext *s)
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
const FFCodec ff_mpeg1video_decoder
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#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...
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
#define PICTURE_START_CODE
int skip_bottom
Number of macroblock rows at the bottom which are skipped.
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for B-frame encodin...
const uint16_t ff_mpeg1_default_intra_matrix[256]
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
#define MB_TYPE_INTERLACED
#define OPEN_READER(name, gb)
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define HWACCEL_D3D11VA(codec)
int ff_mpeg1_decode_block_intra(GetBitContext *gb, const uint16_t *quant_matrix, const uint8_t *scantable, int last_dc[3], int16_t *block, int index, int qscale)
#define MV_TYPE_FIELD
2 vectors, one per field
static void skip_bits1(GetBitContext *s)
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
#define HWACCEL_NVDEC(codec)
static const AVClass mpeg2video_class
static void mpeg_decode_sequence_extension(Mpeg1Context *const s1, GetBitContext *const gb)
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
size_t size
Size of data in bytes.
const AVProfile ff_mpeg2_video_profiles[]
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#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
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
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.
static void mpeg_set_cc_format(AVCodecContext *avctx, enum Mpeg2ClosedCaptionsFormat format, const char *label)
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
av_cold void ff_mpeg12_init_vlcs(void)
#define atomic_store_explicit(object, desired, order)
#define FF_DEBUG_STARTCODE
struct MpegEncContext * thread_context[MAX_THREADS]
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
#define MB_TYPE_MV_2_MV_DIR(a)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Name of the codec implementation.
MPVWorkPicture last_pic
copy of the previous picture structure.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
static int mpeg_decode_motion(Mpeg12SliceContext *const s, int fcode, int pred)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define HWACCEL_VIDEOTOOLBOX(codec)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
const uint8_t ff_zigzag_direct[64]
const AVRational ff_mpeg12_frame_rate_tab[]
static int mpeg_decode_gop(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
static const float pred[4]
@ AV_FRAME_DATA_GOP_TIMECODE
The GOP timecode in 25 bit timecode format.
#define FFSWAP(type, a, b)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
enum AVStereo3DType type
How views are packed within the video.
static const uint8_t * align_get_bits(GetBitContext *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
static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static int mpeg1_decode_block_inter(Mpeg12SliceContext *const s, int16_t *block, int n)
static int skip_1stop_8data_bits(GetBitContext *gb)
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
char * av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
Get the timecode string from the 25-bit timecode format (MPEG GOP format).
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
#define SHOW_UBITS(name, gb, num)
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
#define FF_HW_CALL(avctx, function,...)
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVDictionary * metadata
metadata.
enum Mpeg2ClosedCaptionsFormat cc_format
static av_const int sign_extend(int val, unsigned bits)
void ff_mpv_frame_end(MpegEncContext *s)
static int ref[MAX_W *MAX_W]
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int resync_mb_x
x position of last resync marker
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
VLCElem ff_mb_ptype_vlc[64]
#define FF_DISABLE_DEPRECATION_WARNINGS
int coded_width
Bitstream width / height, may be different from width/height e.g.
@ AV_PICTURE_TYPE_P
Predicted.
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
A reference to a data buffer.
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
uint8_t idct_permutation[64]
IDCT input permutation.
const FFCodec ff_ipu_decoder
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Structure to hold side data for an AVFrame.
static int load_matrix(MPVContext *const s, GetBitContext *const gb, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
int first_field
is 1 for the first field of a field picture 0 otherwise
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
DECLARE_ALIGNED_32(int16_t, block)[12][64]
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int mpeg_decode_picture_coding_extension(Mpeg1Context *const s1, GetBitContext *const gb)
#define HWACCEL_VAAPI(codec)
int width
picture width / height.
static void mpeg_decode_picture_display_extension(Mpeg1Context *const s1, GetBitContext *const gb)
attribute_deprecated unsigned properties
Properties of the stream that gets decoded.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
AVStereo3DType
List of possible 3D Types.
static int mpeg2_decode_block_intra(Mpeg12SliceContext *const s, int16_t *block, int n)
The exact code depends on how similar the blocks are and how related they are to the block
AVRational frame_rate_ext
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
VLCElem ff_mb_btype_vlc[64]
int resync_mb_y
y position of last resync marker
static void mpeg_decode_user_data(AVCodecContext *avctx, const uint8_t *p, int buf_size)
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
Mpeg2ClosedCaptionsFormat
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
int64_t timecode_frame_start
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
@ AVDISCARD_NONREF
discard all non reference
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define DECODE_SLICE_ERROR
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
#define MB_TYPE_FORWARD_MV
static int decode_dc(GetBitContext *gb, int component)
uint16_t chroma_intra_matrix[64]
static int get_dmv(Mpeg12SliceContext *const s)
int codec_tag
internal codec_tag upper case converted from avctx codec_tag