From 78f4da3c13c72076995bcf910462eab1a3023da6 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 4 Nov 2020 12:18:17 +0900 Subject: [PATCH] Add new internal APIs - int camera_create_network(camera_device_e device, camera_h *camera); : API to create network camera handle - int camera_get_device_list(camera_device_list_s *list); : API to get device list [Version] 0.4.42 [Issue Type] New feature Change-Id: I4a9413a75100421b82b71a4e2fd4dfffea33beab Signed-off-by: Jeongmo Yang --- include/camera_internal.h | 53 ++++++++++++++++++++++++++++++++++++ include/camera_private.h | 1 + packaging/capi-media-camera.spec | 3 ++- src/camera.c | 11 ++++++-- src/camera_internal.c | 58 ++++++++++++++++++++++++++++++++++++++-- test/camera_test.c | 54 +++++++++++++++++++++++-------------- 6 files changed, 155 insertions(+), 25 deletions(-) diff --git a/include/camera_internal.h b/include/camera_internal.h index a9ac503..d43dcbd 100644 --- a/include/camera_internal.h +++ b/include/camera_internal.h @@ -41,6 +41,9 @@ extern "C" { #endif /* BUFFER_MAX_PLANE_NUM */ #define BUFFER_MAX_PLANE_NUM 4 +#define CAMERA_DEVICE_MAX ((CAMERA_DEVICE_CAMERA9 + 1) * 2) +#define DEVICE_NAME_MAX_LENGTH 64 +#define DEVICE_ID_MAX_LENGTH 64 typedef struct _camera_stream_data_s { union { @@ -81,6 +84,25 @@ typedef struct _camera_stream_data_s { int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */ } camera_stream_data_s; + +typedef enum { + CAMERA_DEVICE_TYPE_BUILTIN = 0, /**< Built-in camera */ + CAMERA_DEVICE_TYPE_USB, /**< USB connected camera */ + CAMERA_DEVICE_TYPE_NETWORK /**< Network camera */ +} camera_device_type_e; + +typedef struct _camera_device_s { + camera_device_type_e type; + camera_device_e index; + char name[DEVICE_NAME_MAX_LENGTH]; + char id[DEVICE_ID_MAX_LENGTH]; +} camera_device_s; + +typedef struct _camera_device_list_s { + unsigned int count; + camera_device_s device[CAMERA_DEVICE_MAX]; +} camera_device_list_s; + /** * @brief Start the evas rendering. * @@ -147,6 +169,37 @@ void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame); /** + * @brief Creates a new camera handle for controlling a network camera. + * @since_tizen 6.0 + * @remarks A @a camera must be released using camera_destroy(). + * @param[in] device The network camera to access + * @param[out] camera A newly returned handle to the camera + * @return @c 0 on success, otherwise a negative error value + * @retval #CAMERA_ERROR_NONE Successful + * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation + * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported + * @post If it succeeds, the camera state will be #CAMERA_STATE_CREATED. + * + * @see camera_destroy() + */ +int camera_create_network(camera_device_e device, camera_h *camera); + +/** + * @brief Gets a list of available camera devices. + * @since_tizen 6.0 + * @param[out] list A list of available camera devices + * @return @c 0 on success, otherwise a negative error value + * @retval #CAMERA_ERROR_NONE Successful + * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation + * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported + */ +int camera_get_device_list(camera_device_list_s *list); + +/** * @} */ #ifdef __cplusplus diff --git a/include/camera_private.h b/include/camera_private.h index 7a171de..30d5a68 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -232,6 +232,7 @@ int _camera_start_evas_rendering(camera_h camera); int _camera_stop_evas_rendering(camera_h camera, bool keep_screen); int _camera_independent_request(int api, int device_type, const char *key, int *value); int _camera_set_display(camera_h camera, mm_display_type_e type, void *display); +int _camera_create_private(camera_device_e device, bool is_network, camera_h *camera); typedef bool (*camera_supported_cb_param1)(int param, void *user_data); typedef bool (*camera_supported_cb_param2)(int param1, int param2, void *user_data); diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 767458e..e228fb2 100644 --- a/packaging/capi-media-camera.spec +++ b/packaging/capi-media-camera.spec @@ -1,6 +1,6 @@ Name: capi-media-camera Summary: A Camera API -Version: 0.4.41 +Version: 0.4.42 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -67,6 +67,7 @@ export CFLAGS+=" -DTIZEN_DEBUG_ENABLE" export CFLAGS+=" -fprofile-arcs -ftest-coverage" export LDFLAGS+=" -lgcov" %endif +export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\"" MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} diff --git a/src/camera.c b/src/camera.c index af3b409..e260a2b 100644 --- a/src/camera.c +++ b/src/camera.c @@ -2355,7 +2355,7 @@ _REQUEST_EXIT: } -int camera_create(camera_device_e device, camera_h *camera) +int _camera_create_private(camera_device_e device, bool is_network, camera_h *camera) { int sock_fd = -1; char *send_msg = NULL; @@ -2373,7 +2373,7 @@ int camera_create(camera_device_e device, camera_h *camera) return CAMERA_ERROR_INVALID_PARAMETER; } - CAM_LOG_INFO("device %d", device); + CAM_LOG_INFO("device %d, is_network %d", device, is_network); sock_fd = muse_client_new(); if (sock_fd < 0) { @@ -2391,6 +2391,7 @@ int camera_create(camera_device_e device, camera_h *camera) send_msg = muse_core_msg_new(api, MUSE_TYPE_INT, "module", module_index, MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type, + MUSE_TYPE_INT, "is_network", (int)is_network, 0); if (!send_msg) { @@ -2514,6 +2515,12 @@ ErrorExit: } +int camera_create(camera_device_e device, camera_h *camera) +{ + return _camera_create_private(device, false, camera); +} + + int camera_change_device(camera_h camera, camera_device_e device) { int i = 0; diff --git a/src/camera_internal.c b/src/camera_internal.c index 16d4d20..634bb2b 100644 --- a/src/camera_internal.c +++ b/src/camera_internal.c @@ -23,12 +23,15 @@ #include #include #include +#include #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_CAMERA" +#define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so" + /* log level */ extern int g_mmcam_log_level; @@ -38,17 +41,20 @@ int camera_start_evas_rendering(camera_h camera) return _camera_start_evas_rendering(camera); } + int camera_stop_evas_rendering(camera_h camera, bool keep_screen) { return _camera_stop_evas_rendering(camera, keep_screen); } + int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window) { return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window); } //LCOV_EXCL_STOP + void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd, tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame) { @@ -178,7 +184,55 @@ void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd } CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]", - frame->format, frame->width, frame->height, total_size, frame->num_of_planes); + frame->format, frame->width, frame->height, total_size, frame->num_of_planes); +} + + +int camera_create_network(camera_device_e device, camera_h *camera) +{ + return _camera_create_private(device, true, camera); +} + + +int camera_get_device_list(camera_device_list_s *list) +{ + unsigned int i = 0; + int ret = CAMERA_ERROR_NONE; + int (*get_device_list)(camera_device_list_s *list); + void *dl_handle = NULL; + + CAM_LOG_INFO("enter"); + + if (!list) { + CAM_LOG_ERROR("NULL parameter"); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW); + if (!dl_handle) { + CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror()); + return CAMERA_ERROR_NOT_SUPPORTED; + } + + get_device_list = dlsym(dl_handle, "get_device_list"); + if (!get_device_list) { + dlclose(dl_handle); + CAM_LOG_ERROR("failed to get symbol to get device list"); + return CAMERA_ERROR_NOT_SUPPORTED; + } + + ret = get_device_list(list); + + if (ret == CAMERA_ERROR_NONE) { + CAM_LOG_INFO("device count[%d]", list->count); + for (i = 0 ; i < list->count ; i++) + CAM_LOG_INFO(" [%d] : type[%d], device index[%d], name[%s]", + i, list->device[i].type, list->device[i].index, list->device[i].name); + } else { + CAM_LOG_ERROR("failed[0x%x]", ret); + } + + dlclose(dl_handle); - return; + return ret; } diff --git a/test/camera_test.c b/test/camera_test.c index 0d868bd..905485e 100644 --- a/test/camera_test.c +++ b/test/camera_test.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -61,7 +61,7 @@ struct appcore_ops ops = { appdata ad; GIOChannel *stdin_channel; -camera_device_e cam_info; +camera_device_e camera_device; static GTimer *timer; static int g_camera_device_changed_cb_id; @@ -715,7 +715,7 @@ static void print_menu() break; case MENU_STATE_MAIN: g_print("\n\t=======================================\n"); - g_print("\t Video Capture (CAMERA%d)\n", cam_info); + g_print("\t Video Capture (CAMERA%d)\n", camera_device); g_print("\t=======================================\n"); g_print("\t '1' Stillshot test\n"); g_print("\t '2' Multishot test\n"); @@ -1195,7 +1195,7 @@ static void setting_menu(gchar buf) break; case 'S': /* Setting > flash state */ g_print("*flash state\n"); - err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx); + err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx); if (CAMERA_ERROR_NONE == err) g_print("Current flash state = %s\n", idx ? "ON" : "OFF"); else @@ -1401,29 +1401,41 @@ static gboolean init_handle() static gboolean mode_change(gchar buf) { int err = 0; - camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL; - char camera_type = '\0'; - char display_type = '\0'; + int camera_type = 0; + int display_type = 0; bool check = FALSE; + camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL; switch (buf) { case '1': while (1) { - g_print("\n\tEnter the Camera Type[0 ~ 9] : "); + g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : "); + err = scanf("%d", &camera_type); + flush_stdin(); + if (err == EOF) { + g_print("\t!!!read input error!!!\n"); + continue; + } - err = scanf("%c", &camera_type); + if (camera_type != 0 && camera_type != 1) { + g_print("\t Invalid camera type(%d)\n", camera_type); + continue; + } + + g_print("\n\tEnter the Camera Device[0 ~ 9] : "); + err = scanf("%d", (int *)&camera_device); flush_stdin(); if (err == EOF) { g_print("\t!!!read input error!!!\n"); continue; } - if (camera_type < '0' || camera_type > '9') { - g_print("\t Invalid camera type(%c)\n", camera_type); + if (camera_device < 0 || camera_device > 9) { + g_print("\t Invalid camera device(%d)\n", camera_device); continue; } - hcamcorder->type = cam_info = camera_type - '0'; + hcamcorder->type = camera_device; break; } @@ -1455,13 +1467,16 @@ static gboolean mode_change(gchar buf) return FALSE; } - g_print("\n[camcorder_create - type %d]\n", cam_info); + g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device); gettimeofday(&previous_time, NULL); g_timer_reset(timer); - err = camera_create(cam_info, &hcamcorder->camera); + if (camera_type) + err = camera_create_network(camera_device, &hcamcorder->camera); + else + err = camera_create(camera_device, &hcamcorder->camera); g_print("[camera_create() : %12.6lfs]\n", g_timer_elapsed(timer, NULL)); @@ -1472,8 +1487,7 @@ static gboolean mode_change(gchar buf) while (!check) { g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : "); - - err = scanf("%c", &display_type); + err = scanf("%d", &display_type); flush_stdin(); if (err == EOF) { g_print("\t!!!read input error!!!\n"); @@ -1481,20 +1495,20 @@ static gboolean mode_change(gchar buf) } switch (display_type) { - case '1': + case 1: camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win)); check = TRUE; break; - case '2': + case 2: camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo)); check = TRUE; break; - case '3': + case 3: camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL); check = TRUE; break; default: - g_print("\t Invalid display type(%c)\n", display_type); + g_print("\t Invalid display type(%d)\n", display_type); break; } } -- 2.7.4