4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /*=======================================================================================
24 =======================================================================================*/
30 #include <camera_internal.h>
32 #include <Elementary.h>
33 #include <appcore-efl.h>
34 #include <tbm_surface.h>
35 #include <media_bridge_internal.h>
37 /*-----------------------------------------------------------------------
38 | GLOBAL VARIABLE DEFINITIONS: |
39 -----------------------------------------------------------------------*/
40 #define EXPORT_API __attribute__((__visibility__("default")))
45 #define PACKAGE "camera_test"
48 static int app_create(void *data);
49 static int app_terminate(void *data);
57 typedef struct _appdata appdata;
59 static struct appcore_ops ops = {
61 .terminate = app_terminate,
65 static GIOChannel *stdin_channel;
66 static camera_device_e camera_device;
68 static int g_camera_device_state_changed_cb_id;
69 static int g_camera_device_connection_changed_cb_id;
70 static int g_camera_preview_cb_dump;
71 static int g_camera_extra_preview_cb_dump;
72 static int g_camera_mp_preview_cb_dump;
74 static struct timeval previous_time;
75 static struct timeval current_time;
76 static struct timeval result_time;
78 static media_bridge_h bridge;
80 /*-----------------------------------------------------------------------
81 | GLOBAL CONSTANT DEFINITIONS: |
82 -----------------------------------------------------------------------*/
85 /*-----------------------------------------------------------------------
86 | IMPORTED VARIABLE DECLARATIONS: |
87 -----------------------------------------------------------------------*/
90 /*-----------------------------------------------------------------------
91 | IMPORTED FUNCTION DECLARATIONS: |
92 -----------------------------------------------------------------------*/
95 /*-----------------------------------------------------------------------
97 -----------------------------------------------------------------------*/
98 #define DEFAULT_FILE_PATH "/home/owner/media"
99 #define PREVIEW_CB_DUMP_FILE_NAME "preview.data"
100 #define EXTRA_PREVIEW_CB_DUMP_FILE_NAME "extra_preview.data"
101 #define MP_PREVIEW_CB_DUMP_FILE_NAME "mp_preview.data"
102 #define MAX_FILE_NAME_LENGTH 256
103 #define MAX_FILE_PATH_LENGTH (MAX_FILE_NAME_LENGTH - 20)
105 #define CHECK_MM_ERROR(expr) \
110 g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
117 #define SAFE_FREE(x) \
124 #define SENSOR_WHITEBALANCE_NUM 10
125 #define SENSOR_COLOR_TONE_NUM 31
126 #define SENSOR_FLIP_NUM 4
127 #define SENSOR_PROGRAM_MODE_NUM 15
128 #define SENSOR_FOCUS_NUM 6
129 #define SENSOR_INPUT_ROTATION 4
130 #define SENSOR_AF_SCAN_NUM 4
131 #define SENSOR_ISO_NUM 8
132 #define SENSOR_EXPOSURE_NUM 9
133 #define SENSOR_IMAGE_FORMAT 9
136 /*-----------------------------------------------------------------------
137 | LOCAL CONSTANT DEFINITIONS: |
138 -----------------------------------------------------------------------*/
140 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
141 MODE_AUDIO, /* audio recording*/
148 MENU_STATE_MAIN_SETTING,
149 MENU_STATE_DEVICE_STATE,
150 MENU_STATE_DEVICE_LIST,
154 /*-----------------------------------------------------------------------
155 | LOCAL DATA TYPE DEFINITIONS: |
156 -----------------------------------------------------------------------*/
157 typedef struct _cam_handle {
160 int is_multishot; /* flag for multishot mode */
161 int stillshot_count; /* stillshot count */
162 int multishot_count; /* multishot count */
163 char file_path[MAX_FILE_PATH_LENGTH]; /* file path for captured data */
165 unsigned long long elapsed_time;
175 camera_attr_exposure_mode_e mode;
180 camera_attr_iso_e mode;
185 /*---------------------------------------------------------------------------
186 | LOCAL VARIABLE DEFINITIONS: |
187 ---------------------------------------------------------------------------*/
188 static cam_handle_t *hcamcorder;
189 static camera_device_manager_h g_device_manager;
191 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
204 const char *ct[SENSOR_COLOR_TONE_NUM] = {
230 "SELECTVE_COLOR_RED",
231 "SELECTVE_COLOR_GREEN",
232 "SELECTVE_COLOR_BLUE",
233 "SELECTVE_COLOR_YELLOW",
234 "SELECTVE_COLOR_RED_YELLOW",
238 const char *sensor_flip[SENSOR_FLIP_NUM] = {
245 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
263 const char *focus_mode[SENSOR_FOCUS_NUM] = {
272 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
279 const char *iso_mode[SENSOR_ISO_NUM] = {
290 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
298 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
310 const char *face_zoom_mode[] = {
315 const char *display_mode[] = {
317 "Original Size mode",
319 "Cropped Full Screen mode",
323 const char *capture_sound[] = {
329 const char *rotate_mode[] = {
336 const char* strobe_mode[] = {
340 "Strobe RedEyeReduction",
342 "Strobe FrontCurtain",
343 "Strobe RearCurtain",
347 const char *detection_mode[2] = {
348 "Face Detection OFF",
352 const char *wdr_mode[] = {
358 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
365 const char *hdr_mode[] = {
368 "HDR ON and Original",
371 const char *ahs_mode[] = {
372 "Anti-handshake OFF",
374 "Anti-handshake AUTO",
375 "Anti-handshake MOVIE",
378 const char *vs_mode[] = {
379 "Video-stabilization OFF",
380 "Video-stabilization ON",
383 const char *visible_mode[] = {
388 const char *facing_direction[] = {
394 /*---------------------------------------------------------------------------
395 | LOCAL FUNCTION PROTOTYPES: |
396 ---------------------------------------------------------------------------*/
397 static void print_menu();
398 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data);
399 static gboolean mode_change(gchar buf);
400 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
403 static void __release_media_bridge()
406 media_bridge_unset_source(bridge); /* not mandatory, it will be done in media_bridge_destroy() */
407 media_bridge_destroy(bridge);
412 static inline void flush_stdin()
415 while ((ch = getchar()) != EOF && ch != '\n');
418 static gboolean _release_idle_event_callback(void *data)
420 g_print("destroy camera handle\n\n");
422 camera_destroy(hcamcorder->camera);
423 hcamcorder->camera = NULL;
424 hcamcorder->menu_state = MENU_STATE_INIT;
431 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
433 g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
436 case CAMERA_ERROR_RESOURCE_CONFLICT:
437 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
439 case CAMERA_ERROR_SECURITY_RESTRICTED:
440 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
442 case CAMERA_ERROR_SERVICE_DISCONNECTED:
443 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
444 g_idle_add_full(G_PRIORITY_DEFAULT,
445 (GSourceFunc)_release_idle_event_callback,
455 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
457 g_print("\n\tcamera state changed %d -> %d\n", previous, current);
462 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
464 g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
469 static void _camera_device_connection_changed_cb(camera_device_s *device, bool is_connected, void *user_data)
472 g_print("NULL list");
476 g_print("\n\tcamera device changed[is_connected:%d][Type:%d,index:%d,name:%s,id:%s,exstreamnum:%d]\n",
477 is_connected, device->type, device->index, device->name, device->id, device->extra_stream_num);
482 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
484 g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
485 previous, current, policy);
490 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
492 g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
497 static void _dump_preview_data(camera_preview_data_s *frame, const char *file_name)
499 char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
503 g_print("\n[DUMP_PREVIEW_DATA] NULL frame\n");
507 snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
509 fp = fopen(dump_path, "a");
511 g_print("\n[DUMP_PREVIEW_DATA] file[%s] open failed\n", dump_path);
515 switch (frame->format) {
516 case CAMERA_PIXEL_FORMAT_RGBA:
518 case CAMERA_PIXEL_FORMAT_ARGB:
519 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
521 case CAMERA_PIXEL_FORMAT_INVZ:
522 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
524 case CAMERA_PIXEL_FORMAT_H264:
526 case CAMERA_PIXEL_FORMAT_MJPEG:
528 case CAMERA_PIXEL_FORMAT_VP8:
530 case CAMERA_PIXEL_FORMAT_VP9:
531 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
534 switch (frame->num_of_planes) {
536 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
539 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
540 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
543 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
544 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
545 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
553 g_print("[DUMP_PREVIEW_DATA] file[%s] write done\n", dump_path);
558 static void _camera_print_preview_info(camera_preview_data_s *frame)
561 g_print("\n[PREVIEW_CB] NULL frame!\n");
565 g_print("format[%d] res[%dx%d] num plane[%d] ",
566 frame->format, frame->width, frame->height, frame->num_of_planes);
568 if (frame->num_of_planes == 1) {
569 g_print("size [%d]\n",
570 frame->data.single_plane.size);
571 } else if (frame->num_of_planes == 2) {
572 g_print("size Y[%d] UV[%d]\n",
573 frame->data.double_plane.y_size,
574 frame->data.double_plane.uv_size);
575 } else if (frame->num_of_planes == 3) {
576 g_print("size Y[%d] U[%d] V[%d]\n",
577 frame->data.triple_plane.y_size,
578 frame->data.triple_plane.u_size,
579 frame->data.triple_plane.v_size);
583 static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
586 g_print("\n[PREVIEW_CB] NULL frame!\n");
590 g_print("[PREVIEW_CB] preview callback - ");
592 _camera_print_preview_info(frame);
594 if (g_camera_preview_cb_dump)
595 _dump_preview_data(frame, PREVIEW_CB_DUMP_FILE_NAME);
598 static void _camera_extra_preview_cb(camera_preview_data_s *frame, int stream_id, void *user_data)
601 g_print("\n[PREVIEW_CB] NULL frame!\n");
605 g_print("[EXTRA_PREVIEW_CB][stream_id:%d] preview callback - ", stream_id);
607 _camera_print_preview_info(frame);
609 if (g_camera_extra_preview_cb_dump)
610 _dump_preview_data(frame, EXTRA_PREVIEW_CB_DUMP_FILE_NAME);
614 static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
620 char mp_dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
622 media_format_h fmt = NULL;
623 media_format_mimetype_e type = MEDIA_FORMAT_I420;
624 tbm_surface_h surface = NULL;
625 tbm_surface_info_s s_info;
628 g_print("\n[MP_PREVIEW_CB] NULL packet!\n");
632 ret = media_packet_get_format(pkt, &fmt);
633 if (ret != MEDIA_PACKET_ERROR_NONE) {
634 g_print("\n[MP_PREVIEW_CB] get media format failed[0x%x]", ret);
635 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
638 ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
639 if (ret != MEDIA_FORMAT_ERROR_NONE) {
640 g_print("\n[MP_PREVIEW_CB] get video info failed[0x%x]", ret);
641 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
644 g_print("[MP_PREVIEW_CB] media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height);
646 ret = media_packet_get_tbm_surface(pkt, &surface);
647 if (ret != MEDIA_PACKET_ERROR_NONE) {
648 g_print("\n[MP_PREVIEW_CB] get tbm surface failed[0x%x] ====\n", ret);
649 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
652 ret = tbm_surface_get_info(surface, &s_info);
653 if (ret != TBM_SURFACE_ERROR_NONE) {
654 g_print("\n[MP_PREVIEW_CB] get tbm surface info failed[0x%x] ====\n", ret);
655 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
658 g_print(" tbm surface [%dx%d], total size[%u]\n",
659 s_info.width, s_info.height, s_info.size);
661 if (g_camera_mp_preview_cb_dump) {
662 snprintf(mp_dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, MP_PREVIEW_CB_DUMP_FILE_NAME);
663 fp = fopen(mp_dump_path, "a");
665 g_print("\n[MP_PREVIEW_CB] file[%s] open failed ====\n", mp_dump_path);
666 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
670 for (i = 0 ; i < s_info.num_planes ; i++) {
671 g_print(" plane[%d][%p] stride[%u] size[%u]\n",
672 i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
674 fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
677 _MEDIA_PACKET_PREVIEW_CB_OUT:
681 media_packet_unref(pkt);
685 static bool preview_resolution_cb(int width, int height, void *user_data)
687 resolution_stack *data = (resolution_stack *)user_data;
690 g_print("NULL data\n");
694 data->width[data->count] = width;
695 data->height[data->count] = height;
697 g_print("\t%d. %dx%d\n", data->count, width, height);
704 static bool capture_resolution_test_cb(int width, int height, void *user_data)
706 resolution_stack *data = (resolution_stack *)user_data;
709 g_print("NULL data\n");
713 data->width[data->count] = width;
714 data->height[data->count] = height;
716 g_print("\t%d. %dx%d\n", data->count, width, height);
723 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
725 g_print("\t%d. %s\n", mode, af_scan[mode]);
729 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
731 exposure_stack *data = (exposure_stack *)user_data;
734 g_print("NULL data\n");
741 g_print("\t%d. %s\n", mode, exposure_mode[mode]);
745 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
747 g_print("\t%d. %s\n", mode, iso_mode[mode]);
751 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
753 g_print("\t%d. %s\n", mode, camera_rotation[mode]);
757 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
759 g_print("\t%d. %s\n", mode, sensor_flip[mode]);
763 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
765 g_print("\t%d. %s\n", mode, image_fmt[mode]);
769 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
771 g_print("\t%d. %s\n", mode, wb[mode]);
775 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
777 g_print("\t%d. %s\n", mode, ct[mode]);
781 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
783 g_print("\t%d. %s\n", mode, program_mode[mode]);
787 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
789 g_print("\t%d. %s\n", mode, strobe_mode[mode]);
793 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
795 g_print("\tface detected!! - count %d\n", count);
798 for (i = 0 ; i < count ; i++)
799 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
804 static void _file_write(char *path, void *data, int size)
808 if (!path || !data || size <= 0) {
809 g_print("\n\tERROR %p %p %d\n", path, data, size);
813 fp = fopen(path, "w");
815 g_print("\n\topen success [%s]\n", path);
816 if (fwrite(data, size, 1, fp) != 1)
817 g_print("\n\twrite error! errno %d\n", errno);
819 g_print("\n\twrite success [%s]\n", path);
824 g_print("\n\topen error! [%s], errno %d\n", path, errno);
830 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
832 char m_filename[MAX_FILE_NAME_LENGTH];
836 if (hcamcorder->is_multishot) {
837 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
838 hcamcorder->file_path, hcamcorder->multishot_count++);
840 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
841 hcamcorder->file_path, hcamcorder->stillshot_count++);
844 _file_write(m_filename, image->data, image->size);
850 static void capture_completed_cb(void *user_data)
852 camera_start_preview(hcamcorder->camera);
857 static void print_menu()
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 List\n");
867 g_print("\t 'q' Exit\n");
868 g_print("\t=======================================\n");
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");
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");
894 case MENU_STATE_DEVICE_LIST:
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' Get camera device list\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");
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' Picture format \n");
926 g_print("\t 'E' EXIF orientation \n");
927 g_print("\t 'F' Get facing direction of camera module\n");
928 g_print("\t 's' Extra preview stream format\n");
929 g_print("\t 'B' Extra preview bitrate\n");
930 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
931 g_print("\t 'v' Visible \n");
932 g_print("\t 'o' Output mode \n");
933 g_print("\t 'y' Rotate display \n");
934 g_print("\t 'Y' Flip display \n");
935 g_print("\t 'g' Brightness \n");
936 g_print("\t 'c' Contrast \n");
937 g_print("\t 'h' Hue \n");
938 g_print("\t 'w' White balance \n");
939 g_print("\t 't' Color tone \n");
940 g_print("\t 'd' WDR \n");
941 g_print("\t 'e' EV program mode \n");
942 g_print("\t 'R' Display ROI area \n");
943 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
944 g_print("\t 'z' Strobe (Flash) \n");
945 g_print("\t 'S' Strobe (Flash) state\n");
946 g_print("\t 'G' Strobe (Flash) brightness\n");
947 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
948 g_print("\t 'l' Face detection \n");
949 g_print("\t 'k' Anti-handshake \n");
950 g_print("\t 'K' Video-stabilization \n");
951 g_print("\t 'u' Touch AF area \n");
952 g_print("\t 'n' Set file path to write captured image\n");
953 g_print("\t 'm' Set media bridge\n");
954 g_print("\t 'b' back\n");
955 g_print("\t=======================================\n");
958 g_print("\n\tunknow menu state !!\n");
962 g_print("\tCommand >> ");
968 static void main_menu(gchar buf)
976 case '1': /* Capture */
977 hcamcorder->is_multishot = FALSE;
978 camera_attr_set_image_quality(hcamcorder->camera, 100);
979 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
980 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
982 case '2': /* multishot Capture */
983 g_print("multishot capture");
984 hcamcorder->is_multishot = TRUE;
985 g_print("\n\tinput interval(ms) : ");
986 err = scanf("%d", &interval);
988 g_print("\n\tinput count : ");
989 err = scanf("%d", &count);
991 camera_attr_set_image_quality(hcamcorder->camera, 100);
992 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
993 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
995 camera_start_preview(hcamcorder->camera);
997 case '3': /* Setting */
998 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
1000 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
1001 camera_set_display_reuse_hint(hcamcorder->camera, true);
1003 camera_stop_preview(hcamcorder->camera);
1005 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
1006 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
1008 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
1010 camera_change_device(hcamcorder->camera, hcamcorder->type);
1012 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1013 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1014 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1015 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1017 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1019 camera_start_preview(hcamcorder->camera);
1022 g_print("* Preview Callback\n");
1023 g_print("\tUnset[0] / Set[Others] :");
1024 err = scanf("%d", &set_cb);
1027 g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
1028 err = scanf("%d", &g_camera_preview_cb_dump);
1030 err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
1032 err = camera_unset_preview_cb(hcamcorder->camera);
1034 g_print("\tresult[0x%x]\n\n", err);
1037 g_print("* Extra Preview Callback\n");
1038 g_print("\tUnset[0] / Set[Others] :");
1039 err = scanf("%d", &set_cb);
1042 g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1043 err = scanf("%d", &g_camera_extra_preview_cb_dump);
1045 err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
1047 err = camera_unset_extra_preview_cb(hcamcorder->camera);
1049 g_print("\tresult[0x%x]\n\n", err);
1052 g_print("* Media Packet Preview Callback\n");
1053 g_print("\tUnset[0] / Set[Others] :");
1054 err = scanf("%d", &set_cb);
1057 g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
1058 err = scanf("%d", &g_camera_mp_preview_cb_dump);
1060 err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
1062 err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
1064 g_print("\tresult[0x%x]\n\n", err);
1066 case 'b': /* back */
1067 __release_media_bridge();
1069 camera_stop_preview(hcamcorder->camera);
1070 camera_destroy(hcamcorder->camera);
1071 hcamcorder->camera = NULL;
1072 hcamcorder->menu_state = MENU_STATE_INIT;
1075 g_print("\t Invalid input \n");
1083 static void setting_menu(gchar buf)
1103 /* Camera setting */
1104 case '0': /* Setting > Preview Resolution setting */
1105 g_print("\t* Select the preview resolution!\n");
1106 resolution_stack resolution_list;
1107 resolution_list.count = 0;
1109 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1110 preview_resolution_cb, &resolution_list);
1112 g_print("\tCommand >> ");
1114 err = scanf("%d", &idx);
1116 if (resolution_list.count > idx && idx >= 0) {
1117 g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1118 resolution_list.width[idx], resolution_list.height[idx]);
1120 result = camera_set_preview_resolution(hcamcorder->camera,
1121 resolution_list.width[idx], resolution_list.height[idx]);
1123 g_print("\tInvalid command [%d]\n", idx);
1126 resolution_list.count = 0;
1127 if (result == CAMERA_ERROR_NONE)
1128 g_print("\tPASS\n");
1130 g_print("\tFAIL\n");
1132 case '1': /* Setting > Capture Resolution setting */
1133 g_print("\t* Select the preview resolution!\n");
1134 resolution_list.count = 0;
1136 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1137 capture_resolution_test_cb, &resolution_list);
1139 g_print("\tCommand > ");
1141 err = scanf("%d", &idx);
1143 if (resolution_list.count > idx && idx >= 0) {
1144 g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1145 resolution_list.width[idx], resolution_list.height[idx]);
1147 result = camera_set_capture_resolution(hcamcorder->camera,
1148 resolution_list.width[idx], resolution_list.height[idx]);
1150 g_print("\tInvalid command [%d]\n", idx);
1153 resolution_list.count = 0;
1154 if (result == CAMERA_ERROR_NONE)
1155 g_print("\tPASS\n");
1157 g_print("\tFAIL\n");
1159 case '2': /* Setting > Digital zoom level */
1160 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1162 g_print("\tDigital Zoom Not supported\n");
1164 g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1165 err = scanf("%d", &idx);
1167 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1170 case '3': /* Setting > AF mode */
1171 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1172 err = scanf("%d", &idx);
1176 camera_start_focusing(hcamcorder->camera, 0);
1179 camera_cancel_focusing(hcamcorder->camera);
1182 g_print("\tInvalid command [%d]\n", idx);
1186 case '4': /* Setting > AF scan range */
1187 g_print("\t* AF scan range !\n");
1188 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1189 g_print("\tCommand > ");
1190 err = scanf("%d", &idx);
1192 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1194 case '5': /* Setting > Exposure mode */
1195 g_print("* Exposure mode!\n");
1196 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1197 g_print("\n Select Exposure mode \n");
1198 err = scanf("%d", &idx);
1200 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1203 case '6': /* Setting > Exposure value */
1204 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1206 g_print("Not supported !! \n");
1208 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
1209 err = scanf("%d", &idx);
1211 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1214 case '7': /* Setting > F number */
1215 g_print("Not supported !! \n");
1217 case '8': /* Setting > Display reuse hint */
1219 bool reuse_hint = false;
1221 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1222 if (err != CAMERA_ERROR_NONE) {
1223 g_print("failed to get display reuse hint 0x%x\n", err);
1227 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1228 reuse_hint = !reuse_hint;
1229 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1230 g_print("set display reuse hint result : 0x%x\n", err);
1233 case '9': /* Setting > Manual focus */
1234 g_print("*Manual focus !\n");
1235 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1237 g_print("\n\tManual focus is NOT SUPPORTED\n");
1240 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1241 g_print("\tCurrent focus level (%d)\n", idx);
1242 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1243 err = scanf("%d", &idx);
1245 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1247 if (bret == CAMERA_ERROR_NONE) {
1248 bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1249 g_print("\tfocus level[%d] after set\n", idx);
1251 g_print("\tset focus level failed[0x%x]\n", bret);
1254 case 'i': /* Setting > ISO */
1255 g_print("*ISO !\n");
1256 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1257 err = scanf("%d", &idx);
1259 bret = camera_attr_set_iso(hcamcorder->camera, idx);
1261 case 'r': /* Setting > Rotate camera input when recording */
1262 g_print("*Rotate camera input\n");
1263 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1264 err = scanf("%d", &idx);
1266 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1267 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1268 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1270 case 'f': /* Setting > Flip camera input */
1271 g_print("*Flip camera input\n");
1272 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1273 err = scanf("%d", &idx);
1275 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1276 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1277 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1279 case 'j': /* Setting > Jpeg quality */
1280 g_print("*Jpeg quality !\n");
1281 g_print("\n Select Jpeg quality \n");
1282 err = scanf("%d", &idx);
1284 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1286 case 'p': /* Setting > Picture format */
1287 g_print("* Picture format!\n");
1288 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1289 err = scanf("%d", &idx);
1291 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1292 bret = camera_set_preview_format(hcamcorder->camera, idx);
1293 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1295 case 'E': /* Setting > EXIF orientation */
1296 g_print("* EXIF Orientation\n");
1297 g_print("\t 1. TOP_LEFT\n");
1298 g_print("\t 2. TOP_RIGHT(flipped)\n");
1299 g_print("\t 3. BOTTOM_RIGHT\n");
1300 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1301 g_print("\t 5. LEFT_TOP(flipped)\n");
1302 g_print("\t 6. RIGHT_TOP\n");
1303 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1304 g_print("\t 8. LEFT_BOTTOM\n");
1305 err = scanf("%d", &idx);
1307 if (idx < 1 || idx > 8)
1308 g_print("Wrong INPUT[%d]!! \n", idx);
1310 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1312 case 'F': /* Setting > Get Facing direction */
1313 g_print("* Get facing direction of camera module\n");
1314 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1315 if (CAMERA_ERROR_NONE == err)
1316 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1318 g_print("* Error : %d\n", err);
1320 case 's': /* Setting > Set extra preview stream format */
1321 g_print("* Set extra preview stream format\n");
1323 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1324 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1327 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1328 stream_id, pixel_format, width, height, fps);
1329 if (err != CAMERA_ERROR_NONE) {
1330 g_print("* Set Error : 0x%x\n", err);
1334 pixel_format = width = height = fps = -1;
1336 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1337 stream_id, &pixel_format, &width, &height, &fps);
1338 if (err != CAMERA_ERROR_NONE) {
1339 g_print("* Get Error : 0x%x\n", err);
1343 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1344 stream_id, pixel_format, width, height, fps);
1346 case 'B': /* Setting > Set extra preview bitrate */
1347 g_print("* Set extra preview bitrate\n");
1349 g_print("\tstream_id,bitrate : ");
1350 err = scanf("%d,%d", &stream_id, &bitrate);
1353 err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
1354 if (err != CAMERA_ERROR_NONE) {
1355 g_print("* Set Error : 0x%x\n", err);
1361 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1362 if (err != CAMERA_ERROR_NONE) {
1363 g_print("* Get Error : 0x%x\n", err);
1367 g_print("\tGet stream_id[%d],bitrate[%d]\n", stream_id, bitrate);
1369 /* Display / Filter setting */
1370 case 'v': /* Display visible */
1371 g_print("* Display visible setting !\n");
1372 g_print("\n Select Display visible \n");
1373 for (i = 0 ; i < 2 ; i++)
1374 g_print("\t %d. %s\n", i, visible_mode[i]);
1375 err = scanf("%d", &idx);
1377 if (idx == 0 || idx == 1)
1378 bret = camera_set_display_visible(hcamcorder->camera, idx);
1380 g_print("invalid input %d", idx);
1382 case 'o': /* Setting > Display Mode */
1383 g_print("* Display mode!\n");
1384 for (i = 0 ; i < 5 ; i++)
1385 g_print("%d. %s\n", i, display_mode[i]);
1386 err = scanf("%d", &idx);
1388 bret = camera_set_display_mode(hcamcorder->camera, idx);
1390 case 'y': /* Setting > Rotate Display */
1391 g_print("\n Select Rotate mode\n");
1392 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1393 err = scanf("%d", &idx);
1395 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1396 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1397 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1399 case 'Y': /* Setting > Flip Display */
1400 g_print("\n Select Rotate mode\n");
1401 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1402 err = scanf("%d", &idx);
1404 bret = camera_set_display_flip(hcamcorder->camera, idx);
1406 case 'g': /* Setting > Brightness */
1407 g_print("*Brightness !\n");
1408 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1409 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1410 err = scanf("%d", &idx);
1412 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1414 case 'c': /* Setting > Contrast */
1415 g_print("*Contrast !\n");
1416 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1417 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1418 err = scanf("%d", &idx);
1420 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1422 case 'h': /* Setting > Hue */
1423 g_print("*Hue !\n");
1424 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1426 g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1427 err = scanf("%d", &idx);
1429 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1431 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1434 case 'w': /* Setting > White balance */
1435 g_print("*White balance !\n");
1436 g_print("\n Select White balance \n");
1437 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1438 err = scanf("%d", &idx);
1440 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1442 case 't': /* Setting > Color tone */
1443 g_print("*Color tone !\n");
1444 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1445 g_print("\n Select Color tone \n");
1446 err = scanf("%d", &idx);
1448 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1450 case 'd': /* Setting > WDR */
1451 g_print("*WDR !\n");
1452 g_print("\n Select WDR Mode \n");
1453 for (i = 0 ; i < 2 ; i++)
1454 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1455 err = scanf("%d", &idx);
1458 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1460 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1462 case 'e': /* Setting > EV program mode */
1463 g_print("* EV program mode!\n");
1464 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1465 g_print("\n Select EV program mode \n");
1466 err = scanf("%d", &idx);
1468 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1470 case 'R': /* Setting > Display ROI area */
1471 g_print("* Set display roi area. Select x y width height \n");
1472 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1474 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1475 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1476 if (CAMERA_ERROR_NONE != err)
1477 g_print("* Error : %d\n", err);
1479 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1480 if (CAMERA_ERROR_NONE == err)
1481 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1483 g_print("* Error : %d\n", err);
1487 case 'z': /* Setting > Strobe setting */
1488 g_print("*Strobe Mode\n");
1489 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1490 g_print("\n Select Strobe Mode \n");
1491 err = scanf("%d", &idx);
1493 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1495 case 'S': /* Setting > flash state */
1496 g_print("*flash state\n");
1497 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1498 if (CAMERA_ERROR_NONE == err)
1499 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1501 g_print("* Error : %d\n", err);
1503 case 'G': /* Setting > flash brightness */
1504 g_print("*Flash brightness !\n");
1505 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1506 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1507 err = scanf("%d", &idx);
1509 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1511 case 'x': /* Setting > Capture mode ,Muitishot? */
1512 g_print("*Select Capture mode!\n");
1513 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1514 err = scanf("%d", &idx);
1519 g_print("stillshot mode selected and capture callback is set!!!!\n");
1520 hcamcorder->is_multishot = FALSE;
1521 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1524 g_print("HDR Capture mode selected\n");
1525 hcamcorder->is_multishot = FALSE;
1526 g_print("\nSelect HDR capture mode\n");
1527 for (i = 0 ; i < 3 ; i++)
1528 g_print("\t %d. %s\n", i, hdr_mode[i]);
1529 err = scanf("%d", &idx);
1531 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1532 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1534 g_print("invalid input %d\n", idx);
1537 g_print("Wrong input, select again!!\n");
1541 case 'l': /* Setting > Face detection setting */
1542 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1543 g_print("* Face detect mode !\n");
1544 for (i = 0 ; i < 2 ; i++)
1545 g_print("\t %d. %s \n", i, detection_mode[i]);
1546 err = scanf("%d", &idx);
1549 bret = camera_stop_face_detection(hcamcorder->camera);
1551 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1553 g_print("\n invalid input [%d]\n\n", idx);
1555 g_print("face detection_not supported");
1558 case 'k': /* Setting > Anti-handshake */
1559 g_print("*Anti-handshake !\n");
1560 g_print("\n Select Anti-handshake mode \n");
1561 for (i = 0; i < 2; i++)
1562 g_print("\t %d. %s\n", i, ahs_mode[i]);
1563 err = scanf("%d", &idx);
1565 if (idx == 0 || idx == 1)
1566 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1568 g_print("invalid input %d\n", idx);
1570 case 'K': /* Setting > Video-stabilization */
1571 g_print("*Video-stabilization !\n");
1572 g_print("\n Select Video-stabilization mode \n");
1573 for (i = 0 ; i < 2 ; i++)
1574 g_print("\t %d. %s\n", i, vs_mode[i]);
1575 err = scanf("%d", &idx);
1577 if (idx < 0 || idx > 1) {
1578 g_print("invalid input %d\n", idx);
1583 g_print("\n Restart preview with NV12 and 720p resolution\n");
1584 err = camera_stop_preview(hcamcorder->camera);
1585 g_print("stop preview result 0x%x\n", err);
1586 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1587 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1590 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1593 err = camera_start_preview(hcamcorder->camera);
1594 if (err != CAMERA_ERROR_NONE)
1595 g_print("\n Restart FAILED! 0x%x\n", err);
1598 case 'u': /* Touch AF area */
1599 g_print("* Touch AF area !\n");
1600 g_print("\n Input x,y,width,height \n");
1601 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1603 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1605 g_print("Failed to set touch AF area.(%x)\n", err);
1607 g_print("Succeed to set touch AF area.\n");
1609 case 'n': /* file path */
1610 g_print("* File path !\n");
1611 g_print("\n Input file path to save captured data(string) : ");
1612 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1613 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1614 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1616 g_print("\nset file path failed\n");
1619 case 'm': /* media bridge */
1620 g_print("* Media Bridge !\n");
1621 g_print("\tUnset[0] / Set[Others] :");
1622 err = scanf("%d", &set_bridge);
1625 __release_media_bridge();
1627 err = media_bridge_create(&bridge);
1628 err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1630 __release_media_bridge();
1632 g_print("\tresult[0x%x]\n\n", err);
1634 case 'b': /* back */
1635 hcamcorder->menu_state = MENU_STATE_MAIN;
1638 g_print("\t Invalid input \n");
1642 g_print("\t bret : 0x%x \n", bret);
1648 static void device_state_menu(gchar buf)
1651 camera_device_e device = CAMERA_DEVICE_CAMERA0;
1652 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1655 case '1': /* Get device state */
1657 g_print("\n\tEnter Camera Index[0~9]: ");
1659 ret = scanf("%d", (int *)&device);
1663 g_print("\n\t!!!read input error!!!\n");
1667 if (device < CAMERA_DEVICE_CAMERA0 ||
1668 device > CAMERA_DEVICE_CAMERA9) {
1669 g_print("\n\tinvalid input:[%d], try again...\n", device);
1673 ret = camera_get_device_state(device, &device_state);
1674 g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1675 device, device_state, ret);
1679 case '2': /* Add device state changed callback */
1680 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1681 NULL, &g_camera_device_state_changed_cb_id);
1682 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1684 case '3': /* Remove device state changed callback */
1685 if (g_camera_device_state_changed_cb_id > 0) {
1686 ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1687 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1688 g_camera_device_state_changed_cb_id = 0;
1690 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1693 case 'b': /* back */
1694 hcamcorder->menu_state = MENU_STATE_INIT;
1697 g_print("\n\tinvalid input[%c]\n", buf);
1704 static void device_list_menu(gchar buf)
1708 camera_device_list_s device_list;
1711 case '1': /* Initialize device manager */
1712 ret = camera_device_manager_initialize(&g_device_manager);
1713 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1714 g_device_manager, ret);
1716 case '2': /* Get device list */
1717 memset(&device_list, 0x0, sizeof(camera_device_list_s));
1718 ret = camera_device_manager_get_device_list(g_device_manager, &device_list);
1719 if (ret != CAMERA_ERROR_NONE) {
1720 g_print("\n\tGet device list failed[0x%x]\n", ret);
1724 g_print("\n\tDevice list[count:%d]\n", device_list.count);
1726 for (i = 0 ; i < device_list.count ; i++) {
1727 g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
1728 i, device_list.device[i].type, device_list.device[i].index,
1729 device_list.device[i].name, device_list.device[i].id);
1732 case '3': /* Add device connection changed callback */
1733 ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
1734 _camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
1735 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1737 case '4': /* Remove device connection changed callback */
1738 if (g_camera_device_connection_changed_cb_id > 0) {
1739 ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
1740 g_camera_device_connection_changed_cb_id);
1741 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1742 g_camera_device_connection_changed_cb_id = 0;
1744 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
1747 case '9': /* Deinitialize device manager */
1748 ret = camera_device_manager_deinitialize(g_device_manager);
1749 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1750 g_device_manager, ret);
1751 g_device_manager = NULL;
1753 case 'b': /* back */
1754 hcamcorder->menu_state = MENU_STATE_INIT;
1757 g_print("\n\tinvalid input[%c]\n", buf);
1766 * This function is to execute command.
1768 * @param channel [in] 1st parameter
1770 * @return This function returns TRUE/FALSE
1774 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1778 GError *g_error = NULL;
1780 g_print("\n\tENTER\n");
1782 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1784 g_print("\n\tg_io_channel_read_chars error\n");
1785 g_error_free(g_error);
1792 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1793 switch (hcamcorder->menu_state) {
1794 case MENU_STATE_INIT:
1795 mode_change(buf[0]);
1797 case MENU_STATE_MAIN:
1800 case MENU_STATE_MAIN_SETTING:
1801 setting_menu(buf[0]);
1803 case MENU_STATE_DEVICE_STATE:
1804 device_state_menu(buf[0]);
1806 case MENU_STATE_DEVICE_LIST:
1807 device_list_menu(buf[0]);
1818 g_print("\n\tNo read input\n");
1824 static gboolean init_handle()
1826 hcamcorder->is_multishot = FALSE;
1827 hcamcorder->stillshot_count = 0;
1828 hcamcorder->multishot_count = 0;
1829 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1830 hcamcorder->menu_state = MENU_STATE_INIT;
1831 hcamcorder->elapsed_time = 0;
1838 * This function is to change camcorder mode.
1840 * @param buf [in] user input
1842 * @return This function returns TRUE/FALSE
1844 * @see other functions
1846 static gboolean mode_change(gchar buf)
1849 int camera_type = 0;
1850 int display_type = 0;
1856 g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1857 err = scanf("%d", &camera_type);
1860 g_print("\t!!!read input error!!!\n");
1864 if (camera_type != 0 && camera_type != 1) {
1865 g_print("\t Invalid camera type(%d)\n", camera_type);
1869 g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1870 err = scanf("%d", (int *)&camera_device);
1873 g_print("\t!!!read input error!!!\n");
1877 if (camera_device < 0 || camera_device > 9) {
1878 g_print("\t Invalid camera device(%d)\n", camera_device);
1882 hcamcorder->type = camera_device;
1888 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1891 hcamcorder->menu_state = MENU_STATE_DEVICE_LIST;
1894 g_print("\t Quit Camcorder Testsuite!!\n");
1898 g_print("\t Invalid media type(%c)\n", buf);
1902 g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1904 gettimeofday(&previous_time, NULL);
1906 g_timer_reset(timer);
1909 err = camera_create_network(camera_device, &hcamcorder->camera);
1911 err = camera_create(camera_device, &hcamcorder->camera);
1913 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1916 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1921 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1922 err = scanf("%d", &display_type);
1925 g_print("\t!!!read input error!!!\n");
1929 switch (display_type) {
1931 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1935 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1939 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1943 g_print("\t Invalid display type(%d)\n", display_type);
1948 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1949 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1950 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1951 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1952 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1953 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1954 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1955 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1957 camera_start_preview(hcamcorder->camera);
1959 gettimeofday(¤t_time, NULL);
1960 timersub(¤t_time, &previous_time, &result_time);
1962 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1964 hcamcorder->menu_state = MENU_STATE_MAIN;
1969 static int app_create(void *data)
1971 appdata *app_data = data;
1974 Evas_Object *win = NULL;
1975 Evas_Object *eo = NULL;
1976 Evas_Object *bg = NULL;
1977 Evas_Object *rect = NULL;
1979 if (app_data == NULL) {
1980 g_print("\t\nappdata is NULL\n");
1984 /* use gl backend */
1985 elm_config_accel_preference_set("opengl");
1987 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1989 elm_win_title_set(win, "camera_test");
1990 elm_win_borderless_set(win, EINA_TRUE);
1991 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1992 g_print("\n\tscreen size %dx%d\n\n", w, h);
1993 evas_object_resize(win, w, h);
1994 elm_win_autodel_set(win, EINA_TRUE);
1995 elm_win_alpha_set(win, EINA_TRUE);
1997 g_print("\n\tfailed to get window\n\n");
2001 bg = elm_bg_add(win);
2003 elm_win_resize_object_add(win, bg);
2004 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2005 evas_object_show(bg);
2007 g_print("\n\tfailed to get elm bg\n\n");
2011 rect = evas_object_rectangle_add(evas_object_evas_get(win));
2013 evas_object_color_set(rect, 0, 0, 0, 0);
2014 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
2016 g_print("\n\tfailed to get rectangle\n\n");
2020 elm_win_resize_object_add(win, rect);
2021 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2022 evas_object_show(rect);
2024 /* Create evas image object for EVAS surface */
2025 eo = evas_object_image_add(evas_object_evas_get(win));
2026 evas_object_image_size_set(eo, w, h);
2027 evas_object_image_fill_set(eo, 0, 0, w, h);
2028 evas_object_resize(eo, w, h);
2029 evas_object_show(eo);
2031 elm_win_activate(win);
2032 evas_object_show(win);
2034 app_data->win = win;
2037 timer = g_timer_new();
2038 g_timer_reset(timer);
2047 static int app_terminate(void *data)
2049 appdata *app_data = data;
2051 if (app_data == NULL) {
2052 g_print("\n\tappdata is NULL\n");
2057 g_timer_stop(timer);
2058 g_timer_destroy(timer);
2067 * This function is the example main function for mmcamcorder API.
2071 * @return This function returns 0.
2073 * @see other functions
2075 int main(int argc, char **argv)
2079 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
2081 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
2082 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
2084 memset(&ad, 0x0, sizeof(appdata));
2087 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
2089 g_print("\n\treturn appcore_efl : %d\n\n", bret);
2092 g_io_channel_unref(stdin_channel);