FFmpeg
Loading...
Searching...
No Matches
mpeg4videodec.c File Reference
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "codec_internal.h"
#include "error_resilience.h"
#include "hwconfig.h"
#include "idctdsp.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
#include "mpegvideodec.h"
#include "mpegvideo_unquantize.h"
#include "mpeg4video.h"
#include "mpeg4videodata.h"
#include "mpeg4videodec.h"
#include "mpeg4videodefs.h"
#include "h263.h"
#include "h263data.h"
#include "h263dec.h"
#include "internal.h"
#include "profiles.h"
#include "qpeldsp.h"
#include "threadprogress.h"
#include "unary.h"

Go to the source code of this file.

Macros

#define UNCHECKED_BITSTREAM_READER   1
 
#define IS_3IV1   0
 
#define SPRITE_TRAJ_VLC_BITS   6
 
#define DC_VLC_BITS   9
 
#define MB_TYPE_B_VLC_BITS   4
 
#define STUDIO_INTRA_BITS   9
 

Functions

static Mpeg4DecContexth263_to_mpeg4 (H263DecContext *h)
 
static void gmc1_motion (MpegEncContext *s, const Mpeg4DecContext *ctx, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
 
static void gmc_motion (MpegEncContext *s, const Mpeg4DecContext *ctx, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
 
void ff_mpeg4_mcsel_motion (MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t *const *ref_picture)
 
void ff_mpeg4_decode_studio (MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int block_size, int uvlinesize, int dct_linesize, int dct_offset)
 
void ff_mpeg4_pred_ac (H263DecContext *const h, int16_t *block, int n, int dir)
 Predict the ac.
 
static int mpeg4_is_resync (Mpeg4DecContext *ctx)
 check if the next stuff is a resync marker or the end.
 
static int mpeg4_decode_sprite_trajectory (Mpeg4DecContext *ctx, GetBitContext *gb)
 
static int decode_new_pred (Mpeg4DecContext *ctx, GetBitContext *gb)
 
int ff_mpeg4_decode_video_packet_header (H263DecContext *const h)
 Decode the next video packet.
 
static void reset_studio_dc_predictors (Mpeg4DecContext *const ctx)
 
int ff_mpeg4_decode_studio_slice_header (H263DecContext *const h)
 Decode the next video packet.
 
static int get_amv (Mpeg4DecContext *ctx, int n)
 Get the average motion vector for a GMC MB.
 
static int mpeg4_pred_dc (MpegEncContext *s, int n, int *dir_ptr)
 Predict the dc.
 
static int mpeg4_get_level_dc (MpegEncContext *s, int n, int pred, int level)
 
static int mpeg4_decode_dc (H263DecContext *const h, int n, int *dir_ptr)
 Decode the dc value.
 
static int mpeg4_decode_partition_a (Mpeg4DecContext *ctx)
 Decode first partition.
 
static int mpeg4_decode_partition_b (H263DecContext *const h, int mb_count)
 decode second partition.
 
int ff_mpeg4_decode_partitions (H263DecContext *const h)
 Decode the first and second partition.
 
static int mpeg4_decode_block (Mpeg4DecContext *ctx, int16_t *block, int n, int coded, int intra, int use_intra_dc_vlc, int rvlc)
 Decode a block.
 
static int mpeg4_decode_partitioned_mb (H263DecContext *const h)
 decode partition C of one MB.
 
static int mpeg4_decode_mb (H263DecContext *const h)
 
static void next_start_code_studio (GetBitContext *gb)
 
static int mpeg4_decode_studio_block (Mpeg4DecContext *const ctx, int32_t block[64], int n)
 
static int mpeg4_decode_dpcm_macroblock (Mpeg4DecContext *const ctx, int16_t macroblock[256], int n)
 
static int mpeg4_decode_studio_mb (H263DecContext *const h)
 
static int mpeg4_decode_gop_header (MpegEncContext *s, GetBitContext *gb)
 
static int mpeg4_decode_profile_level (MpegEncContext *s, GetBitContext *gb, int *profile, int *level)
 
static int mpeg4_decode_visual_object (MpegEncContext *s, GetBitContext *gb)
 
static void mpeg4_load_default_matrices (MpegEncContext *s)
 
static int read_quant_matrix_ext (MpegEncContext *s, GetBitContext *gb)
 
static void extension_and_user_data (MpegEncContext *s, GetBitContext *gb, int id)
 
static int decode_studio_vol_header (Mpeg4DecContext *ctx, GetBitContext *gb)
 
static int decode_vol_header (Mpeg4DecContext *ctx, GetBitContext *gb)
 
static int decode_user_data (Mpeg4DecContext *ctx, GetBitContext *gb)
 Decode the user data stuff in the header.
 
static int decode_vop_header (Mpeg4DecContext *ctx, GetBitContext *gb, int parse_only)
 
static void decode_smpte_tc (Mpeg4DecContext *ctx, GetBitContext *gb)
 
static int decode_studio_vop_header (Mpeg4DecContext *ctx, GetBitContext *gb)
 Decode the next studio vop header.
 
static int decode_studiovisualobject (Mpeg4DecContext *ctx, GetBitContext *gb)
 
int ff_mpeg4_parse_picture_header (Mpeg4DecContext *ctx, GetBitContext *gb, int header, int parse_only)
 Decode MPEG-4 headers.
 

Variables

static VLCElem dc_lum [512]
 
static VLCElem dc_chrom [512]
 
static VLCElem sprite_trajectory [128]
 
static VLCElem mb_type_b_vlc [16]
 
static const VLCElemstudio_intra_tab [12]
 
static VLCElem studio_luma_dc [528]
 
static VLCElem studio_chroma_dc [528]
 
static const uint8_t mpeg4_block_count [4] = { 0, 6, 8, 12 }
 
static const int16_t mb_type_b_map [4]
 
static const uint8_t ac_state_tab [22][2]
 

Macro Definition Documentation

◆ UNCHECKED_BITSTREAM_READER

#define UNCHECKED_BITSTREAM_READER   1

Definition at line 23 of file mpeg4videodec.c.

◆ IS_3IV1

#define IS_3IV1   0

◆ SPRITE_TRAJ_VLC_BITS

#define SPRITE_TRAJ_VLC_BITS   6

Definition at line 63 of file mpeg4videodec.c.

Referenced by mpeg4_decode_sprite_trajectory().

◆ DC_VLC_BITS

#define DC_VLC_BITS   9

Definition at line 64 of file mpeg4videodec.c.

◆ MB_TYPE_B_VLC_BITS

#define MB_TYPE_B_VLC_BITS   4

Definition at line 65 of file mpeg4videodec.c.

Referenced by mpeg4_decode_mb().

◆ STUDIO_INTRA_BITS

#define STUDIO_INTRA_BITS   9

Definition at line 66 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_block().

Function Documentation

◆ h263_to_mpeg4()

◆ gmc1_motion()

static void gmc1_motion ( MpegEncContext * s,
const Mpeg4DecContext * ctx,
uint8_t * dest_y,
uint8_t * dest_cb,
uint8_t * dest_cr,
uint8_t *const * ref_picture )
static

Definition at line 90 of file mpeg4videodec.c.

Referenced by ff_mpeg4_mcsel_motion().

◆ gmc_motion()

static void gmc_motion ( MpegEncContext * s,
const Mpeg4DecContext * ctx,
uint8_t * dest_y,
uint8_t * dest_cb,
uint8_t * dest_cr,
uint8_t *const * ref_picture )
static

Definition at line 187 of file mpeg4videodec.c.

Referenced by ff_mpeg4_mcsel_motion().

◆ ff_mpeg4_mcsel_motion()

void ff_mpeg4_mcsel_motion ( MpegEncContext * s,
uint8_t * dest_y,
uint8_t * dest_cb,
uint8_t * dest_cr,
uint8_t *const * ref_picture )

Definition at line 245 of file mpeg4videodec.c.

Referenced by mpv_motion_internal().

◆ ff_mpeg4_decode_studio()

void ff_mpeg4_decode_studio ( MpegEncContext * s,
uint8_t * dest_y,
uint8_t * dest_cb,
uint8_t * dest_cr,
int block_size,
int uvlinesize,
int dct_linesize,
int dct_offset )

Definition at line 260 of file mpeg4videodec.c.

Referenced by mpv_reconstruct_mb_internal().

◆ ff_mpeg4_pred_ac()

void ff_mpeg4_pred_ac ( H263DecContext *const h,
int16_t * block,
int n,
int dir )

Predict the ac.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)
dirthe ac prediction direction

Definition at line 328 of file mpeg4videodec.c.

Referenced by ff_msmpeg4_decode_block(), and mpeg4_decode_block().

◆ mpeg4_is_resync()

static int mpeg4_is_resync ( Mpeg4DecContext * ctx)
inlinestatic

check if the next stuff is a resync marker or the end.

Returns
0 if not

Definition at line 383 of file mpeg4videodec.c.

Referenced by mpeg4_decode_mb(), and mpeg4_decode_partitioned_mb().

◆ mpeg4_decode_sprite_trajectory()

static int mpeg4_decode_sprite_trajectory ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 437 of file mpeg4videodec.c.

Referenced by decode_vop_header(), and ff_mpeg4_decode_video_packet_header().

◆ decode_new_pred()

static int decode_new_pred ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 693 of file mpeg4videodec.c.

Referenced by decode_vop_header(), and ff_mpeg4_decode_video_packet_header().

◆ ff_mpeg4_decode_video_packet_header()

int ff_mpeg4_decode_video_packet_header ( H263DecContext *const h)

Decode the next video packet.

Returns
<0 if something went wrong

Definition at line 708 of file mpeg4videodec.c.

Referenced by ff_h263_resync().

◆ reset_studio_dc_predictors()

static void reset_studio_dc_predictors ( Mpeg4DecContext *const ctx)
static

◆ ff_mpeg4_decode_studio_slice_header()

int ff_mpeg4_decode_studio_slice_header ( H263DecContext *const h)

Decode the next video packet.

Returns
<0 if something went wrong

Definition at line 808 of file mpeg4videodec.c.

Referenced by decode_slice().

◆ get_amv()

static int get_amv ( Mpeg4DecContext * ctx,
int n )
inlinestatic

Get the average motion vector for a GMC MB.

Parameters
neither 0 for the x component or 1 for y
Returns
the average MV for a GMC MB

Definition at line 850 of file mpeg4videodec.c.

Referenced by mpeg4_decode_mb(), and mpeg4_decode_partition_a().

◆ mpeg4_pred_dc()

static int mpeg4_pred_dc ( MpegEncContext * s,
int n,
int * dir_ptr )
inlinestatic

Predict the dc.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)
dir_ptrpointer to an integer where the prediction direction will be stored

Definition at line 902 of file mpeg4videodec.c.

Referenced by mpeg4_decode_block(), and mpeg4_decode_dc().

◆ mpeg4_get_level_dc()

static int mpeg4_get_level_dc ( MpegEncContext * s,
int n,
int pred,
int level )
inlinestatic

Definition at line 940 of file mpeg4videodec.c.

Referenced by mpeg4_decode_block(), and mpeg4_decode_dc().

◆ mpeg4_decode_dc()

static int mpeg4_decode_dc ( H263DecContext *const h,
int n,
int * dir_ptr )
inlinestatic

Decode the dc value.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)
dir_ptrthe prediction direction will be stored here
Returns
the quantized dc

Definition at line 983 of file mpeg4videodec.c.

Referenced by mpeg4_decode_block(), mpeg4_decode_partition_a(), and mpeg4_decode_partition_b().

◆ mpeg4_decode_partition_a()

static int mpeg4_decode_partition_a ( Mpeg4DecContext * ctx)
static

Decode first partition.

Returns
number of MBs decoded or <0 if an error occurred

Definition at line 1031 of file mpeg4videodec.c.

Referenced by ff_mpeg4_decode_partitions().

◆ mpeg4_decode_partition_b()

static int mpeg4_decode_partition_b ( H263DecContext *const h,
int mb_count )
static

decode second partition.

Returns
<0 if an error occurred

Definition at line 1223 of file mpeg4videodec.c.

Referenced by ff_mpeg4_decode_partitions().

◆ ff_mpeg4_decode_partitions()

int ff_mpeg4_decode_partitions ( H263DecContext *const h)

Decode the first and second partition.

Returns
<0 if error (and sets error type in the error_status_table)

Definition at line 1316 of file mpeg4videodec.c.

Referenced by decode_slice().

◆ mpeg4_decode_block()

static int mpeg4_decode_block ( Mpeg4DecContext * ctx,
int16_t * block,
int n,
int coded,
int intra,
int use_intra_dc_vlc,
int rvlc )
inlinestatic

Decode a block.

Returns
<0 if an error occurred

Definition at line 1381 of file mpeg4videodec.c.

Referenced by mpeg4_decode_mb(), and mpeg4_decode_partitioned_mb().

◆ mpeg4_decode_partitioned_mb()

static int mpeg4_decode_partitioned_mb ( H263DecContext *const h)
static

decode partition C of one MB.

Returns
<0 if an error occurred

Definition at line 1654 of file mpeg4videodec.c.

Referenced by decode_vop_header().

◆ mpeg4_decode_mb()

static int mpeg4_decode_mb ( H263DecContext *const h)
static

Definition at line 1741 of file mpeg4videodec.c.

Referenced by decode_vop_header().

◆ next_start_code_studio()

◆ mpeg4_decode_studio_block()

static int mpeg4_decode_studio_block ( Mpeg4DecContext *const ctx,
int32_t block[64],
int n )
static

Definition at line 2156 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_mb().

◆ mpeg4_decode_dpcm_macroblock()

static int mpeg4_decode_dpcm_macroblock ( Mpeg4DecContext *const ctx,
int16_t macroblock[256],
int n )
static

Definition at line 2271 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_mb().

◆ mpeg4_decode_studio_mb()

static int mpeg4_decode_studio_mb ( H263DecContext *const h)
static

Definition at line 2356 of file mpeg4videodec.c.

Referenced by decode_studio_vop_header().

◆ mpeg4_decode_gop_header()

static int mpeg4_decode_gop_header ( MpegEncContext * s,
GetBitContext * gb )
static

Definition at line 2404 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ mpeg4_decode_profile_level()

static int mpeg4_decode_profile_level ( MpegEncContext * s,
GetBitContext * gb,
int * profile,
int * level )
static

Definition at line 2426 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ mpeg4_decode_visual_object()

static int mpeg4_decode_visual_object ( MpegEncContext * s,
GetBitContext * gb )
static

Definition at line 2440 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ mpeg4_load_default_matrices()

static void mpeg4_load_default_matrices ( MpegEncContext * s)
static

Definition at line 2472 of file mpeg4videodec.c.

Referenced by decode_studio_vop_header(), and decode_vol_header().

◆ read_quant_matrix_ext()

static int read_quant_matrix_ext ( MpegEncContext * s,
GetBitContext * gb )
static

Definition at line 2489 of file mpeg4videodec.c.

Referenced by extension_and_user_data().

◆ extension_and_user_data()

static void extension_and_user_data ( MpegEncContext * s,
GetBitContext * gb,
int id )
static

◆ decode_studio_vol_header()

static int decode_studio_vol_header ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 2555 of file mpeg4videodec.c.

Referenced by decode_vol_header().

◆ decode_vol_header()

static int decode_vol_header ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 2641 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ decode_user_data()

static int decode_user_data ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Decode the user data stuff in the header.

Also initializes divx/xvid/lavc_version/build.

Definition at line 3011 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ decode_vop_header()

static int decode_vop_header ( Mpeg4DecContext * ctx,
GetBitContext * gb,
int parse_only )
static

Definition at line 3068 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ decode_smpte_tc()

static void decode_smpte_tc ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 3348 of file mpeg4videodec.c.

Referenced by decode_studio_vop_header().

◆ decode_studio_vop_header()

static int decode_studio_vop_header ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Decode the next studio vop header.

Returns
<0 if something went wrong

Definition at line 3367 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ decode_studiovisualobject()

static int decode_studiovisualobject ( Mpeg4DecContext * ctx,
GetBitContext * gb )
static

Definition at line 3413 of file mpeg4videodec.c.

Referenced by ff_mpeg4_parse_picture_header().

◆ ff_mpeg4_parse_picture_header()

int ff_mpeg4_parse_picture_header ( Mpeg4DecContext * ctx,
GetBitContext * gb,
int header,
int parse_only )

Decode MPEG-4 headers.

Parameters
headerIf set the absence of a VOP is not treated as error; otherwise, it is treated as such.
parse_onlyIf set, things only relevant to a decoder may be skipped; furthermore, the VLC tables may be uninitialized.
Returns
<0 if an error occurred FRAME_SKIPPED if a not coded VOP is found 0 else

Definition at line 3440 of file mpeg4videodec.c.

Referenced by mpeg4_decode_header().

Variable Documentation

◆ dc_lum

VLCElem dc_lum[512]
static

Definition at line 68 of file mpeg4videodec.c.

Referenced by mpeg4_decode_dc().

◆ dc_chrom

VLCElem dc_chrom[512]
static

Definition at line 68 of file mpeg4videodec.c.

Referenced by mpeg4_decode_dc().

◆ sprite_trajectory

VLCElem sprite_trajectory[128]
static

Definition at line 69 of file mpeg4videodec.c.

Referenced by mpeg4_decode_sprite_trajectory().

◆ mb_type_b_vlc

VLCElem mb_type_b_vlc[16]
static

Definition at line 70 of file mpeg4videodec.c.

Referenced by mpeg4_decode_mb().

◆ studio_intra_tab

const VLCElem* studio_intra_tab[12]
static

Definition at line 71 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_block().

◆ studio_luma_dc

VLCElem studio_luma_dc[528]
static

Definition at line 72 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_block().

◆ studio_chroma_dc

VLCElem studio_chroma_dc[528]
static

Definition at line 73 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_block().

◆ mpeg4_block_count

const uint8_t mpeg4_block_count[4] = { 0, 6, 8, 12 }
static

Definition at line 75 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_mb().

◆ mb_type_b_map

const int16_t mb_type_b_map[4]
static
Initial value:
= {
}
#define MB_TYPE_BACKWARD_MV
Definition mpegutils.h:50
#define MB_TYPE_DIRECT2
Definition mpegutils.h:46
#define MB_TYPE_BIDIR_MV
Definition mpegutils.h:51
#define MB_TYPE_16x16
Definition mpegutils.h:41
#define MB_TYPE_FORWARD_MV
Definition mpegutils.h:49

Definition at line 77 of file mpeg4videodec.c.

◆ ac_state_tab

const uint8_t ac_state_tab[22][2]
static
Initial value:
=
{
{0, 0},
{0, 1},
{1, 1},
{2, 1},
{3, 1},
{4, 1},
{5, 1},
{1, 2},
{2, 2},
{3, 2},
{4, 2},
{5, 2},
{6, 2},
{1, 3},
{2, 4},
{3, 5},
{4, 6},
{5, 7},
{6, 8},
{7, 9},
{8, 10},
{0, 11}
}

Definition at line 2130 of file mpeg4videodec.c.

Referenced by mpeg4_decode_studio_block().