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

📄 huffman.h

📁 ESS3890+SL原代码(1*16内存)
💻 H
字号:
/* Copyright 1996, ESS Technology, Inc.					*//* SCCSID @(#)huffman.h	4.3 11/12/03 *//* * $Log$ */#ifndef FAKE#ifndef _HUFFMAN_H_#define _HUFFMAN_H_/************************************************************ * constants ************************************************************//* need to find out a good timeout value */#define HUFFDEC_TIME_OUT 60000/************************************************************ * bit definition in mvd[huffdec_stat2] ************************************************************/#define HUFFDEC_STAT2_PC	0x1f800#define HUFFDEC_STAT2_PTR	0x00700#define HUFFDEC_STAT2_INBITS	0x00008/************************************************************ * bit definition in mvd[huffdec_stat1] ************************************************************/#define HUFFDEC_STAT1_RLA_NUMENTRIES	0x3c0#define HUFFDEC_STAT1_NRLA_NOT_EMPTY	0x40/************************************************************ * high level table entry point(write to mvd[huffdec_cmdblock]) ************************************************************/#define HUFFDEC_CMDBLOCK_JNU		0x0#define HUFFDEC_CMDBLOCK_AUDIO_SYNC	HUFFDEC_CMDBLOCK_SEARCH_SC_BASE/*@24 0x2f402,   // searching for next_start_code; goto pc+2 */#define HUFFDEC_CMDBLOCK_SEARCH_SC	0x24/*@1  0x0f869,   // MBA */#define HUFFDEC_CMDBLOCK_MBA_ADDR	0x01/*@20 0x0f40b,   // 5 bits QUANT */#define HUFFDEC_CMDBLOCK_SLICE_CONT	0x20/*@25 0x0f416,   // searching for start_code after MBA *//* 8 bits of zero eaten */#define HUFFDEC_CMDBLOCK_SEARCH_SC_BASE 0x25/************************************************************ * mask for huffdec_stat3 ************************************************************//* Mask to get cnt[5:0] from HUFFDEC_STAT3. Used multiple times. Ugly!! *//* it's a small contant, no need variable copy */#define HUFFDEC_STAT3_CNT_MSK 0x1f800/************************************************************ * mask for mvd[huffdec_control]  ************************************************************/#define HUFFDEC_FLUSH_DMA	0x4000#define HUFFDEC_VALID_ENABLE	0x0800#define HUFFDEC_VALID_OVR	0x0200#define HUFFDEC_VID_MODE	0x0040#define HUFFDEC_AUD_MODE	0x0000#define HUFDECRESET		0x00000002#define HUFFIFORESET		0x00000001#define HUFRESET		(HUFDECRESET | HUFFIFORESET)#define HUFDECLDMODE 		0x00000004#define HUFDECHSRAM		0x00000020/************************************************************ * nrla mb increment value with special meaning ************************************************************/#define HUFFD_STUFF_CODE	(128 + 34)#define HUFFD_ESCAPE_CODE	(128 + 35)#define HUFFD_START_CODE	(0x40)#define HUFFD_START_CODE_HALF	(0x41)/************************************************************ * MTYPE bit definition * stored in Huff. decoder r0 ************************************************************/#ifdef MPEG1 #define	MB_INTRA		1	/* Macroblock intra		*/#define	MB_CBP       		2	/* Macroblock with coded-block-	*					 * pattern (cbp)		*/#define	MB_MVB	        	4	/* Macroblock with backward	*					 * motion vector		*/#define	MB_MVF       		8	/* Macroblock with forward	*					 * motion vector		*/#define	MB_QUANT		16	/* Macro block with quantizer	*/#else#define MB_INTRA	0x01#define MB_CBP		0x02#define MB_MOTIONB	0x04#define MB_MOTIONF	0x08#define MB_QUANT	0x10#define MB_FRAME_MV	0x20#define MB_DCT_TYPE	0x40#endif/************************************************************ * combinational MTYPE ************************************************************/#define MB_MC_DPCM_F_Q	(MB_QUANT|MB_MVF|MB_CBP)#define MB_MC_DPCM_B_Q	(MB_QUANT|MB_MVB|MB_CBP)#define MB_MC_DPCM_FB_Q (MB_QUANT|MB_MVF|MB_MVB|MB_CBP)#define MB_DPCM_Q	(MB_QUANT|MB_CBP) /* Only in P frame ... */#define MB_MC_DPCM_F	(MB_MVF|MB_CBP)#define MB_MC_DPCM_B	(MB_MVB|MB_CBP)#define MB_MC_DPCM_FB	(MB_MVF|MB_MVB|MB_CBP)#define MB_DPCM		(MB_CBP)	/* Hmm only P-frame too */#define MB_INTRA_Q	(MB_INTRA|MB_QUANT)/* -------------------------------- *//* Huffman Com *//* ??? still used */#define HUFCOM_ENDIAN_IN	0x00000004	/* for decoding */#define HUFCOM_ENDIAN_OUT	0x00000000	/* for encoding */#define HUFCOM_TRE_IRQ		0x00000008	/* for oddbyte handling */#define huftbl			0x00002800	/* Huffman table start addr *//* ck_nrla_fifo(a): return 1 if num entries in nrla fifo < a */#define ck_nrla_fifo(a)		((mvd[huffdec_stat1] & 0x3f) < (a))/* wait_nrla_fifo(a): loop until num entries in nrla fifo >= a */#if 1/* a is always constant in our applications; * therefore, the if condition will be determined at compile time */#define wait_nrla_fifo(a) \{ \  if (a==1) while(!(mvd[huffdec_stat1] & 0x1)); \  else while(ck_nrla_fifo(a)); \}#else#define wait_nrla_fifo(a)		do{\  int way_too_much=0;\  int tmp;\  while((tmp = (mvd[huffdec_stat1] & 0x3f)) < (a)) {\    way_too_much++;\    if (way_too_much > HUFFDEC_TIME_OUT) {\      printf("No rla data:count:%x\n",tmp);\      printf("HUFFSTATE:%X\n",HuffState);\      printf("huffdec_stat1:%x\n",mvd[huffdec_stat1]);\      DBG_console();    }\  }\} while (0)#endif/* get a 12 bit data from nrla fifo */#define get_nrla_data(a)	do {\  wait_nrla_fifo(1); \  a = mvd[huffdec_nrlarisc] & 0xfff;\} while (0)/* get_nrla_data_nocheck, convert data from 12 bit sign-magnitude to signed  * according to type of a  */#define get_nrla_data_nocheck(a) \  a = mvd[huffdec_nrlarisc]#define get_nrla_data_nomask(a) do { \  wait_nrla_fifo(1); \  a = mvd[huffdec_nrlarisc]; \} while (0)/* masking of 0xfff is necessary */#define get_nrla_data_MV(a) do {	\  int temp; \  get_nrla_data(temp); \  if (temp & 0x800) temp = 0x800 - temp;\  a = temp;				\} while (0)/* The following macro gets data from huffman input fifo *//* note: remember to set up path for data, whether to get it from * ahuffdec or vhuffdec */#define wait_huffin_valid() while ((mvd[huffdec_stat3] & 0xff) != 0xff)/* The following only works when the size of the two hufdec fifos are 16! */#if 0#define wait_huffdec_fifo(AOrV, n) do {					\    int ff_entries = (mvd[cat3(gate_,AOrV,hufdec_ff_status)]>>2)&0x3f;	\    ff_entries = (ff_entries >> 2) + (ff_entries & 0x3);		\    if (ff_entries >= n) break;						\} while (1)#else#define wait_huffdec_fifo(AOrV, n) do {                                 \  int way_too_much = 0; \  int ff_entries;                                                       \  do { \    ff_entries = (mvd[cat3(gate_,AOrV,hufdec_ff_status)]>>2)&0x3f;      \    ff_entries = (ff_entries >> 2) + (ff_entries & 0x3);                \    if (way_too_much++ >=150000) { \         fifo_timeout=1; \         break; \     }\   } while( ff_entries < n);  \} while (0)#endif#ifdef WAIT_HD_FIFO_USE_MACRO#define HUFF_wait_fifo_audio(n) do {	\    wait_huffdec_fifo(a, n);		\} while (0)#define HUFF_wait_fifo_video(n) do {	\    wait_huffdec_fifo(v, n);		\} while (0)#endif/* macro for changing huffman high sram table values */#define huff_change(location, value) do {			\        mvd[huffdec_highsram + location] = value;		\} while (0)#define HUFF_wait_jnu() do {				\  do {} while (mvd[huffdec_stat2] & HUFFDEC_STAT2_PC);	\} while (0)#define HUFF_byte_align() do {					 \    int scratch = (mvd[huffdec_stat2] >> 8) & 0x7;     		 \    if (scratch) mvd[huffdec_shiftregister] = (8 - scratch) - 1; \} while (0)#define HUFF_eatamount(n)	mvd[huffdec_eatamount] = (n) - 1#define HUFF_switch_to_video() do {	\        mvd[huffdec_control] = 0x40c0;	\	asm("nop"); asm("nop");		\        mvd[huffdec_control] = 0x4ac0;	\	mvd[huffdec_packet_counter] = 0x100; \} while (0)#define HUFF_switch_to_audio() do {	\        mvd[huffdec_control] = 0x4000;	\	asm("nop"); asm("nop");		\        mvd[huffdec_control] = 0x4a00;	\} while (0)/* public functions */extern void HUFF_init(void);extern void HUFF_reset_output_fifo_and_state(void);extern int  HUFF_getbits(int);		/* 8 bits or less */extern int  HUFF_getbits_med(int);	/* up to 16 bits */extern int  HUFF_getbits_big(int);	/* more than 16 bits */extern int  HUFF_autoeat(void);	/* 8 bits or less, use existing eatamount */extern void HUFF_wait_idle(void);/* global variables */GBLDEF0(int fifo_timeout); /* for fifo wait  timeout */#endif /*_HUFFMAN_H_*/#else	/* FAKE */#define HUFF_getbits(n)         STREAM_getbits(n)#define HUFF_getbits_med(n)     STREAM_getbits(n)#define HUFF_getbits_big(n)     STREAM_getbits(n)#define HUFF_eatamount(n)       STREAM_eatamount(n)#define HUFF_autoeat()          STREAM_autoeat()#define HUFF_byte_align()       STREAM_byte_align()#endif

⌨️ 快捷键说明

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