FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
mpeg12dec.c File Reference

MPEG-1/2 decoder. More...

#include "libavutil/attributes.h"
#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 "bytestream.h"
#include "vdpau_internal.h"
#include "xvmc_internal.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  Mpeg1Context
 

Macros

#define MB_TYPE_ZERO_MV   0x20000000
 
#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_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.
 
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.
 
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.
 
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.
 
static int slice_decode_thread (AVCodecContext *c, void *arg)
 
static int slice_end (AVCodecContext *avctx, AVFrame *pict)
 Handle slice ends.
 
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 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 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 MB_TYPE_ZERO_MV   0x20000000

Definition at line 57 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define MT_FIELD   1

Definition at line 675 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define MT_FRAME   2

Definition at line 676 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define MT_16X8   2

Definition at line 677 of file mpeg12dec.c.

#define MT_DMV   3

Definition at line 678 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

#define DECODE_SLICE_ERROR   -1

Definition at line 1606 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

#define DECODE_SLICE_OK   0

Definition at line 1607 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

Function Documentation

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

Definition at line 91 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 119 of file mpeg12dec.c.

Referenced by ff_mpeg1_decode_block_intra(), and mpeg_decode_mb().

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

Definition at line 190 of file mpeg12dec.c.

Referenced by tqi_decode_mb().

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

Definition at line 195 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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 275 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 347 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 431 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 493 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 576 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

static int get_dmv ( MpegEncContext s)
inlinestatic

Definition at line 647 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

static int get_qscale ( MpegEncContext s)
inlinestatic

Definition at line 655 of file mpeg12dec.c.

Referenced by mpeg_decode_mb(), and mpeg_decode_slice().

static void exchange_uv ( MpegEncContext s)
static

Definition at line 665 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Definition at line 680 of file mpeg12dec.c.

Referenced by mpeg_decode_slice().

static av_cold int mpeg_decode_init ( AVCodecContext avctx)
static

Definition at line 1059 of file mpeg12dec.c.

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

Definition at line 1090 of file mpeg12dec.c.

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

Definition at line 1111 of file mpeg12dec.c.

static int uses_vdpau ( AVCodecContext avctx)
inlinestatic

Definition at line 1156 of file mpeg12dec.c.

Referenced by decode_chunks(), and setup_hwaccel_for_pixfmt().

static enum AVPixelFormat mpeg_get_pixelformat ( AVCodecContext avctx)
static

Definition at line 1160 of file mpeg12dec.c.

Referenced by vcr2_init_sequence().

static void setup_hwaccel_for_pixfmt ( AVCodecContext avctx)
static

Definition at line 1176 of file mpeg12dec.c.

Referenced by vcr2_init_sequence().

static int mpeg_decode_postinit ( AVCodecContext avctx)
static

Definition at line 1193 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 1305 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_extension ( Mpeg1Context s1)
static

Definition at line 1350 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_display_extension ( Mpeg1Context s1)
static

Definition at line 1386 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_picture_display_extension ( Mpeg1Context s1)
static

Definition at line 1410 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 1443 of file mpeg12dec.c.

Referenced by mpeg1_decode_sequence(), and mpeg_decode_quant_matrix_extension().

static void mpeg_decode_quant_matrix_extension ( MpegEncContext s)
static

Definition at line 1465 of file mpeg12dec.c.

Referenced by decode_chunks().

static void mpeg_decode_picture_coding_extension ( Mpeg1Context s1)
static

Definition at line 1475 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 1534 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 1615 of file mpeg12dec.c.

Referenced by decode_chunks(), and slice_decode_thread().

static int slice_decode_thread ( AVCodecContext c,
void arg 
)
static

Definition at line 1849 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 1896 of file mpeg12dec.c.

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

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

Definition at line 1946 of file mpeg12dec.c.

Referenced by decode_chunks().

static int vcr2_init_sequence ( AVCodecContext avctx)
static

Definition at line 2029 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

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

Definition at line 2083 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 2119 of file mpeg12dec.c.

Referenced by decode_chunks().

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

Definition at line 2146 of file mpeg12dec.c.

Referenced by mpeg_decode_frame().

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

Definition at line 2451 of file mpeg12dec.c.

static void flush ( AVCodecContext avctx)
static

Definition at line 2513 of file mpeg12dec.c.

static av_cold int mpeg_decode_end ( AVCodecContext avctx)
static

Definition at line 2522 of file mpeg12dec.c.

Variable Documentation

const uint32_t ptype2mb_type[7]
static
Initial value:

Definition at line 59 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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,
}

Definition at line 69 of file mpeg12dec.c.

Referenced by mpeg_decode_mb().

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

Referenced by get_qscale().

enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[]
static
Initial value:

Definition at line 1124 of file mpeg12dec.c.

Referenced by mpeg_get_pixelformat().

enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[]
static
Initial value:

Definition at line 1137 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" },
}

Definition at line 2531 of file mpeg12dec.c.

AVCodec ff_mpeg1video_decoder
Initial value:

Definition at line 2544 of file mpeg12dec.c.

AVCodec ff_mpeg2video_decoder
Initial value:

Definition at line 2561 of file mpeg12dec.c.

AVCodec ff_mpegvideo_decoder
Initial value:
= {
.name = "mpegvideo",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
.priv_data_size = sizeof(Mpeg1Context),
.max_lowres = 3,
}

Definition at line 2579 of file mpeg12dec.c.