From: Sangchul Lee Date: Sat, 9 Mar 2024 05:26:37 +0000 (+0900) Subject: webrtc_private: Ensure signaling state change before returning of _webrtcbin_set_sess... X-Git-Tag: accepted/tizen/unified/20240327.141705~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e73ac03c4aa1e8a144d0ced1d12af43685d3b712;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_private: Ensure signaling state change before returning of _webrtcbin_set_session_description() Though posting to invoke the signaling state changed callback in idle still exists, now it is possible to call webrtc_create_answer() without checking the signaling state changed callback right after calling webrtc_set_remote_description(). [Version] 0.4.52 [Issue Type] Improvement Change-Id: If03504c56ec44654f729ec5ea4c2cd96f4c3547f Signed-off-by: Sangchul Lee (cherry picked from commit d50e506fdff1700698991d00373b57eb30b56f88) --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 798b3f23..1cc92c08 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.4.51 +Version: 0.4.52 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 0d92a0b9..1d1859b9 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1224,6 +1224,10 @@ static void __webrtcbin_signaling_state_cb(GstElement *webrtcbin, GParamSpec * p locker = g_mutex_locker_new(&webrtc->destroy_mutex); + g_mutex_lock(&webrtc->desc_mutex); + g_cond_signal(&webrtc->desc_cond); + g_mutex_unlock(&webrtc->desc_mutex); + __post_signaling_state_change_cb_in_idle(webrtc, __signaling_state_info[state].state); } @@ -2011,13 +2015,14 @@ static int __get_sdp_from_description(const char *description, gchar **sdp, gcha int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote) { - int ret = WEBRTC_ERROR_NONE; - gchar *sdp; - gchar *type; + int ret; + g_autofree gchar *sdp = NULL; + g_autofree gchar *type = NULL; GstSDPMessage *gst_sdp; GstWebRTCSDPType sdp_type; GstWebRTCSessionDescription *desc; GstPromise *promise; + gint64 end_time; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL"); @@ -2030,20 +2035,20 @@ int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description ret = gst_sdp_message_new(&gst_sdp); if (ret != GST_SDP_OK) { LOG_ERROR("failed to gst_sdp_message_new()"); - ret = WEBRTC_ERROR_INVALID_OPERATION; - goto end; + return WEBRTC_ERROR_INVALID_OPERATION; } ret = gst_sdp_message_parse_buffer((guint8 *)sdp, strlen(sdp), gst_sdp); if (ret != GST_SDP_OK) { LOG_ERROR("failed to gst_sdp_message_parse_buffer()"); - ret = WEBRTC_ERROR_INVALID_OPERATION; - goto end; + return WEBRTC_ERROR_INVALID_OPERATION; } sdp_type = g_str_equal(type, "answer") ? GST_WEBRTC_SDP_TYPE_ANSWER : GST_WEBRTC_SDP_TYPE_OFFER; desc = gst_webrtc_session_description_new(sdp_type, gst_sdp); + g_mutex_lock(&webrtc->desc_mutex); + promise = gst_promise_new(); g_signal_emit_by_name(webrtc->gst.webrtcbin, is_remote ? "set-remote-description" : "set-local-description", desc, promise); gst_promise_interrupt(promise); @@ -2060,11 +2065,15 @@ int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description g_free(webrtc->local_desc); webrtc->local_desc = g_strdup(description); } -end: - g_free(sdp); - g_free(type); - return ret; + LOG_DEBUG("wait for invoking __webrtcbin_signaling_state_cb()"); + end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND; + if (!g_cond_wait_until(&webrtc->desc_cond, &webrtc->desc_mutex, end_time)) + LOG_WARNING("timeout of g_cond_wait_until()"); + + g_mutex_unlock(&webrtc->desc_mutex); + + return WEBRTC_ERROR_NONE; } /* Use g_free() to release the candidate parameter. */