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 =======================================================================================*/
32 #include <Elementary.h>
33 #include <appcore-efl.h>
35 /*-----------------------------------------------------------------------
36 | GLOBAL VARIABLE DEFINITIONS: |
37 -----------------------------------------------------------------------*/
38 #define EXPORT_API __attribute__((__visibility__("default")))
43 #define PACKAGE "camera_test"
46 static int app_create(void *data);
47 static int app_terminate(void *data);
55 typedef struct _appdata appdata;
57 struct appcore_ops ops = {
59 .terminate = app_terminate,
63 GIOChannel *stdin_channel;
64 camera_device_e cam_info;
66 static int g_camera_device_changed_cb_id;
68 GTimeVal previous_time;
69 GTimeVal current_time;
72 /*-----------------------------------------------------------------------
73 | GLOBAL CONSTANT DEFINITIONS: |
74 -----------------------------------------------------------------------*/
77 /*-----------------------------------------------------------------------
78 | IMPORTED VARIABLE DECLARATIONS: |
79 -----------------------------------------------------------------------*/
82 /*-----------------------------------------------------------------------
83 | IMPORTED FUNCTION DECLARATIONS: |
84 -----------------------------------------------------------------------*/
87 /*-----------------------------------------------------------------------
89 -----------------------------------------------------------------------*/
90 #define DEFAULT_FILE_PATH "/home/owner/media"
91 #define MAX_FILE_NAME_LENGTH 256
92 #define MAX_FILE_PATH_LENGTH (MAX_FILE_NAME_LENGTH - 20)
94 #define CHECK_MM_ERROR(expr) \
99 g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
106 #define SAFE_FREE(x) \
113 #define SENSOR_WHITEBALANCE_NUM 10
114 #define SENSOR_COLOR_TONE_NUM 31
115 #define SENSOR_FLIP_NUM 3
116 #define SENSOR_PROGRAM_MODE_NUM 15
117 #define SENSOR_FOCUS_NUM 6
118 #define SENSOR_INPUT_ROTATION 4
119 #define SENSOR_AF_SCAN_NUM 4
120 #define SENSOR_ISO_NUM 8
121 #define SENSOR_EXPOSURE_NUM 9
122 #define SENSOR_IMAGE_FORMAT 9
125 /*-----------------------------------------------------------------------
126 | LOCAL CONSTANT DEFINITIONS: |
127 -----------------------------------------------------------------------*/
129 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
130 MODE_AUDIO, /* audio recording*/
141 /*-----------------------------------------------------------------------
142 | LOCAL DATA TYPE DEFINITIONS: |
143 -----------------------------------------------------------------------*/
144 typedef struct _cam_handle {
147 int is_multishot; /* flag for multishot mode */
148 int stillshot_count; /* stillshot count */
149 int multishot_count; /* multishot count */
150 char file_path[MAX_FILE_PATH_LENGTH]; /* file path for captured data */
152 unsigned long long elapsed_time;
162 camera_attr_exposure_mode_e mode;
167 camera_attr_iso_e mode;
172 camera_rotation_e mode;
174 } camera_rotation_stack;
177 /*---------------------------------------------------------------------------
178 | LOCAL VARIABLE DEFINITIONS: |
179 ---------------------------------------------------------------------------*/
180 static cam_handle_t *hcamcorder;
182 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
195 const char *ct[SENSOR_COLOR_TONE_NUM] = {
221 "SELECTVE_COLOR_RED",
222 "SELECTVE_COLOR_GREEN",
223 "SELECTVE_COLOR_BLUE",
224 "SELECTVE_COLOR_YELLOW",
225 "SELECTVE_COLOR_RED_YELLOW",
229 const char *flip[SENSOR_FLIP_NUM] = {
235 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
253 const char *focus_mode[SENSOR_FOCUS_NUM] = {
262 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
269 const char *iso_mode[SENSOR_ISO_NUM] = {
280 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
288 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
300 const char *face_zoom_mode[] = {
305 const char *display_mode[] = {
307 "Original Size mode",
309 "Cropped Full Screen mode",
313 const char *capture_sound[] = {
319 const char *rotate_mode[] = {
326 const char* strobe_mode[] = {
330 "Strobe RedEyeReduction",
332 "Strobe FrontCurtain",
333 "Strobe RearCurtain",
337 const char *detection_mode[2] = {
338 "Face Detection OFF",
342 const char *wdr_mode[] = {
348 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
355 const char *hdr_mode[] = {
358 "HDR ON and Original",
361 const char *ahs_mode[] = {
362 "Anti-handshake OFF",
364 "Anti-handshake AUTO",
365 "Anti-handshake MOVIE",
368 const char *vs_mode[] = {
369 "Video-stabilization OFF",
370 "Video-stabilization ON",
373 const char *visible_mode[] = {
378 const char *facing_direction[] = {
384 /*---------------------------------------------------------------------------
385 | LOCAL FUNCTION PROTOTYPES: |
386 ---------------------------------------------------------------------------*/
387 static void print_menu();
388 static gboolean cmd_input(GIOChannel *channel);
389 static gboolean mode_change(gchar buf);
390 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
393 static inline void flush_stdin()
396 while ((ch = getchar()) != EOF && ch != '\n');
399 static bool _release_idle_event_callback(void *data)
401 g_print("destroy camera handle\n\n");
403 camera_destroy(hcamcorder->camera);
404 hcamcorder->camera = NULL;
405 hcamcorder->menu_state = MENU_STATE_INIT;
411 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
413 g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
416 case CAMERA_ERROR_RESOURCE_CONFLICT:
417 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
419 case CAMERA_ERROR_SECURITY_RESTRICTED:
420 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
422 case CAMERA_ERROR_SERVICE_DISCONNECTED:
423 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
424 g_idle_add_full(G_PRIORITY_DEFAULT,
425 (GSourceFunc)_release_idle_event_callback,
435 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
437 g_print("\ncamera state changed %d -> %d\n", previous, current);
441 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
443 g_print("\ncamera device[%d] state changed to %d\n", device, state);
447 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
449 g_print("\ncamera interrupted callback called[state %d -> %d, policy %d]\n",
450 previous, current, policy);
454 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
456 g_print("\ncamera interrupt started callback called[state %d, policy %d]\n", state, policy);
460 void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
463 FILE *fp = fopen("/opt/usr/media/test.yuv", "a");
465 g_print("\n============ file open failed ===========================\n");
469 switch (frame->num_of_planes) {
471 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
473 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
474 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
476 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
477 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
478 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
483 g_print("file write done ---\n");
488 g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
489 frame->format, frame->width, frame->height, frame->num_of_planes);
496 static bool preview_resolution_cb(int width, int height, void *user_data)
498 resolution_stack *data = (resolution_stack *)user_data;
501 g_print("NULL data\n");
505 data->width[data->count] = width;
506 data->height[data->count] = height;
508 g_print("%d. %dx%d\n", data->count, width, height);
515 static bool capture_resolution_test_cb(int width, int height, void *user_data)
517 resolution_stack *data = (resolution_stack *)user_data;
520 g_print("NULL data\n");
524 data->width[data->count] = width;
525 data->height[data->count] = height;
527 g_print("%d. %dx%d\n", data->count, width, height);
534 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
536 g_print("%d.%s\n", mode, af_scan[mode]);
540 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
542 exposure_stack *data = (exposure_stack *)user_data;
545 g_print("NULL data\n");
552 g_print("%d.%s\n", mode, exposure_mode[mode]);
556 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
558 g_print("%d.%s\n", mode, iso_mode[mode]);
562 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
564 camera_rotation_stack *data = (camera_rotation_stack *)user_data;
567 g_print("NULL data\n");
574 g_print("%d.%s\n", mode, camera_rotation[mode]);
579 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
581 g_print("%d.%s\n", mode, image_fmt[mode]);
585 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
587 g_print("%d.%s\n", mode, wb[mode]);
591 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
593 g_print("%d.%s\n", mode, ct[mode]);
597 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
599 g_print("%d.%s\n", mode, program_mode[mode]);
603 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
605 g_print("%d.%s\n", mode, strobe_mode[mode]);
609 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
611 g_print("face detected!! - count %d\n", count);
614 for (i = 0 ; i < count ; i++)
615 g_print("%d) - %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
620 static void _file_write(char *path, void *data, int size)
624 if (!path || !data || size <= 0) {
625 g_print("ERROR %p %p %d\n", path, data, size);
629 fp = fopen(path, "w");
631 g_print("open error! [%s], errno %d\n", path, errno);
634 g_print("open success [%s]\n", path);
635 if (fwrite(data, size, 1, fp) != 1)
636 g_print("write error! errno %d\n", errno);
638 g_print("write success [%s]\n", path);
645 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
647 char m_filename[MAX_FILE_NAME_LENGTH];
651 if (hcamcorder->is_multishot) {
652 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
653 hcamcorder->file_path, hcamcorder->multishot_count++);
655 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
656 hcamcorder->file_path, hcamcorder->stillshot_count++);
659 _file_write(m_filename, image->data, image->size);
665 static void capture_completed_cb(void *user_data)
667 camera_start_preview(hcamcorder->camera);
674 static void print_menu()
676 switch (hcamcorder->menu_state) {
677 case MENU_STATE_INIT:
678 g_print("\n\t=======================================\n");
679 g_print("\t CAMERA_TESTSUITE\n");
680 g_print("\t=======================================\n");
681 g_print("\t '1' Video Capture\n");
682 g_print("\t '2' Add camera device state changed callback\n");
683 g_print("\t '3' Remove camera device state changed callback\n");
684 g_print("\t '4' Get camera device state\n");
685 g_print("\t 'q' Exit\n");
686 g_print("\t=======================================\n");
688 g_print("\t Enter the media type:\n\t");
690 case MENU_STATE_MAIN:
691 g_print("\n\t=======================================\n");
692 if (cam_info == CAMERA_DEVICE_CAMERA1)
693 g_print("\t Video Capture (Front camera)\n");
694 else if (cam_info == CAMERA_DEVICE_CAMERA0)
695 g_print("\t Video Capture (Rear camera)\n");
696 g_print("\t=======================================\n");
698 g_print("\t '1' Stillshot test\n");
699 g_print("\t '2' Multishot test\n");
700 g_print("\t '3' Setting\n");
701 g_print("\t '4' Change device (CAMERA0 <-> CAMERA1)\n");
702 g_print("\t '5' Add preview callback\n");
703 g_print("\t '6' Remove preview callback\n");
704 g_print("\t 'b' back\n");
705 g_print("\t=======================================\n");
707 case MENU_STATE_SETTING:
708 g_print("\n\t=======================================\n");
709 g_print("\t Video Capture > Setting\n");
710 g_print("\t=======================================\n");
711 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
712 g_print("\t '0' Preview resolution \n");
713 g_print("\t '1' Capture resolution \n");
714 g_print("\t '2' Digital zoom level \n");
715 g_print("\t '3' AF mode \n");
716 g_print("\t '4' AF scan range \n");
717 g_print("\t '5' Exposure mode \n");
718 g_print("\t '6' Exposure value \n");
719 g_print("\t '7' F number \n");
720 g_print("\t '8' Display reuse hint \n");
721 g_print("\t 'i' ISO \n");
722 g_print("\t 'r' Rotate camera input \n");
723 g_print("\t 'f' Flip camera input \n");
724 g_print("\t 'j' Jpeg quality \n");
725 g_print("\t 'p' Picture format \n");
726 g_print("\t 'E' EXIF orientation \n");
727 g_print("\t 'F' Get facing direction of camera module\n");
728 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
729 g_print("\t 'v' Visible \n");
730 g_print("\t 'o' Output mode \n");
731 g_print("\t 'y' Rotate display \n");
732 g_print("\t 'Y' Flip display \n");
733 g_print("\t 'g' Brightness \n");
734 g_print("\t 'c' Contrast \n");
735 g_print("\t 'h' Hue \n");
736 g_print("\t 'w' White balance \n");
737 g_print("\t 't' Color tone \n");
738 g_print("\t 'd' WDR \n");
739 g_print("\t 'e' EV program mode \n");
740 g_print("\t 'R' Display ROI area \n");
741 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
742 g_print("\t 'z' Strobe (Flash) \n");
743 g_print("\t 'S' Strobe (Flash) state\n");
744 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
745 g_print("\t 'l' Face detection \n");
746 g_print("\t 'k' Anti-handshake \n");
747 g_print("\t 'K' Video-stabilization \n");
748 g_print("\t 'u' Touch AF area \n");
749 g_print("\t 'n' Set file path to write captured image\n");
750 g_print("\t 'b' back\n");
751 g_print("\t=======================================\n");
754 g_print("\n\tunknow menu state !!\n");
762 static void main_menu(gchar buf)
767 camera_state_e capi_state = CAMERA_STATE_NONE;
770 case '1': /* Capture */
771 hcamcorder->is_multishot = FALSE;
772 camera_get_state(hcamcorder->camera, &capi_state);
773 camera_attr_set_image_quality(hcamcorder->camera, 100);
774 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
775 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
777 case '2': /* multishot Capture */
778 g_print("multishot capture");
779 hcamcorder->is_multishot = TRUE;
781 g_print("\n\tinput interval(ms) : ");
782 err = scanf("%d", &interval);
784 g_print("\n\tinput count : ");
785 err = scanf("%d", &count);
786 camera_attr_set_image_quality(hcamcorder->camera, 100);
787 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
788 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
790 camera_start_preview(hcamcorder->camera);
792 case '3': /* Setting */
793 hcamcorder->menu_state = MENU_STATE_SETTING;
795 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
796 camera_set_display_reuse_hint(hcamcorder->camera, true);
798 camera_stop_preview(hcamcorder->camera);
800 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0) {
801 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
803 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
806 camera_change_device(hcamcorder->camera, hcamcorder->type);
808 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
809 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
810 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
811 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
813 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
815 camera_start_preview(hcamcorder->camera);
818 camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
821 camera_unset_preview_cb(hcamcorder->camera);
824 camera_stop_preview(hcamcorder->camera);
825 camera_destroy(hcamcorder->camera);
826 hcamcorder->camera = NULL;
827 hcamcorder->menu_state = MENU_STATE_INIT;
831 g_print("\t Invalid input \n");
839 static void setting_menu(gchar buf)
855 case '0': /* Setting > Preview Resolution setting */
856 g_print("*Select the preview resolution!\n");
857 resolution_stack resolution_list;
858 resolution_list.count = 0;
860 camera_foreach_supported_preview_resolution(hcamcorder->camera,
861 preview_resolution_cb, &resolution_list);
864 err = scanf("%d", &idx);
865 if (resolution_list.count > idx && idx >= 0) {
866 g_print("-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
867 resolution_list.width[idx], resolution_list.height[idx]);
869 result = camera_set_preview_resolution(hcamcorder->camera,
870 resolution_list.width[idx], resolution_list.height[idx]);
872 g_print("invalid input %d\n", idx);
875 resolution_list.count = 0;
881 case '1': /* Setting > Capture Resolution setting */
882 g_print("*Select the preview resolution!\n");
883 g_print("-----------------CAPTURE RESOLUTION TEST: ---------------------\n");
884 resolution_list.count = 0;
886 camera_foreach_supported_capture_resolution(hcamcorder->camera,
887 capture_resolution_test_cb, &resolution_list);
890 err = scanf("%d", &idx);
891 if (resolution_list.count > idx && idx >= 0) {
893 result = camera_set_capture_resolution(hcamcorder->camera,
894 resolution_list.width[idx], resolution_list.height[idx]);
896 g_print("camera_set_capture_resolution with width =%d, height=%d ret=0x%x\n",
897 resolution_list.width[idx], resolution_list.height[idx], result);
899 g_print("invalid input %d\n", idx);
902 resolution_list.count = 0;
909 case '2': /* Setting > Digital zoom level */
910 g_print("*Digital zoom level !\n");
911 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
913 g_print("Not supported !! \n");
916 g_print("\n Select Digital zoom level min %d - max %d\n", min, max);
917 err = scanf("%d", &idx);
918 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
921 case '3': /* Setting > AF mode */
922 g_print("*AF mode !\n");
923 g_print("\t1. AF Start !\n");
924 g_print("\t2. AF Stop !\n\n");
926 err = scanf("%d", &idx);
929 camera_start_focusing(hcamcorder->camera, 0);
932 camera_cancel_focusing(hcamcorder->camera);
935 g_print("Wrong Input[%d] !! \n", idx);
939 case '4': /* Setting > AF scan range */
940 g_print("*AF scan range !\n");
941 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
943 err = scanf("%d", &idx);
944 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
946 case '5': /* Setting > Exposure mode */
947 g_print("* Exposure mode!\n");
948 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
950 g_print("\n Select Exposure mode \n");
951 err = scanf("%d", &idx);
952 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
955 case '6': /* Setting > Exposure value */
956 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
958 g_print("Not supported !! \n");
961 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
962 err = scanf("%d", &idx);
963 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
966 case '7': /* Setting > F number */
967 g_print("Not supported !! \n");
969 case '8': /* Setting > Display reuse hint */
971 bool reuse_hint = false;
973 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
974 if (err != CAMERA_ERROR_NONE) {
975 g_print("failed to get display reuse hint 0x%x\n", err);
979 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
980 reuse_hint = !reuse_hint;
981 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
982 g_print("set display reuse hint result : 0x%x\n", err);
985 case 'i': /* Setting > ISO */
987 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
989 err = scanf("%d", &idx);
990 bret = camera_attr_set_iso(hcamcorder->camera, idx);
992 case 'r': /* Setting > Rotate camera input when recording */
993 g_print("*Rotate camera input\n");
994 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
996 err = scanf("%d", &idx);
997 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
998 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
999 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1001 case 'f': /* Setting > Flip camera input */
1003 g_print("*Flip camera input\n");
1004 g_print(" 0. Flip NONE\n");
1005 g_print(" 1. Flip HORIZONTAL\n");
1006 g_print(" 2. Flip VERTICAL\n");
1007 g_print(" 3. Flip BOTH\n");
1008 err = scanf("%d", &idx);
1009 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1010 camera_attr_set_stream_flip(hcamcorder->camera, idx);
1011 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1013 case 'j': /* Setting > Jpeg quality */
1014 g_print("*Jpeg quality !\n");
1016 g_print("\n Select Jpeg quality \n");
1017 err = scanf("%d", &idx);
1018 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1020 case 'p': /* Setting > Picture format */
1021 g_print("* Picture format!\n");
1022 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1024 err = scanf("%d", &idx);
1025 bret = camera_set_preview_format(hcamcorder->camera, idx);
1026 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1027 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1029 case 'E': /* Setting > EXIF orientation */
1030 g_print("* EXIF Orientation\n");
1031 g_print("\t 1. TOP_LEFT\n");
1032 g_print("\t 2. TOP_RIGHT(flipped)\n");
1033 g_print("\t 3. BOTTOM_RIGHT\n");
1034 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1035 g_print("\t 5. LEFT_TOP(flipped)\n");
1036 g_print("\t 6. RIGHT_TOP\n");
1037 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1038 g_print("\t 8. LEFT_BOTTOM\n");
1040 err = scanf("%d", &idx);
1041 if (idx < 1 || idx > 8)
1042 g_print("Wrong INPUT[%d]!! \n", idx);
1044 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1046 case 'F': /* Getting > Get Facing direction */
1047 g_print("* Get facing direction of camera module\n");
1048 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1049 if (CAMERA_ERROR_NONE == err)
1050 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1052 g_print("* Error : %d\n", err);
1054 /* Display / Filter setting */
1055 case 'v': /* Display visible */
1056 g_print("* Display visible setting !\n");
1057 g_print("\n Select Display visible \n");
1059 for (i = 0 ; i < 2 ; i++)
1060 g_print("\t %d. %s\n", i, visible_mode[i]);
1061 err = scanf("%d", &idx);
1062 if (idx == 0 || idx == 1)
1063 bret = camera_set_display_visible(hcamcorder->camera, idx);
1065 g_print("invalid input %d", idx);
1067 case 'o': /* Setting > Display Mode */
1068 g_print("* Display mode!\n");
1070 for (i = 0 ; i < 5 ; i++)
1071 g_print("%d. %s\n", i, display_mode[i]);
1072 err = scanf("%d", &idx);
1073 bret = camera_set_display_mode(hcamcorder->camera, idx);
1075 case 'y': /* Setting > Rotate Display */
1077 g_print("\n Select Rotate mode\n");
1078 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1079 err = scanf("%d", &idx);
1080 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1081 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1082 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1084 case 'Y': /* Setting > Flip Display */
1086 g_print("\n Select Rotate mode\n");
1087 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1088 err = scanf("%d", &idx);
1089 bret = camera_set_display_flip(hcamcorder->camera, idx);
1091 case 'g': /* Setting > Brightness */
1092 g_print("*Brightness !\n");
1093 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1095 g_print("\n Select brightness min (%d) -max(%d)", min, max);
1096 err = scanf("%d", &idx);
1097 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1099 case 'c': /* Setting > Contrast */
1100 g_print("*Contrast !\n");
1101 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1103 g_print("\n Select Contrast min(%d)-max(%d)", min, max);
1104 err = scanf("%d", &idx);
1105 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1107 case 'h': /* Setting > Hue */
1108 g_print("*Hue !\n");
1109 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1112 g_print("\n Select Hue min(%d)-max(%d)", min, max);
1113 err = scanf("%d", &idx);
1114 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1116 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1119 case 'w': /* Setting > White balance */
1120 g_print("*White balance !\n");
1122 g_print("\n Select White balance \n");
1123 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1124 err = scanf("%d", &idx);
1125 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1127 case 't': /* Setting > Color tone */
1128 g_print("*Color tone !\n");
1129 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1130 g_print("\n Select Color tone \n");
1132 err = scanf("%d", &idx);
1133 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1135 case 'd': /* Setting > WDR */
1136 g_print("*WDR !\n");
1137 g_print("\n Select WDR Mode \n");
1139 for (i = 0 ; i < 2 ; i++)
1140 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1141 err = scanf("%d", &idx);
1143 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1145 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1147 case 'e': /* Setting > EV program mode */
1148 g_print("* EV program mode!\n");
1149 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1150 g_print("\n Select EV program mode \n");
1152 err = scanf("%d", &idx);
1153 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1155 case 'R': /* Setting > Display ROI area */
1156 g_print("* Set display roi area. Select x y width height \n");
1158 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1159 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1160 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1161 if (CAMERA_ERROR_NONE != err)
1162 g_print("* Error : %d\n", err);
1164 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1165 if (CAMERA_ERROR_NONE == err)
1166 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1168 g_print("* Error : %d\n", err);
1172 case 'z': /* Setting > Strobe setting */
1173 g_print("*Strobe Mode\n");
1174 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1175 g_print("\n Select Strobe Mode \n");
1177 err = scanf("%d", &idx);
1178 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1180 case 'S': /* Setting > flash state */
1181 g_print("*flash state\n");
1182 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1183 if (CAMERA_ERROR_NONE == err)
1184 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1186 g_print("* Error : %d\n", err);
1188 case 'x': /* Setting > Capture mode ,Muitishot? */
1189 g_print("*Select Capture mode!\n");
1191 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1192 err = scanf("%d", &idx);
1196 g_print("stillshot mode selected and capture callback is set!!!!\n");
1197 hcamcorder->is_multishot = FALSE;
1198 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1201 g_print("HDR Capture mode selected\n");
1202 hcamcorder->is_multishot = FALSE;
1203 g_print("\nSelect HDR capture mode\n");
1205 for (i = 0 ; i < 3 ; i++)
1206 g_print("\t %d. %s\n", i, hdr_mode[i]);
1207 err = scanf("%d", &idx);
1208 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1209 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1211 g_print("invalid input %d\n", idx);
1214 g_print("Wrong input, select again!!\n");
1218 case 'l': /* Setting > Face detection setting */
1219 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1220 g_print("* Face detect mode !\n");
1222 for (i = 0 ; i < 2 ; i++)
1223 g_print("\t %d. %s \n", i, detection_mode[i]);
1224 err = scanf("%d", &idx);
1226 bret = camera_stop_face_detection(hcamcorder->camera);
1228 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1230 g_print("\n invalid input [%d]\n\n", idx);
1232 g_print("face detection_not supported");
1235 case 'k': /* Setting > Anti-handshake */
1236 g_print("*Anti-handshake !\n");
1237 g_print("\n Select Anti-handshake mode \n");
1239 for (i = 0; i < 2; i++)
1240 g_print("\t %d. %s\n", i, ahs_mode[i]);
1241 err = scanf("%d", &idx);
1242 if (idx == 0 || idx == 1)
1243 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1245 g_print("invalid input %d\n", idx);
1247 case 'K': /* Setting > Video-stabilization */
1248 g_print("*Video-stabilization !\n");
1249 g_print("\n Select Video-stabilization mode \n");
1251 for (i = 0 ; i < 2 ; i++)
1252 g_print("\t %d. %s\n", i, vs_mode[i]);
1253 err = scanf("%d", &idx);
1255 if (idx < 0 || idx > 1) {
1256 g_print("invalid input %d\n", idx);
1261 g_print("\n Restart preview with NV12 and 720p resolution\n");
1262 err = camera_stop_preview(hcamcorder->camera);
1263 g_print("stop preview result 0x%x\n", err);
1264 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1265 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1268 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1271 err = camera_start_preview(hcamcorder->camera);
1272 if (err != CAMERA_ERROR_NONE)
1273 g_print("\n Restart FAILED! 0x%x\n", err);
1276 case 'u': /* Touch AF area */
1277 g_print("* Touch AF area !\n");
1279 g_print("\n Input x,y,width,height \n");
1280 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1281 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1283 g_print("Failed to set touch AF area.(%x)\n", err);
1285 g_print("Succeed to set touch AF area.\n");
1287 case 'n': /* file path */
1288 g_print("* File path !\n");
1290 g_print("\n Input file path to save captured data(string) : ");
1291 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1292 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1293 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1295 g_print("\nset file path failed\n");
1298 case 'b': /* back */
1299 hcamcorder->menu_state = MENU_STATE_MAIN;
1302 g_print("\t Invalid input \n");
1306 g_print("\t bret : 0x%x \n", bret);
1313 * This function is to execute command.
1315 * @param channel [in] 1st parameter
1317 * @return This function returns TRUE/FALSE
1321 static gboolean cmd_input(GIOChannel *channel)
1325 GError *g_error = NULL;
1327 g_print("\n\tENTER\n");
1329 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1331 g_print("\n\tg_io_channel_read_chars error\n");
1332 g_error_free(g_error);
1339 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1340 switch (hcamcorder->menu_state) {
1341 case MENU_STATE_INIT:
1342 mode_change(buf[0]);
1344 case MENU_STATE_MAIN:
1347 case MENU_STATE_SETTING:
1348 setting_menu(buf[0]);
1359 g_print("\n\tNo read input\n");
1365 static gboolean init_handle()
1367 hcamcorder->is_multishot = FALSE;
1368 hcamcorder->stillshot_count = 0;
1369 hcamcorder->multishot_count = 0;
1370 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1371 hcamcorder->menu_state = MENU_STATE_INIT;
1372 hcamcorder->elapsed_time = 0;
1379 * This function is to change camcorder mode.
1381 * @param buf [in] user input
1383 * @return This function returns TRUE/FALSE
1385 * @see other functions
1387 static gboolean mode_change(gchar buf)
1390 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1391 char camera_type = '\0';
1392 char display_type = '\0';
1398 g_print("\n\tEnter the Camera Type[0 ~ 9]\n");
1400 err = scanf("%c", &camera_type);
1402 g_print("\t!!!read input error!!!\n");
1406 if (camera_type < '0' || camera_type > '9') {
1407 g_print("\t Invalid camera type(%c)\n", camera_type);
1411 hcamcorder->type = cam_info = camera_type - '0';
1417 err = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1418 NULL, &g_camera_device_changed_cb_id);
1419 g_print("add result 0x%x - cb id %d\n", err, g_camera_device_changed_cb_id);
1422 if (g_camera_device_changed_cb_id > 0) {
1423 err = camera_remove_device_state_changed_cb(g_camera_device_changed_cb_id);
1424 g_camera_device_changed_cb_id = 0;
1425 g_print("remove result 0x%x\n", err);
1427 g_print("invalid callback id %d\n", g_camera_device_changed_cb_id);
1431 err = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &device_state);
1432 g_print("get result 0x%x - state %d\n", err, device_state);
1435 g_print("\t Quit Camcorder Testsuite!!\n");
1439 g_print("\t Invalid media type(%c)\n", buf);
1443 g_print("\n[camcorder_create - type %d]\n", cam_info);
1445 g_get_current_time(&previous_time);
1447 g_timer_reset(timer);
1449 err = camera_create(cam_info, &hcamcorder->camera);
1451 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1454 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1459 g_print("\n\tEnter the Display Type\n");
1460 g_print("\t'1' OVERLAY surface\n");
1461 g_print("\t'2' EVAS surface\n");
1462 g_print("\t'3' NONE surface\n");
1464 err = scanf("%c", &display_type);
1466 g_print("\t!!!read input error!!!\n");
1470 switch (display_type) {
1472 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1476 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1480 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1484 g_print("\t Invalid display type(%c)\n", display_type);
1489 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1490 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1491 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1492 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1493 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1494 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1495 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1496 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1498 camera_start_preview(hcamcorder->camera);
1500 g_get_current_time(¤t_time);
1501 timersub(¤t_time, &previous_time, &result_time);
1503 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1505 hcamcorder->menu_state = MENU_STATE_MAIN;
1512 static int app_create(void *data)
1514 appdata *app_data = data;
1517 Evas_Object *win = NULL;
1518 Evas_Object *eo = NULL;
1519 Evas_Object *bg = NULL;
1520 Evas_Object *rect = NULL;
1522 if (app_data == NULL) {
1523 g_print("\t\nappdata is NULL\n");
1527 /* use gl backend */
1528 elm_config_accel_preference_set("opengl");
1530 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1532 elm_win_title_set(win, "camera_test");
1533 elm_win_borderless_set(win, EINA_TRUE);
1534 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1535 g_print("\n\tscreen size %dx%d\n\n", w, h);
1536 evas_object_resize(win, w, h);
1537 elm_win_autodel_set(win, EINA_TRUE);
1538 elm_win_alpha_set(win, EINA_TRUE);
1540 g_print("\n\tfailed to get window\n\n");
1544 bg = elm_bg_add(win);
1546 elm_win_resize_object_add(win, bg);
1547 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1548 evas_object_show(bg);
1550 g_print("\n\tfailed to get elm bg\n\n");
1554 rect = evas_object_rectangle_add(evas_object_evas_get(win));
1556 evas_object_color_set(rect, 0, 0, 0, 0);
1557 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1559 g_print("\n\tfailed to get rectangle\n\n");
1563 elm_win_resize_object_add(win, rect);
1564 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1565 evas_object_show(rect);
1567 /* Create evas image object for EVAS surface */
1568 eo = evas_object_image_add(evas_object_evas_get(win));
1569 evas_object_image_size_set(eo, w, h);
1570 evas_object_image_fill_set(eo, 0, 0, w, h);
1571 evas_object_resize(eo, w, h);
1572 evas_object_show(eo);
1574 elm_win_activate(win);
1575 evas_object_show(win);
1577 app_data->win = win;
1580 timer = g_timer_new();
1581 g_timer_reset(timer);
1590 static int app_terminate(void *data)
1592 appdata *app_data = data;
1594 if (app_data == NULL) {
1595 g_print("\n\tappdata is NULL\n");
1600 g_timer_stop(timer);
1601 g_timer_destroy(timer);
1610 * This function is the example main function for mmcamcorder API.
1614 * @return This function returns 0.
1616 * @see other functions
1618 int main(int argc, char **argv)
1622 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1624 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1625 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1627 memset(&ad, 0x0, sizeof(appdata));
1630 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1632 g_print("\n\treturn appcore_efl : %d\n\n", bret);
1635 g_io_channel_unref(stdin_channel);