Add locking mutex for state 67/303667/1 accepted/tizen/8.0/unified/20240104.165415
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 3 Jan 2024 03:02:18 +0000 (12:02 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 3 Jan 2024 08:03:28 +0000 (08:03 +0000)
[Version] 0.4.29
[Issue Type] Coverity defect (MISSING_LOCK)

Change-Id: If29613750c55c1179a3393de65f52866be4997b8
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_private.c
src/webrtc_stats.c

index 6ff3c348f135f1527f40121488279bdbb1c199d2..7aada97d9d087e594614222f74fada0061ebeafd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.28
+Version:    0.4.29
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index f5927e5da054d2a7739c578d92c6bb0d2722af24..221d06fde0b75798a2d4580516205386246023f0 100644 (file)
@@ -748,11 +748,12 @@ int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x
        RET_VAL_IF(y < 0, WEBRTC_ERROR_INVALID_PARAMETER, "y < 0");
        RET_VAL_IF(width == 0, WEBRTC_ERROR_INVALID_PARAMETER, "width is 0");
        RET_VAL_IF(height == 0, WEBRTC_ERROR_INVALID_PARAMETER, "height is 0");
-       RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE");
-       RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM);
 
        locker = g_mutex_locker_new(&_webrtc->mutex);
 
+       RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE");
+       RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM);
+
 #ifdef TIZEN_FEATURE_UI
        return _set_screen_source_crop(_webrtc, source_id, x, y, width, height);
 #else
@@ -768,11 +769,12 @@ int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id)
 
        RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0");
-       RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE");
-       RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM);
 
        locker = g_mutex_locker_new(&_webrtc->mutex);
 
+       RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE");
+       RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM);
+
 #ifdef TIZEN_FEATURE_UI
        return _unset_screen_source_crop(_webrtc, source_id);
 #else
index 0cd747f998111bd1058e529c176546da972d4252..c35e1cc09c090cdd7950a141efb245801a6599d0 100644 (file)
@@ -1452,12 +1452,15 @@ static void __webrtcbin_pad_added_cb(GstElement *webrtcbin, GstPad *new_pad, gpo
        webrtc_s *webrtc = (webrtc_s *)user_data;
        gchar *media_type = NULL;
        bool is_audio;
+       g_autoptr(GMutexLocker) locker = NULL;
 
        RET_IF(webrtc == NULL, "webrtc is NULL");
 
        if (GST_PAD_DIRECTION(new_pad) != GST_PAD_SRC)
                return;
 
+       locker = g_mutex_locker_new(&webrtc->mutex);
+
        RET_IF(webrtc->pend_state == WEBRTC_STATE_IDLE, "pend_state is IDLE, skip it");
 
        LOG_INFO("new pad[%s] is added", GST_PAD_NAME(new_pad));
@@ -1473,6 +1476,9 @@ static void __webrtcbin_pad_added_cb(GstElement *webrtcbin, GstPad *new_pad, gpo
        is_audio = _is_audio_media_type(media_type);
        g_free(media_type);
 
+       /* NOTE: Unlock the mutex here before calling track added user callback */
+       g_clear_pointer(&locker, g_mutex_locker_free);
+
        if ((!is_audio && webrtc->encoded_video_frame_cb.callback) ||
                (is_audio && webrtc->encoded_audio_frame_cb.callback)) {
                ret = _add_forwarding_sink_bin(webrtc, new_pad, is_audio);
index ffc9500722ea6199212b6c36d1ced83f73f1349c..7489a023b26bb1321268f587386d43fbba48b9cd 100644 (file)
@@ -973,6 +973,11 @@ void _webrtcbin_foreach_stats(webrtc_s *webrtc, int type_mask, void *callback, v
 static gboolean __get_stats_periodically(gpointer user_data)
 {
        webrtc_s *webrtc = (webrtc_s *)user_data;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       RET_VAL_IF(webrtc == NULL, G_SOURCE_REMOVE, "webrtc is NULL");
+
+       locker = g_mutex_locker_new(&webrtc->mutex);
 
        if (webrtc->state == WEBRTC_STATE_PLAYING)
                _webrtcbin_foreach_stats(webrtc, WEBRTC_STATS_TYPE_GST_ALL, NULL, NULL);