28#include "config_components.h"
30#define UNCHECKED_BITSTREAM_READER 1
62#define A53_MAX_CC_COUNT 2000
132#define MAX_INDEX (64 - 1)
133#define check_scantable_index(ctx, x) \
135 if ((x) > MAX_INDEX) { \
136 av_log(ctx->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
137 ctx->c.mb_x, ctx->c.mb_y); \
138 return AVERROR_INVALIDDATA; \
143 int16_t *
block,
int n)
146 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
147 const uint16_t *quant_matrix =
s->c.inter_matrix;
148 const int qscale =
s->c.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->c.block_last_index[n] =
i;
227 int16_t *
block,
int n)
230 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
231 const uint16_t *quant_matrix;
232 const int qscale =
s->c.qscale;
241 quant_matrix =
s->c.inter_matrix;
243 quant_matrix =
s->c.chroma_inter_matrix;
248 level = (3 * qscale * quant_matrix[0]) >> 5;
269 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
286 level = ((-
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
289 level = ((
level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
303 block[63] ^= (mismatch & 1);
307 s->c.block_last_index[n] =
i;
312 int16_t *
block,
int n)
317 const uint8_t *
const scantable =
s->c.intra_scantable.permutated;
318 const uint16_t *quant_matrix;
319 const int qscale =
s->c.qscale;
324 quant_matrix =
s->c.intra_matrix;
327 quant_matrix =
s->c.chroma_intra_matrix;
328 component = (n & 1) + 1;
331 dc =
s->last_dc[component];
333 s->last_dc[component] = dc;
334 block[0] = dc * (1 << (3 -
s->c.intra_dc_precision));
336 mismatch =
block[0] ^ 1;
338 if (
s->c.intra_vlc_format)
353 }
else if (
level != 0) {
358 level = (
level * qscale * quant_matrix[j]) >> 4;
373 level = (-
level * qscale * quant_matrix[j]) >> 4;
376 level = (
level * qscale * quant_matrix[j]) >> 4;
385 block[63] ^= mismatch & 1;
408 int i, j, k, cbp,
val, mb_type, motion_type;
409 const int mb_block_count = 4 + (1 <<
s->c.chroma_format);
412 ff_tlog(
s->c.avctx,
"decode_mb: x=%d y=%d\n",
s->c.mb_x,
s->c.mb_y);
416 if ((*mb_skip_run)-- != 0) {
419 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] =
425 mb_type =
s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride - 1];
428 mb_type =
s->c.cur_pic.mb_type[
s->c.mb_width + (
s->c.mb_y - 1) *
s->c.mb_stride - 1];
433 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] =
436 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)
443 switch (
s->c.pict_type) {
449 "Invalid mb type in I-frame at %d %d\n",
450 s->c.mb_x,
s->c.mb_y);
462 "Invalid mb type in P-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
470 "Invalid mb type in B-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
475 ff_tlog(
s->c.avctx,
"mb_type=%x\n", mb_type);
478 s->c.bdsp.clear_blocks(
s->block[0]);
480 if (!
s->c.chroma_y_shift)
481 s->c.bdsp.clear_blocks(
s->block[6]);
486 !
s->c.frame_pred_frame_dct)
492 if (
s->c.concealment_motion_vectors) {
498 s->c.last_mv[0][0][0] =
500 s->c.last_mv[0][0][0]);
502 s->c.last_mv[0][0][1] =
504 s->c.last_mv[0][0][1]);
506 check_marker(
s->c.avctx, &
s->gb,
"after concealment_motion_vectors");
509 memset(
s->c.last_mv, 0,
sizeof(
s->c.last_mv));
514 for (
i = 0;
i < mb_block_count;
i++)
518 for (
i = 0;
i < 6;
i++) {
521 s->c.intra_scantable.permutated,
522 s->last_dc,
s->block[
i],
526 s->c.mb_x,
s->c.mb_y);
538 && !
s->c.frame_pred_frame_dct)
544 s->c.field_select[0][0] =
s->c.picture_structure - 1;
550 s->c.last_mv[0][0][0] = 0;
551 s->c.last_mv[0][0][1] = 0;
552 s->c.last_mv[0][1][0] = 0;
553 s->c.last_mv[0][1][1] = 0;
554 s->c.mv[0][0][0] = 0;
555 s->c.mv[0][0][1] = 0;
560 if (
s->c.picture_structure ==
PICT_FRAME &&
s->c.frame_pred_frame_dct) {
573 ff_tlog(
s->c.avctx,
"motion_type=%d\n", motion_type);
574 switch (motion_type) {
579 for (
i = 0;
i < 2;
i++) {
583 s->c.last_mv[
i][0][0] =
584 s->c.last_mv[
i][1][0] =
586 s->c.last_mv[
i][0][0]);
588 s->c.last_mv[
i][0][1] =
589 s->c.last_mv[
i][1][1] =
591 s->c.last_mv[
i][0][1]);
593 if (
s->c.full_pel[
i]) {
594 s->c.mv[
i][0][0] *= 2;
595 s->c.mv[
i][0][1] *= 2;
602 for (
i = 0;
i < 2;
i++) {
605 for (j = 0; j < 2; j++) {
607 for (k = 0; k < 2; k++) {
609 s->c.last_mv[
i][j][k]);
610 s->c.last_mv[
i][j][k] =
val;
611 s->c.mv[
i][j][k] =
val;
622 for (
i = 0;
i < 2;
i++) {
624 for (j = 0; j < 2; j++) {
627 s->c.last_mv[
i][j][0]);
628 s->c.last_mv[
i][j][0] =
val;
629 s->c.mv[
i][j][0] =
val;
632 s->c.last_mv[
i][j][1] >> 1);
633 s->c.last_mv[
i][j][1] = 2 *
val;
634 s->c.mv[
i][j][1] =
val;
642 for (
i = 0;
i < 2;
i++) {
645 for (k = 0; k < 2; k++) {
647 s->c.last_mv[
i][0][k]);
648 s->c.last_mv[
i][0][k] =
val;
649 s->c.last_mv[
i][1][k] =
val;
650 s->c.mv[
i][0][k] =
val;
657 if (
s->c.progressive_sequence){
662 for (
i = 0;
i < 2;
i++) {
664 int dmx, dmy,
mx,
my, m;
665 const int my_shift =
s->c.picture_structure ==
PICT_FRAME;
668 s->c.last_mv[
i][0][0]);
669 s->c.last_mv[
i][0][0] =
mx;
670 s->c.last_mv[
i][1][0] =
mx;
673 s->c.last_mv[
i][0][1] >> my_shift);
677 s->c.last_mv[
i][0][1] =
my * (1 << my_shift);
678 s->c.last_mv[
i][1][1] =
my * (1 << my_shift);
680 s->c.mv[
i][0][0] =
mx;
681 s->c.mv[
i][0][1] =
my;
682 s->c.mv[
i][1][0] =
mx;
683 s->c.mv[
i][1][1] =
my;
689 m =
s->c.top_field_first ? 1 : 3;
692 s->c.mv[
i][2][0] = ((
mx * m + (
mx > 0)) >> 1) + dmx;
693 s->c.mv[
i][2][1] = ((
my * m + (
my > 0)) >> 1) + dmy - 1;
695 s->c.mv[
i][3][0] = ((
mx * m + (
mx > 0)) >> 1) + dmx;
696 s->c.mv[
i][3][1] = ((
my * m + (
my > 0)) >> 1) + dmy + 1;
700 s->c.mv[
i][2][0] = ((
mx + (
mx > 0)) >> 1) + dmx;
701 s->c.mv[
i][2][1] = ((
my + (
my > 0)) >> 1) + dmy;
712 "00 motion_type at %d %d\n",
s->c.mb_x,
s->c.mb_y);
718 s->last_dc[0] =
s->last_dc[1] =
s->last_dc[2] = 128 <<
s->c.intra_dc_precision;
720 s->c.bdsp.clear_blocks(
s->block[0]);
723 if (mb_block_count > 6) {
724 cbp *= 1 << mb_block_count - 6;
725 cbp |=
get_bits(&
s->gb, mb_block_count - 6);
726 s->c.bdsp.clear_blocks(
s->block[6]);
730 "invalid cbp %d at %d %d\n", cbp,
s->c.mb_x,
s->c.mb_y);
735 cbp <<= 12 - mb_block_count;
737 for (
i = 0;
i < mb_block_count;
i++) {
738 if (cbp & (1 << 11)) {
742 s->c.block_last_index[
i] = -1;
747 for (
i = 0;
i < 6;
i++) {
752 s->c.block_last_index[
i] = -1;
758 for (
i = 0;
i < 12;
i++)
759 s->c.block_last_index[
i] = -1;
763 s->c.cur_pic.mb_type[
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride] = mb_type;
771 MPVContext *
const s2 = &
s->slice.c;
774 s2->slice_ctx_size =
sizeof(
s->slice);
792#if CONFIG_MPEG1_NVDEC_HWACCEL
795#if CONFIG_MPEG1_NVDEC_CUARRAY_HWACCEL
798#if CONFIG_MPEG1_VDPAU_HWACCEL
806#if CONFIG_MPEG2_NVDEC_HWACCEL
809#if CONFIG_MPEG2_NVDEC_CUARRAY_HWACCEL
812#if CONFIG_MPEG2_VDPAU_HWACCEL
815#if CONFIG_MPEG2_DXVA2_HWACCEL
818#if CONFIG_MPEG2_D3D11VA_HWACCEL
822#if CONFIG_MPEG2_D3D12VA_HWACCEL
825#if CONFIG_MPEG2_VAAPI_HWACCEL
828#if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
848 MPVContext *
const s = &s1->
slice.
c;
871 MPVContext *
const s = &s1->
slice.
c;
884 s1->pan_scan.height }),
894 s->avctx->sample_aspect_ratio =
898 s->avctx->sample_aspect_ratio =
900 (
AVRational) { s1->pan_scan.width, s1->pan_scan.height });
905 ff_dlog(avctx,
"aspect A %d/%d\n",
908 ff_dlog(avctx,
"aspect B %d/%d\n",
s->avctx->sample_aspect_ratio.num,
909 s->avctx->sample_aspect_ratio.den);
912 s->avctx->sample_aspect_ratio =
925 if (!
s->context_initialized ||
931 if (
s->context_initialized)
959 &
s->avctx->framerate.den,
964 switch (
s->chroma_format) {
976 if (!
s->avctx->lowres)
977 for (
int i = 0;
i <
s->slice_context_count;
i++)
987 MPVContext *
const s = &s1->
slice.
c;
989 int ref, f_code, vbv_delay,
ret;
997 if (
s->pict_type == 0 ||
s->pict_type > 3)
1009 s->mpeg_f_code[0][0] = f_code;
1010 s->mpeg_f_code[0][1] = f_code;
1018 s->mpeg_f_code[1][0] = f_code;
1019 s->mpeg_f_code[1][1] = f_code;
1024 "vbv_delay %d, ref %d type:%d\n", vbv_delay,
ref,
s->pict_type);
1032 MPVContext *
const s = &s1->
slice.
c;
1033 int horiz_size_ext, vert_size_ext;
1042 if (!
s->chroma_format) {
1049 s->width |= (horiz_size_ext << 12);
1050 s->height |= (vert_size_ext << 12);
1052 s1->
bit_rate += (bit_rate_ext << 18) * 400LL;
1054 s->avctx->rc_buffer_size +=
get_bits(gb, 8) * 1024 * 16 << 10;
1063 ff_dlog(
s->avctx,
"sequence extension\n");
1068 "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64
"\n",
1069 s->avctx->profile,
s->avctx->level,
s->progressive_sequence,
s->chroma_format,
1070 s->avctx->rc_buffer_size, s1->
bit_rate);
1076 MPVContext *
const s = &s1->
slice.
c;
1077 int color_description,
w,
h;
1081 if (color_description) {
1082 s->avctx->color_primaries =
get_bits(gb, 8);
1114 MPVContext *
const s = &s1->
slice.
c;
1118 if (
s->progressive_sequence) {
1119 if (
s->repeat_first_field) {
1121 if (
s->top_field_first)
1127 if (
s->repeat_first_field)
1131 for (
i = 0;
i < nofco;
i++) {
1140 "pde (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
")\n",
1147 uint16_t matrix0[64], uint16_t matrix1[64],
int intra)
1151 for (
i = 0;
i < 64;
i++) {
1158 if (intra &&
i == 0 && v != 8) {
1159 av_log(
s->avctx,
AV_LOG_DEBUG,
"intra matrix specifies invalid DC quantizer %d, ignoring\n", v);
1172 ff_dlog(
s->avctx,
"matrix extension\n");
1187 MPVContext *
const s = &s1->
slice.
c;
1189 s->full_pel[0] =
s->full_pel[1] = 0;
1194 s->mpeg_f_code[0][0] += !
s->mpeg_f_code[0][0];
1195 s->mpeg_f_code[0][1] += !
s->mpeg_f_code[0][1];
1196 s->mpeg_f_code[1][0] += !
s->mpeg_f_code[1][0];
1197 s->mpeg_f_code[1][1] += !
s->mpeg_f_code[1][1];
1198 if (!
s->pict_type &&
s->context_initialized) {
1203 if (
s->mpeg_f_code[1][0] == 15 &&
s->mpeg_f_code[1][1] == 15) {
1204 if (
s->mpeg_f_code[0][0] == 15 &&
s->mpeg_f_code[0][1] == 15)
1212 s->intra_dc_precision =
get_bits(gb, 2);
1216 s->concealment_motion_vectors =
get_bits1(gb);
1227 s->idsp.idct_permutation);
1230 ff_dlog(
s->avctx,
"intra_dc_precision=%d\n",
s->intra_dc_precision);
1231 ff_dlog(
s->avctx,
"picture_structure=%d\n",
s->picture_structure);
1232 ff_dlog(
s->avctx,
"top field first=%d\n",
s->top_field_first);
1233 ff_dlog(
s->avctx,
"repeat first field=%d\n",
s->repeat_first_field);
1234 ff_dlog(
s->avctx,
"conceal=%d\n",
s->concealment_motion_vectors);
1235 ff_dlog(
s->avctx,
"intra_vlc_format=%d\n",
s->intra_vlc_format);
1236 ff_dlog(
s->avctx,
"alternate_scan=%d\n",
s->alternate_scan);
1237 ff_dlog(
s->avctx,
"frame_pred_frame_dct=%d\n",
s->frame_pred_frame_dct);
1238 ff_dlog(
s->avctx,
"progressive_frame=%d\n",
s->progressive_frame);
1245 MPVContext *
const s = &s1->
slice.
c;
1247 int second_field = 0;
1251 if (
s->mb_width *
s->mb_height * 11LL / (33 * 2 * 8) > buf_size)
1256 if (
s->first_field ||
s->picture_structure ==
PICT_FRAME) {
1266 for (
int i = 0;
i < 3;
i++) {
1269 s->cur_pic.linesize[
i]);
1271 s->cur_pic.linesize[
i] *= 2;
1278 s->cur_pic.ptr->f->repeat_pict = 0;
1279 if (
s->repeat_first_field) {
1280 if (
s->progressive_sequence) {
1281 if (
s->top_field_first)
1282 s->cur_pic.ptr->f->repeat_pict = 4;
1284 s->cur_pic.ptr->f->repeat_pict = 2;
1285 }
else if (
s->progressive_frame) {
1286 s->cur_pic.ptr->f->repeat_pict = 1;
1327 if (!
s->cur_pic.ptr) {
1332 if (
s->avctx->hwaccel) {
1335 "hardware accelerator failed to decode first field\n");
1343 for (
int i = 0;
i < 3;
i++) {
1344 s->cur_pic.data[
i] =
s->cur_pic.ptr->f->data[
i];
1346 s->cur_pic.data[
i] +=
1347 s->cur_pic.ptr->f->linesize[
i];
1354 }
else if (
s->codec_tag ==
MKTAG(
'V',
'C',
'R',
'2')) {
1356 FFSWAP(uint8_t*,
s->cur_pic.data[1],
s->cur_pic.data[2]);
1357 FFSWAP(ptrdiff_t,
s->cur_pic.linesize[1],
s->cur_pic.linesize[2]);
1358 if (!second_field) {
1359 FFSWAP(uint8_t*,
s->next_pic.data[1],
s->next_pic.data[2]);
1360 FFSWAP(ptrdiff_t,
s->next_pic.linesize[1],
s->next_pic.linesize[2]);
1361 FFSWAP(uint8_t*,
s->last_pic.data[1],
s->last_pic.data[2]);
1362 FFSWAP(ptrdiff_t,
s->last_pic.linesize[1],
s->last_pic.linesize[2]);
1369#define DECODE_SLICE_ERROR -1
1370#define DECODE_SLICE_OK 0
1379 const uint8_t **buf,
int buf_size)
1382 const int lowres =
s->c.avctx->lowres;
1383 const int field_pic =
s->c.picture_structure !=
PICT_FRAME;
1387 s->c.resync_mb_y = -1;
1398 s->c.interlaced_dct = 0;
1402 if (
s->c.qscale == 0) {
1413 if (mb_y == 0 &&
s->c.codec_tag ==
AV_RL32(
"SLIF")) {
1434 if (
s->c.mb_x >= (
unsigned)
s->c.mb_width) {
1440 const uint8_t *buf_end, *buf_start = *buf - 4;
1443 if (buf_end < *buf + buf_size)
1452 s->c.resync_mb_x =
s->c.mb_x;
1453 s->c.resync_mb_y =
s->c.mb_y = mb_y;
1456 if (
s->c.mb_y == 0 &&
s->c.mb_x == 0 && (
s->c.first_field ||
s->c.picture_structure ==
PICT_FRAME)) {
1459 "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",
1461 s->c.mpeg_f_code[0][0],
s->c.mpeg_f_code[0][1],
1462 s->c.mpeg_f_code[1][0],
s->c.mpeg_f_code[1][1],
1466 s->c.progressive_sequence ?
"ps" :
"",
1467 s->c.progressive_frame ?
"pf" :
"",
1468 s->c.alternate_scan ?
"alt" :
"",
1469 s->c.top_field_first ?
"top" :
"",
1470 s->c.intra_dc_precision,
s->c.picture_structure,
1471 s->c.frame_pred_frame_dct,
s->c.concealment_motion_vectors,
1472 s->c.q_scale_type,
s->c.intra_vlc_format,
1473 s->c.repeat_first_field,
s->c.chroma_420_type ?
"420" :
"");
1477 s->last_dc[0] = 128 <<
s->c.intra_dc_precision;
1478 s->last_dc[1] =
s->last_dc[0];
1479 s->last_dc[2] =
s->last_dc[0];
1480 memset(
s->c.last_mv, 0,
sizeof(
s->c.last_mv));
1482 for (
int mb_skip_run = 0;;) {
1488 if (
s->c.cur_pic.motion_val[0]) {
1489 const int wrap =
s->c.b8_stride;
1490 int xy =
s->c.mb_x * 2 +
s->c.mb_y * 2 *
wrap;
1491 int b8_xy = 4 * (
s->c.mb_x +
s->c.mb_y *
s->c.mb_stride);
1492 int motion_x, motion_y, dir,
i;
1494 for (
i = 0;
i < 2;
i++) {
1495 for (dir = 0; dir < 2; dir++) {
1496 if (
s->c.mb_intra ||
1498 motion_x = motion_y = 0;
1501 motion_x =
s->c.mv[dir][0][0];
1502 motion_y =
s->c.mv[dir][0][1];
1504 motion_x =
s->c.mv[dir][
i][0];
1505 motion_y =
s->c.mv[dir][
i][1];
1508 s->c.cur_pic.motion_val[dir][xy][0] = motion_x;
1509 s->c.cur_pic.motion_val[dir][xy][1] = motion_y;
1510 s->c.cur_pic.motion_val[dir][xy + 1][0] = motion_x;
1511 s->c.cur_pic.motion_val[dir][xy + 1][1] = motion_y;
1512 s->c.cur_pic.ref_index [dir][b8_xy] =
1513 s->c.cur_pic.ref_index [dir][b8_xy + 1] =
s->c.field_select[dir][
i];
1515 s->c.field_select[dir][
i] == 1);
1523 s->c.dest[1] +=(16 >>
lowres) >>
s->c.chroma_x_shift;
1524 s->c.dest[2] +=(16 >>
lowres) >>
s->c.chroma_x_shift;
1528 if (++
s->c.mb_x >=
s->c.mb_width) {
1529 const int mb_size = 16 >>
s->c.avctx->lowres;
1535 s->c.mb_y += 1 << field_pic;
1537 if (
s->c.mb_y >=
s->c.mb_height) {
1542 s->c.intra_dc_precision == 2 &&
1543 s->c.q_scale_type == 1 &&
s->c.alternate_scan == 0 &&
1544 s->c.progressive_frame == 0
1547 if (
left >= 32 && !is_d10) {
1574 if (
s->c.mb_y >= ((
s->c.height + 15) >> 4) &&
1575 !
s->c.progressive_sequence &&
1578 mb_skip_run == -1 &&
1586 if (mb_skip_run == -1) {
1599 }
else if (
code == 35) {
1600 if (mb_skip_run != 0 ||
show_bits(&
s->gb, 15) != 0) {
1608 mb_skip_run +=
code;
1616 "skipped MB in I-frame at %d %d\n",
s->c.mb_x,
s->c.mb_y);
1622 for (
i = 0;
i < 12;
i++)
1623 s->c.block_last_index[
i] = -1;
1624 s->last_dc[0] =
s->last_dc[1] =
s->last_dc[2] = 128 <<
s->c.intra_dc_precision;
1632 s->c.mv[0][0][0] =
s->c.mv[0][0][1] = 0;
1633 s->c.last_mv[0][0][0] =
s->c.last_mv[0][0][1] = 0;
1634 s->c.last_mv[0][1][0] =
s->c.last_mv[0][1][1] = 0;
1635 s->c.field_select[0][0] = (
s->c.picture_structure - 1) & 1;
1638 s->c.mv[0][0][0] =
s->c.last_mv[0][0][0];
1639 s->c.mv[0][0][1] =
s->c.last_mv[0][0][1];
1640 s->c.mv[1][0][0] =
s->c.last_mv[1][0][0];
1641 s->c.mv[1][0][1] =
s->c.last_mv[1][0][1];
1642 s->c.field_select[0][0] = (
s->c.picture_structure - 1) & 1;
1643 s->c.field_select[1][0] = (
s->c.picture_structure - 1) & 1;
1654 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);
1661 const uint8_t *buf =
s->gb.buffer;
1663 int mb_y =
s->c.start_mb_y;
1664 const int field_pic =
s->c.picture_structure !=
PICT_FRAME;
1666 s->c.er.error_count = (3 * (
s->c.end_mb_y -
s->c.start_mb_y) *
s->c.mb_width) >> field_pic;
1673 ff_dlog(
c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1674 ret,
s->c.resync_mb_x,
s->c.resync_mb_y,
s->c.mb_x,
s->c.mb_y,
1675 s->c.start_mb_y,
s->c.end_mb_y,
s->c.er.error_count);
1679 if (
s->c.resync_mb_x >= 0 &&
s->c.resync_mb_y >= 0)
1681 s->c.mb_x,
s->c.mb_y,
1685 s->c.mb_x - 1,
s->c.mb_y,
1689 if (
s->c.mb_y ==
s->c.end_mb_y)
1698 mb_y += (*buf&0xE0)<<2;
1702 if (mb_y >=
s->c.end_mb_y)
1714 MPVContext *
const s = &s1->
slice.
c;
1716 if (!
s->context_initialized || !
s->cur_pic.ptr)
1719 if (
s->avctx->hwaccel) {
1723 "hardware accelerator failed to decode picture\n");
1745 if (
s->last_pic.ptr && !
s->last_pic.ptr->dummy) {
1762 const uint8_t *buf,
int buf_size)
1765 MPVContext *
const s = &s1->
slice.
c;
1778 "Invalid horizontal or vertical size value.\n");
1795 if (
check_marker(
s->avctx, gb,
"in sequence header") == 0) {
1799 s->avctx->rc_buffer_size =
get_bits(gb, 10) * 1024 * 16;
1806 for (
i = 0;
i < 64;
i++) {
1807 j =
s->idsp.idct_permutation[
i];
1809 s->intra_matrix[j] = v;
1810 s->chroma_intra_matrix[j] = v;
1816 for (
i = 0;
i < 64;
i++) {
1817 int j =
s->idsp.idct_permutation[
i];
1819 s->inter_matrix[j] = v;
1820 s->chroma_inter_matrix[j] = v;
1833 s->progressive_sequence = 1;
1834 s->progressive_frame = 1;
1837 s->frame_pred_frame_dct = 1;
1845 av_log(
s->avctx,
AV_LOG_DEBUG,
"vbv buffer: %d, bitrate:%"PRId64
", aspect_ratio_info: %d \n",
1854 MPVContext *
const s = &s1->
slice.
c;
1858 if (
s->context_initialized)
1870 if (!
s->avctx->lowres)
1871 for (
int i = 0;
i <
s->slice_context_count;
i++)
1874 for (
i = 0;
i < 64;
i++) {
1875 int j =
s->idsp.idct_permutation[
i];
1877 s->intra_matrix[j] = v;
1878 s->chroma_intra_matrix[j] = v;
1881 s->inter_matrix[j] = v;
1882 s->chroma_inter_matrix[j] = v;
1885 s->progressive_sequence = 1;
1886 s->progressive_frame = 1;
1889 s->frame_pred_frame_dct = 1;
1891 if (
s->codec_tag ==
AV_RL32(
"BW10")) {
1916 const uint8_t *p,
int buf_size)
1922 p[0] ==
'G' && p[1] ==
'A' && p[2] ==
'9' && p[3] ==
'4' &&
1923 p[4] == 3 && (p[5] & 0x40)) {
1925 int cc_count = p[5] & 0x1f;
1926 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
1928 const uint64_t new_size = (old_size + cc_count
1937 memcpy(s1->
a53_buf_ref->
data + old_size, p + 7, cc_count * UINT64_C(3));
1944 p[0] == 0x03 && (p[1]&0x7f) == 0x01) {
1956 const uint64_t new_size = (old_size + cc_count
1963 uint8_t field, cc1, cc2;
1966 memset(cap, 0, cc_count * 3);
1976 cap[0] = cap[1] = cap[2] = 0x00;
1978 field = (field == 2 ? 1 : 0);
1979 if (!s1->
slice.
c.top_field_first) field = !field;
1980 cap[0] = 0x04 | field;
1993 p[0] ==
'C' && p[1] ==
'C' && p[2] == 0x01 && p[3] == 0xf8) {
2023 for (
i = 5;
i + 6 <= buf_size && ((p[
i] & 0xfe) == 0xfe);
i += 6)
2028 const uint64_t new_size = (old_size + cc_count
2035 uint8_t field1 = !!(p[4] & 0x80);
2038 for (
i = 0;
i < cc_count;
i++) {
2039 cap[0] = (p[0] == 0xff && field1) ? 0xfc : 0xfd;
2042 cap[3] = (p[3] == 0xff && !field1) ? 0xfc : 0xfd;
2055 p[0] == 0x05 && p[1] == 0x02) {
2057 const uint8_t cc_header = 0xf8 | 0x04 | 0x00 ;
2058 uint8_t cc_data[4] = {0};
2060 uint8_t cc_type = p[7];
2064 if (cc_type == 0x05 && buf_size >= 7) {
2070 if (cc_type == 0x02 && buf_size >= 4) {
2080 if (cc_type == 0x04 && (cc_data[0] & 0x7f) < 32) {
2082 cc_data[2] = cc_data[0];
2083 cc_data[3] = cc_data[1];
2085 }
else if (cc_type == 0x04 && buf_size >= 5) {
2096 const uint64_t new_size = (old_size + cc_count * UINT64_C(3));
2104 cap[1] = cc_data[0];
2105 cap[2] = cc_data[1];
2106 if (cc_count == 2) {
2108 cap[4] = cc_data[2];
2109 cap[5] = cc_data[3];
2121 const uint8_t *p,
int buf_size)
2123 const uint8_t *buf_end = p + buf_size;
2128 for(
i=0; !(!p[
i-2] && !p[
i-1] && p[
i]==1) &&
i<buf_size;
i++){
2137 if (!memcmp(p+
i,
"\0TMPGEXS\0", 9)){
2142 if (buf_end - p >= 5 &&
2143 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2151 if (buf_end - p < 1)
2154 s1->
afd = p[0] & 0x0f;
2156 }
else if (buf_end - p >= 6 &&
2157 p[0] ==
'J' && p[1] ==
'P' && p[2] ==
'3' && p[3] ==
'D' &&
2160 const uint8_t S3D_video_format_type = p[5] & 0x7F;
2162 if (S3D_video_format_type == 0x03 ||
2163 S3D_video_format_type == 0x04 ||
2164 S3D_video_format_type == 0x08 ||
2165 S3D_video_format_type == 0x23) {
2169 switch (S3D_video_format_type) {
2190 const uint8_t *buf,
int buf_size)
2193 MPVContext *
const s = &s1->
slice.
c;
2214 "GOP (%s) closed_gop=%d broken_link=%d\n",
2226 MPVContext *
const s2 = &
s->slice.c;
2227 int error_count = 0;
2230 s2->mpeg12_contexts,
NULL,
2231 s->slice_count,
sizeof(s2->mpeg12_contexts[0]));
2233 for (
int i = 0;
i <
s->slice_count;
i++) {
2239 if ((
unsigned)slice_err > INT_MAX - error_count) {
2240 error_count = INT_MAX;
2243 error_count += slice_err;
2251 int *got_output,
const uint8_t *buf,
int buf_size)
2254 MPVContext *
const s2 = &
s->slice.c;
2255 const uint8_t *buf_ptr = buf;
2256 const uint8_t *buf_end = buf + buf_size;
2257 int ret, input_size;
2258 int last_code = 0, skip_frame = 0;
2259 int picture_start_code_seen = 0;
2278 return FFMAX(0, buf_ptr - buf);
2281 input_size = buf_end - buf_ptr;
2290 if (last_code == 0) {
2296 "ignoring SEQ_START_CODE after %X\n", last_code);
2303 if (picture_start_code_seen && s2->picture_structure ==
PICT_FRAME) {
2309 picture_start_code_seen = 1;
2318 if (s2->width <= 0 || s2->height <= 0) {
2320 s2->width, s2->height);
2325 s2->intra_dc_precision= 3;
2326 s2->intra_matrix[0]= 1;
2328 if (
s->slice_count) {
2336 "mpeg_decode_postinit() failure\n");
2347 "ignoring pic after %X\n", last_code);
2361 if (last_code == 0) {
2365 "ignoring seq ext after %X\n", last_code);
2386 "ignoring pic cod ext after %X\n", last_code);
2398 if (last_code == 0) {
2399 s2->first_field = 0;
2406 "ignoring GOP_START_CODE after %X\n", last_code);
2414 if (s2->progressive_sequence && !s2->progressive_frame) {
2415 s2->progressive_frame = 1;
2417 "interlaced frame in progressive sequence, ignoring\n");
2420 if (s2->picture_structure == 0 ||
2421 (s2->progressive_frame && s2->picture_structure !=
PICT_FRAME)) {
2423 "picture_structure %d invalid, ignoring\n",
2424 s2->picture_structure);
2428 if (s2->progressive_sequence && !s2->frame_pred_frame_dct)
2432 s2->first_field = 0;
2433 s2->v_edge_pos = 16 * s2->mb_height;
2435 s2->first_field ^= 1;
2436 s2->v_edge_pos = 8 * s2->mb_height;
2437 memset(s2->mbskip_table, 0, s2->mb_stride * s2->mb_height);
2442 const int field_pic = s2->picture_structure !=
PICT_FRAME;
2446 mb_y += (*buf_ptr&0xE0)<<2;
2452 if (buf_end - buf_ptr < 2) {
2457 if (mb_y >= s2->mb_height) {
2459 "slice below image (%d >= %d)\n", mb_y, s2->mb_height);
2463 if (!s2->last_pic.ptr) {
2467 if (!
s->closed_gop) {
2470 "Skipping B slice due to open GOP\n");
2477 if (!s2->next_pic.ptr) {
2483 "Skipping P slice due to !sync\n");
2496 if (!s2->context_initialized)
2500 if (mb_y < avctx->skip_top ||
2505 if (!s2->pict_type) {
2512 if (
s->first_slice) {
2518 if (!s2->cur_pic.ptr) {
2520 "current_picture not initialized\n");
2527 int threshold = (s2->mb_height *
s->slice_count +
2528 s2->slice_context_count / 2) /
2529 s2->slice_context_count;
2530 if (threshold <= mb_y) {
2533 thread_context->
c.start_mb_y = mb_y;
2534 thread_context->
c.end_mb_y = s2->mb_height;
2535 if (
s->slice_count) {
2536 s2->thread_context[
s->slice_count - 1]->end_mb_y = mb_y;
2553 if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0)
2555 s2->resync_mb_y, s2->mb_x, s2->mb_y,
2559 s2->resync_mb_y, s2->mb_x - 1, s2->mb_y,
2572 const uint8_t *buf = avpkt->
data;
2574 int buf_size = avpkt->
size;
2576 MPVContext *
const s2 = &
s->slice.c;
2580 if (s2->low_delay == 0 && s2->next_pic.ptr) {
2592 if (!s2->context_initialized &&
2593 (s2->codec_tag ==
AV_RL32(
"VCR2") || s2->codec_tag ==
AV_RL32(
"BW10")))
2598 if (avctx->
extradata && !
s->extradata_decoded) {
2606 s->extradata_decoded = 1;
2614 if (
ret<0 || *got_output) {
2617 if (
s->timecode_frame_start != -1 && *got_output) {
2624 memcpy(tcside->
data, &
s->timecode_frame_start,
sizeof(
int64_t));
2629 s->timecode_frame_start = -1;
2656 .p.name =
"mpeg1video",
2670#if CONFIG_MPEG1_NVDEC_HWACCEL
2673#if CONFIG_MPEG1_NVDEC_CUARRAY_HWACCEL
2676#if CONFIG_MPEG1_VDPAU_HWACCEL
2679#if CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL
2686#define M2V_OFFSET(x) offsetof(Mpeg1Context, x)
2687#define M2V_PARAM AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2690 {
"cc_format",
"extract a specific Closed Captions format",
2708 .class_name =
"MPEG-2 video",
2716 .p.name =
"mpeg2video",
2732#if CONFIG_MPEG2_DXVA2_HWACCEL
2735#if CONFIG_MPEG2_D3D11VA_HWACCEL
2738#if CONFIG_MPEG2_D3D11VA2_HWACCEL
2741#if CONFIG_MPEG2_D3D12VA_HWACCEL
2744#if CONFIG_MPEG2_NVDEC_HWACCEL
2747#if CONFIG_MPEG2_NVDEC_CUARRAY_HWACCEL
2750#if CONFIG_MPEG2_VAAPI_HWACCEL
2753#if CONFIG_MPEG2_VDPAU_HWACCEL
2756#if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
2765 .p.name =
"mpegvideo",
2790 MPVContext *
const m = &
s->m.c;
2792 int16_t (*
const block)[64] =
s->m.block;
2796 if (avpkt->
size*8LL < (avctx->
width+15)/16 * ((avctx->
height+15)/16) * (2LL + 3*4 + 2*2 + 2*6))
2808 m->intra_dc_precision =
s->flags & 3;
2809 m->q_scale_type = !!(
s->flags & 0x40);
2810 m->intra_vlc_format = !!(
s->flags & 0x20);
2811 m->alternate_scan = !!(
s->flags & 0x10);
2815 m->idsp.idct_permutation);
2817 s->m.last_dc[0] =
s->m.last_dc[1] =
s->m.last_dc[2] = 128 << (
s->flags & 3);
2820 for (
int y = 0; y < avctx->
height; y += 16) {
2823 for (
int x = 0; x < avctx->
width; x += 16) {
2844 for (
int n = 0; n < 6; n++) {
2845 if (
s->flags & 0x80) {
2848 m->intra_scantable.permutated,
2859 m->idsp.idct_put(
frame->data[0] + y *
frame->linesize[0] + x,
2861 m->idsp.idct_put(
frame->data[0] + y *
frame->linesize[0] + x + 8,
2863 m->idsp.idct_put(
frame->data[0] + (y + 8) *
frame->linesize[0] + x,
2865 m->idsp.idct_put(
frame->data[0] + (y + 8) *
frame->linesize[0] + x + 8,
2867 m->idsp.idct_put(
frame->data[1] + (y >> 1) *
frame->linesize[1] + (x >> 1),
2869 m->idsp.idct_put(
frame->data[2] + (y >> 1) *
frame->linesize[2] + (x >> 1),
2886 MPVContext *
const m = &
s->m.c;
2894 for (
int i = 0;
i < 64;
i++) {
2895 int j = m->idsp.idct_permutation[
i];
2897 m->intra_matrix[j] = v;
2898 m->chroma_intra_matrix[j] = v;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
static double val(void *priv, double ch)
static const char *const format[]
const FFCodec ff_mpeg1video_decoder
const FFCodec ff_mpeg2video_decoder
const FFCodec ff_ipu_decoder
const FFCodec ff_mpegvideo_decoder
#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_DEBUG_STARTCODE
#define FF_DEBUG_PICT_INFO
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define SLICE_MAX_START_CODE
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters if all frames are skipped due to the skip_frame setting...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
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.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
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.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
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, int *decode_error_flags)
Indicate that a frame has finished decoding and perform error concealment in case it has been enabled...
static int decode_slice(AVCodecContext *c, void *arg)
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
#define GET_CACHE(name, gb)
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_sbits(GetBitContext *s, int n)
#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 const uint8_t * align_get_bits(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static int get_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#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_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, 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.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
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, size_t size)
Add a new side data to a frame.
@ 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.
const char * av_default_item_name(void *ptr)
Return the context name.
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.
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.
#define LIBAVUTIL_VERSION_INT
AVStereo3DType
List of possible 3D Types.
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 FF_HW_SIMPLE_CALL(avctx, function)
#define FF_HW_CALL(avctx, function,...)
#define HWACCEL_NVDEC_CUARRAY(codec)
#define HWACCEL_DXVA2(codec)
#define HWACCEL_VDPAU(codec)
#define HWACCEL_D3D12VA(codec)
#define HWACCEL_NVDEC(codec)
#define HWACCEL_VAAPI(codec)
#define HWACCEL_D3D11VA(codec)
#define HWACCEL_VIDEOTOOLBOX(codec)
#define HWACCEL_D3D11VA2(codec)
static int shift(int a, int b)
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Macro definitions for various function/variable attributes.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_PTR_ADD(ptr, off)
const uint8_t ff_reverse[256]
static enum AVPixelFormat pix_fmts[]
@ AV_CLASS_CATEGORY_DECODER
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
const uint8_t ff_zigzag_direct[64]
static av_const int sign_extend(int val, unsigned bits)
static const VLCElem * rl_vlc[2]
VLCElem ff_mb_pat_vlc[512]
VLCElem ff_mbincr_vlc[538]
RL_VLC_ELEM ff_mpeg1_rl_vlc[680]
RL_VLC_ELEM ff_mpeg2_rl_vlc[674]
av_cold void ff_mpeg12_init_vlcs(void)
VLCElem ff_mb_btype_vlc[64]
VLCElem ff_mb_ptype_vlc[64]
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 PICTURE_START_CODE
#define SLICE_MIN_START_CODE
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_sequence_display_extension(Mpeg1Context *const s1, GetBitContext *const gb)
static const AVOption mpeg2video_options[]
static void mpeg_decode_picture_display_extension(Mpeg1Context *const s1, GetBitContext *const gb)
static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size)
#define DECODE_SLICE_ERROR
static void mpeg_decode_sequence_extension(Mpeg1Context *const s1, GetBitContext *const gb)
static int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s, int16_t *block, int n)
static void mpeg_decode_quant_matrix_extension(MPVContext *const s, GetBitContext *const gb)
static const AVClass mpeg2video_class
static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y, const uint8_t **buf, int buf_size)
Decode a slice.
static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int mpeg1_decode_block_inter(Mpeg12SliceContext *const s, int16_t *block, int n)
static int slice_decode_thread(AVCodecContext *c, void *arg)
static enum AVPixelFormat mpeg12_pixfmt_list_422[]
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
#define check_scantable_index(ctx, x)
static int mpeg_decode_picture_coding_extension(Mpeg1Context *const s1, GetBitContext *const gb)
static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
static int mpeg1_decode_sequence(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int vcr2_init_sequence(AVCodecContext *avctx)
static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_output, AVPacket *avpkt)
static int mpeg_decode_motion(Mpeg12SliceContext *const s, int fcode, int pred)
static enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[]
static enum AVPixelFormat mpeg12_pixfmt_list_444[]
Mpeg2ClosedCaptionsFormat
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
static int load_matrix(MPVContext *const s, GetBitContext *const gb, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
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 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 slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
static void mpeg12_execute_slice_threads(AVCodecContext *avctx, Mpeg1Context *const s)
static int mpeg_decode_gop(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int mpeg2_decode_block_intra(Mpeg12SliceContext *const s, int16_t *block, int n)
static int get_dmv(Mpeg12SliceContext *const s)
static int mpeg_decode_postinit(AVCodecContext *avctx)
static void mpeg_set_cc_format(AVCodecContext *avctx, enum Mpeg2ClosedCaptionsFormat format, const char *label)
static int decode_dc(GetBitContext *gb, int component)
#define MB_BTYPE_VLC_BITS
#define MB_PTYPE_VLC_BITS
void ff_mpeg_er_frame_start(MpegEncContext *s)
void ff_mpv_unref_picture(MPVWorkPicture *pic)
static void ff_mpv_framesize_disable(ScratchpadContext *sc)
Disable allocating the ScratchpadContext's buffers in future calls to ff_mpv_framesize_alloc().
#define MB_TYPE_MV_2_MV_DIR(a)
#define MB_TYPE_INTERLACED
#define MB_TYPE_FORWARD_MV
#define PICT_BOTTOM_FIELD
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
av_cold void ff_mpv_common_end(MpegEncContext *s)
void ff_init_block_index(MpegEncContext *s)
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
#define MV_TYPE_16X8
2 vectors, one per 16x8 block
#define MV_TYPE_DMV
2 vectors, special mpeg2 Dual Prime Vectors
#define MV_TYPE_FIELD
2 vectors, one per field
#define MV_TYPE_16X16
1 vector for the whole mb
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
void ff_mpv_frame_end(MpegEncContext *s)
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
int ff_mpv_alloc_dummy_frames(MpegEncContext *s)
Ensure that the dummy frames are allocated according to pict_type if necessary.
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
const uint8_t ff_alternate_vertical_scan[64]
mpegvideo decoder header.
#define FF_MPV_QSCALE_TYPE_MPEG2
static int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
@ AVCHROMA_LOC_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_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
@ 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_CUARRAY
hardware decoding through openharmony
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
const AVProfile ff_mpeg2_video_profiles[]
static const float pred[4]
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
#define atomic_load_explicit(object, order)
#define atomic_store_explicit(object, desired, order)
A reference to a data buffer.
uint8_t * data
The data buffer.
size_t size
Size of data in bytes.
Describe the class of an AVClass context structure.
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.
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.
int level
Encoding level descriptor.
int64_t bit_rate
the average bitrate
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.
int64_t rc_max_rate
maximum bitrate
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
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.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
AVDictionary * metadata
metadata.
This structure stores compressed data.
int width
width and height in 1/16 pel
int16_t position[3][2]
position of the top left corner in 1/16 pel for up to 3 fields/frames
Rational number (pair of numerator and denominator).
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
enum AVStereo3DType type
How views are packed within the video.
DECLARE_ALIGNED_32(int16_t, block)[12][64]
int last_dc[3]
last DC values
unsigned frame_rate_index
unsigned aspect_ratio_info
enum Mpeg2ClosedCaptionsFormat cc_format
int64_t timecode_frame_start
AVBufferRef * a53_buf_ref
AVRational frame_rate_ext
enum AVStereo3DType stereo3d_type
struct MpegEncContext * thread_context[MAX_THREADS]
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 struct color_info *a, const struct color_info *b, const int trans_thresh)