ShootPhoto.c
4.5 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
#include <stdio.h>
#include "../CameraParameter.h"
#include "../V4L2/V4L2_Record.h"
#include "JZsdkLib.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;
static 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 PhotoTranscode_Flag ; //图片转码标志位,off为转码完毕,on为转码完成
/*
单拍部分
*/
// 拍摄模式传递函数
int FrameDeal_ShootPhoto_trans(int Count)
{
//拍摄计数值
FrameDeal_ShootPhoto_Count = Count;
FrameDeal_ShootPhotoMode = JZ_FLAGCODE_ON;
JZSDK_LOG_INFO("拍摄传递函数被调用");
}
//拍摄函数
static T_JZsdkReturnCode FrameDeal_ShootPhoto(char* h264_data, uint32_t data_len)
{
//如果转码未完成
if (PhotoTranscode_Flag == JZ_FLAGCODE_ON)
{
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
char *FrameDeal_ShootPhoto_InPath = "/root/sdcard/DCIM/Photos/temp.h264";
// 照片先用h264流保存
FrameDeal_ShootPhoto_fp = fopen(FrameDeal_ShootPhoto_InPath, "wb");
fwrite(h264_data, data_len, 1, FrameDeal_ShootPhoto_fp);
fclose(FrameDeal_ShootPhoto_fp);
//调用转码线程
ffmpeg_H264_tanscodeto(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 -1;
}
//如果开启
//如果该帧 为 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;
}
FrameDeal_ShootPhoto_Count--;
if (FrameDeal_ShootPhoto_Count == 0)
{
FrameDeal_ShootPhotoMode = JZ_FLAGCODE_OFF;
}
}
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}