webrtc_private: Ensure signaling state change before returning of _webrtcbin_set_sess... 48/307848/1
authorSangchul Lee <sc11.lee@samsung.com>
Sat, 9 Mar 2024 05:26:37 +0000 (14:26 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 14 Mar 2024 00:05:25 +0000 (00:05 +0000)
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 <sc11.lee@samsung.com>
(cherry picked from commit d50e506fdff1700698991d00373b57eb30b56f88)

packaging/capi-media-webrtc.spec
src/webrtc_private.c

index 798b3f23c55d0bd1e5cc0b6b05ee7f10f7f06442..1cc92c086c02e1ee7c2daabc38052bdef63c69b4 100644 (file)
@@ -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
index 0d92a0b915be23e515d679d51f205677fb6bf0c7..1d1859b95017bf41bca1a03c78bb49ad99814104 100644 (file)
@@ -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. */