28 #define UNCHECKED_BITSTREAM_READER 1
74 #define MB_TYPE_ZERO_MV 0x20000000
115 val = (val - 1) << shift;
127 #define MAX_INDEX (64 - 1)
128 #define check_scantable_index(ctx, x) \
130 if ((x) > MAX_INDEX) { \
131 av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
132 ctx->mb_x, ctx->mb_y); \
133 return AVERROR_INVALIDDATA; \
144 const int qscale = s->
qscale;
152 level = (3 * qscale * quant_matrix[0]) >> 5;
153 level = (level - 1) | 1;
172 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
173 level = (level - 1) | 1;
187 }
else if (level == 0) {
197 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
198 level = (level - 1) | 1;
201 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
202 level = (level - 1) | 1;
233 const int qscale = s->
qscale;
241 level = (3 * qscale) >> 1;
242 level = (level - 1) | 1;
262 level = ((level * 2 + 1) * qscale) >> 1;
263 level = (level - 1) | 1;
277 }
else if (level == 0) {
287 level = ((level * 2 + 1) * qscale) >> 1;
288 level = (level - 1) | 1;
291 level = ((level * 2 + 1) * qscale) >> 1;
292 level = (level - 1) | 1;
318 const uint16_t *quant_matrix;
319 const int qscale = s->
qscale;
335 level = (3 * qscale * quant_matrix[0]) >> 5;
356 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
373 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
376 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
390 block[63] ^= (mismatch & 1);
409 const int qscale = s->
qscale;
416 level = (3 * qscale) >> 1;
435 level = ((level * 2 + 1) * qscale) >> 1;
452 level = ((-level * 2 + 1) * qscale) >> 1;
455 level = ((level * 2 + 1) * qscale) >> 1;
482 const uint16_t *quant_matrix;
483 const int qscale = s->
qscale;
492 component = (n & 1) + 1;
502 mismatch = block[0] ^ 1;
519 }
else if (level != 0) {
524 level = (level * qscale * quant_matrix[j]) >> 4;
540 level = (-level * qscale * quant_matrix[j]) >> 4;
543 level = (level * qscale * quant_matrix[j]) >> 4;
552 block[63] ^= mismatch & 1;
572 const uint16_t *quant_matrix;
573 const int qscale = s->
qscale;
581 component = (n & 1) + 1;
604 if (level >= 64 || i > 63) {
606 }
else if (level != 0) {
609 level = (level * qscale * quant_matrix[j]) >> 4;
623 level = (-level * qscale * quant_matrix[j]) >> 4;
626 level = (level * qscale * quant_matrix[j]) >> 4;
670 int i, j, k, cbp,
val, mb_type, motion_type;
698 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
711 "Invalid mb type in I-frame at %d %d\n",
724 "Invalid mb type in P-frame at %d %d\n", s->
mb_x, s->
mb_y);
733 "Invalid mb type in B-frame at %d %d\n", s->
mb_x, s->
mb_y);
777 if ((CONFIG_MPEG1_XVMC_HWACCEL || CONFIG_MPEG2_XVMC_HWACCEL) && s->
pack_pblocks)
782 for (i = 0; i < 6; i++)
785 for (i = 0; i < mb_block_count; i++)
790 for (i = 0; i < 6; i++) {
846 s->
mv_dir = (mb_type >> 13) & 3;
848 switch (motion_type) {
853 for (i = 0; i < 2; i++) {
868 s->
mv[i][0][0] <<= 1;
869 s->
mv[i][0][1] <<= 1;
876 for (i = 0; i < 2; i++) {
879 for (j = 0; j < 2; j++) {
881 for (k = 0; k < 2; k++) {
885 s->
mv[i][j][k] =
val;
896 for (i = 0; i < 2; i++) {
898 for (j = 0; j < 2; j++) {
903 s->
mv[i][j][0] =
val;
908 s->
mv[i][j][1] =
val;
916 for (i = 0; i < 2; i++) {
919 for (k = 0; k < 2; k++) {
924 s->
mv[i][0][k] =
val;
936 for (i = 0; i < 2; i++) {
938 int dmx, dmy, mx, my, m;
947 s->
last_mv[i][0][1] >> my_shift);
951 s->
last_mv[i][0][1] = my << my_shift;
952 s->
last_mv[i][1][1] = my << my_shift;
966 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
967 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
969 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
970 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
974 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
975 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
986 "00 motion_type at %d %d\n", s->
mb_x, s->
mb_y);
996 if (mb_block_count > 6) {
997 cbp <<= mb_block_count - 6;
1003 "invalid cbp %d at %d %d\n", cbp, s->
mb_x, s->
mb_y);
1008 if ((CONFIG_MPEG1_XVMC_HWACCEL || CONFIG_MPEG2_XVMC_HWACCEL) && s->
pack_pblocks)
1013 for (i = 0; i < 6; i++) {
1021 cbp <<= 12 - mb_block_count;
1023 for (i = 0; i < mb_block_count; i++) {
1024 if (cbp & (1 << 11)) {
1035 for (i = 0; i < 6; i++) {
1043 for (i = 0; i < 6; i++) {
1055 for (i = 0; i < 12; i++)
1095 static int mpeg_decode_update_thread_context(
AVCodecContext *avctx,
1102 if (avctx == avctx_from ||
1103 !ctx_from->mpeg_enc_ctx_allocated ||
1104 !
s1->context_initialized)
1124 uint16_t temp_matrix[64];
1127 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1129 for (i = 0; i < 64; i++)
1130 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1134 #if CONFIG_MPEG1_XVMC_HWACCEL
1137 #if CONFIG_MPEG1_VDPAU_DECODER && FF_API_VDPAU
1140 #if CONFIG_MPEG1_VDPAU_HWACCEL
1148 #if CONFIG_MPEG2_XVMC_HWACCEL
1151 #if CONFIG_MPEG_VDPAU_DECODER && FF_API_VDPAU
1154 #if CONFIG_MPEG2_VDPAU_HWACCEL
1157 #if CONFIG_MPEG2_DXVA2_HWACCEL
1160 #if CONFIG_MPEG2_D3D11VA_HWACCEL
1163 #if CONFIG_MPEG2_VAAPI_HWACCEL
1166 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
1200 mpeg1_hwaccel_pixfmt_list_420 :
1215 || uses_vdpau(avctx)
1228 avctx->xvmc_acceleration = 2;
1273 ff_dlog(avctx,
"aspect A %d/%d\n",
1293 if ((
s1->mpeg_enc_ctx_allocated == 0) ||
1301 if (
s1->mpeg_enc_ctx_allocated) {
1306 s1->mpeg_enc_ctx_allocated = 0;
1367 s1->mpeg_enc_ctx_allocated = 1;
1377 int ref, f_code, vbv_delay;
1412 "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->
pict_type);
1422 int horiz_size_ext, vert_size_ext;
1438 s->
width |= (horiz_size_ext << 12);
1439 s->
height |= (vert_size_ext << 12);
1441 s->
bit_rate += (bit_rate_ext << 18) * 400LL;
1457 "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64
"\n",
1465 int color_description, w,
h;
1469 if (color_description) {
1505 for (i = 0; i < nofco; i++) {
1514 "pde (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
") (%"PRId16
",%"PRId16
")\n",
1521 uint16_t matrix1[64],
int intra)
1525 for (i = 0; i < 64; i++) {
1532 if (intra && i == 0 && v != 8) {
1568 "Missing picture start code, guessing missing values\n");
1695 "hardware accelerator failed to decode first field\n");
1700 for (i = 0; i < 4; i++) {
1716 #define DECODE_SLICE_ERROR -1
1717 #define DECODE_SLICE_OK 0
1785 const uint8_t *buf_end, *buf_start = *buf - 4;
1788 if (buf_end < *buf + buf_size)
1805 "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",
1825 if ((CONFIG_MPEG1_XVMC_HWACCEL || CONFIG_MPEG2_XVMC_HWACCEL) && s->
pack_pblocks)
1836 int motion_x, motion_y, dir, i;
1838 for (i = 0; i < 2; i++) {
1839 for (dir = 0; dir < 2; dir++) {
1842 motion_x = motion_y = 0;
1845 motion_x = s->
mv[dir][0][0];
1846 motion_y = s->
mv[dir][0][1];
1848 motion_x = s->
mv[dir][i][0];
1849 motion_y = s->
mv[dir][i][1];
1880 s->
mb_y += 1 << field_pic;
1892 if (left >= 32 && !is_d10) {
1944 }
else if (code == 35) {
1961 "skipped MB in I-frame at %d %d\n", s->
mb_x, s->
mb_y);
1967 for (i = 0; i < 12; i++)
1976 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
2015 ff_dlog(c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
2038 mb_y += (*buf&0xE0)<<2;
2042 if (mb_y < 0 || mb_y >= s->
end_mb_y)
2063 "hardware accelerator failed to decode picture\n");
2114 if (width == 0 || height == 0) {
2116 "Invalid horizontal or vertical size value.\n");
2144 for (i = 0; i < 64; i++) {
2154 for (i = 0; i < 64; i++) {
2216 for (i = 0; i < 64; i++) {
2246 const uint8_t *p,
int buf_size)
2250 if (buf_size >= 6 &&
2251 p[0] ==
'G' && p[1] ==
'A' && p[2] ==
'9' && p[3] ==
'4' &&
2252 p[4] == 3 && (p[5] & 0x40)) {
2254 int cc_count = p[5] & 0x1f;
2255 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
2263 }
else if (buf_size >= 11 &&
2264 p[0] ==
'C' && p[1] ==
'C' && p[2] == 0x01 && p[3] == 0xf8) {
2294 for (i = 5; i + 6 <= buf_size && ((p[i] & 0xfe) == 0xfe); i += 6)
2302 uint8_t field1 = !!(p[4] & 0x80);
2305 for (i = 0; i < cc_count; i++) {
2306 cap[0] = (p[0] == 0xff && field1) ? 0xfc : 0xfd;
2309 cap[3] = (p[3] == 0xff && !field1) ? 0xfc : 0xfd;
2323 const uint8_t *p,
int buf_size)
2326 const uint8_t *buf_end = p + buf_size;
2331 for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
2340 if (!memcmp(p+i,
"\0TMPGEXS\0", 9)){
2345 if (buf_end - p >= 5 &&
2346 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2354 if (buf_end - p < 1)
2362 s1->
afd = p[0] & 0x0f;
2364 }
else if (buf_end - p >= 6 &&
2365 p[0] ==
'J' && p[1] ==
'P' && p[2] ==
'3' && p[3] ==
'D' &&
2368 const uint8_t S3D_video_format_type = p[5] & 0x7F;
2370 if (S3D_video_format_type == 0x03 ||
2371 S3D_video_format_type == 0x04 ||
2372 S3D_video_format_type == 0x08 ||
2373 S3D_video_format_type == 0x23) {
2377 switch (S3D_video_format_type) {
2407 tc = s-> timecode_frame_start =
get_bits(&s->
gb, 25);
2409 #if FF_API_PRIVATE_OPT
2425 "GOP (%s) closed_gop=%d broken_link=%d\n",
2431 int *got_output,
const uint8_t *
buf,
int buf_size)
2436 const uint8_t *buf_end = buf + buf_size;
2437 int ret, input_size;
2438 int last_code = 0, skip_frame = 0;
2439 int picture_start_code_seen = 0;
2445 if (start_code > 0x1ff) {
2461 if ((CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER)
2462 && uses_vdpau(avctx))
2483 input_size = buf_end - buf_ptr;
2487 start_code, buf_ptr - buf, input_size);
2490 switch (start_code) {
2492 if (last_code == 0) {
2498 "ignoring SEQ_START_CODE after %X\n", last_code);
2511 picture_start_code_seen = 1;
2538 "mpeg_decode_postinit() failure\n");
2549 "ignoring pic after %X\n", last_code);
2559 if (last_code == 0) {
2563 "ignoring seq ext after %X\n", last_code);
2582 "ignoring pic cod ext after %X\n", last_code);
2593 if (last_code == 0) {
2599 "ignoring GOP_START_CODE after %X\n", last_code);
2610 "interlaced frame in progressive sequence, ignoring\n");
2616 "picture_structure %d invalid, ignoring\n",
2639 mb_y += (*buf_ptr&0xE0)<<2;
2645 if (buf_end - buf_ptr < 2) {
2652 "slice below image (%d >= %d)\n", mb_y, s2->
mb_height);
2689 if (mb_y < avctx->skip_top ||
2709 "current_picture not initialized\n");
2714 if (uses_vdpau(avctx)) {
2727 if (threshold <= mb_y) {
2770 int buf_size = avpkt->
size;
2794 (
const uint8_t **) &buf, &buf_size) < 0)
2821 ret =
decode_chunks(avctx, picture, got_output, buf, buf_size);
2822 if (ret<0 || *got_output) {
2860 .
name =
"mpeg1video",
2877 .
name =
"mpeg2video",
2895 .
name =
"mpegvideo",
2909 #if CONFIG_MPEG_XVMC_DECODER
2918 ff_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2923 avctx->xvmc_acceleration = 2;
2928 AVCodec ff_mpeg_xvmc_decoder = {
2929 .
name =
"mpegvideo_xvmc",
2932 .id = AV_CODEC_ID_MPEG2VIDEO_XVMC,
2934 .
init = mpeg_mc_decode_init,
2946 #if CONFIG_MPEG_VDPAU_DECODER && FF_API_VDPAU
2947 AVCodec ff_mpeg_vdpau_decoder = {
2948 .
name =
"mpegvideo_vdpau",
2962 #if CONFIG_MPEG1_VDPAU_DECODER && FF_API_VDPAU
2963 AVCodec ff_mpeg1_vdpau_decoder = {
2964 .
name =
"mpeg1video_vdpau",
static const uint32_t btype2mb_type[11]
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
const struct AVCodec * codec
const char const char void * val
discard all frames except keyframes
void ff_init_block_index(MpegEncContext *s)
int64_t timecode_frame_start
GOP timecode frame start number, in non drop frame format.
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define SLICE_MAX_START_CODE
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG-2 field pics)
static int shift(int a, int b)
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
This structure describes decoded (raw) audio or video data.
static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm, const uint8_t *new_perm)
ptrdiff_t const GLvoid * data
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
#define MV_TYPE_FIELD
2 vectors, one per field
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
int coded_width
Bitstream width / height, may be different from width/height e.g.
static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
av_cold void ff_mpeg12_init_vlcs(void)
MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstr...
int64_t bit_rate
the average bitrate
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.
hardware decoding through Videotoolbox
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
static av_cold int init(AVCodecContext *avctx)
uint16_t chroma_intra_matrix[64]
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
uint16_t chroma_inter_matrix[64]
void ff_er_frame_end(ERContext *s)
static int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n)
Note: this function can read out of range and crash for corrupt streams.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
int repeat_pict
When decoding, this signals how much the picture must be delayed.
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
void(* clear_blocks)(int16_t *blocks)
static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
void ff_mpeg1_clean_buffers(MpegEncContext *s)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
AVCodec ff_mpeg1video_decoder
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).
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
#define AV_EF_BITSTREAM
detect bitstream specification deviations
static void mpeg_decode_gop(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define SLICE_MIN_START_CODE
Views are next to each other.
static int get_dmv(MpegEncContext *s)
static int get_sbits(GetBitContext *s, int n)
int encoding
true if we are encoding (vs decoding)
Macro definitions for various function/variable attributes.
enum AVDiscard skip_frame
Skip decoding for selected frames.
const uint8_t ff_mpeg2_non_linear_qscale[32]
struct AVHWAccel * hwaccel
Hardware accelerator in use.
#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 USES_LIST(a, list)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
static const uint32_t ptype2mb_type[7]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
enum OutputFormat out_format
output format
#define FF_DEBUG_PICT_INFO
static av_cold int end(AVCodecContext *avctx)
const float ff_mpeg1_aspect[16]
Multithreading support functions.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void ff_mpv_decode_mb(MpegEncContext *s, int16_t block[12][64])
static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
static int mpeg1_fast_decode_block_inter(MpegEncContext *s, int16_t *block, int n)
Note: this function can read out of range and crash for corrupt streams.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Picture current_picture
copy of the current picture structure.
The data is the AVPanScan struct defined in libavcodec.
void ff_xvmc_init_block(MpegEncContext *s)
Initialize the block field of the MpegEncContext pointer passed as parameter after making sure that t...
Structure to hold side data for an AVFrame.
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.
#define PICT_BOTTOM_FIELD
static int get_bits_count(const GetBitContext *s)
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...
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstr...
av_cold void ff_mpv_idct_init(MpegEncContext *s)
int mb_height
number of MBs horizontally & vertically
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int codec_tag
internal codec_tag upper case converted from avctx codec_tag
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...
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, int buf_size, int slice_count)
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
static void setup_hwaccel_for_pixfmt(AVCodecContext *avctx)
Libavcodec version macros.
static int get_bits_left(GetBitContext *gb)
int slice_context_count
number of used thread_contexts
#define UPDATE_CACHE(name, gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int last_dc[3]
last DC values for MPEG-1
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
#define PTRDIFF_SPECIFIER
int mb_skipped
MUST BE SET only during DECODING.
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int mpeg1_decode_block_inter(MpegEncContext *s, int16_t *block, int n)
int active_thread_type
Which multithreading methods are in use by the codec.
AVCodec ff_mpegvideo_decoder
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
ATSC A53 Part 4 Closed Captions.
static int get_qscale(MpegEncContext *s)
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
int width
width and height in 1/16 pel
int low_delay
no reordering needed / has no B-frames
static void mpeg_decode_user_data(AVCodecContext *avctx, const uint8_t *p, int buf_size)
The GOP timecode in 25 bit timecode format.
#define CLOSE_READER(name, gb)
void ff_mpv_common_end(MpegEncContext *s)
static int decode_dc(GetBitContext *gb, int component)
attribute_deprecated int64_t timecode_frame_start
#define DECODE_SLICE_ERROR
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void ff_mpeg_flush(AVCodecContext *avctx)
#define SKIP_BITS(name, gb, num)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int resync_mb_x
x position of last resync marker
int rc_buffer_size
decoder bitstream buffer size
common internal API header
static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
const AVProfile ff_mpeg2_video_profiles[]
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
static int mpeg2_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n)
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
enum AVPictureType pict_type
Picture type of the frame.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define FF_THREAD_FRAME
Decode more than one frame at once.
static int vcr2_init_sequence(AVCodecContext *avctx)
static const uint8_t start_code[]
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for B-frame encodin...
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
#define MB_TYPE_INTERLACED
int16_t(*[2] motion_val)[2]
Picture * current_picture_ptr
pointer to the current picture
void ff_mpeg_er_frame_start(MpegEncContext *s)
static int mpeg_decode_a53_cc(AVCodecContext *avctx, const uint8_t *p, int buf_size)
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
#define MB_BTYPE_VLC_BITS
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
#define LAST_SKIP_BITS(name, gb, num)
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
int16_t(*[12] pblocks)[64]
int block_last_index[12]
last non zero coefficient in block
#define AV_EF_EXPLODE
abort decoding on minor error detection
uint8_t idct_permutation[64]
IDCT input permutation.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int mpeg_enc_ctx_allocated
#define check_scantable_index(ctx, x)
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
preferred ID for MPEG-1/2 video decoding
RL_VLC_ELEM * rl_vlc[32]
decoding only
#define SHOW_UBITS(name, gb, num)
void ff_mpv_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static int mpeg1_decode_sequence(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static const float pred[4]
int first_field
is 1 for the first field of a field picture 0 otherwise
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define MV_TYPE_16X16
1 vector for the whole mb
static int mpeg2_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
enum AVStereo3DType type
How views are packed within the video.
uint16_t inter_matrix[64]
static enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[]
int concealment_motion_vectors
struct MpegEncContext * thread_context[MAX_THREADS]
Libavcodec external API header.
AVRational frame_rate_ext
static int mpeg2_fast_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
Note: this function can read out of range and crash for corrupt streams.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Views are next to each other, but when upscaling apply a checkerboard pattern.
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
#define MB_PTYPE_VLC_BITS
main external API structure.
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define OPEN_READER(name, gb)
#define MV_TYPE_16X8
2 vectors, one per 16x8 block
static int mpeg_decode_slice(MpegEncContext *s, int mb_y, const uint8_t **buf, int buf_size)
Decode a slice.
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
int slice_flags
slice flags
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
static void skip_bits(GetBitContext *s, int n)
static const AVProfile profiles[]
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
int closed_gop
MPEG1/2 GOP is closed.
unsigned int avpriv_toupper4(unsigned int x)
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
static enum AVPixelFormat mpeg12_pixfmt_list_422[]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define GET_CACHE(name, gb)
const uint16_t ff_mpeg1_default_intra_matrix[256]
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.
const uint8_t ff_zigzag_direct[64]
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
attribute_deprecated int dtg_active_format
DTG active format information (additional aspect ratio information only used in DVB MPEG-2 transport ...
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int *got_output, const uint8_t *buf, int buf_size)
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static enum AVPixelFormat pix_fmts[]
av_cold void ff_mpeg12_common_init(MpegEncContext *s)
#define AV_CODEC_CAP_TRUNCATED
static av_const int sign_extend(int val, unsigned bits)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int skip_bottom
Number of macroblock rows at the bottom which are skipped.
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
the normal 219*2^(n-8) "MPEG" YUV ranges
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
#define SHOW_SBITS(name, gb, num)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
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)
discard all non reference
const AVRational ff_mpeg2_aspect[16]
static enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
static int ref[MAX_W *MAX_W]
AVCodec ff_mpeg2video_decoder
static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
Video is not stereoscopic (and metadata has to be there).
const uint8_t * buffer_end
static void flush(AVCodecContext *avctx)
Picture * last_picture_ptr
pointer to the previous picture.
static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
const uint8_t ff_alternate_vertical_scan[64]
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
int16_t position[3][2]
position of the top left corner in 1/16 pel for up to 3 fields/frames
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
static int mpeg_decode_postinit(AVCodecContext *avctx)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define FF_DEBUG_STARTCODE
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
#define FF_ENABLE_DEPRECATION_WARNINGS
void ff_mpv_frame_end(MpegEncContext *s)
#define MV_TYPE_DMV
2 vectors, special mpeg2 Dual Prime Vectors
int resync_mb_y
y position of last resync marker
int16_t(* block)[64]
points to one of the following blocks
ParseContext parse_context
#define FF_QSCALE_TYPE_MPEG2
VLC_TYPE(* table)[2]
code, bits
int64_t bit_rate
wanted bit rate
Views are on top of each other.
int key_frame
1 -> keyframe, 0-> not
static const uint8_t * align_get_bits(GetBitContext *s)
int flags2
AV_CODEC_FLAG2_*.
MpegEncContext mpeg_enc_ctx
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
#define SLICE_FLAG_CODED_ORDER
draw_horiz_band() is called in coded order instead of display
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
uint32_t * mb_type
types and macros are defined in mpegutils.h
ScanTable inter_scantable
if inter == intra then intra should be used to reduce the cache usage
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
#define PICTURE_START_CODE
static int skip_1stop_8data_bits(GetBitContext *gb)
HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer...
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
static int slice_decode_thread(AVCodecContext *c, void *arg)
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
static enum AVPixelFormat mpeg12_pixfmt_list_444[]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
This structure stores compressed data.
void ff_mpv_report_decode_progress(MpegEncContext *s)
const AVRational ff_mpeg12_frame_rate_tab[16]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
#define AV_TIMECODE_STR_SIZE
int64_t rc_max_rate
maximum bitrate