Separate device manager related code 15/291415/4
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 14 Apr 2023 10:20:50 +0000 (19:20 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 19 Apr 2023 03:05:09 +0000 (12:05 +0900)
[Version] 0.4.104
[Issue Type] Clean up

Change-Id: I19d3ac5818fadd6d405c08fdb60b9de498700791
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/camera_device_manager.h [new file with mode: 0644]
include/camera_internal.h
include/camera_private.h
packaging/capi-media-camera.spec
src/camera.c
src/camera_device_manager.c [new file with mode: 0644]
src/camera_internal.c
test/camera_test.c

diff --git a/include/camera_device_manager.h b/include/camera_device_manager.h
new file mode 100644 (file)
index 0000000..6beeec5
--- /dev/null
@@ -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 <camera_internal.h>
+
+#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__ */
index 4de519e..a0b86f8 100644 (file)
@@ -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.
index 343c2b0..18b16b8 100644 (file)
@@ -18,6 +18,7 @@
 #define __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__
 
 #include <glib.h>
+#include <dlog.h>
 #include <camera_internal.h>
 #include <media_bridge_internal.h>
 #include <muse_core.h>
@@ -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);
index 0e65914..990a825 100644 (file)
@@ -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
index 372f15d..0384007 100644 (file)
@@ -25,7 +25,6 @@
 #include <muse_camera_msg.h>
 #include <camera_private.h>
 #include <muse_client.h>
-#include <dlog.h>
 #include <gio/gio.h>
 #include <dlfcn.h>
 
 #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 (file)
index 0000000..3cabc7c
--- /dev/null
@@ -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 <glib.h>
+#include <string.h>
+#include <unistd.h>
+#include <camera_private.h>
+#include <camera_device_manager.h>
+#include <dlfcn.h>
+
+#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
index b5f2082..c994e4d 100644 (file)
@@ -22,7 +22,6 @@
 #include <mm_types.h>
 #include <camera_internal.h>
 #include <camera_private.h>
-#include <dlog.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
index c824ad1..043a67b 100644 (file)
@@ -22,6 +22,7 @@
 /*=======================================================================================
 |  INCLUDE FILES                                                                        |
 =======================================================================================*/
+#include <stdint.h>
 #include "camera_test.h"
 
 /*-----------------------------------------------------------------------