📄 mpegvideo.h
字号:
/* * Generic DCT based hybrid video encoder * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//** * @file mpegvideo.h * mpegvideo header. */ #ifndef AVCODEC_MPEGVIDEO_H#define AVCODEC_MPEGVIDEO_H#include "dsputil.h"#define FRAME_SKIPED 100 ///< return value for header parsers if frame is not codedenum OutputFormat { FMT_MPEG1, FMT_H263, FMT_MJPEG, FMT_H264,};#define EDGE_WIDTH 16#define MPEG_BUF_SIZE (16 * 1024)#define QMAT_SHIFT_MMX 16#define QMAT_SHIFT 22#define MAX_FCODE 7#define MAX_MV 2048#define MAX_THREADS 8#define MAX_PICTURE_COUNT 15#define ME_MAP_SIZE 64#define ME_MAP_SHIFT 3#define ME_MAP_MV_BITS 11/* run length table */#define MAX_RUN 64#define MAX_LEVEL 64#define I_TYPE FF_I_TYPE ///< Intra#define P_TYPE FF_P_TYPE ///< Predicted#define B_TYPE FF_B_TYPE ///< Bi-dir predicted#define S_TYPE FF_S_TYPE ///< S(GMC)-VOP MPEG4#define SI_TYPE FF_SI_TYPE ///< Switching Intra#define SP_TYPE FF_SP_TYPE ///< Switching Predicted/** * Scantable. */typedef struct ScanTable{ const uint8_t *scantable; uint8_t permutated[64]; uint8_t raster_end[64];#ifdef ARCH_POWERPC /** Used by dct_quantise_alitvec to find last-non-zero */ uint8_t __align8 inverse[64];#endif} ScanTable;/** * Picture. */typedef struct Picture{ FF_COMMON_FRAME /** * halfpel luma planes. */ uint8_t *interpolated[3]; int16_t (*motion_val_base[2])[2]; int8_t *ref_index[2]; uint32_t *mb_type_base;#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if theres just one type#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)#define IS_INTRA(a) ((a)&7)#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)#define IS_GMC(a) ((a)&MB_TYPE_GMC)#define IS_16X16(a) ((a)&MB_TYPE_16x16)#define IS_16X8(a) ((a)&MB_TYPE_16x8)#define IS_8X16(a) ((a)&MB_TYPE_8x16)#define IS_8X8(a) ((a)&MB_TYPE_8x8)#define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs#define HAS_CBP(a) ((a)&MB_TYPE_CBP) int field_poc[2]; ///< h264 top/bottom POC int poc; ///< h264 frame POC int frame_num; ///< h264 frame_num int pic_id; ///< h264 pic_num or long_term_pic_idx int long_ref; ///< 1->long term reference 0->short term reference } Picture;typedef struct ParseContext{ uint8_t *buffer; int index; int last_index; int buffer_size; uint32_t state; ///< contains the last few bytes in MSB order int frame_start_found; int overread; ///< the number of bytes which where irreversibly read from the next frame int overread_index; ///< the index into ParseContext.buffer of the overreaded bytes} ParseContext;struct MpegEncContext;/** * MpegEncContext. */typedef struct MpegEncContext { struct AVCodecContext *avctx; /* the following parameters must be initialized before encoding */ int width, height;///< picture size. must be a multiple of 16 int gop_size; int intra_only; ///< if true, only intra pictures are generated int bit_rate; ///< wanted bit rate enum OutputFormat out_format; ///< output format int codec_id; /* see CODEC_ID_xxx */ int fixed_qscale; ///< fixed qscale if non zero int encoding; ///< true if we are encoding (vs decoding) int flags; ///< AVCodecContext.flags (HQ, MV4, ...) int flags2; ///< AVCodecContext.flags2 int max_b_frames; ///< max number of b-frames for encoding int luma_elim_threshold; int chroma_elim_threshold; int strict_std_compliance; ///< strictly follow the std (MPEG4, ...) int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically /* the following fields are managed internally by the encoder */ /** bit output */ PutBitContext pb; /* sequence parameters */ int context_initialized; int input_picture_number; ///< used to set pic->display_picture_number, shouldnt be used for/by anything else int coded_picture_number; ///< used to set pic->coded_picture_number, shouldnt be used for/by anything else int picture_number; //FIXME remove, unclear definition int picture_in_gop_number; ///< 0-> first pic in gop, ... int mb_width, mb_height; ///< number of MBs horizontally & vertically int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressng of left & top MBs withoutt sig11 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressng int b4_stride; ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressng int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replicateion) int mb_num; ///< number of MBs of a picture int linesize; ///< line size, in bytes, may be different from width int uvlinesize; ///< line size, for chroma in bytes, may be different from width Picture *picture; ///< main picture buffer int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) struct MpegEncContext *thread_context[MAX_THREADS]; /** * copy of the previous picture structure. * note, linesize & data, might not match the previous picture (for field pictures) */ Picture last_picture; /** * copy of the next picture structure. * note, linesize & data, might not match the next picture (for field pictures) */ Picture next_picture; /** * copy of the current picture structure. * note, linesize & data, might not match the current picture (for field pictures) */ Picture current_picture; ///< buffer to store the decompressed current picture Picture *last_picture_ptr; ///< pointer to the previous picture. Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *current_picture_ptr; ///< pointer to the current picture uint8_t *prev_pict_types; ///< previous picture types in bitstream order, used for mb skip #define PREV_PICT_TYPES_BUFFER_SIZE 256 int mb_skiped; ///< MUST BE SET only during DECODING uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example) and used for b-frame encoding & decoding (contains skip table of next P Frame) */ uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding uint8_t *allocated_edge_emu_buffer; uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer int qscale; ///< QP int chroma_qscale; ///< chroma QP int pict_type; ///< I_TYPE, P_TYPE, B_TYPE, ... int last_pict_type; int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol /* motion compensation */ int unrestricted_mv; ///< mv can point outside of the coded picture int decode; ///< if 0 then decoding will be skiped (for encoding b frames for example) DSPContext dsp; ///< pointers for accelerated dsp fucntions int hurry_up; /**< when set to 1 during decoding, b frames will be skiped when set to 2 idct/dequant will be skipped too */ /* macroblock layer */ int mb_x, mb_y; int mb_skip_run; int mb_intra;#define CANDIDATE_MB_TYPE_INTRA 0x01#define CANDIDATE_MB_TYPE_INTER 0x02#define CANDIDATE_MB_TYPE_INTER4V 0x04#define CANDIDATE_MB_TYPE_SKIPED 0x08//#define MB_TYPE_GMC 0x10#define CANDIDATE_MB_TYPE_DIRECT 0x10#define CANDIDATE_MB_TYPE_FORWARD 0x20#define CANDIDATE_MB_TYPE_BACKWARD 0x40#define CANDIDATE_MB_TYPE_BIDIR 0x80#define CANDIDATE_MB_TYPE_INTER_I 0x100#define CANDIDATE_MB_TYPE_FORWARD_I 0x200#define CANDIDATE_MB_TYPE_BACKWARD_I 0x400#define CANDIDATE_MB_TYPE_BIDIR_I 0x800 int block_wrap[6]; uint8_t *dest[3]; int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride int ac_esc_length; ///< num of bits needed to encode the longest esc uint8_t *intra_ac_vlc_length; uint8_t *intra_ac_vlc_last_length; uint8_t *inter_ac_vlc_length; uint8_t *inter_ac_vlc_last_length; uint8_t *luma_dc_vlc_length;#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level)) int block_last_index[12]; ///< last non zero coefficient in block /* scantables */ ScanTable __align8 intra_scantable; ScanTable intra_h_scantable; ScanTable intra_v_scantable; ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce tha cache usage #define VP_START 1 ///< current MB is the first after a resync marker #define AC_ERROR 2#define DC_ERROR 4#define MV_ERROR 8#define AC_END 16#define DC_END 32#define MV_END 64//FIXME some prefix? ParseContext parse_context; /* mpeg4 specific */ int data_partitioning; ///< data partitioning flag from header int partitioned_frame; ///< is current frame partitioned int low_delay; ///< no reordering needed / has no b-frames /* lavc specific stuff, used to workaround bugs in libavcodec */ int ffmpeg_version; int lavc_build; /* decompression specific */ GetBitContext gb; int broken_link; ///< no_output_of_prior_pics_flag /* MPEG2 specific - I wish I had not to support this mess. */ int progressive_sequence; int picture_structure;/* picture type */#define PICT_TOP_FIELD 1#define PICT_BOTTOM_FIELD 2#define PICT_FRAME 3 int top_field_first; int alternate_scan; int progressive_frame; short * pblocks[12]; DCTELEM (*block)[64]; ///< points to one of the following blocks DCTELEM (*blocks)[6][64]; // for HQ mode we need to keep the best block int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()#define SLICE_OK 0#define SLICE_ERROR -1#define SLICE_END -2 ///<end marker found#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both) DCTELEM *block/*align 16*/, int n, int qscale); void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both) DCTELEM *block/*align 16*/, int n, int qscale); int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow); int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow); } MpegEncContext;int DCT_common_init(MpegEncContext *s);void MPV_decode_defaults(MpegEncContext *s);int MPV_common_init(MpegEncContext *s);void MPV_common_end(MpegEncContext *s);void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);void MPV_frame_end(MpegEncContext *s);extern void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length);void ff_clean_intra_table_entries(MpegEncContext *s);void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);void ff_draw_horiz_band(MpegEncContext *s, int y, int h);void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h, int src_x, int src_y, int w, int h);#define END_NOT_FOUND -100int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);int ff_find_unused_picture(MpegEncContext *s, int shared);#endif /* AVCODEC_MPEGVIDEO_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -