16,548
社区成员




UINT __stdcall SaveJPGThread( void *dummy )
{
CGQ_TESTDlg* pDlg = (CGQ_TESTDlg*)dummy;
int QueueSize = 0;
int ContinueFailed = 0;
char VedioPath[_MAX_PATH];
strcpy(VedioPath,pDlg->m_VedioSavePath.GetBuffer(0));
pDlg->m_VedioSavePath.ReleaseBuffer();
while(!pDlg->m_bQuitThread)
{
EnterCriticalSection( &pDlg->m_JPG_DATA_cs );
QueueSize = pDlg->m_JPGQueue.size();
if(QueueSize > 0)
{
JPG_DATA JPGImg = (JPG_DATA)pDlg->m_JPGQueue.front();
pDlg->m_JPGQueue.pop();
LeaveCriticalSection( &pDlg->m_JPG_DATA_cs );
if(ContinueFailed > 5)
{
theApp.m_Log.Add("写文件连续错误5次!退出程序");
SetEvent( pDlg->m_SaveJPGThreadEvent );
pDlg->m_bSaveVedio = FALSE;
exit(0);
return 0;
}
if(pDlg->SaveJPGImg(JPGImg,VedioPath))
{
ContinueFailed = 0;
}
else
{
theApp.m_Log.Add("存储视频文件错误!");
ContinueFailed++;
}
EnterCriticalSection( &pDlg->m_JPG_DATA_cs );
pDlg->m_JPGBufList[JPGImg.BufNo].bUsed = FALSE;
LeaveCriticalSection( &pDlg->m_JPG_DATA_cs );
}
else
{
LeaveCriticalSection( &pDlg->m_JPG_DATA_cs );
}
if(0 == QueueSize)
{
Sleep(10);
}
}
SetEvent( pDlg->m_SaveJPGThreadEvent );
return 1;
}
BOOL CGQ_TESTDlg::SaveJPGImg(JPG_DATA& pImg,char* pVedioPath)
{
static char fname[_MAX_PATH];
static char strFilePath[_MAX_PATH];
static char strTimeDay[20];
static char strTimeHour[20];
static char strTimeMin[20];
static char strIP[20];
DEVICE_TIME& systime = pImg.ImgInfo.systemtime;
sprintf(strTimeDay,"%04d-%02d-%02d",systime.tm_year,
systime.tm_mon,systime.tm_mday);
sprintf(strTimeHour,"\\%02d",systime.tm_hour );
sprintf(strTimeMin,"\\%02d",systime.tm_min );
sprintf(strIP,"\\%s",pImg.ImgInfo.IP );
strcpy(strFilePath,pVedioPath);
strcat(strFilePath,strTimeDay);
if(!PathFileExists(strFilePath))
{
if(!CreateDirectory(strFilePath,NULL))
{
return FALSE;
}
}
//小时文件夹
strcat(strFilePath,strTimeHour);
if(!PathFileExists(strFilePath))
{
if(!CreateDirectory(strFilePath,NULL))
{
return FALSE;
}
}
//分钟文件夹
strcat(strFilePath,strTimeMin);
if(!PathFileExists(strFilePath))
{
if(!CreateDirectory(strFilePath,NULL))
{
return FALSE;
}
}
//IP文件夹
strcat(strFilePath,strIP);
if(!PathFileExists(strFilePath))
{
if(!CreateDirectory(strFilePath,NULL))
{
return FALSE;
}
}
sprintf(fname,"%s\\%02d-%03d.jpg",
strFilePath,systime.tm_sec,systime.tm_millisecond);
FILE *pFile = fopen(fname,"wb");
if(pFile != NULL)
{
int size = fwrite(pImg.ImgInfo.pImageData,
1,pImg.ImgInfo.Imagelen,pFile);
fclose(pFile);
if(size == pImg.ImgInfo.Imagelen)
{
return TRUE;
}
}
return FALSE;
}