1 /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include "mm_qcamera_dbg.h"
31 #include "mm_qcamera_app.h"
32
33 /* This callback is received once the complete JPEG encoding is done */
jpeg_encode_cb(jpeg_job_status_t status,uint32_t client_hdl,uint32_t jobId,mm_jpeg_output_t * p_buf,void * userData)34 static void jpeg_encode_cb(jpeg_job_status_t status,
35 uint32_t client_hdl,
36 uint32_t jobId,
37 mm_jpeg_output_t *p_buf,
38 void *userData)
39 {
40 int i = 0;
41 mm_camera_test_obj_t *pme = NULL;
42 CDBG("%s: BEGIN\n", __func__);
43
44 pme = (mm_camera_test_obj_t *)userData;
45 if (pme->jpeg_hdl != client_hdl ||
46 jobId != pme->current_job_id ||
47 !pme->current_job_frames) {
48 CDBG_ERROR("%s: NULL current job frames or not matching job ID (%d, %d)",
49 __func__, jobId, pme->current_job_id);
50 return;
51 }
52
53 /* dump jpeg img */
54 CDBG_ERROR("%s: job %d, status=%d", __func__, jobId, status);
55 if (status == JPEG_JOB_STATUS_DONE && p_buf != NULL) {
56 mm_app_dump_jpeg_frame(p_buf->buf_vaddr, p_buf->buf_filled_len, "jpeg", "jpg", jobId);
57 }
58
59 /* buf done current encoding frames */
60 pme->current_job_id = 0;
61 for (i = 0; i < pme->current_job_frames->num_bufs; i++) {
62 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->current_job_frames->camera_handle,
63 pme->current_job_frames->ch_id,
64 pme->current_job_frames->bufs[i])) {
65 CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
66 }
67 mm_app_cache_ops((mm_camera_app_meminfo_t *) pme->current_job_frames->bufs[i]->mem_info,
68 ION_IOC_INV_CACHES);
69 }
70
71 free(pme->jpeg_buf.buf.buffer);
72 free(pme->current_job_frames);
73 pme->current_job_frames = NULL;
74
75 /* signal snapshot is done */
76 mm_camera_app_done();
77 }
78
encodeData(mm_camera_test_obj_t * test_obj,mm_camera_super_buf_t * recvd_frame,mm_camera_stream_t * m_stream)79 int encodeData(mm_camera_test_obj_t *test_obj, mm_camera_super_buf_t* recvd_frame,
80 mm_camera_stream_t *m_stream)
81 {
82 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
83
84 int rc = -MM_CAMERA_E_GENERAL;
85 mm_jpeg_job_t job;
86
87 /* remember current frames being encoded */
88 test_obj->current_job_frames =
89 (mm_camera_super_buf_t *)malloc(sizeof(mm_camera_super_buf_t));
90 if (!test_obj->current_job_frames) {
91 CDBG_ERROR("%s: No memory for current_job_frames", __func__);
92 return rc;
93 }
94 *(test_obj->current_job_frames) = *recvd_frame;
95
96 memset(&job, 0, sizeof(job));
97 job.job_type = JPEG_JOB_TYPE_ENCODE;
98 job.encode_job.session_id = test_obj->current_jpeg_sess_id;
99
100 // TODO: Rotation should be set according to
101 // sensor&device orientation
102 job.encode_job.rotation = 0;
103 if (cam_cap->position == CAM_POSITION_BACK) {
104 job.encode_job.rotation = 270;
105 }
106
107 /* fill in main src img encode param */
108 job.encode_job.main_dim.src_dim = m_stream->s_config.stream_info->dim;
109 job.encode_job.main_dim.dst_dim = m_stream->s_config.stream_info->dim;
110 job.encode_job.src_index = 0;
111
112 job.encode_job.thumb_dim.src_dim = m_stream->s_config.stream_info->dim;
113 job.encode_job.thumb_dim.dst_dim.width = DEFAULT_PREVIEW_WIDTH;
114 job.encode_job.thumb_dim.dst_dim.height = DEFAULT_PREVIEW_HEIGHT;
115
116 /* fill in sink img param */
117 job.encode_job.dst_index = 0;
118
119 if (test_obj->metadata != NULL) {
120 job.encode_job.p_metadata = test_obj->metadata;
121 } else {
122 CDBG_ERROR("%s: Metadata null, not set for jpeg encoding", __func__);
123 }
124
125 rc = test_obj->jpeg_ops.start_job(&job, &test_obj->current_job_id);
126 if ( 0 != rc ) {
127 free(test_obj->current_job_frames);
128 test_obj->current_job_frames = NULL;
129 }
130
131 return rc;
132 }
133
createEncodingSession(mm_camera_test_obj_t * test_obj,mm_camera_stream_t * m_stream,mm_camera_buf_def_t * m_frame)134 int createEncodingSession(mm_camera_test_obj_t *test_obj,
135 mm_camera_stream_t *m_stream,
136 mm_camera_buf_def_t *m_frame)
137 {
138 mm_jpeg_encode_params_t encode_param;
139
140 memset(&encode_param, 0, sizeof(mm_jpeg_encode_params_t));
141 encode_param.jpeg_cb = jpeg_encode_cb;
142 encode_param.userdata = (void*)test_obj;
143 encode_param.encode_thumbnail = 0;
144 encode_param.quality = 85;
145 encode_param.color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;
146 encode_param.thumb_color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;
147
148 /* fill in main src img encode param */
149 encode_param.num_src_bufs = 1;
150 encode_param.src_main_buf[0].index = 0;
151 encode_param.src_main_buf[0].buf_size = m_frame->frame_len;
152 encode_param.src_main_buf[0].buf_vaddr = (uint8_t *)m_frame->buffer;
153 encode_param.src_main_buf[0].fd = m_frame->fd;
154 encode_param.src_main_buf[0].format = MM_JPEG_FMT_YUV;
155 encode_param.src_main_buf[0].offset = m_stream->offset;
156
157 /* fill in sink img param */
158 encode_param.num_dst_bufs = 1;
159 encode_param.dest_buf[0].index = 0;
160 encode_param.dest_buf[0].buf_size = test_obj->jpeg_buf.buf.frame_len;
161 encode_param.dest_buf[0].buf_vaddr = (uint8_t *)test_obj->jpeg_buf.buf.buffer;
162 encode_param.dest_buf[0].fd = test_obj->jpeg_buf.buf.fd;
163 encode_param.dest_buf[0].format = MM_JPEG_FMT_YUV;
164
165 /* main dimension */
166 encode_param.main_dim.src_dim = m_stream->s_config.stream_info->dim;
167 encode_param.main_dim.dst_dim = m_stream->s_config.stream_info->dim;
168
169 return test_obj->jpeg_ops.create_session(test_obj->jpeg_hdl,
170 &encode_param,
171 &test_obj->current_jpeg_sess_id);
172 }
173
174 /** mm_app_snapshot_metadata_notify_cb
175 * @bufs: Pointer to super buffer
176 * @user_data: Pointer to user data
177 *
178 *
179 **/
mm_app_snapshot_metadata_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)180 static void mm_app_snapshot_metadata_notify_cb(mm_camera_super_buf_t *bufs,
181 void *user_data)
182 {
183 int i = 0;
184 mm_camera_channel_t *channel = NULL;
185 mm_camera_stream_t *p_stream = NULL;
186 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
187 mm_camera_buf_def_t *frame = bufs->bufs[0];
188 metadata_buffer_t *pMetadata;
189 cam_auto_focus_data_t *focus_data;
190
191 if (NULL == bufs || NULL == user_data) {
192 CDBG_ERROR("%s: bufs or user_data are not valid ", __func__);
193 return;
194 }
195
196 /* find channel */
197 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
198 if (pme->channels[i].ch_id == bufs->ch_id) {
199 channel = &pme->channels[i];
200 break;
201 }
202 }
203 /* find meta stream */
204 for (i = 0; i < channel->num_streams; i++) {
205 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_METADATA) {
206 p_stream = &channel->streams[i];
207 break;
208 }
209 }
210 /* find meta frame */
211 for (i = 0; i < bufs->num_bufs; i++) {
212 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
213 frame = bufs->bufs[i];
214 break;
215 }
216 }
217
218 if (NULL == p_stream) {
219 CDBG_ERROR("%s: cannot find metadata stream", __func__);
220 return;
221 }
222 if (!pme->metadata) {
223 /* The app will free the metadata, we don't need to bother here */
224 pme->metadata = malloc(sizeof(metadata_buffer_t));
225 }
226 memcpy(pme->metadata , frame->buffer, sizeof(metadata_buffer_t));
227
228 pMetadata = (metadata_buffer_t *)frame->buffer;
229
230 if (IS_META_AVAILABLE(CAM_INTF_META_AUTOFOCUS_DATA, pMetadata)) {
231 focus_data = (cam_auto_focus_data_t *)
232 POINTER_OF_META(CAM_INTF_META_AUTOFOCUS_DATA, pMetadata);
233 if (focus_data->focus_state == CAM_AF_FOCUSED) {
234 CDBG_ERROR("%s: AutoFocus Done Call Back Received\n",__func__);
235 mm_camera_app_done();
236 } else if (focus_data->focus_state == CAM_AF_NOT_FOCUSED) {
237 CDBG_ERROR("%s: AutoFocus failed\n",__func__);
238 mm_camera_app_done();
239 }
240 }
241
242 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
243 bufs->ch_id,
244 frame)) {
245 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
246 }
247 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
248 ION_IOC_INV_CACHES);
249 }
250
mm_app_snapshot_notify_cb_raw(mm_camera_super_buf_t * bufs,void * user_data)251 static void mm_app_snapshot_notify_cb_raw(mm_camera_super_buf_t *bufs,
252 void *user_data)
253 {
254
255 int i = 0;
256 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
257 mm_camera_channel_t *channel = NULL;
258 mm_camera_stream_t *m_stream = NULL;
259 mm_camera_buf_def_t *m_frame = NULL;
260
261 CDBG("%s: BEGIN\n", __func__);
262
263 /* find channel */
264 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
265 if (pme->channels[i].ch_id == bufs->ch_id) {
266 channel = &pme->channels[i];
267 break;
268 }
269 }
270 if (NULL == channel) {
271 CDBG_ERROR("%s: Wrong channel id (%d)", __func__, bufs->ch_id);
272 goto EXIT;
273 }
274
275 /* find snapshot stream */
276 for (i = 0; i < channel->num_streams; i++) {
277 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_RAW) {
278 m_stream = &channel->streams[i];
279 break;
280 }
281 }
282 if (NULL == m_stream) {
283 CDBG_ERROR("%s: cannot find snapshot stream", __func__);
284 goto EXIT;
285 }
286
287 /* find snapshot frame */
288 for (i = 0; i < bufs->num_bufs; i++) {
289 if (bufs->bufs[i]->stream_id == m_stream->s_id) {
290 m_frame = bufs->bufs[i];
291 break;
292 }
293 }
294 if (NULL == m_frame) {
295 CDBG_ERROR("%s: main frame is NULL", __func__);
296 goto EXIT;
297 }
298
299 mm_app_dump_frame(m_frame, "main", "raw", m_frame->frame_idx);
300
301 EXIT:
302 for (i=0; i<bufs->num_bufs; i++) {
303 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
304 bufs->ch_id,
305 bufs->bufs[i])) {
306 CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
307 }
308 }
309
310 mm_camera_app_done();
311
312 CDBG("%s: END\n", __func__);
313 }
314
mm_app_snapshot_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)315 static void mm_app_snapshot_notify_cb(mm_camera_super_buf_t *bufs,
316 void *user_data)
317 {
318
319 int rc = 0;
320 int i = 0;
321 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
322 mm_camera_channel_t *channel = NULL;
323 mm_camera_stream_t *p_stream = NULL;
324 mm_camera_stream_t *m_stream = NULL;
325 mm_camera_buf_def_t *p_frame = NULL;
326 mm_camera_buf_def_t *m_frame = NULL;
327
328 CDBG("%s: BEGIN\n", __func__);
329
330 /* find channel */
331 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
332 if (pme->channels[i].ch_id == bufs->ch_id) {
333 channel = &pme->channels[i];
334 break;
335 }
336 }
337 if (NULL == channel) {
338 CDBG_ERROR("%s: Wrong channel id (%d)", __func__, bufs->ch_id);
339 rc = -1;
340 goto error;
341 }
342
343 /* find snapshot stream */
344 for (i = 0; i < channel->num_streams; i++) {
345 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) {
346 m_stream = &channel->streams[i];
347 break;
348 }
349 }
350 if (NULL == m_stream) {
351 CDBG_ERROR("%s: cannot find snapshot stream", __func__);
352 rc = -1;
353 goto error;
354 }
355
356 /* find snapshot frame */
357 for (i = 0; i < bufs->num_bufs; i++) {
358 if (bufs->bufs[i]->stream_id == m_stream->s_id) {
359 m_frame = bufs->bufs[i];
360 break;
361 }
362 }
363 if (NULL == m_frame) {
364 CDBG_ERROR("%s: main frame is NULL", __func__);
365 rc = -1;
366 goto error;
367 }
368
369 mm_app_dump_frame(m_frame, "main", "yuv", m_frame->frame_idx);
370
371 /* find postview stream */
372 for (i = 0; i < channel->num_streams; i++) {
373 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_POSTVIEW) {
374 p_stream = &channel->streams[i];
375 break;
376 }
377 }
378 if (NULL != p_stream) {
379 /* find preview frame */
380 for (i = 0; i < bufs->num_bufs; i++) {
381 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
382 p_frame = bufs->bufs[i];
383 break;
384 }
385 }
386 if (NULL != p_frame) {
387 mm_app_dump_frame(p_frame, "postview", "yuv", p_frame->frame_idx);
388 }
389 }
390
391 mm_app_cache_ops((mm_camera_app_meminfo_t *)m_frame->mem_info,
392 ION_IOC_CLEAN_INV_CACHES);
393
394 pme->jpeg_buf.buf.buffer = (uint8_t *)malloc(m_frame->frame_len);
395 if ( NULL == pme->jpeg_buf.buf.buffer ) {
396 CDBG_ERROR("%s: error allocating jpeg output buffer", __func__);
397 goto error;
398 }
399
400 pme->jpeg_buf.buf.frame_len = m_frame->frame_len;
401 /* create a new jpeg encoding session */
402 rc = createEncodingSession(pme, m_stream, m_frame);
403 if (0 != rc) {
404 CDBG_ERROR("%s: error creating jpeg session", __func__);
405 free(pme->jpeg_buf.buf.buffer);
406 goto error;
407 }
408
409 /* start jpeg encoding job */
410 rc = encodeData(pme, bufs, m_stream);
411 if (0 != rc) {
412 CDBG_ERROR("%s: error creating jpeg session", __func__);
413 free(pme->jpeg_buf.buf.buffer);
414 goto error;
415 }
416
417 error:
418 /* buf done rcvd frames in error case */
419 if ( 0 != rc ) {
420 for (i=0; i<bufs->num_bufs; i++) {
421 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
422 bufs->ch_id,
423 bufs->bufs[i])) {
424 CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
425 }
426 mm_app_cache_ops((mm_camera_app_meminfo_t *)bufs->bufs[i]->mem_info,
427 ION_IOC_INV_CACHES);
428 }
429 }
430
431 CDBG("%s: END\n", __func__);
432 }
433
mm_app_add_snapshot_channel(mm_camera_test_obj_t * test_obj)434 mm_camera_channel_t * mm_app_add_snapshot_channel(mm_camera_test_obj_t *test_obj)
435 {
436 mm_camera_channel_t *channel = NULL;
437 mm_camera_stream_t *stream = NULL;
438
439 channel = mm_app_add_channel(test_obj,
440 MM_CHANNEL_TYPE_SNAPSHOT,
441 NULL,
442 NULL,
443 NULL);
444 if (NULL == channel) {
445 CDBG_ERROR("%s: add channel failed", __func__);
446 return NULL;
447 }
448
449 stream = mm_app_add_snapshot_stream(test_obj,
450 channel,
451 mm_app_snapshot_notify_cb,
452 (void *)test_obj,
453 1,
454 1);
455 if (NULL == stream) {
456 CDBG_ERROR("%s: add snapshot stream failed\n", __func__);
457 mm_app_del_channel(test_obj, channel);
458 return NULL;
459 }
460
461 return channel;
462 }
463
mm_app_add_postview_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs,uint8_t num_burst)464 mm_camera_stream_t * mm_app_add_postview_stream(mm_camera_test_obj_t *test_obj,
465 mm_camera_channel_t *channel,
466 mm_camera_buf_notify_t stream_cb,
467 void *userdata,
468 uint8_t num_bufs,
469 uint8_t num_burst)
470 {
471 int rc = MM_CAMERA_OK;
472 mm_camera_stream_t *stream = NULL;
473 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
474
475 stream = mm_app_add_stream(test_obj, channel);
476 if (NULL == stream) {
477 CDBG_ERROR("%s: add stream failed\n", __func__);
478 return NULL;
479 }
480
481 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
482 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
483 stream->s_config.mem_vtbl.clean_invalidate_buf =
484 mm_app_stream_clean_invalidate_buf;
485 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
486 stream->s_config.mem_vtbl.user_data = (void *)stream;
487 stream->s_config.stream_cb = stream_cb;
488 stream->s_config.userdata = userdata;
489 stream->num_of_bufs = num_bufs;
490
491 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
492 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
493 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_POSTVIEW;
494 if (num_burst == 0) {
495 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
496 } else {
497 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_BURST;
498 stream->s_config.stream_info->num_of_burst = num_burst;
499 }
500 stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
501 stream->s_config.stream_info->dim.width = DEFAULT_PREVIEW_WIDTH;
502 stream->s_config.stream_info->dim.height = DEFAULT_PREVIEW_HEIGHT;
503 stream->s_config.padding_info = cam_cap->padding_info;
504
505 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
506 if (MM_CAMERA_OK != rc) {
507 CDBG_ERROR("%s:config preview stream err=%d\n", __func__, rc);
508 return NULL;
509 }
510
511 return stream;
512 }
513
mm_app_start_capture_raw(mm_camera_test_obj_t * test_obj,uint8_t num_snapshots)514 int mm_app_start_capture_raw(mm_camera_test_obj_t *test_obj, uint8_t num_snapshots)
515 {
516 int32_t rc = MM_CAMERA_OK;
517 mm_camera_channel_t *channel = NULL;
518 mm_camera_stream_t *s_main = NULL;
519 mm_camera_channel_attr_t attr;
520
521 memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
522 attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_BURST;
523 attr.max_unmatched_frames = 3;
524 channel = mm_app_add_channel(test_obj,
525 MM_CHANNEL_TYPE_CAPTURE,
526 &attr,
527 mm_app_snapshot_notify_cb_raw,
528 test_obj);
529 if (NULL == channel) {
530 CDBG_ERROR("%s: add channel failed", __func__);
531 return -MM_CAMERA_E_GENERAL;
532 }
533
534 test_obj->buffer_format = DEFAULT_RAW_FORMAT;
535 s_main = mm_app_add_raw_stream(test_obj,
536 channel,
537 mm_app_snapshot_notify_cb_raw,
538 test_obj,
539 num_snapshots,
540 num_snapshots);
541 if (NULL == s_main) {
542 CDBG_ERROR("%s: add main snapshot stream failed\n", __func__);
543 mm_app_del_channel(test_obj, channel);
544 return rc;
545 }
546
547 rc = mm_app_start_channel(test_obj, channel);
548 if (MM_CAMERA_OK != rc) {
549 CDBG_ERROR("%s:start zsl failed rc=%d\n", __func__, rc);
550 mm_app_del_stream(test_obj, channel, s_main);
551 mm_app_del_channel(test_obj, channel);
552 return rc;
553 }
554
555 return rc;
556 }
557
mm_app_stop_capture_raw(mm_camera_test_obj_t * test_obj)558 int mm_app_stop_capture_raw(mm_camera_test_obj_t *test_obj)
559 {
560 int rc = MM_CAMERA_OK;
561 mm_camera_channel_t *ch = NULL;
562 int i;
563
564 ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);
565
566 rc = mm_app_stop_channel(test_obj, ch);
567 if (MM_CAMERA_OK != rc) {
568 CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc);
569 }
570
571 for ( i = 0 ; i < ch->num_streams ; i++ ) {
572 mm_app_del_stream(test_obj, ch, &ch->streams[i]);
573 }
574
575 mm_app_del_channel(test_obj, ch);
576
577 return rc;
578 }
579
mm_app_start_capture(mm_camera_test_obj_t * test_obj,uint8_t num_snapshots)580 int mm_app_start_capture(mm_camera_test_obj_t *test_obj,
581 uint8_t num_snapshots)
582 {
583 int32_t rc = MM_CAMERA_OK;
584 mm_camera_channel_t *channel = NULL;
585 mm_camera_stream_t *s_main = NULL;
586 mm_camera_stream_t *s_metadata = NULL;
587 mm_camera_channel_attr_t attr;
588
589 memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
590 attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS;
591 attr.max_unmatched_frames = 3;
592 channel = mm_app_add_channel(test_obj,
593 MM_CHANNEL_TYPE_CAPTURE,
594 &attr,
595 mm_app_snapshot_notify_cb,
596 test_obj);
597 if (NULL == channel) {
598 CDBG_ERROR("%s: add channel failed", __func__);
599 return -MM_CAMERA_E_GENERAL;
600 }
601 s_metadata = mm_app_add_metadata_stream(test_obj,
602 channel,
603 mm_app_snapshot_metadata_notify_cb,
604 (void *)test_obj,
605 CAPTURE_BUF_NUM);
606 if (NULL == s_metadata) {
607 CDBG_ERROR("%s: add metadata stream failed\n", __func__);
608 mm_app_del_channel(test_obj, channel);
609 return -MM_CAMERA_E_GENERAL;
610 }
611
612 s_main = mm_app_add_snapshot_stream(test_obj,
613 channel,
614 NULL,
615 NULL,
616 CAPTURE_BUF_NUM,
617 num_snapshots);
618 if (NULL == s_main) {
619 CDBG_ERROR("%s: add main snapshot stream failed\n", __func__);
620 mm_app_del_channel(test_obj, channel);
621 return rc;
622 }
623
624 rc = mm_app_start_channel(test_obj, channel);
625 if (MM_CAMERA_OK != rc) {
626 CDBG_ERROR("%s:start zsl failed rc=%d\n", __func__, rc);
627 mm_app_del_stream(test_obj, channel, s_main);
628 mm_app_del_stream(test_obj, channel, s_metadata);
629 mm_app_del_channel(test_obj, channel);
630 return rc;
631 }
632
633 return rc;
634 }
635
mm_app_stop_capture(mm_camera_test_obj_t * test_obj)636 int mm_app_stop_capture(mm_camera_test_obj_t *test_obj)
637 {
638 int rc = MM_CAMERA_OK;
639 mm_camera_channel_t *ch = NULL;
640
641 ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);
642
643 rc = mm_app_stop_and_del_channel(test_obj, ch);
644 if (MM_CAMERA_OK != rc) {
645 CDBG_ERROR("%s:stop capture channel failed rc=%d\n", __func__, rc);
646 }
647
648 return rc;
649 }
650
mm_app_take_picture(mm_camera_test_obj_t * test_obj,uint8_t is_burst_mode)651 int mm_app_take_picture(mm_camera_test_obj_t *test_obj, uint8_t is_burst_mode)
652 {
653 CDBG_HIGH("\nEnter %s!!\n",__func__);
654 int rc = MM_CAMERA_OK;
655 int num_snapshot = 1;
656 int num_rcvd_snapshot = 0;
657
658 if (is_burst_mode)
659 num_snapshot = 6;
660
661 //stop preview before starting capture.
662 rc = mm_app_stop_preview(test_obj);
663 if (rc != MM_CAMERA_OK) {
664 CDBG_ERROR("%s: stop preview failed before capture!!, err=%d\n",__func__, rc);
665 return rc;
666 }
667
668 rc = mm_app_start_capture(test_obj, num_snapshot);
669 if (rc != MM_CAMERA_OK) {
670 CDBG_ERROR("%s: mm_app_start_capture(), err=%d\n", __func__,rc);
671 return rc;
672 }
673 while (num_rcvd_snapshot < num_snapshot) {
674 CDBG_HIGH("\nWaiting mm_camera_app_wait !!\n");
675 mm_camera_app_wait();
676 num_rcvd_snapshot++;
677 }
678 rc = mm_app_stop_capture(test_obj);
679 if (rc != MM_CAMERA_OK) {
680 CDBG_ERROR("%s: mm_app_stop_capture(), err=%d\n",__func__, rc);
681 return rc;
682 }
683 //start preview after capture.
684 rc = mm_app_start_preview(test_obj);
685 if (rc != MM_CAMERA_OK) {
686 CDBG_ERROR("%s: start preview failed after capture!!, err=%d\n",__func__,rc);
687 }
688 return rc;
689 }
690