Libav
Data Structures | Macros | Functions | Variables
mpeg12dec.c File Reference

MPEG-1/2 decoder. More...

#include <inttypes.h>
#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "libavutil/stereo3d.h"
#include "avcodec.h"
#include "bytestream.h"
#include "error_resilience.h"
#include "idctdsp.h"
#include "internal.h"
#include "mpeg_er.h"
#include "mpeg12.h"
#include "mpeg12data.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
#include "profiles.h"
#include "thread.h"
#include "version.h"
#include "xvmc_internal.h"

Go to the source code of this file.

Data Structures

struct  Mpeg1Context
 

Macros

#define MB_TYPE_ZERO_MV   0x20000000
 
#define MAX_INDEX   (64 - 1)
 
#define check_scantable_index(ctx, x)
 
#define MT_FIELD   1
 
#define MT_FRAME   2
 
#define MT_16X8   2
 
#define MT_DMV   3
 
#define DECODE_SLICE_ERROR   -1
 
#define DECODE_SLICE_OK   0
 

Functions

static int mpeg_decode_motion (MpegEncContext *s, int fcode, int pred)
 
static int mpeg1_decode_block_inter (MpegEncContext *s, int16_t *block, int n)
 
static int mpeg1_fast_decode_block_inter (MpegEncContext *s, int16_t *block, int n)
 
static int mpeg2_decode_block_non_intra (MpegEncContext *s, int16_t *block, int n)
 
static int mpeg2_fast_decode_block_non_intra (MpegEncContext *s, int16_t *block, int n)
 
static int mpeg2_decode_block_intra (MpegEncContext *s, int16_t *block, int n)
 
static int mpeg2_fast_decode_block_intra (MpegEncContext *s, int16_t *block, int n)
 
static int get_dmv (MpegEncContext *s)
 
static int get_qscale (MpegEncContext *s)
 
static int mpeg_decode_mb (MpegEncContext *s, int16_t block[12][64])
 
static av_cold int mpeg_decode_init (AVCodecContext *avctx)
 
static int mpeg_decode_update_thread_context (AVCodecContext *avctx, const AVCodecContext *avctx_from)
 
static void quant_matrix_rebuild (uint16_t *matrix, const uint8_t *old_perm, const uint8_t *new_perm)
 
static enum AVPixelFormat mpeg_get_pixelformat (AVCodecContext *avctx)
 
static int mpeg_decode_postinit (AVCodecContext *avctx)
 
static int mpeg1_decode_picture (AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 
static void mpeg_decode_sequence_extension (Mpeg1Context *s1)
 
static void mpeg_decode_sequence_display_extension (Mpeg1Context *s1)
 
static void mpeg_decode_picture_display_extension (Mpeg1Context *s1)
 
static int load_matrix (MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
 
static void mpeg_decode_quant_matrix_extension (MpegEncContext *s)
 
static void mpeg_decode_picture_coding_extension (Mpeg1Context *s1)
 
static int mpeg_field_start (MpegEncContext *s, const uint8_t *buf, int buf_size)
 
static int mpeg_decode_slice (MpegEncContext *s, int mb_y, const uint8_t **buf, int buf_size)
 Decode a slice. More...
 
static int slice_decode_thread (AVCodecContext *c, void *arg)
 
static int slice_end (AVCodecContext *avctx, AVFrame *pict)
 Handle slice ends. More...
 
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_a53_cc (AVCodecContext *avctx, const uint8_t *p, int buf_size)
 
static void mpeg_decode_user_data (AVCodecContext *avctx, const uint8_t *p, int buf_size)
 
static void mpeg_decode_gop (AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 
static int decode_chunks (AVCodecContext *avctx, AVFrame *picture, int *got_output, const uint8_t *buf, int buf_size)
 
static int mpeg_decode_frame (AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
 
static void flush (AVCodecContext *avctx)
 
static av_cold int mpeg_decode_end (AVCodecContext *avctx)
 

Variables

static const uint32_t ptype2mb_type [7]
 
static const uint32_t btype2mb_type [11]
 
static const uint8_t non_linear_qscale [32]
 
static enum AVPixelFormat mpeg12_hwaccel_pixfmt_list_420 []
 
static enum AVPixelFormat mpeg12_pixfmt_list_422 []
 
static enum AVPixelFormat mpeg12_pixfmt_list_444 []
 
AVCodec ff_mpeg1video_decoder
 
AVCodec ff_mpeg2video_decoder
 

Detailed Description

MPEG-1/2 decoder.

Definition in file mpeg12dec.c.

Macro Definition Documentation

◆ MB_TYPE_ZERO_MV

#define MB_TYPE_ZERO_MV   0x20000000

Definition at line 71 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ MAX_INDEX

#define MAX_INDEX   (64 - 1)

◆ check_scantable_index

#define check_scantable_index (   ctx,
 
)
Value:
do { \
if ((x) > MAX_INDEX) { \
av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
ctx->mb_x, ctx->mb_y); \
} \
} while (0)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define MAX_INDEX
Definition: mpeg12dec.c:131
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
AVFormatContext * ctx
Definition: movenc.c:48

Definition at line 132 of file mpeg12dec.c.

Referenced by mpeg1_decode_block_inter(), mpeg1_fast_decode_block_inter(), mpeg2_decode_block_intra(), mpeg2_decode_block_non_intra(), mpeg2_fast_decode_block_intra(), and mpeg2_fast_decode_block_non_intra().

◆ MT_FIELD

#define MT_FIELD   1

Definition at line 654 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ MT_FRAME

#define MT_FRAME   2

Definition at line 655 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ MT_16X8

#define MT_16X8   2

Definition at line 656 of file mpeg12dec.c.

◆ MT_DMV

#define MT_DMV   3

Definition at line 657 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ DECODE_SLICE_ERROR

#define DECODE_SLICE_ERROR   -1

Definition at line 1677 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

◆ DECODE_SLICE_OK

#define DECODE_SLICE_OK   0

Definition at line 1678 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

Function Documentation

◆ mpeg_decode_motion()

static int mpeg_decode_motion ( MpegEncContext s,
int  fcode,
int  pred 
)
static

Definition at line 105 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg1_decode_block_inter()

static int mpeg1_decode_block_inter ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 141 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg1_fast_decode_block_inter()

static int mpeg1_fast_decode_block_inter ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 226 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg2_decode_block_non_intra()

static int mpeg2_decode_block_non_intra ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 311 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg2_fast_decode_block_non_intra()

static int mpeg2_fast_decode_block_non_intra ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 397 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg2_decode_block_intra()

static int mpeg2_decode_block_intra ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 468 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ mpeg2_fast_decode_block_intra()

static int mpeg2_fast_decode_block_intra ( MpegEncContext s,
int16_t *  block,
int  n 
)
inlinestatic

Definition at line 553 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ get_dmv()

static int get_dmv ( MpegEncContext s)
inlinestatic

Definition at line 636 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ get_qscale()

static int get_qscale ( MpegEncContext s)
inlinestatic

Definition at line 644 of file mpeg12dec.c.

Referenced by mpeg_decode_mb(), and mpeg_decode_slice().

◆ mpeg_decode_mb()

static int mpeg_decode_mb ( MpegEncContext s,
int16_t  block[12][64] 
)
static

Definition at line 659 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

◆ mpeg_decode_init()

static av_cold int mpeg_decode_init ( AVCodecContext avctx)
static

Definition at line 1057 of file mpeg12dec.c.

◆ mpeg_decode_update_thread_context()

static int mpeg_decode_update_thread_context ( AVCodecContext avctx,
const AVCodecContext avctx_from 
)
static

Definition at line 1084 of file mpeg12dec.c.

◆ quant_matrix_rebuild()

static void quant_matrix_rebuild ( uint16_t *  matrix,
const uint8_t old_perm,
const uint8_t new_perm 
)
static

Definition at line 1112 of file mpeg12dec.c.

Referenced by mpeg_decode_postinit().

◆ mpeg_get_pixelformat()

static enum AVPixelFormat mpeg_get_pixelformat ( AVCodecContext avctx)
static

Definition at line 1159 of file mpeg12dec.c.

Referenced by mpeg_decode_postinit(), and vcr2_init_sequence().

◆ mpeg_decode_postinit()

static int mpeg_decode_postinit ( AVCodecContext avctx)
static

Definition at line 1184 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg1_decode_picture()

static int mpeg1_decode_picture ( AVCodecContext avctx,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 1302 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_sequence_extension()

static void mpeg_decode_sequence_extension ( Mpeg1Context s1)
static

Definition at line 1346 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_sequence_display_extension()

static void mpeg_decode_sequence_display_extension ( Mpeg1Context s1)
static

Definition at line 1392 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_picture_display_extension()

static void mpeg_decode_picture_display_extension ( Mpeg1Context s1)
static

Definition at line 1416 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ load_matrix()

static int load_matrix ( MpegEncContext s,
uint16_t  matrix0[64],
uint16_t  matrix1[64],
int  intra 
)
static

Definition at line 1450 of file mpeg12dec.c.

Referenced by mpeg1_decode_sequence(), and mpeg_decode_quant_matrix_extension().

◆ mpeg_decode_quant_matrix_extension()

static void mpeg_decode_quant_matrix_extension ( MpegEncContext s)
static

Definition at line 1473 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_picture_coding_extension()

static void mpeg_decode_picture_coding_extension ( Mpeg1Context s1)
static

Definition at line 1487 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_field_start()

static int mpeg_field_start ( MpegEncContext s,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 1565 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_slice()

static int mpeg_decode_slice ( MpegEncContext s,
int  mb_y,
const uint8_t **  buf,
int  buf_size 
)
static

Decode a slice.

MpegEncContext.mb_y must be set to the MB row from the startcode.

Returns
DECODE_SLICE_ERROR if the slice is damaged, DECODE_SLICE_OK if this slice is OK

Definition at line 1686 of file mpeg12dec.c.

Referenced by decode_chunks(), and slice_decode_thread().

◆ slice_decode_thread()

static int slice_decode_thread ( AVCodecContext c,
void arg 
)
static

Definition at line 1932 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ slice_end()

static int slice_end ( AVCodecContext avctx,
AVFrame pict 
)
static

Handle slice ends.

Returns
1 if it seems to be the last slice

Definition at line 1980 of file mpeg12dec.c.

Referenced by decode_chunks(), decode_frame(), filter_slice(), filter_slice_chroma(), and filter_slice_luma().

◆ mpeg1_decode_sequence()

static int mpeg1_decode_sequence ( AVCodecContext avctx,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 2033 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ vcr2_init_sequence()

static int vcr2_init_sequence ( AVCodecContext avctx)
static

Definition at line 2120 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

◆ mpeg_decode_a53_cc()

static int mpeg_decode_a53_cc ( AVCodecContext avctx,
const uint8_t p,
int  buf_size 
)
static

Definition at line 2174 of file mpeg12dec.c.

Referenced by mpeg_decode_user_data().

◆ mpeg_decode_user_data()

static void mpeg_decode_user_data ( AVCodecContext avctx,
const uint8_t p,
int  buf_size 
)
static

Definition at line 2227 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ mpeg_decode_gop()

static void mpeg_decode_gop ( AVCodecContext avctx,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 2286 of file mpeg12dec.c.

Referenced by decode_chunks().

◆ decode_chunks()

static int decode_chunks ( AVCodecContext avctx,
AVFrame picture,
int *  got_output,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 2319 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

◆ mpeg_decode_frame()

static int mpeg_decode_frame ( AVCodecContext avctx,
void data,
int *  got_output,
AVPacket avpkt 
)
static

Definition at line 2585 of file mpeg12dec.c.

◆ flush()

static void flush ( AVCodecContext avctx)
static

Definition at line 2634 of file mpeg12dec.c.

◆ mpeg_decode_end()

static av_cold int mpeg_decode_end ( AVCodecContext avctx)
static

Definition at line 2644 of file mpeg12dec.c.

Variable Documentation

◆ ptype2mb_type

const uint32_t ptype2mb_type[7]
static
Initial value:
= {
MB_TYPE_L0 | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
}
#define MB_TYPE_INTRA
Definition: mpegutils.h:75
#define MB_TYPE_QUANT
Definition: avcodec.h:1101
#define MB_TYPE_16x16
Definition: avcodec.h:1085
#define MB_TYPE_CBP
Definition: avcodec.h:1102
#define MB_TYPE_ZERO_MV
Definition: mpeg12dec.c:71
#define MB_TYPE_L0
Definition: avcodec.h:1098

Definition at line 73 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ btype2mb_type

const uint32_t btype2mb_type[11]
static
Initial value:
= {
MB_TYPE_L1 | MB_TYPE_CBP,
MB_TYPE_L0 | MB_TYPE_CBP,
MB_TYPE_L0L1 | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
}
#define MB_TYPE_INTRA
Definition: mpegutils.h:75
#define MB_TYPE_QUANT
Definition: avcodec.h:1101
#define MB_TYPE_L0L1
Definition: avcodec.h:1100
#define MB_TYPE_L1
Definition: avcodec.h:1099
#define MB_TYPE_CBP
Definition: avcodec.h:1102
#define MB_TYPE_L0
Definition: avcodec.h:1098

Definition at line 83 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

◆ non_linear_qscale

const uint8_t non_linear_qscale[32]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7,
8, 10, 12, 14, 16, 18, 20, 22,
24, 28, 32, 36, 40, 44, 48, 52,
56, 64, 72, 80, 88, 96, 104, 112,
}

Definition at line 97 of file mpeg12dec.c.

Referenced by get_qscale().

◆ mpeg12_hwaccel_pixfmt_list_420

enum AVPixelFormat mpeg12_hwaccel_pixfmt_list_420[]
static
Initial value:
= {
}
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59

Definition at line 1132 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

◆ mpeg12_pixfmt_list_422

enum AVPixelFormat mpeg12_pixfmt_list_422[]
static
Initial value:
= {
}
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63

Definition at line 1149 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

◆ mpeg12_pixfmt_list_444

enum AVPixelFormat mpeg12_pixfmt_list_444[]
static
Initial value:
= {
}
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:64

Definition at line 1154 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

◆ ff_mpeg1video_decoder

AVCodec ff_mpeg1video_decoder
Initial value:
= {
.name = "mpeg1video",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
.priv_data_size = sizeof(Mpeg1Context),
.close = mpeg_decode_end,
}
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
Definition: mpeg12dec.c:1057
static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from)
Definition: mpeg12dec.c:1084
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:863
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:188
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:832
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
Definition: mpeg12dec.c:2644
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:897
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: mpeg12dec.c:2585
#define AV_CODEC_CAP_TRUNCATED
Definition: avcodec.h:839
static void flush(AVCodecContext *avctx)
Definition: mpeg12dec.c:2634
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838

Definition at line 2654 of file mpeg12dec.c.

◆ ff_mpeg2video_decoder

AVCodec ff_mpeg2video_decoder
Initial value:
= {
.name = "mpeg2video",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
.priv_data_size = sizeof(Mpeg1Context),
.close = mpeg_decode_end,
}
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
Definition: mpeg12dec.c:1057
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:863
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
const AVProfile ff_mpeg2_video_profiles[]
Definition: profiles.c:83
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:832
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
static av_cold int mpeg_decode_end(AVCodecContext *avctx)
Definition: mpeg12dec.c:2644
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:198
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:897
static const AVProfile profiles[]
Definition: libdcadec.c:181
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: mpeg12dec.c:2585
#define AV_CODEC_CAP_TRUNCATED
Definition: avcodec.h:839
static void flush(AVCodecContext *avctx)
Definition: mpeg12dec.c:2634
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838

Definition at line 2670 of file mpeg12dec.c.