Add more mutex guard for callbacks 78/271378/1 submit/tizen/20220221.105949
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Feb 2022 10:25:46 +0000 (19:25 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 18 Feb 2022 10:59:21 +0000 (19:59 +0900)
[Version] 0.3.57
[Issue Type] Improvement

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

index ebc5ba7942dce76ca3ceeea1b6a72d184a6f56d8..d72a2ea8854537c68fe66fefc40a0ebba55e431a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.56
+Version:    0.3.57
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 91c4a7326bab1f9a34506a8f9aa7c83794dea881..31f64c43da833cc418c7b67ad91ba571f7c4670c 100644 (file)
@@ -589,36 +589,55 @@ static gboolean __idle_cb(gpointer user_data)
                webrtc_state_e old_state;
 
                g_mutex_lock(&webrtc->mutex);
-
                webrtc->idle_cb_event_source_ids[data->type] = 0;
                old_state = webrtc->state;
                webrtc->state = data->new.state;
-
                g_mutex_unlock(&webrtc->mutex);
 
                _invoke_state_changed_cb(webrtc, old_state, webrtc->state);
                break;
        }
+
        case IDLE_CB_TYPE_ERROR:
+               g_mutex_lock(&webrtc->mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->mutex);
+
                __invoke_error_cb(webrtc, data->new.error);
                break;
+
        case IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE:
+               g_mutex_lock(&webrtc->mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->mutex);
+
                __invoke_peer_connection_state_change_cb(webrtc, data->new.peer_connection_state);
                break;
+
        case IDLE_CB_TYPE_SIGNALING_STATE_CHANGE:
+               g_mutex_lock(&webrtc->mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->mutex);
+
                __invoke_signaling_state_change_cb(webrtc, data->new.signaling_state);
                break;
+
        case IDLE_CB_TYPE_ICE_GATHERING_STATE_CHANGE:
+               g_mutex_lock(&webrtc->mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->mutex);
+
                __invoke_ice_gathering_state_change_cb(webrtc, data->new.ice_gathering_state);
                break;
+
        case IDLE_CB_TYPE_ICE_CONNECTION_STATE_CHANGE:
+               g_mutex_lock(&webrtc->mutex);
                webrtc->idle_cb_event_source_ids[data->type] = 0;
+               g_mutex_unlock(&webrtc->mutex);
+
                __invoke_ice_connection_state_change_cb(webrtc, data->new.ice_connection_state);
                break;
+
        default:
                LOG_ERROR_IF_REACHED("type(%d)", data->type);
        }
@@ -986,7 +1005,9 @@ static void __webrtcbin_on_negotiation_needed_cb(GstElement *webrtcbin, gpointer
        RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
        RET_IF(webrtc == NULL, "webrtc is NULL");
 
+       g_mutex_lock(&webrtc->mutex);
        _post_state_cb_in_idle(webrtc, WEBRTC_STATE_NEGOTIATING);
+       g_mutex_unlock(&webrtc->mutex);
 
        if (webrtc->negotiation_needed_cb.callback == NULL) {
                LOG_DEBUG("negotiation_needed_cb is NULL, skip it");
@@ -1040,7 +1061,9 @@ static void __webrtcbin_peer_connection_state_cb(GstElement *webrtcbin, GParamSp
        LOG_DEBUG("webrtc[%p] [PeerConnectionState] is changed to [%s]", webrtc, __peer_connection_state_info[state].str);
        webrtc->negotiation_states.peer_connection_state = __peer_connection_state_info[state].state;
 
+       g_mutex_lock(&webrtc->mutex);
        __post_peer_connection_state_change_cb_in_idle(webrtc, state);
+       g_mutex_unlock(&webrtc->mutex);
 
        switch (state) {
        case GST_WEBRTC_PEER_CONNECTION_STATE_CONNECTED:
@@ -1077,7 +1100,9 @@ static void __webrtcbin_signaling_state_cb(GstElement *webrtcbin, GParamSpec * p
                state == GST_WEBRTC_SIGNALING_STATE_STABLE)
                __update_data_recovery_type_from_remote_description(webrtc);
 
+       g_mutex_lock(&webrtc->mutex);
        __post_signaling_state_change_cb_in_idle(webrtc, state);
+       g_mutex_unlock(&webrtc->mutex);
 }
 
 static void __webrtcbin_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec * pspec, gpointer user_data)
@@ -1093,7 +1118,9 @@ static void __webrtcbin_ice_gathering_state_cb(GstElement *webrtcbin, GParamSpec
        LOG_DEBUG("webrtc[%p] [IceGatheringState] is changed to [%s]", webrtc, __ice_gathering_state_info[state].str);
        webrtc->negotiation_states.ice_gathering_state = __ice_gathering_state_info[state].state;
 
+       g_mutex_lock(&webrtc->mutex);
        __post_ice_gathering_state_change_cb_in_idle(webrtc, state);
+       g_mutex_unlock(&webrtc->mutex);
 }
 
 //LCOV_EXCL_START
@@ -1110,7 +1137,9 @@ static void __webrtcbin_ice_connection_state_cb(GstElement *webrtcbin, GParamSpe
        LOG_DEBUG("webrtc[%p] [IceConnectionState] is changed to [%s]", webrtc, __ice_connection_state_info[state].str);
        webrtc->negotiation_states.ice_connection_state = __ice_connection_state_info[state].state;
 
+       g_mutex_lock(&webrtc->mutex);
        __post_ice_connection_state_change_cb_in_idle(webrtc, state);
+       g_mutex_unlock(&webrtc->mutex);
 
        if (state == GST_WEBRTC_ICE_CONNECTION_STATE_FAILED)
                __invoke_error_cb(webrtc, WEBRTC_ERROR_CONNECTION_FAILED);
index 596e4a32e9849667ef9cd48409a203628eba3a3f..46dab533dc4dcf500c542ef37ba0a69ddadab809 100644 (file)
@@ -57,7 +57,9 @@ static int __resource_release_cb(mm_resource_manager_h mgr,
        if (_webrtc_stop(webrtc) != WEBRTC_ERROR_NONE)
                ret = false;
 
+       g_mutex_lock(&webrtc->mutex);
        _post_error_cb_in_idle(webrtc, WEBRTC_ERROR_RESOURCE_CONFLICT);
+       g_mutex_unlock(&webrtc->mutex);
 
        webrtc->resource.release_cb_is_calling = false;
 
index 43e6b7c424d56cdc1fb878072e7cce276fc9ecdb..6a49a0f7be413b7759dcfe913b6cb38e3f120d13 100644 (file)
@@ -416,7 +416,9 @@ static void __decodebin_pad_added_cb(GstElement *decodebin, GstPad *new_pad, gpo
 
        if (ret != WEBRTC_ERROR_NONE) {
                LOG_ERROR("failed to build a rendering pipeline, ret[0x%x]", ret);
+               g_mutex_lock(&webrtc->mutex);
                _post_error_cb_in_idle(webrtc, ret);
+               g_mutex_unlock(&webrtc->mutex);
        }
 
        g_free(media_type);
index c8679783ccc267f8543af4eea3994fa9cc263980..2ae726de10c7d526fa63b0717c712d491b5dd885 100644 (file)
@@ -4162,7 +4162,9 @@ static void __loopback_decodebin_pad_added_cb(GstElement *decodebin, GstPad *new
 
        if (ret != WEBRTC_ERROR_NONE) {
                LOG_ERROR("failed to build loopback rendering sink, ret[0x%x]", ret);
+               g_mutex_lock(&source->webrtc->mutex);
                _post_error_cb_in_idle(source->webrtc, ret);
+               g_mutex_unlock(&source->webrtc->mutex);
        }
 }
 //LCOV_EXCL_STOP