📄 dsdemo.cpp
字号:
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::CreateThread()
{
pthread_attr_t attr;
DsStruct DsTemp;
DsTemp.dsclass = this;
DsTemp.pmf = &Dsclass::videopreview;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
dsdemo->bPreviewThreadRun = 1;
pthread_create(&(dsdemo->hPreviewThread), &attr, intermediary, &DsTemp);
while(dsdemo->bPreviewThreadRun == 1)
usleep(USLEEPTIME);
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::SetPreview(UINT useSyncSem)
{
dsdemo->previewconf.w = dsdemo->dstRect.w;
dsdemo->previewconf.h = dsdemo->dstRect.h;
OutputDebugString("ChannelHandle[%d] %d\n", SignPort, dsdemo->ChannelHandle); /* debug */
OutputDebugString("imageSize = %lu, w = %lu, h = %lu, dataAddr = %p, SyncSem = %p \n",
(dsdemo->previewconf).imageSize, (dsdemo->previewconf).w,
(dsdemo->previewconf).h, (dsdemo->previewconf).dataAddr,
(dsdemo->previewconf).SyncSem);
if(StartVideoPreview(dsdemo->ChannelHandle, &(dsdemo->previewconf), useSyncSem) < 0)
OutputErrorString("<demo_info>start video preview failed \n");
OutputDebugString("<demo_info>start video preview successful \n");
OutputDebugString("<demo_info> Start video preview ok, the sync sem is %p!\n",
(dsdemo->previewconf).SyncSem);
dsdemo->pOverlaySurface = SDL_CreateYUVOverlay(dsdemo->previewconf.w, dsdemo->previewconf.h,
SDL_YV12_OVERLAY, pOverlayScreen);
if(dsdemo->pOverlaySurface == NULL)
{
OutputErrorString("<demo_info> the SDL overlay surface create failed!\n");
return;
}
dsdemo->bPreviewOpen = 1;
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::StopPreview()
{
dsdemo->bPreviewOpen = 0;
OutputDebugString("The app is locked or not (:%d).......................\n", app->locked());
#ifndef USE_PREVIEW_TIMER
if(app)
{
app->unlock();
}
sem_post(dsdemo->previewconf.SyncSem);
dsdemo->bPreviewThreadRun = 3;
while(dsdemo->bPreviewThreadRun == 3)
usleep(USLEEPTIME);
if(app)
{
app->lock();
}
#endif
if(StopVideoPreview(dsdemo->ChannelHandle) < 0)
OutputErrorString("<demo_info> StoptVideoPreview(channel %d) failed\n", SignPort);
if(dsdemo->pOverlaySurface != NULL)
{
SDL_FreeYUVOverlay(dsdemo->pOverlaySurface);
dsdemo->pOverlaySurface = NULL;
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::DestoryThread()
{
if(dsdemo->bPreviewOpen)
StopPreview();
dsdemo->bPreviewThreadRun = 0;
usleep(USLEEPTIME);
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::CreateFiles()
{
char savepath[10] = ".";
QString qsFile;
QFile* temp;
pthread_mutex_lock(&(dsdemo->major_start));
end_record();
qsFile.sprintf("%s/Mp4P%02dC%02d.mp4", savepath, SignPort, dsdemo->count);
temp = new QFile(qsFile);
temp->open(IO_ReadWrite | IO_Truncate);
dsdemo->record_fd = temp;
qsFile.sprintf("%s/Mp4P%02dC%02d.dat", savepath, SignPort, dsdemo->count);
temp = new QFile(qsFile);
temp->open(IO_ReadWrite | IO_Truncate);
dsdemo->index_fd = temp;
if(dsdemo->filehead_flag)
{
(dsdemo->record_fd)->writeBlock(dsdemo->file_head, 40);
dsdemo->nodeinfo.FilePos = 40;
dsdemo->nodeinfo.FrameNum = 0;
}
pthread_mutex_unlock(&(dsdemo->major_start));
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::CreateCifQcifFiles()
{
char savepath[10] = ".";
QString qsFile;
QFile* temp;
pthread_mutex_lock(&(dsdemo->minor_start));
end_subrecord();
qsFile.sprintf("%s/CifQCifP%02dC%02d.mp4", savepath, SignPort, dsdemo->count);
temp = new QFile(qsFile);
temp->open(IO_ReadWrite | IO_Truncate);
dsdemo->cifqcif_fd = temp;
if(dsdemo->cifqciffilehead_flag)
(dsdemo->cifqcif_fd)->writeBlock(dsdemo->cifqciffile_head, 40);
pthread_mutex_unlock(&(dsdemo->minor_start));
OutputDebugString("create cifqcif file%02d\n", SignPort);
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::CreateImageStreamFiles()
{
char savepath[10] = ".";
QString qsFile;
QFile* temp;
pthread_mutex_lock(&(dsdemo->imagefile_fd_start));
end_imagestream();
qsFile.sprintf("%s/imagefileP%02dC%02d.yuv", savepath, SignPort, dsdemo->count);
temp = new QFile(qsFile);
temp->open(IO_ReadWrite | IO_Truncate);
dsdemo->imagefile_fd = temp;
pthread_mutex_unlock(&(dsdemo->imagefile_fd_start));
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::StopCapture()
{
StopVideoCapture(dsdemo->ChannelHandle);
dsdemo->bit_rate_size = 0;
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::StopSubCapture()
{
StopSubVideoCapture(dsdemo->ChannelHandle);
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::StartCapture()
{
int retval;
dsdemo->bit_rate_size = 0;
retval = StartVideoCapture(dsdemo->ChannelHandle);
if(retval < 0)
{
dsdemo->record_flag = 0;
OutputErrorString("<demo_info> StartVideoCapture failed. \n");
return;
}
OutputErrorString("<demo_info> StartVideoCapture Successful. \n");
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::StartSubCapture()
{
int retval;
retval = StartSubVideoCapture(dsdemo->ChannelHandle);
OutputDebugString("start port%02d \n", SignPort);
if(retval < 0)
{
dsdemo->cifqcif_flag = 0;
OutputErrorString("<demo_info> StartVideoCapture failed. \n");
return;
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::end_record()
{
if(dsdemo->record_fd != NULL)
{
delete(dsdemo->record_fd);
dsdemo->record_fd = NULL;
}
if(dsdemo->index_fd != NULL)
{
delete(dsdemo->index_fd);
dsdemo->index_fd = NULL;
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::end_subrecord()
{
if(dsdemo->cifqcif_fd != NULL)
{
delete(dsdemo->cifqcif_fd);
dsdemo->cifqcif_fd = NULL;
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::end_imagestream()
{
if(dsdemo->imagefile_fd != NULL)
{
delete(dsdemo->imagefile_fd);
dsdemo->imagefile_fd = NULL;
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void Dsclass::GetImage()
{
int retval = 0;
int size; /* ;
* = 384 * 288
* 2;
* */
char filename[100];
int VideoHeight;
unsigned char* imagebuf;
static int image_count = 0;
#ifdef YUVFILE
int fid;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -