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 static struct timeval previous_time;
69 static struct timeval current_time;
70 static struct timeval result_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 PREVIEW_CB_DUMP_FILE_NAME "preview.data"
92 #define MAX_FILE_NAME_LENGTH 256
93 #define MAX_FILE_PATH_LENGTH (MAX_FILE_NAME_LENGTH - 20)
95 #define CHECK_MM_ERROR(expr) \
100 g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
107 #define SAFE_FREE(x) \
114 #define SENSOR_WHITEBALANCE_NUM 10
115 #define SENSOR_COLOR_TONE_NUM 31
116 #define SENSOR_FLIP_NUM 4
117 #define SENSOR_PROGRAM_MODE_NUM 15
118 #define SENSOR_FOCUS_NUM 6
119 #define SENSOR_INPUT_ROTATION 4
120 #define SENSOR_AF_SCAN_NUM 4
121 #define SENSOR_ISO_NUM 8
122 #define SENSOR_EXPOSURE_NUM 9
123 #define SENSOR_IMAGE_FORMAT 9
126 /*-----------------------------------------------------------------------
127 | LOCAL CONSTANT DEFINITIONS: |
128 -----------------------------------------------------------------------*/
130 MODE_VIDEO_CAPTURE, /* recording and image capture mode */
131 MODE_AUDIO, /* audio recording*/
142 /*-----------------------------------------------------------------------
143 | LOCAL DATA TYPE DEFINITIONS: |
144 -----------------------------------------------------------------------*/
145 typedef struct _cam_handle {
148 int is_multishot; /* flag for multishot mode */
149 int stillshot_count; /* stillshot count */
150 int multishot_count; /* multishot count */
151 char file_path[MAX_FILE_PATH_LENGTH]; /* file path for captured data */
153 unsigned long long elapsed_time;
163 camera_attr_exposure_mode_e mode;
168 camera_attr_iso_e mode;
173 /*---------------------------------------------------------------------------
174 | LOCAL VARIABLE DEFINITIONS: |
175 ---------------------------------------------------------------------------*/
176 static cam_handle_t *hcamcorder;
178 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
191 const char *ct[SENSOR_COLOR_TONE_NUM] = {
217 "SELECTVE_COLOR_RED",
218 "SELECTVE_COLOR_GREEN",
219 "SELECTVE_COLOR_BLUE",
220 "SELECTVE_COLOR_YELLOW",
221 "SELECTVE_COLOR_RED_YELLOW",
225 const char *sensor_flip[SENSOR_FLIP_NUM] = {
232 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
250 const char *focus_mode[SENSOR_FOCUS_NUM] = {
259 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
266 const char *iso_mode[SENSOR_ISO_NUM] = {
277 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
285 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
297 const char *face_zoom_mode[] = {
302 const char *display_mode[] = {
304 "Original Size mode",
306 "Cropped Full Screen mode",
310 const char *capture_sound[] = {
316 const char *rotate_mode[] = {
323 const char* strobe_mode[] = {
327 "Strobe RedEyeReduction",
329 "Strobe FrontCurtain",
330 "Strobe RearCurtain",
334 const char *detection_mode[2] = {
335 "Face Detection OFF",
339 const char *wdr_mode[] = {
345 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
352 const char *hdr_mode[] = {
355 "HDR ON and Original",
358 const char *ahs_mode[] = {
359 "Anti-handshake OFF",
361 "Anti-handshake AUTO",
362 "Anti-handshake MOVIE",
365 const char *vs_mode[] = {
366 "Video-stabilization OFF",
367 "Video-stabilization ON",
370 const char *visible_mode[] = {
375 const char *facing_direction[] = {
381 /*---------------------------------------------------------------------------
382 | LOCAL FUNCTION PROTOTYPES: |
383 ---------------------------------------------------------------------------*/
384 static void print_menu();
385 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data);
386 static gboolean mode_change(gchar buf);
387 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
390 static inline void flush_stdin()
393 while ((ch = getchar()) != EOF && ch != '\n');
396 static gboolean _release_idle_event_callback(void *data)
398 g_print("destroy camera handle\n\n");
400 camera_destroy(hcamcorder->camera);
401 hcamcorder->camera = NULL;
402 hcamcorder->menu_state = MENU_STATE_INIT;
409 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
411 g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
414 case CAMERA_ERROR_RESOURCE_CONFLICT:
415 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
417 case CAMERA_ERROR_SECURITY_RESTRICTED:
418 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
420 case CAMERA_ERROR_SERVICE_DISCONNECTED:
421 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
422 g_idle_add_full(G_PRIORITY_DEFAULT,
423 (GSourceFunc)_release_idle_event_callback,
433 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
435 g_print("\n\tcamera state changed %d -> %d\n", previous, current);
440 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
442 g_print("\n\tcamera 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("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
450 previous, current, policy);
455 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
457 g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
462 void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
465 char preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',};
468 snprintf(preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, PREVIEW_CB_DUMP_FILE_NAME);
470 fp = fopen(preview_dump, "a");
472 g_print("\n==== file[%s] open failed ====\n", preview_dump);
476 if (frame->format == CAMERA_PIXEL_FORMAT_RGBA ||
477 frame->format == CAMERA_PIXEL_FORMAT_ARGB) {
478 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
479 } else if (frame->format == CAMERA_PIXEL_FORMAT_INVZ) {
480 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
481 } else if (frame->format == CAMERA_PIXEL_FORMAT_MJPEG) {
482 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
484 switch (frame->num_of_planes) {
486 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
489 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
490 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
493 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
494 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
495 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
502 g_print("==== file[%s] write done ====\n", preview_dump);
507 g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
508 frame->format, frame->width, frame->height, frame->num_of_planes);
515 static bool preview_resolution_cb(int width, int height, void *user_data)
517 resolution_stack *data = (resolution_stack *)user_data;
520 g_print("NULL data\n");
524 data->width[data->count] = width;
525 data->height[data->count] = height;
527 g_print("\t%d. %dx%d\n", data->count, width, height);
534 static bool capture_resolution_test_cb(int width, int height, void *user_data)
536 resolution_stack *data = (resolution_stack *)user_data;
539 g_print("NULL data\n");
543 data->width[data->count] = width;
544 data->height[data->count] = height;
546 g_print("\t%d. %dx%d\n", data->count, width, height);
553 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
555 g_print("\t%d. %s\n", mode, af_scan[mode]);
559 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
561 exposure_stack *data = (exposure_stack *)user_data;
564 g_print("NULL data\n");
571 g_print("\t%d. %s\n", mode, exposure_mode[mode]);
575 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
577 g_print("\t%d. %s\n", mode, iso_mode[mode]);
581 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
583 g_print("\t%d. %s\n", mode, camera_rotation[mode]);
587 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
589 g_print("\t%d. %s\n", mode, sensor_flip[mode]);
593 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
595 g_print("\t%d. %s\n", mode, image_fmt[mode]);
599 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
601 g_print("\t%d. %s\n", mode, wb[mode]);
605 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
607 g_print("\t%d. %s\n", mode, ct[mode]);
611 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
613 g_print("\t%d. %s\n", mode, program_mode[mode]);
617 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
619 g_print("\t%d. %s\n", mode, strobe_mode[mode]);
623 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
625 g_print("\tface detected!! - count %d\n", count);
628 for (i = 0 ; i < count ; i++)
629 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
634 static void _file_write(char *path, void *data, int size)
638 if (!path || !data || size <= 0) {
639 g_print("\n\tERROR %p %p %d\n", path, data, size);
643 fp = fopen(path, "w");
645 g_print("\n\topen success [%s]\n", path);
646 if (fwrite(data, size, 1, fp) != 1)
647 g_print("\n\twrite error! errno %d\n", errno);
649 g_print("\n\twrite success [%s]\n", path);
654 g_print("\n\topen error! [%s], errno %d\n", path, errno);
660 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
662 char m_filename[MAX_FILE_NAME_LENGTH];
666 if (hcamcorder->is_multishot) {
667 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
668 hcamcorder->file_path, hcamcorder->multishot_count++);
670 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
671 hcamcorder->file_path, hcamcorder->stillshot_count++);
674 _file_write(m_filename, image->data, image->size);
680 static void capture_completed_cb(void *user_data)
682 camera_start_preview(hcamcorder->camera);
687 static void print_menu()
689 switch (hcamcorder->menu_state) {
690 case MENU_STATE_INIT:
691 g_print("\n\t=======================================\n");
692 g_print("\t CAMERA_TESTSUITE\n");
693 g_print("\t=======================================\n");
694 g_print("\t '1' Video Capture\n");
695 g_print("\t '2' Add camera device state changed callback\n");
696 g_print("\t '3' Remove camera device state changed callback\n");
697 g_print("\t '4' Get camera device state\n");
698 g_print("\t 'q' Exit\n");
699 g_print("\t=======================================\n");
701 case MENU_STATE_MAIN:
702 g_print("\n\t=======================================\n");
703 g_print("\t Video Capture (CAMERA%d)\n", cam_info);
704 g_print("\t=======================================\n");
705 g_print("\t '1' Stillshot test\n");
706 g_print("\t '2' Multishot test\n");
707 g_print("\t '3' Setting\n");
708 g_print("\t '4' Change device (CAMERA0 <-> CAMERA1)\n");
709 g_print("\t '5' Add preview callback\n");
710 g_print("\t '6' Remove preview callback\n");
711 g_print("\t 'b' back\n");
712 g_print("\t=======================================\n");
714 case MENU_STATE_SETTING:
715 g_print("\n\t=======================================\n");
716 g_print("\t Video Capture > Setting\n");
717 g_print("\t=======================================\n");
718 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
719 g_print("\t '0' Preview resolution \n");
720 g_print("\t '1' Capture resolution \n");
721 g_print("\t '2' Digital zoom level \n");
722 g_print("\t '3' AF mode \n");
723 g_print("\t '4' AF scan range \n");
724 g_print("\t '5' Exposure mode \n");
725 g_print("\t '6' Exposure value \n");
726 g_print("\t '7' F number \n");
727 g_print("\t '8' Display reuse hint \n");
728 g_print("\t 'i' ISO \n");
729 g_print("\t 'r' Rotate camera input \n");
730 g_print("\t 'f' Flip camera input \n");
731 g_print("\t 'j' Jpeg quality \n");
732 g_print("\t 'p' Picture format \n");
733 g_print("\t 'E' EXIF orientation \n");
734 g_print("\t 'F' Get facing direction of camera module\n");
735 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
736 g_print("\t 'v' Visible \n");
737 g_print("\t 'o' Output mode \n");
738 g_print("\t 'y' Rotate display \n");
739 g_print("\t 'Y' Flip display \n");
740 g_print("\t 'g' Brightness \n");
741 g_print("\t 'c' Contrast \n");
742 g_print("\t 'h' Hue \n");
743 g_print("\t 'w' White balance \n");
744 g_print("\t 't' Color tone \n");
745 g_print("\t 'd' WDR \n");
746 g_print("\t 'e' EV program mode \n");
747 g_print("\t 'R' Display ROI area \n");
748 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
749 g_print("\t 'z' Strobe (Flash) \n");
750 g_print("\t 'S' Strobe (Flash) state\n");
751 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
752 g_print("\t 'l' Face detection \n");
753 g_print("\t 'k' Anti-handshake \n");
754 g_print("\t 'K' Video-stabilization \n");
755 g_print("\t 'u' Touch AF area \n");
756 g_print("\t 'n' Set file path to write captured image\n");
757 g_print("\t 'b' back\n");
758 g_print("\t=======================================\n");
761 g_print("\n\tunknow menu state !!\n");
765 g_print("\tCommand >> ");
771 static void main_menu(gchar buf)
778 case '1': /* Capture */
779 hcamcorder->is_multishot = FALSE;
780 camera_attr_set_image_quality(hcamcorder->camera, 100);
781 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
782 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
784 case '2': /* multishot Capture */
785 g_print("multishot capture");
786 hcamcorder->is_multishot = TRUE;
787 g_print("\n\tinput interval(ms) : ");
788 err = scanf("%d", &interval);
790 g_print("\n\tinput count : ");
791 err = scanf("%d", &count);
793 camera_attr_set_image_quality(hcamcorder->camera, 100);
794 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
795 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
797 camera_start_preview(hcamcorder->camera);
799 case '3': /* Setting */
800 hcamcorder->menu_state = MENU_STATE_SETTING;
802 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
803 camera_set_display_reuse_hint(hcamcorder->camera, true);
805 camera_stop_preview(hcamcorder->camera);
807 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
808 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
810 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
812 camera_change_device(hcamcorder->camera, hcamcorder->type);
814 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
815 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
816 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
817 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
819 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
821 camera_start_preview(hcamcorder->camera);
824 camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
827 camera_unset_preview_cb(hcamcorder->camera);
830 camera_stop_preview(hcamcorder->camera);
831 camera_destroy(hcamcorder->camera);
832 hcamcorder->camera = NULL;
833 hcamcorder->menu_state = MENU_STATE_INIT;
836 g_print("\t Invalid input \n");
844 static void setting_menu(gchar buf)
860 case '0': /* Setting > Preview Resolution setting */
861 g_print("\t* Select the preview resolution!\n");
862 resolution_stack resolution_list;
863 resolution_list.count = 0;
865 camera_foreach_supported_preview_resolution(hcamcorder->camera,
866 preview_resolution_cb, &resolution_list);
868 g_print("\tCommand >> ");
870 err = scanf("%d", &idx);
872 if (resolution_list.count > idx && idx >= 0) {
873 g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
874 resolution_list.width[idx], resolution_list.height[idx]);
876 result = camera_set_preview_resolution(hcamcorder->camera,
877 resolution_list.width[idx], resolution_list.height[idx]);
879 g_print("\tInvalid command [%d]\n", idx);
882 resolution_list.count = 0;
883 if (result == CAMERA_ERROR_NONE)
888 case '1': /* Setting > Capture Resolution setting */
889 g_print("\t* Select the preview resolution!\n");
890 resolution_list.count = 0;
892 camera_foreach_supported_capture_resolution(hcamcorder->camera,
893 capture_resolution_test_cb, &resolution_list);
895 g_print("\tCommand > ");
897 err = scanf("%d", &idx);
899 if (resolution_list.count > idx && idx >= 0) {
900 g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
901 resolution_list.width[idx], resolution_list.height[idx]);
903 result = camera_set_capture_resolution(hcamcorder->camera,
904 resolution_list.width[idx], resolution_list.height[idx]);
906 g_print("\tInvalid command [%d]\n", idx);
909 resolution_list.count = 0;
910 if (result == CAMERA_ERROR_NONE)
915 case '2': /* Setting > Digital zoom level */
916 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
918 g_print("\tDigital Zoom Not supported\n");
920 g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
921 err = scanf("%d", &idx);
923 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
926 case '3': /* Setting > AF mode */
927 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
928 err = scanf("%d", &idx);
932 camera_start_focusing(hcamcorder->camera, 0);
935 camera_cancel_focusing(hcamcorder->camera);
938 g_print("\tInvalid command [%d]\n", idx);
942 case '4': /* Setting > AF scan range */
943 g_print("\t* AF scan range !\n");
944 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
945 g_print("\tCommand > ");
946 err = scanf("%d", &idx);
948 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
950 case '5': /* Setting > Exposure mode */
951 g_print("* Exposure mode!\n");
952 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
953 g_print("\n Select Exposure mode \n");
954 err = scanf("%d", &idx);
956 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
959 case '6': /* Setting > Exposure value */
960 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
962 g_print("Not supported !! \n");
964 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
965 err = scanf("%d", &idx);
967 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
970 case '7': /* Setting > F number */
971 g_print("Not supported !! \n");
973 case '8': /* Setting > Display reuse hint */
975 bool reuse_hint = false;
977 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
978 if (err != CAMERA_ERROR_NONE) {
979 g_print("failed to get display reuse hint 0x%x\n", err);
983 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
984 reuse_hint = !reuse_hint;
985 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
986 g_print("set display reuse hint result : 0x%x\n", err);
989 case 'i': /* Setting > ISO */
991 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
992 err = scanf("%d", &idx);
994 bret = camera_attr_set_iso(hcamcorder->camera, idx);
996 case 'r': /* Setting > Rotate camera input when recording */
997 g_print("*Rotate camera input\n");
998 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
999 err = scanf("%d", &idx);
1001 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1002 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1003 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1005 case 'f': /* Setting > Flip camera input */
1006 g_print("*Flip camera input\n");
1007 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1008 err = scanf("%d", &idx);
1010 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1011 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1012 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1014 case 'j': /* Setting > Jpeg quality */
1015 g_print("*Jpeg quality !\n");
1016 g_print("\n Select Jpeg quality \n");
1017 err = scanf("%d", &idx);
1019 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1021 case 'p': /* Setting > Picture format */
1022 g_print("* Picture format!\n");
1023 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1024 err = scanf("%d", &idx);
1026 bret = camera_set_preview_format(hcamcorder->camera, idx);
1027 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1028 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1030 case 'E': /* Setting > EXIF orientation */
1031 g_print("* EXIF Orientation\n");
1032 g_print("\t 1. TOP_LEFT\n");
1033 g_print("\t 2. TOP_RIGHT(flipped)\n");
1034 g_print("\t 3. BOTTOM_RIGHT\n");
1035 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1036 g_print("\t 5. LEFT_TOP(flipped)\n");
1037 g_print("\t 6. RIGHT_TOP\n");
1038 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1039 g_print("\t 8. LEFT_BOTTOM\n");
1040 err = scanf("%d", &idx);
1042 if (idx < 1 || idx > 8)
1043 g_print("Wrong INPUT[%d]!! \n", idx);
1045 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1047 case 'F': /* Getting > Get Facing direction */
1048 g_print("* Get facing direction of camera module\n");
1049 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1050 if (CAMERA_ERROR_NONE == err)
1051 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1053 g_print("* Error : %d\n", err);
1055 /* Display / Filter setting */
1056 case 'v': /* Display visible */
1057 g_print("* Display visible setting !\n");
1058 g_print("\n Select Display visible \n");
1059 for (i = 0 ; i < 2 ; i++)
1060 g_print("\t %d. %s\n", i, visible_mode[i]);
1061 err = scanf("%d", &idx);
1063 if (idx == 0 || idx == 1)
1064 bret = camera_set_display_visible(hcamcorder->camera, idx);
1066 g_print("invalid input %d", idx);
1068 case 'o': /* Setting > Display Mode */
1069 g_print("* Display mode!\n");
1070 for (i = 0 ; i < 5 ; i++)
1071 g_print("%d. %s\n", i, display_mode[i]);
1072 err = scanf("%d", &idx);
1074 bret = camera_set_display_mode(hcamcorder->camera, idx);
1076 case 'y': /* Setting > Rotate Display */
1077 g_print("\n Select Rotate mode\n");
1078 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1079 err = scanf("%d", &idx);
1081 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1082 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1083 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1085 case 'Y': /* Setting > Flip Display */
1086 g_print("\n Select Rotate mode\n");
1087 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1088 err = scanf("%d", &idx);
1090 bret = camera_set_display_flip(hcamcorder->camera, idx);
1092 case 'g': /* Setting > Brightness */
1093 g_print("*Brightness !\n");
1094 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1095 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1096 err = scanf("%d", &idx);
1098 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1100 case 'c': /* Setting > Contrast */
1101 g_print("*Contrast !\n");
1102 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1103 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1104 err = scanf("%d", &idx);
1106 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1108 case 'h': /* Setting > Hue */
1109 g_print("*Hue !\n");
1110 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1112 g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1113 err = scanf("%d", &idx);
1115 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1117 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1120 case 'w': /* Setting > White balance */
1121 g_print("*White balance !\n");
1122 g_print("\n Select White balance \n");
1123 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1124 err = scanf("%d", &idx);
1126 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1128 case 't': /* Setting > Color tone */
1129 g_print("*Color tone !\n");
1130 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1131 g_print("\n Select Color tone \n");
1132 err = scanf("%d", &idx);
1134 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1136 case 'd': /* Setting > WDR */
1137 g_print("*WDR !\n");
1138 g_print("\n Select WDR Mode \n");
1139 for (i = 0 ; i < 2 ; i++)
1140 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1141 err = scanf("%d", &idx);
1144 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1146 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1148 case 'e': /* Setting > EV program mode */
1149 g_print("* EV program mode!\n");
1150 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1151 g_print("\n Select EV program mode \n");
1152 err = scanf("%d", &idx);
1154 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1156 case 'R': /* Setting > Display ROI area */
1157 g_print("* Set display roi area. Select x y width height \n");
1158 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1160 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1161 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1162 if (CAMERA_ERROR_NONE != err)
1163 g_print("* Error : %d\n", err);
1165 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1166 if (CAMERA_ERROR_NONE == err)
1167 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1169 g_print("* Error : %d\n", err);
1173 case 'z': /* Setting > Strobe setting */
1174 g_print("*Strobe Mode\n");
1175 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1176 g_print("\n Select Strobe Mode \n");
1177 err = scanf("%d", &idx);
1179 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1181 case 'S': /* Setting > flash state */
1182 g_print("*flash state\n");
1183 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1184 if (CAMERA_ERROR_NONE == err)
1185 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1187 g_print("* Error : %d\n", err);
1189 case 'x': /* Setting > Capture mode ,Muitishot? */
1190 g_print("*Select Capture mode!\n");
1191 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1192 err = scanf("%d", &idx);
1197 g_print("stillshot mode selected and capture callback is set!!!!\n");
1198 hcamcorder->is_multishot = FALSE;
1199 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1202 g_print("HDR Capture mode selected\n");
1203 hcamcorder->is_multishot = FALSE;
1204 g_print("\nSelect HDR capture mode\n");
1205 for (i = 0 ; i < 3 ; i++)
1206 g_print("\t %d. %s\n", i, hdr_mode[i]);
1207 err = scanf("%d", &idx);
1209 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1210 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1212 g_print("invalid input %d\n", idx);
1215 g_print("Wrong input, select again!!\n");
1219 case 'l': /* Setting > Face detection setting */
1220 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1221 g_print("* Face detect mode !\n");
1222 for (i = 0 ; i < 2 ; i++)
1223 g_print("\t %d. %s \n", i, detection_mode[i]);
1224 err = scanf("%d", &idx);
1227 bret = camera_stop_face_detection(hcamcorder->camera);
1229 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1231 g_print("\n invalid input [%d]\n\n", idx);
1233 g_print("face detection_not supported");
1236 case 'k': /* Setting > Anti-handshake */
1237 g_print("*Anti-handshake !\n");
1238 g_print("\n Select Anti-handshake mode \n");
1239 for (i = 0; i < 2; i++)
1240 g_print("\t %d. %s\n", i, ahs_mode[i]);
1241 err = scanf("%d", &idx);
1243 if (idx == 0 || idx == 1)
1244 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1246 g_print("invalid input %d\n", idx);
1248 case 'K': /* Setting > Video-stabilization */
1249 g_print("*Video-stabilization !\n");
1250 g_print("\n Select Video-stabilization mode \n");
1251 for (i = 0 ; i < 2 ; i++)
1252 g_print("\t %d. %s\n", i, vs_mode[i]);
1253 err = scanf("%d", &idx);
1255 if (idx < 0 || idx > 1) {
1256 g_print("invalid input %d\n", idx);
1261 g_print("\n Restart preview with NV12 and 720p resolution\n");
1262 err = camera_stop_preview(hcamcorder->camera);
1263 g_print("stop preview result 0x%x\n", err);
1264 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1265 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1268 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1271 err = camera_start_preview(hcamcorder->camera);
1272 if (err != CAMERA_ERROR_NONE)
1273 g_print("\n Restart FAILED! 0x%x\n", err);
1276 case 'u': /* Touch AF area */
1277 g_print("* Touch AF area !\n");
1278 g_print("\n Input x,y,width,height \n");
1279 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1281 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1283 g_print("Failed to set touch AF area.(%x)\n", err);
1285 g_print("Succeed to set touch AF area.\n");
1287 case 'n': /* file path */
1288 g_print("* File path !\n");
1289 g_print("\n Input file path to save captured data(string) : ");
1290 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1291 hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1292 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1294 g_print("\nset file path failed\n");
1297 case 'b': /* back */
1298 hcamcorder->menu_state = MENU_STATE_MAIN;
1301 g_print("\t Invalid input \n");
1305 g_print("\t bret : 0x%x \n", bret);
1312 * This function is to execute command.
1314 * @param channel [in] 1st parameter
1316 * @return This function returns TRUE/FALSE
1320 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1324 GError *g_error = NULL;
1326 g_print("\n\tENTER\n");
1328 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1330 g_print("\n\tg_io_channel_read_chars error\n");
1331 g_error_free(g_error);
1338 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1339 switch (hcamcorder->menu_state) {
1340 case MENU_STATE_INIT:
1341 mode_change(buf[0]);
1343 case MENU_STATE_MAIN:
1346 case MENU_STATE_SETTING:
1347 setting_menu(buf[0]);
1358 g_print("\n\tNo read input\n");
1364 static gboolean init_handle()
1366 hcamcorder->is_multishot = FALSE;
1367 hcamcorder->stillshot_count = 0;
1368 hcamcorder->multishot_count = 0;
1369 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1370 hcamcorder->menu_state = MENU_STATE_INIT;
1371 hcamcorder->elapsed_time = 0;
1378 * This function is to change camcorder mode.
1380 * @param buf [in] user input
1382 * @return This function returns TRUE/FALSE
1384 * @see other functions
1386 static gboolean mode_change(gchar buf)
1389 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1390 char camera_type = '\0';
1391 char display_type = '\0';
1397 g_print("\n\tEnter the Camera Type[0 ~ 9] : ");
1399 err = scanf("%c", &camera_type);
1402 g_print("\t!!!read input error!!!\n");
1406 if (camera_type < '0' || camera_type > '9') {
1407 g_print("\t Invalid camera type(%c)\n", camera_type);
1411 hcamcorder->type = cam_info = camera_type - '0';
1417 err = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1418 NULL, &g_camera_device_changed_cb_id);
1419 g_print("add result 0x%x - cb id %d\n", err, g_camera_device_changed_cb_id);
1422 if (g_camera_device_changed_cb_id > 0) {
1423 err = camera_remove_device_state_changed_cb(g_camera_device_changed_cb_id);
1424 g_camera_device_changed_cb_id = 0;
1425 g_print("remove result 0x%x\n", err);
1427 g_print("invalid callback id %d\n", g_camera_device_changed_cb_id);
1431 err = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &device_state);
1432 g_print("get result 0x%x - state %d\n", err, device_state);
1435 g_print("\t Quit Camcorder Testsuite!!\n");
1439 g_print("\t Invalid media type(%c)\n", buf);
1443 g_print("\n[camcorder_create - type %d]\n", cam_info);
1445 gettimeofday(&previous_time, NULL);
1447 g_timer_reset(timer);
1449 err = camera_create(cam_info, &hcamcorder->camera);
1451 g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1454 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1459 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1461 err = scanf("%c", &display_type);
1464 g_print("\t!!!read input error!!!\n");
1468 switch (display_type) {
1470 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1474 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1478 camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1482 g_print("\t Invalid display type(%c)\n", display_type);
1487 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1488 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1489 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1490 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1491 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1492 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1493 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1494 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1496 camera_start_preview(hcamcorder->camera);
1498 gettimeofday(¤t_time, NULL);
1499 timersub(¤t_time, &previous_time, &result_time);
1501 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1503 hcamcorder->menu_state = MENU_STATE_MAIN;
1508 static int app_create(void *data)
1510 appdata *app_data = data;
1513 Evas_Object *win = NULL;
1514 Evas_Object *eo = NULL;
1515 Evas_Object *bg = NULL;
1516 Evas_Object *rect = NULL;
1518 if (app_data == NULL) {
1519 g_print("\t\nappdata is NULL\n");
1523 /* use gl backend */
1524 elm_config_accel_preference_set("opengl");
1526 win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1528 elm_win_title_set(win, "camera_test");
1529 elm_win_borderless_set(win, EINA_TRUE);
1530 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1531 g_print("\n\tscreen size %dx%d\n\n", w, h);
1532 evas_object_resize(win, w, h);
1533 elm_win_autodel_set(win, EINA_TRUE);
1534 elm_win_alpha_set(win, EINA_TRUE);
1536 g_print("\n\tfailed to get window\n\n");
1540 bg = elm_bg_add(win);
1542 elm_win_resize_object_add(win, bg);
1543 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1544 evas_object_show(bg);
1546 g_print("\n\tfailed to get elm bg\n\n");
1550 rect = evas_object_rectangle_add(evas_object_evas_get(win));
1552 evas_object_color_set(rect, 0, 0, 0, 0);
1553 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1555 g_print("\n\tfailed to get rectangle\n\n");
1559 elm_win_resize_object_add(win, rect);
1560 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1561 evas_object_show(rect);
1563 /* Create evas image object for EVAS surface */
1564 eo = evas_object_image_add(evas_object_evas_get(win));
1565 evas_object_image_size_set(eo, w, h);
1566 evas_object_image_fill_set(eo, 0, 0, w, h);
1567 evas_object_resize(eo, w, h);
1568 evas_object_show(eo);
1570 elm_win_activate(win);
1571 evas_object_show(win);
1573 app_data->win = win;
1576 timer = g_timer_new();
1577 g_timer_reset(timer);
1586 static int app_terminate(void *data)
1588 appdata *app_data = data;
1590 if (app_data == NULL) {
1591 g_print("\n\tappdata is NULL\n");
1596 g_timer_stop(timer);
1597 g_timer_destroy(timer);
1606 * This function is the example main function for mmcamcorder API.
1610 * @return This function returns 0.
1612 * @see other functions
1614 int main(int argc, char **argv)
1618 hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1620 stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1621 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1623 memset(&ad, 0x0, sizeof(appdata));
1626 bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1628 g_print("\n\treturn appcore_efl : %d\n\n", bret);
1631 g_io_channel_unref(stdin_channel);