mpegvideo.c File Reference

The simplest mpeg encoder (well, it was the simplest!). More...

#include "libavutil/intmath.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "dsputil.h"
#include "internal.h"
#include "mpegvideo.h"
#include "mpegvideo_common.h"
#include "mjpegenc.h"
#include "msmpeg4.h"
#include "faandct.h"
#include "xvmc_internal.h"
#include "thread.h"
#include <limits.h>

Go to the source code of this file.

Macros

#define COPY(a)   bak->a = src->a
#define COLOR(theta, r)

Functions

static void dct_unquantize_mpeg1_intra_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_mpeg1_inter_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_mpeg2_intra_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_mpeg2_intra_bitexact (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_mpeg2_inter_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_h263_intra_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
static void dct_unquantize_h263_inter_c (MpegEncContext *s, DCTELEM *block, int n, int qscale)
const uint8_t * avpriv_mpv_find_start_code (const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
av_cold int ff_dct_common_init (MpegEncContext *s)
void ff_copy_picture (Picture *dst, Picture *src)
static void free_frame_buffer (MpegEncContext *s, Picture *pic)
 Release a frame buffer.
static int alloc_frame_buffer (MpegEncContext *s, Picture *pic)
 Allocate a frame buffer.
int ff_alloc_picture (MpegEncContext *s, Picture *pic, int shared)
 Allocate a Picture.
static void free_picture (MpegEncContext *s, Picture *pic)
 Deallocate a picture.
static int init_duplicate_context (MpegEncContext *s, MpegEncContext *base)
static void free_duplicate_context (MpegEncContext *s)
static void backup_duplicate_context (MpegEncContext *bak, MpegEncContext *src)
void ff_update_duplicate_context (MpegEncContext *dst, MpegEncContext *src)
int ff_mpeg_update_thread_context (AVCodecContext *dst, const AVCodecContext *src)
void MPV_common_defaults (MpegEncContext *s)
 Set the given MpegEncContext to common defaults (same for encoding and decoding).
void MPV_decode_defaults (MpegEncContext *s)
 Set the given MpegEncContext to defaults for decoding.
av_cold int MPV_common_init (MpegEncContext *s)
 init common structure for both encoder and decoder.
void MPV_common_end (MpegEncContext *s)
void ff_init_rl (RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
void ff_init_vlc_rl (RLTable *rl)
void ff_release_unused_pictures (MpegEncContext *s, int remove_current)
int ff_find_unused_picture (MpegEncContext *s, int shared)
static void update_noise_reduction (MpegEncContext *s)
int MPV_frame_start (MpegEncContext *s, AVCodecContext *avctx)
 generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded.
void MPV_frame_end (MpegEncContext *s)
static void draw_line (uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color)
 Draw a line from (ex, ey) -> (sx, sy).
static void draw_arrow (uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color)
 Draw an arrow from (ex, ey) -> (sx, sy).
void ff_print_debug_info (MpegEncContext *s, AVFrame *pict)
 Print debugging info for the given picture.
static int hpel_motion_lowres (MpegEncContext *s, uint8_t *dest, uint8_t *src, int field_based, int field_select, int src_x, int src_y, int width, int height, int stride, int h_edge_pos, int v_edge_pos, int w, int h, h264_chroma_mc_func *pix_op, int motion_x, int motion_y)
static av_always_inline void mpeg_motion_lowres (MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, h264_chroma_mc_func *pix_op, int motion_x, int motion_y, int h, int mb_y)
static void chroma_4mv_motion_lowres (MpegEncContext *s, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, h264_chroma_mc_func *pix_op, int mx, int my)
static void MPV_motion_lowres (MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int dir, uint8_t **ref_picture, h264_chroma_mc_func *pix_op)
 motion compensation of a single macroblock
int MPV_lowest_referenced_row (MpegEncContext *s, int dir)
 find the lowest MB row referenced in the MVs
static void put_dct (MpegEncContext *s, DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
static void add_dct (MpegEncContext *s, DCTELEM *block, int i, uint8_t *dest, int line_size)
static void add_dequant_dct (MpegEncContext *s, DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale)
void ff_clean_intra_table_entries (MpegEncContext *s)
 Clean dc, ac, coded_block for the current non-intra MB.
static av_always_inline void MPV_decode_mb_internal (MpegEncContext *s, DCTELEM block[12][64], int lowres_flag, int is_mpeg12)
void MPV_decode_mb (MpegEncContext *s, DCTELEM block[12][64])
void ff_draw_horiz_band (MpegEncContext *s, int y, int h)
void ff_init_block_index (MpegEncContext *s)
void ff_mpeg_flush (AVCodecContext *avctx)
void ff_set_qscale (MpegEncContext *s, int qscale)
 set qscale and update qscale dependent variables.
void MPV_report_decode_progress (MpegEncContext *s)

Variables

static const uint8_t ff_default_chroma_qscale_table [32]
const uint8_t ff_mpeg1_dc_scale_table [128]
static const uint8_t mpeg2_dc_scale_table1 [128]
static const uint8_t mpeg2_dc_scale_table2 [128]
static const uint8_t mpeg2_dc_scale_table3 [128]
const uint8_t *const ff_mpeg2_dc_scale_table [4]
enum PixelFormat ff_pixfmt_list_420 []
enum PixelFormat ff_hwaccel_pixfmt_list_420 []

Detailed Description

The simplest mpeg encoder (well, it was the simplest!).

Definition in file mpegvideo.c.

Macro Definition Documentation

#define COLOR (   theta,
  r 
)
Value:
u = (int)(128 + r * cos(theta * 3.141592 / 180)); \
v = (int)(128 + r * sin(theta * 3.141592 / 180));

Referenced by avfilter_register_all(), and ff_print_debug_info().

#define COPY (   a)    bak->a = src->a

Function Documentation

static void add_dct ( MpegEncContext s,
DCTELEM block,
int  i,
uint8_t *  dest,
int  line_size 
)
inlinestatic

Definition at line 2227 of file mpegvideo.c.

Referenced by MPV_decode_mb_internal().

static void add_dequant_dct ( MpegEncContext s,
DCTELEM block,
int  i,
uint8_t *  dest,
int  line_size,
int  qscale 
)
inlinestatic

Definition at line 2235 of file mpegvideo.c.

Referenced by MPV_decode_mb_internal().

static int alloc_frame_buffer ( MpegEncContext s,
Picture pic 
)
static

Allocate a frame buffer.

Definition at line 246 of file mpegvideo.c.

Referenced by ff_alloc_picture().

const uint8_t* avpriv_mpv_find_start_code ( const uint8_t *restrict  p,
const uint8_t *  end,
uint32_t *restrict  state 
)
static void backup_duplicate_context ( MpegEncContext bak,
MpegEncContext src 
)
static

Definition at line 486 of file mpegvideo.c.

Referenced by ff_update_duplicate_context().

static void chroma_4mv_motion_lowres ( MpegEncContext s,
uint8_t *  dest_cb,
uint8_t *  dest_cr,
uint8_t **  ref_picture,
h264_chroma_mc_func pix_op,
int  mx,
int  my 
)
inlinestatic

Definition at line 1985 of file mpegvideo.c.

Referenced by MPV_motion_lowres().

static void dct_unquantize_h263_inter_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2859 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_h263_intra_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2822 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_mpeg1_inter_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2699 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_mpeg1_intra_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2667 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_mpeg2_inter_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2791 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_mpeg2_intra_bitexact ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2758 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void dct_unquantize_mpeg2_intra_c ( MpegEncContext s,
DCTELEM block,
int  n,
int  qscale 
)
static

Definition at line 2728 of file mpegvideo.c.

Referenced by ff_dct_common_init().

static void draw_arrow ( uint8_t *  buf,
int  sx,
int  sy,
int  ex,
int  ey,
int  w,
int  h,
int  stride,
int  color 
)
static

Draw an arrow from (ex, ey) -> (sx, sy).

Parameters
wwidth of the image
hheight of the image
stridestride/linesize of the image
colorcolor of the arrow

Definition at line 1487 of file mpegvideo.c.

Referenced by ff_print_debug_info().

static void draw_line ( uint8_t *  buf,
int  sx,
int  sy,
int  ex,
int  ey,
int  w,
int  h,
int  stride,
int  color 
)
static

Draw a line from (ex, ey) -> (sx, sy).

Parameters
wwidth of the image
hheight of the image
stridestride/linesize of the image
colorcolor of the arrow

Definition at line 1434 of file mpegvideo.c.

Referenced by draw_arrow().

int ff_alloc_picture ( MpegEncContext s,
Picture pic,
int  shared 
)

Allocate a Picture.

The pixels are allocated/set by calling get_buffer() if shared = 0

Definition at line 295 of file mpegvideo.c.

Referenced by load_input_picture(), MPV_frame_start(), and select_input_picture().

void ff_clean_intra_table_entries ( MpegEncContext s)

Clean dc, ac, coded_block for the current non-intra MB.

Definition at line 2248 of file mpegvideo.c.

Referenced by encode_thread(), mpeg4_decode_partition_a(), and MPV_decode_mb_internal().

void ff_copy_picture ( Picture dst,
Picture src 
)

Definition at line 222 of file mpegvideo.c.

Referenced by decode_slice_header(), MPV_frame_start(), and select_input_picture().

av_cold int ff_dct_common_init ( MpegEncContext s)

Definition at line 177 of file mpegvideo.c.

Referenced by dnxhd_encode_init(), ff_h263_decode_frame(), and MPV_common_init().

int ff_find_unused_picture ( MpegEncContext s,
int  shared 
)
void ff_init_rl ( RLTable rl,
uint8_t  static_store[2][2 *MAX_RUN+MAX_LEVEL+3] 
)
Parameters
static_storestatic uint8_t array[2][2*MAX_RUN + MAX_LEVEL + 3] which will hold the level and run tables, if this is NULL av_malloc() will be used

Definition at line 1008 of file mpegvideo.c.

Referenced by decode_init(), encode_init(), ff_h261_encode_init(), ff_h263_decode_init_vlc(), ff_h263_encode_init(), ff_mpeg12_init_vlcs(), ff_mpeg1_encode_init(), ff_msmpeg4_decode_init(), and h261_decode_init_vlc().

void ff_init_vlc_rl ( RLTable rl)

Definition at line 1060 of file mpegvideo.c.

void ff_mpeg_flush ( AVCodecContext avctx)

Definition at line 2640 of file mpegvideo.c.

Referenced by flush(), and flush_dpb().

int ff_mpeg_update_thread_context ( AVCodecContext dst,
const AVCodecContext src 
)
void ff_print_debug_info ( MpegEncContext s,
AVFrame pict 
)

Print debugging info for the given picture.

Definition at line 1518 of file mpegvideo.c.

Referenced by decode_frame(), ff_h263_decode_frame(), finish_frame(), h261_decode_frame(), rv10_decode_frame(), slice_end(), and vc1_decode_frame().

void ff_release_unused_pictures ( MpegEncContext s,
int  remove_current 
)

Definition at line 1100 of file mpegvideo.c.

Referenced by decode_slice_header(), and MPV_frame_start().

void ff_update_duplicate_context ( MpegEncContext dst,
MpegEncContext src 
)

Definition at line 513 of file mpegvideo.c.

Referenced by decode_chunks(), and encode_picture().

static void free_duplicate_context ( MpegEncContext s)
static

Definition at line 466 of file mpegvideo.c.

Referenced by MPV_common_end().

static void free_frame_buffer ( MpegEncContext s,
Picture pic 
)
static
static void free_picture ( MpegEncContext s,
Picture pic 
)
static

Deallocate a picture.

Definition at line 384 of file mpegvideo.c.

Referenced by MPV_common_end().

static int hpel_motion_lowres ( MpegEncContext s,
uint8_t *  dest,
uint8_t *  src,
int  field_based,
int  field_select,
int  src_x,
int  src_y,
int  width,
int  height,
int  stride,
int  h_edge_pos,
int  v_edge_pos,
int  w,
int  h,
h264_chroma_mc_func pix_op,
int  motion_x,
int  motion_y 
)
inlinestatic

Definition at line 1823 of file mpegvideo.c.

Referenced by MPV_motion_lowres().

static int init_duplicate_context ( MpegEncContext s,
MpegEncContext base 
)
static

Definition at line 415 of file mpegvideo.c.

Referenced by MPV_common_init().

static av_always_inline void mpeg_motion_lowres ( MpegEncContext s,
uint8_t *  dest_y,
uint8_t *  dest_cb,
uint8_t *  dest_cr,
int  field_based,
int  bottom_field,
int  field_select,
uint8_t **  ref_picture,
h264_chroma_mc_func pix_op,
int  motion_x,
int  motion_y,
int  h,
int  mb_y 
)
static

Definition at line 1870 of file mpegvideo.c.

Referenced by MPV_motion_lowres().

void MPV_common_defaults ( MpegEncContext s)

Set the given MpegEncContext to common defaults (same for encoding and decoding).

The changed fields will not depend upon the prior state of the MpegEncContext.

Definition at line 620 of file mpegvideo.c.

Referenced by MPV_decode_defaults(), and MPV_encode_defaults().

void MPV_decode_defaults ( MpegEncContext s)

Set the given MpegEncContext to defaults for decoding.

the changed fields will not depend upon the prior state of the MpegEncContext.

Definition at line 649 of file mpegvideo.c.

Referenced by ff_cavs_init(), ff_h263_decode_init(), ff_h264_decode_init(), ff_rv34_decode_init(), h261_decode_init(), mpeg_decode_init(), rv10_decode_init(), and svq1_decode_init().

static av_always_inline void MPV_decode_mb_internal ( MpegEncContext s,
DCTELEM  block[12][64],
int  lowres_flag,
int  is_mpeg12 
)
static

Definition at line 2289 of file mpegvideo.c.

Referenced by MPV_decode_mb().

int MPV_frame_start ( MpegEncContext s,
AVCodecContext avctx 
)

generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded.

Definition at line 1163 of file mpegvideo.c.

Referenced by ff_h263_decode_frame(), ff_h264_frame_start(), ff_rv34_decode_frame(), h261_decode_frame(), mpeg_field_start(), MPV_encode_picture(), rv10_decode_packet(), svq1_decode_frame(), and vc1_decode_frame().

int MPV_lowest_referenced_row ( MpegEncContext s,
int  dir 
)

find the lowest MB row referenced in the MVs

Definition at line 2184 of file mpegvideo.c.

Referenced by MPV_decode_mb_internal().

static void MPV_motion_lowres ( MpegEncContext s,
uint8_t *  dest_y,
uint8_t *  dest_cb,
uint8_t *  dest_cr,
int  dir,
uint8_t **  ref_picture,
h264_chroma_mc_func pix_op 
)
inlinestatic

motion compensation of a single macroblock

Parameters
scontext
dest_yluma destination pointer
dest_cbchroma cb/u destination pointer
dest_crchroma cr/v destination pointer
dirdirection (0->forward, 1->backward)
ref_picturearray[3] of pointers to the 3 planes of the reference picture
pix_ophalfpel motion compensation function (average or put normally) the motion vectors are taken from s->mv and the MV type from s->mv_type

Definition at line 2050 of file mpegvideo.c.

Referenced by MPV_decode_mb_internal().

void MPV_report_decode_progress ( MpegEncContext s)

Definition at line 2902 of file mpegvideo.c.

Referenced by decode_slice(), and mpeg_decode_slice().

static void put_dct ( MpegEncContext s,
DCTELEM block,
int  i,
uint8_t *  dest,
int  line_size,
int  qscale 
)
inlinestatic

Definition at line 2219 of file mpegvideo.c.

Referenced by MPV_decode_mb_internal().

static void update_noise_reduction ( MpegEncContext s)
static

Definition at line 1138 of file mpegvideo.c.

Referenced by MPV_frame_start().

Variable Documentation

const uint8_t ff_default_chroma_qscale_table[32]
static
Initial value:
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
}

Definition at line 69 of file mpegvideo.c.

Referenced by MPV_common_defaults().

enum PixelFormat ff_hwaccel_pixfmt_list_420[]
const uint8_t ff_mpeg1_dc_scale_table[128]
Initial value:
{
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
}

Definition at line 75 of file mpegvideo.c.

Referenced by common_init(), ff_flv_decode_picture_header(), ff_flv_encode_picture_header(), ff_h261_encode_init(), ff_h263_decode_picture_header(), ff_h263_encode_init(), ff_h263_encode_picture_header(), ff_intel_h263_decode_picture_header(), MPV_common_defaults(), rv10_decode_packet(), and rv20_encode_picture_header().

const uint8_t* const ff_mpeg2_dc_scale_table[4]
enum PixelFormat ff_pixfmt_list_420[]
Initial value:

Definition at line 130 of file mpegvideo.c.

const uint8_t mpeg2_dc_scale_table1[128]
static
Initial value:
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
}

Definition at line 87 of file mpegvideo.c.

const uint8_t mpeg2_dc_scale_table2[128]
static
Initial value:
{
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
}

Definition at line 99 of file mpegvideo.c.

const uint8_t mpeg2_dc_scale_table3[128]
static
Initial value:
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}

Definition at line 111 of file mpegvideo.c.