mpeg12.c File Reference

MPEG-1/2 decoder. More...

#include "internal.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "mpeg12.h"
#include "mpeg12data.h"
#include "mpeg12decdata.h"
#include "bytestream.h"
#include "vdpau_internal.h"
#include "xvmc_internal.h"
#include "thread.h"

Go to the source code of this file.

Macros

#define MV_VLC_BITS   9
#define MBINCR_VLC_BITS   9
#define MB_PAT_VLC_BITS   9
#define MB_PTYPE_VLC_BITS   6
#define MB_BTYPE_VLC_BITS   6
#define check_scantable_index(ctx, x)
#define INIT_2D_VLC_RL(rl, static_size)
#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, DCTELEM *block, int n)
int ff_mpeg1_decode_block_intra (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg1_decode_block_inter (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg1_fast_decode_block_inter (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg2_decode_block_non_intra (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg2_fast_decode_block_non_intra (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg2_decode_block_intra (MpegEncContext *s, DCTELEM *block, int n)
static int mpeg2_fast_decode_block_intra (MpegEncContext *s, DCTELEM *block, int n)
static void init_2d_vlc_rl (RLTable *rl)
void ff_mpeg12_common_init (MpegEncContext *s)
void ff_mpeg1_clean_buffers (MpegEncContext *s)
av_cold void ff_mpeg12_init_vlcs (void)
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, DCTELEM 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 PixelFormat 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.
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)
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.
static int decode_chunks (AVCodecContext *avctx, AVFrame *picture, int *data_size, const uint8_t *buf, int buf_size)
static int mpeg_decode_frame (AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
static void flush (AVCodecContext *avctx)
static int mpeg_decode_end (AVCodecContext *avctx)

Variables

static VLC mv_vlc
uint8_t ff_mpeg12_static_rl_table_store [2][2][2 *MAX_RUN+MAX_LEVEL+3]
VLC ff_dc_lum_vlc
VLC ff_dc_chroma_vlc
static VLC mbincr_vlc
static VLC mb_ptype_vlc
static VLC mb_btype_vlc
static VLC mb_pat_vlc
static enum PixelFormat pixfmt_xvmc_mpg2_420 []
static const AVProfile mpeg2_video_profiles []
AVCodec ff_mpeg1video_decoder
AVCodec ff_mpeg2video_decoder

Detailed Description

MPEG-1/2 decoder.

Definition in file mpeg12.c.

Macro Definition Documentation

#define check_scantable_index (   ctx,
 
)
Value:
do { \
if ((x) > 63) { \
av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
ctx->mb_x, ctx->mb_y); \
} \
} while (0) \

Definition at line 83 of file mpeg12.c.

Referenced by mpeg1_decode_block_intra(), 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().

#define DECODE_SLICE_ERROR   -1

Definition at line 1628 of file mpeg12.c.

Referenced by mpeg_decode_slice().

#define DECODE_SLICE_OK   0

Definition at line 1629 of file mpeg12.c.

Referenced by mpeg_decode_slice().

#define INIT_2D_VLC_RL (   rl,
  static_size 
)
Value:
{\
static RL_VLC_ELEM rl_vlc_table[static_size];\
INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
&rl.table_vlc[0][1], 4, 2,\
&rl.table_vlc[0][0], 4, 2, static_size);\
\
rl.rl_vlc[0] = rl_vlc_table;\
init_2d_vlc_rl(&rl);\
}

Definition at line 605 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs().

#define MB_BTYPE_VLC_BITS   6

Definition at line 50 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and mpeg_decode_mb().

#define MB_PAT_VLC_BITS   9

Definition at line 48 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and mpeg_decode_mb().

#define MB_PTYPE_VLC_BITS   6

Definition at line 49 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and mpeg_decode_mb().

#define MBINCR_VLC_BITS   9

Definition at line 47 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and mpeg_decode_slice().

#define MT_16X8   2

Definition at line 744 of file mpeg12.c.

#define MT_DMV   3

Definition at line 745 of file mpeg12.c.

Referenced by mpeg_decode_mb().

#define MT_FIELD   1

Definition at line 742 of file mpeg12.c.

Referenced by mpeg_decode_mb().

#define MT_FRAME   2

Definition at line 743 of file mpeg12.c.

Referenced by mpeg_decode_mb().

#define MV_VLC_BITS   9

Definition at line 46 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and mpeg_decode_motion().

Function Documentation

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

Definition at line 2246 of file mpeg12.c.

Referenced by mpeg_decode_frame().

static void exchange_uv ( MpegEncContext s)
static

Definition at line 732 of file mpeg12.c.

Referenced by mpeg_decode_mb(), and vcr2_init_sequence().

void ff_mpeg12_common_init ( MpegEncContext s)

Definition at line 649 of file mpeg12.c.

Referenced by ff_mpeg1_encode_init(), and mpeg_decode_init().

av_cold void ff_mpeg12_init_vlcs ( void  )

Definition at line 677 of file mpeg12.c.

Referenced by decode_init(), mpeg_decode_init(), and tqi_decode_init().

void ff_mpeg1_clean_buffers ( MpegEncContext s)

Definition at line 657 of file mpeg12.c.

Referenced by encode_thread(), and mpeg_decode_slice().

int ff_mpeg1_decode_block_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)

Definition at line 161 of file mpeg12.c.

Referenced by tqi_decode_mb().

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.

Returns
the position of the first byte of the next frame, or -1

Definition at line 2138 of file mpeg12.c.

Referenced by mpeg_decode_frame(), and mpegvideo_parse().

static void flush ( AVCodecContext avctx)
static

Definition at line 2477 of file mpeg12.c.

static int get_dmv ( MpegEncContext s)
inlinestatic

Definition at line 714 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int get_qscale ( MpegEncContext s)
inlinestatic

Definition at line 722 of file mpeg12.c.

Referenced by mpeg_decode_mb(), and mpeg_decode_slice().

static void init_2d_vlc_rl ( RLTable rl)
static

Definition at line 616 of file mpeg12.c.

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

Definition at line 1460 of file mpeg12.c.

Referenced by mpeg1_decode_sequence(), and mpeg_decode_quant_matrix_extension().

static int mpeg1_decode_block_inter ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 166 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg1_decode_block_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 92 of file mpeg12.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 1324 of file mpeg12.c.

Referenced by decode_chunks().

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

Definition at line 1947 of file mpeg12.c.

Referenced by decode_chunks().

static int mpeg1_fast_decode_block_inter ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 241 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg2_decode_block_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 456 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg2_decode_block_non_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 315 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg2_fast_decode_block_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 532 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg2_fast_decode_block_non_intra ( MpegEncContext s,
DCTELEM block,
int  n 
)
inlinestatic

Definition at line 392 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static int mpeg_decode_end ( AVCodecContext avctx)
static

Definition at line 2487 of file mpeg12.c.

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

Definition at line 2202 of file mpeg12.c.

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

Definition at line 2103 of file mpeg12.c.

Referenced by decode_chunks().

static av_cold int mpeg_decode_init ( AVCodecContext avctx)
static

Definition at line 1119 of file mpeg12.c.

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

Definition at line 747 of file mpeg12.c.

Referenced by mpeg_decode_slice().

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

Definition at line 55 of file mpeg12.c.

Referenced by mpeg_decode_mb().

static void mpeg_decode_picture_coding_extension ( Mpeg1Context s1)
static

Definition at line 1492 of file mpeg12.c.

Referenced by decode_chunks().

static void mpeg_decode_picture_display_extension ( Mpeg1Context s1)
static

Definition at line 1427 of file mpeg12.c.

Referenced by decode_chunks().

static int mpeg_decode_postinit ( AVCodecContext avctx)
static

Definition at line 1213 of file mpeg12.c.

Referenced by decode_chunks().

static void mpeg_decode_quant_matrix_extension ( MpegEncContext s)
static

Definition at line 1482 of file mpeg12.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_display_extension ( Mpeg1Context s1)
static

Definition at line 1403 of file mpeg12.c.

Referenced by decode_chunks().

static void mpeg_decode_sequence_extension ( Mpeg1Context s1)
static

Definition at line 1366 of file mpeg12.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 1637 of file mpeg12.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 1150 of file mpeg12.c.

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

Definition at line 2081 of file mpeg12.c.

Referenced by decode_chunks().

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

Definition at line 1569 of file mpeg12.c.

Referenced by decode_chunks().

static enum PixelFormat mpeg_get_pixelformat ( AVCodecContext avctx)
static

Definition at line 1189 of file mpeg12.c.

Referenced by 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 1171 of file mpeg12.c.

static int slice_decode_thread ( AVCodecContext c,
void arg 
)
static

Definition at line 1858 of file mpeg12.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 1901 of file mpeg12.c.

Referenced by decode_chunks(), and decode_frame().

static int vcr2_init_sequence ( AVCodecContext avctx)
static

Definition at line 2026 of file mpeg12.c.

Referenced by mpeg_decode_frame().

Variable Documentation

VLC ff_dc_chroma_vlc

Definition at line 670 of file mpeg12.c.

VLC ff_dc_lum_vlc

Definition at line 669 of file mpeg12.c.

uint8_t ff_mpeg12_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]

Definition at line 603 of file mpeg12.c.

Referenced by ff_mpeg12_init_vlcs(), and ff_mpeg1_encode_init().

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

Definition at line 2509 of file mpeg12.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"),
}

Definition at line 2524 of file mpeg12.c.

VLC mb_btype_vlc
static

Definition at line 674 of file mpeg12.c.

VLC mb_pat_vlc
static

Definition at line 675 of file mpeg12.c.

VLC mb_ptype_vlc
static

Definition at line 673 of file mpeg12.c.

VLC mbincr_vlc
static

Definition at line 672 of file mpeg12.c.

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 2496 of file mpeg12.c.

VLC mv_vlc
static

Definition at line 52 of file mpeg12.c.

enum PixelFormat pixfmt_xvmc_mpg2_420[]
static
Initial value:

Definition at line 1184 of file mpeg12.c.

Referenced by mpeg_get_pixelformat().