📄 henc.h
字号:
/*!
********************************************************
*\file
* HEnc.h
*\brief
* Definition of data structure used by encoder,
* Definition of macros and global variables
*\date
* 12/6/2002
*
********************************************************/
#ifndef HENC_H
#define HENC_H
#define HENCLIB
/* Source format */
#define _SUBQCIF 1 //!< 88x72
#define _QCIF 2 //!< 176x144
#define _CIF 3 //!< 352x288
#define _4CIF 4
#define _16CIF 5
#define _CPFMT 6 //!< custom picture format
/* Picture format */
#define YUV420 1
#define YUV411 2
#define RGB24 3
/* MB mode */
#define MODE_INTER 0 //!< inter MB mode
#define MODE_INTER_Q 1 //!< inter MB mode with a nonzero dequant
#define MODE_INTER4V 2 //!< inter MB mode with 4 motion vectors
#define MODE_INTRA 3 //!< intra MB mode
#define MODE_INTRA_Q 4 //!< intra MB mode with a nonzero dequant
#define MODE_INTER4V_Q 5 //!< left unused now
/* Picture coding type */
#define INTRA 0 //!< intra picture
#define INTER 1 //!< inter picture
#define B_IMG 3 //!< B picture
#define SKIP 100 //!< for rate control
#define STORE 999 //!< for control
/* Prediction mode for B frames */
#define B_DIRECT 0 //!< direct prediction
#define B_FORWARD 1 //!< forward prediction
#define B_BACKWARD 2 //!< backward prediction
#define B_BIDIRECTIONAL 3 //!< bi-directional prediction
#define B_INTRA 4 //!< intra coded
/* AIC mode */
#define INTRA_MODE_DC 1
#define INTRA_MODE_VERT_AC 2
#define INTRA_MODE_HORI_AC 3
//mv search method
#define FULLSEARCH 0
#define MVFAST 1
#define MBR 72 //!< rows of MBs per picture(Maximum)
#define MBC 88 //!< columns of MBs per picture(Maximum)
#define NO_VEC 999 //!< MV values for MBs beyond the top of the picture
#define INT16 __int16
struct _tagH263VencStatus;
//! Image structure
typedef struct
{
unsigned char* pLum;
unsigned char* pCr;
unsigned char* pCb;
}Image;
//! MB structure
typedef struct
{
unsigned char *pLum;
unsigned char *pCr;
unsigned char *pCb;
}MB_structure;
typedef struct
{
INT16 top_lum[MBC*2][8];
INT16 top_cb[MBC][8];
INT16 top_cr[MBC][8];
INT16 left_lum[2][8];
INT16 left_cb[1][8];
INT16 left_cr[1][8];
}Coeff;
typedef struct
{
float snrY;
float snrCB;
float snrCR;
}snr_struct;
//! Motion vector stucture
typedef struct
{
int x; //!< x displacement(integer)
int y; //!< y displacement(integer)
int x_half; //!< x displacement(half)
int y_half; //!< y displacement(half)
int Mode; //!< Mode choosen for the corresponding MB
int min_sad; //!< minimum SAD for current MV values and mode
}MotionVector;
//! h263 annex
typedef struct
{
int Advanced_Prediction; //!< annex F advanced prediction mode
int Temporal_Scalability; //!< annex O
int Deblocking_Filter; //!< annex J deblocking filter mode
int RPS; //!< annex N reference picture selection mode
int AIC; //!< annex I advanced intra coding
}H263Annex;
//! Structure for bitstream
typedef struct _tagputstrm
{
/*! the coded bits can be send to other device such as a block of memory instead of
file */
// FILE *bitstrmfptr;
int *poutint; //!< stream buffer(32bits as a unit)
int buff_size; //!< buffer size
int ptrint; //!< pointer of the q_byte buffer
int pcntint; //!< the numbers of vacant bits in the temperory q-byte */
int bitoutint; //!< the temperory q-byte
/*!< the whole 4 bytes will be sent to stream when it is filled */
long (*WriteData) (unsigned char *pData, int len, long tmstamp,
unsigned long type, void* context ); /*!< Call back function used to write encoded data */
unsigned int timestamp; //! time stamp
int pic_type; //! picture type
void* context; //! additional information
}putstrm;
typedef struct
{
void (*DCT) (INT16*, INT16*);
void (*IDCT) (INT16*, INT16*);
void (*pred_lum) (int , int , MotionVector *, unsigned char *, int, unsigned char *);
void (*pred_lum_bid) (int , int , int , int , int , int , unsigned char *, unsigned char *, int, unsigned char *);
void (*pred_obmc) (int,int,MotionVector *[][73][90],int,unsigned char *,int,int,unsigned char *);
void (*pred_chrom) (int , int , unsigned char *,int , int, int, unsigned char *);
void (*pred_chrom_bid) (int, int, unsigned char *, unsigned char *, int, int, int, int, int, unsigned char *);
void (*make_diff) (unsigned char* , int, unsigned char *, INT16 *);
void (*recon_pic) (unsigned char* , int , unsigned char *, INT16 *);
int (*Quant_blk_I) (INT16 *,INT16 *, int);
void (*DeQuant_blk_I) (INT16 *, INT16 *, int);
int (*Quant_blk_P) (INT16 *,INT16 *, int);
void (*DeQuant_blk_P) (INT16 *, INT16 *, int);
void (*block_copy1) ( unsigned char *, unsigned char *, int);
void (*block_copy2) ( INT16 *, unsigned char *, int);
void (*block_copy3) ( unsigned char *, INT16 *, int);
void (*interpolate_lum) (struct _tagH263VencStatus *);
int (*me_sad_a) (int, int, int, int, int, int, unsigned char *, unsigned char *, int, int);
int (*me_sad_b)(int, int, int, int, int, int, unsigned char *, unsigned char *, int, int);
int (*findbiSAD) (unsigned char *, unsigned char *, unsigned char *, int, int, int);
}Method;
//! Encoder status
typedef struct _tagH263VencStatus
{
/* buffer used */
//! points to the other buffer of the input frame double buffer set.
Image frameToEncode;
//! the buffer to store all reconstructed frames for reference
Image frame_buf[10];
//! the buffer to store input frame for B picture.
Image BPicture[10];
//! points to the interpolated picture
unsigned char *prev_ipol;
//! interpolated picture for the searching for backward MV
unsigned char *next_ipol;
/* function used */
Method method;
/* stream control */
putstrm putstrmctrl;
/* Global parameters (fixed once encoding starts) */
//! indicates the source format with which the image is to be encoded. The source
//! formats supported are sub-QCIF, QCIF, CIF (Common Intermediate Format), and 4CIF. The values of
//! sourceFormat corresponding to these formats are 1, 2, 3, and 4 respectively (as described in section
//! 5.1.3 of ITU-T H.263).
int sourceFormat;
int VideoFormat;
// indicate the width and height of the source image to be encoded in terms of pels
// (picture elements) and lines.
int pels; //!< width of picture
int lines; //!< height of picture
int version2; //!< use plus header if set to "1"
int cpusupport; //!< cpu type
//! H263 annex
H263Annex annex;
// annex related parameters
int mv_outside_frame;
int use4mv;
int obmc;
int filter;
int B_frame;
int buf_cycle;
int advanced_intra_coding;
Coeff coeff;
Coeff rcoeff; //!< for AIC option
//! gob indication
int gobsync;
int gfid; //!< the GOB frame ID
//! parameters for Rate Control
int framerate;
int target_bitrate;
int framebits[30];
//! is the number of sequential P-frames to encode.
int p_rate;
//! is the number of skiped frames
int frame_skip;
/* frame level parameters for control */
//! is the sum of all the Quant values on a macroblock basis.
int total_Q;
// QUANT values
int QI; //!< the QUANT value for I-frames.
int QP; //!<the QUANT value for P-frames.
int QB; //!< the QUANT value for B pictures.
//! picture number
int pic_nbr;
//! is the type of frame encoded.
int PTYPE;
//! to save time stamps of B frames(for windows application)
unsigned int nTime[10];
//! to save time reference of B frames
int TR4BPicture[10];
//! Temporal reference of the captured frame.
int TR;
//! Temporal reference of B picture.
int TRB;
//! Temporal reference of P frames in the frame buffer.
int TRP[10];
//! is a counter for the number of frames that have been encoded.
int pcount; /*< use this variant to control p-frames. */
//! is a counter for B frame control
int B_count;
//! buffer index of current reconstructing frame
int zero_index;
//! current reference picture
int ref_pic;
//! buffer index of current reference frame
int ref_index;
/* frame level variables for statistics */
//! indicates the number of bytes encoded into the bitstream for the encoded picture.
int totalBits; //? useful??
//! snr of the reconstructed picture, include snrY,snrCB, snrCR
snr_struct frmsnr;
//! record coded information of the whole frame
int coded_tab[MBR+1][MBC+1];
//! record quant information of the whole frame
int quant_tab[MBR+1][MBC+1];
} H263VencStatus;
//! Structure for Motion Estimation
typedef struct _tagMCPara
{
MotionVector *mv; //!< pointer of current mv
/*! 3D array to save the pointers of all the MVs in one picture,
including mvs in inter4v mode and mvs for B picture */
MotionVector *mv_frame[6][MBR+1][MBC+2]; //!< for all mvs
MotionVector *mv_lastframe[5][MBR+1][MBC+2]; //!< for B frames to compute MVs in
int search_range; //!< search range
//! MV search range for 8x8 block around 16x16 vectors
int search_range_8x8;
/*! the integer search functions will be choosed online */
int method;
//! full search spiral
int SpiralX[6561];
int SpiralY[6561];
}
MCParam;
#define sign(a) ((a) < 0 ? -1 : 1)
#define Int(a) ((a) < 0 ? (int)(a-0.5) : (int)(a))
#define mnint(a) ((a) < 0 ? (int)(a - 0.5) : (int)(a + 0.5))
#define mfloor(a) ((a) < 0 ? (int)(a - 0.5) : (int)(a))
#define mmax(a, b) ((a) > (b) ? (a) : (b))
#define mmin(a, b) ((a) < (b) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define absm(A) ((A)<(0) ? (-(A)):(A)) //!< abs macro, faster than procedure
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -