From: Sangchul Lee Date: Wed, 28 Dec 2022 05:26:20 +0000 (+0900) Subject: webrtc_sink_snapshot: Create queue before creating convert thread X-Git-Tag: accepted/tizen/7.0/unified/20221229.170958^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c5a06f45652e407947b51f529a756144cba6bf4;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_sink_snapshot: Create queue before creating convert thread Sometimes the new thread tries to access queue not created yet which causes a crash. It is fixed to create queue first and then create thread as well as check if the result of pop operation is NULL. [Version] 0.3.275 [Issue Type] Crash Change-Id: Icefd4d6d9b38141384fbc70b3a7097a6f674fd4d Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 7c916632..ed2e87cd 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.3.274 +Version: 0.3.275 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_sink_snapshot.c b/src/webrtc_sink_snapshot.c index d6e1edea..31d87ebf 100644 --- a/src/webrtc_sink_snapshot.c +++ b/src/webrtc_sink_snapshot.c @@ -471,7 +471,10 @@ static gpointer __convert_thread(gpointer data) queue_data_s *qd; LOG_DEBUG("wait for data..."); - qd = g_async_queue_pop(webrtc->snapshot.queue); + if (!(qd = g_async_queue_pop(webrtc->snapshot.queue))) { + LOG_ERROR("qd is NULL"); + break; + } LOG_INFO("process qd[%p, vbuffer:%p, target_format:%s, exit:%d]", qd, qd->vbuffer, __get_format_str((webrtc_snapshot_format_e)qd->target_format), qd->exit); if (qd->exit) { @@ -517,14 +520,18 @@ static gpointer __convert_thread(gpointer data) int _init_convert_thread(webrtc_s *webrtc) { RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(webrtc->snapshot.queue != NULL, WEBRTC_ERROR_INVALID_OPERATION, "snapshot.queue is not NULL"); + RET_VAL_IF(webrtc->snapshot.thread != NULL, WEBRTC_ERROR_INVALID_OPERATION, "snapshot.thread is not NULL"); + + webrtc->snapshot.queue = g_async_queue_new_full(__release_queue_data); if (!(webrtc->snapshot.thread = g_thread_try_new("convert_thread", __convert_thread, (gpointer)webrtc, NULL))) { LOG_ERROR("failed to g_thread_try_new()"); + g_async_queue_unref(webrtc->snapshot.queue); + webrtc->snapshot.queue = NULL; return WEBRTC_ERROR_INVALID_OPERATION; } - webrtc->snapshot.queue = g_async_queue_new_full(__release_queue_data); - return WEBRTC_ERROR_NONE; } @@ -533,6 +540,8 @@ void _deinit_convert_thread(webrtc_s *webrtc) queue_data_s *qd; RET_IF(webrtc == NULL, "webrtc is NULL"); + RET_IF(webrtc->snapshot.queue == NULL, "snapshot.queue is NULL"); + RET_IF(webrtc->snapshot.thread == NULL, "snapshot.thread is NULL"); qd = g_new0(queue_data_s, 1); qd->exit = true; @@ -543,6 +552,9 @@ void _deinit_convert_thread(webrtc_s *webrtc) LOG_DEBUG("convert thread exits"); g_async_queue_unref(webrtc->snapshot.queue); + + webrtc->snapshot.queue = NULL; + webrtc->snapshot.thread = NULL; } int _capture_video_frame(webrtc_gst_slot_s *sink)