28 #define UNCHECKED_BITSTREAM_READER 1
55 #define A53_MAX_CC_COUNT 2000
78 #define MB_TYPE_ZERO_MV 0x20000000
131 #define MAX_INDEX (64 - 1)
132 #define check_scantable_index(ctx, x) \
134 if ((x) > MAX_INDEX) { \
135 av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
136 ctx->mb_x, ctx->mb_y); \
137 return AVERROR_INVALIDDATA; \
142 int16_t *
block,
int n)
146 uint8_t *
const scantable =
s->intra_scantable.permutated;
147 const uint16_t *quant_matrix =
s->inter_matrix;
148 const int qscale =
s->qscale;
156 level = (3 * qscale * quant_matrix[0]) >> 5;
176 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
191 }
else if (
level == 0) {
201 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
205 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
222 s->block_last_index[n] =
i;
231 int16_t *
block,
int n)
235 uint8_t *
const scantable =
s->intra_scantable.permutated;
236 const int qscale =
s->qscale;
244 level = (3 * qscale) >> 1;
280 }
else if (
level == 0) {
311 s->block_last_index[n] =
i;
316 int16_t *
block,
int n)
320 uint8_t *
const scantable =
s->intra_scantable.permutated;
321 const uint16_t *quant_matrix;
322 const int qscale =
s->qscale;
331 quant_matrix =
s->inter_matrix;
333 quant_matrix =
s->chroma_inter_matrix;
338 level = (3 * qscale * quant_matrix[0]) >> 5;
359 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
376 level = ((-
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
379 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
393 block[63] ^= (mismatch & 1);
397 s->block_last_index[n] =
i;
406 int16_t *
block,
int n)
410 uint8_t *
const scantable =
s->intra_scantable.permutated;
411 const int qscale =
s->qscale;
418 level = (3 * qscale) >> 1;
473 s->block_last_index[n] =
i;
478 int16_t *
block,
int n)
483 uint8_t *
const scantable =
s->intra_scantable.permutated;
484 const uint16_t *quant_matrix;
485 const int qscale =
s->qscale;
490 quant_matrix =
s->intra_matrix;
493 quant_matrix =
s->chroma_intra_matrix;
494 component = (n & 1) + 1;
497 dc =
s->last_dc[component];
499 s->last_dc[component] =
dc;
500 block[0] =
dc * (1 << (3 -
s->intra_dc_precision));
502 mismatch =
block[0] ^ 1;
504 if (
s->intra_vlc_format)
519 }
else if (
level != 0) {
524 level = (
level * qscale * quant_matrix[j]) >> 4;
539 level = (-
level * qscale * quant_matrix[j]) >> 4;
542 level = (
level * qscale * quant_matrix[j]) >> 4;
551 block[63] ^= mismatch & 1;
555 s->block_last_index[n] =
i;
564 int16_t *
block,
int n)
569 uint8_t *
const scantable =
s->intra_scantable.permutated;
570 const uint16_t *quant_matrix;
571 const int qscale =
s->qscale;
575 quant_matrix =
s->intra_matrix;
578 quant_matrix =
s->chroma_intra_matrix;
579 component = (n & 1) + 1;
582 dc =
s->last_dc[component];
584 s->last_dc[component] =
dc;
585 block[0] =
dc * (1 << (3 -
s->intra_dc_precision));
587 if (
s->intra_vlc_format)
600 if (
level >= 64 ||
i > 63) {
602 }
else if (
level != 0) {
605 level = (
level * qscale * quant_matrix[j]) >> 4;
618 level = (-
level * qscale * quant_matrix[j]) >> 4;
621 level = (
level * qscale * quant_matrix[j]) >> 4;
632 s->block_last_index[n] =
i;
655 int i, j, k, cbp,
val, mb_type, motion_type;
656 const int mb_block_count = 4 + (1 <<
s->chroma_format);
659 ff_tlog(
s->avctx,
"decode_mb: x=%d y=%d\n",
s->mb_x,
s->mb_y);
663 if (
s->mb_skip_run-- != 0) {
666 s->current_picture.mb_type[
s->mb_x +
s->mb_y *
s->mb_stride] =
672 mb_type =
s->current_picture.mb_type[
s->mb_x +
s->mb_y *
s->mb_stride - 1];
675 mb_type =
s->current_picture.mb_type[
s->mb_width + (
s->mb_y - 1) *
s->mb_stride - 1];
680 s->current_picture.mb_type[
s->mb_x +
s->mb_y *
s->mb_stride] =
683 if ((
s->mv[0][0][0] |
s->mv[0][0][1] |
s->mv[1][0][0] |
s->mv[1][0][1]) == 0)
690 switch (
s->pict_type) {
696 "Invalid mb type in I-frame at %d %d\n",
709 "Invalid mb type in P-frame at %d %d\n",
s->mb_x,
s->mb_y);
718 "Invalid mb type in B-frame at %d %d\n",
s->mb_x,
s->mb_y);
724 ff_tlog(
s->avctx,
"mb_type=%x\n", mb_type);
727 s->bdsp.clear_blocks(
s->block[0]);
729 if (!
s->chroma_y_shift)
730 s->bdsp.clear_blocks(
s->block[6]);
735 !
s->frame_pred_frame_dct)
741 if (
s->concealment_motion_vectors) {
747 s->last_mv[0][0][0] =
749 s->last_mv[0][0][0]);
751 s->last_mv[0][0][1] =
753 s->last_mv[0][0][1]);
755 check_marker(
s->avctx, &
s->gb,
"after concealment_motion_vectors");
758 memset(
s->last_mv, 0,
sizeof(
s->last_mv));
767 for (
i = 0;
i < 6;
i++)
770 for (
i = 0;
i < mb_block_count;
i++)
775 for (
i = 0;
i < 6;
i++) {
778 s->intra_scantable.permutated,
779 s->last_dc, *
s->pblocks[
i],
787 s->block_last_index[
i] = ret;
797 && !
s->frame_pred_frame_dct)
803 s->field_select[0][0] =
s->picture_structure - 1;
809 s->last_mv[0][0][0] = 0;
810 s->last_mv[0][0][1] = 0;
811 s->last_mv[0][1][0] = 0;
812 s->last_mv[0][1][1] = 0;
819 if (
s->picture_structure ==
PICT_FRAME &&
s->frame_pred_frame_dct) {
831 s->mv_dir = (mb_type >> 13) & 3;
832 ff_tlog(
s->avctx,
"motion_type=%d\n", motion_type);
833 switch (motion_type) {
838 for (
i = 0;
i < 2;
i++) {
842 s->last_mv[
i][0][0] =
843 s->last_mv[
i][1][0] =
845 s->last_mv[
i][0][0]);
847 s->last_mv[
i][0][1] =
848 s->last_mv[
i][1][1] =
850 s->last_mv[
i][0][1]);
852 if (
s->full_pel[
i]) {
861 for (
i = 0;
i < 2;
i++) {
864 for (j = 0; j < 2; j++) {
866 for (k = 0; k < 2; k++) {
868 s->last_mv[
i][j][k]);
869 s->last_mv[
i][j][k] =
val;
870 s->mv[
i][j][k] =
val;
881 for (
i = 0;
i < 2;
i++) {
883 for (j = 0; j < 2; j++) {
886 s->last_mv[
i][j][0]);
887 s->last_mv[
i][j][0] =
val;
888 s->mv[
i][j][0] =
val;
891 s->last_mv[
i][j][1] >> 1);
892 s->last_mv[
i][j][1] = 2 *
val;
893 s->mv[
i][j][1] =
val;
901 for (
i = 0;
i < 2;
i++) {
904 for (k = 0; k < 2; k++) {
906 s->last_mv[
i][0][k]);
907 s->last_mv[
i][0][k] =
val;
908 s->last_mv[
i][1][k] =
val;
909 s->mv[
i][0][k] =
val;
916 if (
s->progressive_sequence){
921 for (
i = 0;
i < 2;
i++) {
923 int dmx, dmy, mx, my, m;
924 const int my_shift =
s->picture_structure ==
PICT_FRAME;
927 s->last_mv[
i][0][0]);
928 s->last_mv[
i][0][0] = mx;
929 s->last_mv[
i][1][0] = mx;
932 s->last_mv[
i][0][1] >> my_shift);
936 s->last_mv[
i][0][1] = my * (1 << my_shift);
937 s->last_mv[
i][1][1] = my * (1 << my_shift);
948 m =
s->top_field_first ? 1 : 3;
951 s->mv[
i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
952 s->mv[
i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
954 s->mv[
i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
955 s->mv[
i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
959 s->mv[
i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
960 s->mv[
i][2][1] = ((my + (my > 0)) >> 1) + dmy;
971 "00 motion_type at %d %d\n",
s->mb_x,
s->mb_y);
978 s->bdsp.clear_blocks(
s->block[0]);
981 if (mb_block_count > 6) {
982 cbp *= 1 << mb_block_count - 6;
983 cbp |=
get_bits(&
s->gb, mb_block_count - 6);
984 s->bdsp.clear_blocks(
s->block[6]);
988 "invalid cbp %d at %d %d\n", cbp,
s->mb_x,
s->mb_y);
998 for (
i = 0;
i < 6;
i++) {
1002 s->block_last_index[
i] = -1;
1006 cbp <<= 12 - mb_block_count;
1008 for (
i = 0;
i < mb_block_count;
i++) {
1009 if (cbp & (1 << 11)) {
1013 s->block_last_index[
i] = -1;
1020 for (
i = 0;
i < 6;
i++) {
1024 s->block_last_index[
i] = -1;
1028 for (
i = 0;
i < 6;
i++) {
1033 s->block_last_index[
i] = -1;
1040 for (
i = 0;
i < 12;
i++)
1041 s->block_last_index[
i] = -1;
1045 s->current_picture.mb_type[
s->mb_x +
s->mb_y *
s->mb_stride] = mb_type;
1066 s2->chroma_format = 1;
1067 s->mpeg_enc_ctx_allocated = 0;
1068 s->mpeg_enc_ctx.picture_number = 0;
1069 s->repeat_field = 0;
1070 s->mpeg_enc_ctx.codec_id = avctx->
codec->
id;
1076 static int mpeg_decode_update_thread_context(
AVCodecContext *avctx,
1083 if (avctx == avctx_from ||
1084 !ctx_from->mpeg_enc_ctx_allocated ||
1085 !
s1->context_initialized)
1092 if (!
ctx->mpeg_enc_ctx_allocated)
1096 s->picture_number++;
1105 uint16_t temp_matrix[64];
1108 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1110 for (
i = 0;
i < 64;
i++)
1111 matrix[new_perm[
i]] = temp_matrix[old_perm[
i]];
1115 #if CONFIG_MPEG1_NVDEC_HWACCEL
1118 #if CONFIG_MPEG1_XVMC_HWACCEL
1121 #if CONFIG_MPEG1_VDPAU_HWACCEL
1129 #if CONFIG_MPEG2_NVDEC_HWACCEL
1132 #if CONFIG_MPEG2_XVMC_HWACCEL
1135 #if CONFIG_MPEG2_VDPAU_HWACCEL
1138 #if CONFIG_MPEG2_DXVA2_HWACCEL
1141 #if CONFIG_MPEG2_D3D11VA_HWACCEL
1145 #if CONFIG_MPEG2_VAAPI_HWACCEL
1148 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
1174 if (
s->chroma_format < 2)
1178 else if (
s->chroma_format == 2)
1197 s->pack_pblocks = 1;
1216 if (
s->aspect_ratio_info > 1) {
1220 s1->pan_scan.height }),
1227 if ((
s1->pan_scan.width == 0) || (
s1->pan_scan.height == 0) ||
1230 s->avctx->sample_aspect_ratio =
1234 s->avctx->sample_aspect_ratio =
1236 (
AVRational) { s1->pan_scan.width, s1->pan_scan.height });
1241 ff_dlog(avctx,
"aspect A %d/%d\n",
1244 ff_dlog(avctx,
"aspect B %d/%d\n",
s->avctx->sample_aspect_ratio.num,
1245 s->avctx->sample_aspect_ratio.den);
1248 s->avctx->sample_aspect_ratio =
1261 if ((
s1->mpeg_enc_ctx_allocated == 0) ||
1264 s1->save_width !=
s->width ||
1265 s1->save_height !=
s->height ||
1266 av_cmp_q(
s1->save_aspect,
s->avctx->sample_aspect_ratio) ||
1267 (
s1->save_progressive_seq !=
s->progressive_sequence &&
FFALIGN(
s->height, 16) !=
FFALIGN(
s->height, 32)) ||
1269 if (
s1->mpeg_enc_ctx_allocated) {
1271 s->parse_context.buffer = 0;
1273 s->parse_context = pc;
1274 s1->mpeg_enc_ctx_allocated = 0;
1284 (
s->bit_rate != 0x3FFFF*400 ||
s->vbv_delay != 0xFFFF)) {
1287 s1->save_aspect =
s->avctx->sample_aspect_ratio;
1288 s1->save_width =
s->width;
1289 s1->save_height =
s->height;
1290 s1->save_progressive_seq =
s->progressive_sequence;
1305 &
s->avctx->framerate.den,
1311 switch (
s->chroma_format) {
1324 memcpy(old_permutation,
s->idsp.idct_permutation, 64 *
sizeof(
uint8_t));
1335 s1->mpeg_enc_ctx_allocated = 1;
1345 int ref, f_code, vbv_delay;
1351 if (
s->pict_type == 0 ||
s->pict_type > 3)
1355 s->vbv_delay = vbv_delay;
1363 s->mpeg_f_code[0][0] = f_code;
1364 s->mpeg_f_code[0][1] = f_code;
1372 s->mpeg_f_code[1][0] = f_code;
1373 s->mpeg_f_code[1][1] = f_code;
1375 s->current_picture.f->pict_type =
s->pict_type;
1380 "vbv_delay %d, ref %d type:%d\n", vbv_delay,
ref,
s->pict_type);
1390 int horiz_size_ext, vert_size_ext;
1400 if (!
s->chroma_format) {
1401 s->chroma_format = 1;
1407 s->width |= (horiz_size_ext << 12);
1408 s->height |= (vert_size_ext << 12);
1410 s->bit_rate += (bit_rate_ext << 18) * 400LL;
1412 s1->rc_buffer_size +=
get_bits(&
s->gb, 8) * 1024 * 16 << 10;
1421 ff_dlog(
s->avctx,
"sequence extension\n");
1426 if (
s->bit_rate != 0x3FFFF*400)
1432 "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64
"\n",
1433 s->avctx->profile,
s->avctx->level,
s->progressive_sequence,
s->chroma_format,
1434 s1->rc_buffer_size,
s->bit_rate);
1440 int color_description,
w,
h;
1444 if (color_description) {
1445 s->avctx->color_primaries =
get_bits(&
s->gb, 8);
1454 s1->pan_scan.width = 16 *
w;
1455 s1->pan_scan.height = 16 *
h;
1467 if (
s->progressive_sequence) {
1468 if (
s->repeat_first_field) {
1470 if (
s->top_field_first)
1476 if (
s->repeat_first_field)
1480 for (
i = 0;
i < nofco;
i++) {
1489 "pde (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
")\n",
1490 s1->pan_scan.position[0][0],
s1->pan_scan.position[0][1],
1491 s1->pan_scan.position[1][0],
s1->pan_scan.position[1][1],
1492 s1->pan_scan.position[2][0],
s1->pan_scan.position[2][1]);
1496 uint16_t matrix1[64],
int intra)
1500 for (
i = 0;
i < 64;
i++) {
1507 if (intra &&
i == 0 && v != 8) {
1508 av_log(
s->avctx,
AV_LOG_DEBUG,
"intra matrix specifies invalid DC quantizer %d, ignoring\n", v);
1520 ff_dlog(
s->avctx,
"matrix extension\n");
1536 s->full_pel[0] =
s->full_pel[1] = 0;
1541 if (!
s->pict_type &&
s1->mpeg_enc_ctx_allocated) {
1543 "Missing picture start code, guessing missing values\n");
1544 if (
s->mpeg_f_code[1][0] == 15 &&
s->mpeg_f_code[1][1] == 15) {
1545 if (
s->mpeg_f_code[0][0] == 15 &&
s->mpeg_f_code[0][1] == 15)
1551 s->current_picture.f->pict_type =
s->pict_type;
1554 s->mpeg_f_code[0][0] += !
s->mpeg_f_code[0][0];
1555 s->mpeg_f_code[0][1] += !
s->mpeg_f_code[0][1];
1556 s->mpeg_f_code[1][0] += !
s->mpeg_f_code[1][0];
1557 s->mpeg_f_code[1][1] += !
s->mpeg_f_code[1][1];
1563 s->concealment_motion_vectors =
get_bits1(&
s->gb);
1571 if (
s->alternate_scan) {
1580 ff_dlog(
s->avctx,
"intra_dc_precision=%d\n",
s->intra_dc_precision);
1581 ff_dlog(
s->avctx,
"picture_structure=%d\n",
s->picture_structure);
1582 ff_dlog(
s->avctx,
"top field first=%d\n",
s->top_field_first);
1583 ff_dlog(
s->avctx,
"repeat first field=%d\n",
s->repeat_first_field);
1584 ff_dlog(
s->avctx,
"conceal=%d\n",
s->concealment_motion_vectors);
1585 ff_dlog(
s->avctx,
"intra_vlc_format=%d\n",
s->intra_vlc_format);
1586 ff_dlog(
s->avctx,
"alternate_scan=%d\n",
s->alternate_scan);
1587 ff_dlog(
s->avctx,
"frame_pred_frame_dct=%d\n",
s->frame_pred_frame_dct);
1588 ff_dlog(
s->avctx,
"progressive_frame=%d\n",
s->progressive_frame);
1598 if (
s->mb_width *
s->mb_height * 11LL / (33 * 2 * 8) > buf_size)
1603 if (
s->first_field ||
s->picture_structure ==
PICT_FRAME) {
1612 s->current_picture_ptr->f->repeat_pict = 0;
1613 if (
s->repeat_first_field) {
1614 if (
s->progressive_sequence) {
1615 if (
s->top_field_first)
1616 s->current_picture_ptr->f->repeat_pict = 4;
1618 s->current_picture_ptr->f->repeat_pict = 2;
1619 }
else if (
s->progressive_frame) {
1620 s->current_picture_ptr->f->repeat_pict = 1;
1626 sizeof(
s1->pan_scan));
1629 memcpy(pan_scan->
data, &
s1->pan_scan,
sizeof(
s1->pan_scan));
1631 if (
s1->a53_buf_ref) {
1640 if (
s1->has_stereo3d) {
1645 *stereo =
s1->stereo3d;
1646 s1->has_stereo3d = 0;
1665 if (!
s->current_picture_ptr) {
1670 if (
s->avctx->hwaccel) {
1671 if ((ret =
s->avctx->hwaccel->end_frame(
s->avctx)) < 0) {
1673 "hardware accelerator failed to decode first field\n");
1678 for (
i = 0;
i < 4;
i++) {
1679 s->current_picture.f->data[
i] =
s->current_picture_ptr->f->data[
i];
1681 s->current_picture.f->data[
i] +=
1682 s->current_picture_ptr->f->linesize[
i];
1694 #define DECODE_SLICE_ERROR -1
1695 #define DECODE_SLICE_OK 0
1704 const uint8_t **buf,
int buf_size)
1707 const int lowres =
s->avctx->lowres;
1708 const int field_pic =
s->picture_structure !=
PICT_FRAME;
1712 s->resync_mb_y = -1;
1721 s->interlaced_dct = 0;
1725 if (
s->qscale == 0) {
1736 if (mb_y == 0 &&
s->codec_tag ==
AV_RL32(
"SLIF")) {
1757 if (
s->mb_x >= (
unsigned)
s->mb_width) {
1763 const uint8_t *buf_end, *buf_start = *buf - 4;
1766 if (buf_end < *buf + buf_size)
1775 s->resync_mb_x =
s->mb_x;
1776 s->resync_mb_y =
s->mb_y = mb_y;
1780 if (
s->mb_y == 0 &&
s->mb_x == 0 && (
s->first_field ||
s->picture_structure ==
PICT_FRAME)) {
1783 "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
1785 s->mpeg_f_code[0][0],
s->mpeg_f_code[0][1],
1786 s->mpeg_f_code[1][0],
s->mpeg_f_code[1][1],
1790 s->progressive_sequence ?
"ps" :
"",
1791 s->progressive_frame ?
"pf" :
"",
1792 s->alternate_scan ?
"alt" :
"",
1793 s->top_field_first ?
"top" :
"",
1794 s->intra_dc_precision,
s->picture_structure,
1795 s->frame_pred_frame_dct,
s->concealment_motion_vectors,
1796 s->q_scale_type,
s->intra_vlc_format,
1797 s->repeat_first_field,
s->chroma_420_type ?
"420" :
"");
1810 if (
s->current_picture.motion_val[0] && !
s->encoding) {
1811 const int wrap =
s->b8_stride;
1812 int xy =
s->mb_x * 2 +
s->mb_y * 2 *
wrap;
1813 int b8_xy = 4 * (
s->mb_x +
s->mb_y *
s->mb_stride);
1814 int motion_x, motion_y, dir,
i;
1816 for (
i = 0;
i < 2;
i++) {
1817 for (dir = 0; dir < 2; dir++) {
1820 motion_x = motion_y = 0;
1823 motion_x =
s->mv[dir][0][0];
1824 motion_y =
s->mv[dir][0][1];
1826 motion_x =
s->mv[dir][
i][0];
1827 motion_y =
s->mv[dir][
i][1];
1830 s->current_picture.motion_val[dir][xy][0] = motion_x;
1831 s->current_picture.motion_val[dir][xy][1] = motion_y;
1832 s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
1833 s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
1834 s->current_picture.ref_index [dir][b8_xy] =
1835 s->current_picture.ref_index [dir][b8_xy + 1] =
s->field_select[dir][
i];
1837 s->field_select[dir][
i] == 1);
1845 s->dest[1] +=(16 >>
lowres) >>
s->chroma_x_shift;
1846 s->dest[2] +=(16 >>
lowres) >>
s->chroma_x_shift;
1850 if (++
s->mb_x >=
s->mb_width) {
1851 const int mb_size = 16 >>
s->avctx->lowres;
1858 s->mb_y += 1 << field_pic;
1860 if (
s->mb_y >=
s->mb_height) {
1862 int is_d10 =
s->chroma_format == 2 &&
1865 s->intra_dc_precision == 2 &&
1866 s->q_scale_type == 1 &&
s->alternate_scan == 0 &&
1867 s->progressive_frame == 0
1870 if (left >= 32 && !is_d10) {
1897 if (
s->mb_y >= ((
s->height + 15) >> 4) &&
1898 !
s->progressive_sequence &&
1901 s->mb_skip_run == -1 &&
1909 if (
s->mb_skip_run == -1) {
1921 s->mb_skip_run += 33;
1922 }
else if (
code == 35) {
1923 if (
s->mb_skip_run != 0 ||
show_bits(&
s->gb, 15) != 0) {
1931 s->mb_skip_run +=
code;
1935 if (
s->mb_skip_run) {
1939 "skipped MB in I-frame at %d %d\n",
s->mb_x,
s->mb_y);
1945 for (
i = 0;
i < 12;
i++)
1946 s->block_last_index[
i] = -1;
1954 s->mv[0][0][0] =
s->mv[0][0][1] = 0;
1955 s->last_mv[0][0][0] =
s->last_mv[0][0][1] = 0;
1956 s->last_mv[0][1][0] =
s->last_mv[0][1][1] = 0;
1957 s->field_select[0][0] = (
s->picture_structure - 1) & 1;
1960 s->mv[0][0][0] =
s->last_mv[0][0][0];
1961 s->mv[0][0][1] =
s->last_mv[0][0][1];
1962 s->mv[1][0][0] =
s->last_mv[1][0][0];
1963 s->mv[1][0][1] =
s->last_mv[1][0][1];
1964 s->field_select[0][0] = (
s->picture_structure - 1) & 1;
1965 s->field_select[1][0] = (
s->picture_structure - 1) & 1;
1976 ff_dlog(
s,
"Slice start:%d %d end:%d %d\n",
s->resync_mb_x,
s->resync_mb_y,
s->mb_x,
s->mb_y);
1984 int mb_y =
s->start_mb_y;
1985 const int field_pic =
s->picture_structure !=
PICT_FRAME;
1987 s->er.error_count = (3 * (
s->end_mb_y -
s->start_mb_y) *
s->mb_width) >> field_pic;
1995 ff_dlog(
c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1996 ret,
s->resync_mb_x,
s->resync_mb_y,
s->mb_x,
s->mb_y,
1997 s->start_mb_y,
s->end_mb_y,
s->er.error_count);
2001 if (
s->resync_mb_x >= 0 &&
s->resync_mb_y >= 0)
2007 s->mb_x - 1,
s->mb_y,
2011 if (
s->mb_y ==
s->end_mb_y)
2020 mb_y += (*buf&0xE0)<<2;
2024 if (mb_y >=
s->end_mb_y)
2038 if (!
s1->mpeg_enc_ctx_allocated || !
s->current_picture_ptr)
2041 if (
s->avctx->hwaccel) {
2042 int ret =
s->avctx->hwaccel->end_frame(
s->avctx);
2045 "hardware accelerator failed to decode picture\n");
2051 if ( !
s->first_field && !
s1->first_slice) {
2066 s->picture_number++;
2069 if (
s->last_picture_ptr) {
2085 const uint8_t *buf,
int buf_size)
2098 "Invalid horizontal or vertical size value.\n");
2103 if (
s->aspect_ratio_info == 0) {
2109 if (
s->frame_rate_index == 0 ||
s->frame_rate_index > 13) {
2111 "frame_rate_index %d is invalid\n",
s->frame_rate_index);
2112 s->frame_rate_index = 1;
2119 s1->rc_buffer_size =
get_bits(&
s->gb, 10) * 1024 * 16;
2126 for (
i = 0;
i < 64;
i++) {
2127 j =
s->idsp.idct_permutation[
i];
2129 s->intra_matrix[j] = v;
2130 s->chroma_intra_matrix[j] = v;
2136 for (
i = 0;
i < 64;
i++) {
2137 int j =
s->idsp.idct_permutation[
i];
2139 s->inter_matrix[j] = v;
2140 s->chroma_inter_matrix[j] = v;
2153 s->progressive_sequence = 1;
2154 s->progressive_frame = 1;
2157 s->frame_pred_frame_dct = 1;
2158 s->chroma_format = 1;
2167 av_log(
s->avctx,
AV_LOG_DEBUG,
"vbv buffer: %d, bitrate:%"PRId64
", aspect_ratio_info: %d \n",
2168 s1->rc_buffer_size,
s->bit_rate,
s->aspect_ratio_info);
2181 if (
s1->mpeg_enc_ctx_allocated) {
2183 s1->mpeg_enc_ctx_allocated = 0;
2196 s1->mpeg_enc_ctx_allocated = 1;
2198 for (
i = 0;
i < 64;
i++) {
2199 int j =
s->idsp.idct_permutation[
i];
2201 s->intra_matrix[j] = v;
2202 s->chroma_intra_matrix[j] = v;
2205 s->inter_matrix[j] = v;
2206 s->chroma_inter_matrix[j] = v;
2209 s->progressive_sequence = 1;
2210 s->progressive_frame = 1;
2213 s->frame_pred_frame_dct = 1;
2214 s->chroma_format = 1;
2215 if (
s->codec_tag ==
AV_RL32(
"BW10")) {
2221 s1->save_width =
s->width;
2222 s1->save_height =
s->height;
2223 s1->save_progressive_seq =
s->progressive_sequence;
2228 const uint8_t *p,
int buf_size)
2232 if (buf_size >= 6 &&
2233 p[0] ==
'G' && p[1] ==
'A' && p[2] ==
'9' && p[3] ==
'4' &&
2234 p[4] == 3 && (p[5] & 0x40)) {
2236 int cc_count = p[5] & 0x1f;
2237 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
2238 int old_size =
s1->a53_buf_ref ?
s1->a53_buf_ref->size : 0;
2239 const uint64_t new_size = (old_size + cc_count
2248 memcpy(
s1->a53_buf_ref->data + old_size, p + 7, cc_count * UINT64_C(3));
2253 }
else if (buf_size >= 2 &&
2254 p[0] == 0x03 && (p[1]&0x7f) == 0x01) {
2263 int old_size =
s1->a53_buf_ref ?
s1->a53_buf_ref->size : 0;
2264 const uint64_t new_size = (old_size + cc_count
2274 memset(
s1->a53_buf_ref->data + old_size, 0, cc_count * 3);
2284 cap[0] = cap[1] = cap[2] = 0x00;
2286 field = (field == 2 ? 1 : 0);
2287 if (!
s1->mpeg_enc_ctx.top_field_first) field = !field;
2288 cap[0] = 0x04 | field;
2298 }
else if (buf_size >= 11 &&
2299 p[0] ==
'C' && p[1] ==
'C' && p[2] == 0x01 && p[3] == 0xf8) {
2329 for (
i = 5;
i + 6 <= buf_size && ((p[
i] & 0xfe) == 0xfe);
i += 6)
2333 int old_size =
s1->a53_buf_ref ?
s1->a53_buf_ref->size : 0;
2334 const uint64_t new_size = (old_size + cc_count
2341 uint8_t field1 = !!(p[4] & 0x80);
2344 for (
i = 0;
i < cc_count;
i++) {
2345 cap[0] = (p[0] == 0xff && field1) ? 0xfc : 0xfd;
2348 cap[3] = (p[3] == 0xff && !field1) ? 0xfc : 0xfd;
2363 const uint8_t *p,
int buf_size)
2366 const uint8_t *buf_end = p + buf_size;
2371 for(
i=0; !(!p[
i-2] && !p[
i-1] && p[
i]==1) &&
i<buf_size;
i++){
2380 if (!memcmp(p+
i,
"\0TMPGEXS\0", 9)){
2385 if (buf_end - p >= 5 &&
2386 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2394 if (buf_end - p < 1)
2397 s1->afd = p[0] & 0x0f;
2399 }
else if (buf_end - p >= 6 &&
2400 p[0] ==
'J' && p[1] ==
'P' && p[2] ==
'3' && p[3] ==
'D' &&
2403 const uint8_t S3D_video_format_type = p[5] & 0x7F;
2405 if (S3D_video_format_type == 0x03 ||
2406 S3D_video_format_type == 0x04 ||
2407 S3D_video_format_type == 0x08 ||
2408 S3D_video_format_type == 0x23) {
2410 s1->has_stereo3d = 1;
2412 switch (S3D_video_format_type) {
2433 const uint8_t *buf,
int buf_size)
2444 #if FF_API_PRIVATE_OPT
2460 "GOP (%s) closed_gop=%d broken_link=%d\n",
2461 tcbuf,
s->closed_gop, broken_link);
2466 int *got_output,
const uint8_t *buf,
int buf_size)
2471 const uint8_t *buf_end = buf + buf_size;
2472 int ret, input_size;
2473 int last_code = 0, skip_frame = 0;
2474 int picture_start_code_seen = 0;
2489 &
s2->thread_context[0],
NULL,
2490 s->slice_count,
sizeof(
void *));
2491 for (
i = 0;
i <
s->slice_count;
i++)
2492 s2->er.error_count +=
s2->thread_context[
i]->er.error_count;
2509 return FFMAX(0, buf_ptr - buf -
s2->parse_context.last_index);
2512 input_size = buf_end - buf_ptr;
2521 if (last_code == 0) {
2527 "ignoring SEQ_START_CODE after %X\n", last_code);
2534 if (picture_start_code_seen &&
s2->picture_structure ==
PICT_FRAME) {
2540 picture_start_code_seen = 1;
2542 if (
s2->width <= 0 ||
s2->height <= 0) {
2544 s2->width,
s2->height);
2549 s2->intra_dc_precision= 3;
2550 s2->intra_matrix[0]= 1;
2553 !avctx->
hwaccel &&
s->slice_count) {
2557 s2->thread_context,
NULL,
2558 s->slice_count,
sizeof(
void *));
2559 for (
i = 0;
i <
s->slice_count;
i++)
2560 s2->er.error_count +=
s2->thread_context[
i]->er.error_count;
2567 "mpeg_decode_postinit() failure\n");
2578 "ignoring pic after %X\n", last_code);
2588 if (last_code == 0) {
2592 "ignoring seq ext after %X\n", last_code);
2611 "ignoring pic cod ext after %X\n", last_code);
2622 if (last_code == 0) {
2623 s2->first_field = 0;
2628 "ignoring GOP_START_CODE after %X\n", last_code);
2636 if (
s2->progressive_sequence && !
s2->progressive_frame) {
2637 s2->progressive_frame = 1;
2639 "interlaced frame in progressive sequence, ignoring\n");
2642 if (
s2->picture_structure == 0 ||
2643 (
s2->progressive_frame &&
s2->picture_structure !=
PICT_FRAME)) {
2645 "picture_structure %d invalid, ignoring\n",
2646 s2->picture_structure);
2650 if (
s2->progressive_sequence && !
s2->frame_pred_frame_dct)
2654 s2->first_field = 0;
2655 s2->v_edge_pos = 16 *
s2->mb_height;
2657 s2->first_field ^= 1;
2658 s2->v_edge_pos = 8 *
s2->mb_height;
2659 memset(
s2->mbskip_table, 0,
s2->mb_stride *
s2->mb_height);
2664 const int field_pic =
s2->picture_structure !=
PICT_FRAME;
2668 mb_y += (*buf_ptr&0xE0)<<2;
2674 if (buf_end - buf_ptr < 2) {
2679 if (mb_y >=
s2->mb_height) {
2681 "slice below image (%d >= %d)\n", mb_y,
s2->mb_height);
2685 if (!
s2->last_picture_ptr) {
2689 if (!
s2->closed_gop) {
2692 "Skipping B slice due to open GOP\n");
2699 if (!
s2->next_picture_ptr) {
2705 "Skipping P slice due to !sync\n");
2718 if (!
s->mpeg_enc_ctx_allocated)
2722 if (mb_y < avctx->skip_top ||
2727 if (!
s2->pict_type) {
2734 if (
s->first_slice) {
2740 if (!
s2->current_picture_ptr) {
2742 "current_picture not initialized\n");
2749 int threshold = (
s2->mb_height *
s->slice_count +
2750 s2->slice_context_count / 2) /
2751 s2->slice_context_count;
2753 if (threshold <= mb_y) {
2758 if (
s->slice_count) {
2759 s2->thread_context[
s->slice_count - 1]->end_mb_y = mb_y;
2775 if (
s2->resync_mb_x >= 0 &&
s2->resync_mb_y >= 0)
2777 s2->resync_mb_y,
s2->mb_x,
s2->mb_y,
2781 s2->resync_mb_y,
s2->mb_x - 1,
s2->mb_y,
2796 int buf_size = avpkt->
size;
2803 if (
s2->low_delay == 0 &&
s2->next_picture_ptr) {
2808 s2->next_picture_ptr =
NULL;
2820 (
const uint8_t **) &buf, &buf_size) < 0)
2825 if (
s->mpeg_enc_ctx_allocated == 0 && (
s2->codec_tag ==
AV_RL32(
"VCR2")
2832 if (avctx->
extradata && !
s->extradata_decoded) {
2840 s->extradata_decoded = 1;
2842 s2->current_picture_ptr =
NULL;
2847 ret =
decode_chunks(avctx, picture, got_output, buf, buf_size);
2848 if (ret<0 || *got_output) {
2849 s2->current_picture_ptr =
NULL;
2851 if (
s2->timecode_frame_start != -1 && *got_output) {
2858 memcpy(tcside->
data, &
s2->timecode_frame_start,
sizeof(int64_t));
2863 s2->timecode_frame_start = -1;
2883 if (
s->mpeg_enc_ctx_allocated)
2890 .
name =
"mpeg1video",
2907 #if CONFIG_MPEG1_NVDEC_HWACCEL
2910 #if CONFIG_MPEG1_VDPAU_HWACCEL
2913 #if CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL
2916 #if CONFIG_MPEG1_XVMC_HWACCEL
2924 .
name =
"mpeg2video",
2941 #if CONFIG_MPEG2_DXVA2_HWACCEL
2944 #if CONFIG_MPEG2_D3D11VA_HWACCEL
2947 #if CONFIG_MPEG2_D3D11VA2_HWACCEL
2950 #if CONFIG_MPEG2_NVDEC_HWACCEL
2953 #if CONFIG_MPEG2_VAAPI_HWACCEL
2956 #if CONFIG_MPEG2_VDPAU_HWACCEL
2959 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
2962 #if CONFIG_MPEG2_XVMC_HWACCEL
2971 .
name =
"mpegvideo",
3016 if (
s->flags & 0x10) {
3027 for (
int y = 0; y < avctx->
height; y += 16) {
3030 for (
int x = 0; x < avctx->
width; x += 16) {
3049 memset(
s->block, 0,
sizeof(
s->block));
3051 for (
int n = 0; n < 6; n++) {
3052 if (
s->flags & 0x80) {
3106 for (
int i = 0;
i < 64;
i++) {
3113 for (
int i = 0;
i < 64;
i++) {
static double val(void *priv, double ch)
Macro definitions for various function/variable attributes.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
#define FF_DEBUG_STARTCODE
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define FF_DEBUG_PICT_INFO
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
static av_cold int init(AVCodecContext *avctx)
#define SLICE_MAX_START_CODE
#define flags(name, subs,...)
#define CONFIG_MPEG1_XVMC_HWACCEL
#define CONFIG_MPEG2_XVMC_HWACCEL
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_er_frame_end(ERContext *s)
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
#define GET_CACHE(name, gb)
static int get_sbits(GetBitContext *s, int n)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define CLOSE_READER(name, gb)
static int get_bits_left(GetBitContext *gb)
#define SHOW_UBITS(name, gb, num)
static unsigned int get_bits1(GetBitContext *s)
#define SHOW_SBITS(name, gb, num)
#define OPEN_READER(name, gb)
static void skip_bits(GetBitContext *s, int n)
static int skip_1stop_8data_bits(GetBitContext *gb)
#define SKIP_BITS(name, gb, num)
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
#define UPDATE_CACHE(name, gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define LAST_SKIP_BITS(name, gb, num)
static int get_bits_count(const GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
static const uint8_t * align_get_bits(GetBitContext *s)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
#define AV_CODEC_CAP_TRUNCATED
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_NONREF
discard all non reference
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_realloc(AVBufferRef **pbuf, buffer_size_t size)
Reallocate a given buffer.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, buffer_size_t size)
Add a new side data to a frame.
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
@ AV_FRAME_DATA_GOP_TIMECODE
The GOP timecode in 25 bit timecode format.
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
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.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
#define HWACCEL_DXVA2(codec)
#define HWACCEL_VDPAU(codec)
#define HWACCEL_XVMC(codec)
#define HWACCEL_NVDEC(codec)
#define HWACCEL_VAAPI(codec)
#define HWACCEL_D3D11VA(codec)
#define HWACCEL_D3D11VA2(codec)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
#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...
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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.
unsigned int avpriv_toupper4(unsigned int x)
#define FF_QSCALE_TYPE_MPEG2
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define PTRDIFF_SPECIFIER
#define FF_ENABLE_DEPRECATION_WARNINGS
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
const uint8_t ff_reverse[256]
static const AVProfile profiles[]
static enum AVPixelFormat pix_fmts[]
const uint8_t ff_zigzag_direct[64]
static av_const int sign_extend(int val, unsigned bits)
av_cold void ff_mpeg12_init_vlcs(void)
int ff_mpeg1_decode_block_intra(GetBitContext *gb, const uint16_t *quant_matrix, uint8_t *const scantable, int last_dc[3], int16_t *block, int index, int qscale)
void ff_mpeg1_clean_buffers(MpegEncContext *s)
av_cold void ff_mpeg12_common_init(MpegEncContext *s)
int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)
Find the end of the current frame in the bitstream.
static int decode_dc(GetBitContext *gb, int component)
const uint16_t ff_mpeg1_default_intra_matrix[256]
const float ff_mpeg1_aspect[16]
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
const AVRational ff_mpeg2_aspect[16]
const AVRational ff_mpeg12_frame_rate_tab[]
static void mpeg_decode_gop(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
AVCodec ff_mpeg2video_decoder
static int mpeg_decode_slice(MpegEncContext *s, int mb_y, const uint8_t **buf, int buf_size)
Decode a slice.
static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
static int mpeg1_decode_block_inter(MpegEncContext *s, int16_t *block, int n)
#define DECODE_SLICE_ERROR
static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
AVCodec ff_mpeg1video_decoder
static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
static int mpeg2_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n)
static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int slice_decode_thread(AVCodecContext *c, void *arg)
static void setup_hwaccel_for_pixfmt(AVCodecContext *avctx)
static enum AVPixelFormat mpeg12_pixfmt_list_422[]
static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
static int mpeg2_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
#define check_scantable_index(ctx, x)
static int mpeg1_decode_sequence(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int vcr2_init_sequence(AVCodecContext *avctx)
static const uint32_t ptype2mb_type[7]
static int ipu_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[]
static int mpeg2_fast_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
Changing this would eat up any speed benefits it has.
static enum AVPixelFormat mpeg12_pixfmt_list_444[]
static int mpeg1_fast_decode_block_inter(MpegEncContext *s, int16_t *block, int n)
Changing this would eat up any speed benefits it has.
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
static enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[]
static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int *got_output, const uint8_t *buf, int buf_size)
static av_cold int ipu_decode_end(AVCodecContext *avctx)
static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm, const uint8_t *new_perm)
static const uint32_t btype2mb_type[11]
static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
static void mpeg_decode_user_data(AVCodecContext *avctx, const uint8_t *p, int buf_size)
static int mpeg_decode_a53_cc(AVCodecContext *avctx, const uint8_t *p, int buf_size)
static av_cold int ipu_decode_init(AVCodecContext *avctx)
static int get_dmv(MpegEncContext *s)
AVCodec ff_mpegvideo_decoder
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
static int mpeg_decode_postinit(AVCodecContext *avctx)
static int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n)
Changing this would eat up any speed benefits it has.
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
static void flush(AVCodecContext *avctx)
#define MB_BTYPE_VLC_BITS
#define MB_PTYPE_VLC_BITS
void ff_mpeg_er_frame_start(MpegEncContext *s)
#define USES_LIST(a, list)
#define MB_TYPE_INTERLACED
#define PICT_BOTTOM_FIELD
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
void ff_mpv_common_end(MpegEncContext *s)
void ff_mpv_frame_end(MpegEncContext *s)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
void ff_mpeg_flush(AVCodecContext *avctx)
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_init_block_index(MpegEncContext *s)
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
void ff_mpv_report_decode_progress(MpegEncContext *s)
#define PICTURE_START_CODE
#define MV_TYPE_16X8
2 vectors, one per 16x8 block
#define MV_TYPE_DMV
2 vectors, special mpeg2 Dual Prime Vectors
#define SLICE_MIN_START_CODE
#define MV_TYPE_FIELD
2 vectors, one per field
static int mpeg_get_qscale(MpegEncContext *s)
#define MV_TYPE_16X16
1 vector for the whole mb
void ff_xvmc_init_block(MpegEncContext *s)
Initialize the block field of the MpegEncContext pointer passed as parameter after making sure that t...
void ff_xvmc_pack_pblocks(MpegEncContext *s, int cbp)
Fill individual block pointers, so there are no gaps in the data_block array in case not all blocks i...
const uint8_t ff_alternate_vertical_scan[64]
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
@ AV_PIX_FMT_XVMC
XVideo Motion Acceleration via common packet passing.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
const AVProfile ff_mpeg2_video_profiles[]
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
FF_DISABLE_DEPRECATION_WARNINGS enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
static const float pred[4]
static int shift(int a, int b)
A reference to a data buffer.
This structure describes the bitrate properties of an encoded bitstream.
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int max_bitrate
Maximum bitrate of the stream, in bits per second.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int flags2
AV_CODEC_FLAG2_*.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
int active_thread_type
Which multithreading methods are in use by the codec.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
unsigned properties
Properties of the stream that gets decoded.
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.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
attribute_deprecated int64_t timecode_frame_start
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int skip_bottom
Number of macroblock rows at the bottom which are skipped.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVDiscard skip_frame
Skip decoding for selected frames.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
AVDictionary * metadata
metadata.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
uint8_t idct_permutation[64]
IDCT input permutation.
MpegEncContext mpeg_enc_ctx
AVBufferRef * a53_buf_ref
int mpeg_enc_ctx_allocated
AVRational frame_rate_ext
uint16_t inter_matrix[64]
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
int block_last_index[12]
last non zero coefficient in block
int last_dc[3]
last DC values for MPEG-1
ScanTable inter_scantable
if inter == intra then intra should be used to reduce the cache usage
uint16_t chroma_inter_matrix[64]
ScanTable intra_scantable
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
uint16_t chroma_intra_matrix[64]
RL_VLC_ELEM * rl_vlc[32]
decoding only
VLC_TYPE(* table)[2]
code, bits
static int ref[MAX_W *MAX_W]
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).
#define AV_TIMECODE_STR_SIZE
static av_always_inline int diff(const uint32_t a, const uint32_t b)