mpeg12dec.c File Reference

MPEG-1/2 decoder. More...

#include "libavutil/internal.h"
#include "internal.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "error_resilience.h"
#include "mpeg12.h"
#include "mpeg12data.h"
#include "mpeg12decdata.h"
#include "bytestream.h"
#include "vdpau_internal.h"
#include "xvmc_internal.h"
#include "thread.h"
Include dependency graph for mpeg12dec.c:

Go to the source code of this file.

Data Structures

struct  Mpeg1Context
 

Macros

#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
 

Typedefs

typedef struct Mpeg1Context Mpeg1Context
 

Functions

static int mpeg_decode_motion (MpegEncContext *s, int fcode, int pred)
 
static int mpeg1_decode_block_intra (MpegEncContext *s, int16_t *block, int n)
 
int ff_mpeg1_decode_block_intra (MpegEncContext *s, int16_t *block, int n)
 
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)
 Note: this function can read out of range and crash for corrupt streams. More...
 
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)
 Note: this function can read out of range and crash for corrupt streams. More...
 
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)
 Note: this function can read out of range and crash for corrupt streams. More...
 
static int get_dmv (MpegEncContext *s)
 
static int get_qscale (MpegEncContext *s)
 
static void exchange_uv (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 int uses_vdpau (AVCodecContext *avctx)
 
static enum AVPixelFormat mpeg_get_pixelformat (AVCodecContext *avctx)
 
static void setup_hwaccel_for_pixfmt (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 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 int mpeg_decode_end (AVCodecContext *avctx)
 

Variables

static enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420 []
 
static enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420 []
 
static const AVProfile mpeg2_video_profiles []
 
AVCodec ff_mpeg1video_decoder
 
AVCodec ff_mpeg2video_decoder
 
AVCodec ff_mpegvideo_decoder
 

Detailed Description

MPEG-1/2 decoder.

Definition in file mpeg12dec.c.

Macro Definition Documentation

#define DECODE_SLICE_ERROR   -1

Definition at line 1573 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

#define DECODE_SLICE_OK   0

Definition at line 1574 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

#define MT_16X8   2

Definition at line 645 of file mpeg12dec.c.

#define MT_DMV   3

Definition at line 646 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define MT_FIELD   1

Definition at line 643 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define MT_FRAME   2

Definition at line 644 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

Typedef Documentation

typedef struct Mpeg1Context Mpeg1Context

Function Documentation

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

Definition at line 2113 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

static void exchange_uv ( MpegEncContext s)
static

Definition at line 633 of file mpeg12dec.c.

Referenced by mpeg_decode_mb(), and vcr2_init_sequence().

int ff_mpeg1_decode_block_intra ( MpegEncContext s,
int16_t *  block,
int  n 
)

Definition at line 158 of file mpeg12dec.c.

Referenced by decode_dc(), and tqi_decode_mb().

static void flush ( AVCodecContext avctx)
static

Definition at line 2464 of file mpeg12dec.c.

static int get_dmv ( MpegEncContext s)
inlinestatic

Definition at line 615 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

static int get_qscale ( MpegEncContext s)
inlinestatic

Definition at line 623 of file mpeg12dec.c.

Referenced by mpeg_decode_mb(), and mpeg_decode_slice().

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

Definition at line 1410 of file mpeg12dec.c.

Referenced by mpeg1_decode_sequence(), and mpeg_decode_quant_matrix_extension().

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

Definition at line 163 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Definition at line 87 of file mpeg12dec.c.

Referenced by ff_mpeg1_decode_block_intra(), and mpeg_decode_mb().

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

Definition at line 1272 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 1913 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Note: this function can read out of range and crash for corrupt streams.

Changing this would eat up any speed benefits it has. Do not use "fast" flag if you need the code to be robust.

Definition at line 243 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Definition at line 461 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Definition at line 315 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Note: this function can read out of range and crash for corrupt streams.

Changing this would eat up any speed benefits it has. Do not use "fast" flag if you need the code to be robust.

Definition at line 544 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Note: this function can read out of range and crash for corrupt streams.

Changing this would eat up any speed benefits it has. Do not use "fast" flag if you need the code to be robust.

Definition at line 399 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

static int mpeg_decode_end ( AVCodecContext avctx)
static

Definition at line 2473 of file mpeg12dec.c.

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

Definition at line 2402 of file mpeg12dec.c.

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

Definition at line 2086 of file mpeg12dec.c.

Referenced by decode_chunks().

static av_cold int mpeg_decode_init ( AVCodecContext avctx)
static

Definition at line 1029 of file mpeg12dec.c.

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

Definition at line 648 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

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

Definition at line 59 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

static void mpeg_decode_picture_coding_extension ( Mpeg1Context s1)
static

Definition at line 1442 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_picture_display_extension ( Mpeg1Context s1)
static

Definition at line 1377 of file mpeg12dec.c.

Referenced by decode_chunks().

static int mpeg_decode_postinit ( AVCodecContext avctx)
static

Definition at line 1161 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_quant_matrix_extension ( MpegEncContext s)
static

Definition at line 1432 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_display_extension ( Mpeg1Context s1)
static

Definition at line 1353 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_extension ( Mpeg1Context s1)
static

Definition at line 1317 of file mpeg12dec.c.

Referenced by decode_chunks().

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 1582 of file mpeg12dec.c.

Referenced by decode_chunks(), and slice_decode_thread().

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

Definition at line 1060 of file mpeg12dec.c.

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

Definition at line 2050 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 1501 of file mpeg12dec.c.

Referenced by decode_chunks().

static enum AVPixelFormat mpeg_get_pixelformat ( AVCodecContext avctx)
static

Definition at line 1128 of file mpeg12dec.c.

Referenced by mpeg_decode_postinit(), and vcr2_init_sequence().

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

Definition at line 1081 of file mpeg12dec.c.

Referenced by mpeg_decode_postinit().

static void setup_hwaccel_for_pixfmt ( AVCodecContext avctx)
static

Definition at line 1144 of file mpeg12dec.c.

Referenced by mpeg_decode_postinit(), and vcr2_init_sequence().

static int slice_decode_thread ( AVCodecContext c,
void arg 
)
static

Definition at line 1816 of file mpeg12dec.c.

Referenced by decode_chunks().

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 1863 of file mpeg12dec.c.

Referenced by decode_chunks(), and decode_frame().

static int uses_vdpau ( AVCodecContext avctx)
inlinestatic

Definition at line 1124 of file mpeg12dec.c.

Referenced by decode_chunks(), and setup_hwaccel_for_pixfmt().

static int vcr2_init_sequence ( AVCodecContext avctx)
static

Definition at line 1996 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

Variable Documentation

AVCodec ff_mpeg1video_decoder
Initial value:
= {
.name = "mpeg1video",
.priv_data_size = sizeof(Mpeg1Context),
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define CODEC_CAP_TRUNCATED
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
Definition: mpeg12dec.c:1029
static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from)
Definition: mpeg12dec.c:1060
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: mpeg12dec.c:2402
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static void flush(AVCodecContext *avctx)
Definition: mpeg12dec.c:2464
static int mpeg_decode_end(AVCodecContext *avctx)
Definition: mpeg12dec.c:2473
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
struct Mpeg1Context Mpeg1Context

Definition at line 2495 of file mpeg12dec.c.

AVCodec ff_mpeg2video_decoder
Initial value:
= {
.name = "mpeg2video",
.priv_data_size = sizeof(Mpeg1Context),
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
}
static const AVProfile mpeg2_video_profiles[]
Definition: mpeg12dec.c:2482
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define CODEC_CAP_TRUNCATED
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
Definition: mpeg12dec.c:1029
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
preferred ID for MPEG-1/2 video decoding
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: mpeg12dec.c:2402
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static void flush(AVCodecContext *avctx)
Definition: mpeg12dec.c:2464
static int mpeg_decode_end(AVCodecContext *avctx)
Definition: mpeg12dec.c:2473
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
struct Mpeg1Context Mpeg1Context

Definition at line 2512 of file mpeg12dec.c.

AVCodec ff_mpegvideo_decoder
Initial value:
= {
.name = "mpegvideo",
.priv_data_size = sizeof(Mpeg1Context),
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define CODEC_CAP_TRUNCATED
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
Definition: mpeg12dec.c:1029
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
preferred ID for MPEG-1/2 video decoding
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_output, AVPacket *avpkt)
Definition: mpeg12dec.c:2402
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static void flush(AVCodecContext *avctx)
Definition: mpeg12dec.c:2464
static int mpeg_decode_end(AVCodecContext *avctx)
Definition: mpeg12dec.c:2473
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
struct Mpeg1Context Mpeg1Context

Definition at line 2530 of file mpeg12dec.c.

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

Definition at line 1094 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

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

Definition at line 1106 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

const AVProfile mpeg2_video_profiles[]
static
Initial value:
= {
{ FF_PROFILE_MPEG2_422, "4:2:2" },
{ FF_PROFILE_MPEG2_HIGH, "High" },
{ FF_PROFILE_MPEG2_SS, "Spatially Scalable" },
{ FF_PROFILE_MPEG2_SNR_SCALABLE, "SNR Scalable" },
{ FF_PROFILE_MPEG2_MAIN, "Main" },
{ FF_PROFILE_MPEG2_SIMPLE, "Simple" },
{ FF_PROFILE_RESERVED, "Reserved" },
{ FF_PROFILE_RESERVED, "Reserved" },
}
#define FF_PROFILE_MPEG2_SNR_SCALABLE
#define FF_PROFILE_MPEG2_SS
#define FF_PROFILE_RESERVED
#define FF_PROFILE_UNKNOWN
#define FF_PROFILE_MPEG2_MAIN
#define FF_PROFILE_MPEG2_HIGH
#define FF_PROFILE_MPEG2_SIMPLE
#define FF_PROFILE_MPEG2_422

Definition at line 2482 of file mpeg12dec.c.