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