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 static bool preview_resolution_cb(int width, int height, void *user_data)
462 resolution_stack *data = (resolution_stack *)user_data;
465 g_print("NULL data\n");
469 data->width[data->count] = width;
470 data->height[data->count] = height;
472 g_print("%d. %dx%d\n", data->count, width, height);
479 static bool capture_resolution_test_cb(int width, int height, void *user_data)
481 resolution_stack *data = (resolution_stack *)user_data;
484 g_print("NULL data\n");
488 data->width[data->count] = width;
489 data->height[data->count] = height;
491 g_print("%d. %dx%d\n", data->count, width, height);
498 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
500 g_print("%d.%s\n", mode, af_scan[mode]);
504 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
506 exposure_stack *data = (exposure_stack *)user_data;
509 g_print("NULL data\n");
516 g_print("%d.%s\n", mode, exposure_mode[mode]);
520 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
522 g_print("%d.%s\n", mode, iso_mode[mode]);
526 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
528 camera_rotation_stack *data = (camera_rotation_stack *)user_data;
531 g_print("NULL data\n");
538 g_print("%d.%s\n", mode, camera_rotation[mode]);
543 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
545 g_print("%d.%s\n", mode, image_fmt[mode]);
549 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
551 g_print("%d.%s\n", mode, wb[mode]);
555 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
557 g_print("%d.%s\n", mode, ct[mode]);
561 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
563 g_print("%d.%s\n", mode, program_mode[mode]);
567 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
569 g_print("%d.%s\n", mode, strobe_mode[mode]);
573 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
575 g_print("face detected!! - count %d\n", count);
578 for (i = 0 ; i < count ; i++)
579 g_print("%d) - %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
584 static void _file_write(char *path, void *data, int size)
588 if (!path || !data || size <= 0) {
589 g_print("ERROR %p %p %d\n", path, data, size);
593 fp = fopen(path, "w");
595 g_print("open error! [%s], errno %d\n", path, errno);
598 g_print("open success [%s]\n", path);
599 if (fwrite(data, size, 1, fp) != 1)
600 g_print("write error! errno %d\n", errno);
602 g_print("write success [%s]\n", path);
609 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
611 char m_filename[MAX_FILE_NAME_LENGTH];
615 if (hcamcorder->is_multishot) {
616 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
617 hcamcorder->file_path, hcamcorder->multishot_count++);
619 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
620 hcamcorder->file_path, hcamcorder->stillshot_count++);
623 _file_write(m_filename, image->data, image->size);
629 static void capture_completed_cb(void *user_data)
631 camera_start_preview(hcamcorder->camera);
638 static void print_menu()
640 switch (hcamcorder->menu_state) {
641 case MENU_STATE_INIT:
642 g_print("\n\t=======================================\n");
643 g_print("\t CAMERA_TESTSUITE\n");
644 g_print("\t=======================================\n");
645 g_print("\t '1' Video Capture - Front Camera\n");
646 g_print("\t '2' Video Capture - Rear Camera\n");
647 g_print("\t '3' Add camera device state changed callback\n");
648 g_print("\t '4' Remove camera device state changed callback\n");
649 g_print("\t '5' Get camera device state\n");
650 g_print("\t 'q' Exit\n");
651 g_print("\t=======================================\n");
653 g_print("\t Enter the media type:\n\t");
655 case MENU_STATE_MAIN:
656 g_print("\n\t=======================================\n");
657 if (cam_info == CAMERA_DEVICE_CAMERA1)
658 g_print("\t Video Capture (Front camera)\n");
659 else if (cam_info == CAMERA_DEVICE_CAMERA0)
660 g_print("\t Video Capture (Rear camera)\n");
661 g_print("\t=======================================\n");
663 g_print("\t '1' Stillshot test\n");
664 g_print("\t '2' Multishot test\n");
665 g_print("\t '3' Setting\n");
666 g_print("\t '4' Change device (Rear <-> Front)\n");
667 g_print("\t 'b' back\n");
668 g_print("\t=======================================\n");
670 case MENU_STATE_SETTING:
671 g_print("\n\t=======================================\n");
672 g_print("\t Video Capture > Setting\n");
673 g_print("\t=======================================\n");
674 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
675 g_print("\t '0' Preview resolution \n");
676 g_print("\t '1' Capture resolution \n");
677 g_print("\t '2' Digital zoom level \n");
678 g_print("\t '3' AF mode \n");
679 g_print("\t '4' AF scan range \n");
680 g_print("\t '5' Exposure mode \n");
681 g_print("\t '6' Exposure value \n");
682 g_print("\t '7' F number \n");
683 g_print("\t '8' Display reuse hint \n");
684 g_print("\t 'i' ISO \n");
685 g_print("\t 'r' Rotate camera input \n");
686 g_print("\t 'f' Flip camera input \n");
687 g_print("\t 'j' Jpeg quality \n");
688 g_print("\t 'p' Picture format \n");
689 g_print("\t 'E' EXIF orientation \n");
690 g_print("\t 'F' Get facing direction of camera module\n");
691 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
692 g_print("\t 'v' Visible \n");
693 g_print("\t 'o' Output mode \n");
694 g_print("\t 'y' Rotate display \n");
695 g_print("\t 'Y' Flip display \n");
696 g_print("\t 'g' Brightness \n");
697 g_print("\t 'c' Contrast \n");
698 g_print("\t 'w' White balance \n");
699 g_print("\t 't' Color tone \n");
700 g_print("\t 'd' WDR \n");
701 g_print("\t 'e' EV program mode \n");
702 g_print("\t 'R' Display ROI area \n");
703 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
704 g_print("\t 'z' Strobe (Flash) \n");
705 g_print("\t 'S' Strobe (Flash) state\n");
706 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
707 g_print("\t 'l' Face detection \n");
708 g_print("\t 'k' Anti-handshake \n");
709 g_print("\t 'K' Video-stabilization \n");
710 g_print("\t 'u' Touch AF area \n");
711 g_print("\t 'n' Set file path to write captured image\n");
712 g_print("\t 'b' back\n");
713 g_print("\t=======================================\n");
716 g_print("\n\tunknow menu state !!\n");
724 static void main_menu(gchar buf)
727 camera_state_e capi_state = CAMERA_STATE_NONE;
730 case '1': /* Capture */
731 hcamcorder->is_multishot = FALSE;
732 camera_get_state(hcamcorder->camera, &capi_state);
733 camera_attr_set_image_quality(hcamcorder->camera, 100);
734 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
735 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
737 case '2': /* multishot Capture */
738 g_print("multishot capture");
739 hcamcorder->is_multishot = TRUE;
740 int interval = 0, count = 0;
742 g_print("\n\tinput interval(ms) : ");
743 err = scanf("%d", &interval);
745 g_print("\n\tinput count : ");
746 err = scanf("%d", &count);
747 camera_attr_set_image_quality(hcamcorder->camera, 100);
748 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
749 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
751 camera_start_preview(hcamcorder->camera);
753 case '3': /* Setting */
754 hcamcorder->menu_state = MENU_STATE_SETTING;
756 case '4': /* Change device (Rear <-> Front) */
757 camera_set_display_reuse_hint(hcamcorder->camera, true);
759 camera_stop_preview(hcamcorder->camera);
761 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0) {
762 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
764 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
767 camera_change_device(hcamcorder->camera, hcamcorder->type);
769 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
770 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
771 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
772 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
774 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
776 camera_start_preview(hcamcorder->camera);
779 camera_stop_preview(hcamcorder->camera);
780 camera_destroy(hcamcorder->camera);
781 hcamcorder->camera = NULL;
782 hcamcorder->menu_state = MENU_STATE_INIT;
786 g_print("\t Invalid input \n");
794 static void setting_menu(gchar buf)
809 case '0': /* Setting > Preview Resolution setting */
810 g_print("*Select the preview resolution!\n");
811 resolution_stack resolution_list;
812 resolution_list.count = 0;
814 camera_foreach_supported_preview_resolution(hcamcorder->camera,
815 preview_resolution_cb, &resolution_list);
818 err = scanf("%d", &idx);
820 if (resolution_list.count > idx && idx >= 0) {
821 g_print("-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
822 resolution_list.width[idx], resolution_list.height[idx]);
824 result = camera_set_preview_resolution(hcamcorder->camera,
825 resolution_list.width[idx], resolution_list.height[idx]);
827 g_print("invalid input %d\n", idx);
830 resolution_list.count = 0;
836 case '1': /* Setting > Capture Resolution setting */
837 g_print("*Select the preview resolution!\n");
838 g_print("-----------------CAPTURE RESOLUTION TEST: ---------------------\n");
839 resolution_list.count = 0;
841 camera_foreach_supported_capture_resolution(hcamcorder->camera,
842 capture_resolution_test_cb, &resolution_list);
845 err = scanf("%d", &idx);
846 if (resolution_list.count > idx && idx >= 0) {
848 result = camera_set_capture_resolution(hcamcorder->camera,
849 resolution_list.width[idx], resolution_list.height[idx]);
851 g_print("camera_set_capture_resolution with width =%d, height=%d ret=0x%x\n",
852 resolution_list.width[idx], resolution_list.height[idx], result);
854 g_print("invalid input %d\n", idx);
857 resolution_list.count = 0;
864 case '2': /* Setting > Digital zoom level */
865 g_print("*Digital zoom level !\n");
866 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
868 g_print("Not supported !! \n");
871 g_print("\n Select Digital zoom level min %d - max %d\n", min, max);
872 err = scanf("%d", &idx);
873 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
876 case '3': /* Setting > AF mode */
877 g_print("*AF mode !\n");
878 g_print("\t1. AF Start !\n");
879 g_print("\t2. AF Stop !\n\n");
881 err = scanf("%d", &idx);
884 camera_start_focusing(hcamcorder->camera, 0);
887 camera_cancel_focusing(hcamcorder->camera);
890 g_print("Wrong Input[%d] !! \n", idx);
894 case '4': /* Setting > AF scan range */
895 g_print("*AF scan range !\n");
896 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
898 err = scanf("%d", &idx);
899 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
901 case '5': /* Setting > Exposure mode */
902 g_print("* Exposure mode!\n");
903 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
905 g_print("\n Select Exposure mode \n");
906 err = scanf("%d", &idx);
907 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
910 case '6': /* Setting > Exposure value */
911 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
913 g_print("Not supported !! \n");
916 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
917 err = scanf("%d", &idx);
918 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
921 case '7': /* Setting > F number */
922 g_print("Not supported !! \n");
924 case '8': /* Setting > Display reuse hint */
926 bool reuse_hint = false;
928 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
929 if (err != CAMERA_ERROR_NONE) {
930 g_print("failed to get display reuse hint 0x%x\n", err);
934 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
935 reuse_hint = !reuse_hint;
936 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
937 g_print("set display reuse hint result : 0x%x\n", err);
940 case 'i': /* Setting > ISO */
942 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
944 err = scanf("%d", &idx);
945 bret = camera_attr_set_iso(hcamcorder->camera, idx);
947 case 'r': /* Setting > Rotate camera input when recording */
948 g_print("*Rotate camera input\n");
949 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
951 err = scanf("%d", &idx);
952 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
953 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
954 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
956 case 'f': /* Setting > Flip camera input */
958 g_print("*Flip camera input\n");
959 g_print(" 0. Flip NONE\n");
960 g_print(" 1. Flip HORIZONTAL\n");
961 g_print(" 2. Flip VERTICAL\n");
962 g_print(" 3. Flip BOTH\n");
963 err = scanf("%d", &idx);
964 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
965 camera_attr_set_stream_flip(hcamcorder->camera, idx);
966 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
968 case 'j': /* Setting > Jpeg quality */
969 g_print("*Jpeg quality !\n");
971 g_print("\n Select Jpeg quality \n");
972 err = scanf("%d", &idx);
973 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
975 case 'p': /* Setting > Picture format */
976 g_print("* Picture format!\n");
977 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
979 err = scanf("%d", &idx);
980 bret = camera_set_preview_format(hcamcorder->camera, idx);
981 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
982 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
984 case 'E': /* Setting > EXIF orientation */
985 g_print("* EXIF Orientation\n");
986 g_print("\t 1. TOP_LEFT\n");
987 g_print("\t 2. TOP_RIGHT(flipped)\n");
988 g_print("\t 3. BOTTOM_RIGHT\n");
989 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
990 g_print("\t 5. LEFT_TOP(flipped)\n");
991 g_print("\t 6. RIGHT_TOP\n");
992 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
993 g_print("\t 8. LEFT_BOTTOM\n");
995 err = scanf("%d", &idx);
996 if (idx < 1 || idx > 8)
997 g_print("Wrong INPUT[%d]!! \n", idx);
999 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1001 case 'F': /* Getting > Get Facing direction */
1002 g_print("* Get facing direction of camera module\n");
1003 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1004 if (CAMERA_ERROR_NONE == err)
1005 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1007 g_print("* Error : %d\n", err);
1009 /* Display / Filter setting */
1010 case 'v': /* Display visible */
1011 g_print("* Display visible setting !\n");
1012 g_print("\n Select Display visible \n");
1014 for (i = 0 ; i < 2 ; i++)
1015 g_print("\t %d. %s\n", i, visible_mode[i]);
1016 err = scanf("%d", &idx);
1017 if (idx == 0 || idx == 1)
1018 bret = camera_set_display_visible(hcamcorder->camera, idx);
1020 g_print("invalid input %d", idx);
1022 case 'o': /* Setting > Display Mode */
1023 g_print("* Display mode!\n");
1025 for (i = 0 ; i < 5 ; i++)
1026 g_print("%d. %s\n", i, display_mode[i]);
1027 err = scanf("%d", &idx);
1028 bret = camera_set_display_mode(hcamcorder->camera, idx);
1030 case 'y': /* Setting > Rotate Display */
1032 g_print("\n Select Rotate mode\n");
1033 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1034 err = scanf("%d", &idx);
1035 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1036 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1037 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1039 case 'Y': /* Setting > Flip Display */
1041 g_print("\n Select Rotate mode\n");
1042 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1043 err = scanf("%d", &idx);
1044 bret = camera_set_display_flip(hcamcorder->camera, idx);
1046 case 'g': /* Setting > Brightness */
1047 g_print("*Brightness !\n");
1048 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1050 g_print("\n Select brightness min (%d) -max(%d)", min, max);
1051 err = scanf("%d", &idx);
1052 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1054 case 'c': /* Setting > Contrast */
1055 g_print("*Contrast !\n");
1056 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1058 g_print("\n Select Contrast min(%d)-max(%d)", min, max);
1059 err = scanf("%d", &idx);
1060 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1062 case 'w': /* Setting > White balance */
1063 g_print("*White balance !\n");
1065 g_print("\n Select White balance \n");
1066 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1067 err = scanf("%d", &idx);
1068 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1070 case 't': /* Setting > Color tone */
1071 g_print("*Color tone !\n");
1072 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1073 g_print("\n Select Color tone \n");
1075 err = scanf("%d", &idx);
1076 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1078 case 'd': /* Setting > WDR */
1079 g_print("*WDR !\n");
1080 g_print("\n Select WDR Mode \n");
1082 for (i = 0 ; i < 2 ; i++)
1083 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1084 err = scanf("%d", &idx);
1086 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1088 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1090 case 'e': /* Setting > EV program mode */
1091 g_print("* EV program mode!\n");
1092 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1093 g_print("\n Select EV program mode \n");
1095 err = scanf("%d", &idx);
1096 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1098 case 'R': /* Setting > Display ROI area */
1099 g_print("* Set display roi area. Select x y width height \n");
1101 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1102 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1103 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1104 if (CAMERA_ERROR_NONE != err)
1105 g_print("* Error : %d\n", err);
1107 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1108 if (CAMERA_ERROR_NONE == err)
1109 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1111 g_print("* Error : %d\n", err);
1115 case 'z': /* Setting > Strobe setting */
1116 g_print("*Strobe Mode\n");
1117 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1118 g_print("\n Select Strobe Mode \n");
1120 err = scanf("%d", &idx);
1121 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1123 case 'S': /* Setting > flash state */
1124 g_print("*flash state\n");
1125 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1126 if (CAMERA_ERROR_NONE == err)
1127 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1129 g_print("* Error : %d\n", err);
1131 case 'x': /* Setting > Capture mode ,Muitishot? */
1132 g_print("*Select Capture mode!\n");
1134 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1135 err = scanf("%d", &idx);
1139 g_print("stillshot mode selected and capture callback is set!!!!\n");
1140 hcamcorder->is_multishot = FALSE;
1141 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1144 g_print("HDR Capture mode selected\n");
1145 hcamcorder->is_multishot = FALSE;
1146 g_print("\nSelect HDR capture mode\n");
1148 for (i = 0 ; i < 3 ; i++)
1149 g_print("\t %d. %s\n", i, hdr_mode[i]);
1150 err = scanf("%d", &idx);
1151 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1152 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1154 g_print("invalid input %d\n", idx);
1157 g_print("Wrong input, select again!!\n");
1161 case 'l': /* Setting > Face detection setting */
1162 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1163 g_print("* Face detect mode !\n");
1165 for (i = 0 ; i < 2 ; i++)
1166 g_print("\t %d. %s \n", i, detection_mode[i]);
1167 err = scanf("%d", &idx);
1169 bret = camera_stop_face_detection(hcamcorder->camera);
1171 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1173 g_print("\n invalid input [%d]\n\n", idx);
1175 g_print("face detection_not supported");
1178 case 'k': /* Setting > Anti-handshake */
1179 g_print("*Anti-handshake !\n");
1180 g_print("\n Select Anti-handshake mode \n");
1182 for (i = 0; i < 2; i++)
1183 g_print("\t %d. %s\n", i, ahs_mode[i]);
1184 err = scanf("%d", &idx);
1185 if (idx == 0 || idx == 1)
1186 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1188 g_print("invalid input %d\n", idx);
1190 case 'K': /* Setting > Video-stabilization */
1191 g_print("*Video-stabilization !\n");
1192 g_print("\n Select Video-stabilization mode \n");
1194 for (i = 0 ; i < 2 ; i++)
1195 g_print("\t %d. %s\n", i, vs_mode[i]);
1196 err = scanf("%d", &idx);
1198 if (idx < 0 || idx > 1) {
1199 g_print("invalid input %d\n", idx);
1204 g_print("\n Restart preview with NV12 and 720p resolution\n");
1205 err = camera_stop_preview(hcamcorder->camera);
1206 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1207 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1210 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1213 err = camera_start_preview(hcamcorder->camera);
1214 if (err != CAMERA_ERROR_NONE)
1215 g_print("\n Restart FAILED! 0x%x\n", err);
1218 case 'u': /* Touch AF area */
1219 g_print("* Touch AF area !\n");
1221 g_print("\n Input x,y,width,height \n");
1222 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1223 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1225 g_print("Failed to set touch AF area.(%x)\n", err);
1227 g_print("Succeed to set touch AF area.\n");
1229 case 'n': /* file path */
1230 g_print("* File path !\n");
1232 g_print("\n Input file path to save captured data(string) : ");
1233 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1234 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1235 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1237 g_print("\nset file path failed\n");
1240 case 'b': /* back */
1241 hcamcorder->menu_state = MENU_STATE_MAIN;
1244 g_print("\t Invalid input \n");
1248 g_print("\t bret : 0x%x \n", bret);
1255 * This function is to execute command.
1257 * @param channel [in] 1st parameter
1259 * @return This function returns TRUE/FALSE
1263 static gboolean cmd_input(GIOChannel *channel)
1267 GError *g_error = NULL;
1269 g_print("\n\tENTER\n");
1271 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1273 g_print("\n\tg_io_channel_read_chars error\n");
1274 g_error_free(g_error);
1281 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1282 switch (hcamcorder->menu_state) {
1283 case MENU_STATE_INIT:
1284 mode_change(buf[0]);
1286 case MENU_STATE_MAIN:
1289 case MENU_STATE_SETTING:
1290 setting_menu(buf[0]);
1301 g_print("\n\tNo read input\n");
1307 static gboolean init_handle()
1309 hcamcorder->is_multishot = FALSE;
1310 hcamcorder->stillshot_count = 0;
1311 hcamcorder->multishot_count = 0;
1312 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1313 hcamcorder->menu_state = MENU_STATE_INIT;
1314 hcamcorder->elapsed_time = 0;
1319 void _preview_cb(camera_preview_data_s *frame, void *user_data)
1322 FILE *fp = fopen("/opt/usr/media/test.yuv", "a");
1324 g_print("\n============ file open failed ===========================\n");
1328 switch (frame->num_of_planes) {
1330 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
1332 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
1333 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
1335 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
1336 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
1337 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
1342 g_print("file write done ---\n");
1347 g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
1348 frame->format, frame->width, frame->height, frame->num_of_planes);
1355 * This function is to change camcorder mode.
1357 * @param buf [in] user input
1359 * @return This function returns TRUE/FALSE
1361 * @see other functions
1363 static gboolean mode_change(gchar buf)
1366 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1367 char display_type = '\0';
1372 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA1;
1376 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA0;
1380 err = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1381 NULL, &g_camera_device_changed_cb_id);
1382 g_print("add result 0x%x - cb id %d\n", err, g_camera_device_changed_cb_id);
1385 if (g_camera_device_changed_cb_id > 0) {
1386 err = camera_remove_device_state_changed_cb(g_camera_device_changed_cb_id);
1387 g_camera_device_changed_cb_id = 0;
1388 g_print("remove result 0x%x\n", err);
1390 g_print("invalid callback id %d\n", g_camera_device_changed_cb_id);
1394 err = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &device_state);
1395 g_print("get result 0x%x - state %d\n", err, device_state);
1398 g_print("\t Quit Camcorder Testsuite!!\n");
1402 g_print("\t Invalid media type(%c)\n", buf);
1406 g_print("\n[camcorder_create - type %d]\n", cam_info);
1408 g_get_current_time(&previous_time);
1410 g_timer_reset(timer);
1412 err = camera_create(cam_info, &hcamcorder->camera);
1414 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1417 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1423 g_print("\n\tEnter the Display Type\n");
1424 g_print("\t'1' OVERLAY surface\n");
1425 g_print("\t'2' EVAS surface\n");
1426 g_print("\t'3' NONE surface\n");
1428 err = scanf("%c", &display_type);
1430 g_print("\t!!!read input error!!!\n");
1434 switch (display_type) {
1436 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1440 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1444 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1448 g_print("\t Invalid display type(%c)\n", display_type);
1453 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1454 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1455 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1456 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1457 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1458 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1459 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1460 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1462 camera_start_preview(hcamcorder->camera);
1464 g_get_current_time(¤t_time);
1465 timersub(¤t_time, &previous_time, &result_time);
1467 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1469 hcamcorder->menu_state = MENU_STATE_MAIN;
1476 static int app_create(void *data)
1478 appdata *app_data = data;
1481 Evas_Object *win = NULL;
1482 Evas_Object *eo = NULL;
1483 Evas_Object *bg = NULL;
1484 Evas_Object *rect = NULL;
1486 if (app_data == NULL) {
1487 g_print("\t\nappdata is NULL\n");
1491 /* use gl backend */
1492 elm_config_accel_preference_set("opengl");
1494 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1496 elm_win_title_set(win, "camera_test");
1497 elm_win_borderless_set(win, EINA_TRUE);
1498 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1499 g_print("\n\tscreen size %dx%d\n\n", w, h);
1500 evas_object_resize(win, w, h);
1501 elm_win_autodel_set(win, EINA_TRUE);
1502 elm_win_alpha_set(win, EINA_TRUE);
1504 g_print("\n\tfailed to get window\n\n");
1508 bg = elm_bg_add(win);
1510 elm_win_resize_object_add(win, bg);
1511 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1512 evas_object_show(bg);
1514 g_print("\n\tfailed to get elm bg\n\n");
1518 rect = evas_object_rectangle_add(evas_object_evas_get(win));
1520 evas_object_color_set(rect, 0, 0, 0, 0);
1521 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1523 g_print("\n\tfailed to get rectangle\n\n");
1527 elm_win_resize_object_add(win, rect);
1528 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1529 evas_object_show(rect);
1531 /* Create evas image object for EVAS surface */
1532 eo = evas_object_image_add(evas_object_evas_get(win));
1533 evas_object_image_size_set(eo, w, h);
1534 evas_object_image_fill_set(eo, 0, 0, w, h);
1535 evas_object_resize(eo, w, h);
1536 evas_object_show(eo);
1538 elm_win_activate(win);
1539 evas_object_show(win);
1541 app_data->win = win;
1544 timer = g_timer_new();
1545 g_timer_reset(timer);
1554 static int app_terminate(void *data)
1556 appdata *app_data = data;
1558 if (app_data == NULL) {
1559 g_print("\n\tappdata is NULL\n");
1564 g_timer_stop(timer);
1565 g_timer_destroy(timer);
1574 * This function is the example main function for mmcamcorder API.
1578 * @return This function returns 0.
1580 * @see other functions
1582 int main(int argc, char **argv)
1586 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1588 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1589 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1591 memset(&ad, 0x0, sizeof(appdata));
1594 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1596 g_print("\n\treturn appcore_efl : %d\n\n", bret);
1599 g_io_channel_unref(stdin_channel);