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

📄 mp4_compressor.c

📁 凌阳32位单片机开发的小游戏
💻 C
字号:
 #include "..\SysLib_Basic\Include\Sys_Register.h"
 #include "include\mp4_compressor.h"
 
extern void print1(char* x);
extern void print2(char x [],int type,unsigned int y);
extern void print3(char x [],int type,unsigned long y);


/////////////////////////////////////////////////////////////
void set_decode_frame_buffer_address()
{
	//---- Buffer control setting
	*P_PTR_SETTING		= 0x1040;//using software(0)/hardware(1) to control buffer change
	*P_C2P_SETTING		= 0x001b;//MP4 trigger TVE triple buffer switch 
       
	*P_TVE_BUF_PTR_REG	= 0x00000001;
	*P_TV_START_ADR1	= BUFFER_START_ADDRESS;
	*P_TV_START_ADR2	= BUFFER_START_ADDRESS+0x00030000;
	*P_TV_START_ADR3	= BUFFER_START_ADDRESS+0x00060000;
	////////////////////////////////////////////////////////////
	*P_MP4V_BUF_PTR_REG	= 0x00; 
	*P_MP4V_START_ADR1	= 0x00000000;
	*P_MP4V_START_ADR2	= 0x00000000;
	//------ SET E/F buffer
	*P_MP4W_BUF_PTR_REG	= 0x01; 
	*P_MP4R_BUF_PTR_REG	= 0x00; 
	*P_MP4W_START_ADR1	= BUFFER_START_ADDRESS;
	*P_MP4W_START_ADR2	= BUFFER_START_ADDRESS+0x00030000;
	*P_MP4W_START_ADR3	= BUFFER_START_ADDRESS+0x00060000;
}
/////////////////////////////////////////////////////////////
void mp4_deocder_prepare(unsigned int width,unsigned int height,unsigned int VOPTimeIncrementLen)
{
	*P_setting_reg0032		=0x30;				//yuv420 to Yuv422
	// imgwidth
	*P_MP4_FRAME_BUF_HSIZE	= width;
	*P_decmjwidth_low		= width;
	*P_decmjwidth_high		= (width>>8);
        
	// imgheight
	*P_decmjheight_low		= height;
	*P_decmjheight_high		= (height>>8);
	// vlc offset
	*P_decVlcOffaddr_low	= 0x00; 
	*P_decVlcOffaddr_mid	= 0x00;                             
	*P_decVlcOffaddr_high	= 0x00;
        
	*P_setting_reg0014		= 0x07; 			//operation mode       

	*P_Hsf					= 0x00;
	*P_Vsf					= 0x00;

	*P_Gopval				= P_FRAME_NUMBER;	//gop can not be zero due to the design architecture
	*P_setting_reg0021		= 0x01;				// bit 0 : dobule buffer enable
												// bit 1 : double buffer update by sor/sdram
												// bit 4 : zero mv
												// bit 7 : video conference mode
	*P_setting_reg0019		= 0x32; 			// bit 0 : goprstn 
                                    			// bit 1 : halfpelen
                                    			// bit 2 : bit rate control enable
                                    			// bit 3 : rate control initial setting
                                    			// bit 4 : SOF mode ( 1 : MJPG engine is triggered by CPU )
                                    			// bit 5 : unrestricted
                                    			// bit 6 : gopsetting
                                    			// bit 7 : Mpg1skipmode
	*P_setting_reg0185		= 0x00000001;		// bit 0 : Truncated after quantization
  												// bit 1 : DCT resolution
	// turn on all the srams of texture engine 
	*P_SRAM_CS_N			= 0x01;
        
	// set Qscale enable
	*P_setting_reg0181 		= 0x06;				// bit 0 : Q value one
                                    			// bit 1 : Q scale en
                                    			// bit 2 : Skip Type
                                    			// bit 3 : ExHeader Enable
                                    			// bit 4 : Half Pix MV enable
	*P_VOPTimeIncLen		= VOPTimeIncrementLen;
	/////////////////////////////////////////////////////////////////////////////////    
	*P_MatchCnt				= 0x03;
	*P_MatchCode0			= 0xb6;
	*P_MatchCode1			= 0x01;
	*P_MatchCode2			= 0x00;
	*P_MatchCode3			= 0x00;
	/////////////////////////////////////////////////////////////////////////////////    
	*P_H263_ctrl			= 0x40;
	/////////////////////////////////////////////////////////////////////////////////    
	*P_Int_Mask				= 0x0f;
}
/////////////////////////////////////////////////////////////
void switch_decode_frame_buffer(unsigned int frame)
{
	unsigned int rd_buffer_switch=frame%3;
	unsigned int wd_buffer_switch=rd_buffer_switch+1;

	if(wd_buffer_switch==3)
		wd_buffer_switch	=0;
	        
	//------ SET C/D buffer ------//
	// RD Bufer
	*P_MP4R_BUF_PTR_REG		= rd_buffer_switch; 
	// WR Bufer
	*P_MP4W_BUF_PTR_REG		= wd_buffer_switch; 
        
	*P_TVE_BUF_PTR_REG		= rd_buffer_switch;
}
/////////////////////////////////////////////////////////////
void decompress_mp4(unsigned int vlc_address)
{
	unsigned int vlc_sa=vlc_address&0xfffffc00;

	*P_MP4V_START_ADR1		= vlc_sa;
    
	*P_decVlcOffaddr_low	= vlc_address;
	vlc_sa					= vlc_address&0x00000300;
	vlc_sa					= vlc_sa>>8;
	*P_decVlcOffaddr_mid	= vlc_sa;
	*P_decVlcOffaddr_high	= 0;
  
	*P_sofeof_ctrl			= 0x00000010;		// bit 0 : mjpg c sof / encode done
                                			    // bit 1 : eof status
                                    			// bit 2 : skip frame
                                    			// bit 3 : sof info
                                    			// bit 4 : mjpg d sof /decode done
 	while ((*P_sofeof_ctrl & 0x10) != 0);                                    
}

⌨️ 快捷键说明

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