1 /*
2 Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13 * Neither the name of The Linux Foundation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 // Camera dependencies
31 #include "mm_qcamera_app.h"
32 #include "mm_qcamera_dbg.h"
33
mm_app_metadata_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)34 static void mm_app_metadata_notify_cb(mm_camera_super_buf_t *bufs,
35 void *user_data)
36 {
37 uint32_t i = 0;
38 mm_camera_channel_t *channel = NULL;
39 mm_camera_stream_t *p_stream = NULL;
40 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
41 mm_camera_buf_def_t *frame;
42 metadata_buffer_t *pMetadata;
43
44 if (NULL == bufs || NULL == user_data) {
45 LOGE("bufs or user_data are not valid ");
46 return;
47 }
48 frame = bufs->bufs[0];
49
50 /* find channel */
51 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
52 if (pme->channels[i].ch_id == bufs->ch_id) {
53 channel = &pme->channels[i];
54 break;
55 }
56 }
57
58 if (NULL == channel) {
59 LOGE("Channel object is NULL ");
60 return;
61 }
62
63 /* find preview stream */
64 for (i = 0; i < channel->num_streams; i++) {
65 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_METADATA) {
66 p_stream = &channel->streams[i];
67 break;
68 }
69 }
70
71 if (NULL == p_stream) {
72 LOGE("cannot find metadata stream");
73 return;
74 }
75
76 /* find preview frame */
77 for (i = 0; i < bufs->num_bufs; i++) {
78 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
79 frame = bufs->bufs[i];
80 break;
81 }
82 }
83
84 if (pme->metadata == NULL) {
85 /* The app will free the meta data, we don't need to bother here */
86 pme->metadata = malloc(sizeof(metadata_buffer_t));
87 if (NULL == pme->metadata) {
88 LOGE("Canot allocate metadata memory\n");
89 return;
90 }
91 }
92 memcpy(pme->metadata, frame->buffer, sizeof(metadata_buffer_t));
93
94 pMetadata = (metadata_buffer_t *)frame->buffer;
95 IF_META_AVAILABLE(uint32_t, afState, CAM_INTF_META_AF_STATE, pMetadata) {
96 if ((cam_af_state_t)(*afState) == CAM_AF_STATE_FOCUSED_LOCKED ||
97 (cam_af_state_t)(*afState) == CAM_AF_STATE_NOT_FOCUSED_LOCKED) {
98 LOGE("AutoFocus Done Call Back Received\n");
99 mm_camera_app_done();
100 } else if ((cam_af_state_t)(*afState) == CAM_AF_STATE_NOT_FOCUSED_LOCKED) {
101 LOGE("AutoFocus failed\n");
102 mm_camera_app_done();
103 }
104 }
105
106 if (pme->user_metadata_cb) {
107 LOGD("[DBG] %s, user defined own metadata cb. calling it...");
108 pme->user_metadata_cb(frame);
109 }
110
111 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
112 bufs->ch_id,
113 frame)) {
114 LOGE("Failed in Preview Qbuf\n");
115 }
116 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
117 ION_IOC_INV_CACHES);
118 }
119
120
mm_app_snapshot_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)121 static void mm_app_snapshot_notify_cb(mm_camera_super_buf_t *bufs,
122 void *user_data)
123 {
124
125 int rc = 0;
126 uint32_t i = 0;
127 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
128 mm_camera_channel_t *channel = NULL;
129 mm_camera_stream_t *p_stream = NULL;
130 mm_camera_stream_t *m_stream = NULL;
131 mm_camera_buf_def_t *p_frame = NULL;
132 mm_camera_buf_def_t *m_frame = NULL;
133
134 /* find channel */
135 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
136 if (pme->channels[i].ch_id == bufs->ch_id) {
137 channel = &pme->channels[i];
138 break;
139 }
140 }
141 if (NULL == channel) {
142 LOGE("Wrong channel id (%d)", bufs->ch_id);
143 rc = -1;
144 goto error;
145 }
146
147 /* find snapshot stream */
148 for (i = 0; i < channel->num_streams; i++) {
149 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) {
150 m_stream = &channel->streams[i];
151 break;
152 }
153 }
154 if (NULL == m_stream) {
155 LOGE("cannot find snapshot stream");
156 rc = -1;
157 goto error;
158 }
159
160 /* find snapshot frame */
161 for (i = 0; i < bufs->num_bufs; i++) {
162 if (bufs->bufs[i]->stream_id == m_stream->s_id) {
163 m_frame = bufs->bufs[i];
164 break;
165 }
166 }
167 if (NULL == m_frame) {
168 LOGE("main frame is NULL");
169 rc = -1;
170 goto error;
171 }
172
173 mm_app_dump_frame(m_frame, "main", "yuv", m_frame->frame_idx);
174
175 /* find postview stream */
176 for (i = 0; i < channel->num_streams; i++) {
177 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_POSTVIEW) {
178 p_stream = &channel->streams[i];
179 break;
180 }
181 }
182 if (NULL != p_stream) {
183 /* find preview frame */
184 for (i = 0; i < bufs->num_bufs; i++) {
185 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
186 p_frame = bufs->bufs[i];
187 break;
188 }
189 }
190 if (NULL != p_frame) {
191 mm_app_dump_frame(p_frame, "postview", "yuv", p_frame->frame_idx);
192 }
193 }
194
195 mm_app_cache_ops((mm_camera_app_meminfo_t *)m_frame->mem_info,
196 ION_IOC_CLEAN_INV_CACHES);
197
198 pme->jpeg_buf.buf.buffer = (uint8_t *)malloc(m_frame->frame_len);
199 if ( NULL == pme->jpeg_buf.buf.buffer ) {
200 LOGE("error allocating jpeg output buffer");
201 goto error;
202 }
203
204 pme->jpeg_buf.buf.frame_len = m_frame->frame_len;
205 /* create a new jpeg encoding session */
206 rc = createEncodingSession(pme, m_stream, m_frame);
207 if (0 != rc) {
208 LOGE("error creating jpeg session");
209 free(pme->jpeg_buf.buf.buffer);
210 goto error;
211 }
212
213 /* start jpeg encoding job */
214 rc = encodeData(pme, bufs, m_stream);
215 if (0 != rc) {
216 LOGE("error creating jpeg session");
217 free(pme->jpeg_buf.buf.buffer);
218 goto error;
219 }
220
221 error:
222 /* buf done rcvd frames in error case */
223 if ( 0 != rc ) {
224 for (i=0; i<bufs->num_bufs; i++) {
225 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
226 bufs->ch_id,
227 bufs->bufs[i])) {
228 LOGE("Failed in Qbuf\n");
229 }
230 mm_app_cache_ops((mm_camera_app_meminfo_t *)bufs->bufs[i]->mem_info,
231 ION_IOC_INV_CACHES);
232 }
233 }
234
235 LOGD(" END\n");
236 }
237
mm_app_preview_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)238 static void mm_app_preview_notify_cb(mm_camera_super_buf_t *bufs,
239 void *user_data)
240 {
241 uint32_t i = 0;
242 mm_camera_channel_t *channel = NULL;
243 mm_camera_stream_t *p_stream = NULL;
244 mm_camera_buf_def_t *frame = NULL;
245 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
246
247 if (NULL == bufs || NULL == user_data) {
248 LOGE("bufs or user_data are not valid ");
249 return;
250 }
251
252 frame = bufs->bufs[0];
253
254 /* find channel */
255 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
256 if (pme->channels[i].ch_id == bufs->ch_id) {
257 channel = &pme->channels[i];
258 break;
259 }
260 }
261 if (NULL == channel) {
262 LOGE("Channel object is NULL ");
263 return;
264 }
265 /* find preview stream */
266 for (i = 0; i < channel->num_streams; i++) {
267 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_PREVIEW) {
268 p_stream = &channel->streams[i];
269 break;
270 }
271 }
272
273 if (NULL == p_stream) {
274 LOGE("cannot find preview stream");
275 return;
276 }
277
278 /* find preview frame */
279 for (i = 0; i < bufs->num_bufs; i++) {
280 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
281 frame = bufs->bufs[i];
282 break;
283 }
284 }
285
286 if ( 0 < pme->fb_fd ) {
287 mm_app_overlay_display(pme, frame->fd);
288 }
289 #ifdef DUMP_PRV_IN_FILE
290 {
291 char file_name[64];
292 snprintf(file_name, sizeof(file_name), "P_C%d", pme->cam->camera_handle);
293 mm_app_dump_frame(frame, file_name, "yuv", frame->frame_idx);
294 }
295 #endif
296 if (pme->user_preview_cb) {
297 LOGE("[DBG] %s, user defined own preview cb. calling it...");
298 pme->user_preview_cb(frame);
299 }
300 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
301 bufs->ch_id,
302 frame)) {
303 LOGE("Failed in Preview Qbuf\n");
304 }
305 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
306 ION_IOC_INV_CACHES);
307
308 LOGD(" END\n");
309 }
310
311
mm_app_video_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)312 static void mm_app_video_notify_cb(mm_camera_super_buf_t *bufs,
313 void *user_data)
314 {
315 char file_name[64];
316 mm_camera_buf_def_t *frame = bufs->bufs[0];
317 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
318
319 LOGD("BEGIN - length=%zu, frame idx = %d\n",
320 frame->frame_len, frame->frame_idx);
321 snprintf(file_name, sizeof(file_name), "V_C%d", pme->cam->camera_handle);
322 mm_app_dump_frame(frame, file_name, "yuv", frame->frame_idx);
323
324 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
325 bufs->ch_id,
326 frame)) {
327 LOGE("Failed in Preview Qbuf\n");
328 }
329 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
330 ION_IOC_INV_CACHES);
331
332 LOGD("END\n");
333 }
334
mm_app_add_video_preview_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)335 mm_camera_stream_t * mm_app_add_video_preview_stream(mm_camera_test_obj_t *test_obj,
336 mm_camera_channel_t *channel,
337 mm_camera_buf_notify_t stream_cb,
338 void *userdata,
339 uint8_t num_bufs)
340 {
341 int rc = MM_CAMERA_OK;
342 mm_camera_stream_t *stream = NULL;
343 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
344 cam_dimension_t preview_dim = {0, 0};
345
346 if ((test_obj->preview_resolution.user_input_display_width == 0) ||
347 ( test_obj->preview_resolution.user_input_display_height == 0)) {
348 preview_dim.width = DEFAULT_PREVIEW_WIDTH;
349 preview_dim.height = DEFAULT_PREVIEW_HEIGHT;
350 } else {
351 preview_dim.width = test_obj->preview_resolution.user_input_display_width;
352 preview_dim.height = test_obj->preview_resolution.user_input_display_height;
353 }
354 LOGI("preview dimesion: %d x %d\n", preview_dim.width, preview_dim.height);
355
356 stream = mm_app_add_stream(test_obj, channel);
357 if (NULL == stream) {
358 LOGE("add stream failed\n");
359 return NULL;
360 }
361 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
362 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
363 stream->s_config.mem_vtbl.clean_invalidate_buf =
364 mm_app_stream_clean_invalidate_buf;
365 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
366 stream->s_config.mem_vtbl.clean_buf = mm_app_stream_clean_buf;
367 stream->s_config.mem_vtbl.user_data = (void *)stream;
368 stream->s_config.stream_cb = stream_cb;
369 stream->s_config.stream_cb_sync = NULL;
370 stream->s_config.userdata = userdata;
371 stream->num_of_bufs = num_bufs;
372
373 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
374 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
375 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_PREVIEW;
376 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
377 stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
378
379 stream->s_config.stream_info->dim.width = preview_dim.width;
380 stream->s_config.stream_info->dim.height = preview_dim.height;
381 stream->s_config.stream_info->num_bufs = num_bufs;
382 stream->s_config.padding_info = cam_cap->padding_info;
383
384 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
385 if (MM_CAMERA_OK != rc) {
386 LOGE("config preview stream err=%d\n", rc);
387 return NULL;
388 }
389
390 return stream;
391 }
392
393
mm_app_add_video_snapshot_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)394 mm_camera_stream_t * mm_app_add_video_snapshot_stream(mm_camera_test_obj_t *test_obj,
395 mm_camera_channel_t *channel,
396 mm_camera_buf_notify_t stream_cb,
397 void *userdata,
398 uint8_t num_bufs,
399 uint8_t num_burst)
400 {
401 int rc = MM_CAMERA_OK;
402 mm_camera_stream_t *stream = NULL;
403 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
404
405 stream = mm_app_add_stream(test_obj, channel);
406 if (NULL == stream) {
407 LOGE("add stream failed\n");
408 return NULL;
409 }
410
411 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
412 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
413 stream->s_config.mem_vtbl.clean_invalidate_buf =
414 mm_app_stream_clean_invalidate_buf;
415 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
416 stream->s_config.mem_vtbl.clean_buf = mm_app_stream_clean_buf;
417 stream->s_config.mem_vtbl.user_data = (void *)stream;
418 stream->s_config.stream_cb = stream_cb;
419 stream->s_config.stream_cb_sync = NULL;
420 stream->s_config.userdata = userdata;
421 stream->num_of_bufs = num_bufs;
422
423 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
424 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
425 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_SNAPSHOT;
426 if (num_burst == 0) {
427 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
428 } else {
429 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_BURST;
430 stream->s_config.stream_info->num_of_burst = num_burst;
431 }
432 stream->s_config.stream_info->fmt = DEFAULT_SNAPSHOT_FORMAT;
433 if ( test_obj->buffer_width == 0 || test_obj->buffer_height == 0 ) {
434 stream->s_config.stream_info->dim.width = DEFAULT_SNAPSHOT_WIDTH;
435 stream->s_config.stream_info->dim.height = DEFAULT_SNAPSHOT_HEIGHT;
436 } else {
437 stream->s_config.stream_info->dim.width = test_obj->buffer_width;
438 stream->s_config.stream_info->dim.height = test_obj->buffer_height;
439 }
440 stream->s_config.padding_info = cam_cap->padding_info;
441 /* Make offset as zero as CPP will not be used */
442 stream->s_config.padding_info.offset_info.offset_x = 0;
443 stream->s_config.padding_info.offset_info.offset_y = 0;
444 stream->s_config.stream_info->num_bufs = num_bufs;
445 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
446 if (MM_CAMERA_OK != rc) {
447 LOGE("config preview stream err=%d\n", rc);
448 return NULL;
449 }
450
451 return stream;
452
453 }
454
455
mm_app_add_video_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)456 mm_camera_stream_t * mm_app_add_video_stream(mm_camera_test_obj_t *test_obj,
457 mm_camera_channel_t *channel,
458 mm_camera_buf_notify_t stream_cb,
459 void *userdata,
460 uint8_t num_bufs)
461 {
462 int rc = MM_CAMERA_OK;
463 mm_camera_stream_t *stream = NULL;
464 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
465
466 cam_stream_size_info_t abc_snap ;
467 memset (&abc_snap , 0, sizeof (cam_stream_size_info_t));
468
469 abc_snap.num_streams = 3;
470 abc_snap.postprocess_mask[2] = 2178;
471 abc_snap.stream_sizes[2].width = DEFAULT_PREVIEW_WIDTH;
472 abc_snap.stream_sizes[2].height = DEFAULT_PREVIEW_HEIGHT;
473 abc_snap.type[2] = CAM_STREAM_TYPE_PREVIEW;
474
475 abc_snap.postprocess_mask[1] = 2178;
476 abc_snap.stream_sizes[1].width = DEFAULT_PREVIEW_WIDTH;
477 abc_snap.stream_sizes[1].height = DEFAULT_PREVIEW_HEIGHT;
478 abc_snap.type[1] = CAM_STREAM_TYPE_VIDEO;
479
480 abc_snap.postprocess_mask[0] = 0;
481 if ( test_obj->buffer_width == 0 || test_obj->buffer_height == 0 ) {
482 abc_snap.stream_sizes[0].width = DEFAULT_SNAPSHOT_WIDTH;
483 abc_snap.stream_sizes[0].height = DEFAULT_SNAPSHOT_HEIGHT;
484 } else {
485 abc_snap.stream_sizes[0].width = test_obj->buffer_width;
486 abc_snap.stream_sizes[0].height = test_obj->buffer_height;
487 }
488 abc_snap.type[0] = CAM_STREAM_TYPE_SNAPSHOT;
489
490 abc_snap.buffer_info.min_buffers = 7;
491 abc_snap.buffer_info.max_buffers = 7;
492 abc_snap.is_type[0] = IS_TYPE_NONE;
493
494 rc = setmetainfoCommand(test_obj, &abc_snap);
495 if (rc != MM_CAMERA_OK) {
496 LOGE("meta info command snapshot failed\n");
497 }
498
499 stream = mm_app_add_stream(test_obj, channel);
500 if (NULL == stream) {
501 LOGE("add stream failed\n");
502 return NULL;
503 }
504
505 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
506 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
507 stream->s_config.mem_vtbl.clean_invalidate_buf =
508 mm_app_stream_clean_invalidate_buf;
509 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
510 stream->s_config.mem_vtbl.clean_buf = mm_app_stream_clean_buf;
511 stream->s_config.mem_vtbl.user_data = (void *)stream;
512 stream->s_config.stream_cb = stream_cb;
513 stream->s_config.stream_cb_sync = NULL;
514 stream->s_config.userdata = userdata;
515 stream->num_of_bufs = num_bufs;
516
517 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
518 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
519 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_VIDEO;
520 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
521 stream->s_config.stream_info->fmt = DEFAULT_VIDEO_FORMAT;
522 stream->s_config.stream_info->dim.width = DEFAULT_PREVIEW_WIDTH;
523 stream->s_config.stream_info->dim.height = DEFAULT_PREVIEW_HEIGHT;
524 stream->s_config.stream_info->num_bufs = num_bufs;
525 stream->s_config.padding_info = cam_cap->padding_info;
526
527 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
528 if (MM_CAMERA_OK != rc) {
529 LOGE("config preview stream err=%d\n", rc);
530 return NULL;
531 }
532
533 return stream;
534 }
535
mm_app_add_video_channel(mm_camera_test_obj_t * test_obj)536 mm_camera_channel_t * mm_app_add_video_channel(mm_camera_test_obj_t *test_obj)
537 {
538 mm_camera_channel_t *channel = NULL;
539 mm_camera_stream_t *stream = NULL;
540
541 channel = mm_app_add_channel(test_obj,
542 MM_CHANNEL_TYPE_VIDEO,
543 NULL,
544 NULL,
545 NULL);
546 if (NULL == channel) {
547 LOGE("add channel failed");
548 return NULL;
549 }
550
551 stream = mm_app_add_video_stream(test_obj,
552 channel,
553 mm_app_video_notify_cb,
554 (void *)test_obj,
555 1);
556 if (NULL == stream) {
557 LOGE("add video stream failed\n");
558 mm_app_del_channel(test_obj, channel);
559 return NULL;
560 }
561
562 return channel;
563 }
564
mm_app_start_record_preview(mm_camera_test_obj_t * test_obj,mm_camera_lib_snapshot_params * dim)565 int mm_app_start_record_preview(mm_camera_test_obj_t *test_obj,
566 mm_camera_lib_snapshot_params *dim)
567 {
568 int rc = MM_CAMERA_OK;
569 mm_camera_channel_t *p_ch = NULL;
570 mm_camera_channel_t *v_ch = NULL;
571 mm_camera_channel_t *s_ch = NULL;
572 mm_camera_stream_t *s_preview = NULL;
573 mm_camera_stream_t *s_metadata = NULL;
574 mm_camera_stream_t *s_main = NULL;
575 mm_camera_stream_t *s_video = NULL;
576
577
578 if (dim != NULL) {
579 test_obj->buffer_width = dim->width;
580 test_obj->buffer_height = dim->height;
581 }
582 /* Create Video Channel */
583 v_ch = mm_app_add_channel(test_obj,
584 MM_CHANNEL_TYPE_VIDEO,
585 NULL,
586 NULL,
587 NULL);
588 if (NULL == v_ch) {
589 LOGE("add channel failed");
590 return -MM_CAMERA_E_GENERAL;
591 }
592
593 /* Add Video Stream */
594 s_video = mm_app_add_video_stream(test_obj,
595 v_ch,
596 mm_app_video_notify_cb,
597 (void*)test_obj,
598 VIDEO_BUF_NUM);
599
600 if (NULL == s_video) {
601 LOGE("add video stream failed\n");
602 mm_app_del_channel(test_obj, v_ch);
603 return rc;
604 }
605
606 /* Create Preview Channel */
607 p_ch = mm_app_add_channel(test_obj,
608 MM_CHANNEL_TYPE_PREVIEW,
609 NULL,
610 NULL,
611 NULL);
612 /* Add Preview stream to Channel */
613 if (NULL == p_ch) {
614 LOGE("add channel failed");
615 return -MM_CAMERA_E_GENERAL;
616 }
617
618
619 s_preview = mm_app_add_video_preview_stream(test_obj,
620 p_ch,
621 mm_app_preview_notify_cb,
622 (void *)test_obj,
623 PREVIEW_BUF_NUM);
624 if (NULL == s_preview) {
625 LOGE("add preview stream failed\n");
626 mm_app_del_channel(test_obj, p_ch);
627 return rc;
628 }
629 /* Create Snapshot Channel */
630 s_ch = mm_app_add_channel(test_obj,
631 MM_CHANNEL_TYPE_SNAPSHOT,
632 NULL,
633 NULL,
634 NULL);
635 if (NULL == s_ch) {
636 LOGE("add channel failed");
637 return -MM_CAMERA_E_GENERAL;
638 }
639
640 /* Add Snapshot Stream */
641 s_main = mm_app_add_video_snapshot_stream(test_obj,
642 s_ch,
643 mm_app_snapshot_notify_cb,
644 (void *)test_obj,
645 1,
646 1);
647 if (NULL == s_main) {
648 LOGE("add main snapshot stream failed\n");
649 mm_app_del_channel(test_obj, s_ch);
650 return rc;
651 }
652
653
654 /* Add Metadata Stream to preview channel */
655 s_metadata = mm_app_add_metadata_stream(test_obj,
656 p_ch,
657 mm_app_metadata_notify_cb,
658 (void *)test_obj,
659 PREVIEW_BUF_NUM);
660
661 if (NULL == s_metadata) {
662 LOGE("add metadata stream failed\n");
663 mm_app_del_channel(test_obj, p_ch);
664 return rc;
665 }
666
667 /* Start Preview Channel */
668 rc = mm_app_start_channel(test_obj, p_ch);
669 if (MM_CAMERA_OK != rc) {
670 LOGE("start preview failed rc=%d\n", rc);
671 mm_app_del_channel(test_obj, p_ch);
672 mm_app_del_channel(test_obj, v_ch);
673 mm_app_del_channel(test_obj, s_ch);
674 return rc;
675 }
676
677 /* Start Video Channel */
678 rc = mm_app_start_channel(test_obj, v_ch);
679 if (MM_CAMERA_OK != rc) {
680 LOGE("start preview failed rc=%d\n", rc);
681 mm_app_del_channel(test_obj, p_ch);
682 mm_app_del_channel(test_obj, v_ch);
683 mm_app_del_channel(test_obj, s_ch);
684 return rc;
685 }
686
687 return rc;
688 }
689
mm_app_stop_record_preview(mm_camera_test_obj_t * test_obj)690 int mm_app_stop_record_preview(mm_camera_test_obj_t *test_obj)
691 {
692 int rc = MM_CAMERA_OK;
693 mm_camera_channel_t *p_ch = NULL;
694 mm_camera_channel_t *v_ch = NULL;
695 mm_camera_channel_t *s_ch = NULL;
696
697 p_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_PREVIEW);
698 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
699 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
700
701 rc = mm_app_stop_and_del_channel(test_obj, p_ch);
702 if (MM_CAMERA_OK != rc) {
703 LOGE("Stop Preview failed rc=%d\n", rc);
704 }
705
706 rc = mm_app_stop_and_del_channel(test_obj, v_ch);
707 if (MM_CAMERA_OK != rc) {
708 LOGE("Stop Preview failed rc=%d\n", rc);
709 }
710
711 rc = mm_app_stop_and_del_channel(test_obj, s_ch);
712 if (MM_CAMERA_OK != rc) {
713 LOGE("Stop Preview failed rc=%d\n", rc);
714 }
715
716 return rc;
717 }
718
mm_app_start_record(mm_camera_test_obj_t * test_obj)719 int mm_app_start_record(mm_camera_test_obj_t *test_obj)
720 {
721 int rc = MM_CAMERA_OK;
722 mm_camera_channel_t *v_ch = NULL;
723
724 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
725
726 rc = mm_app_start_channel(test_obj, v_ch);
727 if (MM_CAMERA_OK != rc) {
728 LOGE("start recording failed rc=%d\n", rc);
729 }
730
731 return rc;
732 }
733
mm_app_stop_record(mm_camera_test_obj_t * test_obj)734 int mm_app_stop_record(mm_camera_test_obj_t *test_obj)
735 {
736 int rc = MM_CAMERA_OK;
737 mm_camera_channel_t *v_ch = NULL;
738
739 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO);
740
741 rc = mm_app_stop_channel(test_obj, v_ch);
742 if (MM_CAMERA_OK != rc) {
743 LOGE("stop recording failed rc=%d\n", rc);
744 }
745
746 return rc;
747 }
748
mm_app_start_live_snapshot(mm_camera_test_obj_t * test_obj)749 int mm_app_start_live_snapshot(mm_camera_test_obj_t *test_obj)
750 {
751 int rc = MM_CAMERA_OK;
752 mm_camera_channel_t *s_ch = NULL;
753
754 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
755
756 rc = mm_app_start_channel(test_obj, s_ch);
757 if (MM_CAMERA_OK != rc) {
758 LOGE("start recording failed rc=%d\n", rc);
759 }
760
761 return rc;
762 }
763
mm_app_stop_live_snapshot(mm_camera_test_obj_t * test_obj)764 int mm_app_stop_live_snapshot(mm_camera_test_obj_t *test_obj)
765 {
766 int rc = MM_CAMERA_OK;
767 mm_camera_channel_t *s_ch = NULL;
768
769 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT);
770
771 rc = mm_app_stop_channel(test_obj, s_ch);
772 if (MM_CAMERA_OK != rc) {
773 LOGE("stop recording failed rc=%d\n", rc);
774 }
775
776 return rc;
777 }
778