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>
36 /*-----------------------------------------------------------------------
37 | GLOBAL VARIABLE DEFINITIONS: |
38 -----------------------------------------------------------------------*/
39 #define EXPORT_API __attribute__((__visibility__("default")))
44 #define PACKAGE "camera_test"
47 static int app_create(void *data);
48 static int app_terminate(void *data);
56 typedef struct _appdata appdata;
58 static struct appcore_ops ops = {
60 .terminate = app_terminate,
64 static GIOChannel *stdin_channel;
65 static camera_device_e camera_device;
67 static int g_camera_device_state_changed_cb_id;
68 static int g_camera_device_list_changed_cb_id;
69 static int g_camera_preview_cb_file_write;
70 static int g_camera_mp_preview_cb_file_write;
72 static struct timeval previous_time;
73 static struct timeval current_time;
74 static struct timeval result_time;
76 /*-----------------------------------------------------------------------
77 | GLOBAL CONSTANT DEFINITIONS: |
78 -----------------------------------------------------------------------*/
81 /*-----------------------------------------------------------------------
82 | IMPORTED VARIABLE DECLARATIONS: |
83 -----------------------------------------------------------------------*/
86 /*-----------------------------------------------------------------------
87 | IMPORTED FUNCTION DECLARATIONS: |
88 -----------------------------------------------------------------------*/
91 /*-----------------------------------------------------------------------
93 -----------------------------------------------------------------------*/
94 #define DEFAULT_FILE_PATH "/home/owner/media"
95 #define PREVIEW_CB_DUMP_FILE_NAME "preview.data"
96 #define MP_PREVIEW_CB_DUMP_FILE_NAME "mp_preview.data"
97 #define MAX_FILE_NAME_LENGTH 256
98 #define MAX_FILE_PATH_LENGTH (MAX_FILE_NAME_LENGTH - 20)
100 #define CHECK_MM_ERROR(expr) \
105 g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
112 #define SAFE_FREE(x) \
119 #define SENSOR_WHITEBALANCE_NUM 10
120 #define SENSOR_COLOR_TONE_NUM 31
121 #define SENSOR_FLIP_NUM 4
122 #define SENSOR_PROGRAM_MODE_NUM 15
123 #define SENSOR_FOCUS_NUM 6
124 #define SENSOR_INPUT_ROTATION 4
125 #define SENSOR_AF_SCAN_NUM 4
126 #define SENSOR_ISO_NUM 8
127 #define SENSOR_EXPOSURE_NUM 9
128 #define SENSOR_IMAGE_FORMAT 9
131 /*-----------------------------------------------------------------------
132 | LOCAL CONSTANT DEFINITIONS: |
133 -----------------------------------------------------------------------*/
135 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
136 MODE_AUDIO, /* audio recording*/
143 MENU_STATE_MAIN_SETTING,
144 MENU_STATE_DEVICE_STATE,
145 MENU_STATE_DEVICE_LIST,
149 /*-----------------------------------------------------------------------
150 | LOCAL DATA TYPE DEFINITIONS: |
151 -----------------------------------------------------------------------*/
152 typedef struct _cam_handle {
155 int is_multishot; /* flag for multishot mode */
156 int stillshot_count; /* stillshot count */
157 int multishot_count; /* multishot count */
158 char file_path[MAX_FILE_PATH_LENGTH]; /* file path for captured data */
160 unsigned long long elapsed_time;
170 camera_attr_exposure_mode_e mode;
175 camera_attr_iso_e mode;
180 /*---------------------------------------------------------------------------
181 | LOCAL VARIABLE DEFINITIONS: |
182 ---------------------------------------------------------------------------*/
183 static cam_handle_t *hcamcorder;
184 static camera_device_manager_h g_device_manager;
186 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
199 const char *ct[SENSOR_COLOR_TONE_NUM] = {
225 "SELECTVE_COLOR_RED",
226 "SELECTVE_COLOR_GREEN",
227 "SELECTVE_COLOR_BLUE",
228 "SELECTVE_COLOR_YELLOW",
229 "SELECTVE_COLOR_RED_YELLOW",
233 const char *sensor_flip[SENSOR_FLIP_NUM] = {
240 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
258 const char *focus_mode[SENSOR_FOCUS_NUM] = {
267 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
274 const char *iso_mode[SENSOR_ISO_NUM] = {
285 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
293 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
305 const char *face_zoom_mode[] = {
310 const char *display_mode[] = {
312 "Original Size mode",
314 "Cropped Full Screen mode",
318 const char *capture_sound[] = {
324 const char *rotate_mode[] = {
331 const char* strobe_mode[] = {
335 "Strobe RedEyeReduction",
337 "Strobe FrontCurtain",
338 "Strobe RearCurtain",
342 const char *detection_mode[2] = {
343 "Face Detection OFF",
347 const char *wdr_mode[] = {
353 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
360 const char *hdr_mode[] = {
363 "HDR ON and Original",
366 const char *ahs_mode[] = {
367 "Anti-handshake OFF",
369 "Anti-handshake AUTO",
370 "Anti-handshake MOVIE",
373 const char *vs_mode[] = {
374 "Video-stabilization OFF",
375 "Video-stabilization ON",
378 const char *visible_mode[] = {
383 const char *facing_direction[] = {
389 /*---------------------------------------------------------------------------
390 | LOCAL FUNCTION PROTOTYPES: |
391 ---------------------------------------------------------------------------*/
392 static void print_menu();
393 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data);
394 static gboolean mode_change(gchar buf);
395 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
398 static inline void flush_stdin()
401 while ((ch = getchar()) != EOF && ch != '\n');
404 static gboolean _release_idle_event_callback(void *data)
406 g_print("destroy camera handle\n\n");
408 camera_destroy(hcamcorder->camera);
409 hcamcorder->camera = NULL;
410 hcamcorder->menu_state = MENU_STATE_INIT;
417 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
419 g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
422 case CAMERA_ERROR_RESOURCE_CONFLICT:
423 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
425 case CAMERA_ERROR_SECURITY_RESTRICTED:
426 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
428 case CAMERA_ERROR_SERVICE_DISCONNECTED:
429 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
430 g_idle_add_full(G_PRIORITY_DEFAULT,
431 (GSourceFunc)_release_idle_event_callback,
441 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
443 g_print("\n\tcamera state changed %d -> %d\n", previous, current);
448 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
450 g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
455 static void _camera_device_list_changed_cb(camera_device_list_s *device_list, void *user_data)
460 g_print("NULL list");
464 g_print("\n\tcamera device list changed[count:%d]\n", device_list->count);
466 for (i = 0 ; i < device_list->count ; i++) {
467 g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
468 i, device_list->device[i].type, device_list->device[i].index,
469 device_list->device[i].name, device_list->device[i].id);
475 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
477 g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
478 previous, current, policy);
483 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
485 g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
490 void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
492 char preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',};
496 g_print("\n[PREVIEW_CB] NULL frame!\n");
500 g_print("[PREVIEW_CB] preview callback - format[%d] res[%dx%d] num plane[%d] ",
501 frame->format, frame->width, frame->height, frame->num_of_planes);
503 if (frame->num_of_planes == 1) {
504 g_print("size YUV[%d]\n",
505 frame->data.single_plane.size);
506 } else if (frame->num_of_planes == 2) {
507 g_print("size Y[%d] UV[%d]\n",
508 frame->data.double_plane.y_size,
509 frame->data.double_plane.uv_size);
510 } else if (frame->num_of_planes == 3) {
511 g_print("size Y[%d] U[%d] V[%d]\n",
512 frame->data.triple_plane.y_size,
513 frame->data.triple_plane.u_size,
514 frame->data.triple_plane.v_size);
517 if (!g_camera_preview_cb_file_write)
520 snprintf(preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, PREVIEW_CB_DUMP_FILE_NAME);
522 fp = fopen(preview_dump, "a");
524 g_print("\n[PREVIEW_CB] file[%s] open failed\n", preview_dump);
528 if (frame->format == CAMERA_PIXEL_FORMAT_RGBA ||
529 frame->format == CAMERA_PIXEL_FORMAT_ARGB) {
530 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
531 } else if (frame->format == CAMERA_PIXEL_FORMAT_INVZ) {
532 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
533 } else if (frame->format == CAMERA_PIXEL_FORMAT_MJPEG) {
534 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
536 switch (frame->num_of_planes) {
538 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
541 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
542 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
545 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
546 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
547 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
554 g_print("[PREVIEW_CB] file[%s] write done\n", preview_dump);
560 static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
566 char mp_preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',};
568 media_format_h fmt = NULL;
569 media_format_mimetype_e type = MEDIA_FORMAT_I420;
570 tbm_surface_h surface = NULL;
571 tbm_surface_info_s s_info;
574 g_print("\n[MP_PREVIEW_CB] NULL packet!\n");
578 ret = media_packet_get_format(pkt, &fmt);
579 if (ret != MEDIA_PACKET_ERROR_NONE) {
580 g_print("\n[MP_PREVIEW_CB] get media format failed[0x%x]", ret);
581 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
584 ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
585 if (ret != MEDIA_FORMAT_ERROR_NONE) {
586 g_print("\n[MP_PREVIEW_CB] get video info failed[0x%x]", ret);
587 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
590 g_print("[MP_PREVIEW_CB] media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height);
592 ret = media_packet_get_tbm_surface(pkt, &surface);
593 if (ret != MEDIA_PACKET_ERROR_NONE) {
594 g_print("\n[MP_PREVIEW_CB] get tbm surface failed[0x%x] ====\n", ret);
595 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
598 ret = tbm_surface_get_info(surface, &s_info);
599 if (ret != TBM_SURFACE_ERROR_NONE) {
600 g_print("\n[MP_PREVIEW_CB] get tbm surface info failed[0x%x] ====\n", ret);
601 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
604 g_print(" tbm surface [%dx%d], total size[%u]\n",
605 s_info.width, s_info.height, s_info.size);
607 if (g_camera_mp_preview_cb_file_write) {
608 snprintf(mp_preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, MP_PREVIEW_CB_DUMP_FILE_NAME);
610 fp = fopen(mp_preview_dump, "a");
612 g_print("\n[MP_PREVIEW_CB] file[%s] open failed ====\n", mp_preview_dump);
613 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
617 for (i = 0 ; i < s_info.num_planes ; i++) {
618 g_print(" plane[%d][%p] stride[%u] size[%u]\n",
619 i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
621 fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
624 _MEDIA_PACKET_PREVIEW_CB_OUT:
628 media_packet_unref(pkt);
632 static bool preview_resolution_cb(int width, int height, void *user_data)
634 resolution_stack *data = (resolution_stack *)user_data;
637 g_print("NULL data\n");
641 data->width[data->count] = width;
642 data->height[data->count] = height;
644 g_print("\t%d. %dx%d\n", data->count, width, height);
651 static bool capture_resolution_test_cb(int width, int height, void *user_data)
653 resolution_stack *data = (resolution_stack *)user_data;
656 g_print("NULL data\n");
660 data->width[data->count] = width;
661 data->height[data->count] = height;
663 g_print("\t%d. %dx%d\n", data->count, width, height);
670 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
672 g_print("\t%d. %s\n", mode, af_scan[mode]);
676 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
678 exposure_stack *data = (exposure_stack *)user_data;
681 g_print("NULL data\n");
688 g_print("\t%d. %s\n", mode, exposure_mode[mode]);
692 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
694 g_print("\t%d. %s\n", mode, iso_mode[mode]);
698 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
700 g_print("\t%d. %s\n", mode, camera_rotation[mode]);
704 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
706 g_print("\t%d. %s\n", mode, sensor_flip[mode]);
710 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
712 g_print("\t%d. %s\n", mode, image_fmt[mode]);
716 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
718 g_print("\t%d. %s\n", mode, wb[mode]);
722 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
724 g_print("\t%d. %s\n", mode, ct[mode]);
728 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
730 g_print("\t%d. %s\n", mode, program_mode[mode]);
734 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
736 g_print("\t%d. %s\n", mode, strobe_mode[mode]);
740 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
742 g_print("\tface detected!! - count %d\n", count);
745 for (i = 0 ; i < count ; i++)
746 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
751 static void _file_write(char *path, void *data, int size)
755 if (!path || !data || size <= 0) {
756 g_print("\n\tERROR %p %p %d\n", path, data, size);
760 fp = fopen(path, "w");
762 g_print("\n\topen success [%s]\n", path);
763 if (fwrite(data, size, 1, fp) != 1)
764 g_print("\n\twrite error! errno %d\n", errno);
766 g_print("\n\twrite success [%s]\n", path);
771 g_print("\n\topen error! [%s], errno %d\n", path, errno);
777 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
779 char m_filename[MAX_FILE_NAME_LENGTH];
783 if (hcamcorder->is_multishot) {
784 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
785 hcamcorder->file_path, hcamcorder->multishot_count++);
787 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
788 hcamcorder->file_path, hcamcorder->stillshot_count++);
791 _file_write(m_filename, image->data, image->size);
797 static void capture_completed_cb(void *user_data)
799 camera_start_preview(hcamcorder->camera);
804 static void print_menu()
806 switch (hcamcorder->menu_state) {
807 case MENU_STATE_INIT:
808 g_print("\n\t=======================================\n");
809 g_print("\t CAMERA_TESTSUITE\n");
810 g_print("\t=======================================\n");
811 g_print("\t '1' Video Capture\n");
812 g_print("\t '2' Device State\n");
813 g_print("\t '3' Device List\n");
814 g_print("\t 'q' Exit\n");
815 g_print("\t=======================================\n");
817 case MENU_STATE_MAIN:
818 g_print("\n\t=======================================\n");
819 g_print("\t Video Capture (CAMERA%d)\n", camera_device);
820 g_print("\t=======================================\n");
821 g_print("\t '1' Stillshot test\n");
822 g_print("\t '2' Multishot test\n");
823 g_print("\t '3' Setting\n");
824 g_print("\t '4' Change device (CAMERA0 <-> CAMERA1)\n");
825 g_print("\t '5' Set preview callback\n");
826 g_print("\t '6' Unset preview callback\n");
827 g_print("\t '7' Set media packet preview callback\n");
828 g_print("\t '8' Unset media packet preview callback\n");
829 g_print("\t 'b' back\n");
830 g_print("\t=======================================\n");
832 case MENU_STATE_DEVICE_STATE:
833 g_print("\n\t=======================================\n");
834 g_print("\t Device State\n");
835 g_print("\t=======================================\n");
836 g_print("\t '1' Get camera device state\n");
837 g_print("\t '2' Add camera device state changed callback\n");
838 g_print("\t '3' Remove camera device state changed callback\n");
839 g_print("\t 'b' back\n");
840 g_print("\t=======================================\n");
842 case MENU_STATE_DEVICE_LIST:
843 g_print("\n\t=======================================\n");
844 g_print("\t Device List\n");
845 g_print("\t=======================================\n");
846 g_print("\t '1' Initialize device manager\n");
847 g_print("\t '2' Get camera device list\n");
848 g_print("\t '3' Add camera device list changed callback\n");
849 g_print("\t '4' Remove camera device list changed callback\n");
850 g_print("\t '5' Deinitialize device manager\n");
851 g_print("\t 'b' back\n");
852 g_print("\t=======================================\n");
854 case MENU_STATE_MAIN_SETTING:
855 g_print("\n\t=======================================\n");
856 g_print("\t Video Capture > Setting\n");
857 g_print("\t=======================================\n");
858 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
859 g_print("\t '0' Preview resolution \n");
860 g_print("\t '1' Capture resolution \n");
861 g_print("\t '2' Digital zoom level \n");
862 g_print("\t '3' AF mode \n");
863 g_print("\t '4' AF scan range \n");
864 g_print("\t '5' Exposure mode \n");
865 g_print("\t '6' Exposure value \n");
866 g_print("\t '7' F number \n");
867 g_print("\t '8' Display reuse hint \n");
868 g_print("\t 'i' ISO \n");
869 g_print("\t 'r' Rotate camera input \n");
870 g_print("\t 'f' Flip camera input \n");
871 g_print("\t 'j' Jpeg quality \n");
872 g_print("\t 'p' Picture format \n");
873 g_print("\t 'E' EXIF orientation \n");
874 g_print("\t 'F' Get facing direction of camera module\n");
875 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
876 g_print("\t 'v' Visible \n");
877 g_print("\t 'o' Output mode \n");
878 g_print("\t 'y' Rotate display \n");
879 g_print("\t 'Y' Flip display \n");
880 g_print("\t 'g' Brightness \n");
881 g_print("\t 'c' Contrast \n");
882 g_print("\t 'h' Hue \n");
883 g_print("\t 'w' White balance \n");
884 g_print("\t 't' Color tone \n");
885 g_print("\t 'd' WDR \n");
886 g_print("\t 'e' EV program mode \n");
887 g_print("\t 'R' Display ROI area \n");
888 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
889 g_print("\t 'z' Strobe (Flash) \n");
890 g_print("\t 'S' Strobe (Flash) state\n");
891 g_print("\t 'G' Strobe (Flash) brightness\n");
892 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
893 g_print("\t 'l' Face detection \n");
894 g_print("\t 'k' Anti-handshake \n");
895 g_print("\t 'K' Video-stabilization \n");
896 g_print("\t 'u' Touch AF area \n");
897 g_print("\t 'n' Set file path to write captured image\n");
898 g_print("\t 'b' back\n");
899 g_print("\t=======================================\n");
902 g_print("\n\tunknow menu state !!\n");
906 g_print("\tCommand >> ");
912 static void main_menu(gchar buf)
919 case '1': /* Capture */
920 hcamcorder->is_multishot = FALSE;
921 camera_attr_set_image_quality(hcamcorder->camera, 100);
922 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
923 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
925 case '2': /* multishot Capture */
926 g_print("multishot capture");
927 hcamcorder->is_multishot = TRUE;
928 g_print("\n\tinput interval(ms) : ");
929 err = scanf("%d", &interval);
931 g_print("\n\tinput count : ");
932 err = scanf("%d", &count);
934 camera_attr_set_image_quality(hcamcorder->camera, 100);
935 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
936 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
938 camera_start_preview(hcamcorder->camera);
940 case '3': /* Setting */
941 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
943 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
944 camera_set_display_reuse_hint(hcamcorder->camera, true);
946 camera_stop_preview(hcamcorder->camera);
948 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
949 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
951 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
953 camera_change_device(hcamcorder->camera, hcamcorder->type);
955 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
956 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
957 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
958 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
960 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
962 camera_start_preview(hcamcorder->camera);
965 g_print("\n\tWrite preview data to file(0:NO, Others:YES) : ");
966 err = scanf("%d", &g_camera_preview_cb_file_write);
968 camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
971 camera_unset_preview_cb(hcamcorder->camera);
974 g_print("\n\tWrite preview data to file(0:NO, Others:YES) : ");
975 err = scanf("%d", &g_camera_mp_preview_cb_file_write);
977 camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
980 camera_unset_media_packet_preview_cb(hcamcorder->camera);
983 camera_stop_preview(hcamcorder->camera);
984 camera_destroy(hcamcorder->camera);
985 hcamcorder->camera = NULL;
986 hcamcorder->menu_state = MENU_STATE_INIT;
989 g_print("\t Invalid input \n");
997 static void setting_menu(gchar buf)
1012 /* Camera setting */
1013 case '0': /* Setting > Preview Resolution setting */
1014 g_print("\t* Select the preview resolution!\n");
1015 resolution_stack resolution_list;
1016 resolution_list.count = 0;
1018 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1019 preview_resolution_cb, &resolution_list);
1021 g_print("\tCommand >> ");
1023 err = scanf("%d", &idx);
1025 if (resolution_list.count > idx && idx >= 0) {
1026 g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1027 resolution_list.width[idx], resolution_list.height[idx]);
1029 result = camera_set_preview_resolution(hcamcorder->camera,
1030 resolution_list.width[idx], resolution_list.height[idx]);
1032 g_print("\tInvalid command [%d]\n", idx);
1035 resolution_list.count = 0;
1036 if (result == CAMERA_ERROR_NONE)
1037 g_print("\tPASS\n");
1039 g_print("\tFAIL\n");
1041 case '1': /* Setting > Capture Resolution setting */
1042 g_print("\t* Select the preview resolution!\n");
1043 resolution_list.count = 0;
1045 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1046 capture_resolution_test_cb, &resolution_list);
1048 g_print("\tCommand > ");
1050 err = scanf("%d", &idx);
1052 if (resolution_list.count > idx && idx >= 0) {
1053 g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1054 resolution_list.width[idx], resolution_list.height[idx]);
1056 result = camera_set_capture_resolution(hcamcorder->camera,
1057 resolution_list.width[idx], resolution_list.height[idx]);
1059 g_print("\tInvalid command [%d]\n", idx);
1062 resolution_list.count = 0;
1063 if (result == CAMERA_ERROR_NONE)
1064 g_print("\tPASS\n");
1066 g_print("\tFAIL\n");
1068 case '2': /* Setting > Digital zoom level */
1069 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1071 g_print("\tDigital Zoom Not supported\n");
1073 g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1074 err = scanf("%d", &idx);
1076 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1079 case '3': /* Setting > AF mode */
1080 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1081 err = scanf("%d", &idx);
1085 camera_start_focusing(hcamcorder->camera, 0);
1088 camera_cancel_focusing(hcamcorder->camera);
1091 g_print("\tInvalid command [%d]\n", idx);
1095 case '4': /* Setting > AF scan range */
1096 g_print("\t* AF scan range !\n");
1097 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1098 g_print("\tCommand > ");
1099 err = scanf("%d", &idx);
1101 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1103 case '5': /* Setting > Exposure mode */
1104 g_print("* Exposure mode!\n");
1105 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1106 g_print("\n Select Exposure mode \n");
1107 err = scanf("%d", &idx);
1109 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1112 case '6': /* Setting > Exposure value */
1113 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1115 g_print("Not supported !! \n");
1117 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
1118 err = scanf("%d", &idx);
1120 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1123 case '7': /* Setting > F number */
1124 g_print("Not supported !! \n");
1126 case '8': /* Setting > Display reuse hint */
1128 bool reuse_hint = false;
1130 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1131 if (err != CAMERA_ERROR_NONE) {
1132 g_print("failed to get display reuse hint 0x%x\n", err);
1136 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1137 reuse_hint = !reuse_hint;
1138 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1139 g_print("set display reuse hint result : 0x%x\n", err);
1142 case 'i': /* Setting > ISO */
1143 g_print("*ISO !\n");
1144 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1145 err = scanf("%d", &idx);
1147 bret = camera_attr_set_iso(hcamcorder->camera, idx);
1149 case 'r': /* Setting > Rotate camera input when recording */
1150 g_print("*Rotate camera input\n");
1151 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1152 err = scanf("%d", &idx);
1154 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1155 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1156 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1158 case 'f': /* Setting > Flip camera input */
1159 g_print("*Flip camera input\n");
1160 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1161 err = scanf("%d", &idx);
1163 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1164 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1165 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1167 case 'j': /* Setting > Jpeg quality */
1168 g_print("*Jpeg quality !\n");
1169 g_print("\n Select Jpeg quality \n");
1170 err = scanf("%d", &idx);
1172 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1174 case 'p': /* Setting > Picture format */
1175 g_print("* Picture format!\n");
1176 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1177 err = scanf("%d", &idx);
1179 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1180 bret = camera_set_preview_format(hcamcorder->camera, idx);
1181 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1183 case 'E': /* Setting > EXIF orientation */
1184 g_print("* EXIF Orientation\n");
1185 g_print("\t 1. TOP_LEFT\n");
1186 g_print("\t 2. TOP_RIGHT(flipped)\n");
1187 g_print("\t 3. BOTTOM_RIGHT\n");
1188 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1189 g_print("\t 5. LEFT_TOP(flipped)\n");
1190 g_print("\t 6. RIGHT_TOP\n");
1191 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1192 g_print("\t 8. LEFT_BOTTOM\n");
1193 err = scanf("%d", &idx);
1195 if (idx < 1 || idx > 8)
1196 g_print("Wrong INPUT[%d]!! \n", idx);
1198 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1200 case 'F': /* Getting > Get Facing direction */
1201 g_print("* Get facing direction of camera module\n");
1202 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1203 if (CAMERA_ERROR_NONE == err)
1204 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1206 g_print("* Error : %d\n", err);
1208 /* Display / Filter setting */
1209 case 'v': /* Display visible */
1210 g_print("* Display visible setting !\n");
1211 g_print("\n Select Display visible \n");
1212 for (i = 0 ; i < 2 ; i++)
1213 g_print("\t %d. %s\n", i, visible_mode[i]);
1214 err = scanf("%d", &idx);
1216 if (idx == 0 || idx == 1)
1217 bret = camera_set_display_visible(hcamcorder->camera, idx);
1219 g_print("invalid input %d", idx);
1221 case 'o': /* Setting > Display Mode */
1222 g_print("* Display mode!\n");
1223 for (i = 0 ; i < 5 ; i++)
1224 g_print("%d. %s\n", i, display_mode[i]);
1225 err = scanf("%d", &idx);
1227 bret = camera_set_display_mode(hcamcorder->camera, idx);
1229 case 'y': /* Setting > Rotate Display */
1230 g_print("\n Select Rotate mode\n");
1231 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1232 err = scanf("%d", &idx);
1234 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1235 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1236 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1238 case 'Y': /* Setting > Flip Display */
1239 g_print("\n Select Rotate mode\n");
1240 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1241 err = scanf("%d", &idx);
1243 bret = camera_set_display_flip(hcamcorder->camera, idx);
1245 case 'g': /* Setting > Brightness */
1246 g_print("*Brightness !\n");
1247 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1248 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1249 err = scanf("%d", &idx);
1251 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1253 case 'c': /* Setting > Contrast */
1254 g_print("*Contrast !\n");
1255 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1256 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1257 err = scanf("%d", &idx);
1259 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1261 case 'h': /* Setting > Hue */
1262 g_print("*Hue !\n");
1263 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1265 g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1266 err = scanf("%d", &idx);
1268 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1270 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1273 case 'w': /* Setting > White balance */
1274 g_print("*White balance !\n");
1275 g_print("\n Select White balance \n");
1276 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1277 err = scanf("%d", &idx);
1279 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1281 case 't': /* Setting > Color tone */
1282 g_print("*Color tone !\n");
1283 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1284 g_print("\n Select Color tone \n");
1285 err = scanf("%d", &idx);
1287 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1289 case 'd': /* Setting > WDR */
1290 g_print("*WDR !\n");
1291 g_print("\n Select WDR Mode \n");
1292 for (i = 0 ; i < 2 ; i++)
1293 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1294 err = scanf("%d", &idx);
1297 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1299 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1301 case 'e': /* Setting > EV program mode */
1302 g_print("* EV program mode!\n");
1303 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1304 g_print("\n Select EV program mode \n");
1305 err = scanf("%d", &idx);
1307 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1309 case 'R': /* Setting > Display ROI area */
1310 g_print("* Set display roi area. Select x y width height \n");
1311 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1313 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1314 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1315 if (CAMERA_ERROR_NONE != err)
1316 g_print("* Error : %d\n", err);
1318 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1319 if (CAMERA_ERROR_NONE == err)
1320 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1322 g_print("* Error : %d\n", err);
1326 case 'z': /* Setting > Strobe setting */
1327 g_print("*Strobe Mode\n");
1328 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1329 g_print("\n Select Strobe Mode \n");
1330 err = scanf("%d", &idx);
1332 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1334 case 'S': /* Setting > flash state */
1335 g_print("*flash state\n");
1336 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1337 if (CAMERA_ERROR_NONE == err)
1338 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1340 g_print("* Error : %d\n", err);
1342 case 'G': /* Setting > flash brightness */
1343 g_print("*Flash brightness !\n");
1344 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1345 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1346 err = scanf("%d", &idx);
1348 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1350 case 'x': /* Setting > Capture mode ,Muitishot? */
1351 g_print("*Select Capture mode!\n");
1352 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1353 err = scanf("%d", &idx);
1358 g_print("stillshot mode selected and capture callback is set!!!!\n");
1359 hcamcorder->is_multishot = FALSE;
1360 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1363 g_print("HDR Capture mode selected\n");
1364 hcamcorder->is_multishot = FALSE;
1365 g_print("\nSelect HDR capture mode\n");
1366 for (i = 0 ; i < 3 ; i++)
1367 g_print("\t %d. %s\n", i, hdr_mode[i]);
1368 err = scanf("%d", &idx);
1370 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1371 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1373 g_print("invalid input %d\n", idx);
1376 g_print("Wrong input, select again!!\n");
1380 case 'l': /* Setting > Face detection setting */
1381 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1382 g_print("* Face detect mode !\n");
1383 for (i = 0 ; i < 2 ; i++)
1384 g_print("\t %d. %s \n", i, detection_mode[i]);
1385 err = scanf("%d", &idx);
1388 bret = camera_stop_face_detection(hcamcorder->camera);
1390 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1392 g_print("\n invalid input [%d]\n\n", idx);
1394 g_print("face detection_not supported");
1397 case 'k': /* Setting > Anti-handshake */
1398 g_print("*Anti-handshake !\n");
1399 g_print("\n Select Anti-handshake mode \n");
1400 for (i = 0; i < 2; i++)
1401 g_print("\t %d. %s\n", i, ahs_mode[i]);
1402 err = scanf("%d", &idx);
1404 if (idx == 0 || idx == 1)
1405 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1407 g_print("invalid input %d\n", idx);
1409 case 'K': /* Setting > Video-stabilization */
1410 g_print("*Video-stabilization !\n");
1411 g_print("\n Select Video-stabilization mode \n");
1412 for (i = 0 ; i < 2 ; i++)
1413 g_print("\t %d. %s\n", i, vs_mode[i]);
1414 err = scanf("%d", &idx);
1416 if (idx < 0 || idx > 1) {
1417 g_print("invalid input %d\n", idx);
1422 g_print("\n Restart preview with NV12 and 720p resolution\n");
1423 err = camera_stop_preview(hcamcorder->camera);
1424 g_print("stop preview result 0x%x\n", err);
1425 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1426 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1429 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1432 err = camera_start_preview(hcamcorder->camera);
1433 if (err != CAMERA_ERROR_NONE)
1434 g_print("\n Restart FAILED! 0x%x\n", err);
1437 case 'u': /* Touch AF area */
1438 g_print("* Touch AF area !\n");
1439 g_print("\n Input x,y,width,height \n");
1440 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1442 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1444 g_print("Failed to set touch AF area.(%x)\n", err);
1446 g_print("Succeed to set touch AF area.\n");
1448 case 'n': /* file path */
1449 g_print("* File path !\n");
1450 g_print("\n Input file path to save captured data(string) : ");
1451 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1452 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1453 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1455 g_print("\nset file path failed\n");
1458 case 'b': /* back */
1459 hcamcorder->menu_state = MENU_STATE_MAIN;
1462 g_print("\t Invalid input \n");
1466 g_print("\t bret : 0x%x \n", bret);
1472 static void device_state_menu(gchar buf)
1475 camera_device_e device = CAMERA_DEVICE_CAMERA0;
1476 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1479 case '1': /* Get device state */
1481 g_print("\n\tEnter Camera Index[0~9]: ");
1483 ret = scanf("%d", (int *)&device);
1487 g_print("\n\t!!!read input error!!!\n");
1491 if (device < CAMERA_DEVICE_CAMERA0 ||
1492 device > CAMERA_DEVICE_CAMERA9) {
1493 g_print("\n\tinvalid input:[%d], try again...\n", device);
1497 ret = camera_get_device_state(device, &device_state);
1498 g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1499 device, device_state, ret);
1503 case '2': /* Add device state changed callback */
1504 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1505 NULL, &g_camera_device_state_changed_cb_id);
1506 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1508 case '3': /* Remove device state changed callback */
1509 if (g_camera_device_state_changed_cb_id > 0) {
1510 ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1511 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1512 g_camera_device_state_changed_cb_id = 0;
1514 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1517 case 'b': /* back */
1518 hcamcorder->menu_state = MENU_STATE_INIT;
1521 g_print("\n\tinvalid input[%c]\n", buf);
1528 static void device_list_menu(gchar buf)
1532 camera_device_list_s device_list;
1535 case '1': /* Initialize device manager */
1536 ret = camera_device_manager_initialize(&g_device_manager);
1537 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1538 g_device_manager, ret);
1540 case '2': /* Get device list */
1541 memset(&device_list, 0x0, sizeof(camera_device_list_s));
1542 ret = camera_device_manager_get_device_list(g_device_manager, &device_list);
1543 if (ret != CAMERA_ERROR_NONE) {
1544 g_print("\n\tGet device list failed[0x%x]\n", ret);
1548 g_print("\n\tDevice list[count:%d]\n", device_list.count);
1550 for (i = 0 ; i < device_list.count ; i++) {
1551 g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
1552 i, device_list.device[i].type, device_list.device[i].index,
1553 device_list.device[i].name, device_list.device[i].id);
1556 case '3': /* Add device list changed callback */
1557 ret = camera_device_manager_add_device_list_changed_cb(g_device_manager,
1558 _camera_device_list_changed_cb, NULL, &g_camera_device_list_changed_cb_id);
1559 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_list_changed_cb_id);
1561 case '4': /* Remove device list changed callback */
1562 if (g_camera_device_list_changed_cb_id > 0) {
1563 ret = camera_device_manager_remove_device_list_changed_cb(g_device_manager,
1564 g_camera_device_list_changed_cb_id);
1565 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_list_changed_cb_id);
1566 g_camera_device_list_changed_cb_id = 0;
1568 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_list_changed_cb_id);
1571 case '5': /* Deinitialize device manager */
1572 ret = camera_device_manager_deinitialize(g_device_manager);
1573 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1574 g_device_manager, ret);
1575 g_device_manager = NULL;
1577 case 'b': /* back */
1578 hcamcorder->menu_state = MENU_STATE_INIT;
1581 g_print("\n\tinvalid input[%c]\n", buf);
1590 * This function is to execute command.
1592 * @param channel [in] 1st parameter
1594 * @return This function returns TRUE/FALSE
1598 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1602 GError *g_error = NULL;
1604 g_print("\n\tENTER\n");
1606 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1608 g_print("\n\tg_io_channel_read_chars error\n");
1609 g_error_free(g_error);
1616 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1617 switch (hcamcorder->menu_state) {
1618 case MENU_STATE_INIT:
1619 mode_change(buf[0]);
1621 case MENU_STATE_MAIN:
1624 case MENU_STATE_MAIN_SETTING:
1625 setting_menu(buf[0]);
1627 case MENU_STATE_DEVICE_STATE:
1628 device_state_menu(buf[0]);
1630 case MENU_STATE_DEVICE_LIST:
1631 device_list_menu(buf[0]);
1642 g_print("\n\tNo read input\n");
1648 static gboolean init_handle()
1650 hcamcorder->is_multishot = FALSE;
1651 hcamcorder->stillshot_count = 0;
1652 hcamcorder->multishot_count = 0;
1653 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1654 hcamcorder->menu_state = MENU_STATE_INIT;
1655 hcamcorder->elapsed_time = 0;
1662 * This function is to change camcorder mode.
1664 * @param buf [in] user input
1666 * @return This function returns TRUE/FALSE
1668 * @see other functions
1670 static gboolean mode_change(gchar buf)
1673 int camera_type = 0;
1674 int display_type = 0;
1680 g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1681 err = scanf("%d", &camera_type);
1684 g_print("\t!!!read input error!!!\n");
1688 if (camera_type != 0 && camera_type != 1) {
1689 g_print("\t Invalid camera type(%d)\n", camera_type);
1693 g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1694 err = scanf("%d", (int *)&camera_device);
1697 g_print("\t!!!read input error!!!\n");
1701 if (camera_device < 0 || camera_device > 9) {
1702 g_print("\t Invalid camera device(%d)\n", camera_device);
1706 hcamcorder->type = camera_device;
1712 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1715 hcamcorder->menu_state = MENU_STATE_DEVICE_LIST;
1718 g_print("\t Quit Camcorder Testsuite!!\n");
1722 g_print("\t Invalid media type(%c)\n", buf);
1726 g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1728 gettimeofday(&previous_time, NULL);
1730 g_timer_reset(timer);
1733 err = camera_create_network(camera_device, &hcamcorder->camera);
1735 err = camera_create(camera_device, &hcamcorder->camera);
1737 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1740 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1745 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1746 err = scanf("%d", &display_type);
1749 g_print("\t!!!read input error!!!\n");
1753 switch (display_type) {
1755 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1759 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1763 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1767 g_print("\t Invalid display type(%d)\n", display_type);
1772 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1773 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1774 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1775 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1776 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1777 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1778 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1779 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1781 camera_start_preview(hcamcorder->camera);
1783 gettimeofday(¤t_time, NULL);
1784 timersub(¤t_time, &previous_time, &result_time);
1786 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1788 hcamcorder->menu_state = MENU_STATE_MAIN;
1793 static int app_create(void *data)
1795 appdata *app_data = data;
1798 Evas_Object *win = NULL;
1799 Evas_Object *eo = NULL;
1800 Evas_Object *bg = NULL;
1801 Evas_Object *rect = NULL;
1803 if (app_data == NULL) {
1804 g_print("\t\nappdata is NULL\n");
1808 /* use gl backend */
1809 elm_config_accel_preference_set("opengl");
1811 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1813 elm_win_title_set(win, "camera_test");
1814 elm_win_borderless_set(win, EINA_TRUE);
1815 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1816 g_print("\n\tscreen size %dx%d\n\n", w, h);
1817 evas_object_resize(win, w, h);
1818 elm_win_autodel_set(win, EINA_TRUE);
1819 elm_win_alpha_set(win, EINA_TRUE);
1821 g_print("\n\tfailed to get window\n\n");
1825 bg = elm_bg_add(win);
1827 elm_win_resize_object_add(win, bg);
1828 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1829 evas_object_show(bg);
1831 g_print("\n\tfailed to get elm bg\n\n");
1835 rect = evas_object_rectangle_add(evas_object_evas_get(win));
1837 evas_object_color_set(rect, 0, 0, 0, 0);
1838 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1840 g_print("\n\tfailed to get rectangle\n\n");
1844 elm_win_resize_object_add(win, rect);
1845 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1846 evas_object_show(rect);
1848 /* Create evas image object for EVAS surface */
1849 eo = evas_object_image_add(evas_object_evas_get(win));
1850 evas_object_image_size_set(eo, w, h);
1851 evas_object_image_fill_set(eo, 0, 0, w, h);
1852 evas_object_resize(eo, w, h);
1853 evas_object_show(eo);
1855 elm_win_activate(win);
1856 evas_object_show(win);
1858 app_data->win = win;
1861 timer = g_timer_new();
1862 g_timer_reset(timer);
1871 static int app_terminate(void *data)
1873 appdata *app_data = data;
1875 if (app_data == NULL) {
1876 g_print("\n\tappdata is NULL\n");
1881 g_timer_stop(timer);
1882 g_timer_destroy(timer);
1891 * This function is the example main function for mmcamcorder API.
1895 * @return This function returns 0.
1897 * @see other functions
1899 int main(int argc, char **argv)
1903 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1905 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1906 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1908 memset(&ad, 0x0, sizeof(appdata));
1911 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1913 g_print("\n\treturn appcore_efl : %d\n\n", bret);
1916 g_io_channel_unref(stdin_channel);