From: Sangchul Lee Date: Tue, 22 Feb 2022 08:00:39 +0000 (+0900) Subject: fixup! Add more mutex guard for callbacks X-Git-Tag: submit/tizen/20220224.015113^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75edbf55015d8f4345084b738b178d7b50fa17d0;p=platform%2Fcore%2Fapi%2Fwebrtc.git fixup! Add more mutex guard for callbacks New mutex variable is defined for idle cb event source. [Version] 0.3.60 [Issue Type] Improvement Change-Id: Iee25695dbee13d25ff027baf39be79986a7bd9a0 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 062f7cc8..47ff2043 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -434,6 +434,7 @@ typedef struct _webrtc_s { guint stats_timer_src; GMutex mutex; + GMutex event_src_mutex; GMutex desc_mutex; GCond desc_cond; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 0e3db840..bac73b16 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.59 +Version: 0.3.60 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index af3cd54c..986a6aaa 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -92,7 +92,7 @@ int webrtc_create(webrtc_h *webrtc) g_mutex_init(&_webrtc->mutex); locker = g_mutex_locker_new(&_webrtc->mutex); - + g_mutex_init(&_webrtc->event_src_mutex); g_mutex_init(&_webrtc->desc_mutex); g_cond_init(&_webrtc->desc_cond); @@ -159,8 +159,9 @@ int webrtc_destroy(webrtc_h webrtc) _gst_destroy_pipeline(_webrtc); _unload_ini(_webrtc); - g_mutex_clear(&_webrtc->desc_mutex); g_cond_clear(&_webrtc->desc_cond); + g_mutex_clear(&_webrtc->desc_mutex); + g_mutex_clear(&_webrtc->event_src_mutex); LOG_INFO("webrtc[%p] is destroyed", webrtc); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 31f64c43..cb95b7a9 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -589,7 +589,9 @@ static gboolean __idle_cb(gpointer user_data) webrtc_state_e old_state; g_mutex_lock(&webrtc->mutex); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; + g_mutex_unlock(&webrtc->event_src_mutex); old_state = webrtc->state; webrtc->state = data->new.state; g_mutex_unlock(&webrtc->mutex); @@ -599,41 +601,41 @@ static gboolean __idle_cb(gpointer user_data) } case IDLE_CB_TYPE_ERROR: - g_mutex_lock(&webrtc->mutex); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; - g_mutex_unlock(&webrtc->mutex); + g_mutex_unlock(&webrtc->event_src_mutex); __invoke_error_cb(webrtc, data->new.error); break; case IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE: - g_mutex_lock(&webrtc->mutex); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; - g_mutex_unlock(&webrtc->mutex); + g_mutex_unlock(&webrtc->event_src_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); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; - g_mutex_unlock(&webrtc->mutex); + g_mutex_unlock(&webrtc->event_src_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); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; - g_mutex_unlock(&webrtc->mutex); + g_mutex_unlock(&webrtc->event_src_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); + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = 0; - g_mutex_unlock(&webrtc->mutex); + g_mutex_unlock(&webrtc->event_src_mutex); __invoke_ice_connection_state_change_cb(webrtc, data->new.ice_connection_state); break; @@ -675,7 +677,9 @@ void _post_state_cb_in_idle(webrtc_s *webrtc, webrtc_state_e new_state) webrtc->pend_state = new_state; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("state will be changed [%s] -> [%s], source id[%u]", __state_str[webrtc->state], __state_str[new_state], webrtc->idle_cb_event_source_ids[data->type]); @@ -693,7 +697,9 @@ void _post_error_cb_in_idle(webrtc_s *webrtc, webrtc_error_e error) data->type = IDLE_CB_TYPE_ERROR; data->new.error = error; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("error will occur [0x%x], source id[%u]", error, webrtc->idle_cb_event_source_ids[data->type]); } @@ -709,7 +715,9 @@ static void __post_peer_connection_state_change_cb_in_idle(webrtc_s *webrtc, web data->type = IDLE_CB_TYPE_PEER_CONNECTION_STATE_CHANGE; data->new.peer_connection_state = state; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("connection state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]); } @@ -726,7 +734,9 @@ static void __post_signaling_state_change_cb_in_idle(webrtc_s *webrtc, webrtc_si data->type = IDLE_CB_TYPE_SIGNALING_STATE_CHANGE; data->new.signaling_state = state; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("signaling state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]); } @@ -742,7 +752,9 @@ static void __post_ice_gathering_state_change_cb_in_idle(webrtc_s *webrtc, webrt data->type = IDLE_CB_TYPE_ICE_GATHERING_STATE_CHANGE; data->new.ice_gathering_state = state; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("ICE gathering state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]); } @@ -759,7 +771,9 @@ static void __post_ice_connection_state_change_cb_in_idle(webrtc_s *webrtc, webr data->type = IDLE_CB_TYPE_ICE_CONNECTION_STATE_CHANGE; data->new.ice_connection_state = state; + g_mutex_lock(&webrtc->event_src_mutex); webrtc->idle_cb_event_source_ids[data->type] = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __idle_cb, data, g_free); + g_mutex_unlock(&webrtc->event_src_mutex); LOG_DEBUG("ICE connection state will be changed to [%u], source id[%u]", state, webrtc->idle_cb_event_source_ids[data->type]); } @@ -1005,9 +1019,7 @@ 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"); @@ -1061,9 +1073,7 @@ 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: @@ -1100,9 +1110,7 @@ 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) @@ -1118,9 +1126,7 @@ 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 @@ -1137,9 +1143,7 @@ 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 46dab533..596e4a32 100644 --- a/src/webrtc_resource.c +++ b/src/webrtc_resource.c @@ -57,9 +57,7 @@ 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 6a49a0f7..43e6b7c4 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -416,9 +416,7 @@ 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 2ae726de..c8679783 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -4162,9 +4162,7 @@ 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