From: Jeongmo Yang Date: Thu, 4 Jan 2024 10:36:45 +0000 (+0900) Subject: [ACR-1813] Add new return value for preview callback APIs X-Git-Tag: accepted/tizen/unified/20240123.165901~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91750794315a423aa95befb186b089011b5d9563;p=platform%2Fcore%2Fapi%2Fcamera.git [ACR-1813] Add new return value for preview callback APIs - It could be deadlock or delay of preview frames if preview callback APIs are called in preview callback thread. - This patch adds new return value for error for that case and prevents the such problems. [Version] 0.4.119 [Issue Type] New feature Change-Id: I5048a2323719d5b2f17db4e3e18409610b181f42 Signed-off-by: Jeongmo Yang --- diff --git a/include/camera.h b/include/camera.h index 409908d..b7dbdfc 100644 --- a/include/camera.h +++ b/include/camera.h @@ -1890,6 +1890,8 @@ int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state); /** * @brief Sets a callback function to be invoked for extra preview frames. * @since_tizen 7.0 + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @param[in] callback The callback function to be invoked * @param[in] user_data The user data to be passed to the callback function @@ -1897,6 +1899,7 @@ int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state); * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @pre The camera state must be set to #CAMERA_STATE_CREATED or #CAMERA_STATE_PREVIEW. * @see camera_start_preview() @@ -1908,11 +1911,14 @@ int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callbac /** * @brief Unsets the extra preview callback function. * @since_tizen 7.0 + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @return @c 0 on success, otherwise a negative error value * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @see camera_set_extra_preview_cb() */ @@ -2089,6 +2095,8 @@ bool camera_is_supported_extra_preview(camera_h camera); * it could not be displayed on the device in case of copied buffer.\n * and if camera_is_supported_media_packet_preview_cb() returns false,\n * it's copied buffer case. + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @param[in] callback The callback function to be invoked * @param[in] user_data The user data to be passed to the callback function @@ -2097,6 +2105,7 @@ bool camera_is_supported_extra_preview(camera_h camera); * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @pre Before 4.0 : The camera state must be set to #CAMERA_STATE_CREATED.\n * Since 4.0 : The camera state must be set to #CAMERA_STATE_CREATED or #CAMERA_STATE_PREVIEW. @@ -2109,12 +2118,15 @@ int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *use /** * @brief Unsets the preview callback function. * @since_tizen 2.3 + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @return @c 0 on success, otherwise a negative error value * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @see camera_set_preview_cb() */ @@ -2130,6 +2142,8 @@ int camera_unset_preview_cb(camera_h camera); * The callback function holds the same buffer that will be drawn on the display device.\n * So if you change the media packet in a callback, it will be displayed on the device\n * and the media packet is available until it's destroyed by media_packet_destroy(). + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @param[in] callback The callback function to be invoked * @param[in] user_data The user data to be passed to the callback function @@ -2138,6 +2152,7 @@ int camera_unset_preview_cb(camera_h camera); * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @pre The camera's state should be #CAMERA_STATE_CREATED. * @see camera_start_preview() @@ -2149,12 +2164,15 @@ int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_prev /** * @brief Unsets the media packet callback function. * @since_tizen 2.3 + * @remarks This function should not be called within a invoked @a callback,\n + * otherwise #CAMERA_ERROR_INVALID_OPERATION is returned. (Since 9.0) * @param[in] camera The handle to the camera * @return @c 0 on success, otherwise a negative error value * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported * @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected * @see camera_set_media_packet_preview_cb() */ diff --git a/include/camera_private.h b/include/camera_private.h index ed4ae18..1a81ddf 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -106,6 +106,14 @@ extern "C" { }\ } while (0) +#define CAMERA_CHECK_THREAD_RETURN_VAL(thread_to_check, val, error_msg) \ + do {\ + if (thread_to_check == g_thread_self()) {\ + CAM_LOG_ERROR(error_msg);\ + return (val);\ + }\ + } while (0) + enum { CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 2c01ab2..147ca36 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.118 +Version: 0.4.119 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index ecd9e82..d10029f 100644 --- a/src/camera.c +++ b/src/camera.c @@ -3837,6 +3837,9 @@ int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *use return CAMERA_ERROR_INVALID_PARAMETER; } + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); + CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); @@ -3863,6 +3866,8 @@ int camera_unset_preview_cb(camera_h camera) muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB; CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER); + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); CAM_LOG_INFO("Enter"); @@ -3901,6 +3906,9 @@ int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_prev return CAMERA_ERROR_INVALID_PARAMETER; } + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); + CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); @@ -3933,6 +3941,9 @@ int camera_unset_media_packet_preview_cb(camera_h camera) return CAMERA_ERROR_NOT_SUPPORTED; } + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); + CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); @@ -6606,6 +6617,9 @@ int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callbac return CAMERA_ERROR_INVALID_PARAMETER; } + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); + CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); @@ -6638,6 +6652,9 @@ int camera_unset_extra_preview_cb(camera_h camera) return CAMERA_ERROR_NOT_SUPPORTED; } + CAMERA_CHECK_THREAD_RETURN_VAL(pc->cb_info->preview_cb_info.thread, + CAMERA_ERROR_INVALID_OPERATION, "should not be called within a invoked callback"); + CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);