ShootPhoto.c
6.8 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <stdio.h>
#include "../CameraParameter.h"
#include "../V4L2/V4L2_Record.h"
#include "JZsdkLib.h"
#include "../Camera_InAndOut.h"
#include "../VideoTranscode/VideoTranscode.h"
#define FrameDeal_SHOOTPHOTO_CLOSE (0)
#define FrameDeal_SHOOTPHOTO_ON (1)
#define FrameDeal_SHOOTPHOTOBURST_ON (1)
//连拍照片数
static int FrameDeal_ShootPhoto_Count;
static int FrameDeal_ShootPhotoBurst_Count;
static int FrameDeal_ShootPhotoBurst_Count_Save;
static int FrameDeal_ShootPhotoBurst_FrameCount;
int FrameDeal_ShootPhotoMode = JZ_FLAGCODE_OFF;
static int FrameDeal_ShootPhotoBurst_mode = JZ_FLAGCODE_OFF;
static int FrameDeal_BurstButton = JZ_FLAGCODE_OFF ;
//输出文件
FILE *FrameDeal_ShootPhoto_fp = NULL;
FILE *FrameDeal_ShootPhotoBurst_fp = NULL;
extern int g_CameraStatus ;
/*
单拍部分
*/
// 单拍模式传递函数
T_JZsdkReturnCode FrameDeal_ShootPhoto_trans(int Count)
{
//如果传入数量值不为0
if (Count > 0)
{
//如果相机处于空闲状态
if (g_CameraStatus == CAMERA_IDLE)
{
//拍摄计数值
FrameDeal_ShootPhoto_Count += Count;
FrameDeal_ShootPhotoMode = JZ_FLAGCODE_ON;
g_CameraStatus = CAMERA_SHOOTPHOTO;
JZSDK_LOG_INFO("单拍模式已开启");
}
//如果处于录像中
else if (g_CameraStatus == CAMERA_RECORD)
{
JZSDK_LOG_ERROR("相机已经处于录像中,请勿重复打开单拍功能");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
//如果处于拍摄中
else if (g_CameraStatus == CAMERA_SHOOTPHOTO)
{
//则增加拍摄的数量
FrameDeal_ShootPhoto_Count += Count;
JZSDK_LOG_INFO("拍摄中,单拍数量增加%d 当前为未拍摄数量为%d",Count,FrameDeal_ShootPhoto_Count);
}
//如果处于连拍中
else if (g_CameraStatus == CAMERA_BRUSTSHOORPHOTO)
{
JZSDK_LOG_ERROR("相机已经处于连拍中,请勿重复打开单拍功能");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
//如果处于转码中
else if (g_CameraStatus == CAMERA_TRANSCODE)
{
//如果不处于拍摄转码
if (FrameDeal_ShootPhotoMode != JZ_FLAGCODE_ON)
{
JZSDK_LOG_ERROR("相机已经处于转码中,请勿重复打开单拍功能");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
//如果是拍摄转码状态
FrameDeal_ShootPhoto_Count += Count;
JZSDK_LOG_INFO("转码中,单拍数量增加%d 当前为未拍摄数量为%d",Count,FrameDeal_ShootPhoto_Count);
}
}
//如果传入的是0张
else if(Count == 0)
{
JZSDK_LOG_ERROR("单拍数量传入为0");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
//传入的是其他参数
else
{
JZSDK_LOG_ERROR("错误的单拍数量");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
//拍摄函数
static T_JZsdkReturnCode FrameDeal_ShootPhoto(char* h264_data, uint32_t data_len)
{
//如果拍摄函数没开,或者上一张还没转码完,不进行拍摄
if (FrameDeal_ShootPhotoMode != JZ_FLAGCODE_ON || g_CameraStatus != CAMERA_SHOOTPHOTO)
{
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
char *FrameDeal_ShootPhoto_InPath = "/root/sdcard/DCIM/Photos/temp.h264";
JZSDK_LOG_INFO("是I帧 拍照一次");
// 照片先用h264流保存
FrameDeal_ShootPhoto_fp = fopen(FrameDeal_ShootPhoto_InPath, "wb");
fwrite(h264_data, data_len, 1, FrameDeal_ShootPhoto_fp);
fclose(FrameDeal_ShootPhoto_fp);
//如果数量为0,关闭拍摄模式
FrameDeal_ShootPhoto_Count--;
if (FrameDeal_ShootPhoto_Count == 0)
{
FrameDeal_ShootPhotoMode = JZ_FLAGCODE_OFF;
}
//调用转码线程
Video_TansCode_Trans(SHOOT_TRANSCODE,1);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/*
连拍部分
*/
//连拍模式传递函数
void FrameDeal_ShootPhotoBurst_trans(int Count)
{
FrameDeal_ShootPhotoBurst_mode = FrameDeal_SHOOTPHOTOBURST_ON;
FrameDeal_ShootPhotoBurst_Count = Count;
FrameDeal_ShootPhotoBurst_Count_Save = Count;
char *FrameDeal_ShootPhotoBurst_InPath = "/root/sdcard/DCIM/Photos/temp.h264";
// 照片先用h264流保存
FrameDeal_ShootPhotoBurst_fp = fopen(FrameDeal_ShootPhotoBurst_InPath, "wb");
}
//连拍函数
static void FrameDeal_BurstShootPhoto(char* h264_data, uint32_t data_len)
{
fwrite(h264_data, data_len, 1, FrameDeal_ShootPhotoBurst_fp);
}
//连拍处理函数
static int FrameDeal_ShootPhotoBurstDeal(char* h264_data, uint32_t data_len)
{
if(FrameDeal_ShootPhotoBurst_mode == JZ_FLAGCODE_OFF)
{
return -1;
}
if(h264_data[4] == 0x67 && FrameDeal_ShootPhotoBurst_mode == JZ_FLAGCODE_ON)
{
JZSDK_LOG_INFO("连拍触发");
FrameDeal_BurstButton = JZ_FLAGCODE_ON;
}
if(FrameDeal_BurstButton == JZ_FLAGCODE_ON)
{
//如果开始
//录像函数
FrameDeal_BurstShootPhoto(h264_data ,data_len);
FrameDeal_ShootPhotoBurst_FrameCount++;
if(FrameDeal_ShootPhotoBurst_FrameCount == 3)
{
FrameDeal_ShootPhotoBurst_Count--;
FrameDeal_ShootPhotoBurst_FrameCount = 0;
//3帧1拍
if(FrameDeal_ShootPhotoBurst_Count == 0)
{
//调用转码线程
fclose(FrameDeal_ShootPhotoBurst_fp);
FrameDeal_ShootPhotoBurst_mode = JZ_FLAGCODE_OFF;
FrameDeal_BurstButton = JZ_FLAGCODE_OFF;
JZSDK_LOG_INFO("打开连拍转码");
//ffmpeg_H264_tanscodeto(3, FrameDeal_ShootPhotoBurst_Count_Save);
}
}
}
}
//拍照处理函数
T_JZsdkReturnCode V4L2_ShootPhotoDeal(char* h264_data, unsigned int data_len)
{
T_JZsdkReturnCode ret;
//如果拍照模式未开启
if (FrameDeal_ShootPhotoMode == JZ_FLAGCODE_OFF)
{
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
//如果开启
//JZSDK_LOG_INFO("拍照处理函数");
//如果该帧 为 I 帧
if(h264_data[4] == 0x67)
{
JZSDK_LOG_INFO("触发I");
ret = FrameDeal_ShootPhoto( h264_data, data_len);
if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
{
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
}
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}