H150ST_Cam.c
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include "JZsdkLib.h"
#include "version_choose.h"
#include "BaseConfig.h"
#include "../V4L2_camera/V4L2_Record.h"
#include "../../StreamProc/StreamProc.h"
#include "../../MediaParm.h"
#include "../../VideoMgmt/VideoMgmt.h"
#include "../../StreamProc/StreamProc.h"
#include "Ircut/ircut.h"
#include "../Camera.h"
#include "UI_control/UI_control.h"
static int CameraFd = 0;
//光学相机数据读取线程
static void *JZsdk_Cam_Data_Thread(void *args)
{
while (1)
{
unsigned int buf_size = 0;
unsigned char *buf = NULL;
//从相机中读取一张照片
V4L2_CameraFrameRecord_OnlyGetFrame(&buf, &buf_size);
if (buf == NULL)
{
JZSDK_LOG_ERROR("相机数据读取失败");
continue;
}
//放入缓冲池
VideoMgmt_write_data(&VideoMgmt_FirstVideo_index, buf, buf_size);
//归还图片
V4L2_CameraFrameRecord_OnlyReturnFrame();
}
}
//150st相机初始化
T_JZsdkReturnCode JZsdk_H150ST_CameraInit(int width, int height, int frame_num)
{
T_JZsdkReturnCode ret;
//初始化摄像头
ret = V4l2_Camarainit2(&CameraFd,width,height,frame_num);
if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
{
return ret;
}
//初始化数据接收线程
pthread_t ReadDataTask;
pthread_attr_t task_attribute; //线程属性
pthread_attr_init(&task_attribute); //初始化线程属性
pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); //设置线程分离属性
int opus_Protection = pthread_create(&ReadDataTask,&task_attribute,JZsdk_Cam_Data_Thread,NULL); //线程
if(opus_Protection != 0)
{
JZSDK_LOG_ERROR("创建v4l2线程失败!");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}