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

📄 vcdll.cpp

📁 jpeg and mpeg 编解码技术源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	GetINIParameters(dwSlotNumber);			//必须读,否则RecordMode有可能出错

	RECCTL_LVE_CONFIG LVEConfig;

	LVEConfig.dwSlotNumber = dwSlotNumber;	// indicate the slot number
	LVEConfig.CaptureType = MPJ_LIVE_VIDEO;
	if (_ConfigInfo[dwSlotNumber].iPictureSize == 0) // SIF格式
		LVEConfig.Resolution = MPJ_SIF;
	else
		LVEConfig.Resolution = MPJ_QSIF;


	LVEConfig.fVCDFormat = FALSE;
	if (_ConfigInfo[dwSlotNumber].iVideoStandard == 0)
	{
		LVEConfig.iAdjustAudioSamplesPeriodically=0;
		LVEConfig.VideoStandard = MPJ_NTSC;
	}
	else
	{
		LVEConfig.iAdjustAudioSamplesPeriodically=0;
		LVEConfig.VideoStandard = MPJ_PAL;
	}
	
	switch( _ConfigInfo[dwSlotNumber].iRecordMode )
	{
		case 0:
			LVEConfig.StreamType=MPJ_VIDEO_STREAM;
			break;
		case 1:
			LVEConfig.StreamType=MPJ_AUDIO_STREAM;
			break;
		case 2:
			LVEConfig.StreamType=MPJ_BOTH_STREAMS;
			break;
		default:
			LVEConfig.StreamType=MPJ_BOTH_STREAMS;
			break;
	}
	LVEConfig.CompressMethod = MPJ_MPEG1;

	LVEConfig.lpLogoBuffer = NULL;
	LVEConfig.fLogoEnable = FALSE;
	LVEConfig.iLogoX = 0;
	LVEConfig.iLogoY = 0;

	LVEConfig.fOutOfSyncStop = FALSE; 
	LVEConfig.iDelayTicks = _ConfigInfo[dwSlotNumber].iAudioDelay;
	
	if ( _ConfigInfo[dwSlotNumber].iRecordMode == 0 ||  
		_ConfigInfo[dwSlotNumber].iRecordMode == 1  )
		LVEConfig.fNeedMux = FALSE;
	else
	{
		LVEConfig.fNeedMux = TRUE;
		RECCTL_EnableSoundCard(TRUE);
	}

	LVEConfig.dwAudioSampleRate = _ConfigInfo[dwSlotNumber].iAudioSampleRate;	//44100
	LVEConfig.dwAudioBitRate= _ConfigInfo[dwSlotNumber].iAudioBitrate;	//112

	if( _ConfigInfo[dwSlotNumber].iVideoCons )	//固定码流
	{
		LVEConfig.iVideoBitRate =(int)(_ConfigInfo[dwSlotNumber].iVideoConsVal*1000);
		LVEConfig.Quality = _ConfigInfo[dwSlotNumber].iConBiQuality;
		LVEConfig.RateControl = (MPJ_RateControlMethod) 0; // CBR:0 VBR:2
	}
	else	//可变码流
	{
		LVEConfig.iVideoBitRate = _ConfigInfo[dwSlotNumber].iConQuBitRate * 1000;
		LVEConfig.Quality = _ConfigInfo[dwSlotNumber].iVideoConsVal;
		if( LVEConfig.Quality >=2 )
			LVEConfig.Quality =3;
		LVEConfig.RateControl = (MPJ_RateControlMethod) 2; // CBR:0 VBR:2
	}

//根据时间生成新文件
	CString csMPEGDataFile;

	CTime curTime = CTime::GetCurrentTime();
	int curYear = curTime.GetYear();
	int curMonth = curTime.GetMonth();
	int curDay = curTime.GetDay();
	int curH = curTime.GetHour();
	int curM = curTime.GetMinute();
	int curS = curTime.GetSecond();

	//S2F2000-08-13H10-09-30T10-10-17.mpg
	csMPEGDataFile.Format( "S%02dF%d-%02d-%02dH%02d-%02d-%02d.mpg",dwSlotNumber+1,curYear,curMonth,curDay,curH,curM,curS);
	if( m_fileSavePath[dwSlotNumber].Right(1) == "\\" )
		m_fileSavePath[dwSlotNumber] = m_fileSavePath[dwSlotNumber].Left(m_fileSavePath[dwSlotNumber].GetLength()-1);
	csMPEGDataFile = m_fileSavePath[dwSlotNumber] + "\\" + csMPEGDataFile;
	_ConfigInfo[dwSlotNumber].csFileName = 	csMPEGDataFile;
	strcpy( LVEConfig.csOutputFilename, csMPEGDataFile ); 

	if( RECCTL_LiveVideoEncoding(&LVEConfig) != ERR_OK )
		return -1;

	return 0;  
}

//删除过期文件,删除返回0,否则返回-1
//sPath是给定搜索的条件
int _stdcall DVS_DeleteFileOverDue(DWORD dwSlotNumber, int nInterval)
{

	CFileFind finder;
	CString strToFind, strFileName;
	CString strConst="S01F2000-09-11H20-07-03T20-24-10.mpg";

	if( m_fileDelPath[dwSlotNumber].Right(1) == "\\" )
		m_fileDelPath[dwSlotNumber] = m_fileDelPath[dwSlotNumber].Left(m_fileDelPath[dwSlotNumber].GetLength()-1);

	strToFind.Format("S%02d*.mpg",dwSlotNumber+1);
	strToFind=m_fileDelPath[dwSlotNumber]+"\\"+strToFind;
//MessageBox(NULL,strToFind,"",MB_OK);
	BOOL bWorking = finder.FindFile(strToFind); 
	CTime currentTime=CTime::GetCurrentTime();
	while(bWorking)
	{
//MessageBox(NULL,"Finded","",MB_OK);
		bWorking = finder.FindNextFile();
		
		strFileName=finder.GetFileName();
//MessageBox(NULL,strFileName,"",MB_OK);
		int year=atoi(strFileName.Mid(4,4));
		int month=atoi(strFileName.Mid(9,2));
		int day=atoi(strFileName.Mid(12,2));

		CTime RecordTime(year,month,day,1,1,1);
		
//CString s = RecordTime.Format("%A, %B %d, %Y" );
//MessageBox(NULL,s,"",MB_OK);
		
		CTimeSpan timeSpan=currentTime-RecordTime;

		if(timeSpan.GetDays() > nInterval)
{			
//MessageBox(NULL,"dELETE  " +finder.GetFilePath(),"",MB_OK);
			::DeleteFile(finder.GetFilePath());
}
	}
	return 0;
}

// 调节指定通道的各项参数
int _stdcall DVS_AdjustSlot(DWORD dwSlotNumber, int iWhich, int nV)
{
	switch(iWhich)
	{
		case 0:
			RECCTL_SetVideoDecoder( dwSlotNumber, RECTL_BRIGHTNESS, nV+128);
			break;
		case 1:
			RECCTL_SetVideoDecoder( dwSlotNumber, RECTL_CONTRAST, nV);
			break;
		case 2:
			RECCTL_SetVideoDecoder( dwSlotNumber, RECTL_HUE, nV);
			break;
		case 3:
			RECCTL_SetVideoDecoder( dwSlotNumber, RECTL_SATURATION, nV);
			break;
	}
	return nV;
}

// 设置显示区域
int _stdcall DVS_SetSlotOutArea( DWORD dwSlotNumber, int nL, int nT, int nW, int nH)
{
	CRect rect;
	
	rect.left = nL;
	rect.top = nT;
	rect.right = nL + nW;
	rect.bottom =nT + nH;
	VIEWCTL_SetOutputArea(dwSlotNumber, rect);

	return 0;
}

int _stdcall DVS_SetSavePath(DWORD dwSlotNumber, LPCSTR sPath)
{
	m_fileSavePath[dwSlotNumber]= sPath;
	return 0;
}

int _stdcall DVS_SetDelPath(DWORD dwSlotNumber, LPCSTR sPath)
{
	m_fileDelPath[dwSlotNumber]= sPath;
	return 0;
}

BOOL _stdcall DVS_DetectSource(DWORD dwSlotNumber)
{
	BOOL _fVideoSourceOK, _fLocked;
	static BOOL _fLastTimeSourceErr;

	RECCTL_VideoSourceOK(dwSlotNumber,&_fVideoSourceOK);

	if (_fVideoSourceOK) // Source is OK
	{
		if (_fLastTimeSourceErr) // Last time Source is NG
			_fLastTimeSourceErr = FALSE;
	}
	else // Source is NG
	{
		_fLastTimeSourceErr = TRUE;
		RECCTL_VideoSourceOK(dwSlotNumber,&_fVideoSourceOK);
		Sleep(100);
		CHIPCTL_CheckVideoLocked(dwSlotNumber,&_fLocked);
		if (_fLocked==FALSE)
		{
			Sleep(100);
			return FALSE;
		}
	}

	return TRUE;
}

// 使声卡可用否	
int _stdcall DVS_EnableSoundCard(BOOL bEn)
{
	RECCTL_EnableSoundCard(!bEn);
	return 0;
}

int _stdcall DVS_GetDiskSpace(LPCTSTR sPath, PINT lpFreeBytesAvailableToCaller,  PINT lpTotalNumberOfBytes, PINT lpTotalNumberOfFreeBytes )
{

	ULARGE_INTEGER FreeBytesAvailableToCaller;
	ULARGE_INTEGER TotalNumberOfBytes;
	ULARGE_INTEGER TotalNumberOfFreeBytes;
	
	GetDiskFreeSpaceEx(sPath, &FreeBytesAvailableToCaller, &TotalNumberOfBytes,  &TotalNumberOfFreeBytes );
	*lpFreeBytesAvailableToCaller = FreeBytesAvailableToCaller.QuadPart  / 1048576L;
	*lpTotalNumberOfBytes = TotalNumberOfBytes.QuadPart / 1048576L;
	*lpTotalNumberOfFreeBytes =TotalNumberOfFreeBytes.QuadPart  / 1048576L; 
	
	return 0;
}

//-------------
void GetAppPath( CString& pathName1)
{
	char pathName[MAX_PATH]; 
	DWORD l = GetModuleFileName( (HMODULE)NULL, pathName,sizeof( pathName ) );
    char *a,*b;
    a = b = pathName;
    
    while(b)
    {
    	b=strchr(a+1,'\\');
    	if(b) a=b;
    } 
    *a='\0'; 
	pathName1= pathName;
}

void GetINIParameters(DWORD dwSlotNumber)
{
	CString filePath;
	char INIFileName[MAX_PATH];

	GetAppPath(filePath);
	strcpy(INIFileName,filePath);

	filePath.Format("%s\\Ini\\DVSSlot%d.ini",INIFileName,dwSlotNumber+1);
	strcpy(INIFileName,filePath);

    // *** Get various parameters
	_ConfigInfo[dwSlotNumber].iInputSource = GetPrivateProfileInt("Setup","Video_Source",0,INIFileName);
	_ConfigInfo[dwSlotNumber].iVideoStandard = GetPrivateProfileInt("Setup","Video_Stand",MPJ_PAL,INIFileName);
	_ConfigInfo[dwSlotNumber].iVCD = GetPrivateProfileInt("Setup","VCD",0,INIFileName);
	_ConfigInfo[dwSlotNumber].iRecordMode = GetPrivateProfileInt("Setup","Recorde_Mode",2,INIFileName);

	_ConfigInfo[dwSlotNumber].iVideoCons = GetPrivateProfileInt("Setup","Video_Constant",1,INIFileName); 
	_ConfigInfo[dwSlotNumber].iConQuBitRate=GetPrivateProfileInt("Setup","Video_ConQuBitRate",1024,INIFileName); 
	_ConfigInfo[dwSlotNumber].iConBiQuality= GetPrivateProfileInt("Setup","Video_ConBiQuality",8,INIFileName); 
	_ConfigInfo[dwSlotNumber].iVideoConsVal = GetPrivateProfileInt("Setup","Video_Constant_Value",600,INIFileName); 

	_ConfigInfo[dwSlotNumber].iPictureSize = GetPrivateProfileInt("Setup","Video_Size",0,INIFileName);
	
	_ConfigInfo[dwSlotNumber].iAudioBitrate = GetPrivateProfileInt("Setup","Audio_Bitrate",112,INIFileName);
	_ConfigInfo[dwSlotNumber].iAudioSampleRate = GetPrivateProfileInt("Setup","Audio_Samrate",44100,INIFileName); 
	_ConfigInfo[dwSlotNumber].iAudioDelay  = GetPrivateProfileInt("Setup","Audio_Delay",0,INIFileName); 

	_ConfigInfo[dwSlotNumber].iVideoBri = GetPrivateProfileInt("Setup","Brightness",45,INIFileName); 
	_ConfigInfo[dwSlotNumber].iVideoCta = GetPrivateProfileInt("Setup","Contrast",75,INIFileName); 
	_ConfigInfo[dwSlotNumber].iVideoSta = GetPrivateProfileInt("Setup","Saturation",64,INIFileName); 
	_ConfigInfo[dwSlotNumber].iVideoHue = GetPrivateProfileInt("Setup","Hue",0,INIFileName); 

	return;
}

//停止录像时改变文件名
//S3F2000-4-5-10-23-10.mpg
//S3F2000-4-5-10-23-10T19-9-3.mpg
void ModifyMpegFileName(DWORD dwSlotNumber, CTime curTime)
{
	CString csfileTmp, csFileOldName, csFileNewName;

	csFileOldName = _ConfigInfo[dwSlotNumber].csFileName;
	int findPos = csFileOldName.Find(".mpg");
	csfileTmp = csFileOldName.Left(findPos);
	
	int curH = curTime.GetHour();
	int curM = curTime.GetMinute();
	int curS = curTime.GetSecond();
	csFileNewName.Format( "%sT%02d-%02d-%02d.mpg",csfileTmp,curH,curM,curS);
	CFile::Rename( csFileOldName, csFileNewName );
}

⌨️ 快捷键说明

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