📄 testmd.c~
字号:
/*************************************************************************/
/** This file and the information contain herein is provided "AS IS" **/
/** without warranty of any kind, either expressed or implied, **/
/** including but not limited to the implied warranties of **/
/** merchantability and/or fitness for a particular purpose. **/
/** **/
/** Copyright (C) 2007 QPixel Technology Inc **/
/** All rights reserved. **/
/*************************************************************************/
#include <unistd.h>
//#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
//#include <termios.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
//#include <sys/time.h>
//#include <time.h>
#include <mntent.h>
#include <signal.h>
//#include <asm/types.h>
#include <errno.h> /* perror() */
#include "typedefs.h"
#include "qlioctl.h"
#include "videodev2.h"
#include "qltypes.h"
#include "testmd.h"
static unsigned long hEncDev1 =0;
static HANDLE hMD;
static BYTE *pbyConf;
BYTE abyResult[MD_WIN_NUM];
//volatile unsigned int bCtrlCReceived=FALSE;
void MotionDetectionThreadProc(unsigned long parameters)
{
FILE *pfMDConf = NULL;
BYTE *pbyConf;
TMDTaskParameters *ptMDParam = (TMDTaskParameters *)parameters;
TQLMDInitOptions tInitOptions;
int Err;
int iInterval;
tInitOptions.dwVersion = QLMD_VERSION;
tInitOptions.hEncDev = (HANDLE)ptMDParam->hEncDev;
pfMDConf = fopen("/var/streamer/testmd.mdc", "rb");
if (pfMDConf == NULL)
{
printf("Error opening motion detection window configuration file: testmd.mdc\n");
return;
}
pbyConf = malloc(1+ptMDParam->dwWidth*ptMDParam->dwHeight+2*MD_WIN_NUM);
fread(pbyConf, 1+ptMDParam->dwWidth*ptMDParam->dwHeight+2*MD_WIN_NUM, 1, pfMDConf);
fclose(pfMDConf);
iInterval = pbyConf[0] & 0x7F;
//Initialize QLMD library
Err = QLMD_Initial(&hMD, &tInitOptions);
if (Err != 0)
{
printf("Error initial QLMD\n");
free(pbyConf);
return;
}
//Setup MD size
Err = QLMD_SetSize(hMD, ptMDParam->dwWidth, ptMDParam->dwHeight);
if (Err != 0)
{
printf("Error set MD size %dx%d\n", ptMDParam->dwWidth, ptMDParam->dwHeight);
free(pbyConf);
return;
}
//Setup MD window configuration
Err = QLMD_SetConfig(hMD, pbyConf);
if (Err != 0)
{
printf("Error set MD window configuration\n");
free(pbyConf);
return;
}
nice(15);
usleep(1000000);
//Start MD
printf("Start motion detection...\n");
QLMD_Start(hMD);
}
long start_motion_detection_vi(void)
{
long Err= 0;
TMDTaskParameters tMDParam;
hEncDev1 = open("/dev/video0", O_RDWR);
if(hEncDev1 < 0) {
printf("Unable to Open (/dev/video0) hEncDev = (0x%08x)\r\n", hEncDev1);
return (2);
} else {
tMDParam.hEncDev = hEncDev1;
ioctl(hEncDev1, QL201_ENC_G_ENC_WIDTH, &tMDParam.dwWidth);
ioctl(hEncDev1, QL201_ENC_G_ENC_HEIGHT, &tMDParam.dwHeight);
tMDParam.dwWidth = tMDParam.dwWidth >> 4;
tMDParam.dwHeight = tMDParam.dwHeight >> 4;
tMDParam.dwHeight = (tMDParam.dwHeight<9) ? 9 : tMDParam.dwHeight;
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
enum ql201_v4l2_mpeg_streamtype strmtype = STREAM_TYPE_VI_ONLY;
Err = ioctl(hEncDev1, QL201_ENC_S_STRMTYPE, &strmtype);
if (Err) {
printf("Set VI-only mode (%x) failed. Err = %x\n", strmtype, Err);
goto MD0_END;
}
Err = ioctl(hEncDev1, VIDIOC_STREAMON, &type);
if (Err) {
printf("STREAMON (VI-only mode) ioctl returns Err=%d, errnot=%d %s\n", Err, errno, strerror(errno));
goto MD0_END;
}else{
printf("STREAMON (VI-only mode) OK\n");
}
MotionDetectionThreadProc((unsigned long)&tMDParam);
return Err;
}
MD0_END:
if (hEncDev1) {
close(hEncDev1);
hEncDev1 = 0;
}
return Err;
}
void stop_motion_detection_vi(void)
{
long Err= 0;
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
QLMD_Stop(hMD);
QLMD_Release(&hMD);
free(pbyConf);
Err= ioctl(hEncDev1, VIDIOC_STREAMOFF, &type);
if(Err == -1) {
printf("STREAMOFF (VI-only mode) ioctl returns Err=%d, errnot=%d %s\n", Err, errno, strerror(errno));
}
if (hEncDev1) {
close(hEncDev1);
hEncDev1 = 0;
}
}
long get_motion_detection_vi(void)
{
long Err =0;
if (QLMD_GetResult(hMD, abyResult) == S_OK)
{
//printf("QLMD_GetResult Got something! \n");
if (abyResult[4]+abyResult[5]!=0)//abyResult[0]+abyResult[1]+abyResult[2]+abyResult[3]+abyResult[4]+abyResult[5]!=0
{
int i;
printf("Motion detection result:");
for (i=0; i<MD_WIN_NUM;i++)
printf(" %d", abyResult[i]);
printf("\n");
return 1;
}
} else {
//printf("QLMD_GetResult returned error %d. errno=%d %s\n", Err, errno, strerror(errno));
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -