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 'V' Extra preview GOP interval\n");
931 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
932 g_print("\t 'v' Visible \n");
933 g_print("\t 'o' Output mode \n");
934 g_print("\t 'y' Rotate display \n");
935 g_print("\t 'Y' Flip display \n");
936 g_print("\t 'g' Brightness \n");
937 g_print("\t 'c' Contrast \n");
938 g_print("\t 'h' Hue \n");
939 g_print("\t 'w' White balance \n");
940 g_print("\t 't' Color tone \n");
941 g_print("\t 'd' WDR \n");
942 g_print("\t 'e' EV program mode \n");
943 g_print("\t 'R' Display ROI area \n");
944 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
945 g_print("\t 'z' Strobe (Flash) \n");
946 g_print("\t 'S' Strobe (Flash) state\n");
947 g_print("\t 'G' Strobe (Flash) brightness\n");
948 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
949 g_print("\t 'l' Face detection \n");
950 g_print("\t 'k' Anti-handshake \n");
951 g_print("\t 'K' Video-stabilization \n");
952 g_print("\t 'u' Touch AF area \n");
953 g_print("\t 'n' Set file path to write captured image\n");
954 g_print("\t 'm' Set media bridge\n");
955 g_print("\t 'b' back\n");
956 g_print("\t=======================================\n");
959 g_print("\n\tunknow menu state !!\n");
963 g_print("\tCommand >> ");
969 static void main_menu(gchar buf)
977 case '1': /* Capture */
978 hcamcorder->is_multishot = FALSE;
979 camera_attr_set_image_quality(hcamcorder->camera, 100);
980 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
981 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
983 case '2': /* multishot Capture */
984 g_print("multishot capture");
985 hcamcorder->is_multishot = TRUE;
986 g_print("\n\tinput interval(ms) : ");
987 err = scanf("%d", &interval);
989 g_print("\n\tinput count : ");
990 err = scanf("%d", &count);
992 camera_attr_set_image_quality(hcamcorder->camera, 100);
993 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
994 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
996 camera_start_preview(hcamcorder->camera);
998 case '3': /* Setting */
999 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
1001 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
1002 camera_set_display_reuse_hint(hcamcorder->camera, true);
1004 camera_stop_preview(hcamcorder->camera);
1006 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
1007 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
1009 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
1011 camera_change_device(hcamcorder->camera, hcamcorder->type);
1013 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1014 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1015 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1016 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1018 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1020 camera_start_preview(hcamcorder->camera);
1023 g_print("* Preview Callback\n");
1024 g_print("\tUnset[0] / Set[Others] :");
1025 err = scanf("%d", &set_cb);
1028 g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
1029 err = scanf("%d", &g_camera_preview_cb_dump);
1031 err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
1033 err = camera_unset_preview_cb(hcamcorder->camera);
1035 g_print("\tresult[0x%x]\n\n", err);
1038 g_print("* Extra Preview Callback\n");
1039 g_print("\tUnset[0] / Set[Others] :");
1040 err = scanf("%d", &set_cb);
1043 g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1044 err = scanf("%d", &g_camera_extra_preview_cb_dump);
1046 err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
1048 err = camera_unset_extra_preview_cb(hcamcorder->camera);
1050 g_print("\tresult[0x%x]\n\n", err);
1053 g_print("* Media Packet Preview Callback\n");
1054 g_print("\tUnset[0] / Set[Others] :");
1055 err = scanf("%d", &set_cb);
1058 g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
1059 err = scanf("%d", &g_camera_mp_preview_cb_dump);
1061 err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
1063 err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
1065 g_print("\tresult[0x%x]\n\n", err);
1067 case 'b': /* back */
1068 __release_media_bridge();
1070 camera_stop_preview(hcamcorder->camera);
1071 camera_destroy(hcamcorder->camera);
1072 hcamcorder->camera = NULL;
1073 hcamcorder->menu_state = MENU_STATE_INIT;
1076 g_print("\t Invalid input \n");
1084 static void setting_menu(gchar buf)
1105 /* Camera setting */
1106 case '0': /* Setting > Preview Resolution setting */
1107 g_print("\t* Select the preview resolution!\n");
1108 resolution_stack resolution_list;
1109 resolution_list.count = 0;
1111 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1112 preview_resolution_cb, &resolution_list);
1114 g_print("\tCommand >> ");
1116 err = scanf("%d", &idx);
1118 if (resolution_list.count > idx && idx >= 0) {
1119 g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1120 resolution_list.width[idx], resolution_list.height[idx]);
1122 result = camera_set_preview_resolution(hcamcorder->camera,
1123 resolution_list.width[idx], resolution_list.height[idx]);
1125 g_print("\tInvalid command [%d]\n", idx);
1128 resolution_list.count = 0;
1129 if (result == CAMERA_ERROR_NONE)
1130 g_print("\tPASS\n");
1132 g_print("\tFAIL\n");
1134 case '1': /* Setting > Capture Resolution setting */
1135 g_print("\t* Select the preview resolution!\n");
1136 resolution_list.count = 0;
1138 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1139 capture_resolution_test_cb, &resolution_list);
1141 g_print("\tCommand > ");
1143 err = scanf("%d", &idx);
1145 if (resolution_list.count > idx && idx >= 0) {
1146 g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1147 resolution_list.width[idx], resolution_list.height[idx]);
1149 result = camera_set_capture_resolution(hcamcorder->camera,
1150 resolution_list.width[idx], resolution_list.height[idx]);
1152 g_print("\tInvalid command [%d]\n", idx);
1155 resolution_list.count = 0;
1156 if (result == CAMERA_ERROR_NONE)
1157 g_print("\tPASS\n");
1159 g_print("\tFAIL\n");
1161 case '2': /* Setting > Digital zoom level */
1162 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1164 g_print("\tDigital Zoom Not supported\n");
1166 g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1167 err = scanf("%d", &idx);
1169 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1172 case '3': /* Setting > AF mode */
1173 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1174 err = scanf("%d", &idx);
1178 camera_start_focusing(hcamcorder->camera, 0);
1181 camera_cancel_focusing(hcamcorder->camera);
1184 g_print("\tInvalid command [%d]\n", idx);
1188 case '4': /* Setting > AF scan range */
1189 g_print("\t* AF scan range !\n");
1190 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1191 g_print("\tCommand > ");
1192 err = scanf("%d", &idx);
1194 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1196 case '5': /* Setting > Exposure mode */
1197 g_print("* Exposure mode!\n");
1198 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1199 g_print("\n Select Exposure mode \n");
1200 err = scanf("%d", &idx);
1202 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1205 case '6': /* Setting > Exposure value */
1206 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1208 g_print("Not supported !! \n");
1210 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
1211 err = scanf("%d", &idx);
1213 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1216 case '7': /* Setting > F number */
1217 g_print("Not supported !! \n");
1219 case '8': /* Setting > Display reuse hint */
1221 bool reuse_hint = false;
1223 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1224 if (err != CAMERA_ERROR_NONE) {
1225 g_print("failed to get display reuse hint 0x%x\n", err);
1229 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1230 reuse_hint = !reuse_hint;
1231 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1232 g_print("set display reuse hint result : 0x%x\n", err);
1235 case '9': /* Setting > Manual focus */
1236 g_print("*Manual focus !\n");
1237 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1239 g_print("\n\tManual focus is NOT SUPPORTED\n");
1242 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1243 g_print("\tCurrent focus level (%d)\n", idx);
1244 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1245 err = scanf("%d", &idx);
1247 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1249 if (bret == CAMERA_ERROR_NONE) {
1250 bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1251 g_print("\tfocus level[%d] after set\n", idx);
1253 g_print("\tset focus level failed[0x%x]\n", bret);
1256 case 'i': /* Setting > ISO */
1257 g_print("*ISO !\n");
1258 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1259 err = scanf("%d", &idx);
1261 bret = camera_attr_set_iso(hcamcorder->camera, idx);
1263 case 'r': /* Setting > Rotate camera input when recording */
1264 g_print("*Rotate camera input\n");
1265 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1266 err = scanf("%d", &idx);
1268 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1269 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1270 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1272 case 'f': /* Setting > Flip camera input */
1273 g_print("*Flip camera input\n");
1274 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1275 err = scanf("%d", &idx);
1277 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1278 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1279 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1281 case 'j': /* Setting > Jpeg quality */
1282 g_print("*Jpeg quality !\n");
1283 g_print("\n Select Jpeg quality \n");
1284 err = scanf("%d", &idx);
1286 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1288 case 'p': /* Setting > Picture format */
1289 g_print("* Picture format!\n");
1290 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1291 err = scanf("%d", &idx);
1293 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1294 bret = camera_set_preview_format(hcamcorder->camera, idx);
1295 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1297 case 'E': /* Setting > EXIF orientation */
1298 g_print("* EXIF Orientation\n");
1299 g_print("\t 1. TOP_LEFT\n");
1300 g_print("\t 2. TOP_RIGHT(flipped)\n");
1301 g_print("\t 3. BOTTOM_RIGHT\n");
1302 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1303 g_print("\t 5. LEFT_TOP(flipped)\n");
1304 g_print("\t 6. RIGHT_TOP\n");
1305 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1306 g_print("\t 8. LEFT_BOTTOM\n");
1307 err = scanf("%d", &idx);
1309 if (idx < 1 || idx > 8)
1310 g_print("Wrong INPUT[%d]!! \n", idx);
1312 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1314 case 'F': /* Setting > Get Facing direction */
1315 g_print("* Get facing direction of camera module\n");
1316 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1317 if (CAMERA_ERROR_NONE == err)
1318 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1320 g_print("* Error : %d\n", err);
1322 case 's': /* Setting > Set extra preview stream format */
1323 g_print("* Set extra preview stream format\n");
1325 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1326 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1329 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1330 stream_id, pixel_format, width, height, fps);
1331 if (err != CAMERA_ERROR_NONE) {
1332 g_print("* Set Error : 0x%x\n", err);
1336 pixel_format = width = height = fps = -1;
1338 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1339 stream_id, &pixel_format, &width, &height, &fps);
1340 if (err != CAMERA_ERROR_NONE) {
1341 g_print("* Get Error : 0x%x\n", err);
1345 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1346 stream_id, pixel_format, width, height, fps);
1348 case 'B': /* Setting > Set extra preview bitrate */
1349 g_print("* Set extra preview bitrate\n");
1350 g_print("\tstream_id : ");
1351 err = scanf("%d", &stream_id);
1354 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1355 if (err != CAMERA_ERROR_NONE) {
1356 g_print("\tFailed to get bitrate for stream_id[%d]\n", stream_id);
1360 g_print("\tCurrent bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1362 g_print("\tSet bitrate(bps) : ");
1363 err = scanf("%d", &bitrate);
1366 err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
1367 if (err != CAMERA_ERROR_NONE) {
1368 g_print("* Set Error : 0x%x\n", err);
1374 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1375 if (err != CAMERA_ERROR_NONE) {
1376 g_print("* Get Error : 0x%x\n", err);
1380 g_print("\tResult bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1382 case 'V': /* Setting > Set extra preview GOP interval */
1383 g_print("* Set extra preview GOP interval\n");
1384 g_print("\tstream_id : ");
1385 err = scanf("%d", &stream_id);
1388 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1389 if (err != CAMERA_ERROR_NONE) {
1390 g_print("\tFailed to get GOP interval for stream_id[%d]\n", stream_id);
1394 g_print("\tCurrent GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1396 g_print("\tSet GOP interval(ms) : ");
1397 err = scanf("%d", &interval);
1400 err = camera_attr_set_extra_preview_gop_interval(hcamcorder->camera, stream_id, interval);
1401 if (err != CAMERA_ERROR_NONE) {
1402 g_print("* Set Error : 0x%x\n", err);
1408 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1409 if (err != CAMERA_ERROR_NONE) {
1410 g_print("* Get Error : 0x%x\n", err);
1414 g_print("\tResult GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1416 /* Display / Filter setting */
1417 case 'v': /* Display visible */
1418 g_print("* Display visible setting !\n");
1419 g_print("\n Select Display visible \n");
1420 for (i = 0 ; i < 2 ; i++)
1421 g_print("\t %d. %s\n", i, visible_mode[i]);
1422 err = scanf("%d", &idx);
1424 if (idx == 0 || idx == 1)
1425 bret = camera_set_display_visible(hcamcorder->camera, idx);
1427 g_print("invalid input %d", idx);
1429 case 'o': /* Setting > Display Mode */
1430 g_print("* Display mode!\n");
1431 for (i = 0 ; i < 5 ; i++)
1432 g_print("%d. %s\n", i, display_mode[i]);
1433 err = scanf("%d", &idx);
1435 bret = camera_set_display_mode(hcamcorder->camera, idx);
1437 case 'y': /* Setting > Rotate Display */
1438 g_print("\n Select Rotate mode\n");
1439 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1440 err = scanf("%d", &idx);
1442 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1443 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1444 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1446 case 'Y': /* Setting > Flip Display */
1447 g_print("\n Select Rotate mode\n");
1448 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1449 err = scanf("%d", &idx);
1451 bret = camera_set_display_flip(hcamcorder->camera, idx);
1453 case 'g': /* Setting > Brightness */
1454 g_print("*Brightness !\n");
1455 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1456 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1457 err = scanf("%d", &idx);
1459 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1461 case 'c': /* Setting > Contrast */
1462 g_print("*Contrast !\n");
1463 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1464 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1465 err = scanf("%d", &idx);
1467 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1469 case 'h': /* Setting > Hue */
1470 g_print("*Hue !\n");
1471 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1473 g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1474 err = scanf("%d", &idx);
1476 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1478 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1481 case 'w': /* Setting > White balance */
1482 g_print("*White balance !\n");
1483 g_print("\n Select White balance \n");
1484 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1485 err = scanf("%d", &idx);
1487 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1489 case 't': /* Setting > Color tone */
1490 g_print("*Color tone !\n");
1491 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1492 g_print("\n Select Color tone \n");
1493 err = scanf("%d", &idx);
1495 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1497 case 'd': /* Setting > WDR */
1498 g_print("*WDR !\n");
1499 g_print("\n Select WDR Mode \n");
1500 for (i = 0 ; i < 2 ; i++)
1501 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1502 err = scanf("%d", &idx);
1505 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1507 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1509 case 'e': /* Setting > EV program mode */
1510 g_print("* EV program mode!\n");
1511 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1512 g_print("\n Select EV program mode \n");
1513 err = scanf("%d", &idx);
1515 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1517 case 'R': /* Setting > Display ROI area */
1518 g_print("* Set display roi area. Select x y width height \n");
1519 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1521 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1522 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1523 if (CAMERA_ERROR_NONE != err)
1524 g_print("* Error : %d\n", err);
1526 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1527 if (CAMERA_ERROR_NONE == err)
1528 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1530 g_print("* Error : %d\n", err);
1534 case 'z': /* Setting > Strobe setting */
1535 g_print("*Strobe Mode\n");
1536 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1537 g_print("\n Select Strobe Mode \n");
1538 err = scanf("%d", &idx);
1540 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1542 case 'S': /* Setting > flash state */
1543 g_print("*flash state\n");
1544 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1545 if (CAMERA_ERROR_NONE == err)
1546 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1548 g_print("* Error : %d\n", err);
1550 case 'G': /* Setting > flash brightness */
1551 g_print("*Flash brightness !\n");
1552 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1553 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1554 err = scanf("%d", &idx);
1556 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1558 case 'x': /* Setting > Capture mode ,Muitishot? */
1559 g_print("*Select Capture mode!\n");
1560 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1561 err = scanf("%d", &idx);
1566 g_print("stillshot mode selected and capture callback is set!!!!\n");
1567 hcamcorder->is_multishot = FALSE;
1568 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1571 g_print("HDR Capture mode selected\n");
1572 hcamcorder->is_multishot = FALSE;
1573 g_print("\nSelect HDR capture mode\n");
1574 for (i = 0 ; i < 3 ; i++)
1575 g_print("\t %d. %s\n", i, hdr_mode[i]);
1576 err = scanf("%d", &idx);
1578 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1579 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1581 g_print("invalid input %d\n", idx);
1584 g_print("Wrong input, select again!!\n");
1588 case 'l': /* Setting > Face detection setting */
1589 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1590 g_print("* Face detect mode !\n");
1591 for (i = 0 ; i < 2 ; i++)
1592 g_print("\t %d. %s \n", i, detection_mode[i]);
1593 err = scanf("%d", &idx);
1596 bret = camera_stop_face_detection(hcamcorder->camera);
1598 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1600 g_print("\n invalid input [%d]\n\n", idx);
1602 g_print("face detection_not supported");
1605 case 'k': /* Setting > Anti-handshake */
1606 g_print("*Anti-handshake !\n");
1607 g_print("\n Select Anti-handshake mode \n");
1608 for (i = 0; i < 2; i++)
1609 g_print("\t %d. %s\n", i, ahs_mode[i]);
1610 err = scanf("%d", &idx);
1612 if (idx == 0 || idx == 1)
1613 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1615 g_print("invalid input %d\n", idx);
1617 case 'K': /* Setting > Video-stabilization */
1618 g_print("*Video-stabilization !\n");
1619 g_print("\n Select Video-stabilization mode \n");
1620 for (i = 0 ; i < 2 ; i++)
1621 g_print("\t %d. %s\n", i, vs_mode[i]);
1622 err = scanf("%d", &idx);
1624 if (idx < 0 || idx > 1) {
1625 g_print("invalid input %d\n", idx);
1630 g_print("\n Restart preview with NV12 and 720p resolution\n");
1631 err = camera_stop_preview(hcamcorder->camera);
1632 g_print("stop preview result 0x%x\n", err);
1633 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1634 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1637 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1640 err = camera_start_preview(hcamcorder->camera);
1641 if (err != CAMERA_ERROR_NONE)
1642 g_print("\n Restart FAILED! 0x%x\n", err);
1645 case 'u': /* Touch AF area */
1646 g_print("* Touch AF area !\n");
1647 g_print("\n Input x,y,width,height \n");
1648 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1650 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1652 g_print("Failed to set touch AF area.(%x)\n", err);
1654 g_print("Succeed to set touch AF area.\n");
1656 case 'n': /* file path */
1657 g_print("* File path !\n");
1658 g_print("\n Input file path to save captured data(string) : ");
1659 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1660 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1661 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1663 g_print("\nset file path failed\n");
1666 case 'm': /* media bridge */
1667 g_print("* Media Bridge !\n");
1668 g_print("\tUnset[0] / Set[Others] :");
1669 err = scanf("%d", &set_bridge);
1672 __release_media_bridge();
1674 err = media_bridge_create(&bridge);
1675 err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1677 __release_media_bridge();
1679 g_print("\tresult[0x%x]\n\n", err);
1681 case 'b': /* back */
1682 hcamcorder->menu_state = MENU_STATE_MAIN;
1685 g_print("\t Invalid input \n");
1689 g_print("\t bret : 0x%x \n", bret);
1695 static void device_state_menu(gchar buf)
1698 camera_device_e device = CAMERA_DEVICE_CAMERA0;
1699 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1702 case '1': /* Get device state */
1704 g_print("\n\tEnter Camera Index[0~9]: ");
1706 ret = scanf("%d", (int *)&device);
1710 g_print("\n\t!!!read input error!!!\n");
1714 if (device < CAMERA_DEVICE_CAMERA0 ||
1715 device > CAMERA_DEVICE_CAMERA9) {
1716 g_print("\n\tinvalid input:[%d], try again...\n", device);
1720 ret = camera_get_device_state(device, &device_state);
1721 g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1722 device, device_state, ret);
1726 case '2': /* Add device state changed callback */
1727 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1728 NULL, &g_camera_device_state_changed_cb_id);
1729 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1731 case '3': /* Remove device state changed callback */
1732 if (g_camera_device_state_changed_cb_id > 0) {
1733 ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1734 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1735 g_camera_device_state_changed_cb_id = 0;
1737 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1740 case 'b': /* back */
1741 hcamcorder->menu_state = MENU_STATE_INIT;
1744 g_print("\n\tinvalid input[%c]\n", buf);
1751 static void device_list_menu(gchar buf)
1755 camera_device_list_s device_list;
1758 case '1': /* Initialize device manager */
1759 ret = camera_device_manager_initialize(&g_device_manager);
1760 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1761 g_device_manager, ret);
1763 case '2': /* Get device list */
1764 memset(&device_list, 0x0, sizeof(camera_device_list_s));
1765 ret = camera_device_manager_get_device_list(g_device_manager, &device_list);
1766 if (ret != CAMERA_ERROR_NONE) {
1767 g_print("\n\tGet device list failed[0x%x]\n", ret);
1771 g_print("\n\tDevice list[count:%d]\n", device_list.count);
1773 for (i = 0 ; i < device_list.count ; i++) {
1774 g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
1775 i, device_list.device[i].type, device_list.device[i].index,
1776 device_list.device[i].name, device_list.device[i].id);
1779 case '3': /* Add device connection changed callback */
1780 ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
1781 _camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
1782 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1784 case '4': /* Remove device connection changed callback */
1785 if (g_camera_device_connection_changed_cb_id > 0) {
1786 ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
1787 g_camera_device_connection_changed_cb_id);
1788 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1789 g_camera_device_connection_changed_cb_id = 0;
1791 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
1794 case '9': /* Deinitialize device manager */
1795 ret = camera_device_manager_deinitialize(g_device_manager);
1796 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1797 g_device_manager, ret);
1798 g_device_manager = NULL;
1800 case 'b': /* back */
1801 hcamcorder->menu_state = MENU_STATE_INIT;
1804 g_print("\n\tinvalid input[%c]\n", buf);
1813 * This function is to execute command.
1815 * @param channel [in] 1st parameter
1817 * @return This function returns TRUE/FALSE
1821 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1825 GError *g_error = NULL;
1827 g_print("\n\tENTER\n");
1829 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1831 g_print("\n\tg_io_channel_read_chars error\n");
1832 g_error_free(g_error);
1839 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1840 switch (hcamcorder->menu_state) {
1841 case MENU_STATE_INIT:
1842 mode_change(buf[0]);
1844 case MENU_STATE_MAIN:
1847 case MENU_STATE_MAIN_SETTING:
1848 setting_menu(buf[0]);
1850 case MENU_STATE_DEVICE_STATE:
1851 device_state_menu(buf[0]);
1853 case MENU_STATE_DEVICE_LIST:
1854 device_list_menu(buf[0]);
1865 g_print("\n\tNo read input\n");
1871 static gboolean init_handle()
1873 hcamcorder->is_multishot = FALSE;
1874 hcamcorder->stillshot_count = 0;
1875 hcamcorder->multishot_count = 0;
1876 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1877 hcamcorder->menu_state = MENU_STATE_INIT;
1878 hcamcorder->elapsed_time = 0;
1885 * This function is to change camcorder mode.
1887 * @param buf [in] user input
1889 * @return This function returns TRUE/FALSE
1891 * @see other functions
1893 static gboolean mode_change(gchar buf)
1896 int camera_type = 0;
1897 int display_type = 0;
1903 g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1904 err = scanf("%d", &camera_type);
1907 g_print("\t!!!read input error!!!\n");
1911 if (camera_type != 0 && camera_type != 1) {
1912 g_print("\t Invalid camera type(%d)\n", camera_type);
1916 g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1917 err = scanf("%d", (int *)&camera_device);
1920 g_print("\t!!!read input error!!!\n");
1924 if (camera_device < 0 || camera_device > 9) {
1925 g_print("\t Invalid camera device(%d)\n", camera_device);
1929 hcamcorder->type = camera_device;
1935 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1938 hcamcorder->menu_state = MENU_STATE_DEVICE_LIST;
1941 g_print("\t Quit Camcorder Testsuite!!\n");
1945 g_print("\t Invalid media type(%c)\n", buf);
1949 g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1951 gettimeofday(&previous_time, NULL);
1953 g_timer_reset(timer);
1956 err = camera_create_network(camera_device, &hcamcorder->camera);
1958 err = camera_create(camera_device, &hcamcorder->camera);
1960 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1963 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1968 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1969 err = scanf("%d", &display_type);
1972 g_print("\t!!!read input error!!!\n");
1976 switch (display_type) {
1978 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1982 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1986 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1990 g_print("\t Invalid display type(%d)\n", display_type);
1995 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1996 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1997 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1998 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1999 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
2000 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
2001 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
2002 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
2004 camera_start_preview(hcamcorder->camera);
2006 gettimeofday(¤t_time, NULL);
2007 timersub(¤t_time, &previous_time, &result_time);
2009 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
2011 hcamcorder->menu_state = MENU_STATE_MAIN;
2016 static int app_create(void *data)
2018 appdata *app_data = data;
2021 Evas_Object *win = NULL;
2022 Evas_Object *eo = NULL;
2023 Evas_Object *bg = NULL;
2024 Evas_Object *rect = NULL;
2026 if (app_data == NULL) {
2027 g_print("\t\nappdata is NULL\n");
2031 /* use gl backend */
2032 elm_config_accel_preference_set("opengl");
2034 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
2036 elm_win_title_set(win, "camera_test");
2037 elm_win_borderless_set(win, EINA_TRUE);
2038 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
2039 g_print("\n\tscreen size %dx%d\n\n", w, h);
2040 evas_object_resize(win, w, h);
2041 elm_win_autodel_set(win, EINA_TRUE);
2042 elm_win_alpha_set(win, EINA_TRUE);
2044 g_print("\n\tfailed to get window\n\n");
2048 bg = elm_bg_add(win);
2050 elm_win_resize_object_add(win, bg);
2051 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2052 evas_object_show(bg);
2054 g_print("\n\tfailed to get elm bg\n\n");
2058 rect = evas_object_rectangle_add(evas_object_evas_get(win));
2060 evas_object_color_set(rect, 0, 0, 0, 0);
2061 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
2063 g_print("\n\tfailed to get rectangle\n\n");
2067 elm_win_resize_object_add(win, rect);
2068 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2069 evas_object_show(rect);
2071 /* Create evas image object for EVAS surface */
2072 eo = evas_object_image_add(evas_object_evas_get(win));
2073 evas_object_image_size_set(eo, w, h);
2074 evas_object_image_fill_set(eo, 0, 0, w, h);
2075 evas_object_resize(eo, w, h);
2076 evas_object_show(eo);
2078 elm_win_activate(win);
2079 evas_object_show(win);
2081 app_data->win = win;
2084 timer = g_timer_new();
2085 g_timer_reset(timer);
2094 static int app_terminate(void *data)
2096 appdata *app_data = data;
2098 if (app_data == NULL) {
2099 g_print("\n\tappdata is NULL\n");
2104 g_timer_stop(timer);
2105 g_timer_destroy(timer);
2114 * This function is the example main function for mmcamcorder API.
2118 * @return This function returns 0.
2120 * @see other functions
2122 int main(int argc, char **argv)
2126 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
2128 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
2129 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
2131 memset(&ad, 0x0, sizeof(appdata));
2134 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
2136 g_print("\n\treturn appcore_efl : %d\n\n", bret);
2139 g_io_channel_unref(stdin_channel);