From c1da0d29e418cfb05fc77399af31cbd3bc232bb9 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 14 Apr 2023 19:20:50 +0900 Subject: [PATCH] Separate device manager related code [Version] 0.4.104 [Issue Type] Clean up Change-Id: I19d3ac5818fadd6d405c08fdb60b9de498700791 Signed-off-by: Jeongmo Yang --- include/camera_device_manager.h | 57 ++++++++++ include/camera_internal.h | 12 -- include/camera_private.h | 10 +- packaging/capi-media-camera.spec | 3 +- src/camera.c | 210 +--------------------------------- src/camera_device_manager.c | 235 +++++++++++++++++++++++++++++++++++++++ src/camera_internal.c | 1 - test/camera_test.c | 1 + 8 files changed, 297 insertions(+), 232 deletions(-) create mode 100644 include/camera_device_manager.h create mode 100644 src/camera_device_manager.c diff --git a/include/camera_device_manager.h b/include/camera_device_manager.h new file mode 100644 index 0000000..6beeec5 --- /dev/null +++ b/include/camera_device_manager.h @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_MULTIMEDIA_CAMERA_DEVICE_MANAGER_H__ +#define __TIZEN_MULTIMEDIA_CAMERA_DEVICE_MANAGER_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CAMERA_DEVICE_MAX ((CAMERA_DEVICE_CAMERA9 + 1) * 2) + + +/** + * @internal + * @brief The structure type of the camera device list. + * @since_tizen 6.0 + */ +typedef struct _camera_device_list_s { + unsigned int count; + camera_device_s device[CAMERA_DEVICE_MAX]; +} camera_device_list_s; + +/** + * @internal + * @brief The structure type for the camera device manager. + * @since_tizen 7.0 + */ +typedef struct _camera_device_manager { + void *dl_handle; + int (*initialize)(void); + int (*deinitialize)(void); + int (*get_device_list)(void *list); + int (*add_device_connection_changed_cb)(void *, void *, int *); + int (*remove_device_connection_changed_cb)(int); +} camera_device_manager; + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_MULTIMEDIA_CAMERA_DEVICE_MANAGER_H__ */ diff --git a/include/camera_internal.h b/include/camera_internal.h index 4de519e..a0b86f8 100644 --- a/include/camera_internal.h +++ b/include/camera_internal.h @@ -37,18 +37,6 @@ extern "C" { * @{ */ -#define CAMERA_DEVICE_MAX ((CAMERA_DEVICE_CAMERA9 + 1) * 2) - -/** - * @internal - * @brief The structure type of the camera device list. - * @since_tizen 6.0 - */ -typedef struct _camera_device_list_s { - unsigned int count; - camera_device_s device[CAMERA_DEVICE_MAX]; -} camera_device_list_s; - /** * @internal * @brief The structure type of the meta timestamp. diff --git a/include/camera_private.h b/include/camera_private.h index 343c2b0..18b16b8 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -18,6 +18,7 @@ #define __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__ #include +#include #include #include #include @@ -267,15 +268,6 @@ typedef struct _camera_cb_info { void *user_data; } camera_cb_info; -typedef struct _camera_device_manager { - void *dl_handle; - int (*initialize)(void); - int (*deinitialize)(void); - int (*get_device_list)(void *list); - int (*add_device_connection_changed_cb)(void *, void *, int *); - int (*remove_device_connection_changed_cb)(int); -} camera_device_manager; - int _camera_get_tbm_format(int in_format, uint32_t *out_format); int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype); diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 0e65914..990a825 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.103 +Version: 0.4.104 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -109,6 +109,7 @@ find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %files devel %{_includedir}/media/camera.h +%{_includedir}/media/camera_device_manager.h %{_includedir}/media/camera_internal.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-media-camera.so diff --git a/src/camera.c b/src/camera.c index 372f15d..0384007 100644 --- a/src/camera.c +++ b/src/camera.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -34,21 +33,7 @@ #endif #define LOG_TAG "TIZEN_N_CAMERA" #define MODULE_NAME "camera" -#define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so" -#define CAMERA_CHECK_DEVICE_MANAGER \ - do {\ - if (access(LIB_CAMERA_DEVICE_MANAGER, F_OK) != 0) {\ - CAM_LOG_ERROR("no camera device maanger[errno:%d]", errno);\ - return CAMERA_ERROR_NOT_SUPPORTED;\ - }\ - } while (0) - - -/* for camera device manager */ -typedef struct _cdm_symbol_table { - void **func_ptr; - const char *func_name; -} cdm_symbol_table; + /* for device changed callback */ static GMutex g_cam_dev_state_changed_cb_lock; @@ -6975,198 +6960,6 @@ int camera_create_network(camera_device_e device, camera_h *camera) } -int camera_device_manager_initialize(camera_device_manager_h *manager) -{ - unsigned int i = 0; - int ret = CAMERA_ERROR_NONE; - void *dl_handle = NULL; - g_autofree camera_device_manager *new_manager = g_new0(camera_device_manager, 1); - cdm_symbol_table sym_table[] = { - {(void **)&new_manager->initialize, "cdm_initialize"}, - {(void **)&new_manager->deinitialize, "cdm_deinitialize"}, - {(void **)&new_manager->get_device_list, "cdm_get_device_list"}, - {(void **)&new_manager->add_device_connection_changed_cb, "cdm_add_device_connection_changed_cb"}, - {(void **)&new_manager->remove_device_connection_changed_cb, "cdm_remove_device_connection_changed_cb"}, - }; - - CAMERA_CHECK_DEVICE_MANAGER; - - if (!manager) { - CAM_LOG_ERROR("NULL manager"); - ret = CAMERA_ERROR_INVALID_PARAMETER; - goto _INITIALIZE_FAILED; - } - - dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW); - if (!dl_handle) { - CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror()); - ret = CAMERA_ERROR_INVALID_OPERATION; - goto _INITIALIZE_FAILED; - } - - /* get symbols */ - for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) { - *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name); - if (*sym_table[i].func_ptr == NULL) { - CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name); - ret = CAMERA_ERROR_INVALID_OPERATION; - goto _INITIALIZE_FAILED; - } - } - - ret = new_manager->initialize(); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("failed[0x%x]", ret); - goto _INITIALIZE_FAILED; - } - - new_manager->dl_handle = dl_handle; - *manager = (camera_device_manager_h)g_steal_pointer(&new_manager); - - CAM_LOG_INFO("camera device manager[%p](dl handle[%p]) initialized", - *manager, dl_handle); - - return CAMERA_ERROR_NONE; - -_INITIALIZE_FAILED: - if (dl_handle) - dlclose(dl_handle); - - return ret; -} - - -//LCOV_EXCL_START -int camera_device_manager_deinitialize(camera_device_manager_h manager) -{ - int ret = CAMERA_ERROR_NONE; - camera_device_manager *m = (camera_device_manager *)manager; - - CAMERA_CHECK_DEVICE_MANAGER; - - if (!m) { - CAM_LOG_ERROR("NULL manager"); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - CAM_LOG_INFO("deinitialize camera device manager[%p]", m); - - ret = m->deinitialize(); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("failed[0x%x]", ret); - return ret; - } - - CAM_LOG_INFO("close dl handle[%p]", m->dl_handle); - - dlclose(m->dl_handle); - - memset(m, 0x0, sizeof(camera_device_manager)); - g_free(m); - - return CAMERA_ERROR_NONE; -} - - -int camera_device_manager_foreach_supported_device(camera_device_manager_h manager, camera_supported_device_cb callback, void *user_data) -{ - int ret = CAMERA_ERROR_NONE; - unsigned int i = 0; - camera_device_list_s device_list; - camera_device_s *device = NULL; - camera_device_manager *m = (camera_device_manager *)manager; - - CAMERA_CHECK_DEVICE_MANAGER; - - if (!m || !callback) { - CAM_LOG_ERROR("NULL parameter[%p,%p]", m, callback); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - CAM_LOG_INFO("enter"); - - memset(&device_list, 0x0, sizeof(camera_device_list_s)); - - ret = m->get_device_list(&device_list); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("failed[0x%x]", ret); - return ret; - } - - CAM_LOG_INFO("device count[%d]", device_list.count); - - for (i = 0 ; i < device_list.count ; i++) { - device = &device_list.device[i]; - - CAM_LOG_INFO(" [%d] : type[%d], index[%d], name[%s], id[%s], ex-stream[%d]", - i, device->type, device->index, - device->name, device->id, device->extra_stream_num); - - if (!callback(device, user_data)) { - CAM_LOG_WARNING("callback is stopped[called:%u,total:%u]", - i + 1, device_list.count); - break; - } - } - - return CAMERA_ERROR_NONE; -} - - -int camera_device_manager_add_device_connection_changed_cb(camera_device_manager_h manager, - camera_device_connection_changed_cb callback, void *user_data, int *cb_id) -{ - int ret = CAMERA_ERROR_NONE; - camera_device_manager *m = (camera_device_manager *)manager; - - CAMERA_CHECK_DEVICE_MANAGER; - - if (!m || !callback || !cb_id) { - CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - CAM_LOG_INFO("enter"); - - ret = m->add_device_connection_changed_cb(callback, user_data, cb_id); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("failed[0x%x]", ret); - return ret; - } - - CAM_LOG_INFO("cb_id[%d] added", *cb_id); - - return CAMERA_ERROR_NONE; -} - - -int camera_device_manager_remove_device_connection_changed_cb(camera_device_manager_h manager, int cb_id) -{ - int ret = CAMERA_ERROR_NONE; - camera_device_manager *m = (camera_device_manager *)manager; - - CAMERA_CHECK_DEVICE_MANAGER; - - if (!m) { - CAM_LOG_ERROR("NULL manager"); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - CAM_LOG_INFO("enter - cb_id[%d]", cb_id); - - ret = m->remove_device_connection_changed_cb(cb_id); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("failed[0x%x]", ret); - return ret; - } - - CAM_LOG_INFO("cb_id[%d] removed", cb_id); - - return CAMERA_ERROR_NONE; -} -//LCOV_EXCL_STOP - - int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data) { int ret = CAMERA_ERROR_NONE; @@ -7423,4 +7216,3 @@ int _camera_get_log_level(void) { return g_camera_log_level; } - diff --git a/src/camera_device_manager.c b/src/camera_device_manager.c new file mode 100644 index 0000000..3cabc7c --- /dev/null +++ b/src/camera_device_manager.c @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#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" +#define CAMERA_CHECK_DEVICE_MANAGER \ + do {\ + if (access(LIB_CAMERA_DEVICE_MANAGER, F_OK) != 0) {\ + CAM_LOG_ERROR("no camera device manager[errno:%d]", errno);\ + return CAMERA_ERROR_NOT_SUPPORTED;\ + }\ + } while (0) + + +/* for camera device manager */ +typedef struct _cdm_symbol_table { + void **func_ptr; + const char *func_name; +} cdm_symbol_table; + + +int camera_device_manager_initialize(camera_device_manager_h *manager) +{ + unsigned int i = 0; + int ret = CAMERA_ERROR_NONE; + void *dl_handle = NULL; + g_autofree camera_device_manager *new_manager = g_new0(camera_device_manager, 1); + cdm_symbol_table sym_table[] = { + {(void **)&new_manager->initialize, "cdm_initialize"}, + {(void **)&new_manager->deinitialize, "cdm_deinitialize"}, + {(void **)&new_manager->get_device_list, "cdm_get_device_list"}, + {(void **)&new_manager->add_device_connection_changed_cb, "cdm_add_device_connection_changed_cb"}, + {(void **)&new_manager->remove_device_connection_changed_cb, "cdm_remove_device_connection_changed_cb"}, + }; + + CAMERA_CHECK_DEVICE_MANAGER; + + if (!manager) { + CAM_LOG_ERROR("NULL manager"); + ret = CAMERA_ERROR_INVALID_PARAMETER; + goto _INITIALIZE_FAILED; + } + + dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW); + if (!dl_handle) { + CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror()); + ret = CAMERA_ERROR_INVALID_OPERATION; + goto _INITIALIZE_FAILED; + } + + /* get symbols */ + for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) { + *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name); + if (*sym_table[i].func_ptr == NULL) { + CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name); + ret = CAMERA_ERROR_INVALID_OPERATION; + goto _INITIALIZE_FAILED; + } + } + + ret = new_manager->initialize(); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + goto _INITIALIZE_FAILED; + } + + new_manager->dl_handle = dl_handle; + *manager = (camera_device_manager_h)g_steal_pointer(&new_manager); + + CAM_LOG_INFO("camera device manager[%p](dl handle[%p]) initialized", + *manager, dl_handle); + + return CAMERA_ERROR_NONE; + +_INITIALIZE_FAILED: + if (dl_handle) + dlclose(dl_handle); + + return ret; +} + + +//LCOV_EXCL_START +int camera_device_manager_deinitialize(camera_device_manager_h manager) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)manager; + + CAMERA_CHECK_DEVICE_MANAGER; + + if (!m) { + CAM_LOG_ERROR("NULL manager"); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + CAM_LOG_INFO("deinitialize camera device manager[%p]", m); + + ret = m->deinitialize(); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } + + CAM_LOG_INFO("close dl handle[%p]", m->dl_handle); + + dlclose(m->dl_handle); + + memset(m, 0x0, sizeof(camera_device_manager)); + g_free(m); + + return CAMERA_ERROR_NONE; +} + + +int camera_device_manager_foreach_supported_device(camera_device_manager_h manager, camera_supported_device_cb callback, void *user_data) +{ + int ret = CAMERA_ERROR_NONE; + unsigned int i = 0; + camera_device_list_s device_list; + camera_device_s *device = NULL; + camera_device_manager *m = (camera_device_manager *)manager; + + CAMERA_CHECK_DEVICE_MANAGER; + + if (!m || !callback) { + CAM_LOG_ERROR("NULL parameter[%p,%p]", m, callback); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + CAM_LOG_INFO("enter"); + + memset(&device_list, 0x0, sizeof(camera_device_list_s)); + + ret = m->get_device_list(&device_list); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } + + CAM_LOG_INFO("device count[%d]", device_list.count); + + for (i = 0 ; i < device_list.count ; i++) { + device = &device_list.device[i]; + + CAM_LOG_INFO(" [%d] : type[%d], index[%d], name[%s], id[%s], ex-stream[%d]", + i, device->type, device->index, + device->name, device->id, device->extra_stream_num); + + if (!callback(device, user_data)) { + CAM_LOG_WARNING("callback is stopped[called:%u,total:%u]", + i + 1, device_list.count); + break; + } + } + + return CAMERA_ERROR_NONE; +} + + +int camera_device_manager_add_device_connection_changed_cb(camera_device_manager_h manager, + camera_device_connection_changed_cb callback, void *user_data, int *cb_id) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)manager; + + CAMERA_CHECK_DEVICE_MANAGER; + + if (!m || !callback || !cb_id) { + CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + CAM_LOG_INFO("enter"); + + ret = m->add_device_connection_changed_cb(callback, user_data, cb_id); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } + + CAM_LOG_INFO("cb_id[%d] added", *cb_id); + + return CAMERA_ERROR_NONE; +} + + +int camera_device_manager_remove_device_connection_changed_cb(camera_device_manager_h manager, int cb_id) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)manager; + + CAMERA_CHECK_DEVICE_MANAGER; + + if (!m) { + CAM_LOG_ERROR("NULL manager"); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + CAM_LOG_INFO("enter - cb_id[%d]", cb_id); + + ret = m->remove_device_connection_changed_cb(cb_id); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } + + CAM_LOG_INFO("cb_id[%d] removed", cb_id); + + return CAMERA_ERROR_NONE; +} +//LCOV_EXCL_STOP diff --git a/src/camera_internal.c b/src/camera_internal.c index b5f2082..c994e4d 100644 --- a/src/camera_internal.c +++ b/src/camera_internal.c @@ -22,7 +22,6 @@ #include #include #include -#include #ifdef LOG_TAG #undef LOG_TAG diff --git a/test/camera_test.c b/test/camera_test.c index c824ad1..043a67b 100644 --- a/test/camera_test.c +++ b/test/camera_test.c @@ -22,6 +22,7 @@ /*======================================================================================= | INCLUDE FILES | =======================================================================================*/ +#include #include "camera_test.h" /*----------------------------------------------------------------------- -- 2.7.4