summary refs log tree commit diff
diff options
context:
space:
mode:
authortrilene <trilene@runbox.com>2020-08-02 22:27:05 -0400
committertrilene <trilene@runbox.com>2020-08-02 22:27:05 -0400
commit02dfc8039f03e6965ee094671ef59c128e6c7eac (patch)
treee1435e6d5bfca66d6371397149abeea04d7b1b14
parentMerge remote-tracking branch 'upstream/master' into voip (diff)
downloadnheko-02dfc8039f03e6965ee094671ef59c128e6c7eac.tar.xz
Conditionally compile against upcoming GStreamer release
-rw-r--r--src/WebRTCSession.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/WebRTCSession.cpp b/src/WebRTCSession.cpp
index 32b67123..07dfaac4 100644
--- a/src/WebRTCSession.cpp
+++ b/src/WebRTCSession.cpp
@@ -169,6 +169,30 @@ createAnswer(GstPromise *promise, gpointer webrtc)
         g_signal_emit_by_name(webrtc, "create-answer", nullptr, promise);
 }
 
+#if GST_CHECK_VERSION(1, 17, 0)
+void
+iceGatheringStateChanged(GstElement *webrtc,
+                         GParamSpec *pspec G_GNUC_UNUSED,
+                         gpointer user_data G_GNUC_UNUSED)
+{
+        GstWebRTCICEGatheringState newState;
+        g_object_get(webrtc, "ice-gathering-state", &newState, nullptr);
+        if (newState == GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE) {
+                nhlog::ui()->debug("WebRTC: GstWebRTCICEGatheringState -> Complete");
+                if (isoffering_) {
+                        emit WebRTCSession::instance().offerCreated(localsdp_, localcandidates_);
+                        emit WebRTCSession::instance().stateChanged(
+                          WebRTCSession::State::OFFERSENT);
+                } else {
+                        emit WebRTCSession::instance().answerCreated(localsdp_, localcandidates_);
+                        emit WebRTCSession::instance().stateChanged(
+                          WebRTCSession::State::ANSWERSENT);
+                }
+        }
+}
+
+#else
+
 gboolean
 onICEGatheringCompletion(gpointer timerid)
 {
@@ -182,6 +206,7 @@ onICEGatheringCompletion(gpointer timerid)
         }
         return FALSE;
 }
+#endif
 
 void
 addLocalICECandidate(GstElement *webrtc G_GNUC_UNUSED,
@@ -200,13 +225,15 @@ addLocalICECandidate(GstElement *webrtc G_GNUC_UNUSED,
         localcandidates_.push_back({"audio", (uint16_t)mlineIndex, candidate});
 
         // GStreamer v1.16: webrtcbin's notify::ice-gathering-state triggers
-        // GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE too early. Fixed in v1.18. Use a 100ms timeout in
-        // the meantime
+        // GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE too early. Fixed in v1.17.
+        // Use a 100ms timeout in the meantime
+#if !GST_CHECK_VERSION(1, 17, 0)
         static guint timerid = 0;
         if (timerid)
                 g_source_remove(timerid);
 
         timerid = g_timeout_add(100, onICEGatheringCompletion, &timerid);
+#endif
 }
 
 void
@@ -437,6 +464,11 @@ WebRTCSession::startPipeline(int opusPayloadType)
         gst_element_set_state(pipe_, GST_STATE_READY);
         g_signal_connect(webrtc_, "pad-added", G_CALLBACK(addDecodeBin), pipe_);
 
+#if GST_CHECK_VERSION(1, 17, 0)
+        // capture ICE gathering completion
+        g_signal_connect(
+          webrtc_, "notify::ice-gathering-state", G_CALLBACK(iceGatheringStateChanged), nullptr);
+#endif
         // webrtcbin lifetime is the same as that of the pipeline
         gst_object_unref(webrtc_);