FrameDeal.c
3.0 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../CameraParameter.h"
#include "../V4L2/V4L2_Record.h"
#include "JZsdkLib.h"
#include "./CameraFeatures.h"
#include "version_choose.h"
#define DATA_SEND_FROM_VIDEO_STREAM_MAX_LEN 60000
#define VIDEO_FRAME_AUD_LEN 6
#if APP_VERSION == APP_PSDK
#include "Dji_Control/DJI_VideoDeal.h"
#endif
static const uint8_t s_frameAudInfo[VIDEO_FRAME_AUD_LEN] = {0x00, 0x00, 0x00, 0x01, 0x09, 0x10};
extern int Camera_PushVideoInitFlag;
pthread_mutex_t FrameDealMutex;
static void FrameDeal_PsdkPushFrame(char* h264_data, uint32_t data_len, int AudLength)
{
unsigned int FrameBufSize = 0;
FrameBufSize = data_len;
//如果视频为大疆H264型
if (PUSHFRAME_VIDEO_TPYE == VIDEO_TPYE_DJIH264)
{
FrameBufSize += VIDEO_FRAME_AUD_LEN;
memcpy(h264_data + data_len, s_frameAudInfo, VIDEO_FRAME_AUD_LEN);
//printf("大疆264型\n");
}
else
{
//printf("普通h264\n");
}
#if APP_VERSION == APP_PSDK
//放入到对应的传输函数
DJI_VideoDeal_Push_DJIH264Frame(h264_data, FrameBufSize);
#endif
}
//线程方案
static void *JZsdk_CameraFrameDeal_thread(void *args)
{
int FrameLength;
int AudLength ; //帧尾长度
JZSDK_LOG_INFO("JZsdk_CameraFrameDeal_thread创建完毕\n");
while (1)
{
pthread_mutex_lock(&FrameDealMutex);
//如果已经初始化了摄像头及推流部分
if (Camera_PushVideoInitFlag == JZ_FLAGCODE_OFF)
{
continue;
}
//创建一个缓存区,用于存放视频数据
char *FrameDealBuffer;
FrameLength = 0;
//如果要求的推送的视频流是 djih264
if (PUSHFRAME_VIDEO_TPYE == VIDEO_TPYE_DJIH264)
{
AudLength = VIDEO_FRAME_AUD_LEN ;
}
//如果要求的是普通的h264
else if (PUSHFRAME_VIDEO_TPYE == VIDEO_TPYE_H264)
{
AudLength = 0 ;
}
else
{
AudLength = 0 ;
}
//从摄像头录制并取出一帧数据
V4L2_CameraFrameRecord(&FrameDealBuffer, &FrameLength, AudLength);
//拍照处理函数
V4L2_ShootPhotoDeal(FrameDealBuffer, FrameLength);
//录像处理函数
V4L2_RecordVedioDeal(FrameDealBuffer, FrameLength);
//连拍处理函数
//FrameDeal_ShootPhotoBurstDeal(FrameDealBuffer, FrameLength);
//推送一帧
FrameDeal_PsdkPushFrame(FrameDealBuffer, FrameLength, AudLength);
free(FrameDealBuffer);
}
pthread_exit(NULL);
}
int JZsdk_CameraFrameDeal_thread_Init()
{
pthread_mutex_init(&FrameDealMutex, NULL); // 创建互斥锁
pthread_t FrameDeal_thread;
pthread_create(&FrameDeal_thread, NULL, JZsdk_CameraFrameDeal_thread, NULL);
}
int FrameDeal_FrameDealThread_UnlockFun()
{
//解锁帧处理线程
pthread_mutex_unlock(&FrameDealMutex);
return 0;
}