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 =======================================================================================*/
33 #include <Elementary.h>
35 /*-----------------------------------------------------------------------
36 | GLOBAL VARIABLE DEFINITIONS: |
37 -----------------------------------------------------------------------*/
38 #define EXPORT_API __attribute__((__visibility__("default")))
40 #define PACKAGE "camera_testsuite"
46 GIOChannel *stdin_channel;
47 camera_device_e cam_info;
54 int camera_print_state;
56 static GTimer *timer = NULL;
58 GTimeVal previous_time;
59 GTimeVal current_time;
62 /*-----------------------------------------------------------------------
63 | GLOBAL CONSTANT DEFINITIONS: |
64 -----------------------------------------------------------------------*/
67 /*-----------------------------------------------------------------------
68 | IMPORTED VARIABLE DECLARATIONS: |
69 -----------------------------------------------------------------------*/
72 /*-----------------------------------------------------------------------
73 | IMPORTED FUNCTION DECLARATIONS: |
74 -----------------------------------------------------------------------*/
77 /*-----------------------------------------------------------------------
79 -----------------------------------------------------------------------*/
80 #define test_ffmux_mp4
83 #define DISPLAY_X_0 0 /* for direct FB */
84 #define DISPLAY_Y_0 0 /* for direct FB */
86 #define DISPLAY_W_320 320 /* for direct FB */
87 #define DISPLAY_H_240 240 /* for direct FB */
90 #define IMAGE_ENC_QUALITY 85 /* quality of jpeg */
91 #define IMAGE_CAPTURE_COUNT_STILL 1 /* the number of still-shot */
92 #define IMAGE_CAPTURE_COUNT_MULTI 3 /* default the number of multi-shot */
93 #define IMAGE_CAPTURE_COUNT_INTERVAL 100 /* mili seconds */
95 #define MAX_FILE_SIZE_FOR_MMS (250 * 1024)
97 #define EXT_JPEG "jpg"
100 #define EXT_AMR "amr"
101 #define EXT_MKV "mkv"
103 #define TARGET_FILENAME_PATH "/opt/usr/media/"
104 #define STILL_CAPTURE_FILE_PATH_NAME TARGET_FILENAME_PATH"StillshotCapture"
105 #define MULTI_CAPTURE_FILE_PATH_NAME TARGET_FILENAME_PATH"MultishotCapture"
106 #define IMAGE_CAPTURE_THUMBNAIL_PATH TARGET_FILENAME_PATH"thumbnail.jpg"
107 #define IMAGE_CAPTURE_SCREENNAIL_PATH TARGET_FILENAME_PATH"screennail.yuv"
108 #define IMAGE_CAPTURE_EXIF_PATH TARGET_FILENAME_PATH"exif.raw"
109 #define CAPTURE_FILENAME_LEN 256
110 #define MAX_STILLSHOT_CAPTURE_RESOLUTION_SUPPORTED 2
112 #define DEFAULT_CAM_DEVICE MM_VIDEO_DEVICE_CAMERA1
115 #define CHECK_MM_ERROR(expr) \
120 printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
127 #define SAFE_FREE(x) \
134 #define SENSOR_WHITEBALANCE_NUM 10
135 #define SENSOR_COLOR_TONE_NUM 31
136 #define SENSOR_FLIP_NUM 3
137 #define SENSOR_PROGRAM_MODE_NUM 15
138 #define SENSOR_FOCUS_NUM 6
139 #define SENSOR_INPUT_ROTATION 4
140 #define SENSOR_AF_SCAN_NUM 4
141 #define SENSOR_ISO_NUM 8
142 #define SENSOR_EXPOSURE_NUM 9
143 #define SENSOR_IMAGE_FORMAT 9
146 /*-----------------------------------------------------------------------
147 | LOCAL CONSTANT DEFINITIONS: |
148 -----------------------------------------------------------------------*/
150 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
151 MODE_AUDIO, /* audio recording*/
161 /*-----------------------------------------------------------------------
162 | LOCAL DATA TYPE DEFINITIONS: |
163 -----------------------------------------------------------------------*/
164 typedef struct _cam_handle {
166 int mode; /* image(capture)/video(recording) mode */
167 int isMultishot; /* flag for multishot mode */
168 int stillshot_count; /* total stillshot count */
169 int multishot_count; /* total multishot count */
170 const char *stillshot_filename; /* stored filename of stillshot */
171 const char *multishot_filename; /* stored filename of multishot */
174 unsigned long long elapsed_time;
190 camera_attr_af_mode_e mode;
200 camera_attr_exposure_mode_e mode;
205 camera_attr_iso_e mode;
210 camera_rotation_e mode;
212 } camera_rotation_stack;
215 /*---------------------------------------------------------------------------
216 | LOCAL VARIABLE DEFINITIONS: |
217 ---------------------------------------------------------------------------*/
218 static cam_handle_t *hcamcorder;
220 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
233 const char *ct[SENSOR_COLOR_TONE_NUM] = {
259 "SELECTVE_COLOR_RED",
260 "SELECTVE_COLOR_GREEN",
261 "SELECTVE_COLOR_BLUE",
262 "SELECTVE_COLOR_YELLOW",
263 "SELECTVE_COLOR_RED_YELLOW",
267 const char *flip[SENSOR_FLIP_NUM] = {
273 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
291 const char *focus_mode[SENSOR_FOCUS_NUM] = {
300 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
307 const char *iso_mode[SENSOR_ISO_NUM] = {
318 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
326 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
338 const char *face_zoom_mode[] = {
343 const char *display_mode[] = {
345 "Original Size mode",
347 "Cropped Full Screen mode",
351 const char *capture_sound[] = {
357 const char *rotate_mode[] = {
364 const char* strobe_mode[] = {
368 "Strobe RedEyeReduction",
370 "Strobe FrontCurtain",
371 "Strobe RearCurtain",
375 const char *detection_mode[2] = {
376 "Face Detection OFF",
380 const char *wdr_mode[] = {
386 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
393 const char *hdr_mode[] = {
396 "HDR ON and Original",
399 const char *ahs_mode[] = {
400 "Anti-handshake OFF",
402 "Anti-handshake AUTO",
403 "Anti-handshake MOVIE",
406 const char *vs_mode[] = {
407 "Video-stabilization OFF",
408 "Video-stabilization ON",
411 const char *visible_mode[] = {
416 const char *facing_direction[] = {
422 /*---------------------------------------------------------------------------
423 | LOCAL FUNCTION PROTOTYPES: |
424 ---------------------------------------------------------------------------*/
425 static void print_menu();
426 static gboolean cmd_input(GIOChannel *channel);
427 static gboolean mode_change();
428 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
429 bool preview_resolution_cb(int width, int height, void *user_data);
432 static inline void flush_stdin()
435 while ((ch = getchar()) != EOF && ch != '\n');
438 void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
440 printf("camera state changed %d -> %d\n", previous, current);
443 void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
445 printf("camera interrupted callback called %d\n", policy);
448 bool preview_resolution_cb(int width, int height, void *user_data)
450 resolution_stack *data = (resolution_stack *)user_data;
453 printf("NULL data\n");
457 data->width[data->count] = width;
458 data->height[data->count] = height;
460 printf("%d. %dx%d\n", data->count, width, height);
467 bool capture_resolution_test_cb(int width, int height, void *user_data)
469 resolution_stack *data = (resolution_stack *)user_data;
472 printf("NULL data\n");
476 data->width[data->count] = width;
477 data->height[data->count] = height;
479 printf("%d. %dx%d\n", data->count, width, height);
486 bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
488 printf("%d.%s\n", mode, af_scan[mode]);
492 bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
494 exposure_stack *data = (exposure_stack *)user_data;
497 printf("NULL data\n");
504 printf("%d.%s\n", mode, exposure_mode[mode]);
508 bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
510 printf("%d.%s\n", mode, iso_mode[mode]);
514 bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
516 camera_rotation_stack *data = (camera_rotation_stack *)user_data;
519 printf("NULL data\n");
526 printf("%d.%s\n", mode, camera_rotation[mode]);
531 bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
533 printf("%d.%s\n", mode, image_fmt[mode]);
537 bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
539 printf("%d.%s\n", mode, wb[mode]);
543 bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
545 printf("%d.%s\n", mode, ct[mode]);
549 bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
551 printf("%d.%s\n", mode, program_mode[mode]);
555 bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
557 printf("%d.%s\n", mode, strobe_mode[mode]);
561 void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
563 printf("face detected!!\n");
566 for (i = 0 ; i < count ; i++)
567 printf("%d) - %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
573 void cam_utils_convert_YUYV_to_UYVY(unsigned char *dst, unsigned char *src, gint length)
578 memset(dst, 0x00, length);
579 memcpy(dst, src+1, length-1);
581 for (i = 0 ; i < length ; i++) {
590 static void _file_write(char *path, void *data, int size)
594 if (!path || !data || size <= 0) {
595 printf("ERROR %p %p %d\n", path, data, size);
599 fp = fopen(path, "w");
601 printf("open error! [%s], errno %d\n", path, errno);
604 printf("open success [%s]\n", path);
605 if (fwrite(data, size, 1, fp) != 1)
606 printf("write error! errno %d\n", errno);
608 printf("write success [%s]\n", path);
615 void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
617 char m_filename[CAPTURE_FILENAME_LEN];
619 if (hcamcorder->isMultishot)
620 snprintf(m_filename, CAPTURE_FILENAME_LEN, "/opt/usr/media/Stillshot%03d.jpg", hcamcorder->multishot_count++);
622 snprintf(m_filename, CAPTURE_FILENAME_LEN, "/opt/usr/media/Multishot%03d.jpg", hcamcorder->stillshot_count++);
626 _file_write(m_filename, image->data, image->size);
631 void capture_completed_cb(void *user_data)
633 camera_start_preview(hcamcorder->camera);
640 static void print_menu()
642 switch (hcamcorder->menu_state) {
643 case MENU_STATE_MAIN:
644 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
645 g_print("\n\t=======================================\n");
646 if (cam_info == CAMERA_DEVICE_CAMERA1)
647 g_print("\t Video Capture (Front camera)\n");
648 else if (cam_info == CAMERA_DEVICE_CAMERA0)
649 g_print("\t Video Capture (Rear camera)\n");
650 g_print("\t=======================================\n");
652 g_print("\t '1' Stillshot test\n");
653 g_print("\t '2' Multishot test\n");
654 g_print("\t '3' Setting\n");
655 g_print("\t 'b' back\n");
656 g_print("\t=======================================\n");
659 case MENU_STATE_SETTING:
660 g_print("\n\t=======================================\n");
661 g_print("\t Video Capture > Setting\n");
662 g_print("\t=======================================\n");
663 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
664 g_print("\t '0' Preview resolution \n");
665 g_print("\t '1' Capture resolution \n");
666 g_print("\t '2' Digital zoom level \n");
667 g_print("\t '3' AF mode \n");
668 g_print("\t '4' AF scan range \n");
669 g_print("\t '5' Exposure mode \n");
670 g_print("\t '6' Exposure value \n");
671 g_print("\t '7' F number \n");
672 g_print("\t 'i' ISO \n");
673 g_print("\t 'r' Rotate camera input \n");
674 g_print("\t 'f' Flip camera input \n");
675 g_print("\t 'j' Jpeg quality \n");
676 g_print("\t 'p' Picture format \n");
677 g_print("\t 'E' EXIF orientation \n");
678 g_print("\t 'F' Get facing direction of camera module\n");
679 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
680 g_print("\t 'v' Visible \n");
681 g_print("\t 'o' Output mode \n");
682 g_print("\t 'y' Rotate display \n");
683 g_print("\t 'Y' Flip display \n");
684 g_print("\t 'g' Brightness \n");
685 g_print("\t 'c' Contrast \n");
686 g_print("\t 'w' White balance \n");
687 g_print("\t 't' Color tone \n");
688 g_print("\t 'd' WDR \n");
689 g_print("\t 'e' EV program mode \n");
690 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
691 g_print("\t 'z' Strobe (Flash) \n");
692 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
693 g_print("\t 'l' Face detection \n");
694 g_print("\t 'k' Anti-handshake \n");
695 g_print("\t 'K' Video-stabilization \n");
696 g_print("\t 'u' Touch AF area \n");
697 g_print("\t 'b' back\n");
698 g_print("\t=======================================\n");
701 LOGE("unknow menu state !!\n");
709 static void main_menu(gchar buf)
712 camera_state_e capi_state;
713 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
715 case '1': /* Capture */
716 camera_get_state(hcamcorder->camera, &capi_state);
717 camera_attr_set_image_quality(hcamcorder->camera, 100);
718 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
719 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
721 case '2': /* multishot Capture */
722 g_print("multishot capture");
723 hcamcorder->isMultishot = TRUE;
724 int interval = 0, count = 0;
726 printf("\ninput interval(ms)\n");
727 err = scanf("%d", &interval);
729 printf("\ninput count(ms) \n");
730 err = scanf("%d", &count);
731 camera_attr_set_image_quality(hcamcorder->camera, 100);
732 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
733 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
735 camera_start_preview(hcamcorder->camera);
737 case '3': /* Setting */
738 hcamcorder->menu_state = MENU_STATE_SETTING;
741 camera_stop_preview(hcamcorder->camera);
742 camera_destroy(hcamcorder->camera);
743 hcamcorder->camera = NULL;
744 hcamcorder->menu_state = MENU_STATE_MAIN;
748 g_print("\t Invalid input \n");
752 g_print("\t Invalid mode, back to upper menu \n");
753 hcamcorder->menu_state = MENU_STATE_MAIN;
761 static void setting_menu(gchar buf)
763 gboolean bret = FALSE;
770 int x = 0, y = 0, width = 0, height = 0;
772 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
775 case '0': /* Setting > Preview Resolution setting */
776 g_print("*Select the preview resolution!\n");
777 resolution_stack resolution_list;
778 resolution_list.count = 0;
779 camera_foreach_supported_preview_resolution(hcamcorder->camera, preview_resolution_cb, &resolution_list);
781 err = scanf("%d", &idx);
783 preview_test_data data;
785 if (resolution_list.count > idx && idx >= 0) {
786 data.expected_width = resolution_list.width[idx];
787 data.expected_height = resolution_list.height[idx];
788 printf("-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n", data.expected_width, data.expected_height);
789 result = camera_set_preview_resolution(hcamcorder->camera, data.expected_width, data.expected_height);
791 printf("invalid input %d\n", idx);
794 resolution_list.count = 0;
800 case '1': /* Setting > Capture Resolution setting */
801 g_print("*Select the preview resolution!\n");
802 printf("-----------------CAPTURE RESOLUTION TEST: ---------------------\n");
803 resolution_list.count = 0;
804 camera_foreach_supported_capture_resolution(hcamcorder->camera, capture_resolution_test_cb, &resolution_list);
806 err = scanf("%d", &idx);
808 if (resolution_list.count > idx && idx >= 0) {
809 data.expected_width = resolution_list.width[idx];
810 data.expected_height = resolution_list.height[idx];
812 result = camera_set_capture_resolution(hcamcorder->camera, data.expected_width, data.expected_height);
813 printf("camera_set_capture_resolution with width =%d, height=%d ret=0x%x\n", data.expected_width, data.expected_height, result);
815 printf("invalid input %d\n", idx);
818 resolution_list.count = 0;
825 case '2': /* Setting > Digital zoom level */
826 g_print("*Digital zoom level !\n");
827 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
829 g_print("Not supported !! \n");
832 g_print("\n Select Digital zoom level min %d - max %d\n", min, max);
833 err = scanf("%d", &idx);
834 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
837 case '3': /* Setting > AF mode */
838 g_print("*AF mode !\n");
839 g_print("\t1. AF Start !\n");
840 g_print("\t2. AF Stop !\n\n");
842 err = scanf("%d", &idx);
845 camera_start_focusing(hcamcorder->camera, 0);
848 camera_cancel_focusing(hcamcorder->camera);
851 g_print("Wrong Input[%d] !! \n", idx);
855 case '4': /* Setting > AF scan range */
856 g_print("*AF scan range !\n");
857 af_stack af_mode_list;
858 af_mode_list.count = 0;
859 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
861 data1.ispass = false;
862 data1.expected_mode = af_mode_list.mode;
864 err = scanf("%d", &idx);
865 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
867 case '5': /* Setting > Exposure mode */
868 g_print("* Exposure mode!\n");
869 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
871 g_print("\n Select Exposure mode \n");
872 err = scanf("%d", &idx);
873 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
876 case '6': /* Setting > Exposure value */
877 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
879 g_print("Not supported !! \n");
882 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
883 err = scanf("%d", &idx);
884 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
887 case '7': /* Setting > F number */
888 g_print("Not supported !! \n");
890 case 'i': /* Setting > ISO */
892 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
894 err = scanf("%d", &idx);
895 bret = camera_attr_set_iso(hcamcorder->camera, idx);
897 case 'r': /* Setting > Rotate camera input when recording */
898 g_print("*Rotate camera input\n");
899 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
901 err = scanf("%d", &idx);
902 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
903 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
904 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
906 case 'f': /* Setting > Flip camera input */
908 g_print("*Flip camera input\n");
909 g_print(" 0. Flip NONE\n");
910 g_print(" 1. Flip HORIZONTAL\n");
911 g_print(" 2. Flip VERTICAL\n");
912 g_print(" 3. Flip BOTH\n");
913 err = scanf("%d", &idx);
914 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
915 camera_attr_set_stream_flip(hcamcorder->camera, idx);
916 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
918 case 'j': /* Setting > Jpeg quality */
919 g_print("*Jpeg quality !\n");
921 g_print("\n Select Jpeg quality \n");
922 err = scanf("%d", &idx);
923 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
925 case 'p': /* Setting > Picture format */
926 g_print("* Picture format!\n");
927 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
929 err = scanf("%d", &idx);
930 bret = camera_set_preview_format(hcamcorder->camera, idx);
931 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
932 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
934 case 'E': /* Setting > EXIF orientation */
935 g_print("* EXIF Orientation\n");
936 g_print("\t 1. TOP_LEFT\n");
937 g_print("\t 2. TOP_RIGHT(flipped)\n");
938 g_print("\t 3. BOTTOM_RIGHT\n");
939 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
940 g_print("\t 5. LEFT_TOP(flipped)\n");
941 g_print("\t 6. RIGHT_TOP\n");
942 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
943 g_print("\t 8. LEFT_BOTTOM\n");
945 err = scanf("%d", &idx);
946 if (idx < 1 || idx > 8)
947 g_print("Wrong INPUT[%d]!! \n", idx);
949 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
951 case 'F': /* Getting > Get Facing direction */
952 g_print("* Get facing direction of camera module\n");
953 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
954 if (CAMERA_ERROR_NONE == err)
955 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
957 g_print("* Error : %d\n", err);
960 /* Display / Filter setting */
961 case 'v': /* Display visible */
962 g_print("* Display visible setting !\n");
963 g_print("\n Select Display visible \n");
965 for (i = 0 ; i < 2 ; i++)
966 g_print("\t %d. %s\n", i+1, visible_mode[i]);
967 err = scanf("%d", &value);
968 bret = camera_set_display_visible(hcamcorder->camera, idx-1);
970 case 'o': /* Setting > Display Mode */
971 g_print("* Display mode!\n");
973 for (i = 0 ; i < 5 ; i++)
974 g_print("%d. %s\n", i, display_mode[i]);
975 err = scanf("%d", &idx);
976 bret = camera_set_display_mode(hcamcorder->camera, idx);
978 case 'y': /* Setting > Rotate Display */
980 g_print("\n Select Rotate mode\n");
981 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
982 err = scanf("%d", &idx);
983 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
984 bret = camera_set_display_rotation(hcamcorder->camera, idx);
985 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
987 case 'Y': /* Setting > Flip Display */
989 g_print("\n Select Rotate mode\n");
990 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
991 err = scanf("%d", &idx);
992 bret = camera_set_display_flip(hcamcorder->camera, idx);
994 case 'g': /* Setting > Brightness */
995 g_print("*Brightness !\n");
996 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
998 g_print("\n Select brightness min (%d) -max(%d)", min, max);
999 err = scanf("%d", &idx);
1000 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1002 case 'c': /* Setting > Contrast */
1003 g_print("*Contrast !\n");
1004 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1006 g_print("\n Select Contrast min(%d)-max(%d)", min, max);
1007 err = scanf("%d", &idx);
1008 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1010 case 'w': /* Setting > White balance */
1011 g_print("*White balance !\n");
1013 g_print("\n Select White balance \n");
1014 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1015 err = scanf("%d", &idx);
1016 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1018 case 't': /* Setting > Color tone */
1019 g_print("*Color tone !\n");
1020 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1021 g_print("\n Select Color tone \n");
1023 err = scanf("%d", &idx);
1024 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1026 case 'd': /* Setting > WDR */
1027 g_print("*WDR !\n");
1028 g_print("\n Select WDR Mode \n");
1030 for (i = 0 ; i < 2 ; i++)
1031 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1032 err = scanf("%d", &idx);
1034 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1036 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1038 case 'e': /* Setting > EV program mode */
1039 g_print("* EV program mode!\n");
1040 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1041 g_print("\n Select EV program mode \n");
1043 err = scanf("%d", &idx);
1044 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1048 case 'z': /* Setting > Strobe setting */
1049 g_print("*Strobe Mode\n");
1050 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1051 g_print("\n Select Strobe Mode \n");
1053 err = scanf("%d", &idx);
1054 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1056 case 'x': /* Setting > Capture mode ,Muitishot? */
1057 g_print("*Select Capture mode!\n");
1059 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1060 err = scanf("%d", &idx);
1064 g_print("stillshot mode selected and capture callback is set!!!!\n");
1065 hcamcorder->isMultishot = FALSE;
1066 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1069 g_print("HDR Capture mode selected\n");
1070 hcamcorder->isMultishot = FALSE;
1071 g_print("\nSelect HDR capture mode\n");
1073 for (i = 0 ; i < 3 ; i++)
1074 g_print("\t %d. %s\n", i+1, hdr_mode[i]);
1075 err = scanf("%d", &idx);
1076 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx-1);
1079 g_print("Wrong input, select again!!\n");
1083 case 'l': /* Setting > Face detection setting */
1084 g_print("* Face detect mode !\n");
1086 for (i = 0 ; i < 2 ; i++)
1087 g_print("\t %d. %s \n", i+1, detection_mode[i]);
1088 err = scanf("%d", &idx);
1089 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1090 if (idx >= 0 && idx < 2)
1091 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1093 g_print("face detection_not supported");
1095 case 'k': /* Setting > Anti-handshake */
1096 g_print("*Anti-handshake !\n");
1097 g_print("\n Select Anti-handshake mode \n");
1099 for (i = 0; i < 2; i++)
1100 g_print("\t %d. %s\n", i+1, ahs_mode[i]);
1101 err = scanf("%d", &idx);
1102 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx-1);
1104 case 'K': /* Setting > Video-stabilization */
1105 g_print("*Video-stabilization !\n");
1106 g_print("\n Select Video-stabilization mode \n");
1108 for (i = 0 ; i < 2 ; i++)
1109 g_print("\t %d. %s\n", i+1, vs_mode[i]);
1110 err = scanf("%d", &idx);
1112 g_print("\n Restart preview with NV12 and 720p resolution\n");
1113 err = camera_stop_preview(hcamcorder->camera);
1114 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1115 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1116 camera_attr_enable_video_stabilization(hcamcorder->camera, idx-1);
1118 err = camera_start_preview(hcamcorder->camera);
1120 g_print("\n Restart FAILED! %x\n", err);
1124 case 'u': /* Touch AF area */
1125 g_print("* Touch AF area !\n");
1127 g_print("\n Input x,y,width,height \n");
1128 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1129 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1131 g_print("Failed to set touch AF area.(%x)\n", err);
1133 g_print("Succeed to set touch AF area.\n");
1135 case 'b': /* back */
1136 hcamcorder->menu_state = MENU_STATE_MAIN;
1139 g_print("\t Invalid input \n");
1143 g_print("\t Invalid mode, back to upper menu \n");
1144 hcamcorder->menu_state = MENU_STATE_MAIN;
1147 g_print("\t bret : 0x%x \n", bret);
1154 * This function is to execute command.
1156 * @param channel [in] 1st parameter
1158 * @return This function returns TRUE/FALSE
1162 static gboolean cmd_input(GIOChannel *channel)
1166 GError *g_error = NULL;
1170 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1172 LOGD("g_io_channel_read_chars error");
1173 g_error_free(g_error);
1180 LOGD("Menu Status : %d", hcamcorder->menu_state);
1181 switch (hcamcorder->menu_state) {
1182 case MENU_STATE_MAIN:
1185 case MENU_STATE_SETTING:
1186 setting_menu(buf[0]);
1197 LOGD("No read input");
1203 static gboolean init_handle()
1205 hcamcorder->mode = MODE_VIDEO_CAPTURE; /* image(capture)/video(recording) mode */
1206 hcamcorder->isMultishot = FALSE;
1207 hcamcorder->stillshot_count = 0; /* total stillshot count */
1208 hcamcorder->multishot_count = 0; /* total multishot count */
1209 hcamcorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME; /* stored filename of stillshot */
1210 hcamcorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME; /* stored filename of multishot */
1211 hcamcorder->menu_state = MENU_STATE_MAIN;
1212 hcamcorder->isMute = FALSE;
1213 hcamcorder->elapsed_time = 0;
1214 multishot_num = IMAGE_CAPTURE_COUNT_MULTI;
1219 void _preview_cb(camera_preview_data_s *frame, void *user_data)
1222 FILE *fp = fopen("/opt/usr/media/test.yuv", "a");
1224 g_print("\n============ file open failed ===========================\n");
1228 switch (frame->num_of_planes) {
1230 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
1232 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
1233 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
1235 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
1236 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
1237 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
1242 g_print("file write done ---\n");
1247 g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
1248 frame->format, frame->width, frame->height, frame->num_of_planes);
1255 * This function is to change camcorder mode.
1257 * @param type [in] image(capture)/video(recording) mode
1259 * @return This function returns TRUE/FALSE
1261 * @see other functions
1263 static gboolean mode_change()
1266 char media_type = '\0';
1271 g_print("\n\t=======================================\n");
1272 g_print("\t CAMERA_TESTSUITE\n");
1273 g_print("\t=======================================\n");
1274 g_print("\t '1' Video Capture - Front Camera\n");
1275 g_print("\t '2' Video Capture - Rear Camera\n");
1276 g_print("\t 'q' Exit\n");
1277 g_print("\t=======================================\n");
1279 g_print("\t Enter the media type:\n\t");
1281 err = scanf("%c", &media_type);
1283 g_print("\t!!!read input error!!!\n");
1287 switch (media_type) {
1289 hcamcorder->mode = MODE_VIDEO_CAPTURE;
1290 cam_info = CAMERA_DEVICE_CAMERA1;
1294 hcamcorder->mode = MODE_VIDEO_CAPTURE;
1295 cam_info = CAMERA_DEVICE_CAMERA0;
1299 g_print("\t Quit Camcorder Testsuite!!\n");
1300 hcamcorder->mode = -1;
1301 if (g_main_loop_is_running(g_loop))
1302 g_main_loop_quit(g_loop);
1306 g_print("\t Invalid media type(%d)\n", media_type);
1311 LOGD("camcorder_create");
1312 g_get_current_time(&previous_time);
1313 g_timer_reset(timer);
1315 err = camera_create(cam_info, &hcamcorder->camera);
1316 LOGD("camera_create() : %12.6lfs", g_timer_elapsed(timer, NULL));
1319 LOGE("mmcamcorder_create = %x", err);
1322 camera_state = CAMERA_STATE_NONE;
1324 camera_print_state = CAMERA_STATE_CREATED;
1326 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1327 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1328 camera_set_display_mode(hcamcorder->camera, 0); /* MM_DISPLAY_METHOD_LETTER_BOX */
1329 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(eo));
1331 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1333 camera_start_preview(hcamcorder->camera);
1334 g_get_current_time(¤t_time);
1335 timersub(¤t_time, &previous_time, &res);
1336 LOGD("Camera Starting Time : %ld.%lds", res.tv_sec, res.tv_usec);
1337 camera_print_state = CAMERA_STATE_PREVIEW;
1344 * This function is the example main function for mmcamcorder API.
1348 * @return This function returns 0.
1350 * @see other functions
1352 int main(int argc, char **argv)
1357 elm_init(argc, argv);
1359 eo = elm_win_add(NULL, "VIDEO OVERLAY", ELM_WIN_BASIC);
1361 elm_win_title_set(eo, "TITLE");
1362 elm_win_borderless_set(eo, EINA_TRUE);
1363 elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
1364 evas_object_resize(eo, w, h);
1365 elm_win_autodel_set(eo, EINA_TRUE);
1367 elm_win_alpha_set(eo, EINA_TRUE);
1368 #endif /* HAVE_WAYLAND */
1370 g_print("\n\tfailed to get window\n\n");
1374 bg = elm_bg_add(eo);
1376 elm_win_resize_object_add(eo, bg);
1377 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1378 evas_object_show(bg);
1380 g_print("\n\tfailed to get elm bg\n\n");
1384 rect = evas_object_rectangle_add(evas_object_evas_get(eo));
1386 evas_object_color_set(rect, 0, 0, 0, 0);
1387 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1389 g_print("\n\tfailed to get rectangle\n\n");
1393 elm_win_resize_object_add(eo, rect);
1394 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1395 evas_object_show(rect);
1396 elm_win_activate(eo);
1397 evas_object_show(eo);
1399 #if !GLIB_CHECK_VERSION(2, 35, 0)
1400 if (!g_thread_supported())
1401 g_thread_init(NULL);
1404 timer = g_timer_new();
1406 gst_init(&argc, &argv);
1408 LOGD("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1410 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1411 camera_state = CAMERA_STATE_NONE;
1413 g_timer_reset(timer);
1415 bret = mode_change();
1421 g_loop = g_main_loop_new(NULL, FALSE);
1423 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1424 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1426 LOGD("RUN main loop");
1428 g_main_loop_run(g_loop);
1430 LOGD("STOP main loop");
1433 g_timer_stop(timer);
1434 g_timer_destroy(timer);
1438 g_main_loop_unref(g_loop);
1439 g_io_channel_unref(stdin_channel);