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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "mm_qcamera_dbg.h"
#include "mm_qcamera_app.h"
/* This callback is received once the complete JPEG encoding is done */
static void jpeg_encode_cb(jpeg_job_status_t status,
uint32_t client_hdl,
uint32_t jobId,
mm_jpeg_output_t *p_buf,
void *userData)
{
uint32_t i = 0;
mm_camera_test_obj_t *pme = NULL;
CDBG("%s: BEGIN\n", __func__);
pme = (mm_camera_test_obj_t *)userData;
if (pme->jpeg_hdl != client_hdl ||
jobId != pme->current_job_id ||
!pme->current_job_frames) {
CDBG_ERROR("%s: NULL current job frames or not matching job ID (%d, %d)",
__func__, jobId, pme->current_job_id);
return;
}
/* dump jpeg img */
CDBG_ERROR("%s: job %d, status=%d", __func__, jobId, status);
if (status == JPEG_JOB_STATUS_DONE && p_buf != NULL) {
mm_app_dump_jpeg_frame(p_buf->buf_vaddr, p_buf->buf_filled_len, "jpeg", "jpg", jobId);
}
/* buf done current encoding frames */
pme->current_job_id = 0;
for (i = 0; i < pme->current_job_frames->num_bufs; i++) {
if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->current_job_frames->camera_handle,
pme->current_job_frames->ch_id,
pme->current_job_frames->bufs[i])) {
CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
}
mm_app_cache_ops((mm_camera_app_meminfo_t *) pme->current_job_frames->bufs[i]->mem_info,
ION_IOC_INV_CACHES);
}
free(pme->jpeg_buf.buf.buffer);
free(pme->current_job_frames);
pme->current_job_frames = NULL;
/* signal snapshot is done */
mm_camera_app_done();
}
int encodeData(mm_camera_test_obj_t *test_obj, mm_camera_super_buf_t* recvd_frame,
mm_camera_stream_t *m_stream)
{
cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
int rc = -MM_CAMERA_E_GENERAL;
mm_jpeg_job_t job;
/* remember current frames being encoded */
test_obj->current_job_frames =
(mm_camera_super_buf_t *)malloc(sizeof(mm_camera_super_buf_t));
if (!test_obj->current_job_frames) {
CDBG_ERROR("%s: No memory for current_job_frames", __func__);
return rc;
}
*(test_obj->current_job_frames) = *recvd_frame;
memset(&job, 0, sizeof(job));
job.job_type = JPEG_JOB_TYPE_ENCODE;
job.encode_job.session_id = test_obj->current_jpeg_sess_id;
// TODO: Rotation should be set according to
// sensor&device orientation
job.encode_job.rotation = 0;
if (cam_cap->position == CAM_POSITION_BACK) {
job.encode_job.rotation = 270;
}
/* fill in main src img encode param */
job.encode_job.main_dim.src_dim = m_stream->s_config.stream_info->dim;
job.encode_job.main_dim.dst_dim = m_stream->s_config.stream_info->dim;
job.encode_job.src_index = 0;
job.encode_job.thumb_dim.src_dim = m_stream->s_config.stream_info->dim;
job.encode_job.thumb_dim.dst_dim.width = DEFAULT_PREVIEW_WIDTH;
job.encode_job.thumb_dim.dst_dim.height = DEFAULT_PREVIEW_HEIGHT;
/* fill in sink img param */
job.encode_job.dst_index = 0;
if (test_obj->metadata != NULL) {
job.encode_job.p_metadata = test_obj->metadata;
}
rc = test_obj->jpeg_ops.start_job(&job, &test_obj->current_job_id);
if ( 0 != rc ) {
free(test_obj->current_job_frames);
test_obj->current_job_frames = NULL;
}
return rc;
}
int createEncodingSession(mm_camera_test_obj_t *test_obj,
mm_camera_stream_t *m_stream,
mm_camera_buf_def_t *m_frame)
{
mm_jpeg_encode_params_t encode_param;
memset(&encode_param, 0, sizeof(mm_jpeg_encode_params_t));
encode_param.jpeg_cb = jpeg_encode_cb;
encode_param.userdata = (void*)test_obj;
encode_param.encode_thumbnail = 0;
encode_param.quality = 85;
encode_param.color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;
encode_param.thumb_color_format = MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2;
/* fill in main src img encode param */
encode_param.num_src_bufs = 1;
encode_param.src_main_buf[0].index = 0;
encode_param.src_main_buf[0].buf_size = m_frame->frame_len;
encode_param.src_main_buf[0].buf_vaddr = (uint8_t *)m_frame->buffer;
encode_param.src_main_buf[0].fd = m_frame->fd;
encode_param.src_main_buf[0].format = MM_JPEG_FMT_YUV;
encode_param.src_main_buf[0].offset = m_stream->offset;
/* fill in sink img param */
encode_param.num_dst_bufs = 1;
encode_param.dest_buf[0].index = 0;
encode_param.dest_buf[0].buf_size = test_obj->jpeg_buf.buf.frame_len;
encode_param.dest_buf[0].buf_vaddr = (uint8_t *)test_obj->jpeg_buf.buf.buffer;
encode_param.dest_buf[0].fd = test_obj->jpeg_buf.buf.fd;
encode_param.dest_buf[0].format = MM_JPEG_FMT_YUV;
/* main dimension */
encode_param.main_dim.src_dim = m_stream->s_config.stream_info->dim;
encode_param.main_dim.dst_dim = m_stream->s_config.stream_info->dim;
return test_obj->jpeg_ops.create_session(test_obj->jpeg_hdl,
&encode_param,
&test_obj->current_jpeg_sess_id);
}
#if 0 // Removing metadata stream for snapshot in qcamera app.
/** mm_app_snapshot_metadata_notify_cb
* @bufs: Pointer to super buffer
* @user_data: Pointer to user data
*
*
**/
static void mm_app_snapshot_metadata_notify_cb(mm_camera_super_buf_t *bufs,
void *user_data)
{
uint32_t i = 0;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *p_stream = NULL;
mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
mm_camera_buf_def_t *frame = bufs->bufs[0];
cam_metadata_info_t *pMetadata;
cam_auto_focus_data_t *focus_data;
/* find channel */
for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
if (pme->channels[i].ch_id == bufs->ch_id) {
channel = &pme->channels[i];
break;
}
}
if (NULL == channel) {
CDBG_ERROR("%s: Wrong channel id", __func__);
return;
}
/* find preview stream */
for (i = 0; i < channel->num_streams; i++) {
if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_METADATA) {
p_stream = &channel->streams[i];
break;
}
}
if (NULL == p_stream) {
CDBG_ERROR("%s: Wrong preview stream", __func__);
return;
}
/* find preview frame */
for (i = 0; i < bufs->num_bufs; i++) {
if (bufs->bufs[i]->stream_id == p_stream->s_id) {
frame = bufs->bufs[i];
break;
}
}
if (NULL == p_stream) {
CDBG_ERROR("%s: cannot find metadata stream", __func__);
return;
}
if (!pme->metadata) {
/* The app will free the metadata, we don't need to bother here */
pme->metadata = malloc(sizeof(cam_metadata_info_t));
}
/* find meta data frame */
mm_camera_buf_def_t *meta_frame = NULL;
for (i = 0; i < bufs->num_bufs; i++) {
if (bufs->bufs[i]->stream_type == CAM_STREAM_TYPE_METADATA) {
meta_frame = bufs->bufs[i];
break;
}
}
/* fill in meta data frame ptr */
if (meta_frame != NULL) {
pme->metadata = (cam_metadata_info_t *)meta_frame->buffer;
}
pMetadata = (cam_metadata_info_t *)frame->buffer;
if (pMetadata->is_focus_valid) {
focus_data = (cam_auto_focus_data_t *)&(pMetadata->focus_data);
if (focus_data->focus_state == CAM_AF_FOCUSED) {
CDBG_ERROR("%s: AutoFocus Done Call Back Received\n",__func__);
mm_camera_app_done();
}
}
if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
bufs->ch_id,
frame)) {
CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
}
mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
ION_IOC_INV_CACHES);
}
#endif
static void mm_app_snapshot_notify_cb_raw(mm_camera_super_buf_t *bufs,
void *user_data)
{
int rc;
uint32_t i = 0;
mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *m_stream = NULL;
mm_camera_buf_def_t *m_frame = NULL;
CDBG("%s: BEGIN\n", __func__);
/* find channel */
for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
if (pme->channels[i].ch_id == bufs->ch_id) {
channel = &pme->channels[i];
break;
}
}
if (NULL == channel) {
CDBG_ERROR("%s: Wrong channel id (%d)", __func__, bufs->ch_id);
rc = -1;
goto EXIT;
}
/* find snapshot stream */
for (i = 0; i < channel->num_streams; i++) {
if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_RAW) {
m_stream = &channel->streams[i];
break;
}
}
if (NULL == m_stream) {
CDBG_ERROR("%s: cannot find snapshot stream", __func__);
rc = -1;
goto EXIT;
}
/* find snapshot frame */
for (i = 0; i < bufs->num_bufs; i++) {
if (bufs->bufs[i]->stream_id == m_stream->s_id) {
m_frame = bufs->bufs[i];
break;
}
}
if (NULL == m_frame) {
CDBG_ERROR("%s: main frame is NULL", __func__);
rc = -1;
goto EXIT;
}
mm_app_dump_frame(m_frame, "main", "raw", m_frame->frame_idx);
EXIT:
for (i=0; i<bufs->num_bufs; i++) {
if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
bufs->ch_id,
bufs->bufs[i])) {
CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
}
}
mm_camera_app_done();
CDBG("%s: END\n", __func__);
}
static void mm_app_snapshot_notify_cb(mm_camera_super_buf_t *bufs,
void *user_data)
{
int rc = 0;
uint32_t i = 0;
mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *p_stream = NULL;
mm_camera_stream_t *m_stream = NULL;
mm_camera_buf_def_t *p_frame = NULL;
mm_camera_buf_def_t *m_frame = NULL;
CDBG("%s: BEGIN\n", __func__);
/* find channel */
for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
if (pme->channels[i].ch_id == bufs->ch_id) {
channel = &pme->channels[i];
break;
}
}
if (NULL == channel) {
CDBG_ERROR("%s: Wrong channel id (%d)", __func__, bufs->ch_id);
rc = -1;
goto error;
}
/* find snapshot stream */
for (i = 0; i < channel->num_streams; i++) {
if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) {
m_stream = &channel->streams[i];
break;
}
}
if (NULL == m_stream) {
CDBG_ERROR("%s: cannot find snapshot stream", __func__);
rc = -1;
goto error;
}
/* find snapshot frame */
for (i = 0; i < bufs->num_bufs; i++) {
if (bufs->bufs[i]->stream_id == m_stream->s_id) {
m_frame = bufs->bufs[i];
break;
}
}
if (NULL == m_frame) {
CDBG_ERROR("%s: main frame is NULL", __func__);
rc = -1;
goto error;
}
mm_app_dump_frame(m_frame, "main", "yuv", m_frame->frame_idx);
/* find postview stream */
for (i = 0; i < channel->num_streams; i++) {
if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_POSTVIEW) {
p_stream = &channel->streams[i];
break;
}
}
if (NULL != p_stream) {
/* find preview frame */
for (i = 0; i < bufs->num_bufs; i++) {
if (bufs->bufs[i]->stream_id == p_stream->s_id) {
p_frame = bufs->bufs[i];
break;
}
}
if (NULL != p_frame) {
mm_app_dump_frame(p_frame, "postview", "yuv", p_frame->frame_idx);
}
}
mm_app_cache_ops((mm_camera_app_meminfo_t *)m_frame->mem_info,
ION_IOC_CLEAN_INV_CACHES);
pme->jpeg_buf.buf.buffer = (uint8_t *)malloc(m_frame->frame_len);
if ( NULL == pme->jpeg_buf.buf.buffer ) {
CDBG_ERROR("%s: error allocating jpeg output buffer", __func__);
goto error;
}
pme->jpeg_buf.buf.frame_len = m_frame->frame_len;
/* create a new jpeg encoding session */
rc = createEncodingSession(pme, m_stream, m_frame);
if (0 != rc) {
CDBG_ERROR("%s: error creating jpeg session", __func__);
free(pme->jpeg_buf.buf.buffer);
goto error;
}
/* start jpeg encoding job */
rc = encodeData(pme, bufs, m_stream);
if (0 != rc) {
CDBG_ERROR("%s: error creating jpeg session", __func__);
free(pme->jpeg_buf.buf.buffer);
goto error;
}
error:
/* buf done rcvd frames in error case */
if ( 0 != rc ) {
for (i=0; i<bufs->num_bufs; i++) {
if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
bufs->ch_id,
bufs->bufs[i])) {
CDBG_ERROR("%s: Failed in Qbuf\n", __func__);
}
mm_app_cache_ops((mm_camera_app_meminfo_t *)bufs->bufs[i]->mem_info,
ION_IOC_INV_CACHES);
}
}
CDBG("%s: END\n", __func__);
}
mm_camera_channel_t * mm_app_add_snapshot_channel(mm_camera_test_obj_t *test_obj)
{
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *stream = NULL;
channel = mm_app_add_channel(test_obj,
MM_CHANNEL_TYPE_SNAPSHOT,
NULL,
NULL,
NULL);
if (NULL == channel) {
CDBG_ERROR("%s: add channel failed", __func__);
return NULL;
}
stream = mm_app_add_snapshot_stream(test_obj,
channel,
mm_app_snapshot_notify_cb,
(void *)test_obj,
1,
1);
if (NULL == stream) {
CDBG_ERROR("%s: add snapshot stream failed\n", __func__);
mm_app_del_channel(test_obj, channel);
return NULL;
}
return channel;
}
mm_camera_stream_t * 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)
{
int rc = MM_CAMERA_OK;
mm_camera_stream_t *stream = NULL;
cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
stream = mm_app_add_stream(test_obj, channel);
if (NULL == stream) {
CDBG_ERROR("%s: add stream failed\n", __func__);
return NULL;
}
stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
stream->s_config.mem_vtbl.clean_invalidate_buf =
mm_app_stream_clean_invalidate_buf;
stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
stream->s_config.mem_vtbl.user_data = (void *)stream;
stream->s_config.stream_cb = stream_cb;
stream->s_config.userdata = userdata;
stream->num_of_bufs = num_bufs;
stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_POSTVIEW;
if (num_burst == 0) {
stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
} else {
stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_BURST;
stream->s_config.stream_info->num_of_burst = num_burst;
}
stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
stream->s_config.stream_info->dim.width = DEFAULT_PREVIEW_WIDTH;
stream->s_config.stream_info->dim.height = DEFAULT_PREVIEW_HEIGHT;
stream->s_config.padding_info = cam_cap->padding_info;
rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
if (MM_CAMERA_OK != rc) {
CDBG_ERROR("%s:config preview stream err=%d\n", __func__, rc);
return NULL;
}
return stream;
}
int mm_app_start_capture_raw(mm_camera_test_obj_t *test_obj, uint8_t num_snapshots)
{
int32_t rc = MM_CAMERA_OK;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *s_main = NULL;
mm_camera_channel_attr_t attr;
memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_BURST;
attr.max_unmatched_frames = 3;
channel = mm_app_add_channel(test_obj,
MM_CHANNEL_TYPE_CAPTURE,
&attr,
mm_app_snapshot_notify_cb_raw,
test_obj);
if (NULL == channel) {
CDBG_ERROR("%s: add channel failed", __func__);
return -MM_CAMERA_E_GENERAL;
}
test_obj->buffer_format = DEFAULT_RAW_FORMAT;
s_main = mm_app_add_raw_stream(test_obj,
channel,
mm_app_snapshot_notify_cb_raw,
test_obj,
num_snapshots,
num_snapshots);
if (NULL == s_main) {
CDBG_ERROR("%s: add main snapshot stream failed\n", __func__);
mm_app_del_channel(test_obj, channel);
return rc;
}
rc = mm_app_start_channel(test_obj, channel);
if (MM_CAMERA_OK != rc) {
CDBG_ERROR("%s:start zsl failed rc=%d\n", __func__, rc);
mm_app_del_stream(test_obj, channel, s_main);
mm_app_del_channel(test_obj, channel);
return rc;
}
return rc;
}
int mm_app_stop_capture_raw(mm_camera_test_obj_t *test_obj)
{
int rc = MM_CAMERA_OK;
mm_camera_channel_t *ch = NULL;
int i;
ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);
rc = mm_app_stop_channel(test_obj, ch);
if (MM_CAMERA_OK != rc) {
CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc);
}
for ( i = 0 ; i < ch->num_streams ; i++ ) {
mm_app_del_stream(test_obj, ch, &ch->streams[i]);
}
mm_app_del_channel(test_obj, ch);
return rc;
}
int mm_app_start_capture(mm_camera_test_obj_t *test_obj,
uint8_t num_snapshots)
{
int32_t rc = MM_CAMERA_OK;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *s_main = NULL;
mm_camera_stream_t *s_metadata = NULL;
mm_camera_channel_attr_t attr;
memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS;
attr.max_unmatched_frames = 3;
channel = mm_app_add_channel(test_obj,
MM_CHANNEL_TYPE_CAPTURE,
&attr,
mm_app_snapshot_notify_cb,
test_obj);
if (NULL == channel) {
CDBG_ERROR("%s: add channel failed", __func__);
return -MM_CAMERA_E_GENERAL;
}
#if 0 // Removing metadata stream for snapshot in qcamera app.
s_metadata = mm_app_add_metadata_stream(test_obj,
channel,
mm_app_snapshot_metadata_notify_cb,
(void *)test_obj,
CAPTURE_BUF_NUM);
if (NULL == s_metadata) {
CDBG_ERROR("%s: add metadata stream failed\n", __func__);
mm_app_del_channel(test_obj, channel);
return -MM_CAMERA_E_GENERAL;
}
#endif
s_main = mm_app_add_snapshot_stream(test_obj,
channel,
NULL,
NULL,
CAPTURE_BUF_NUM,
num_snapshots);
if (NULL == s_main) {
CDBG_ERROR("%s: add main snapshot stream failed\n", __func__);
mm_app_del_channel(test_obj, channel);
return rc;
}
rc = mm_app_start_channel(test_obj, channel);
if (MM_CAMERA_OK != rc) {
CDBG_ERROR("%s:start zsl failed rc=%d\n", __func__, rc);
mm_app_del_stream(test_obj, channel, s_main);
mm_app_del_stream(test_obj, channel, s_metadata);
mm_app_del_channel(test_obj, channel);
return rc;
}
return rc;
}
int mm_app_stop_capture(mm_camera_test_obj_t *test_obj)
{
int rc = MM_CAMERA_OK;
mm_camera_channel_t *ch = NULL;
ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);
rc = mm_app_stop_and_del_channel(test_obj, ch);
if (MM_CAMERA_OK != rc) {
CDBG_ERROR("%s:stop capture channel failed rc=%d\n", __func__, rc);
}
return rc;
}
int mm_app_take_picture(mm_camera_test_obj_t *test_obj, uint8_t is_burst_mode)
{
CDBG_HIGH("\nEnter %s!!\n",__func__);
int rc = MM_CAMERA_OK;
uint8_t num_snapshot = 1;
int num_rcvd_snapshot = 0;
if (is_burst_mode)
num_snapshot = 6;
//stop preview before starting capture.
rc = mm_app_stop_preview(test_obj);
if (rc != MM_CAMERA_OK) {
CDBG_ERROR("%s: stop preview failed before capture!!, err=%d\n",__func__, rc);
return rc;
}
rc = mm_app_start_capture(test_obj, num_snapshot);
if (rc != MM_CAMERA_OK) {
CDBG_ERROR("%s: mm_app_start_capture(), err=%d\n", __func__,rc);
return rc;
}
while (num_rcvd_snapshot < num_snapshot) {
CDBG_HIGH("\nWaiting mm_camera_app_wait !!\n");
mm_camera_app_wait();
num_rcvd_snapshot++;
}
rc = mm_app_stop_capture(test_obj);
if (rc != MM_CAMERA_OK) {
CDBG_ERROR("%s: mm_app_stop_capture(), err=%d\n",__func__, rc);
return rc;
}
//start preview after capture.
rc = mm_app_start_preview(test_obj);
if (rc != MM_CAMERA_OK) {
CDBG_ERROR("%s: start preview failed after capture!!, err=%d\n",__func__,rc);
}
return rc;
}
|