@@ -32,15 +32,18 @@ uint32_t FrameBuffer::getBufferSize() {
32
32
if (this ->vbuf ) {
33
33
return this ->vbuf ->bytesused ;
34
34
}
35
+ return 0 ;
35
36
}
36
37
37
38
uint8_t * FrameBuffer::getBuffer () {
38
39
if (this ->vbuf ) {
39
40
return this ->vbuf ->buffer ;
40
41
}
42
+ return nullptr ;
41
43
}
42
44
43
- Camera::Camera () : vdev(NULL ), byte_swap(false ), yuv_to_gray(false ) {
45
+ Camera::Camera () : vdev(NULL ), byte_swap(false ), yuv_to_gray(false ),
46
+ snapshot_mode(CONFIG_VIDEO_BUFFER_POOL_NUM_MAX <= 1 ) {
44
47
for (size_t i = 0 ; i < ARRAY_SIZE (this ->vbuf ); i++) {
45
48
this ->vbuf [i] = NULL ;
46
49
}
@@ -95,6 +98,7 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
95
98
96
99
// Set format.
97
100
static struct video_format fmt = {
101
+ .type = VIDEO_BUF_TYPE_OUTPUT,
98
102
.pixelformat = pixformat,
99
103
.width = width,
100
104
.height = height,
@@ -124,6 +128,16 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
124
128
// this should compute the sizes needed.
125
129
video_get_format (this ->vdev , &fmt);
126
130
131
+
132
+ // If we are in snapshot mode, try starting the video stream with no buffers
133
+ // to tell it that we want snapshot...
134
+ if (snapshot_mode) {
135
+ if (video_stream_start (this ->vdev , VIDEO_BUF_TYPE_OUTPUT)) {
136
+ Serial.println (" Snapshot mode Failed to start capture" );
137
+ // return false;
138
+ }
139
+ }
140
+
127
141
// Allocate video buffers.
128
142
for (size_t i = 0 ; i < ARRAY_SIZE (this ->vbuf ); i++) {
129
143
this ->vbuf [i] = video_buffer_aligned_alloc (fmt.pitch * fmt.height ,
@@ -137,11 +151,12 @@ bool Camera::begin(uint32_t width, uint32_t height, uint32_t crop_width, uint32_
137
151
}
138
152
139
153
// Start video capture
140
- if (video_stream_start (this ->vdev , VIDEO_BUF_TYPE_OUTPUT)) {
141
- Serial.println (" Failed to start capture" );
142
- return false ;
143
- }
144
-
154
+ if (!snapshot_mode) {
155
+ if (video_stream_start (this ->vdev , VIDEO_BUF_TYPE_OUTPUT)) {
156
+ Serial.println (" Failed to start capture" );
157
+ return false ;
158
+ }
159
+ }
145
160
return true ;
146
161
}
147
162
@@ -179,7 +194,7 @@ bool Camera::releaseFrame(FrameBuffer &fb) {
179
194
180
195
int ret;
181
196
// printk("Camera::ReleaseFrame called\n");
182
- if (ret = video_enqueue (this ->vdev , fb.vbuf )) {
197
+ if (( ret = video_enqueue (this ->vdev , fb.vbuf )) != 0 ) {
183
198
printk (" Failed to enqueue buffer %d\n " , ret);
184
199
return false ;
185
200
}
@@ -226,22 +241,28 @@ int Camera::getSelection(struct video_selection *sel) {
226
241
*
227
242
* @param snapshot_mode pointer to Turn Snaphsot mode on or off..
228
243
*/
229
- int Camera::getSnapshotMode (bool *snapshot_mode) {
230
- #if DT_HAS_CHOSEN(zephyr_camera)
231
- this ->vdev = DEVICE_DT_GET (DT_CHOSEN (zephyr_camera));
232
- #endif
233
- return video_get_snapshot_mode (vdev, snapshot_mode);
244
+ bool Camera::getSnapshotMode () {
245
+ return snapshot_mode;
234
246
}
235
247
236
248
/* *
237
- * @brief Function pointer type for video_set_snapshot_mode()
249
+ * @brief returns if snapshot mode is turned on or off.
250
+ *
251
+ * Must be called before begin to take effect.
252
+ *
253
+ * @param snap_shot mode if true.
238
254
*
239
- * @param snapshot_mode Turn Snaphsot mode on or off. .
255
+ * @retval 0 is successful .
240
256
*/
241
- int Camera::setSnapshotMode (bool snapshot_mode) {
242
- #if DT_HAS_CHOSEN(zephyr_camera)
243
- this ->vdev = DEVICE_DT_GET (DT_CHOSEN (zephyr_camera));
244
- #endif
245
- return video_set_snapshot_mode (vdev, snapshot_mode);
257
+ int Camera::setSnapshotMode (bool snap_shot) {
258
+ if (snap_shot) {
259
+ snapshot_mode = snap_shot;
260
+ return 0 ;
261
+ } else {
262
+ #if CONFIG_VIDEO_BUFFER_POOL_NUM_MAX <= 1
263
+ return -EINVAL;
264
+ #endif
265
+ snapshot_mode = snap_shot;
266
+ return 0 ;
267
+ }
246
268
}
247
-
0 commit comments