From 151c8babe2b0f05aa953aa4f0fd60e6e9a3f8b6c Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Tue, 15 Dec 2020 16:48:07 +0900 Subject: [PATCH] Add new internal APIs for device manager [Version] 0.4.43 [Issue Type] New feature Change-Id: I54e1429496fa325c5fde2315e848f30e267ebb38 Signed-off-by: Jeongmo Yang --- include/camera_internal.h | 86 +++++++++++++++++++- include/camera_private.h | 9 +++ packaging/capi-media-camera.spec | 2 +- src/camera_internal.c | 165 ++++++++++++++++++++++++++++++++++----- 4 files changed, 237 insertions(+), 25 deletions(-) diff --git a/include/camera_internal.h b/include/camera_internal.h index d43dcbd..7049087 100644 --- a/include/camera_internal.h +++ b/include/camera_internal.h @@ -103,9 +103,21 @@ typedef struct _camera_device_list_s { camera_device_s device[CAMERA_DEVICE_MAX]; } camera_device_list_s; +typedef struct camera_device_manager *camera_device_manager_h; + +/** + * @internal + * @brief Called when the camera device list is changed. + * @since_tizen 6.0 + * @param[in] list The device list of the camera + * @param[in] user_data The user data passed from the callback registration function + * @see camera_device_manager_add_device_list_changed_cb() + */ +typedef void (*camera_device_list_changed_cb)(camera_device_list_s *list, void *user_data); + /** + * @internal * @brief Start the evas rendering. - * * @since_tizen 3.0 * @param[in] camera The handle to the camera * @return @c 0 on success, otherwise a negative error value @@ -118,8 +130,8 @@ typedef struct _camera_device_list_s { int camera_start_evas_rendering(camera_h camera); /** + * @internal * @brief Stop the evas rendering. - * * @since_tizen 3.0 * @param[in] camera The handle to the camera * @param[in] keep_screen If @c true keep last frame on display, otherwise @c false @@ -133,6 +145,7 @@ int camera_start_evas_rendering(camera_h camera); int camera_stop_evas_rendering(camera_h camera, bool keep_screen); /** + * @internal * @brief Sets the ecore wayland video display. * @since_tizen 6.0 * @remarks This function must be called in main thread of the application. @@ -157,6 +170,7 @@ int camera_stop_evas_rendering(camera_h camera, bool keep_screen); int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window); /** + * @internal * @brief Creates preview frame from stream data. * @since_tizen 6.0 * @param[in] stream The stream from internal pipeline @@ -169,6 +183,7 @@ 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); /** + * @internal * @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(). @@ -187,9 +202,39 @@ void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd int camera_create_network(camera_device_e device, camera_h *camera); /** + * @internal + * @brief Initialize a camera device manager. + * @since_tizen 6.0 + * @param[out] manager A newly returned handle to the camera device manager + * @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 + * @see camera_device_manager_deinitialize() + */ +int camera_device_manager_initialize(camera_device_manager_h *manager); + +/** + * @internal + * @brief Deinitialize the camera device manager handle. + * @since_tizen 6.0 + * @param[in] manager The handle to the camera device manager + * @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_INVALID_OPERATION Invalid operation + * @see camera_device_manager_initialize() + */ +int camera_device_manager_deinitialize(camera_device_manager_h manager); + +/** + * @internal * @brief Gets a list of available camera devices. * @since_tizen 6.0 - * @param[out] list A list of available camera devices + * @param[in] manager The handle to the camera device manager + * @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 @@ -197,7 +242,40 @@ int camera_create_network(camera_device_e device, camera_h *camera); * @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); +int camera_device_manager_get_device_list(camera_device_manager_h manager, camera_device_list_s *list); + +/** + * @internal + * @brief Registers a callback function to be called when the camera device list changes. + * @since_tizen 6.0 + * @param[in] manager The handle to the camera device manager + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @param[out] cb_id The id of registered callback + * @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_INVALID_OPERATION Invalid operation + * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory + * @post This function will invoke camera_device_list_changed_cb() when the camera device list changes. + * @see camera_device_manager_remove_device_list_changed_cb() + * @see camera_device_list_changed_cb() + */ +int camera_device_manager_add_device_list_changed_cb(camera_device_manager_h manager, camera_device_list_changed_cb callback, void *user_data, int *cb_id); + +/** + * @internal + * @brief Unregisters the callback function. + * @since_tizen 6.0 + * @param[in] manager The handle to the camera device manager + * @param[in] cb_id The id of registered callback + * @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_INVALID_OPERATION Invalid operation + * @see camera_device_manager_add_device_list_changed_cb() + */ +int camera_device_manager_remove_device_list_changed_cb(camera_device_manager_h manager, int cb_id); /** * @} diff --git a/include/camera_private.h b/include/camera_private.h index 30d5a68..e8da26f 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -224,6 +224,15 @@ 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_list_changed_cb)(void *, void *, int *); + int (*remove_device_list_changed_cb)(int); +} camera_device_manager; + int _camera_get_tbm_surface_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 e228fb2..5c53cb8 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.42 +Version: 0.4.43 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera_internal.c b/src/camera_internal.c index 634bb2b..5521042 100644 --- a/src/camera_internal.c +++ b/src/camera_internal.c @@ -32,6 +32,12 @@ #define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so" +typedef struct _cdm_symbol_table { + void **func_ptr; + const char *func_name; +} cdm_symbol_table; + + /* log level */ extern int g_mmcam_log_level; @@ -194,45 +200,164 @@ int camera_create_network(camera_device_e device, camera_h *camera) } -int camera_get_device_list(camera_device_list_s *list) +int camera_device_manager_initialize(camera_device_manager_h *manager) { unsigned int i = 0; int ret = CAMERA_ERROR_NONE; - int (*get_device_list)(camera_device_list_s *list); void *dl_handle = NULL; + 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_list_changed_cb, "cdm_add_device_list_changed_cb"}, + {(void **)&new_manager->remove_device_list_changed_cb, "cdm_remove_device_list_changed_cb"}, + }; - CAM_LOG_INFO("enter"); - - if (!list) { - CAM_LOG_ERROR("NULL parameter"); - return CAMERA_ERROR_INVALID_PARAMETER; + 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()); - return CAMERA_ERROR_NOT_SUPPORTED; + ret = CAMERA_ERROR_NOT_SUPPORTED; + goto _INITIALIZE_FAILED; } - get_device_list = dlsym(dl_handle, "get_device_list"); - if (!get_device_list) { + /* 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)new_manager; + + CAM_LOG_INFO("camera device manager[%p]", new_manager); + + return CAMERA_ERROR_NONE; + +_INITIALIZE_FAILED: + if (dl_handle) dlclose(dl_handle); - CAM_LOG_ERROR("failed to get symbol to get device list"); - return CAMERA_ERROR_NOT_SUPPORTED; + g_free(new_manager); + return ret; +} + + +int camera_device_manager_deinitialize(camera_device_manager_h manager) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)manager; + + if (!m) { + CAM_LOG_ERROR("NULL manager"); + return CAMERA_ERROR_INVALID_PARAMETER; } - ret = get_device_list(list); + ret = m->deinitialize(); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } - 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 { + dlclose(m->dl_handle); + memset(m, 0x0, sizeof(camera_device_manager)); + g_free(m); + + CAM_LOG_INFO("finalized"); + + return ret; +} + + +int camera_device_manager_get_device_list(camera_device_manager_h manager, camera_device_list_s *list) +{ + int ret = CAMERA_ERROR_NONE; + unsigned int i = 0; + camera_device_manager *m = (camera_device_manager *)manager; + + if (!m || !list) { + CAM_LOG_ERROR("NULL parameter[%p,%p]", m, list); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + CAM_LOG_INFO("enter"); + + ret = m->get_device_list(list); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; + } + + 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); + } + + return ret; +} + + +int camera_device_manager_add_device_list_changed_cb(camera_device_manager_h manager, + camera_device_list_changed_cb callback, void *user_data, int *cb_id) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)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_list_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 ret; +} + + +int camera_device_manager_remove_device_list_changed_cb(camera_device_manager_h manager, int cb_id) +{ + int ret = CAMERA_ERROR_NONE; + camera_device_manager *m = (camera_device_manager *)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_list_changed_cb(cb_id); + if (ret != CAMERA_ERROR_NONE) { CAM_LOG_ERROR("failed[0x%x]", ret); + return ret; } - dlclose(dl_handle); + CAM_LOG_INFO("cb_id[%d] removed", cb_id); return ret; } -- 2.7.4