From: Sangchul Lee Date: Fri, 18 Feb 2022 10:25:46 +0000 (+0900) Subject: Add more mutex guard for callbacks X-Git-Tag: submit/tizen/20220221.105949^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d4fcf85d8c20450f5d01e37eacb5de1d4ce9bbe;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add more mutex guard for callbacks [Version] 0.3.57 [Issue Type] Improvement Change-Id: I1f536532c3c4bac4101d68c125197d80b267856f Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index ebc5ba79..d72a2ea8 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.56 +Version: 0.3.57 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 91c4a732..31f64c43 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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); diff --git a/src/webrtc_resource.c b/src/webrtc_resource.c index 596e4a32..46dab533 100644 --- a/src/webrtc_resource.c +++ b/src/webrtc_resource.c @@ -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; diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index 43e6b7c4..6a49a0f7 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -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); diff --git a/src/webrtc_source.c b/src/webrtc_source.c index c8679783..2ae726de 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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