From: Jeongmo Yang Date: Wed, 1 Dec 2021 10:21:10 +0000 (+0900) Subject: Remove thread for preview callback when stop preview X-Git-Tag: submit/tizen/20211203.034808^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F267320%2F5;p=platform%2Fcore%2Fapi%2Fcamera.git Remove thread for preview callback when stop preview - Minor change : Add sub function to release fds from server. : Create thread for preview callback when start preview. : Close fds when release remained messages. [Version] 0.4.67 [Issue Type] Improvement Change-Id: Ic52013a49839e05adaf91bc5132b9964e4d86cbd Signed-off-by: Jeongmo Yang --- diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 4c24127..9a4d5f8 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.66 +Version: 0.4.67 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index 4f0e2b9..2ec2d1f 100644 --- a/src/camera.c +++ b/src/camera.c @@ -54,6 +54,7 @@ static void __camera_media_packet_data_release(camera_media_packet_data *mp_data static gboolean __camera_allocate_preview_buffer(camera_h camera); static void __camera_release_preview_buffer(camera_h camera); +static void __camera_release_tfd(int tfd[MUSE_NUM_FD]); static gboolean __camera_allocate_preview_buffer(camera_h camera) @@ -172,6 +173,25 @@ static void __camera_release_preview_buffer(camera_h camera) } +static void __camera_release_tfd(int tfd[MUSE_NUM_FD]) +{ + int i; + + if (!tfd) { + CAM_LOG_WARNING("NULL tfd"); + return; + } + + for (i = 0 ; i < MUSE_NUM_FD ; i++) { + if (!CAMERA_IS_FD_VALID(tfd[i])) + break; + + close(tfd[i]); + tfd[i] = CAMERA_FD_INIT; + } +} + + void _camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int value) { if (!cb_info || @@ -423,20 +443,12 @@ _PREVIEW_CB_HANDLER_DONE: for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++) __camera_release_imported_bo(&buffer_bo[i]); - for (i = 0 ; i < MUSE_NUM_FD ; i++) { - if (CAMERA_IS_FD_VALID(tfd[i])) { - close(tfd[i]); - tfd[i] = CAMERA_FD_INIT; - } else { - break; - } - } + __camera_release_tfd(tfd); } static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv_msg, int *tfd) { - int i = 0; int tfd_index = 0; int capture_fd_main = 0; int capture_fd_post = 0; @@ -542,15 +554,7 @@ _CAPTURE_CB_HANDLER_DONE: _camera_msg_return_buffer(capture_fd_thumb, cb_info); } - for (i = 0 ; i < MUSE_NUM_FD ; i++) { - if (CAMERA_IS_FD_VALID(tfd[i])) { - CAM_LOG_INFO("close tfd[%d] %d", i, tfd[i]); - close(tfd[i]); - tfd[i] = CAMERA_FD_INIT; - } else { - break; - } - } + __camera_release_tfd(tfd); CAM_LOG_INFO("return buffer done"); } @@ -1692,11 +1696,11 @@ static gpointer __camera_msg_handler_func(gpointer data) while (!g_queue_is_empty(handler_info->queue)) { cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue); if (cam_msg) { - CAM_LOG_INFO("t:%d remove camera message %p", type, cam_msg); - free(cam_msg); - cam_msg = NULL; + CAM_LOG_INFO("t:%d remove message %p", type, cam_msg); + __camera_release_tfd(cam_msg->tfd); + g_free(cam_msg); } else { - CAM_LOG_WARNING("t:%d NULL camera message", type); + CAM_LOG_WARNING("t:%d NULL message", type); } } @@ -1782,7 +1786,7 @@ static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int ev cam_msg->event = event; cam_msg->event_class = event_class; - if (tfd && CAMERA_IS_FD_VALID(tfd[0])) + if (tfd) memcpy(cam_msg->tfd, tfd, sizeof(cam_msg->tfd)); strncpy(cam_msg->recv_msg, msg, sizeof(cam_msg->recv_msg) - 1); @@ -2139,13 +2143,6 @@ static camera_cb_info_s *__camera_client_callback_new(gint sockfd) goto ErrorExit; } - /* message handler thread for preview callback */ - if (!__create_msg_handler_thread(&cb_info->preview_cb_info, - CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", cb_info)) { - CAM_LOG_ERROR("preview_cb_info failed"); - goto ErrorExit; - } - /* message handler thread for capture callback */ if (!__create_msg_handler_thread(&cb_info->capture_cb_info, CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "camera_msg_handler:capture_cb", cb_info)) { @@ -2175,7 +2172,6 @@ static camera_cb_info_s *__camera_client_callback_new(gint sockfd) ErrorExit: if (cb_info) { __destroy_msg_handler_thread(&cb_info->msg_handler_info); - __destroy_msg_handler_thread(&cb_info->preview_cb_info); __destroy_msg_handler_thread(&cb_info->capture_cb_info); for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) @@ -2213,7 +2209,6 @@ static void __camera_client_callback_destroy(camera_cb_info_s *cb_info) /* destroy msg handler threads */ __destroy_msg_handler_thread(&cb_info->msg_handler_info); - __destroy_msg_handler_thread(&cb_info->preview_cb_info); __destroy_msg_handler_thread(&cb_info->capture_cb_info); for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) @@ -2636,23 +2631,35 @@ int camera_start_preview(camera_h camera) return CAMERA_ERROR_INVALID_OPERATION; } - if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) { - if (!__camera_allocate_preview_buffer(camera)) - return CAMERA_ERROR_INVALID_OPERATION; + /* message handler thread for preview callback */ + if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info, + CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", pc->cb_info)) { + CAM_LOG_ERROR("preview_cb_info failed"); + return CAMERA_ERROR_INVALID_OPERATION; + } - _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT); + if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) { + if (__camera_allocate_preview_buffer(camera)) + _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT); + else + ret = CAMERA_ERROR_INVALID_OPERATION; } else { _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT); } - if (ret == CAMERA_ERROR_NONE && pc->cb_info->is_evas_render) { - ret = _camera_start_evas_rendering(camera); - if (ret != CAMERA_ERROR_NONE) { - CAM_LOG_ERROR("stop preview because of error"); - _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0); + if (ret == CAMERA_ERROR_NONE) { + if (pc->cb_info->is_evas_render) { + ret = _camera_start_evas_rendering(camera); + if (ret != CAMERA_ERROR_NONE) { + CAM_LOG_ERROR("stop preview because of error"); + _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0); + } } } + if (ret != CAMERA_ERROR_NONE) + __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info); + CAM_LOG_INFO("ret : 0x%x", ret); return ret; @@ -2694,6 +2701,9 @@ int camera_stop_preview(camera_h camera) if (ret == CAMERA_ERROR_NONE) { if (pc->cb_info->user_buffer_supported) __camera_release_preview_buffer(camera); + + /* release remained message for preview callback */ + __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info); } else if (current_state == CAMERA_STATE_PREVIEW) { CAM_LOG_WARNING("restart evas rendering"); _camera_start_evas_rendering(camera);