sendrecv: wait until the offer is set before creating answer
authorMatthew Waters <matthew@centricular.com>
Fri, 1 May 2020 08:52:33 +0000 (18:52 +1000)
committerMatthew Waters <ystreet00@gmail.com>
Wed, 6 May 2020 06:01:57 +0000 (06:01 +0000)
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

index f2fef12..956b92b 100644 (file)
@@ -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 */