webrtc_sink_snapshot: Create queue before creating convert thread 16/286116/1 accepted/tizen/7.0/unified/20221229.170958
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 28 Dec 2022 05:26:20 +0000 (14:26 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 28 Dec 2022 07:43:45 +0000 (07:43 +0000)
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 <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_sink_snapshot.c

index 7c916632d9a5852271255baed310c933811afb0c..ed2e87cdd00493e81ac5ebdebad9cf60c02900e4 100644 (file)
@@ -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
index d6e1edea145290c56c0b1e2d04948ab1d2d8db03..31d87ebf205dc2fd8dcbd741795d9ba697648a32 100644 (file)
@@ -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)