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;
70 int camera_print_state;
72 static GTimer *timer = NULL;
74 GTimeVal previous_time;
75 GTimeVal current_time;
78 /*-----------------------------------------------------------------------
79 | GLOBAL CONSTANT DEFINITIONS: |
80 -----------------------------------------------------------------------*/
83 /*-----------------------------------------------------------------------
84 | IMPORTED VARIABLE DECLARATIONS: |
85 -----------------------------------------------------------------------*/
88 /*-----------------------------------------------------------------------
89 | IMPORTED FUNCTION DECLARATIONS: |
90 -----------------------------------------------------------------------*/
93 /*-----------------------------------------------------------------------
95 -----------------------------------------------------------------------*/
96 #define test_ffmux_mp4
99 #define DISPLAY_X_0 0 /* for direct FB */
100 #define DISPLAY_Y_0 0 /* for direct FB */
102 #define DISPLAY_W_320 320 /* for direct FB */
103 #define DISPLAY_H_240 240 /* for direct FB */
106 #define IMAGE_ENC_QUALITY 85 /* quality of jpeg */
107 #define IMAGE_CAPTURE_COUNT_STILL 1 /* the number of still-shot */
108 #define IMAGE_CAPTURE_COUNT_MULTI 3 /* default the number of multi-shot */
109 #define IMAGE_CAPTURE_COUNT_INTERVAL 100 /* millisecond */
111 #define MAX_FILE_SIZE_FOR_MMS (250 * 1024)
113 #define EXT_JPEG "jpg"
114 #define EXT_MP4 "mp4"
115 #define EXT_3GP "3gp"
116 #define EXT_AMR "amr"
117 #define EXT_MKV "mkv"
119 #define TARGET_FILENAME_PATH "/home/owner/content/"
120 #define STILL_CAPTURE_FILE_PATH_NAME TARGET_FILENAME_PATH"StillshotCapture"
121 #define MULTI_CAPTURE_FILE_PATH_NAME TARGET_FILENAME_PATH"MultishotCapture"
122 #define IMAGE_CAPTURE_THUMBNAIL_PATH TARGET_FILENAME_PATH"thumbnail.jpg"
123 #define IMAGE_CAPTURE_SCREENNAIL_PATH TARGET_FILENAME_PATH"screennail.yuv"
124 #define IMAGE_CAPTURE_EXIF_PATH TARGET_FILENAME_PATH"exif.raw"
125 #define CAPTURE_FILENAME_LEN 256
126 #define MAX_STILLSHOT_CAPTURE_RESOLUTION_SUPPORTED 2
128 #define CHECK_MM_ERROR(expr) \
133 printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
140 #define SAFE_FREE(x) \
147 #define SENSOR_WHITEBALANCE_NUM 10
148 #define SENSOR_COLOR_TONE_NUM 31
149 #define SENSOR_FLIP_NUM 3
150 #define SENSOR_PROGRAM_MODE_NUM 15
151 #define SENSOR_FOCUS_NUM 6
152 #define SENSOR_INPUT_ROTATION 4
153 #define SENSOR_AF_SCAN_NUM 4
154 #define SENSOR_ISO_NUM 8
155 #define SENSOR_EXPOSURE_NUM 9
156 #define SENSOR_IMAGE_FORMAT 9
159 /*-----------------------------------------------------------------------
160 | LOCAL CONSTANT DEFINITIONS: |
161 -----------------------------------------------------------------------*/
163 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
164 MODE_AUDIO, /* audio recording*/
175 /*-----------------------------------------------------------------------
176 | LOCAL DATA TYPE DEFINITIONS: |
177 -----------------------------------------------------------------------*/
178 typedef struct _cam_handle {
181 int mode; /* image(capture)/video(recording) mode */
182 int isMultishot; /* flag for multishot mode */
183 int stillshot_count; /* total stillshot count */
184 int multishot_count; /* total multishot count */
185 const char *stillshot_filename; /* stored filename of stillshot */
186 const char *multishot_filename; /* stored filename of multishot */
189 unsigned long long elapsed_time;
199 camera_attr_exposure_mode_e mode;
204 camera_attr_iso_e mode;
209 camera_rotation_e mode;
211 } camera_rotation_stack;
214 /*---------------------------------------------------------------------------
215 | LOCAL VARIABLE DEFINITIONS: |
216 ---------------------------------------------------------------------------*/
217 static cam_handle_t *hcamcorder;
219 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
232 const char *ct[SENSOR_COLOR_TONE_NUM] = {
258 "SELECTVE_COLOR_RED",
259 "SELECTVE_COLOR_GREEN",
260 "SELECTVE_COLOR_BLUE",
261 "SELECTVE_COLOR_YELLOW",
262 "SELECTVE_COLOR_RED_YELLOW",
266 const char *flip[SENSOR_FLIP_NUM] = {
272 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
290 const char *focus_mode[SENSOR_FOCUS_NUM] = {
299 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
306 const char *iso_mode[SENSOR_ISO_NUM] = {
317 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
325 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
337 const char *face_zoom_mode[] = {
342 const char *display_mode[] = {
344 "Original Size mode",
346 "Cropped Full Screen mode",
350 const char *capture_sound[] = {
356 const char *rotate_mode[] = {
363 const char* strobe_mode[] = {
367 "Strobe RedEyeReduction",
369 "Strobe FrontCurtain",
370 "Strobe RearCurtain",
374 const char *detection_mode[2] = {
375 "Face Detection OFF",
379 const char *wdr_mode[] = {
385 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
392 const char *hdr_mode[] = {
395 "HDR ON and Original",
398 const char *ahs_mode[] = {
399 "Anti-handshake OFF",
401 "Anti-handshake AUTO",
402 "Anti-handshake MOVIE",
405 const char *vs_mode[] = {
406 "Video-stabilization OFF",
407 "Video-stabilization ON",
410 const char *visible_mode[] = {
415 const char *facing_direction[] = {
421 /*---------------------------------------------------------------------------
422 | LOCAL FUNCTION PROTOTYPES: |
423 ---------------------------------------------------------------------------*/
424 static void print_menu();
425 static gboolean cmd_input(GIOChannel *channel);
426 static gboolean mode_change(gchar buf);
427 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
430 static inline void flush_stdin()
433 while ((ch = getchar()) != EOF && ch != '\n');
436 static bool _release_idle_event_callback(void *data)
438 printf("destroy camera handle\n\n");
440 camera_destroy(hcamcorder->camera);
441 hcamcorder->camera = NULL;
442 hcamcorder->menu_state = MENU_STATE_INIT;
448 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
450 printf("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
453 case CAMERA_ERROR_RESOURCE_CONFLICT:
454 printf("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
456 case CAMERA_ERROR_SECURITY_RESTRICTED:
457 printf("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
459 case CAMERA_ERROR_SERVICE_DISCONNECTED:
460 printf("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
461 g_idle_add_full(G_PRIORITY_DEFAULT,
462 (GSourceFunc)_release_idle_event_callback,
472 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
474 printf("camera state changed %d -> %d\n", previous, current);
477 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
479 printf("camera interrupted callback called %d\n", policy);
482 static bool preview_resolution_cb(int width, int height, void *user_data)
484 resolution_stack *data = (resolution_stack *)user_data;
487 printf("NULL data\n");
491 data->width[data->count] = width;
492 data->height[data->count] = height;
494 printf("%d. %dx%d\n", data->count, width, height);
501 static bool capture_resolution_test_cb(int width, int height, void *user_data)
503 resolution_stack *data = (resolution_stack *)user_data;
506 printf("NULL data\n");
510 data->width[data->count] = width;
511 data->height[data->count] = height;
513 printf("%d. %dx%d\n", data->count, width, height);
520 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
522 printf("%d.%s\n", mode, af_scan[mode]);
526 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
528 exposure_stack *data = (exposure_stack *)user_data;
531 printf("NULL data\n");
538 printf("%d.%s\n", mode, exposure_mode[mode]);
542 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
544 printf("%d.%s\n", mode, iso_mode[mode]);
548 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
550 camera_rotation_stack *data = (camera_rotation_stack *)user_data;
553 printf("NULL data\n");
560 printf("%d.%s\n", mode, camera_rotation[mode]);
565 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
567 printf("%d.%s\n", mode, image_fmt[mode]);
571 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
573 printf("%d.%s\n", mode, wb[mode]);
577 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
579 printf("%d.%s\n", mode, ct[mode]);
583 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
585 printf("%d.%s\n", mode, program_mode[mode]);
589 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
591 printf("%d.%s\n", mode, strobe_mode[mode]);
595 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
597 printf("face detected!!\n");
600 for (i = 0 ; i < count ; i++)
601 printf("%d) - %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
606 static void _file_write(char *path, void *data, int size)
610 if (!path || !data || size <= 0) {
611 printf("ERROR %p %p %d\n", path, data, size);
615 fp = fopen(path, "w");
617 printf("open error! [%s], errno %d\n", path, errno);
620 printf("open success [%s]\n", path);
621 if (fwrite(data, size, 1, fp) != 1)
622 printf("write error! errno %d\n", errno);
624 printf("write success [%s]\n", path);
631 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
633 char m_filename[CAPTURE_FILENAME_LEN];
635 if (!hcamcorder->isMultishot)
636 snprintf(m_filename, CAPTURE_FILENAME_LEN, "/opt/usr/media/Stillshot%03d.jpg", hcamcorder->multishot_count++);
638 snprintf(m_filename, CAPTURE_FILENAME_LEN, "/opt/usr/media/Multishot%03d.jpg", hcamcorder->stillshot_count++);
642 _file_write(m_filename, image->data, image->size);
647 static void capture_completed_cb(void *user_data)
649 camera_start_preview(hcamcorder->camera);
656 static void print_menu()
658 switch (hcamcorder->menu_state) {
659 case MENU_STATE_INIT:
660 g_print("\n\t=======================================\n");
661 g_print("\t CAMERA_TESTSUITE\n");
662 g_print("\t=======================================\n");
663 g_print("\t '1' Video Capture - Front Camera\n");
664 g_print("\t '2' Video Capture - Rear Camera\n");
665 g_print("\t 'q' Exit\n");
666 g_print("\t=======================================\n");
668 g_print("\t Enter the media type:\n\t");
670 case MENU_STATE_MAIN:
671 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
672 g_print("\n\t=======================================\n");
673 if (cam_info == CAMERA_DEVICE_CAMERA1)
674 g_print("\t Video Capture (Front camera)\n");
675 else if (cam_info == CAMERA_DEVICE_CAMERA0)
676 g_print("\t Video Capture (Rear camera)\n");
677 g_print("\t=======================================\n");
679 g_print("\t '1' Stillshot test\n");
680 g_print("\t '2' Multishot test\n");
681 g_print("\t '3' Setting\n");
682 g_print("\t '4' Change device (Rear <-> Front)\n");
683 g_print("\t 'b' back\n");
684 g_print("\t=======================================\n");
687 case MENU_STATE_SETTING:
688 g_print("\n\t=======================================\n");
689 g_print("\t Video Capture > Setting\n");
690 g_print("\t=======================================\n");
691 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
692 g_print("\t '0' Preview resolution \n");
693 g_print("\t '1' Capture resolution \n");
694 g_print("\t '2' Digital zoom level \n");
695 g_print("\t '3' AF mode \n");
696 g_print("\t '4' AF scan range \n");
697 g_print("\t '5' Exposure mode \n");
698 g_print("\t '6' Exposure value \n");
699 g_print("\t '7' F number \n");
700 g_print("\t '8' Display reuse hint \n");
701 g_print("\t 'i' ISO \n");
702 g_print("\t 'r' Rotate camera input \n");
703 g_print("\t 'f' Flip camera input \n");
704 g_print("\t 'j' Jpeg quality \n");
705 g_print("\t 'p' Picture format \n");
706 g_print("\t 'E' EXIF orientation \n");
707 g_print("\t 'F' Get facing direction of camera module\n");
708 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
709 g_print("\t 'v' Visible \n");
710 g_print("\t 'o' Output mode \n");
711 g_print("\t 'y' Rotate display \n");
712 g_print("\t 'Y' Flip display \n");
713 g_print("\t 'g' Brightness \n");
714 g_print("\t 'c' Contrast \n");
715 g_print("\t 'w' White balance \n");
716 g_print("\t 't' Color tone \n");
717 g_print("\t 'd' WDR \n");
718 g_print("\t 'e' EV program mode \n");
719 g_print("\t 'R' Display ROI area \n");
720 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
721 g_print("\t 'z' Strobe (Flash) \n");
722 g_print("\t 'S' Strobe (Flash) state\n");
723 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
724 g_print("\t 'l' Face detection \n");
725 g_print("\t 'k' Anti-handshake \n");
726 g_print("\t 'K' Video-stabilization \n");
727 g_print("\t 'u' Touch AF area \n");
729 g_print("\t 'b' back\n");
730 g_print("\t=======================================\n");
733 g_print("\n\tunknow menu state !!\n");
741 static void main_menu(gchar buf)
744 camera_state_e capi_state;
745 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
747 case '1': /* Capture */
748 hcamcorder->isMultishot = FALSE;
749 camera_get_state(hcamcorder->camera, &capi_state);
750 camera_attr_set_image_quality(hcamcorder->camera, 100);
751 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
752 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
754 case '2': /* multishot Capture */
755 g_print("multishot capture");
756 hcamcorder->isMultishot = TRUE;
757 int interval = 0, count = 0;
759 printf("\ninput interval(ms)\n");
760 err = scanf("%d", &interval);
762 printf("\ninput count(ms) \n");
763 err = scanf("%d", &count);
764 camera_attr_set_image_quality(hcamcorder->camera, 100);
765 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
766 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
768 camera_start_preview(hcamcorder->camera);
770 case '3': /* Setting */
771 hcamcorder->menu_state = MENU_STATE_SETTING;
773 case '4': /* Change device (Rear <-> Front) */
774 camera_stop_preview(hcamcorder->camera);
776 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0) {
777 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
779 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
782 camera_change_device(hcamcorder->camera, hcamcorder->type);
784 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
786 camera_start_preview(hcamcorder->camera);
789 camera_stop_preview(hcamcorder->camera);
790 camera_destroy(hcamcorder->camera);
791 hcamcorder->camera = NULL;
792 hcamcorder->menu_state = MENU_STATE_INIT;
796 g_print("\t Invalid input \n");
800 g_print("\t Invalid mode, back to upper menu \n");
801 hcamcorder->menu_state = MENU_STATE_INIT;
809 static void setting_menu(gchar buf)
811 gboolean bret = FALSE;
818 int x = 0, y = 0, width = 0, height = 0;
820 if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
823 case '0': /* Setting > Preview Resolution setting */
824 g_print("*Select the preview resolution!\n");
825 resolution_stack resolution_list;
826 resolution_list.count = 0;
828 camera_foreach_supported_preview_resolution(hcamcorder->camera,
829 preview_resolution_cb, &resolution_list);
832 err = scanf("%d", &idx);
834 if (resolution_list.count > idx && idx >= 0) {
835 printf("-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
836 resolution_list.width[idx], resolution_list.height[idx]);
838 result = camera_set_preview_resolution(hcamcorder->camera,
839 resolution_list.width[idx], resolution_list.height[idx]);
841 printf("invalid input %d\n", idx);
844 resolution_list.count = 0;
850 case '1': /* Setting > Capture Resolution setting */
851 g_print("*Select the preview resolution!\n");
852 printf("-----------------CAPTURE RESOLUTION TEST: ---------------------\n");
853 resolution_list.count = 0;
855 camera_foreach_supported_capture_resolution(hcamcorder->camera,
856 capture_resolution_test_cb, &resolution_list);
859 err = scanf("%d", &idx);
860 if (resolution_list.count > idx && idx >= 0) {
862 result = camera_set_capture_resolution(hcamcorder->camera,
863 resolution_list.width[idx], resolution_list.height[idx]);
865 printf("camera_set_capture_resolution with width =%d, height=%d ret=0x%x\n",
866 resolution_list.width[idx], resolution_list.height[idx], result);
868 printf("invalid input %d\n", idx);
871 resolution_list.count = 0;
878 case '2': /* Setting > Digital zoom level */
879 g_print("*Digital zoom level !\n");
880 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
882 g_print("Not supported !! \n");
885 g_print("\n Select Digital zoom level min %d - max %d\n", min, max);
886 err = scanf("%d", &idx);
887 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
890 case '3': /* Setting > AF mode */
891 g_print("*AF mode !\n");
892 g_print("\t1. AF Start !\n");
893 g_print("\t2. AF Stop !\n\n");
895 err = scanf("%d", &idx);
898 camera_start_focusing(hcamcorder->camera, 0);
901 camera_cancel_focusing(hcamcorder->camera);
904 g_print("Wrong Input[%d] !! \n", idx);
908 case '4': /* Setting > AF scan range */
909 g_print("*AF scan range !\n");
910 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
912 err = scanf("%d", &idx);
913 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
915 case '5': /* Setting > Exposure mode */
916 g_print("* Exposure mode!\n");
917 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
919 g_print("\n Select Exposure mode \n");
920 err = scanf("%d", &idx);
921 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
924 case '6': /* Setting > Exposure value */
925 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
927 g_print("Not supported !! \n");
930 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
931 err = scanf("%d", &idx);
932 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
935 case '7': /* Setting > F number */
936 g_print("Not supported !! \n");
938 case '8': /* Setting > Display reuse hint */
940 bool reuse_hint = false;
942 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
943 if (err != CAMERA_ERROR_NONE) {
944 g_print("failed to get display reuse hint 0x%x\n", err);
948 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
949 reuse_hint = !reuse_hint;
950 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
951 g_print("set display reuse hint result : 0x%x\n", err);
954 case 'i': /* Setting > ISO */
956 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
958 err = scanf("%d", &idx);
959 bret = camera_attr_set_iso(hcamcorder->camera, idx);
961 case 'r': /* Setting > Rotate camera input when recording */
962 g_print("*Rotate camera input\n");
963 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
965 err = scanf("%d", &idx);
966 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
967 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
968 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
970 case 'f': /* Setting > Flip camera input */
972 g_print("*Flip camera input\n");
973 g_print(" 0. Flip NONE\n");
974 g_print(" 1. Flip HORIZONTAL\n");
975 g_print(" 2. Flip VERTICAL\n");
976 g_print(" 3. Flip BOTH\n");
977 err = scanf("%d", &idx);
978 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
979 camera_attr_set_stream_flip(hcamcorder->camera, idx);
980 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
982 case 'j': /* Setting > Jpeg quality */
983 g_print("*Jpeg quality !\n");
985 g_print("\n Select Jpeg quality \n");
986 err = scanf("%d", &idx);
987 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
989 case 'p': /* Setting > Picture format */
990 g_print("* Picture format!\n");
991 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
993 err = scanf("%d", &idx);
994 bret = camera_set_preview_format(hcamcorder->camera, idx);
995 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
996 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
998 case 'E': /* Setting > EXIF orientation */
999 g_print("* EXIF Orientation\n");
1000 g_print("\t 1. TOP_LEFT\n");
1001 g_print("\t 2. TOP_RIGHT(flipped)\n");
1002 g_print("\t 3. BOTTOM_RIGHT\n");
1003 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1004 g_print("\t 5. LEFT_TOP(flipped)\n");
1005 g_print("\t 6. RIGHT_TOP\n");
1006 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1007 g_print("\t 8. LEFT_BOTTOM\n");
1009 err = scanf("%d", &idx);
1010 if (idx < 1 || idx > 8)
1011 g_print("Wrong INPUT[%d]!! \n", idx);
1013 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1015 case 'F': /* Getting > Get Facing direction */
1016 g_print("* Get facing direction of camera module\n");
1017 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1018 if (CAMERA_ERROR_NONE == err)
1019 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1021 g_print("* Error : %d\n", err);
1023 /* Display / Filter setting */
1024 case 'v': /* Display visible */
1025 g_print("* Display visible setting !\n");
1026 g_print("\n Select Display visible \n");
1028 for (i = 0 ; i < 2 ; i++)
1029 g_print("\t %d. %s\n", i+1, visible_mode[i]);
1030 err = scanf("%d", &value);
1031 bret = camera_set_display_visible(hcamcorder->camera, idx-1);
1033 case 'o': /* Setting > Display Mode */
1034 g_print("* Display mode!\n");
1036 for (i = 0 ; i < 5 ; i++)
1037 g_print("%d. %s\n", i, display_mode[i]);
1038 err = scanf("%d", &idx);
1039 bret = camera_set_display_mode(hcamcorder->camera, idx);
1041 case 'y': /* Setting > Rotate Display */
1043 g_print("\n Select Rotate mode\n");
1044 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1045 err = scanf("%d", &idx);
1046 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1047 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1048 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1050 case 'Y': /* Setting > Flip Display */
1052 g_print("\n Select Rotate mode\n");
1053 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1054 err = scanf("%d", &idx);
1055 bret = camera_set_display_flip(hcamcorder->camera, idx);
1057 case 'g': /* Setting > Brightness */
1058 g_print("*Brightness !\n");
1059 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1061 g_print("\n Select brightness min (%d) -max(%d)", min, max);
1062 err = scanf("%d", &idx);
1063 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1065 case 'c': /* Setting > Contrast */
1066 g_print("*Contrast !\n");
1067 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1069 g_print("\n Select Contrast min(%d)-max(%d)", min, max);
1070 err = scanf("%d", &idx);
1071 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1073 case 'w': /* Setting > White balance */
1074 g_print("*White balance !\n");
1076 g_print("\n Select White balance \n");
1077 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1078 err = scanf("%d", &idx);
1079 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1081 case 't': /* Setting > Color tone */
1082 g_print("*Color tone !\n");
1083 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1084 g_print("\n Select Color tone \n");
1086 err = scanf("%d", &idx);
1087 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1089 case 'd': /* Setting > WDR */
1090 g_print("*WDR !\n");
1091 g_print("\n Select WDR Mode \n");
1093 for (i = 0 ; i < 2 ; i++)
1094 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1095 err = scanf("%d", &idx);
1097 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1099 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1101 case 'e': /* Setting > EV program mode */
1102 g_print("* EV program mode!\n");
1103 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1104 g_print("\n Select EV program mode \n");
1106 err = scanf("%d", &idx);
1107 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1109 case 'R': /* Setting > Display ROI area */
1110 g_print("* Set display roi area. Select x y width height \n");
1112 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1113 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1114 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1115 if (CAMERA_ERROR_NONE != err)
1116 g_print("* Error : %d\n", err);
1118 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1119 if (CAMERA_ERROR_NONE == err)
1120 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1122 g_print("* Error : %d\n", err);
1126 case 'z': /* Setting > Strobe setting */
1127 g_print("*Strobe Mode\n");
1128 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1129 g_print("\n Select Strobe Mode \n");
1131 err = scanf("%d", &idx);
1132 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1134 case 'S': /* Setting > flash state */
1135 g_print("*flash state\n");
1136 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1137 if (CAMERA_ERROR_NONE == err)
1138 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1140 g_print("* Error : %d\n", err);
1142 case 'x': /* Setting > Capture mode ,Muitishot? */
1143 g_print("*Select Capture mode!\n");
1145 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1146 err = scanf("%d", &idx);
1150 g_print("stillshot mode selected and capture callback is set!!!!\n");
1151 hcamcorder->isMultishot = FALSE;
1152 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1155 g_print("HDR Capture mode selected\n");
1156 hcamcorder->isMultishot = FALSE;
1157 g_print("\nSelect HDR capture mode\n");
1159 for (i = 0 ; i < 3 ; i++)
1160 g_print("\t %d. %s\n", i+1, hdr_mode[i]);
1161 err = scanf("%d", &idx);
1162 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx-1);
1165 g_print("Wrong input, select again!!\n");
1169 case 'l': /* Setting > Face detection setting */
1170 g_print("* Face detect mode !\n");
1172 for (i = 0 ; i < 2 ; i++)
1173 g_print("\t %d. %s \n", i+1, detection_mode[i]);
1174 err = scanf("%d", &idx);
1175 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1176 if (idx >= 0 && idx < 2)
1177 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1179 g_print("face detection_not supported");
1181 case 'k': /* Setting > Anti-handshake */
1182 g_print("*Anti-handshake !\n");
1183 g_print("\n Select Anti-handshake mode \n");
1185 for (i = 0; i < 2; i++)
1186 g_print("\t %d. %s\n", i+1, ahs_mode[i]);
1187 err = scanf("%d", &idx);
1188 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx-1);
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+1, vs_mode[i]);
1196 err = scanf("%d", &idx);
1198 g_print("\n Restart preview with NV12 and 720p resolution\n");
1199 err = camera_stop_preview(hcamcorder->camera);
1200 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1201 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1202 camera_attr_enable_video_stabilization(hcamcorder->camera, idx-1);
1204 err = camera_start_preview(hcamcorder->camera);
1206 g_print("\n Restart FAILED! %x\n", err);
1210 case 'u': /* Touch AF area */
1211 g_print("* Touch AF area !\n");
1213 g_print("\n Input x,y,width,height \n");
1214 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1215 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1217 g_print("Failed to set touch AF area.(%x)\n", err);
1219 g_print("Succeed to set touch AF area.\n");
1221 case 'b': /* back */
1222 hcamcorder->menu_state = MENU_STATE_MAIN;
1225 g_print("\t Invalid input \n");
1229 g_print("\t Invalid mode, back to upper menu \n");
1230 hcamcorder->menu_state = MENU_STATE_MAIN;
1233 g_print("\t bret : 0x%x \n", bret);
1240 * This function is to execute command.
1242 * @param channel [in] 1st parameter
1244 * @return This function returns TRUE/FALSE
1248 static gboolean cmd_input(GIOChannel *channel)
1252 GError *g_error = NULL;
1254 g_print("\n\tENTER\n");
1256 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1258 g_print("\n\tg_io_channel_read_chars error\n");
1259 g_error_free(g_error);
1266 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1267 switch (hcamcorder->menu_state) {
1268 case MENU_STATE_INIT:
1269 mode_change(buf[0]);
1271 case MENU_STATE_MAIN:
1274 case MENU_STATE_SETTING:
1275 setting_menu(buf[0]);
1286 g_print("\n\tNo read input\n");
1292 static gboolean init_handle()
1294 hcamcorder->mode = MODE_VIDEO_CAPTURE; /* image(capture)/video(recording) mode */
1295 hcamcorder->isMultishot = FALSE;
1296 hcamcorder->stillshot_count = 0; /* total stillshot count */
1297 hcamcorder->multishot_count = 0; /* total multishot count */
1298 hcamcorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME; /* stored filename of stillshot */
1299 hcamcorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME; /* stored filename of multishot */
1300 hcamcorder->menu_state = MENU_STATE_INIT;
1301 hcamcorder->isMute = FALSE;
1302 hcamcorder->elapsed_time = 0;
1303 multishot_num = IMAGE_CAPTURE_COUNT_MULTI;
1308 void _preview_cb(camera_preview_data_s *frame, void *user_data)
1311 FILE *fp = fopen("/opt/usr/media/test.yuv", "a");
1313 g_print("\n============ file open failed ===========================\n");
1317 switch (frame->num_of_planes) {
1319 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
1321 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
1322 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
1324 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
1325 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
1326 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
1331 g_print("file write done ---\n");
1336 g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
1337 frame->format, frame->width, frame->height, frame->num_of_planes);
1344 * This function is to change camcorder mode.
1346 * @param buf [in] user input
1348 * @return This function returns TRUE/FALSE
1350 * @see other functions
1352 static gboolean mode_change(gchar buf)
1355 char display_type = '\0';
1360 hcamcorder->mode = MODE_VIDEO_CAPTURE;
1361 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA1;
1365 hcamcorder->mode = MODE_VIDEO_CAPTURE;
1366 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA0;
1370 g_print("\t Quit Camcorder Testsuite!!\n");
1371 hcamcorder->mode = -1;
1375 g_print("\t Invalid media type(%c)\n", buf);
1379 g_print("\n[camcorder_create - type %d]\n", cam_info);
1381 g_get_current_time(&previous_time);
1383 g_timer_reset(timer);
1385 err = camera_create(cam_info, &hcamcorder->camera);
1387 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1390 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1394 camera_print_state = CAMERA_STATE_CREATED;
1398 g_print("\n\tEnter the Display Type\n");
1399 g_print("\t'1' OVERLAY surface\n");
1400 g_print("\t'2' EVAS surface\n");
1401 g_print("\t'3' NONE surface\n");
1403 err = scanf("%c", &display_type);
1405 g_print("\t!!!read input error!!!\n");
1409 switch (display_type) {
1411 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1415 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1419 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1423 g_print("\t Invalid display type(%c)\n", display_type);
1428 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1429 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1430 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1431 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1432 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1433 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1434 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1436 camera_start_preview(hcamcorder->camera);
1438 g_get_current_time(¤t_time);
1439 timersub(¤t_time, &previous_time, &res);
1441 g_print("\n\tCamera Starting Time : %ld.%lds\n", res.tv_sec, res.tv_usec);
1443 camera_print_state = CAMERA_STATE_PREVIEW;
1444 hcamcorder->menu_state = MENU_STATE_MAIN;
1451 static int app_create(void *data)
1453 appdata *app_data = data;
1456 Evas_Object *win = NULL;
1457 Evas_Object *eo = NULL;
1458 Evas_Object *bg = NULL;
1459 Evas_Object *rect = NULL;
1461 if (app_data == NULL) {
1462 g_print("\t\nappdata is NULL\n");
1466 /* use gl backend */
1467 elm_config_accel_preference_set("opengl");
1469 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1471 elm_win_title_set(win, "camera_test");
1472 elm_win_borderless_set(win, EINA_TRUE);
1473 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1474 g_print("\n\tscreen size %dx%d\n\n", w, h);
1475 evas_object_resize(win, w, h);
1476 elm_win_autodel_set(win, EINA_TRUE);
1477 elm_win_alpha_set(win, EINA_TRUE);
1479 g_print("\n\tfailed to get window\n\n");
1483 bg = elm_bg_add(win);
1485 elm_win_resize_object_add(win, bg);
1486 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1487 evas_object_show(bg);
1489 g_print("\n\tfailed to get elm bg\n\n");
1493 rect = evas_object_rectangle_add(evas_object_evas_get(win));
1495 evas_object_color_set(rect, 0, 0, 0, 0);
1496 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1498 g_print("\n\tfailed to get rectangle\n\n");
1502 elm_win_resize_object_add(win, rect);
1503 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1504 evas_object_show(rect);
1506 /* Create evas image object for EVAS surface */
1507 eo = evas_object_image_add(evas_object_evas_get(win));
1508 evas_object_image_size_set(eo, w, h);
1509 evas_object_image_fill_set(eo, 0, 0, w, h);
1510 evas_object_resize(eo, w, h);
1511 evas_object_show(eo);
1513 elm_win_activate(win);
1514 evas_object_show(win);
1516 app_data->win = win;
1519 timer = g_timer_new();
1520 g_timer_reset(timer);
1529 static int app_terminate(void *data)
1531 appdata *app_data = data;
1533 if (app_data == NULL) {
1534 g_print("\n\tappdata is NULL\n");
1539 g_timer_stop(timer);
1540 g_timer_destroy(timer);
1549 * This function is the example main function for mmcamcorder API.
1553 * @return This function returns 0.
1555 * @see other functions
1557 int main(int argc, char **argv)
1561 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1562 camera_state = CAMERA_STATE_NONE;
1564 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1565 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1567 memset(&ad, 0x0, sizeof(appdata));
1570 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1572 g_print("\n\treturn appcore_efl : %d\n\n", bret);
1575 g_io_channel_unref(stdin_channel);