www.pudn.com > henclib263.rar > HEnc.h
/*
* HEnc.h
*
* Definition of data structure used by encoder,
* Definition of macros and global variables
*
* Copyright (c) 2002-2004 Li Chun-lin(li_chunlin@263.net)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef HENC_H
#define HENC_H
#ifdef __cplusplus
extern "C" {
#endif
#define _HENDLIB
/* Source format */
#define _SUBQCIF 1 //!< 88x72
#define _QCIF 2 //!< 176x144
#define _CIF 3 //!< 352x288
#define _4CIF 4
#define _16CIF 5
/* 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
//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
//! 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
{
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
}H263Annex;
//! 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];
//! Temporal reference of P frames in the frame buffer.
int TRP[10];
//! the buffer to store input frame for B picture.
Image BPicture[10];
//! to save time reference of B frames
int TR4BPicture[10];
//! points to the interpolated picture
unsigned char *prev_ipol;
//! interpolated picture for the searching for backward MV
unsigned char *next_ipol;
/* 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;
// 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"
//! H263 annex
H263Annex annex;
// annex related parameters
int mv_outside_frame;
int use4mv;
int obmc;
int filter;
int B_frame;
int buf_cycle;
//! gob indication
int gobsync;
int gfid; //!< GOB frame ID
// 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.
//! 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;
//! picture number
int pic_nbr;
//! is the type of frame encoded.
int PTYPE;
//! to save time stamps of captured frames(for windows application)
unsigned int nTime[10];
//! Temporal reference.
int TR;
//! Temporal reference for B picture.
int TRB;
//! 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??
//! indicates the number of encoded bits per picture.
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;
}
MCParam;
//! 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;
unsigned char *pout; //!< stream buffer
int buff_size; //!< buffer size
int ptr;
char pcnt; //!< the numbers of vacant bits in the temperory byte */
char bitout; //!< the temperory byte
/*!< the whole byte 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;
#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
#ifdef __cplusplus
}
#endif
#endif