From 3a86a37c03c9701061abe551ac1d9fb2e38dd610 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 1 May 2020 18:52:33 +1000 Subject: [PATCH] sendrecv: wait until the offer is set before creating answer Pragmatically, an answer cannot be created until the offer is created as the answer creation needs information from the offer. Practically, due to implementation details, the answer was always queued after the set of the offer and so the call flow did not matter. The current code also hid a bug in webrtcbin where ice candidates would be generated before the answer had been created which is against the JSEP specification. Change to the correct call flow for exemplary effect. --- webrtc/sendrecv/gst/webrtc-sendrecv.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/webrtc/sendrecv/gst/webrtc-sendrecv.c b/webrtc/sendrecv/gst/webrtc-sendrecv.c index f2fef123cc..956b92b95a 100644 --- a/webrtc/sendrecv/gst/webrtc-sendrecv.c +++ b/webrtc/sendrecv/gst/webrtc-sendrecv.c @@ -517,7 +517,15 @@ on_answer_created (GstPromise * promise, gpointer user_data) } static void -on_offer_received (GstSDPMessage * sdp) +on_offer_set (GstPromise * promise, gpointer user_data) +{ + gst_promise_unref (promise); + promise = gst_promise_new_with_change_func (on_answer_created, NULL, NULL); + g_signal_emit_by_name (webrtc1, "create-answer", NULL, promise); +} + +static void +on_offer_received (GstSDPMessage *sdp) { GstWebRTCSessionDescription *offer = NULL; GstPromise *promise; @@ -527,15 +535,11 @@ on_offer_received (GstSDPMessage * sdp) /* Set remote description on our pipeline */ { - promise = gst_promise_new (); - g_signal_emit_by_name (webrtc1, "set-remote-description", offer, promise); - gst_promise_interrupt (promise); - gst_promise_unref (promise); + promise = gst_promise_new_with_change_func (on_offer_set, NULL, NULL); + g_signal_emit_by_name (webrtc1, "set-remote-description", offer, + promise); } gst_webrtc_session_description_free (offer); - - promise = gst_promise_new_with_change_func (on_answer_created, NULL, NULL); - g_signal_emit_by_name (webrtc1, "create-answer", NULL, promise); } /* One mega message handler for our asynchronous calling mechanism */