camera_internal: Fix invalid type for timestamp
[platform/core/api/camera.git] / test / camera_test.c
1 /*
2  * camera_test
3  *
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License f(r the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /*=======================================================================================
23 |  INCLUDE FILES                                                                        |
24 =======================================================================================*/
25 #include <stdint.h>
26 #include "camera_test.h"
27
28 /*-----------------------------------------------------------------------
29 |    GLOBAL VARIABLE DEFINITIONS:                                       |
30 -----------------------------------------------------------------------*/
31 #define EXPORT_API __attribute__((__visibility__("default")))
32
33 #ifdef LOG_TAG
34 #undef LOG_TAG
35 #endif
36 #define LOG_TAG "CAMERA_TEST"
37
38
39 static cam_handle_t *hcamcorder;
40 static camera_device_e camera_device;
41 static int g_camera_device_state_changed_cb_id;
42 static int g_camera_device_connection_changed_cb_id;
43 static int g_camera_preview_cb_dump;
44 static int g_camera_extra_preview_cb_dump;
45 static int g_camera_mp_preview_cb_dump;
46
47 static struct timeval previous_time;
48 static struct timeval current_time;
49 static struct timeval result_time;
50
51 static media_bridge_h bridge;
52 static camera_device_manager_h g_device_manager;
53
54 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
55         "None",
56         "Auto",
57         "Daylight",
58         "Cloudy",
59         "Fluoroscent",
60         "Incandescent",
61         "Shade",
62         "Horizon",
63         "Flash",
64         "Custom",
65 };
66
67 const char *ct[SENSOR_COLOR_TONE_NUM] = {
68         "NONE",
69         "MONO",
70         "SEPIA",
71         "NEGATIVE",
72         "BLUE",
73         "GREEN",
74         "AQUA",
75         "VIOLET",
76         "ORANGE",
77         "GRAY",
78         "RED",
79         "ANTIQUE",
80         "WARM",
81         "PINK",
82         "YELLOW",
83         "PURPLE",
84         "EMBOSS",
85         "OUTLINE",
86         "SOLARIZATION",
87         "SKETCH",
88         "WASHED",
89         "VINTAGE_WARM",
90         "VINTAGE_COLD",
91         "POSTERIZATION",
92         "CARTOON",
93         "SELECTVE_COLOR_RED",
94         "SELECTVE_COLOR_GREEN",
95         "SELECTVE_COLOR_BLUE",
96         "SELECTVE_COLOR_YELLOW",
97         "SELECTVE_COLOR_RED_YELLOW",
98         "GRAPHICS"
99 };
100
101 const char *sensor_flip[SENSOR_FLIP_NUM] = {
102         "NONE",
103         "HORIZONTAL",
104         "VERTICAL",
105         "BOTH"
106 };
107
108 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
109         "NORMAL",
110         "PORTRAIT",
111         "LANDSCAPE",
112         "SPORTS",
113         "PARTY_N_INDOOR",
114         "BEACH_N_INDOOR",
115         "SUNSET",
116         "DUSK_N_DAWN",
117         "FALL_COLOR",
118         "NIGHT_SCENE",
119         "FIREWORK",
120         "TEXT",
121         "SHOW_WINDOW",
122         "CANDLE_LIGHT",
123         "BACKLIGHT",
124 };
125
126 const char *focus_mode[SENSOR_FOCUS_NUM] = {
127         "None",
128         "Pan",
129         "Auto",
130         "Manual",
131         "Touch Auto",
132         "Continuous Auto",
133 };
134
135 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
136         "None",
137         "90",
138         "180",
139         "270",
140 };
141
142 const char *iso_mode[SENSOR_ISO_NUM] = {
143         "ISO Auto",
144         "ISO 50",
145         "ISO 100",
146         "ISO 200",
147         "ISO 400",
148         "ISO 800",
149         "ISO 1600",
150         "ISO 3200",
151 };
152
153 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
154         "AE off",
155         "AE all mode",
156         "AE center mode",
157         "AE spot 1 mode",
158         "AE custom mode",
159 };
160
161 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
162         "NV12",
163         "NV12T",
164         "NV16",
165         "NV21",
166         "YUYV",
167         "UYVY",
168         "422P",
169         "I420",
170         "YV12",
171         "RGB565",
172         "RGB888",
173         "RGBA",
174         "ARGB",
175         "JPEG",
176         "ITLV(YUYV+JPEG, but should not be seen)",
177         "H264",
178         "INVZ",
179         "MJPEG",
180         "VP8",
181         "VP9"
182 };
183
184 const char *face_zoom_mode[] = {
185         "Face Zoom OFF",
186         "Face Zoom ON",
187 };
188
189 const char *display_mode[] = {
190         "Letter Box mode",
191         "Original Size mode",
192         "Full Screen mode",
193         "Cropped Full Screen mode",
194         "ROI mode",
195 };
196
197 const char *capture_sound[] = {
198         "Default",
199         "Extra 01",
200         "Extra 02",
201 };
202
203 const char *rotate_mode[] = {
204         "0",
205         "90",
206         "180",
207         "270",
208 };
209
210 const char* strobe_mode[] = {
211         "Strobe OFF",
212         "Strobe ON",
213         "Strobe Auto",
214         "Strobe RedEyeReduction",
215         "Strobe SlowSync",
216         "Strobe FrontCurtain",
217         "Strobe RearCurtain",
218         "Strobe Permanent",
219 };
220
221 const char *detection_mode[2] = {
222         "Face Detection OFF",
223         "Face Detection ON",
224 };
225
226 const char *wdr_mode[] = {
227         "WDR OFF",
228         "WDR ON",
229         "WDR AUTO",
230 };
231
232 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
233         "None",
234         "Normal",
235         "Macro mode",
236         "Full mode",
237 };
238
239 const char *hdr_mode[] = {
240         "HDR OFF",
241         "HDR ON",
242         "HDR ON and Original",
243 };
244
245 const char *ahs_mode[] = {
246         "Anti-handshake OFF",
247         "Anti-handshake ON",
248         "Anti-handshake AUTO",
249         "Anti-handshake MOVIE",
250 };
251
252 const char *vs_mode[] = {
253         "Video-stabilization OFF",
254         "Video-stabilization ON",
255 };
256
257 const char *visible_mode[] = {
258         "Display OFF",
259         "Display ON",
260 };
261
262 const char *facing_direction[] = {
263         "REAR",
264         "FRONT",
265 };
266
267 enum {
268         PREVIEW_CB_TYPE_NORMAL = 0,
269         PREVIEW_CB_TYPE_MEDIA_PACKET,
270         PREVIEW_CB_TYPE_EXTRA
271 };
272
273 typedef void (*preview_cb)(void);
274 typedef int (*set_preview_cb)(camera_h, void *, void *);
275
276
277 /*---------------------------------------------------------------------------
278   |    LOCAL FUNCTION PROTOTYPES:                                             |
279   ---------------------------------------------------------------------------*/
280 static gboolean mode_change(gchar buf);
281 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
282
283
284 static void __release_media_bridge()
285 {
286         if (bridge) {
287                 media_bridge_unset_source(bridge); /* not mandatory, it will be done in media_bridge_destroy() */
288                 media_bridge_destroy(bridge);
289                 bridge = NULL;
290         }
291 }
292
293 void flush_stdin()
294 {
295         int ch;
296         while ((ch = getchar()) != EOF && ch != '\n');
297 }
298
299 static gboolean _release_idle_event_callback(void *data)
300 {
301         g_print("destroy camera handle\n\n");
302
303         camera_destroy(hcamcorder->camera);
304         hcamcorder->camera = NULL;
305         hcamcorder->menu_state = MENU_STATE_INIT;
306
307         print_menu();
308
309         return 0;
310 }
311
312 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
313 {
314         g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
315
316         switch (error) {
317         case CAMERA_ERROR_RESOURCE_CONFLICT:
318                 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
319                 break;
320         case CAMERA_ERROR_SECURITY_RESTRICTED:
321                 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
322                 break;
323         case CAMERA_ERROR_SERVICE_DISCONNECTED:
324                 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
325                 g_idle_add_full(G_PRIORITY_DEFAULT,
326                         (GSourceFunc)_release_idle_event_callback,
327                         NULL, NULL);
328                 break;
329         default:
330                 break;
331         }
332 }
333
334 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
335 {
336         g_print("\n\tcamera state changed %d -> %d\n", previous, current);
337 }
338
339 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
340 {
341         g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
342 }
343
344 static void _camera_device_connection_changed_cb(camera_device_s *device, bool is_connected, void *user_data)
345 {
346         g_print("\n\tcamera device changed[is_connected:%d][Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
347                 is_connected, device->type, device->index, device->name, device->id, device->extra_stream_num);
348 }
349
350 static bool _camera_supported_device_cb(camera_device_s *device, void *user_data)
351 {
352         g_print("\n\tcamera supported device[Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
353                 device->type, device->index, device->name, device->id, device->extra_stream_num);
354
355         return true;
356 }
357
358 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
359 {
360         g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
361                 previous, current, policy);
362 }
363
364 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
365 {
366         g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
367 }
368
369 static void _dump_preview_data(camera_preview_data_s *frame, const char *file_name)
370 {
371         char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
372         FILE *fp = NULL;
373
374         if (!frame) {
375                 LOGE("NULL frame");
376                 return;
377         }
378
379         snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
380
381         fp = fopen(dump_path, "a");
382         if (fp == NULL) {
383                 LOGE("file[%s] open failed", dump_path);
384                 return;
385         }
386
387         switch (frame->format) {
388         case CAMERA_PIXEL_FORMAT_RGBA:
389                 /* fall through */
390         case CAMERA_PIXEL_FORMAT_ARGB:
391                 LOGD("RGB p[%p] size[%u]", frame->data.rgb_plane.data, frame->data.rgb_plane.size);
392                 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
393                 break;
394         case CAMERA_PIXEL_FORMAT_INVZ:
395                 LOGD("INVZ p[%p] size[%u]", frame->data.depth_plane.data, frame->data.depth_plane.size);
396                 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
397                 break;
398         case CAMERA_PIXEL_FORMAT_H264:
399                 /* fall through */
400         case CAMERA_PIXEL_FORMAT_MJPEG:
401                 /* fall through */
402         case CAMERA_PIXEL_FORMAT_VP8:
403                 /* fall through */
404         case CAMERA_PIXEL_FORMAT_VP9:
405                 LOGD("ENCODED[%d] p[%p] size[%u]",
406                         frame->format, frame->data.encoded_plane.data, frame->data.encoded_plane.size);
407                 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
408                 break;
409         default:
410                 switch (frame->num_of_planes) {
411                 case 1:
412                         LOGD("SINGLE plane p[%p], size[%u]",
413                                 frame->data.single_plane.yuv, frame->data.single_plane.size);
414                         fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
415                         break;
416                 case 2:
417                         LOGD("DOUBLE plane p[%p,%p], size[%u,%u]",
418                                 frame->data.double_plane.y, frame->data.double_plane.uv,
419                                 frame->data.double_plane.y_size, frame->data.double_plane.uv_size);
420                         fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
421                         fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
422                         break;
423                 case 3:
424                         LOGD("TRIPLE plane p[%p,%p,%p], size[%u,%u,%u]",
425                                 frame->data.triple_plane.y, frame->data.triple_plane.u, frame->data.triple_plane.v,
426                                 frame->data.triple_plane.y_size, frame->data.triple_plane.u_size, frame->data.triple_plane.v_size);
427                         fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
428                         fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
429                         fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
430                         break;
431                 default:
432                         break;
433                 }
434                 break;
435         }
436
437         fclose(fp);
438 }
439
440 static void _camera_print_preview_info(camera_preview_data_s *frame, int stream_id)
441 {
442         char frame_info[128] = {'\0', };
443
444         if (!frame) {
445                 LOGE("[PREVIEW_CB] NULL frame!");
446                 return;
447         }
448
449         snprintf(frame_info, sizeof(frame_info), "stream_id[%d] format[%d] res[%dx%d] num plane[%d]",
450                 stream_id, frame->format, frame->width, frame->height, frame->num_of_planes);
451
452         if (frame->num_of_planes == 1) {
453                 LOGD("%s size [%d]",
454                         frame_info,
455                         frame->data.single_plane.size);
456         } else if (frame->num_of_planes == 2) {
457                 LOGD("%s size Y[%d] UV[%d]",
458                         frame_info,
459                         frame->data.double_plane.y_size,
460                         frame->data.double_plane.uv_size);
461         } else if (frame->num_of_planes == 3) {
462                 LOGD("%s size Y[%d] U[%d] V[%d]",
463                         frame_info,
464                         frame->data.triple_plane.y_size,
465                         frame->data.triple_plane.u_size,
466                         frame->data.triple_plane.v_size);
467         }
468 }
469
470 static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
471 {
472         int ret = CAMERA_ERROR_NONE;
473         camera_h cam_handle = (camera_h)user_data;
474         camera_rotation_e rotation = CAMERA_ROTATION_NONE;
475         unsigned long long timestamp = 0;
476         camera_frame_meta_s frame_meta = {0, };
477         camera_status_auto_exposure_e status_ae = CAMERA_STATUS_AUTO_EXPOSURE_NONE;
478         camera_status_auto_white_balance_e status_awb = CAMERA_STATUS_AUTO_WHITE_BALANCE_NONE;
479
480         if (!cam_handle || !frame) {
481                 LOGE("NULL param! %p %p", cam_handle, frame);
482                 return;
483         }
484
485         ret = camera_attr_get_preview_frame_rotation(cam_handle, &rotation);
486         if (ret != CAMERA_ERROR_NONE)
487                 LOGW("get preview frame rotation failed[0x%x]", ret);
488
489         ret = camera_attr_get_preview_frame_timestamp(cam_handle, &timestamp);
490         if (ret == CAMERA_ERROR_NONE)
491                 LOGI("rotation[%d], timestamp[%llu]", rotation, timestamp);
492         else
493                 LOGW("get preview frame timestamp failed[0x%x]", ret);
494
495         ret = camera_attr_get_preview_frame_meta(cam_handle, &frame_meta);
496         if (ret == CAMERA_ERROR_NONE) {
497                 LOGD("meta %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu%llu,%llu",
498                         frame_meta.ts_soe, frame_meta.ts_eoe, frame_meta.ts_sof, frame_meta.ts_eof,
499                         frame_meta.ts_hal, frame_meta.ts_qmf, frame_meta.ts_gst, frame_meta.td_exp,
500                         frame_meta.ts_aux, frame_meta.td_aux, frame_meta.seqnum, frame_meta.flags);
501         } else {
502                 LOGW("get preview frame meta failed[0x%x]", ret);
503         }
504
505         ret = camera_attr_get_preview_frame_status_auto_exposure(cam_handle, &status_ae);
506         if (ret == CAMERA_ERROR_NONE)
507                 LOGD("status: auto exposure[%d]", status_ae);
508         else
509                 LOGW("get preview frame status auto exposure failed[0x%x]", ret);
510
511         ret = camera_attr_get_preview_frame_status_auto_white_balance(cam_handle, &status_awb);
512         if (ret == CAMERA_ERROR_NONE)
513                 LOGD("status: auto white balance[%d]", status_awb);
514         else
515                 LOGW("get preview frame status auto white balance failed[0x%x]", ret);
516
517         _camera_print_preview_info(frame, -1);
518
519         if (g_camera_preview_cb_dump)
520                 _dump_preview_data(frame, PREVIEW_CB_DUMP_FILE_NAME);
521 }
522
523 static void _camera_extra_preview_cb(camera_preview_data_s *frame, int stream_id, void *user_data)
524 {
525         if (!frame) {
526                 LOGE("NULL frame!");
527                 return;
528         }
529
530         _camera_print_preview_info(frame, stream_id);
531
532         if (g_camera_extra_preview_cb_dump)
533                 _dump_preview_data(frame, EXTRA_PREVIEW_CB_DUMP_FILE_NAME);
534 }
535
536 static void _dump_media_packet_data(media_packet_h pkt, const char *file_name)
537 {
538         int ret = 0;
539         unsigned int i = 0;
540         bool has_surface = false;
541         FILE *fp = NULL;
542         char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
543         tbm_surface_h surface = NULL;
544         tbm_surface_info_s s_info;
545         void *data = NULL;
546         uint64_t data_size = 0;
547
548         if (!pkt) {
549                 LOGE("NULL packet");
550                 return;
551         }
552
553         snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
554         fp = fopen(dump_path, "a");
555         if (fp == NULL) {
556                 LOGE("file[%s] open failed[errno:%d]", dump_path, errno);
557                 goto _DUMP_MEDIA_PACKET_DATA_OUT;
558         }
559
560         ret = media_packet_has_tbm_surface_buffer(pkt, &has_surface);
561         if (ret != MEDIA_PACKET_ERROR_NONE) {
562                 LOGE("has tbm surface failed[0x%x]", ret);
563                 goto _DUMP_MEDIA_PACKET_DATA_OUT;
564         }
565
566         if (has_surface) {
567                 ret = media_packet_get_tbm_surface(pkt, &surface);
568                 if (ret != MEDIA_PACKET_ERROR_NONE) {
569                         LOGE("get tbm surface failed[0x%x]", ret);
570                         goto _DUMP_MEDIA_PACKET_DATA_OUT;
571                 }
572
573                 ret = tbm_surface_get_info(surface, &s_info);
574                 if (ret != TBM_SURFACE_ERROR_NONE) {
575                         LOGE("get tbm surface info failed[0x%x]", ret);
576                         goto _DUMP_MEDIA_PACKET_DATA_OUT;
577                 }
578
579                 LOGD("tbm surface[%dx%d], size[%u]", s_info.width, s_info.height, s_info.size);
580
581                 for (i = 0 ; i < s_info.num_planes ; i++) {
582                         LOGD("  plane[%d][%p] stride[%u] size[%u]",
583                                 i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
584
585                         fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
586                 }
587         } else {
588                 ret = media_packet_get_buffer_data_ptr(pkt, &data);
589                 if (ret != MEDIA_PACKET_ERROR_NONE) {
590                         LOGE("get data ptr failed[0x%x]", ret);
591                         goto _DUMP_MEDIA_PACKET_DATA_OUT;
592                 }
593
594                 ret = media_packet_get_buffer_size(pkt, &data_size);
595                 if (ret != MEDIA_PACKET_ERROR_NONE) {
596                         LOGE("get data size failed[0x%x]", ret);
597                         goto _DUMP_MEDIA_PACKET_DATA_OUT;
598                 }
599
600                 LOGD("no tbm surface, data[%p], size[%"PRIu64"]", data, data_size);
601
602                 fwrite(data, 1, data_size, fp);
603         }
604
605 _DUMP_MEDIA_PACKET_DATA_OUT:
606         if (fp)
607                 fclose(fp);
608 }
609
610 static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
611 {
612         int ret = 0;
613         int width = 0;
614         int height = 0;
615         media_format_h fmt = NULL;
616         media_format_mimetype_e type = MEDIA_FORMAT_I420;
617
618         if (!pkt) {
619                 LOGE("NULL packet!");
620                 return;
621         }
622
623         ret = media_packet_get_format(pkt, &fmt);
624         if (ret != MEDIA_PACKET_ERROR_NONE) {
625                 LOGW("get media format failed[0x%x]", ret);
626                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
627         }
628
629         ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
630         if (ret != MEDIA_FORMAT_ERROR_NONE) {
631                 LOGW("get video info failed[0x%x]", ret);
632                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
633         }
634
635         LOGD("mimetype[0x%x], resolution[%dx%d]", type, width, height);
636
637         if (g_camera_mp_preview_cb_dump)
638                 _dump_media_packet_data(pkt, MP_PREVIEW_CB_DUMP_FILE_NAME);
639
640 _MEDIA_PACKET_PREVIEW_CB_OUT:
641         if (fmt) {
642                 media_format_unref(fmt);
643                 fmt = NULL;
644         }
645
646         media_packet_unref(pkt);
647 }
648
649
650 static int __set_preview_cb_common(int *preview_cb_dump, set_preview_cb set_cb, preview_cb callback)
651 {
652         g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
653
654         if (scanf("%d", preview_cb_dump) <= 0)
655                 g_print("\n\tscanf for preview_cb_dump failed[errno:%d]\n", errno);
656
657         flush_stdin();
658
659         return set_cb(hcamcorder->camera, callback, hcamcorder->camera);
660 }
661
662
663 static int _camera_set_preview_cb(int type)
664 {
665         int set_cb = 0;
666
667         g_print("* Preview Callback[type:%d,0:NORMAL,1:MEDIAPACKET,2:EXTRA]\n", type);
668
669         g_print("\tUnset[0] / Set[Others] :");
670
671         if (scanf("%d", &set_cb) <= 0)
672                 g_print("\n\tscanf failed[errno:%d]\n", errno);
673
674         flush_stdin();
675
676         switch (type) {
677         case PREVIEW_CB_TYPE_NORMAL:
678                 if (set_cb == 0)
679                         return camera_unset_preview_cb(hcamcorder->camera);
680                 else
681                         return __set_preview_cb_common(&g_camera_preview_cb_dump,
682                                 (set_preview_cb)camera_set_preview_cb,
683                                 (preview_cb)_camera_preview_cb);
684         case PREVIEW_CB_TYPE_MEDIA_PACKET:
685                 if (set_cb == 0)
686                         return camera_unset_media_packet_preview_cb(hcamcorder->camera);
687                 else
688                         return __set_preview_cb_common(&g_camera_mp_preview_cb_dump,
689                                 (set_preview_cb)camera_set_media_packet_preview_cb,
690                                 (preview_cb)_camera_media_packet_preview_cb);
691         case PREVIEW_CB_TYPE_EXTRA:
692                 if (set_cb == 0)
693                         return camera_unset_extra_preview_cb(hcamcorder->camera);
694                 else
695                         return __set_preview_cb_common(&g_camera_extra_preview_cb_dump,
696                                 (set_preview_cb)camera_set_extra_preview_cb,
697                                 (preview_cb)_camera_extra_preview_cb);
698         default:
699                 g_print("\n\tUnknown type[%d]\n", type);
700                 return CAMERA_ERROR_INVALID_PARAMETER;
701         }
702 }
703
704
705 static bool _resolution_cb(int width, int height, void *user_data)
706 {
707         resolution_stack *data = (resolution_stack *)user_data;
708
709         if (data == NULL) {
710                 g_print("NULL data\n");
711                 return false;
712         }
713
714         data->width[data->count] = width;
715         data->height[data->count] = height;
716
717         g_print("\t%d. %dx%d\n", data->count, width, height);
718
719         data->count++;
720
721         return true;
722 }
723
724 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
725 {
726         g_print("\t%d. %s\n", mode, af_scan[mode]);
727         return true;
728 }
729
730 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
731 {
732         exposure_stack *data = (exposure_stack *)user_data;
733
734         if (data == NULL) {
735                 g_print("NULL data\n");
736                 return false;
737         }
738
739         data->mode = mode;
740         data->count++;
741
742         g_print("\t%d. %s\n", mode, exposure_mode[mode]);
743         return true;
744 }
745
746 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
747 {
748         g_print("\t%d. %s\n", mode, iso_mode[mode]);
749         return true;
750 }
751
752 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
753 {
754         g_print("\t%d. %s\n", mode, camera_rotation[mode]);
755         return true;
756 }
757
758 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
759 {
760         g_print("\t%d. %s\n", mode, sensor_flip[mode]);
761         return true;
762 }
763
764 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
765 {
766         g_print("\t%d. %s\n", mode, image_fmt[mode]);
767         return true;
768 }
769
770 static bool capture_format_cb(camera_pixel_format_e mode, void *user_data)
771 {
772         g_print("\t%d. %s\n", mode, image_fmt[mode]);
773         return true;
774 }
775
776 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
777 {
778         g_print("\t%d. %s\n", mode, wb[mode]);
779         return true;
780 }
781
782 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
783 {
784         g_print("\t%d. %s\n", mode, ct[mode]);
785         return true;
786 }
787
788 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
789 {
790         g_print("\t%d. %s\n", mode, program_mode[mode]);
791         return true;
792 }
793
794 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
795 {
796         g_print("\t%d. %s\n", mode, strobe_mode[mode]);
797         return true;
798 }
799
800 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
801 {
802         int i;
803
804         g_print("\tface detected!! - count %d\n", count);
805
806         for (i = 0 ; i < count ; i++)
807                 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
808 }
809
810 static void _file_write(char *path, void *data, int size)
811 {
812         FILE *fp = NULL;
813
814         if (!path || !data || size <= 0) {
815                 g_print("\n\tERROR %p %p %d\n", path, data, size);
816                 return;
817         }
818
819         fp = fopen(path, "w");
820         if (fp) {
821                 g_print("\n\topen success [%s]\n", path);
822                 if (fwrite(data, size, 1, fp) != 1)
823                         g_print("\n\twrite error! errno %d\n", errno);
824                 else
825                         g_print("\n\twrite success [%s]\n", path);
826
827                 fclose(fp);
828                 fp = NULL;
829         } else {
830                 g_print("\n\topen error! [%s], errno %d\n", path, errno);
831         }
832 }
833
834 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
835 {
836         char m_filename[MAX_FILE_NAME_LENGTH];
837
838         /* main image */
839         if (image) {
840                 if (hcamcorder->is_multishot) {
841                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
842                                 hcamcorder->file_path, hcamcorder->multishot_count++);
843                 } else {
844                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
845                                 hcamcorder->file_path, hcamcorder->stillshot_count++);
846                 }
847
848                 _file_write(m_filename, image->data, image->size);
849         }
850 }
851
852 static void capture_completed_cb(void *user_data)
853 {
854         camera_start_preview(hcamcorder->camera);
855 }
856
857 void print_menu()
858 {
859         switch (hcamcorder->menu_state) {
860         case MENU_STATE_INIT:
861                 g_print("\n\t=======================================\n");
862                 g_print("\t   CAMERA_TESTSUITE\n");
863                 g_print("\t=======================================\n");
864                 g_print("\t   '1' Video Capture\n");
865                 g_print("\t   '2' Device State\n");
866                 g_print("\t   '3' Device Manager\n");
867                 g_print("\t   'q' Exit\n");
868                 g_print("\t=======================================\n");
869                 break;
870         case MENU_STATE_MAIN:
871                 g_print("\n\t=======================================\n");
872                 g_print("\t   Video Capture (CAMERA%d)\n", camera_device);
873                 g_print("\t=======================================\n");
874                 g_print("\t   '1' Stillshot test\n");
875                 g_print("\t   '2' Multishot test\n");
876                 g_print("\t   '3' Setting\n");
877                 g_print("\t   '4' Change device (CAMERA0 <-> CAMERA1)\n");
878                 g_print("\t   '5' Set/Unset preview callback\n");
879                 g_print("\t   '6' Set/Unset extra preview callback\n");
880                 g_print("\t   '7' Set/Unset media packet preview callback\n");
881                 g_print("\t   'b' back\n");
882                 g_print("\t=======================================\n");
883                 break;
884         case MENU_STATE_DEVICE_STATE:
885                 g_print("\n\t=======================================\n");
886                 g_print("\t   Device State\n");
887                 g_print("\t=======================================\n");
888                 g_print("\t   '1' Get camera device state\n");
889                 g_print("\t   '2' Add camera device state changed callback\n");
890                 g_print("\t   '3' Remove camera device state changed callback\n");
891                 g_print("\t   'b' back\n");
892                 g_print("\t=======================================\n");
893                 break;
894         case MENU_STATE_DEVICE_MANAGER:
895                 g_print("\n\t=======================================\n");
896                 g_print("\t   Device List\n");
897                 g_print("\t=======================================\n");
898                 g_print("\t   '1' Initialize device manager\n");
899                 g_print("\t   '2' Foreach supported camera device\n");
900                 g_print("\t   '3' Add camera device connection changed callback\n");
901                 g_print("\t   '4' Remove camera device connection changed callback\n");
902                 g_print("\t   '9' Deinitialize device manager\n");
903                 g_print("\t   'b' back\n");
904                 g_print("\t=======================================\n");
905                 break;
906         case MENU_STATE_MAIN_SETTING:
907                 g_print("\n\t=======================================\n");
908                 g_print("\t   Video Capture > Setting\n");
909                 g_print("\t=======================================\n");
910                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
911                 g_print("\t     '0' Preview resolution \n");
912                 g_print("\t     '1' Capture resolution \n");
913                 g_print("\t     '2' Digital zoom level \n");
914                 g_print("\t     '3' AF mode \n");
915                 g_print("\t     '4' AF scan range \n");
916                 g_print("\t     '5' Exposure mode \n");
917                 g_print("\t     '6' Exposure value \n");
918                 g_print("\t     '7' F number \n");
919                 g_print("\t     '8' Display reuse hint \n");
920                 g_print("\t     '9' Manual Focus \n");
921                 g_print("\t     'i' ISO \n");
922                 g_print("\t     'r' Rotate camera input \n");
923                 g_print("\t     'f' Flip camera input \n");
924                 g_print("\t     'j' Jpeg quality \n");
925                 g_print("\t     'p' Preview format \n");
926                 g_print("\t     'C' Capture format \n");
927                 g_print("\t     'E' EXIF orientation \n");
928                 g_print("\t     'F' Get facing direction of camera module\n");
929                 g_print("\t     's' Extra preview stream format\n");
930                 g_print("\t     'B' Extra preview bitrate\n");
931                 g_print("\t     'V' Extra preview GOP interval\n");
932                 g_print("\t     'D' Request codec config\n");
933                 g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
934                 g_print("\t     'v' Visible \n");
935                 g_print("\t     'o' Output mode \n");
936                 g_print("\t     'y' Rotate display \n");
937                 g_print("\t     'Y' Flip display \n");
938                 g_print("\t     'g' Brightness \n");
939                 g_print("\t     'c' Contrast \n");
940                 g_print("\t     'h' Hue \n");
941                 g_print("\t     'a' Saturation \n");
942                 g_print("\t     'A' Sharpness \n");
943                 g_print("\t     'q' Gain \n");
944                 g_print("\t     'w' White balance \n");
945                 g_print("\t     'W' White balance temperature \n");
946                 g_print("\t     't' Color tone \n");
947                 g_print("\t     'd' WDR \n");
948                 g_print("\t     'e' EV program mode \n");
949                 g_print("\t     'R' Display ROI area \n");
950                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
951                 g_print("\t     'z' Strobe (Flash) \n");
952                 g_print("\t     'S' Strobe (Flash) state\n");
953                 g_print("\t     'G' Strobe (Flash) brightness\n");
954                 g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
955                 g_print("\t     'l' Face detection \n");
956                 g_print("\t     'k' Anti-handshake \n");
957                 g_print("\t     'K' Video-stabilization \n");
958                 g_print("\t     'u' Touch AF area \n");
959                 g_print("\t     'n' Set file path to write captured image\n");
960                 g_print("\t     'm' Set media bridge\n");
961                 g_print("\t     'b' back\n");
962                 g_print("\t=======================================\n");
963                 break;
964         default:
965                 g_print("\n\tunknow menu state !!\n");
966                 return;
967         }
968
969         g_print("\tCommand >> ");
970 }
971
972
973 static void main_menu(gchar buf)
974 {
975         int err = 0;
976         int interval = 0;
977         int count = 0;
978
979         switch (buf) {
980         case '1': /* Capture */
981                 hcamcorder->is_multishot = FALSE;
982                 camera_attr_set_image_quality(hcamcorder->camera, 100);
983                 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
984                 break;
985         case '2': /* multishot Capture */
986                 g_print("multishot capture");
987                 hcamcorder->is_multishot = TRUE;
988                 g_print("\n\tinput interval(ms) : ");
989                 err = scanf("%d", &interval);
990                 flush_stdin();
991                 g_print("\n\tinput count : ");
992                 err = scanf("%d", &count);
993                 flush_stdin();
994                 camera_attr_set_image_quality(hcamcorder->camera, 100);
995                 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
996                 sleep(3);
997                 camera_start_preview(hcamcorder->camera);
998                 break;
999         case '3': /* Setting */
1000                 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
1001                 break;
1002         case '4': /* Change device (CAMERA0 <-> CAMERA1) */
1003                 camera_set_display_reuse_hint(hcamcorder->camera, true);
1004
1005                 camera_stop_preview(hcamcorder->camera);
1006
1007                 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
1008                         hcamcorder->type = CAMERA_DEVICE_CAMERA1;
1009                 else
1010                         hcamcorder->type = CAMERA_DEVICE_CAMERA0;
1011
1012                 camera_change_device(hcamcorder->camera, hcamcorder->type);
1013
1014                 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1015                 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1016                 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1017                 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1018
1019                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1020
1021                 camera_start_preview(hcamcorder->camera);
1022                 break;
1023         case '5':
1024                 err = _camera_set_preview_cb(PREVIEW_CB_TYPE_NORMAL);
1025                 g_print("\tresult[0x%x]\n\n", err);
1026                 break;
1027         case '6':
1028                 err = _camera_set_preview_cb(PREVIEW_CB_TYPE_EXTRA);
1029                 g_print("\tresult[0x%x]\n\n", err);
1030                 break;
1031         case '7':
1032                 err = _camera_set_preview_cb(PREVIEW_CB_TYPE_MEDIA_PACKET);
1033                 g_print("\tresult[0x%x]\n\n", err);
1034                 break;
1035         case 'b': /* back */
1036                 __release_media_bridge();
1037
1038                 camera_stop_preview(hcamcorder->camera);
1039                 camera_destroy(hcamcorder->camera);
1040                 hcamcorder->camera = NULL;
1041                 hcamcorder->menu_state = MENU_STATE_INIT;
1042                 break;
1043         default:
1044                 g_print("\t Invalid input \n");
1045                 break;
1046         }
1047 }
1048
1049
1050 static void setting_menu(gchar buf)
1051 {
1052         int bret = FALSE;
1053         int idx = 0;
1054         int min = 0;
1055         int max = 0;
1056         int i = 0;
1057         int err = 0;
1058         int x = 0;
1059         int y = 0;
1060         int width = 0;
1061         int height = 0;
1062         int result = 0;
1063         int set_bridge = 0;
1064         int stream_id;
1065         int pixel_format;
1066         int fps;
1067         int bitrate;
1068         int interval;
1069         int step = 0;
1070
1071         switch (buf) {
1072         /* Camera setting */
1073         case '0':  /* Setting > Preview Resolution setting */
1074                 g_print("\t* Select the preview resolution!\n");
1075                 resolution_stack resolution_list;
1076                 resolution_list.count = 0;
1077
1078                 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1079                         _resolution_cb, &resolution_list);
1080
1081                 g_print("\tCommand >> ");
1082
1083                 err = scanf("%d", &idx);
1084                 flush_stdin();
1085                 if (resolution_list.count > idx && idx >= 0) {
1086                         g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1087                                 resolution_list.width[idx], resolution_list.height[idx]);
1088
1089                         result = camera_set_preview_resolution(hcamcorder->camera,
1090                                 resolution_list.width[idx], resolution_list.height[idx]);
1091                 } else {
1092                         g_print("\tInvalid command [%d]\n", idx);
1093                         result = -1;
1094                 }
1095                 resolution_list.count = 0;
1096                 if (result == CAMERA_ERROR_NONE)
1097                         g_print("\tPASS\n");
1098                 else
1099                         g_print("\tFAIL\n");
1100                 break;
1101         case '1': /* Setting > Capture Resolution setting */
1102                 g_print("\t* Select the capture resolution!\n");
1103                 resolution_list.count = 0;
1104
1105                 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1106                         _resolution_cb, &resolution_list);
1107
1108                 g_print("\tCommand > ");
1109
1110                 err = scanf("%d", &idx);
1111                 flush_stdin();
1112                 if (resolution_list.count > idx && idx >= 0) {
1113                         g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1114                                 resolution_list.width[idx], resolution_list.height[idx]);
1115
1116                         result = camera_set_capture_resolution(hcamcorder->camera,
1117                                 resolution_list.width[idx], resolution_list.height[idx]);
1118                 } else {
1119                         g_print("\tInvalid command [%d]\n", idx);
1120                         result = -1;
1121                 }
1122                 resolution_list.count = 0;
1123                 if (result == CAMERA_ERROR_NONE)
1124                         g_print("\tPASS\n");
1125                 else
1126                         g_print("\tFAIL\n");
1127                 break;
1128         case '2': /* Setting > Digital zoom level */
1129                 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1130                 if (min > max) {
1131                         g_print("\tDigital Zoom Not supported\n");
1132                 } else {
1133                         g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1134                         err = scanf("%d", &idx);
1135                         flush_stdin();
1136                         bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1137                 }
1138                 break;
1139         case '3': /* Setting > AF mode */
1140                 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1141                 err = scanf("%d", &idx);
1142                 flush_stdin();
1143                 switch (idx) {
1144                 case 1:
1145                         camera_start_focusing(hcamcorder->camera, 0);
1146                         break;
1147                 case 2:
1148                         camera_cancel_focusing(hcamcorder->camera);
1149                         break;
1150                 default:
1151                         g_print("\tInvalid command [%d]\n", idx);
1152                         break;
1153                 }
1154                 break;
1155         case '4': /* Setting > AF scan range */
1156                 g_print("\t* AF scan range !\n");
1157                 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1158                 g_print("\tCommand > ");
1159                 err = scanf("%d", &idx);
1160                 flush_stdin();
1161                 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1162                 break;
1163         case '5': /* Setting > Exposure mode */
1164                 g_print("* Exposure mode!\n");
1165                 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1166                 g_print("\n Select  Exposure mode \n");
1167                 err = scanf("%d", &idx);
1168                 flush_stdin();
1169                 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1170                 break;
1171
1172         case '6': /* Setting > Exposure value */
1173                 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1174                 if (min >= max)
1175                         g_print("Not supported !! \n");
1176                 else {
1177                         g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
1178                         err = scanf("%d", &idx);
1179                         flush_stdin();
1180                         bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1181                 }
1182                 break;
1183         case '7': /* Setting > F number */
1184                 g_print("Not supported !! \n");
1185                 break;
1186         case '8': /* Setting > Display reuse hint */
1187                 {
1188                         bool reuse_hint = false;
1189
1190                         err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1191                         if (err != CAMERA_ERROR_NONE) {
1192                                 g_print("failed to get display reuse hint 0x%x\n", err);
1193                                 break;
1194                         }
1195
1196                         g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1197                         reuse_hint = !reuse_hint;
1198                         err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1199                         g_print("set display reuse hint result : 0x%x\n", err);
1200                 }
1201                 break;
1202         case '9': /* Setting > Manual focus */
1203                 g_print("*Manual focus !\n");
1204                 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1205                 if (min > max) {
1206                         g_print("\n\tManual focus is NOT SUPPORTED\n");
1207                         break;
1208                 }
1209                 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1210                 g_print("\tCurrent focus level (%d)\n", idx);
1211                 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1212                 err = scanf("%d", &idx);
1213                 flush_stdin();
1214                 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1215                 idx = -1;
1216                 if (bret == CAMERA_ERROR_NONE) {
1217                         bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1218                         g_print("\tfocus level[%d] after set\n", idx);
1219                 } else {
1220                         g_print("\tset focus level failed[0x%x]\n", bret);
1221                 }
1222                 break;
1223         case 'i': /* Setting > ISO */
1224                 g_print("*ISO !\n");
1225                 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1226                 err = scanf("%d", &idx);
1227                 flush_stdin();
1228                 bret =  camera_attr_set_iso(hcamcorder->camera, idx);
1229                 break;
1230         case 'r': /* Setting > Rotate camera input when recording */
1231                 g_print("*Rotate camera input\n");
1232                 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1233                 err = scanf("%d", &idx);
1234                 flush_stdin();
1235                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1236                 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1237                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1238                 break;
1239         case 'f': /* Setting > Flip camera input */
1240                 g_print("*Flip camera input\n");
1241                 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1242                 err = scanf("%d", &idx);
1243                 flush_stdin();
1244                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1245                 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1246                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1247                 break;
1248         case 'j': /* Setting > Jpeg quality */
1249                 g_print("*Jpeg quality !\n");
1250                 g_print("\n Select  Jpeg quality \n");
1251                 err = scanf("%d", &idx);
1252                 flush_stdin();
1253                 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1254                 break;
1255         case 'p': /* Setting > Preview format */
1256                 g_print("* Preview format!\n");
1257                 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1258                 err = scanf("%d", &idx);
1259                 flush_stdin();
1260                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1261                 bret = camera_set_preview_format(hcamcorder->camera, idx);
1262                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1263                 break;
1264         case 'C': /* Setting > Capture format */
1265                 g_print("* Capture format!\n");
1266                 camera_foreach_supported_capture_format(hcamcorder->camera, capture_format_cb, NULL);
1267                 err = scanf("%d", &idx);
1268                 flush_stdin();
1269                 bret = camera_set_capture_format(hcamcorder->camera, idx);
1270                 break;
1271         case 'E': /* Setting > EXIF orientation */
1272                 g_print("* EXIF Orientation\n");
1273                 g_print("\t 1. TOP_LEFT\n");
1274                 g_print("\t 2. TOP_RIGHT(flipped)\n");
1275                 g_print("\t 3. BOTTOM_RIGHT\n");
1276                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1277                 g_print("\t 5. LEFT_TOP(flipped)\n");
1278                 g_print("\t 6. RIGHT_TOP\n");
1279                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1280                 g_print("\t 8. LEFT_BOTTOM\n");
1281                 err = scanf("%d", &idx);
1282                 flush_stdin();
1283                 if (idx < 1 || idx > 8)
1284                         g_print("Wrong INPUT[%d]!! \n", idx);
1285                 else
1286                         camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1287                 break;
1288         case 'F': /* Setting > Get Facing direction */
1289                 g_print("* Get facing direction of camera module\n");
1290                 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1291                 if (CAMERA_ERROR_NONE == err)
1292                         g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1293                 else
1294                         g_print("* Error : %d\n", err);
1295                 break;
1296         case 's': /* Setting > Set extra preview stream format */
1297                 g_print("* Set extra preview stream format\n");
1298
1299                 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1300                 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1301                 flush_stdin();
1302
1303                 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1304                         stream_id, pixel_format, width, height, fps);
1305                 if (err != CAMERA_ERROR_NONE) {
1306                         g_print("* Set Error : 0x%x\n", err);
1307                         break;
1308                 }
1309
1310                 pixel_format = width = height = fps = -1;
1311
1312                 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1313                         stream_id, &pixel_format, &width, &height, &fps);
1314                 if (err != CAMERA_ERROR_NONE) {
1315                         g_print("* Get Error : 0x%x\n", err);
1316                         break;
1317                 }
1318
1319                 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1320                         stream_id, pixel_format, width, height, fps);
1321                 break;
1322         case 'B': /* Setting > Set extra preview bitrate */
1323                 g_print("* Set extra preview bitrate\n");
1324                 g_print("\tstream_id : ");
1325                 err = scanf("%d", &stream_id);
1326                 flush_stdin();
1327
1328                 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1329                 if (err != CAMERA_ERROR_NONE) {
1330                         g_print("\tFailed to get bitrate for stream_id[%d]\n", stream_id);
1331                         break;
1332                 }
1333
1334                 g_print("\tCurrent bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1335
1336                 g_print("\tSet bitrate(bps) : ");
1337                 err = scanf("%d", &bitrate);
1338                 flush_stdin();
1339
1340                 err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
1341                 if (err != CAMERA_ERROR_NONE) {
1342                         g_print("* Set Error : 0x%x\n", err);
1343                         break;
1344                 }
1345
1346                 bitrate = -1;
1347
1348                 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1349                 if (err != CAMERA_ERROR_NONE) {
1350                         g_print("* Get Error : 0x%x\n", err);
1351                         break;
1352                 }
1353
1354                 g_print("\tResult bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1355                 break;
1356         case 'V': /* Setting > Set extra preview GOP interval */
1357                 g_print("* Set extra preview GOP interval\n");
1358                 g_print("\tstream_id : ");
1359                 err = scanf("%d", &stream_id);
1360                 flush_stdin();
1361
1362                 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1363                 if (err != CAMERA_ERROR_NONE) {
1364                         g_print("\tFailed to get GOP interval for stream_id[%d]\n", stream_id);
1365                         break;
1366                 }
1367
1368                 g_print("\tCurrent GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1369
1370                 g_print("\tSet GOP interval(ms) : ");
1371                 err = scanf("%d", &interval);
1372                 flush_stdin();
1373
1374                 err = camera_attr_set_extra_preview_gop_interval(hcamcorder->camera, stream_id, interval);
1375                 if (err != CAMERA_ERROR_NONE) {
1376                         g_print("* Set Error : 0x%x\n", err);
1377                         break;
1378                 }
1379
1380                 interval = -1;
1381
1382                 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1383                 if (err != CAMERA_ERROR_NONE) {
1384                         g_print("* Get Error : 0x%x\n", err);
1385                         break;
1386                 }
1387
1388                 g_print("\tResult GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1389                 break;
1390         case 'D': /* Setting > Request codec config */
1391                 g_print("* Request codec config\n");
1392
1393                 err = camera_request_codec_config(hcamcorder->camera);
1394                 if (err != CAMERA_ERROR_NONE) {
1395                         g_print("\tFailed to request codec config\n");
1396                         break;
1397                 }
1398                 break;
1399                 /* Display / Filter setting */
1400         case 'v': /* Display visible */
1401                 g_print("* Display visible setting !\n");
1402                 g_print("\n Select Display visible \n");
1403                 for (i = 0 ; i < 2 ; i++)
1404                         g_print("\t %d. %s\n", i, visible_mode[i]);
1405                 err = scanf("%d", &idx);
1406                 flush_stdin();
1407                 if (idx == 0 || idx == 1)
1408                         bret = camera_set_display_visible(hcamcorder->camera, idx);
1409                 else
1410                         g_print("invalid input %d", idx);
1411                 break;
1412         case 'o': /* Setting > Display Mode */
1413                 g_print("* Display mode!\n");
1414                 for (i = 0 ; i < 5 ; i++)
1415                         g_print("%d. %s\n", i, display_mode[i]);
1416                 err = scanf("%d", &idx);
1417                 flush_stdin();
1418                 bret =  camera_set_display_mode(hcamcorder->camera, idx);
1419                 break;
1420         case 'y': /* Setting > Rotate Display */
1421                 g_print("\n Select Rotate mode\n");
1422                 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1423                 err = scanf("%d", &idx);
1424                 flush_stdin();
1425                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1426                 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1427                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1428                 break;
1429         case 'Y': /* Setting > Flip Display */
1430                 g_print("\n Select Rotate mode\n");
1431                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1432                 err = scanf("%d", &idx);
1433                 flush_stdin();
1434                 bret = camera_set_display_flip(hcamcorder->camera, idx);
1435                 break;
1436         case 'g': /* Setting > Brightness */
1437                 g_print("*Brightness !\n");
1438                 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1439                 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1440                 err = scanf("%d", &idx);
1441                 flush_stdin();
1442                 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1443                 break;
1444         case 'c': /* Setting > Contrast */
1445                 g_print("*Contrast !\n");
1446                 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1447                 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1448                 err = scanf("%d", &idx);
1449                 flush_stdin();
1450                 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1451                 break;
1452         case 'h': /* Setting > Hue */
1453                 g_print("*Hue !\n");
1454                 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1455                 if (max >= min) {
1456                         g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1457                         err = scanf("%d", &idx);
1458                         flush_stdin();
1459                         bret = camera_attr_set_hue(hcamcorder->camera, idx);
1460                 } else {
1461                         g_print("\n Hue is not supported (%d,%d)\n", min, max);
1462                 }
1463                 break;
1464         case 'a': /* Setting > Saturation */
1465                 g_print("*Saturation !\n");
1466                 camera_attr_get_saturation_range(hcamcorder->camera, &min, &max);
1467                 if (max >= min) {
1468                         camera_attr_get_saturation(hcamcorder->camera, &idx);
1469                         g_print("\n Select Saturation min(%d)-max(%d)(current:%d) > ", min, max, idx);
1470                         err = scanf("%d", &idx);
1471                         flush_stdin();
1472                         bret = camera_attr_set_saturation(hcamcorder->camera, idx);
1473                 } else {
1474                         g_print("\n Saturation is not supported\n");
1475                 }
1476                 break;
1477         case 'A': /* Setting > Sharpness */
1478                 g_print("*Sharpness !\n");
1479                 camera_attr_get_sharpness_range(hcamcorder->camera, &min, &max);
1480                 if (max >= min) {
1481                         camera_attr_get_sharpness(hcamcorder->camera, &idx);
1482                         g_print("\n Select Sharpness min(%d)-max(%d)(current:%d) > ", min, max, idx);
1483                         err = scanf("%d", &idx);
1484                         flush_stdin();
1485                         bret = camera_attr_set_sharpness(hcamcorder->camera, idx);
1486                 } else {
1487                         g_print("\n Sharpness is not supported\n");
1488                 }
1489                 break;
1490         case 'q': /* Setting > Gain */
1491                 g_print("*Gain !\n");
1492                 camera_attr_get_gain_range(hcamcorder->camera, &min, &max);
1493                 if (max >= min) {
1494                         camera_attr_get_gain(hcamcorder->camera, &idx);
1495                         camera_attr_get_gain_step(hcamcorder->camera, &step);
1496                         g_print("\n Select Gain min(%d)-max(%d)(current:%d,step:%d) > ", min, max, idx, step);
1497                         err = scanf("%d", &idx);
1498                         flush_stdin();
1499                         bret = camera_attr_set_gain(hcamcorder->camera, idx);
1500                 } else {
1501                         g_print("\n Gain is not supported\n");
1502                 }
1503                 break;
1504         case 'w': /* Setting > White balance */
1505                 g_print("*White balance !\n");
1506                 g_print("\n Select White balance \n");
1507                 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1508                 err = scanf("%d", &idx);
1509                 flush_stdin();
1510                 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1511                 break;
1512         case 'W': /* Setting > White balance temperature */
1513                 g_print("*White balance temperature !\n");
1514                 camera_attr_get_whitebalance_temperature_range(hcamcorder->camera, &min, &max);
1515                 if (max >= min) {
1516                         camera_attr_get_whitebalance_temperature(hcamcorder->camera, &idx);
1517                         camera_attr_get_whitebalance_temperature_step(hcamcorder->camera, &step);
1518                         g_print("\n Select White balance temperature min(%d)-max(%d)(current:%d,step:%d) > ",
1519                                 min, max, idx, step);
1520                         err = scanf("%d", &idx);
1521                         flush_stdin();
1522                         bret = camera_attr_set_whitebalance_temperature(hcamcorder->camera, idx);
1523                 } else {
1524                         g_print("\n White balance temperature is not supported\n");
1525                 }
1526                 break;
1527         case 't': /* Setting > Color tone */
1528                 g_print("*Color tone !\n");
1529                 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1530                 g_print("\n Select Color tone \n");
1531                 err = scanf("%d", &idx);
1532                 flush_stdin();
1533                 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1534                 break;
1535         case 'd': /* Setting > WDR */
1536                 g_print("*WDR !\n");
1537                 g_print("\n Select WDR Mode \n");
1538                 for (i = 0 ; i < 2 ; i++)
1539                         g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1540                 err = scanf("%d", &idx);
1541                 flush_stdin();
1542                 if (idx == 1)
1543                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1544                 else if (idx == 2)
1545                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1546                 break;
1547         case 'e': /* Setting > EV program mode */
1548                 g_print("* EV program mode!\n");
1549                 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1550                 g_print("\n Select EV program mode \n");
1551                 err = scanf("%d", &idx);
1552                 flush_stdin();
1553                 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1554                 break;
1555         case 'R': /* Setting > Display ROI area */
1556                 g_print("* Set display roi area. Select x y width height \n");
1557                 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1558                 flush_stdin();
1559                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1560                 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1561                 if (CAMERA_ERROR_NONE != err)
1562                         g_print("* Error : %d\n", err);
1563
1564                 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1565                 if (CAMERA_ERROR_NONE == err)
1566                         g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1567                 else
1568                         g_print("* Error : %d\n", err);
1569                 break;
1570
1571                 /* ext. setting */
1572         case 'z': /* Setting > Strobe setting */
1573                 g_print("*Strobe Mode\n");
1574                 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1575                 g_print("\n Select Strobe Mode \n");
1576                 err = scanf("%d", &idx);
1577                 flush_stdin();
1578                 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1579                 break;
1580         case 'S': /* Setting > flash state */
1581                 g_print("*flash state\n");
1582                 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1583                 if (CAMERA_ERROR_NONE == err)
1584                         g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1585                 else
1586                         g_print("* Error : %d\n", err);
1587                 break;
1588         case 'G': /* Setting > flash brightness */
1589                 g_print("*Flash brightness !\n");
1590                 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1591                 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1592                 err = scanf("%d", &idx);
1593                 flush_stdin();
1594                 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1595                 break;
1596         case 'x': /* Setting > Capture mode ,Muitishot? */
1597                 g_print("*Select Capture mode!\n");
1598                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1599                 err = scanf("%d", &idx);
1600                 flush_stdin();
1601
1602                 switch (idx) {
1603                 case 1:
1604                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1605                         hcamcorder->is_multishot = FALSE;
1606                         camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1607                         break;
1608                 case 2:
1609                         g_print("HDR Capture mode selected\n");
1610                         hcamcorder->is_multishot = FALSE;
1611                         g_print("\nSelect HDR capture mode\n");
1612                         for (i = 0 ; i < 3 ; i++)
1613                                 g_print("\t %d. %s\n", i, hdr_mode[i]);
1614                         err = scanf("%d", &idx);
1615                         flush_stdin();
1616                         if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1617                                 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1618                         else
1619                                 g_print("invalid input %d\n", idx);
1620                         break;
1621                 default:
1622                         g_print("Wrong input, select again!!\n");
1623                         break;
1624                 }
1625                 break;
1626         case 'l': /* Setting > Face detection setting */
1627                 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1628                         g_print("* Face detect mode !\n");
1629                         for (i = 0 ; i < 2 ; i++)
1630                                 g_print("\t %d. %s \n", i, detection_mode[i]);
1631                         err = scanf("%d", &idx);
1632                         flush_stdin();
1633                         if (idx == 0)
1634                                 bret = camera_stop_face_detection(hcamcorder->camera);
1635                         else if (idx == 1)
1636                                 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1637                         else
1638                                 g_print("\n invalid input [%d]\n\n", idx);
1639                 } else {
1640                         g_print("face detection_not supported");
1641                 }
1642                 break;
1643         case 'k': /* Setting > Anti-handshake */
1644                 g_print("*Anti-handshake !\n");
1645                 g_print("\n Select Anti-handshake mode \n");
1646                 for (i = 0; i < 2; i++)
1647                         g_print("\t %d. %s\n", i, ahs_mode[i]);
1648                 err = scanf("%d", &idx);
1649                 flush_stdin();
1650                 if (idx == 0 || idx == 1)
1651                         bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1652                 else
1653                         g_print("invalid input %d\n", idx);
1654                 break;
1655         case 'K': /* Setting > Video-stabilization */
1656                 g_print("*Video-stabilization !\n");
1657                 g_print("\n Select Video-stabilization mode \n");
1658                 for (i = 0 ; i < 2 ; i++)
1659                         g_print("\t %d. %s\n", i, vs_mode[i]);
1660                 err = scanf("%d", &idx);
1661                 flush_stdin();
1662                 if (idx < 0 || idx > 1) {
1663                         g_print("invalid input %d\n", idx);
1664                         break;
1665                 }
1666
1667                 if (idx == 1) {
1668                         g_print("\n Restart preview with NV12 and 720p resolution\n");
1669                         err = camera_stop_preview(hcamcorder->camera);
1670                         g_print("stop preview result 0x%x\n", err);
1671                         camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1672                         camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1673                 }
1674
1675                 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1676
1677                 if (idx == 1) {
1678                         err = camera_start_preview(hcamcorder->camera);
1679                         if (err != CAMERA_ERROR_NONE)
1680                                 g_print("\n Restart FAILED! 0x%x\n", err);
1681                 }
1682                 break;
1683         case 'u': /* Touch AF area */
1684                 g_print("* Touch AF area !\n");
1685                 g_print("\n Input x,y,width,height \n");
1686                 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1687                 flush_stdin();
1688                 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1689                 if (err != 0)
1690                         g_print("Failed to set touch AF area.(%x)\n", err);
1691                 else
1692                         g_print("Succeed to set touch AF area.\n");
1693                 break;
1694         case 'n': /* file path */
1695                 g_print("* File path !\n");
1696                 g_print("\n Input file path to save captured data(string) : ");
1697                 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin))
1698                         g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1699                 else
1700                         g_print("\nset file path failed\n");
1701                 break;
1702         case 'm': /* media bridge */
1703                 g_print("* Media Bridge !\n");
1704                 g_print("\tUnset[0] / Set[Others] :");
1705                 err = scanf("%d", &set_bridge);
1706                 flush_stdin();
1707                 if (set_bridge) {
1708                         __release_media_bridge();
1709
1710                         err = media_bridge_create(&bridge);
1711                         err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1712                 } else {
1713                         __release_media_bridge();
1714                 }
1715                 g_print("\tresult[0x%x]\n\n", err);
1716                 break;
1717         case 'b': /* back */
1718                 hcamcorder->menu_state = MENU_STATE_MAIN;
1719                 break;
1720         default:
1721                 g_print("\t Invalid input \n");
1722                 break;
1723         }
1724
1725         g_print("\t bret : 0x%x \n", bret);
1726 }
1727
1728
1729 static void device_state_menu(gchar buf)
1730 {
1731         int ret = 0;
1732         camera_device_e device = CAMERA_DEVICE_CAMERA0;
1733         camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1734
1735         switch (buf) {
1736         case '1': /* Get device state */
1737                 while (1) {
1738                         g_print("\n\tEnter Camera Index[0~9]: ");
1739
1740                         ret = scanf("%d", (int *)&device);
1741                         flush_stdin();
1742
1743                         if (ret == EOF) {
1744                                 g_print("\n\t!!!read input error!!!\n");
1745                                 return;
1746                         }
1747
1748                         if (device < CAMERA_DEVICE_CAMERA0 ||
1749                                 device > CAMERA_DEVICE_CAMERA9) {
1750                                 g_print("\n\tinvalid input:[%d], try again...\n", device);
1751                                 continue;
1752                         }
1753
1754                         ret = camera_get_device_state(device, &device_state);
1755                         g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1756                                 device, device_state, ret);
1757                         break;
1758                 }
1759                 break;
1760         case '2': /* Add device state changed callback */
1761                 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1762                         NULL, &g_camera_device_state_changed_cb_id);
1763                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1764                 break;
1765         case '3': /* Remove device state changed callback */
1766                 if (g_camera_device_state_changed_cb_id > 0) {
1767                         ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1768                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1769                         g_camera_device_state_changed_cb_id = 0;
1770                 } else {
1771                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1772                 }
1773                 break;
1774         case 'b': /* back */
1775                 hcamcorder->menu_state = MENU_STATE_INIT;
1776                 break;
1777         default:
1778                 g_print("\n\tinvalid input[%c]\n", buf);
1779                 break;
1780         }
1781 }
1782
1783 static void device_manager_menu(gchar buf)
1784 {
1785         int ret = 0;
1786
1787         switch (buf) {
1788         case '1': /* Initialize device manager */
1789                 ret = camera_device_manager_initialize(&g_device_manager);
1790                 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1791                         g_device_manager, ret);
1792                 break;
1793         case '2': /* Foreach supported camera device */
1794                 ret = camera_device_manager_foreach_supported_device(g_device_manager, _camera_supported_device_cb, NULL);
1795                 if (ret != CAMERA_ERROR_NONE) {
1796                         g_print("\n\tGet device list failed[0x%x]\n", ret);
1797                         return;
1798                 }
1799                 break;
1800         case '3': /* Add device connection changed callback */
1801                 ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
1802                         _camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
1803                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1804                 break;
1805         case '4': /* Remove device connection changed callback */
1806                 if (g_camera_device_connection_changed_cb_id > 0) {
1807                         ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
1808                                 g_camera_device_connection_changed_cb_id);
1809                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1810                         g_camera_device_connection_changed_cb_id = 0;
1811                 } else {
1812                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
1813                 }
1814                 break;
1815         case '9': /* Deinitialize device manager */
1816                 ret = camera_device_manager_deinitialize(g_device_manager);
1817                 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1818                         g_device_manager, ret);
1819                 g_device_manager = NULL;
1820                 break;
1821         case 'b': /* back */
1822                 hcamcorder->menu_state = MENU_STATE_INIT;
1823                 break;
1824         default:
1825                 g_print("\n\tinvalid input[%c]\n", buf);
1826                 break;
1827         }
1828 }
1829
1830
1831 /**
1832  * This function is to execute command.
1833  *
1834  * @param   channel [in]    1st parameter
1835  *
1836  * @return  This function returns TRUE/FALSE
1837  * @remark
1838  * @see
1839  */
1840 gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1841 {
1842         gchar *buf = NULL;
1843         gsize read_size;
1844         GError *g_error = NULL;
1845
1846         g_print("\n\tENTER\n");
1847
1848         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1849         if (g_error) {
1850                 g_print("\n\tg_io_channel_read_chars error\n");
1851                 g_error_free(g_error);
1852                 g_error = NULL;
1853         }
1854
1855         if (buf) {
1856                 g_strstrip(buf);
1857
1858                 switch (hcamcorder->menu_state) {
1859                 case MENU_STATE_INIT:
1860                         if (!mode_change(buf[0]))
1861                                 return FALSE;
1862                         break;
1863                 case MENU_STATE_MAIN:
1864                         main_menu(buf[0]);
1865                         break;
1866                 case MENU_STATE_MAIN_SETTING:
1867                         setting_menu(buf[0]);
1868                         break;
1869                 case MENU_STATE_DEVICE_STATE:
1870                         device_state_menu(buf[0]);
1871                         break;
1872                 case MENU_STATE_DEVICE_MANAGER:
1873                         device_manager_menu(buf[0]);
1874                         break;
1875                 default:
1876                         break;
1877                 }
1878
1879                 g_free(buf);
1880                 buf = NULL;
1881
1882                 print_menu();
1883         } else {
1884                 g_print("\n\tNo read input\n");
1885         }
1886
1887         return TRUE;
1888 }
1889
1890
1891 cam_handle_t *init_handle()
1892 {
1893         hcamcorder = (cam_handle_t *)g_malloc0(sizeof(cam_handle_t));
1894
1895         hcamcorder->is_multishot =  FALSE;
1896         hcamcorder->stillshot_count = 0;
1897         hcamcorder->multishot_count = 0;
1898         snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1899         hcamcorder->menu_state = MENU_STATE_INIT;
1900
1901         return hcamcorder;
1902 }
1903
1904
1905 static void __enable_extra_preview_and_callback(camera_h camera)
1906 {
1907         int err = 0;
1908         int stream_id = 0;
1909         int width = 0;
1910         int height = 0;
1911         int fps = 0;
1912         int pixel_format = 0;
1913         int device = 0;
1914
1915         g_print("\n\t- Format list");
1916         g_print("\n\t0:NV12, 1:NV12T, 2:NV16, 3:NV21, 4:YUYV, 5:UYVY, 6:422P, 7:I420, 8:YV12, 9:RGB565, 10:RGB888");
1917         g_print("\n\t11:RGBA, 12:ARGB, 13:ENCODED(JPEG), 14:INTERLEAVED_JPEG_UYVY, 15:H264, 16:INVZ, 17:MJPEG, 18:VP8, 19:VP9");
1918         g_print("\n\tSet extra preview format[stream_id width height fps format] : ");
1919
1920         err = scanf("%d %d %d %d %d", &stream_id, &width, &height, &fps, &pixel_format);
1921         flush_stdin();
1922
1923         err = camera_set_extra_preview_stream_format(camera, stream_id, pixel_format, width, height, fps);
1924         if (err != CAMERA_ERROR_NONE) {
1925                 g_print("\n\tcamera_set_extra_preview_stream_format failed[0x%x]\n", err);
1926                 return;
1927         }
1928
1929         err = camera_set_extra_preview_cb(camera, _camera_extra_preview_cb, camera);
1930         if (err != CAMERA_ERROR_NONE) {
1931                 g_print("\n\tcamera_set_extra_preview_cb failed[0x%x]\n", err);
1932                 return;
1933         }
1934
1935         g_print("\n\t## for MM_CAMCORDER_EXTRA_PREVIEW_MODE_PIPELINE_ELEMENT ##\n");
1936         g_print("\n\tSet device for extra preview[0 ~ 9] : ");
1937         err = scanf("%d", &device);
1938         flush_stdin();
1939
1940         err = camera_set_extra_preview_device(hcamcorder->camera, 0, device);
1941         g_print("\n\tcamera_set_extra_preview_device(device:%d) 0x%x\n", device, err);
1942
1943         g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1944         err = scanf("%d", &g_camera_extra_preview_cb_dump);
1945         flush_stdin();
1946 }
1947
1948
1949 /**
1950  * This function is to change camcorder mode.
1951  *
1952  * @param   buf    [in]    user input
1953  *
1954  * @return  This function returns TRUE/FALSE
1955  * @remark
1956  * @see     other functions
1957  */
1958 static gboolean mode_change(gchar buf)
1959 {
1960         int err = 0;
1961         int camera_type = 0;
1962         int enable_extra_preview = 0;
1963
1964         switch (buf) {
1965         case '1':
1966                 while (1) {
1967                         g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1968                         err = scanf("%d", &camera_type);
1969                         flush_stdin();
1970                         if (err == EOF) {
1971                                 g_print("\t!!!read input error!!!\n");
1972                                 continue;
1973                         }
1974
1975                         if (camera_type != 0 && camera_type != 1) {
1976                                 g_print("\t Invalid camera type(%d)\n", camera_type);
1977                                 continue;
1978                         }
1979
1980                         g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1981                         err = scanf("%d", (int *)&camera_device);
1982                         flush_stdin();
1983                         if (err == EOF) {
1984                                 g_print("\t!!!read input error!!!\n");
1985                                 continue;
1986                         }
1987
1988                         if (camera_device < 0 || camera_device > 9) {
1989                                 g_print("\t Invalid camera device(%d)\n", camera_device);
1990                                 continue;
1991                         }
1992
1993                         hcamcorder->type = camera_device;
1994                         break;
1995                 }
1996                 break;
1997         case '2':
1998                 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1999                 return TRUE;
2000         case '3':
2001                 hcamcorder->menu_state = MENU_STATE_DEVICE_MANAGER;
2002                 return TRUE;
2003         case 'q':
2004                 quit_test();
2005                 return FALSE;
2006         default:
2007                 g_print("\t Invalid command(%c)\n", buf);
2008                 return TRUE;
2009         }
2010
2011         g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
2012
2013         gettimeofday(&previous_time, NULL);
2014
2015         if (camera_type)
2016                 err = camera_create_network(camera_device, &hcamcorder->camera);
2017         else
2018                 err = camera_create(camera_device, &hcamcorder->camera);
2019
2020         if (err != 0) {
2021                 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
2022                 return TRUE;
2023         }
2024
2025         set_display(hcamcorder);
2026
2027         camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
2028         camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
2029         camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
2030         camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
2031         camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
2032         /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
2033         /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
2034         /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
2035
2036         if (_camera_set_preview_cb(PREVIEW_CB_TYPE_NORMAL) != CAMERA_ERROR_NONE)
2037                 g_print("\n\tpreview cb failed\n");
2038
2039         if (camera_is_supported_extra_preview(hcamcorder->camera)) {
2040                 g_print("\n\tEnable extra preview callback - NO[0], YES[Others] : ");
2041                 err = scanf("%d", (int *)&enable_extra_preview);
2042                 flush_stdin();
2043
2044                 if (enable_extra_preview)
2045                         __enable_extra_preview_and_callback(hcamcorder->camera);
2046         }
2047
2048         camera_start_preview(hcamcorder->camera);
2049
2050         gettimeofday(&current_time, NULL);
2051         timersub(&current_time, &previous_time, &result_time);
2052
2053         g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
2054
2055         hcamcorder->menu_state = MENU_STATE_MAIN;
2056
2057         return TRUE;
2058 }
2059 /*EOF*/