4 * Copyright (c) 2022 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 =======================================================================================*/
26 #include "camera_test.h"
28 /*-----------------------------------------------------------------------
29 | GLOBAL VARIABLE DEFINITIONS: |
30 -----------------------------------------------------------------------*/
31 #define EXPORT_API __attribute__((__visibility__("default")))
36 #define LOG_TAG "CAMERA_TEST"
39 static cam_handle_t *hcamcorder;
40 static camera_device_e camera_device;
41 static int g_camera_device_state_changed_cb_id;
42 static int g_camera_device_connection_changed_cb_id;
43 static int g_camera_preview_cb_dump;
44 static int g_camera_extra_preview_cb_dump;
45 static int g_camera_mp_preview_cb_dump;
47 static struct timeval previous_time;
48 static struct timeval current_time;
49 static struct timeval result_time;
51 static media_bridge_h bridge;
52 static camera_device_manager_h g_device_manager;
54 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
67 const char *ct[SENSOR_COLOR_TONE_NUM] = {
94 "SELECTVE_COLOR_GREEN",
95 "SELECTVE_COLOR_BLUE",
96 "SELECTVE_COLOR_YELLOW",
97 "SELECTVE_COLOR_RED_YELLOW",
101 const char *sensor_flip[SENSOR_FLIP_NUM] = {
108 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
126 const char *focus_mode[SENSOR_FOCUS_NUM] = {
135 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
142 const char *iso_mode[SENSOR_ISO_NUM] = {
153 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
161 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
176 "ITLV(YUYV+JPEG, but should not be seen)",
184 const char *face_zoom_mode[] = {
189 const char *display_mode[] = {
191 "Original Size mode",
193 "Cropped Full Screen mode",
197 const char *capture_sound[] = {
203 const char *rotate_mode[] = {
210 const char* strobe_mode[] = {
214 "Strobe RedEyeReduction",
216 "Strobe FrontCurtain",
217 "Strobe RearCurtain",
221 const char *detection_mode[2] = {
222 "Face Detection OFF",
226 const char *wdr_mode[] = {
232 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
239 const char *hdr_mode[] = {
242 "HDR ON and Original",
245 const char *ahs_mode[] = {
246 "Anti-handshake OFF",
248 "Anti-handshake AUTO",
249 "Anti-handshake MOVIE",
252 const char *vs_mode[] = {
253 "Video-stabilization OFF",
254 "Video-stabilization ON",
257 const char *visible_mode[] = {
262 const char *facing_direction[] = {
268 /*---------------------------------------------------------------------------
269 | LOCAL FUNCTION PROTOTYPES: |
270 ---------------------------------------------------------------------------*/
271 static gboolean mode_change(gchar buf);
272 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
275 static void __release_media_bridge()
278 media_bridge_unset_source(bridge); /* not mandatory, it will be done in media_bridge_destroy() */
279 media_bridge_destroy(bridge);
287 while ((ch = getchar()) != EOF && ch != '\n');
290 static gboolean _release_idle_event_callback(void *data)
292 g_print("destroy camera handle\n\n");
294 camera_destroy(hcamcorder->camera);
295 hcamcorder->camera = NULL;
296 hcamcorder->menu_state = MENU_STATE_INIT;
303 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
305 g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
308 case CAMERA_ERROR_RESOURCE_CONFLICT:
309 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
311 case CAMERA_ERROR_SECURITY_RESTRICTED:
312 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
314 case CAMERA_ERROR_SERVICE_DISCONNECTED:
315 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
316 g_idle_add_full(G_PRIORITY_DEFAULT,
317 (GSourceFunc)_release_idle_event_callback,
325 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
327 g_print("\n\tcamera state changed %d -> %d\n", previous, current);
330 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
332 g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
335 static void _camera_device_connection_changed_cb(camera_device_s *device, bool is_connected, void *user_data)
337 g_print("\n\tcamera device changed[is_connected:%d][Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
338 is_connected, device->type, device->index, device->name, device->id, device->extra_stream_num);
341 static bool _camera_supported_device_cb(camera_device_s *device, void *user_data)
343 g_print("\n\tcamera supported device[Type:%d,index:%d,name:%s,id:%s,exstream:%d]\n",
344 device->type, device->index, device->name, device->id, device->extra_stream_num);
349 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
351 g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
352 previous, current, policy);
355 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
357 g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
360 static void _dump_preview_data(camera_preview_data_s *frame, const char *file_name)
362 char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
370 snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
372 fp = fopen(dump_path, "a");
374 LOGE("file[%s] open failed", dump_path);
378 switch (frame->format) {
379 case CAMERA_PIXEL_FORMAT_RGBA:
381 case CAMERA_PIXEL_FORMAT_ARGB:
382 LOGD("RGB p[%p] size[%u]", frame->data.rgb_plane.data, frame->data.rgb_plane.size);
383 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
385 case CAMERA_PIXEL_FORMAT_INVZ:
386 LOGD("INVZ p[%p] size[%u]", frame->data.depth_plane.data, frame->data.depth_plane.size);
387 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
389 case CAMERA_PIXEL_FORMAT_H264:
391 case CAMERA_PIXEL_FORMAT_MJPEG:
393 case CAMERA_PIXEL_FORMAT_VP8:
395 case CAMERA_PIXEL_FORMAT_VP9:
396 LOGD("ENCODED[%d] p[%p] size[%u]",
397 frame->format, frame->data.encoded_plane.data, frame->data.encoded_plane.size);
398 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
401 switch (frame->num_of_planes) {
403 LOGD("SINGLE plane p[%p], size[%u]",
404 frame->data.single_plane.yuv, frame->data.single_plane.size);
405 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
408 LOGD("DOUBLE plane p[%p,%p], size[%u,%u]",
409 frame->data.double_plane.y, frame->data.double_plane.uv,
410 frame->data.double_plane.y_size, frame->data.double_plane.uv_size);
411 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
412 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
415 LOGD("TRIPLE plane p[%p,%p,%p], size[%u,%u,%u]",
416 frame->data.triple_plane.y, frame->data.triple_plane.u, frame->data.triple_plane.v,
417 frame->data.triple_plane.y_size, frame->data.triple_plane.u_size, frame->data.triple_plane.v_size);
418 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
419 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
420 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
431 static void _camera_print_preview_info(camera_preview_data_s *frame, int stream_id)
433 char frame_info[128] = {'\0', };
436 LOGE("[PREVIEW_CB] NULL frame!");
440 snprintf(frame_info, sizeof(frame_info), "stream_id[%d] format[%d] res[%dx%d] num plane[%d]",
441 stream_id, frame->format, frame->width, frame->height, frame->num_of_planes);
443 if (frame->num_of_planes == 1) {
446 frame->data.single_plane.size);
447 } else if (frame->num_of_planes == 2) {
448 LOGD("%s size Y[%d] UV[%d]",
450 frame->data.double_plane.y_size,
451 frame->data.double_plane.uv_size);
452 } else if (frame->num_of_planes == 3) {
453 LOGD("%s size Y[%d] U[%d] V[%d]",
455 frame->data.triple_plane.y_size,
456 frame->data.triple_plane.u_size,
457 frame->data.triple_plane.v_size);
461 static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
463 int ret = CAMERA_ERROR_NONE;
464 camera_h cam_handle = (camera_h)user_data;
465 camera_rotation_e rotation = CAMERA_ROTATION_NONE;
466 unsigned long timestamp = 0;
467 camera_meta_timestamp_s meta_timestamp = {0, };
469 if (!cam_handle || !frame) {
470 LOGE("NULL param! %p %p", cam_handle, frame);
474 ret = camera_attr_get_preview_frame_rotation(cam_handle, &rotation);
475 if (ret != CAMERA_ERROR_NONE)
476 LOGW("get preview frame rotation failed[0x%x]", ret);
478 ret = camera_attr_get_preview_frame_timestamp(cam_handle, ×tamp);
479 if (ret != CAMERA_ERROR_NONE)
480 LOGW("get preview frame timestamp failed[0x%x]", ret);
482 LOGI("rotation[%d], timestamp[%lu]", rotation, timestamp);
484 ret = camera_attr_get_preview_frame_meta_timestamp(cam_handle, &meta_timestamp);
485 if (ret == CAMERA_ERROR_NONE) {
486 LOGD("meta %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
487 meta_timestamp.ts_soe, meta_timestamp.ts_eoe,
488 meta_timestamp.ts_sof, meta_timestamp.ts_eof,
489 meta_timestamp.ts_hal, meta_timestamp.ts_qmf,
490 meta_timestamp.ts_gst, meta_timestamp.td_exp,
491 meta_timestamp.ts_aux, meta_timestamp.td_aux);
493 LOGW("get preview frame meta timestamp failed[0x%x]", ret);
496 _camera_print_preview_info(frame, -1);
498 if (g_camera_preview_cb_dump)
499 _dump_preview_data(frame, PREVIEW_CB_DUMP_FILE_NAME);
502 static void _camera_extra_preview_cb(camera_preview_data_s *frame, int stream_id, void *user_data)
509 _camera_print_preview_info(frame, stream_id);
511 if (g_camera_extra_preview_cb_dump)
512 _dump_preview_data(frame, EXTRA_PREVIEW_CB_DUMP_FILE_NAME);
515 static void _dump_media_packet_data(media_packet_h pkt, const char *file_name)
519 bool has_surface = false;
521 char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
522 tbm_surface_h surface = NULL;
523 tbm_surface_info_s s_info;
525 uint64_t data_size = 0;
532 snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
533 fp = fopen(dump_path, "a");
535 LOGE("file[%s] open failed[errno:%d]", dump_path, errno);
536 goto _DUMP_MEDIA_PACKET_DATA_OUT;
539 ret = media_packet_has_tbm_surface_buffer(pkt, &has_surface);
540 if (ret != MEDIA_PACKET_ERROR_NONE) {
541 LOGE("has tbm surface failed[0x%x]", ret);
542 goto _DUMP_MEDIA_PACKET_DATA_OUT;
546 ret = media_packet_get_tbm_surface(pkt, &surface);
547 if (ret != MEDIA_PACKET_ERROR_NONE) {
548 LOGE("get tbm surface failed[0x%x]", ret);
549 goto _DUMP_MEDIA_PACKET_DATA_OUT;
552 ret = tbm_surface_get_info(surface, &s_info);
553 if (ret != TBM_SURFACE_ERROR_NONE) {
554 LOGE("get tbm surface info failed[0x%x]", ret);
555 goto _DUMP_MEDIA_PACKET_DATA_OUT;
558 LOGD("tbm surface[%dx%d], size[%u]", s_info.width, s_info.height, s_info.size);
560 for (i = 0 ; i < s_info.num_planes ; i++) {
561 LOGD(" plane[%d][%p] stride[%u] size[%u]",
562 i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
564 fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
567 ret = media_packet_get_buffer_data_ptr(pkt, &data);
568 if (ret != MEDIA_PACKET_ERROR_NONE) {
569 LOGE("get data ptr failed[0x%x]", ret);
570 goto _DUMP_MEDIA_PACKET_DATA_OUT;
573 ret = media_packet_get_buffer_size(pkt, &data_size);
574 if (ret != MEDIA_PACKET_ERROR_NONE) {
575 LOGE("get data size failed[0x%x]", ret);
576 goto _DUMP_MEDIA_PACKET_DATA_OUT;
579 LOGD("no tbm surface, data[%p], size[%"PRIu64"]", data, data_size);
581 fwrite(data, 1, data_size, fp);
584 _DUMP_MEDIA_PACKET_DATA_OUT:
589 static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
594 media_format_h fmt = NULL;
595 media_format_mimetype_e type = MEDIA_FORMAT_I420;
598 LOGE("NULL packet!");
602 ret = media_packet_get_format(pkt, &fmt);
603 if (ret != MEDIA_PACKET_ERROR_NONE) {
604 LOGW("get media format failed[0x%x]", ret);
605 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
608 ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
609 if (ret != MEDIA_FORMAT_ERROR_NONE) {
610 LOGW("get video info failed[0x%x]", ret);
611 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
614 LOGD("mimetype[0x%x], resolution[%dx%d]", type, width, height);
616 if (g_camera_mp_preview_cb_dump)
617 _dump_media_packet_data(pkt, MP_PREVIEW_CB_DUMP_FILE_NAME);
619 _MEDIA_PACKET_PREVIEW_CB_OUT:
621 media_format_unref(fmt);
625 media_packet_unref(pkt);
628 static bool _resolution_cb(int width, int height, void *user_data)
630 resolution_stack *data = (resolution_stack *)user_data;
633 g_print("NULL data\n");
637 data->width[data->count] = width;
638 data->height[data->count] = height;
640 g_print("\t%d. %dx%d\n", data->count, width, height);
647 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
649 g_print("\t%d. %s\n", mode, af_scan[mode]);
653 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
655 exposure_stack *data = (exposure_stack *)user_data;
658 g_print("NULL data\n");
665 g_print("\t%d. %s\n", mode, exposure_mode[mode]);
669 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
671 g_print("\t%d. %s\n", mode, iso_mode[mode]);
675 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
677 g_print("\t%d. %s\n", mode, camera_rotation[mode]);
681 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
683 g_print("\t%d. %s\n", mode, sensor_flip[mode]);
687 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
689 g_print("\t%d. %s\n", mode, image_fmt[mode]);
693 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
695 g_print("\t%d. %s\n", mode, wb[mode]);
699 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
701 g_print("\t%d. %s\n", mode, ct[mode]);
705 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
707 g_print("\t%d. %s\n", mode, program_mode[mode]);
711 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
713 g_print("\t%d. %s\n", mode, strobe_mode[mode]);
717 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
721 g_print("\tface detected!! - count %d\n", count);
723 for (i = 0 ; i < count ; i++)
724 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
727 static void _file_write(char *path, void *data, int size)
731 if (!path || !data || size <= 0) {
732 g_print("\n\tERROR %p %p %d\n", path, data, size);
736 fp = fopen(path, "w");
738 g_print("\n\topen success [%s]\n", path);
739 if (fwrite(data, size, 1, fp) != 1)
740 g_print("\n\twrite error! errno %d\n", errno);
742 g_print("\n\twrite success [%s]\n", path);
747 g_print("\n\topen error! [%s], errno %d\n", path, errno);
751 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
753 char m_filename[MAX_FILE_NAME_LENGTH];
757 if (hcamcorder->is_multishot) {
758 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
759 hcamcorder->file_path, hcamcorder->multishot_count++);
761 snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
762 hcamcorder->file_path, hcamcorder->stillshot_count++);
765 _file_write(m_filename, image->data, image->size);
769 static void capture_completed_cb(void *user_data)
771 camera_start_preview(hcamcorder->camera);
776 switch (hcamcorder->menu_state) {
777 case MENU_STATE_INIT:
778 g_print("\n\t=======================================\n");
779 g_print("\t CAMERA_TESTSUITE\n");
780 g_print("\t=======================================\n");
781 g_print("\t '1' Video Capture\n");
782 g_print("\t '2' Device State\n");
783 g_print("\t '3' Device Manager\n");
784 g_print("\t 'q' Exit\n");
785 g_print("\t=======================================\n");
787 case MENU_STATE_MAIN:
788 g_print("\n\t=======================================\n");
789 g_print("\t Video Capture (CAMERA%d)\n", camera_device);
790 g_print("\t=======================================\n");
791 g_print("\t '1' Stillshot test\n");
792 g_print("\t '2' Multishot test\n");
793 g_print("\t '3' Setting\n");
794 g_print("\t '4' Change device (CAMERA0 <-> CAMERA1)\n");
795 g_print("\t '5' Set/Unset preview callback\n");
796 g_print("\t '6' Set/Unset extra preview callback\n");
797 g_print("\t '7' Set/Unset media packet preview callback\n");
798 g_print("\t 'b' back\n");
799 g_print("\t=======================================\n");
801 case MENU_STATE_DEVICE_STATE:
802 g_print("\n\t=======================================\n");
803 g_print("\t Device State\n");
804 g_print("\t=======================================\n");
805 g_print("\t '1' Get camera device state\n");
806 g_print("\t '2' Add camera device state changed callback\n");
807 g_print("\t '3' Remove camera device state changed callback\n");
808 g_print("\t 'b' back\n");
809 g_print("\t=======================================\n");
811 case MENU_STATE_DEVICE_MANAGER:
812 g_print("\n\t=======================================\n");
813 g_print("\t Device List\n");
814 g_print("\t=======================================\n");
815 g_print("\t '1' Initialize device manager\n");
816 g_print("\t '2' Foreach supported camera device\n");
817 g_print("\t '3' Add camera device connection changed callback\n");
818 g_print("\t '4' Remove camera device connection changed callback\n");
819 g_print("\t '9' Deinitialize device manager\n");
820 g_print("\t 'b' back\n");
821 g_print("\t=======================================\n");
823 case MENU_STATE_MAIN_SETTING:
824 g_print("\n\t=======================================\n");
825 g_print("\t Video Capture > Setting\n");
826 g_print("\t=======================================\n");
827 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera] \n");
828 g_print("\t '0' Preview resolution \n");
829 g_print("\t '1' Capture resolution \n");
830 g_print("\t '2' Digital zoom level \n");
831 g_print("\t '3' AF mode \n");
832 g_print("\t '4' AF scan range \n");
833 g_print("\t '5' Exposure mode \n");
834 g_print("\t '6' Exposure value \n");
835 g_print("\t '7' F number \n");
836 g_print("\t '8' Display reuse hint \n");
837 g_print("\t '9' Manual Focus \n");
838 g_print("\t 'i' ISO \n");
839 g_print("\t 'r' Rotate camera input \n");
840 g_print("\t 'f' Flip camera input \n");
841 g_print("\t 'j' Jpeg quality \n");
842 g_print("\t 'p' Picture format \n");
843 g_print("\t 'E' EXIF orientation \n");
844 g_print("\t 'F' Get facing direction of camera module\n");
845 g_print("\t 's' Extra preview stream format\n");
846 g_print("\t 'B' Extra preview bitrate\n");
847 g_print("\t 'V' Extra preview GOP interval\n");
848 g_print("\t 'D' Request codec config\n");
849 g_print("\t >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
850 g_print("\t 'v' Visible \n");
851 g_print("\t 'o' Output mode \n");
852 g_print("\t 'y' Rotate display \n");
853 g_print("\t 'Y' Flip display \n");
854 g_print("\t 'g' Brightness \n");
855 g_print("\t 'c' Contrast \n");
856 g_print("\t 'h' Hue \n");
857 g_print("\t 'a' Saturation \n");
858 g_print("\t 'A' Sharpness \n");
859 g_print("\t 'q' Gain \n");
860 g_print("\t 'w' White balance \n");
861 g_print("\t 'W' White balance temperature \n");
862 g_print("\t 't' Color tone \n");
863 g_print("\t 'd' WDR \n");
864 g_print("\t 'e' EV program mode \n");
865 g_print("\t 'R' Display ROI area \n");
866 g_print("\t >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
867 g_print("\t 'z' Strobe (Flash) \n");
868 g_print("\t 'S' Strobe (Flash) state\n");
869 g_print("\t 'G' Strobe (Flash) brightness\n");
870 g_print("\t 'x' Capture mode (Still/Multishot/HDR)\n");
871 g_print("\t 'l' Face detection \n");
872 g_print("\t 'k' Anti-handshake \n");
873 g_print("\t 'K' Video-stabilization \n");
874 g_print("\t 'u' Touch AF area \n");
875 g_print("\t 'n' Set file path to write captured image\n");
876 g_print("\t 'm' Set media bridge\n");
877 g_print("\t 'b' back\n");
878 g_print("\t=======================================\n");
881 g_print("\n\tunknow menu state !!\n");
885 g_print("\tCommand >> ");
889 static void main_menu(gchar buf)
897 case '1': /* Capture */
898 hcamcorder->is_multishot = FALSE;
899 camera_attr_set_image_quality(hcamcorder->camera, 100);
900 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
901 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
903 case '2': /* multishot Capture */
904 g_print("multishot capture");
905 hcamcorder->is_multishot = TRUE;
906 g_print("\n\tinput interval(ms) : ");
907 err = scanf("%d", &interval);
909 g_print("\n\tinput count : ");
910 err = scanf("%d", &count);
912 camera_attr_set_image_quality(hcamcorder->camera, 100);
913 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
914 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
916 camera_start_preview(hcamcorder->camera);
918 case '3': /* Setting */
919 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
921 case '4': /* Change device (CAMERA0 <-> CAMERA1) */
922 camera_set_display_reuse_hint(hcamcorder->camera, true);
924 camera_stop_preview(hcamcorder->camera);
926 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
927 hcamcorder->type = CAMERA_DEVICE_CAMERA1;
929 hcamcorder->type = CAMERA_DEVICE_CAMERA0;
931 camera_change_device(hcamcorder->camera, hcamcorder->type);
933 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
934 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
935 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
936 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
938 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
940 camera_start_preview(hcamcorder->camera);
943 g_print("* Preview Callback\n");
944 g_print("\tUnset[0] / Set[Others] :");
945 err = scanf("%d", &set_cb);
948 g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
949 err = scanf("%d", &g_camera_preview_cb_dump);
951 err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
953 err = camera_unset_preview_cb(hcamcorder->camera);
955 g_print("\tresult[0x%x]\n\n", err);
958 g_print("* Extra Preview Callback\n");
959 g_print("\tUnset[0] / Set[Others] :");
960 err = scanf("%d", &set_cb);
963 g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
964 err = scanf("%d", &g_camera_extra_preview_cb_dump);
966 err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
968 err = camera_unset_extra_preview_cb(hcamcorder->camera);
970 g_print("\tresult[0x%x]\n\n", err);
973 g_print("* Media Packet Preview Callback\n");
974 g_print("\tUnset[0] / Set[Others] :");
975 err = scanf("%d", &set_cb);
978 g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
979 err = scanf("%d", &g_camera_mp_preview_cb_dump);
981 err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
983 err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
985 g_print("\tresult[0x%x]\n\n", err);
988 __release_media_bridge();
990 camera_stop_preview(hcamcorder->camera);
991 camera_destroy(hcamcorder->camera);
992 hcamcorder->camera = NULL;
993 hcamcorder->menu_state = MENU_STATE_INIT;
996 g_print("\t Invalid input \n");
1002 static void setting_menu(gchar buf)
1024 /* Camera setting */
1025 case '0': /* Setting > Preview Resolution setting */
1026 g_print("\t* Select the preview resolution!\n");
1027 resolution_stack resolution_list;
1028 resolution_list.count = 0;
1030 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1031 _resolution_cb, &resolution_list);
1033 g_print("\tCommand >> ");
1035 err = scanf("%d", &idx);
1037 if (resolution_list.count > idx && idx >= 0) {
1038 g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1039 resolution_list.width[idx], resolution_list.height[idx]);
1041 result = camera_set_preview_resolution(hcamcorder->camera,
1042 resolution_list.width[idx], resolution_list.height[idx]);
1044 g_print("\tInvalid command [%d]\n", idx);
1047 resolution_list.count = 0;
1048 if (result == CAMERA_ERROR_NONE)
1049 g_print("\tPASS\n");
1051 g_print("\tFAIL\n");
1053 case '1': /* Setting > Capture Resolution setting */
1054 g_print("\t* Select the capture resolution!\n");
1055 resolution_list.count = 0;
1057 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1058 _resolution_cb, &resolution_list);
1060 g_print("\tCommand > ");
1062 err = scanf("%d", &idx);
1064 if (resolution_list.count > idx && idx >= 0) {
1065 g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1066 resolution_list.width[idx], resolution_list.height[idx]);
1068 result = camera_set_capture_resolution(hcamcorder->camera,
1069 resolution_list.width[idx], resolution_list.height[idx]);
1071 g_print("\tInvalid command [%d]\n", idx);
1074 resolution_list.count = 0;
1075 if (result == CAMERA_ERROR_NONE)
1076 g_print("\tPASS\n");
1078 g_print("\tFAIL\n");
1080 case '2': /* Setting > Digital zoom level */
1081 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1083 g_print("\tDigital Zoom Not supported\n");
1085 g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1086 err = scanf("%d", &idx);
1088 bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1091 case '3': /* Setting > AF mode */
1092 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1093 err = scanf("%d", &idx);
1097 camera_start_focusing(hcamcorder->camera, 0);
1100 camera_cancel_focusing(hcamcorder->camera);
1103 g_print("\tInvalid command [%d]\n", idx);
1107 case '4': /* Setting > AF scan range */
1108 g_print("\t* AF scan range !\n");
1109 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1110 g_print("\tCommand > ");
1111 err = scanf("%d", &idx);
1113 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1115 case '5': /* Setting > Exposure mode */
1116 g_print("* Exposure mode!\n");
1117 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1118 g_print("\n Select Exposure mode \n");
1119 err = scanf("%d", &idx);
1121 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1124 case '6': /* Setting > Exposure value */
1125 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1127 g_print("Not supported !! \n");
1129 g_print("\n Select Exposure mode min%d -max %d\n", min, max);
1130 err = scanf("%d", &idx);
1132 bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1135 case '7': /* Setting > F number */
1136 g_print("Not supported !! \n");
1138 case '8': /* Setting > Display reuse hint */
1140 bool reuse_hint = false;
1142 err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1143 if (err != CAMERA_ERROR_NONE) {
1144 g_print("failed to get display reuse hint 0x%x\n", err);
1148 g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1149 reuse_hint = !reuse_hint;
1150 err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1151 g_print("set display reuse hint result : 0x%x\n", err);
1154 case '9': /* Setting > Manual focus */
1155 g_print("*Manual focus !\n");
1156 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1158 g_print("\n\tManual focus is NOT SUPPORTED\n");
1161 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1162 g_print("\tCurrent focus level (%d)\n", idx);
1163 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1164 err = scanf("%d", &idx);
1166 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1168 if (bret == CAMERA_ERROR_NONE) {
1169 bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1170 g_print("\tfocus level[%d] after set\n", idx);
1172 g_print("\tset focus level failed[0x%x]\n", bret);
1175 case 'i': /* Setting > ISO */
1176 g_print("*ISO !\n");
1177 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1178 err = scanf("%d", &idx);
1180 bret = camera_attr_set_iso(hcamcorder->camera, idx);
1182 case 'r': /* Setting > Rotate camera input when recording */
1183 g_print("*Rotate camera input\n");
1184 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1185 err = scanf("%d", &idx);
1187 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1188 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1189 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1191 case 'f': /* Setting > Flip camera input */
1192 g_print("*Flip camera input\n");
1193 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1194 err = scanf("%d", &idx);
1196 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1197 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1198 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1200 case 'j': /* Setting > Jpeg quality */
1201 g_print("*Jpeg quality !\n");
1202 g_print("\n Select Jpeg quality \n");
1203 err = scanf("%d", &idx);
1205 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1207 case 'p': /* Setting > Picture format */
1208 g_print("* Picture format!\n");
1209 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1210 err = scanf("%d", &idx);
1212 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1213 bret = camera_set_preview_format(hcamcorder->camera, idx);
1214 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1216 case 'E': /* Setting > EXIF orientation */
1217 g_print("* EXIF Orientation\n");
1218 g_print("\t 1. TOP_LEFT\n");
1219 g_print("\t 2. TOP_RIGHT(flipped)\n");
1220 g_print("\t 3. BOTTOM_RIGHT\n");
1221 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1222 g_print("\t 5. LEFT_TOP(flipped)\n");
1223 g_print("\t 6. RIGHT_TOP\n");
1224 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1225 g_print("\t 8. LEFT_BOTTOM\n");
1226 err = scanf("%d", &idx);
1228 if (idx < 1 || idx > 8)
1229 g_print("Wrong INPUT[%d]!! \n", idx);
1231 camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1233 case 'F': /* Setting > Get Facing direction */
1234 g_print("* Get facing direction of camera module\n");
1235 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1236 if (CAMERA_ERROR_NONE == err)
1237 g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1239 g_print("* Error : %d\n", err);
1241 case 's': /* Setting > Set extra preview stream format */
1242 g_print("* Set extra preview stream format\n");
1244 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1245 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1248 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1249 stream_id, pixel_format, width, height, fps);
1250 if (err != CAMERA_ERROR_NONE) {
1251 g_print("* Set Error : 0x%x\n", err);
1255 pixel_format = width = height = fps = -1;
1257 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1258 stream_id, &pixel_format, &width, &height, &fps);
1259 if (err != CAMERA_ERROR_NONE) {
1260 g_print("* Get Error : 0x%x\n", err);
1264 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1265 stream_id, pixel_format, width, height, fps);
1267 case 'B': /* Setting > Set extra preview bitrate */
1268 g_print("* Set extra preview bitrate\n");
1269 g_print("\tstream_id : ");
1270 err = scanf("%d", &stream_id);
1273 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1274 if (err != CAMERA_ERROR_NONE) {
1275 g_print("\tFailed to get bitrate for stream_id[%d]\n", stream_id);
1279 g_print("\tCurrent bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1281 g_print("\tSet bitrate(bps) : ");
1282 err = scanf("%d", &bitrate);
1285 err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
1286 if (err != CAMERA_ERROR_NONE) {
1287 g_print("* Set Error : 0x%x\n", err);
1293 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1294 if (err != CAMERA_ERROR_NONE) {
1295 g_print("* Get Error : 0x%x\n", err);
1299 g_print("\tResult bitrate[%d]bps for stream_id[%d]\n", bitrate, stream_id);
1301 case 'V': /* Setting > Set extra preview GOP interval */
1302 g_print("* Set extra preview GOP interval\n");
1303 g_print("\tstream_id : ");
1304 err = scanf("%d", &stream_id);
1307 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1308 if (err != CAMERA_ERROR_NONE) {
1309 g_print("\tFailed to get GOP interval for stream_id[%d]\n", stream_id);
1313 g_print("\tCurrent GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1315 g_print("\tSet GOP interval(ms) : ");
1316 err = scanf("%d", &interval);
1319 err = camera_attr_set_extra_preview_gop_interval(hcamcorder->camera, stream_id, interval);
1320 if (err != CAMERA_ERROR_NONE) {
1321 g_print("* Set Error : 0x%x\n", err);
1327 err = camera_attr_get_extra_preview_gop_interval(hcamcorder->camera, stream_id, &interval);
1328 if (err != CAMERA_ERROR_NONE) {
1329 g_print("* Get Error : 0x%x\n", err);
1333 g_print("\tResult GOP interval[%d]bps for stream_id[%d]\n", interval, stream_id);
1335 case 'D': /* Setting > Request codec config */
1336 g_print("* Request codec config\n");
1338 err = camera_request_codec_config(hcamcorder->camera);
1339 if (err != CAMERA_ERROR_NONE) {
1340 g_print("\tFailed to request codec config\n");
1344 /* Display / Filter setting */
1345 case 'v': /* Display visible */
1346 g_print("* Display visible setting !\n");
1347 g_print("\n Select Display visible \n");
1348 for (i = 0 ; i < 2 ; i++)
1349 g_print("\t %d. %s\n", i, visible_mode[i]);
1350 err = scanf("%d", &idx);
1352 if (idx == 0 || idx == 1)
1353 bret = camera_set_display_visible(hcamcorder->camera, idx);
1355 g_print("invalid input %d", idx);
1357 case 'o': /* Setting > Display Mode */
1358 g_print("* Display mode!\n");
1359 for (i = 0 ; i < 5 ; i++)
1360 g_print("%d. %s\n", i, display_mode[i]);
1361 err = scanf("%d", &idx);
1363 bret = camera_set_display_mode(hcamcorder->camera, idx);
1365 case 'y': /* Setting > Rotate Display */
1366 g_print("\n Select Rotate mode\n");
1367 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1368 err = scanf("%d", &idx);
1370 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1371 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1372 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1374 case 'Y': /* Setting > Flip Display */
1375 g_print("\n Select Rotate mode\n");
1376 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1377 err = scanf("%d", &idx);
1379 bret = camera_set_display_flip(hcamcorder->camera, idx);
1381 case 'g': /* Setting > Brightness */
1382 g_print("*Brightness !\n");
1383 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1384 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1385 err = scanf("%d", &idx);
1387 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1389 case 'c': /* Setting > Contrast */
1390 g_print("*Contrast !\n");
1391 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1392 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1393 err = scanf("%d", &idx);
1395 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1397 case 'h': /* Setting > Hue */
1398 g_print("*Hue !\n");
1399 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1401 g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1402 err = scanf("%d", &idx);
1404 bret = camera_attr_set_hue(hcamcorder->camera, idx);
1406 g_print("\n Hue is not supported (%d,%d)\n", min, max);
1409 case 'a': /* Setting > Saturation */
1410 g_print("*Saturation !\n");
1411 camera_attr_get_saturation_range(hcamcorder->camera, &min, &max);
1413 camera_attr_get_saturation(hcamcorder->camera, &idx);
1414 g_print("\n Select Saturation min(%d)-max(%d)(current:%d) > ", min, max, idx);
1415 err = scanf("%d", &idx);
1417 bret = camera_attr_set_saturation(hcamcorder->camera, idx);
1419 g_print("\n Saturation is not supported\n");
1422 case 'A': /* Setting > Sharpness */
1423 g_print("*Sharpness !\n");
1424 camera_attr_get_sharpness_range(hcamcorder->camera, &min, &max);
1426 camera_attr_get_sharpness(hcamcorder->camera, &idx);
1427 g_print("\n Select Sharpness min(%d)-max(%d)(current:%d) > ", min, max, idx);
1428 err = scanf("%d", &idx);
1430 bret = camera_attr_set_sharpness(hcamcorder->camera, idx);
1432 g_print("\n Sharpness is not supported\n");
1435 case 'q': /* Setting > Gain */
1436 g_print("*Gain !\n");
1437 camera_attr_get_gain_range(hcamcorder->camera, &min, &max);
1439 camera_attr_get_gain(hcamcorder->camera, &idx);
1440 camera_attr_get_gain_step(hcamcorder->camera, &step);
1441 g_print("\n Select Gain min(%d)-max(%d)(current:%d,step:%d) > ", min, max, idx, step);
1442 err = scanf("%d", &idx);
1444 bret = camera_attr_set_gain(hcamcorder->camera, idx);
1446 g_print("\n Gain is not supported\n");
1449 case 'w': /* Setting > White balance */
1450 g_print("*White balance !\n");
1451 g_print("\n Select White balance \n");
1452 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1453 err = scanf("%d", &idx);
1455 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1457 case 'W': /* Setting > White balance temperature */
1458 g_print("*White balance temperature !\n");
1459 camera_attr_get_whitebalance_temperature_range(hcamcorder->camera, &min, &max);
1461 camera_attr_get_whitebalance_temperature(hcamcorder->camera, &idx);
1462 camera_attr_get_whitebalance_temperature_step(hcamcorder->camera, &step);
1463 g_print("\n Select White balance temperature min(%d)-max(%d)(current:%d,step:%d) > ",
1464 min, max, idx, step);
1465 err = scanf("%d", &idx);
1467 bret = camera_attr_set_whitebalance_temperature(hcamcorder->camera, idx);
1469 g_print("\n White balance temperature is not supported\n");
1472 case 't': /* Setting > Color tone */
1473 g_print("*Color tone !\n");
1474 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1475 g_print("\n Select Color tone \n");
1476 err = scanf("%d", &idx);
1478 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1480 case 'd': /* Setting > WDR */
1481 g_print("*WDR !\n");
1482 g_print("\n Select WDR Mode \n");
1483 for (i = 0 ; i < 2 ; i++)
1484 g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1485 err = scanf("%d", &idx);
1488 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1490 bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1492 case 'e': /* Setting > EV program mode */
1493 g_print("* EV program mode!\n");
1494 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1495 g_print("\n Select EV program mode \n");
1496 err = scanf("%d", &idx);
1498 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1500 case 'R': /* Setting > Display ROI area */
1501 g_print("* Set display roi area. Select x y width height \n");
1502 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1504 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1505 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1506 if (CAMERA_ERROR_NONE != err)
1507 g_print("* Error : %d\n", err);
1509 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1510 if (CAMERA_ERROR_NONE == err)
1511 g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1513 g_print("* Error : %d\n", err);
1517 case 'z': /* Setting > Strobe setting */
1518 g_print("*Strobe Mode\n");
1519 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1520 g_print("\n Select Strobe Mode \n");
1521 err = scanf("%d", &idx);
1523 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1525 case 'S': /* Setting > flash state */
1526 g_print("*flash state\n");
1527 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1528 if (CAMERA_ERROR_NONE == err)
1529 g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1531 g_print("* Error : %d\n", err);
1533 case 'G': /* Setting > flash brightness */
1534 g_print("*Flash brightness !\n");
1535 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1536 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1537 err = scanf("%d", &idx);
1539 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1541 case 'x': /* Setting > Capture mode ,Muitishot? */
1542 g_print("*Select Capture mode!\n");
1543 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1544 err = scanf("%d", &idx);
1549 g_print("stillshot mode selected and capture callback is set!!!!\n");
1550 hcamcorder->is_multishot = FALSE;
1551 camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1554 g_print("HDR Capture mode selected\n");
1555 hcamcorder->is_multishot = FALSE;
1556 g_print("\nSelect HDR capture mode\n");
1557 for (i = 0 ; i < 3 ; i++)
1558 g_print("\t %d. %s\n", i, hdr_mode[i]);
1559 err = scanf("%d", &idx);
1561 if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1562 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1564 g_print("invalid input %d\n", idx);
1567 g_print("Wrong input, select again!!\n");
1571 case 'l': /* Setting > Face detection setting */
1572 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1573 g_print("* Face detect mode !\n");
1574 for (i = 0 ; i < 2 ; i++)
1575 g_print("\t %d. %s \n", i, detection_mode[i]);
1576 err = scanf("%d", &idx);
1579 bret = camera_stop_face_detection(hcamcorder->camera);
1581 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1583 g_print("\n invalid input [%d]\n\n", idx);
1585 g_print("face detection_not supported");
1588 case 'k': /* Setting > Anti-handshake */
1589 g_print("*Anti-handshake !\n");
1590 g_print("\n Select Anti-handshake mode \n");
1591 for (i = 0; i < 2; i++)
1592 g_print("\t %d. %s\n", i, ahs_mode[i]);
1593 err = scanf("%d", &idx);
1595 if (idx == 0 || idx == 1)
1596 bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1598 g_print("invalid input %d\n", idx);
1600 case 'K': /* Setting > Video-stabilization */
1601 g_print("*Video-stabilization !\n");
1602 g_print("\n Select Video-stabilization mode \n");
1603 for (i = 0 ; i < 2 ; i++)
1604 g_print("\t %d. %s\n", i, vs_mode[i]);
1605 err = scanf("%d", &idx);
1607 if (idx < 0 || idx > 1) {
1608 g_print("invalid input %d\n", idx);
1613 g_print("\n Restart preview with NV12 and 720p resolution\n");
1614 err = camera_stop_preview(hcamcorder->camera);
1615 g_print("stop preview result 0x%x\n", err);
1616 camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1617 camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1620 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1623 err = camera_start_preview(hcamcorder->camera);
1624 if (err != CAMERA_ERROR_NONE)
1625 g_print("\n Restart FAILED! 0x%x\n", err);
1628 case 'u': /* Touch AF area */
1629 g_print("* Touch AF area !\n");
1630 g_print("\n Input x,y,width,height \n");
1631 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1633 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1635 g_print("Failed to set touch AF area.(%x)\n", err);
1637 g_print("Succeed to set touch AF area.\n");
1639 case 'n': /* file path */
1640 g_print("* File path !\n");
1641 g_print("\n Input file path to save captured data(string) : ");
1642 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin))
1643 g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1645 g_print("\nset file path failed\n");
1647 case 'm': /* media bridge */
1648 g_print("* Media Bridge !\n");
1649 g_print("\tUnset[0] / Set[Others] :");
1650 err = scanf("%d", &set_bridge);
1653 __release_media_bridge();
1655 err = media_bridge_create(&bridge);
1656 err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1658 __release_media_bridge();
1660 g_print("\tresult[0x%x]\n\n", err);
1662 case 'b': /* back */
1663 hcamcorder->menu_state = MENU_STATE_MAIN;
1666 g_print("\t Invalid input \n");
1670 g_print("\t bret : 0x%x \n", bret);
1674 static void device_state_menu(gchar buf)
1677 camera_device_e device = CAMERA_DEVICE_CAMERA0;
1678 camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1681 case '1': /* Get device state */
1683 g_print("\n\tEnter Camera Index[0~9]: ");
1685 ret = scanf("%d", (int *)&device);
1689 g_print("\n\t!!!read input error!!!\n");
1693 if (device < CAMERA_DEVICE_CAMERA0 ||
1694 device > CAMERA_DEVICE_CAMERA9) {
1695 g_print("\n\tinvalid input:[%d], try again...\n", device);
1699 ret = camera_get_device_state(device, &device_state);
1700 g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1701 device, device_state, ret);
1705 case '2': /* Add device state changed callback */
1706 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1707 NULL, &g_camera_device_state_changed_cb_id);
1708 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1710 case '3': /* Remove device state changed callback */
1711 if (g_camera_device_state_changed_cb_id > 0) {
1712 ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1713 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1714 g_camera_device_state_changed_cb_id = 0;
1716 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1719 case 'b': /* back */
1720 hcamcorder->menu_state = MENU_STATE_INIT;
1723 g_print("\n\tinvalid input[%c]\n", buf);
1728 static void device_manager_menu(gchar buf)
1733 case '1': /* Initialize device manager */
1734 ret = camera_device_manager_initialize(&g_device_manager);
1735 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1736 g_device_manager, ret);
1738 case '2': /* Foreach supported camera device */
1739 ret = camera_device_manager_foreach_supported_device(g_device_manager, _camera_supported_device_cb, NULL);
1740 if (ret != CAMERA_ERROR_NONE) {
1741 g_print("\n\tGet device list failed[0x%x]\n", ret);
1745 case '3': /* Add device connection changed callback */
1746 ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
1747 _camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
1748 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1750 case '4': /* Remove device connection changed callback */
1751 if (g_camera_device_connection_changed_cb_id > 0) {
1752 ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
1753 g_camera_device_connection_changed_cb_id);
1754 g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1755 g_camera_device_connection_changed_cb_id = 0;
1757 g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
1760 case '9': /* Deinitialize device manager */
1761 ret = camera_device_manager_deinitialize(g_device_manager);
1762 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1763 g_device_manager, ret);
1764 g_device_manager = NULL;
1766 case 'b': /* back */
1767 hcamcorder->menu_state = MENU_STATE_INIT;
1770 g_print("\n\tinvalid input[%c]\n", buf);
1777 * This function is to execute command.
1779 * @param channel [in] 1st parameter
1781 * @return This function returns TRUE/FALSE
1785 gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1789 GError *g_error = NULL;
1791 g_print("\n\tENTER\n");
1793 g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1795 g_print("\n\tg_io_channel_read_chars error\n");
1796 g_error_free(g_error);
1803 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1804 switch (hcamcorder->menu_state) {
1805 case MENU_STATE_INIT:
1806 mode_change(buf[0]);
1808 case MENU_STATE_MAIN:
1811 case MENU_STATE_MAIN_SETTING:
1812 setting_menu(buf[0]);
1814 case MENU_STATE_DEVICE_STATE:
1815 device_state_menu(buf[0]);
1817 case MENU_STATE_DEVICE_MANAGER:
1818 device_manager_menu(buf[0]);
1829 g_print("\n\tNo read input\n");
1836 cam_handle_t *init_handle()
1838 hcamcorder = (cam_handle_t *)g_malloc0(sizeof(cam_handle_t));
1840 hcamcorder->is_multishot = FALSE;
1841 hcamcorder->stillshot_count = 0;
1842 hcamcorder->multishot_count = 0;
1843 snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1844 hcamcorder->menu_state = MENU_STATE_INIT;
1850 static void __enable_extra_preview_and_callback(camera_h camera)
1857 int pixel_format = 0;
1860 g_print("\n\t- Format list");
1861 g_print("\n\t0:NV12, 1:NV12T, 2:NV16, 3:NV21, 4:YUYV, 5:UYVY, 6:422P, 7:I420, 8:YV12, 9:RGB565, 10:RGB888");
1862 g_print("\n\t11:RGBA, 12:ARGB, 13:ENCODED(JPEG), 14:INTERLEAVED_JPEG_UYVY, 15:H264, 16:INVZ, 17:MJPEG, 18:VP8, 19:VP9");
1863 g_print("\n\tSet extra preview format[stream_id width height fps format] : ");
1865 err = scanf("%d %d %d %d %d", &stream_id, &width, &height, &fps, &pixel_format);
1868 err = camera_set_extra_preview_stream_format(camera, stream_id, pixel_format, width, height, fps);
1869 if (err != CAMERA_ERROR_NONE) {
1870 g_print("\n\tcamera_set_extra_preview_stream_format failed[0x%x]\n", err);
1874 err = camera_set_extra_preview_cb(camera, _camera_extra_preview_cb, camera);
1875 if (err != CAMERA_ERROR_NONE) {
1876 g_print("\n\tcamera_set_extra_preview_cb failed[0x%x]\n", err);
1880 g_print("\n\t## for MM_CAMCORDER_EXTRA_PREVIEW_MODE_PIPELINE_ELEMENT ##\n");
1881 g_print("\n\tSet device for extra preview[0 ~ 9] : ");
1882 err = scanf("%d", &device);
1885 err = camera_set_extra_preview_device(hcamcorder->camera, 0, device);
1886 g_print("\n\tcamera_set_extra_preview_device(device:%d) 0x%x\n", device, err);
1888 g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1889 err = scanf("%d", &g_camera_extra_preview_cb_dump);
1895 * This function is to change camcorder mode.
1897 * @param buf [in] user input
1899 * @return This function returns TRUE/FALSE
1901 * @see other functions
1903 static gboolean mode_change(gchar buf)
1906 int camera_type = 0;
1907 int enable_extra_preview = 0;
1912 g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1913 err = scanf("%d", &camera_type);
1916 g_print("\t!!!read input error!!!\n");
1920 if (camera_type != 0 && camera_type != 1) {
1921 g_print("\t Invalid camera type(%d)\n", camera_type);
1925 g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1926 err = scanf("%d", (int *)&camera_device);
1929 g_print("\t!!!read input error!!!\n");
1933 if (camera_device < 0 || camera_device > 9) {
1934 g_print("\t Invalid camera device(%d)\n", camera_device);
1938 hcamcorder->type = camera_device;
1943 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1946 hcamcorder->menu_state = MENU_STATE_DEVICE_MANAGER;
1949 g_print("\t Quit Camcorder Testsuite!!\n");
1953 g_print("\t Invalid media type(%c)\n", buf);
1957 g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1959 gettimeofday(&previous_time, NULL);
1962 err = camera_create_network(camera_device, &hcamcorder->camera);
1964 err = camera_create(camera_device, &hcamcorder->camera);
1967 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1971 set_display(hcamcorder);
1973 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1974 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1975 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1976 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1977 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1978 /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1979 /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1980 /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1982 if (camera_is_supported_extra_preview(hcamcorder->camera)) {
1983 g_print("\n\tEnable extra preview callback - NO[0], YES[Others] : ");
1984 err = scanf("%d", (int *)&enable_extra_preview);
1987 if (enable_extra_preview)
1988 __enable_extra_preview_and_callback(hcamcorder->camera);
1991 camera_start_preview(hcamcorder->camera);
1993 gettimeofday(¤t_time, NULL);
1994 timersub(¤t_time, &previous_time, &result_time);
1996 g_print("\n\tCamera Starting Time : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1998 hcamcorder->menu_state = MENU_STATE_MAIN;