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

📄 codec.cpp

📁 VW2010芯片的控制程序和库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	}
	else if(name=="Open_Encode_Channel")
	{	//Open Encode function? ( Open=Run Encode; Close=Stop Encode function)
			if(val == "Close" || val=="CLOSE"){
				info->doEncode = FALSE;
			}
			else
				info->doEncode = TRUE;
	}else if(name=="SplitAV_enc"){		//Splite Video and Audio ? ( "Yes" or "No" ) , ONLY avialiable under PS
			if( info->m_StreamType == PS){
				if((val=="YES") || (val=="yes")|| (val=="Yes")){
					info->doSplitAV = TRUE;
				}
				else
					info->doSplitAV = FALSE;
			}
			else
				info->doSplitAV = FALSE;
			cprintf("Splite AV = %d\n", info->doSplitAV );
	}else if(name=="Video_Resolution"){		//(Encode) Video Resolution
			if(info->m_SignalType == PAL ){
				if( val=="D1"){
					value = "720x576";
				}else if( val=="1/2D1"){
					value = "352x576";
				}else if( val=="CIF"){		//SIF
					value = "352x288";
				}else if( val=="QCIF"){
					value = "176x144";
				}else
					value = "352x288";
			}else{
				if( val=="D1"){
					value = "720x480";
				}else if( val=="1/2D1"){
					value = "352x480";
				}else if( val=="CIF"){
					value = "352x240";	//SIF
				}else if( val=="QCIF"){
					value = "176x144";
				}else
					value = "352x240";
			}
			x_pos = value.find("x");
			 // check to see if entry is valid
			 if (x_pos != std::string::npos) {
				  // get Horizontal
				  vid_h.assign(value,0,x_pos);
				  // get vertical
				  vid_v = value.substr(x_pos+1);
				 if(info->m_StreamType == TS){
					 vw2010->SetParam( "video_horizontal_size", STRUCT_MUX , strtoul(vid_h.c_str(), NULL, 0));
					 vw2010->SetParam( "video_vertical_size", STRUCT_MUX , strtoul(vid_v.c_str(), NULL, 0));
				 } else{
					 vw2010->SetParam( "vid_horizontal_size_value", STRUCT_MUX , strtoul(vid_h.c_str(), NULL, 0));
					 vw2010->SetParam( "vid_vertical_size_value", STRUCT_MUX , strtoul(vid_v.c_str(), NULL, 0));
				 }
			 }
	}else if(name=="Video_Bitrate"){				//(Encode) Video BitRate
			ul = 1000*strtoul(val.c_str(), NULL, 0);
			ul = MIN( ul, 15000000);
			ul = MAX( ul, 128000);
			cprintf("Video_Bitrate(average) = %d\n", ul);
			vw2010->SetParam( "vid_vbr", STRUCT_MUX , 1 );		//set "vbr" enable
			vw2010->SetParam( "vid_average_bit_rate", STRUCT_MUX , ul);
			if( info->m_StreamType == TS)
				vw2010->SetParam( "video_bit_rate", STRUCT_MUX , ul);
			else
				vw2010->SetParam( "vid_bit_rate", STRUCT_MUX , ul);
	}else if(name=="Video_Percentage_of_Variance"){			//(Encode) VBR Video Bitrate in %. 
			if ( 0 == strtol(val.c_str(), NULL, 0) ){
				vw2010->SetParam( "vid_vbr", STRUCT_MUX , 0 );		//if =0, then set "vbr" DISABLE
			}else{
				vw2010->SetParam( "vid_vbr", STRUCT_MUX , 0 );		//Set "vbr" ENABLE
				ul = vw2010->GetParam( "vid_average_bit_rate" , STRUCT_MUX);
				ul2 = 100+strtol(val.c_str(), NULL, 0);
				ul2 = (ul/100)*ul2;
				if( info->m_StreamType == TS)
					vw2010->SetParam( "video_bit_rate", STRUCT_MUX , ul2);
				else{
					vw2010->SetParam("vid_bit_rate", STRUCT_MUX , ul);
					vw2010->SetParam("vid_average_bit_rate", STRUCT_MUX , ul2);
				}
			}
			cprintf("Video_Bitrate(top) = %d\n", ul2);
	}else if(name=="Audio_Input_Mode"){				//(Encode) Audio Input Mode
			if (val == "DualChannel"){
				ul = 1;
			}else if ( val == "JointStereo"){
				ul = 2;
			}else if(val == "Mono"){
				ul = 3;
			}else {
				ul = 0;	// = stereo
			}
			if ( info->m_StreamType == TS)
				vw2010->SetParam("audio_channel", STRUCT_MUX , ul);
			else
				vw2010->SetParam("aud_mode", STRUCT_MUX , ul);
	}else if(name=="Audio_Bitrate"){			//(Encode) Audio encode BitRate
			if( val == "32K"){
				ul = 32000;
				ul2 = 1;
			}else if ( val == "48K"){
				ul = 48000;
				ul2 = 2;
			}else if ( val == "56K"){
				ul = 56000;
				ul2 = 3;
			}else if ( val == "64K"){
				ul = 64000;
				ul2 = 4;
			}else if ( val == "80K"){
				ul = 80000;
				ul2 = 5;
			}else if ( val == "96K"){
				ul = 96000;
				ul2 = 6;
			}else if ( val == "112K"){
				ul = 112000;
				ul2 = 7;
			}else if ( val == "128K"){
				ul = 128000;
				ul2 = 8;
			}else if ( val == "160K"){
				ul = 160000;
				ul2 = 9;
			}else if ( val == "192K"){
				ul = 192000;
				ul2 =10;
			}else if ( val == "224K"){
				ul = 224000;
				ul2 = 11;
			}else if ( val == "256K"){
				ul = 256000;
				ul2 = 12;
			}else if ( val == "320K"){
				ul = 320000;
				ul2 = 13;
			}else if ( val == "384K"){
				ul = 384000;
				ul2 = 14;
			}else {
				ul = 32000;
				ul2 = 1;
			}
			cprintf("Audio_Bitrate = %d, %d \n", ul, ul2);
			if ( info->m_StreamType == TS){
				vw2010->SetParam("audio_bit_rate", STRUCT_MUX , ul2);
			}
			else{
				vw2010->SetParam("aud_bit_rate", STRUCT_MUX , ul);
			}
	}else if(name=="Video_Stream_Type"){				//(Encode) Encode Video Stream Type
			if( val == "MPEG1" )
				n = 1;
			else if (val == "MPEG2")
				n = 2;
			else
				n = 4;
			if( info->m_StreamType == TS ){
				vw2010->SetParam( "mpeg_coding_standard", STRUCT_MUX , n );
				vw2010->SetParam( "mux_mpeg_coding_standard", STRUCT_MUX , n );
			} else {
				vw2010->SetParam( "vid_stream_type", STRUCT_MUX , n );
			}
			info->m_MPEGType = (n==1 ? MPEG1 : n==2 ? MPEG2 : MPEG4);		
	}else if(name=="Video_Format"){				//(Encode) Video Fomart( Signal Type : PAL / NTSC )
			n = (val=="PAL"? PAL : NTSC );
			cprintf("video_format = %d.(PAL=1)\n",n);
			if(info->m_StreamType == TS){
				vw2010->SetParam( "vid_video_format", STRUCT_MUX , n );			 // we set them both
				vw2010->SetParam( "video_format", STRUCT_MUX , n); 			// we set them both
			}else{
				vw2010->SetParam( "vid_video_format", STRUCT_MUX , n );	
			}
			// try to get the video format
			info->m_SignalType = (SignalType)n;
			cprintf("Set video_format to %d(PAL=1)\n", info->m_SignalType);
	}else if(name=="Video_Frame_Rate"){				//(Encode) Encode Video Frame Rate
			if( info->m_SignalType == NTSC)
				vw2010->SetParam( "vid_frame_rate_code", STRUCT_MUX , 5 ); // NTSC => 30fps
			else
				vw2010->SetParam( "vid_frame_rate_code", STRUCT_MUX , 3 ); //PAL => 25fps

			if( val=="12.5" || val =="15" ) { //skip 1 frame per 2 frame
				if(info->m_StreamType == PS){
					vw2010->SetParam( "vid_low_delay", STRUCT_MUX , 1 );	//ENABLE Low_Delay
					vw2010->SetParam( "vid_frame_skip",STRUCT_MUX ,1);
				}
				else{
					vw2010->SetParam( "low_delay", STRUCT_MUX, 138);//129
				}
			}else if( val=="8" || val =="10" ) { //skip 2 frame per 3 frame
				if(info->m_StreamType == PS){
					vw2010->SetParam( "vid_low_delay", STRUCT_MUX , 1 );	//ENABLE Low_Delay
					vw2010->SetParam( "vid_frame_skip",STRUCT_MUX ,2);
				}
				else{
					vw2010->SetParam("low_delay", STRUCT_MUX ,144);//129
				}
			}else{
				if(info->m_StreamType == PS){
					vw2010->SetParam("vid_low_delay", STRUCT_MUX , 1);
					vw2010->SetParam("vid_frame_skip", STRUCT_MUX , 0);
				}
				else{
					vw2010->SetParam("low_delay", STRUCT_MUX , 0 );//129
				}
			}
	}else if(name=="dec_Mpeg_Coding_Standard"){				//(Decode) MPEG Coding standard
			if( val == "MPEG1" )
				n = 1;
			else if (val == "MPEG2")
				n = 2;
			else 
				n = 4;
			vw2010->SetParam( "mpeg_coding_standard", STRUCT_DEMUX, n);
	}else if(name=="dec_Video_Format"){				//(Decode) Video Format
			n=(val=="PAL"? 2 : 1);
			cprintf("video_format(DEMUX): %d (PAL=2)\n",n);
				vw2010->SetParam( "video_format", STRUCT_DEMUX , n);
				info->m_decSignalType = (SignalType)n;
	}else if(name=="dec_Audio_Mute"){				//(Decode) Mute Audio
			if(val == "NO" || val == "No" || val == "no" )
				ul = 0x00;
			else 
				ul = 0x01;
			vw2010->SetParam( "audio_mute", STRUCT_DEMUX, ul);
    	}else{
	    		return FAILURE;
    	}
	return SUCCESS;	
}
//*/
/****************************************************/
/*	Get Stream_Type from config file( in XML format ). 
ONLY surport PROGRAM_STREAM and TRANSPORT_STREAM.
INPUT	@filename	:name of the config file( include path name).
		@config		:point of ConfigSetting structure for store stream type var.
RETURN	:	SUCCESS;FAILURE	;
*/
int	configGetStreamType_XML( char *filename, ConfigSetting *config)
{
	std::string line, name, name2, val, str1, str2;
	FILE *file = fopen(filename, "r");
	if ( file == NULL ){
		printf("[ CODEC application ] : Connot open config file.\n");
		return FAILURE;
	}
	char lineTemp[8*1024];
	while (fgets(lineTemp, sizeof(lineTemp), file)!=NULL) {
		if (lineTemp[strlen(lineTemp)-1]=='\n') lineTemp[strlen(lineTemp)-1] = '\0';
		line.erase();
		line.insert(0, lineTemp);

		if (line.find_first_not_of(" \t\n\r")==std::string::npos) continue; // skip ahead if line is empty
		if (line[0]=='#') continue; // skip ahead if the line is a comment
		if (line[0]=='<' && line[1]=='!') continue;		//comment line in .xml file

		if (configParseLine_XML(line, name, val) == -1) continue; 

		if( name ==	"Stream_Type"){
			if (val == "PROGRAM_STREAM") {
				config->m_StreamType = PS;
				dprintf("[ CODEC application ] : Stream_Type = PS\n");
				return SUCCESS;
			} else {
			       config->m_StreamType = TS;
				dprintf("[ CODEC application ] : Stream_Type = TS\n");
				return SUCCESS;
			} 
		}
	}
	printf("[ CODEC application ] : Cannot find StreamType in config file.\n");
	if (fclose(file)!=0) printf("[ CODEC application ] : Cannot close options file.\n");
	return FAILURE;
}
/****************************************************/
/*	Get Device_Type from config file( in XML format ). 
ONLY surport CODEC and CODEC_G7xx.
INPUT	@filename	:name of the config file( include path name).
		@config		:point of ConfigSetting structure for store Control Mode var.
RETURN	:	SUCCESS;FAILURE	;
*/
int	configGetControlMode_XML( char *filename, ConfigSetting *config)
{
	std::string line, name, name2, val, str1, str2;
	FILE *file = fopen(filename, "r");
	if ( file == NULL ){
		printf("[ CODEC application ] : Connot open config file.\n");
		return FAILURE;
	}
	char lineTemp[8*1024];
	while (fgets(lineTemp, sizeof(lineTemp), file)!=NULL) {
		if (lineTemp[strlen(lineTemp)-1]=='\n') lineTemp[strlen(lineTemp)-1] = '\0';
		line.erase();
		line.insert(0, lineTemp);

		if (line.find_first_not_of(" \t\n\r")==std::string::npos) continue; // skip ahead if line is empty
		if (line[0]=='#') continue; // skip ahead if the line is a comment
		if (line[0]=='<' && line[1]=='!') continue;		//comment line in .xml file

		if (configParseLine_XML(line, name, val) == -1) continue; 

		if(name=="Device_Type"){
			if( val == "CODEC_G7xx" && config->m_StreamType==PS){
				config->m_ControlMode = CODEC_CTRL;		//need more work on this!!!! select  firmwares !
				config->m_FirmwareType = G7xxCODEC;
				return SUCCESS;
			}else{
				config->m_ControlMode = CODEC_CTRL;
				config->m_FirmwareType = NormalCODEC;
				return SUCCESS;
			}
		}
	}
	printf("[ CODEC application ] : Connot find CODECMode in config file.\n");
	if (fclose(file)!=0) cprintf("[ CODEC application ] : Cannot close options file.\n");
	return FAILURE;
}
/****************************************************/
/*	Parse the config file( in XML format ). Line by line.
INPUT	@filename	:name of the config file( include path name).
		@vw2010		:point to implementation of the vw2010 interface for set down new value.
		@config		:point of ConfigSetting structure for store Control Mode var.
RETURN	:	SUCCESS;FAILURE	;
*/
int	configLoadFile_XML(char *filename, VW2010 *vw2010 , ConfigSetting *config)
{
	std::string line, name, name2, val, str1, str2;
	double tempfloat;
	int index, gop_M, gop_N, tempval;
	int len,i;
	
	FILE *file = fopen(filename, "r");
	if ( file == NULL )
		return -1;

	char lineTemp[8*1024];
	while (fgets(lineTemp, sizeof(lineTemp), file)!=NULL) {
		if (lineTemp[strlen(lineTemp)-1]=='\n') lineTemp[strlen(lineTemp)-1] = '\0';
		line.erase();
		line.insert(0, lineTemp);

		if (line.find_first_not_of(" \t\n\r")==string::npos) continue; // skip ahead if line is empty
		if (line[0]=='#') continue; // skip ahead if the line is a comment
		if (line[0]=='<' && line[1]=='!') continue;		//comment line in .xml file

		if (configParseLine_XML(line, name, val) == -1) continue; 
		//printf("Config Line: [%s]=[%s]\n",name.c_str(),val.c_str());
		configProcess( name, val, vw2010, config);
	}
	vw2010->SetParam("video_input_device", STRUCT_MUX , 0xc40242 );
	dprintf("[ CODEC application ] : finished reading config file.\n");
	if (fclose(file)!=0) cprintf("[ CODEC application ] : Cannot close options file.\n");
	return SUCCESS;	
}

⌨️ 快捷键说明

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