⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h264_define.h

📁 自己在wince的环境下做的一移动数字电视驱动
💻 H
📖 第 1 页 / 共 4 页
字号:
#define H264MB_BLOCK_SIZE		16
#define H264MB_BLOCK_SIZE_SHIFT	4
#define H264MB_BLOCK_SIZE_HALF	((H264MB_BLOCK_SIZE)/2)
#define H264MB_BLOCK_SIZE_HALF_SHIFT	3
#define H264MB_BLOCK_MULTIPLE	4

#ifdef H264DEC_SUPPORT_VGA
#	define MAXFRAMEHEIGHTINMBS		(30)	// 1200 Mbs: QVGA 640(40)x480(30)
#else //H264DEC_SUPPORT_VGA
#	define MAXFRAMEHEIGHTINMBS		(18)	//Mbs: T-DMB 352x288, MB(22x18)
#endif //H264DEC_SUPPORT_VGA
								

#if 1 //TEST_WQVGA20061101
#	ifdef H264DEC_SUPPORT_VGA
#		define MAXPICSIZEINMBS		(40*MAXFRAMEHEIGHTINMBS) 	// 1200 Mbs: QVGA 640(40)x480(30)
#		define MAXPICWIDTHINMBS		(40)						// 1200 Mbs: QVGA 640(40)x480(30)
#		define MAXPICWIDTHINMBS2	(40)						// 1200 Mbs: QVGA 640(40)x480(30)
#	else //H264DEC_SUPPORT_VGA
#		define MAXPICSIZEINMBS		(30*MAXFRAMEHEIGHTINMBS)	// 510 Mbs: WQVGA 480x272
#		define MAXPICWIDTHINMBS		(30)						// 510 Mbs: WQVGA 480x272
#		define MAXPICWIDTHINMBS2	(30)						// 510 Mbs: WQVGA 480x272
#	endif //H264DEC_SUPPORT_VGA
#else //TEST_WQVGA20061101
#	define MAXPICSIZEINMBS		(22*MAXFRAMEHEIGHTINMBS) // 396 Mbs: T-DMB 352x288
#	define MAXPICWIDTHINMBS		(24)	//Mbs: T-DMB WDF 384x224, MB(24
#	define MAXPICWIDTHINMBS2	(24)	//Mbs: T-DMB WDF 384x224, MB(24
#endif //TEST_WQVGA20061101

#define MAXPICWIDTHINMBSPLUS1	(MAXPICWIDTHINMBS+1)

#define MAXPICPICELWIDTH2		((H264MBS_SIZE)*(MAXPICWIDTHINMBS2))

#define MAXPICPICELWIDTH		((H264MBS_SIZE)*(MAXPICWIDTHINMBS))
#define MAXPICPICELWIDTH_HALF	((H264MBS_SIZE>>1)*(MAXPICWIDTHINMBS))
#define MAXPICPICELWIDTH_INT	((H264MBS_SIZE>>2)*(MAXPICWIDTHINMBS))
#define MAXPICPICELHEIGHT		((H264MBS_SIZE)*(MAXFRAMEHEIGHTINMBS))
#define MAXPICSIZEINSUBMBS		(MAXPICSIZEINMBS*H264BLOCK_SIZE*H264BLOCK_SIZE) //6336 Mbs: T-DMB
#define MAXPICSIZEINSUBMBSWIDTH ((MAXPICWIDTHINMBS)*H264BLOCK_SIZE)
#define MAXPICSIZEINSUBMBSWIDTHHALF ((MAXPICWIDTHINMBS)*(H264BLOCK_SIZE>>1))

#define MAXPICPIXELWIDTH		((H264MB_BLOCK_SIZE)*(MAXPICWIDTHINMBS))
#define MAXPICPIXELWIDTH2		((MAXPICPIXELWIDTH)*2)
#define MAXPICPIXELHEIGHT		((H264MB_BLOCK_SIZE)*(MAXFRAMEHEIGHTINMBS))
#define MAXPICPIXELSIZE			(MAXPICSIZEINMBS*H264MB_BLOCK_SIZE*H264MB_BLOCK_SIZE)	//added by soo 20050401

#define MAXPICPIXELSIZEHALF		(((int)MAXPICPIXELSIZE)>>1)						//added by soo 20050407
#define MAXPICPIXELSIZEQUARTER	(((int)MAXPICPIXELSIZE)>>2)						//added by soo 20050429

#define MAXPICPIXELYUVFACTOR	(1.5)  //added by soo 20050419

#define H264IMAGEOFFSET			((MAXPICPIXELSIZE)*(MAXPICPIXELYUVFACTOR))
#define H264_INPUT_BUFFER_SIZE	((int)(MAXPICPIXELSIZE*MAXPICPIXELYUVFACTOR*1/*5*/))
#define MAX_CODED_FRAME_SIZE	((int)(MAXPICPIXELSIZE*MAXPICPIXELYUVFACTOR*1/*5*/)) //modified by soo

#define MAX_CODED_FRAME_NUM_MBS ((int)(MAXPICSIZEINMBS*MAXPICPIXELYUVFACTOR)) //the maximum total number of MBs for CIF(352x288) : 396 = 22x18
#define LUMA_FORMAT_SIZE		((H264MB_BLOCK_SIZE)*(H264MB_BLOCK_SIZE)) //the total number of pixels in a MB.		

#define LBLKSIZE				4
#define CBLKSIZE				2
#define MBPARTSIZE				2

// chromaFormat	ChromaFormatFactor  ChromaFormatFactor2(Idx) Luma	Cb(HxW)	Cr(HxW) Table(Height, Width, ChromaFormatSize)
// monochrome	: 1					: 0						16x16	0		0				0		0			0
// 4:2:0		: 1.5				: 1						16x16	8x 8	 8x 8			8		8			64
// 4:2:2		: 2					: 2						16x16	16x 8	16x 8			16		8			128
// 4:4:4		: 3					: 3						16x16	16x16	16x16			16		16			256
#define CHROMA_FORMAT_FACTOR2	1 //4:2:0 format

#if   CHROMA_FORMAT_FACTOR2 == 0
	#define CHROMA_FORMAT_HEIGHT	0
	#define CHROMA_FORMAT_WIDTH		0
	#define CHROMA_FORMAT_SIZE		0
#elif CHROMA_FORMAT_FACTOR2 == 1
	#define CHROMA_FORMAT_HEIGHT	8
	#define CHROMA_FORMAT_WIDTH		8
	#define CHROMA_FORMAT_SIZE		64
#elif CHROMA_FORMAT_FACTOR2 == 2
	#define CHROMA_FORMAT_HEIGHT	16
	#define CHROMA_FORMAT_WIDTH		8
	#define CHROMA_FORMAT_SIZE		128
#elif CHROMA_FORMAT_FACTOR2 == 3
	#define CHROMA_FORMAT_HEIGHT	16
	#define CHROMA_FORMAT_WIDTH		16
	#define CHROMA_FORMAT_SIZE		256
#endif

#define EOR						-1		//ERROR Of bistream.. added by soo 20050620
#define EOS						1		// End Of Sequence
#define SOP						2       // Start Of Picture
#define SOS						3       // Start Of Slice

//Start code and Emulation Prevention need this to be defined in identical manner at encoder and decoder
#define ZEROBYTES_SHORTSTARTCODE 2 //indicates the number of zero bytes in the short start-code prefix

#define H264DECODE_MB			1
#define H264_DECODING_OK		0
#define H264_SEARCH_SYNC		1

// 4x4 intra prediction modes
#ifndef VERT_PRED
#define VERT_PRED				0
#define HOR_PRED				1
#define DC_PRED					2
#define DIAG_DOWN_LEFT_PRED		3
#define DIAG_DOWN_RIGHT_PRED	4
#define VERT_RIGHT_PRED			5
#define HOR_DOWN_PRED			6
#define VERT_LEFT_PRED			7
#define HOR_UP_PRED				8

#define DC_PRED_INT				((DC_PRED<<24)|(DC_PRED<<16)|(DC_PRED<<8)|(DC_PRED)) //added by soo 20060308_1
#endif

// 16x16 intra prediction modes
#ifndef VERT_PRED_16
#define VERT_PRED_16			0
#define HOR_PRED_16				1
#define DC_PRED_16				2
#define PLANE_16				3
#endif

// 8x8 chroma intra prediction modes
#ifndef DC_PRED_8
#define DC_PRED_8				0
#define HOR_PRED_8				1
#define VERT_PRED_8				2
#define PLANE_8					3
#endif

/* mb_type Definition*/

/* for I_SLICE */
#define	I_4x4					0
#define	I_16x16_0_0_0			1
#define	I_16x16_1_0_0			2
#define	I_16x16_2_0_0			3
#define	I_16x16_3_0_0			4
#define	I_16x16_0_1_0			5
#define	I_16x16_1_1_0			6
#define	I_16x16_2_1_0			7
#define	I_16x16_3_1_0			8
#define	I_16x16_0_2_0			9
#define	I_16x16_1_2_0			10
#define	I_16x16_2_2_0			11
#define	I_16x16_3_2_0			12
#define	I_16x16_0_0_1			13
#define	I_16x16_1_0_1			14
#define	I_16x16_2_0_1			15
#define	I_16x16_3_0_1			16
#define	I_16x16_0_1_1			17
#define	I_16x16_1_1_1			18
#define	I_16x16_2_1_1			19
#define	I_16x16_3_1_1			20
#define	I_16x16_0_2_1			21
#define	I_16x16_1_2_1			22
#define	I_16x16_2_2_1			23
#define	I_16x16_3_2_1			24
#define	I_PCM					25		//interface : 0x04

/* MbPartPredMode() return Val */
#define INTRA_4x4				26		//interface : 0x02
#define INTRA_16x16				27		//interface : 0x03

/* for P_SLICE */
#define P_L0_16x16				30		//interface : 0x05
#define P_L0_L0_16x8			31		//interface : 0x06
#define P_L0_L0_8x16			32		//interface : 0x07
#define P_8x8					33		//interface : 0x08
#define P_8x8ref0				34		//interface : ???
#define P_SKIP					35		//interface : 0x15

#define Pred_L0					50		// Table 7-14
#define Pred_L1					51

#define NA						60

/* check intra_inter_flag */
// mb_type
#define INTRA_CODING(x)			( ( x >= 0 ) && ( x < 25 ) )
#define INTRA_IPCM_CODING(x)	( ( x >= 0 ) && ( x =< 25 ) )
// mb_type2
#define INTRA_CODING2(x)		( ( x == 26 ) || ( x == 27 ) )
#define INTRA_IPCM_CODING2(x)	( ( x == 25 ) || ( x == 26 ) || ( x == 27 ) )


/* mb_type in TaskList */
/*
#define T_I_PCM			0x04
#define T_INTRA_4x4		0x02
#define T_INTRA_16x16	0x03
#define T_P_L0_16x16	0x05
#define T_P_L0_L0_16x8	0x06
#define T_P_L0_L0_8x16	0x07
#define T_P_8x8ref0		0x08
#define T_P_8x8			0x08
#define T_P_SKIP			0x09
#define T_INVALID		0x0FF
*/

/* for Sub_mb_pred  Table 7-14 */
#define	P_L0_8x8						0
#define	P_L0_8x4						1
#define	P_L0_4x8						2
#define	P_L0_4x4						3

/* mb_type Definition End */

/* prediction type of motion vector */ //added by soo 20050530
#define MVPRED_MEDIAN					0
#define MVPRED_L						1
#define MVPRED_U						2
#define MVPRED_UR						4 //modified by soo 20050729_1 from 3

#define NONE							-1

#define LUM								0
#define CHROM							1

/* IDCT Transform */ //moved from H264_iTransform.h by soo 20050421
#define DQ_BITS							6

/* CAVLC */
#define LUMA_DC_BLOCK_INDEX				25
#define CHROMA_DC_BLOCK_INDEX			26

#define CHROMA_DC_COEFF_TOKEN_VLC_BITS	8
#define COEFF_TOKEN_VLC_BITS			8
#define TOTAL_ZEROS_VLC_BITS			9
#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS	3
#define RUN_VLC_BITS					3
#define RUN7_VLC_BITS					6

/* error */
#include "h264_define_error.h"

/* macro functions */
#define DQ_ROUND				(1<<5/*(DQ_BITS-1)*/)
#define Clip3(min,max,val)		(((val)<(min))?(min):(((val)>(max))?(max):(val)))
#define ABS(a) 					((a) > 0 ? (a) : (-(a))) 
#define Clip1( val )		( ((val) < 0)? 0 : ( ((val) > 255)? 255 : (val) ) )

#define	MIN(x, y)			( ( (x) < (y) )? (x) : (y) )
#define	MAX(x, y)			( ( (x) > (y) )? (x) : (y) )


#define	Cb		0
#define	Cr		1


//#define	EVENMB		(mb_x&1)
//#define	ODDMB		((~mb_y)&1)
#define	EVENMB		(gCurMBAddr&0x1)
#define	ODDMB		((~gCurMBAddr&0x1)

#define	T0(x)		((x)&0xFF)
#define	T1(x)		(((x)&0xFF)<<8)
#define	T2(x)		(((x)&0xFF)<<16)
#define	T3(x)		(((x)&0xFF)<<24)


#ifndef FALSE
  typedef enum {
	FALSE,
	TRUE
  } Boolean;
#endif //FALSE

#ifndef NALU_TYPE_SLICE
typedef enum {
	NALU_TYPE_SLICE    =1,
	NALU_TYPE_DPA      =2,
	NALU_TYPE_DPB      =3,
	NALU_TYPE_DPC      =4,
	NALU_TYPE_IDR      =5,
	NALU_TYPE_SEI      =6,
	NALU_TYPE_SPS      =7,
	NALU_TYPE_PPS      =8,
	NALU_TYPE_AUD      =9,
	NALU_TYPE_EOSEQ    =10,
	NALU_TYPE_EOSTREAM =11,
	NALU_TYPE_FILL     =12
} NALU_TYPES;
#endif

#ifndef P_SLICE
  typedef enum {
	P_SLICE = 0,
	B_SLICE,			//not use for DMB
	I_SLICE,
	SP_SLICE,			//not use for DMB
	SI_SLICE			//not use for DMB
} SliceType;
#endif //P_SLICE

/*
#ifndef UEG_V
  typedef enum {
	  UEG_V,
	  SEG_V,
	  MEG_V
  } Exp_golomb;
#endif //UEG_V
*/

typedef struct old_slice_par // only 946ES : 20 bytes
{
   unsigned int 	frame_num;
   #if 0 //mod from int to byte
   int nal_ref_idc;
   int idr_flag;
   int idr_pic_id;
   int pps_id;
   #else
   unsigned char 	nal_ref_idc;      
   unsigned char 	pps_id;
   unsigned short 	idr_pic_id;
   int	 			idr_flag;   
   #endif 
} OldSliceParams_t;

#ifndef NALU_t
typedef struct		//8 bytes
{
  uint8_t			*buf;								// conjtains the first byte followed by the EBSP
  unsigned short	len;								// the byte size of the NAL unit
  uint8_t			nal_unit_type;						//u(5) // NALU_TYPE_xxxx
														//0 or >12 not used
														// 1 : Coded slice of a non-IDR picture
														// 2, 3, 4 : not used((baseline profile)													
														// 5 : Coded slice of an IDR picture

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -