webrtc: Split sctptransport into lib and implementation parts
authorJohan Sternerup <johast@axis.com>
Fri, 7 May 2021 06:12:25 +0000 (08:12 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 25 Aug 2021 13:20:22 +0000 (13:20 +0000)
GstWebRTCSCTPTransport is now made into into an abstract base class
that only contains property specifications matching the
RTCSctpTransport interface of the W3C WebRTC specification, see
https://w3c.github.io/webrtc-pc/#rtcsctptransport-interface. This
class is put into the WebRTC library to expose it for applications and
to allow for generation of bindings for non-dynamic languages using
GObject introspection.

The actual implementation is moved to the subclass WebRTCSCTPTransport
located in the WebRTC plugin.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2214>

14 files changed:
ext/webrtc/gstwebrtcbin.c
ext/webrtc/gstwebrtcbin.h
ext/webrtc/meson.build
ext/webrtc/sctptransport.c [deleted file]
ext/webrtc/sctptransport.h [deleted file]
ext/webrtc/webrtcdatachannel.c
ext/webrtc/webrtcdatachannel.h
ext/webrtc/webrtcsctptransport.c [new file with mode: 0644]
ext/webrtc/webrtcsctptransport.h [new file with mode: 0644]
gst-libs/gst/webrtc/meson.build
gst-libs/gst/webrtc/sctptransport.c [new file with mode: 0644]
gst-libs/gst/webrtc/sctptransport.h [new file with mode: 0644]
gst-libs/gst/webrtc/webrtc-priv.h
gst-libs/gst/webrtc/webrtc_fwd.h

index c6855fc7f78402564925d632c599dc995201ac46..0e585bb936d4eac9c3521d7f9cee256432f56663 100644 (file)
@@ -29,7 +29,7 @@
 #include "webrtcsdp.h"
 #include "webrtctransceiver.h"
 #include "webrtcdatachannel.h"
-#include "sctptransport.h"
+#include "webrtcsctptransport.h"
 
 #include "gst/webrtc/webrtc-priv.h"
 
@@ -1986,7 +1986,7 @@ gst_webrtc_bin_update_sctp_priority (GstWebRTCBin * webrtc)
   /* If one stream has a non-default priority, then everyone else does too */
   gst_webrtc_bin_attach_tos (webrtc);
 
-  gst_webrtc_sctp_transport_set_priority (webrtc->priv->sctp_transport,
+  webrtc_sctp_transport_set_priority (webrtc->priv->sctp_transport,
       sctp_priority);
 }
 
@@ -2201,7 +2201,7 @@ _on_sctpdec_pad_added (GstElement * sctpdec, GstPad * pad,
 }
 
 static void
-_on_sctp_state_notify (GstWebRTCSCTPTransport * sctp, GParamSpec * pspec,
+_on_sctp_state_notify (WebRTCSCTPTransport * sctp, GParamSpec * pspec,
     GstWebRTCBin * webrtc)
 {
   GstWebRTCSCTPTransportState state;
@@ -2238,7 +2238,7 @@ _sctp_check_dtls_state_task (GstWebRTCBin * webrtc, gpointer unused)
   TransportStream *stream;
   GstWebRTCDTLSTransport *transport;
   GstWebRTCDTLSTransportState dtls_state;
-  GstWebRTCSCTPTransport *sctp_transport;
+  WebRTCSCTPTransport *sctp_transport;
 
   stream = webrtc->priv->data_channel_transport;
   transport = stream->transport;
@@ -2326,7 +2326,7 @@ _get_or_create_data_channel_transports (GstWebRTCBin * webrtc, guint session_id)
 {
   if (!webrtc->priv->data_channel_transport) {
     TransportStream *stream;
-    GstWebRTCSCTPTransport *sctp_transport;
+    WebRTCSCTPTransport *sctp_transport;
 
     stream = _find_transport_for_session (webrtc, session_id);
 
@@ -2336,7 +2336,7 @@ _get_or_create_data_channel_transports (GstWebRTCBin * webrtc, guint session_id)
     webrtc->priv->data_channel_transport = stream;
 
     if (!(sctp_transport = webrtc->priv->sctp_transport)) {
-      sctp_transport = gst_webrtc_sctp_transport_new ();
+      sctp_transport = webrtc_sctp_transport_new ();
       sctp_transport->transport =
           g_object_ref (webrtc->priv->data_channel_transport->transport);
       sctp_transport->webrtcbin = webrtc;
index b180aa62f9515878d58dbf4677c8116e8447e400..e2ef991ebcff2a20367938d393bd99ab34400838 100644 (file)
@@ -24,6 +24,7 @@
 #include "fwd.h"
 #include "gstwebrtcice.h"
 #include "transportstream.h"
+#include "webrtcsctptransport.h"
 
 G_BEGIN_DECLS
 
@@ -106,7 +107,7 @@ struct _GstWebRTCBinPrivate
 
   guint jb_latency;
 
-  GstWebRTCSCTPTransport *sctp_transport;
+  WebRTCSCTPTransport *sctp_transport;
   TransportStream *data_channel_transport;
 
   GstWebRTCICE *ice;
index 05a3b97bdb302550fc20e34ba08ea2419a08c539..1696d2aa6bf3d550d79513bd71d06eabf6b30563 100644 (file)
@@ -4,7 +4,7 @@ webrtc_sources = [
   'gstwebrtcstats.c',
   'icestream.c',
   'nicetransport.c',
-  'sctptransport.c',
+  'webrtcsctptransport.c',
   'gstwebrtcbin.c',
   'transportreceivebin.c',
   'transportsendbin.c',
diff --git a/ext/webrtc/sctptransport.c b/ext/webrtc/sctptransport.c
deleted file mode 100644 (file)
index 8452198..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/* GStreamer
- * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-
-#include "sctptransport.h"
-#include "gstwebrtcbin.h"
-
-#define GST_CAT_DEFAULT gst_webrtc_sctp_transport_debug
-GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
-
-enum
-{
-  SIGNAL_0,
-  ON_STREAM_RESET_SIGNAL,
-  LAST_SIGNAL,
-};
-
-enum
-{
-  PROP_0,
-  PROP_TRANSPORT,
-  PROP_STATE,
-  PROP_MAX_MESSAGE_SIZE,
-  PROP_MAX_CHANNELS,
-};
-
-static guint gst_webrtc_sctp_transport_signals[LAST_SIGNAL] = { 0 };
-
-#define gst_webrtc_sctp_transport_parent_class parent_class
-G_DEFINE_TYPE_WITH_CODE (GstWebRTCSCTPTransport, gst_webrtc_sctp_transport,
-    GST_TYPE_OBJECT, GST_DEBUG_CATEGORY_INIT (gst_webrtc_sctp_transport_debug,
-        "webrtcsctptransport", 0, "webrtcsctptransport"););
-
-typedef void (*SCTPTask) (GstWebRTCSCTPTransport * sctp, gpointer user_data);
-
-struct task
-{
-  GstWebRTCSCTPTransport *sctp;
-  SCTPTask func;
-  gpointer user_data;
-  GDestroyNotify notify;
-};
-
-static GstStructure *
-_execute_task (GstWebRTCBin * webrtc, struct task *task)
-{
-  if (task->func)
-    task->func (task->sctp, task->user_data);
-  return NULL;
-}
-
-static void
-_free_task (struct task *task)
-{
-  gst_object_unref (task->sctp);
-
-  if (task->notify)
-    task->notify (task->user_data);
-  g_free (task);
-}
-
-static void
-_sctp_enqueue_task (GstWebRTCSCTPTransport * sctp, SCTPTask func,
-    gpointer user_data, GDestroyNotify notify)
-{
-  struct task *task = g_new0 (struct task, 1);
-
-  task->sctp = gst_object_ref (sctp);
-  task->func = func;
-  task->user_data = user_data;
-  task->notify = notify;
-
-  gst_webrtc_bin_enqueue_task (sctp->webrtcbin,
-      (GstWebRTCBinFunc) _execute_task, task, (GDestroyNotify) _free_task,
-      NULL);
-}
-
-static void
-_emit_stream_reset (GstWebRTCSCTPTransport * sctp, gpointer user_data)
-{
-  guint stream_id = GPOINTER_TO_UINT (user_data);
-
-  g_signal_emit (sctp,
-      gst_webrtc_sctp_transport_signals[ON_STREAM_RESET_SIGNAL], 0, stream_id);
-}
-
-static void
-_on_sctp_dec_pad_removed (GstElement * sctpdec, GstPad * pad,
-    GstWebRTCSCTPTransport * sctp)
-{
-  guint stream_id;
-
-  if (sscanf (GST_PAD_NAME (pad), "src_%u", &stream_id) != 1)
-    return;
-
-  _sctp_enqueue_task (sctp, (SCTPTask) _emit_stream_reset,
-      GUINT_TO_POINTER (stream_id), NULL);
-}
-
-static void
-_on_sctp_association_established (GstElement * sctpenc, gboolean established,
-    GstWebRTCSCTPTransport * sctp)
-{
-  GST_OBJECT_LOCK (sctp);
-  if (established)
-    sctp->state = GST_WEBRTC_SCTP_TRANSPORT_STATE_CONNECTED;
-  else
-    sctp->state = GST_WEBRTC_SCTP_TRANSPORT_STATE_CLOSED;
-  sctp->association_established = established;
-  GST_OBJECT_UNLOCK (sctp);
-
-  g_object_notify (G_OBJECT (sctp), "state");
-}
-
-static void
-gst_webrtc_sctp_transport_set_property (GObject * object, guint prop_id,
-    const GValue * value, GParamSpec * pspec)
-{
-//  GstWebRTCSCTPTransport *sctp = GST_WEBRTC_SCTP_TRANSPORT (object);
-
-  switch (prop_id) {
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-  }
-}
-
-void
-gst_webrtc_sctp_transport_set_priority (GstWebRTCSCTPTransport * sctp,
-    GstWebRTCPriorityType priority)
-{
-  GstPad *pad;
-
-  pad = gst_element_get_static_pad (sctp->sctpenc, "src");
-  gst_pad_push_event (pad,
-      gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY,
-          gst_structure_new ("GstWebRtcBinUpdateTos", "sctp-priority",
-              GST_TYPE_WEBRTC_PRIORITY_TYPE, priority, NULL)));
-  gst_object_unref (pad);
-}
-
-static void
-gst_webrtc_sctp_transport_get_property (GObject * object, guint prop_id,
-    GValue * value, GParamSpec * pspec)
-{
-  GstWebRTCSCTPTransport *sctp = GST_WEBRTC_SCTP_TRANSPORT (object);
-
-  switch (prop_id) {
-    case PROP_TRANSPORT:
-      g_value_set_object (value, sctp->transport);
-      break;
-    case PROP_STATE:
-      g_value_set_enum (value, sctp->state);
-      break;
-    case PROP_MAX_MESSAGE_SIZE:
-      g_value_set_uint64 (value, sctp->max_message_size);
-      break;
-    case PROP_MAX_CHANNELS:
-      g_value_set_uint (value, sctp->max_channels);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-  }
-}
-
-static void
-gst_webrtc_sctp_transport_finalize (GObject * object)
-{
-  GstWebRTCSCTPTransport *sctp = GST_WEBRTC_SCTP_TRANSPORT (object);
-
-  g_signal_handlers_disconnect_by_data (sctp->sctpdec, sctp);
-  g_signal_handlers_disconnect_by_data (sctp->sctpenc, sctp);
-
-  gst_object_unref (sctp->sctpdec);
-  gst_object_unref (sctp->sctpenc);
-
-  g_clear_object (&sctp->transport);
-
-  G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-gst_webrtc_sctp_transport_constructed (GObject * object)
-{
-  GstWebRTCSCTPTransport *sctp = GST_WEBRTC_SCTP_TRANSPORT (object);
-  guint association_id;
-
-  association_id = g_random_int_range (0, G_MAXUINT16);
-
-  sctp->sctpdec =
-      g_object_ref_sink (gst_element_factory_make ("sctpdec", NULL));
-  g_object_set (sctp->sctpdec, "sctp-association-id", association_id, NULL);
-  sctp->sctpenc =
-      g_object_ref_sink (gst_element_factory_make ("sctpenc", NULL));
-  g_object_set (sctp->sctpenc, "sctp-association-id", association_id, NULL);
-  g_object_set (sctp->sctpenc, "use-sock-stream", TRUE, NULL);
-
-  g_signal_connect (sctp->sctpdec, "pad-removed",
-      G_CALLBACK (_on_sctp_dec_pad_removed), sctp);
-  g_signal_connect (sctp->sctpenc, "sctp-association-established",
-      G_CALLBACK (_on_sctp_association_established), sctp);
-
-  G_OBJECT_CLASS (parent_class)->constructed (object);
-}
-
-static void
-gst_webrtc_sctp_transport_class_init (GstWebRTCSCTPTransportClass * klass)
-{
-  GObjectClass *gobject_class = (GObjectClass *) klass;
-
-  gobject_class->constructed = gst_webrtc_sctp_transport_constructed;
-  gobject_class->get_property = gst_webrtc_sctp_transport_get_property;
-  gobject_class->set_property = gst_webrtc_sctp_transport_set_property;
-  gobject_class->finalize = gst_webrtc_sctp_transport_finalize;
-
-  g_object_class_install_property (gobject_class,
-      PROP_TRANSPORT,
-      g_param_spec_object ("transport",
-          "WebRTC DTLS Transport",
-          "DTLS transport used for this SCTP transport",
-          GST_TYPE_WEBRTC_DTLS_TRANSPORT,
-          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-  g_object_class_install_property (gobject_class,
-      PROP_STATE,
-      g_param_spec_enum ("state",
-          "WebRTC SCTP Transport state", "WebRTC SCTP Transport state",
-          GST_TYPE_WEBRTC_SCTP_TRANSPORT_STATE,
-          GST_WEBRTC_SCTP_TRANSPORT_STATE_NEW,
-          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-  g_object_class_install_property (gobject_class,
-      PROP_MAX_MESSAGE_SIZE,
-      g_param_spec_uint64 ("max-message-size",
-          "Maximum message size",
-          "Maximum message size as reported by the transport", 0, G_MAXUINT64,
-          0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-  g_object_class_install_property (gobject_class,
-      PROP_MAX_CHANNELS,
-      g_param_spec_uint ("max-channels",
-          "Maximum number of channels", "Maximum number of channels",
-          0, G_MAXUINT16, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-  /**
-   * GstWebRTCSCTPTransport::stream-reset:
-   * @object: the #GstWebRTCSCTPTransport
-   * @stream_id: the SCTP stream that was reset
-   */
-  gst_webrtc_sctp_transport_signals[ON_STREAM_RESET_SIGNAL] =
-      g_signal_new ("stream-reset", G_TYPE_FROM_CLASS (klass),
-      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT);
-}
-
-static void
-gst_webrtc_sctp_transport_init (GstWebRTCSCTPTransport * nice)
-{
-}
-
-GstWebRTCSCTPTransport *
-gst_webrtc_sctp_transport_new (void)
-{
-  return g_object_new (GST_TYPE_WEBRTC_SCTP_TRANSPORT, NULL);
-}
diff --git a/ext/webrtc/sctptransport.h b/ext/webrtc/sctptransport.h
deleted file mode 100644 (file)
index 8a1466c..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* GStreamer
- * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __GST_WEBRTC_SCTP_TRANSPORT_H__
-#define __GST_WEBRTC_SCTP_TRANSPORT_H__
-
-#include <gst/gst.h>
-/* libnice */
-#include <agent.h>
-#include <gst/webrtc/webrtc.h>
-#include "gstwebrtcice.h"
-
-G_BEGIN_DECLS
-
-GType gst_webrtc_sctp_transport_get_type(void);
-#define GST_TYPE_WEBRTC_SCTP_TRANSPORT            (gst_webrtc_sctp_transport_get_type())
-#define GST_WEBRTC_SCTP_TRANSPORT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransport))
-#define GST_IS_WEBRTC_SCTP_TRANSPORT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_SCTP_TRANSPORT))
-#define GST_WEBRTC_SCTP_TRANSPORT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransportClass))
-#define GST_IS_WEBRTC_SCTP_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT))
-#define GST_WEBRTC_SCTP_TRANSPORT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransportClass))
-
-struct _GstWebRTCSCTPTransport
-{
-  GstObject                     parent;
-
-  GstWebRTCDTLSTransport       *transport;
-  GstWebRTCSCTPTransportState   state;
-  guint64                       max_message_size;
-  guint                         max_channels;
-
-  gboolean                      association_established;
-
-  gulong                        sctpdec_block_id;
-  GstElement                   *sctpdec;
-  GstElement                   *sctpenc;
-
-  GstWebRTCBin                 *webrtcbin;
-};
-
-struct _GstWebRTCSCTPTransportClass
-{
-  GstObjectClass                parent_class;
-};
-
-GstWebRTCSCTPTransport *    gst_webrtc_sctp_transport_new               (void);
-
-void
-gst_webrtc_sctp_transport_set_priority (GstWebRTCSCTPTransport *sctp,
-                                        GstWebRTCPriorityType priority);
-
-G_END_DECLS
-
-#endif /* __GST_WEBRTC_SCTP_TRANSPORT_H__ */
index 16b81d849ab94952d49dedf23a565906a8ef0cc9..e3877f87b624a748d5f9971e125ee4b54535ed8d 100644 (file)
@@ -356,7 +356,7 @@ _close_procedure (WebRTCDataChannel * channel, gpointer user_data)
 }
 
 static void
-_on_sctp_stream_reset (GstWebRTCSCTPTransport * sctp, guint stream_id,
+_on_sctp_stream_reset (WebRTCSCTPTransport * sctp, guint stream_id,
     WebRTCDataChannel * channel)
 {
   if (channel->parent.id == stream_id) {
@@ -1003,7 +1003,7 @@ webrtc_data_channel_init (WebRTCDataChannel * channel)
 
 static void
 _data_channel_set_sctp_transport (WebRTCDataChannel * channel,
-    GstWebRTCSCTPTransport * sctp)
+    WebRTCSCTPTransport * sctp)
 {
   g_return_if_fail (GST_IS_WEBRTC_DATA_CHANNEL (channel));
   g_return_if_fail (GST_IS_WEBRTC_SCTP_TRANSPORT (sctp));
@@ -1026,7 +1026,7 @@ _data_channel_set_sctp_transport (WebRTCDataChannel * channel,
 
 void
 webrtc_data_channel_link_to_sctp (WebRTCDataChannel * channel,
-    GstWebRTCSCTPTransport * sctp_transport)
+    WebRTCSCTPTransport * sctp_transport)
 {
   if (sctp_transport && !channel->sctp_transport) {
     gint id;
index 463e6ce12f0309ddd2b09b62d6febeaff8db1bd5..a0b38a7ad2d59ff71215b5899146a51ead5c71e3 100644 (file)
@@ -24,7 +24,7 @@
 #include <gst/webrtc/webrtc_fwd.h>
 #include <gst/webrtc/dtlstransport.h>
 #include <gst/webrtc/datachannel.h>
-#include "sctptransport.h"
+#include "webrtcsctptransport.h"
 
 #include "gst/webrtc/webrtc-priv.h"
 
@@ -45,7 +45,7 @@ struct _WebRTCDataChannel
 {
   GstWebRTCDataChannel              parent;
 
-  GstWebRTCSCTPTransport           *sctp_transport;
+  WebRTCSCTPTransport              *sctp_transport;
   GstElement                       *appsrc;
   GstElement                       *appsink;
 
@@ -68,7 +68,7 @@ struct _WebRTCDataChannelClass
 void    webrtc_data_channel_start_negotiation   (WebRTCDataChannel       *channel);
 G_GNUC_INTERNAL
 void    webrtc_data_channel_link_to_sctp (WebRTCDataChannel                 *channel,
-                                          GstWebRTCSCTPTransport            *sctp_transport);
+                                          WebRTCSCTPTransport               *sctp_transport);
 
 G_END_DECLS
 
diff --git a/ext/webrtc/webrtcsctptransport.c b/ext/webrtc/webrtcsctptransport.c
new file mode 100644 (file)
index 0000000..c65dd19
--- /dev/null
@@ -0,0 +1,251 @@
+/* GStreamer
+ * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "webrtcsctptransport.h"
+#include "gstwebrtcbin.h"
+
+#define GST_CAT_DEFAULT webrtc_sctp_transport_debug
+GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
+
+enum
+{
+  SIGNAL_0,
+  ON_STREAM_RESET_SIGNAL,
+  LAST_SIGNAL,
+};
+
+enum
+{
+  PROP_0,
+  PROP_TRANSPORT,
+  PROP_STATE,
+  PROP_MAX_MESSAGE_SIZE,
+  PROP_MAX_CHANNELS,
+};
+
+static guint webrtc_sctp_transport_signals[LAST_SIGNAL] = { 0 };
+
+#define webrtc_sctp_transport_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (WebRTCSCTPTransport, webrtc_sctp_transport,
+    GST_TYPE_WEBRTC_SCTP_TRANSPORT,
+    GST_DEBUG_CATEGORY_INIT (webrtc_sctp_transport_debug,
+        "webrtcsctptransport", 0, "webrtcsctptransport"););
+
+typedef void (*SCTPTask) (WebRTCSCTPTransport * sctp, gpointer user_data);
+
+struct task
+{
+  WebRTCSCTPTransport *sctp;
+  SCTPTask func;
+  gpointer user_data;
+  GDestroyNotify notify;
+};
+
+static GstStructure *
+_execute_task (GstWebRTCBin * webrtc, struct task *task)
+{
+  if (task->func)
+    task->func (task->sctp, task->user_data);
+  return NULL;
+}
+
+static void
+_free_task (struct task *task)
+{
+  gst_object_unref (task->sctp);
+
+  if (task->notify)
+    task->notify (task->user_data);
+  g_free (task);
+}
+
+static void
+_sctp_enqueue_task (WebRTCSCTPTransport * sctp, SCTPTask func,
+    gpointer user_data, GDestroyNotify notify)
+{
+  struct task *task = g_new0 (struct task, 1);
+
+  task->sctp = gst_object_ref (sctp);
+  task->func = func;
+  task->user_data = user_data;
+  task->notify = notify;
+
+  gst_webrtc_bin_enqueue_task (sctp->webrtcbin,
+      (GstWebRTCBinFunc) _execute_task, task, (GDestroyNotify) _free_task,
+      NULL);
+}
+
+static void
+_emit_stream_reset (WebRTCSCTPTransport * sctp, gpointer user_data)
+{
+  guint stream_id = GPOINTER_TO_UINT (user_data);
+
+  g_signal_emit (sctp,
+      webrtc_sctp_transport_signals[ON_STREAM_RESET_SIGNAL], 0, stream_id);
+}
+
+static void
+_on_sctp_dec_pad_removed (GstElement * sctpdec, GstPad * pad,
+    WebRTCSCTPTransport * sctp)
+{
+  guint stream_id;
+
+  if (sscanf (GST_PAD_NAME (pad), "src_%u", &stream_id) != 1)
+    return;
+
+  _sctp_enqueue_task (sctp, (SCTPTask) _emit_stream_reset,
+      GUINT_TO_POINTER (stream_id), NULL);
+}
+
+static void
+_on_sctp_association_established (GstElement * sctpenc, gboolean established,
+    WebRTCSCTPTransport * sctp)
+{
+  GST_OBJECT_LOCK (sctp);
+  if (established)
+    sctp->state = GST_WEBRTC_SCTP_TRANSPORT_STATE_CONNECTED;
+  else
+    sctp->state = GST_WEBRTC_SCTP_TRANSPORT_STATE_CLOSED;
+  sctp->association_established = established;
+  GST_OBJECT_UNLOCK (sctp);
+
+  g_object_notify (G_OBJECT (sctp), "state");
+}
+
+void
+webrtc_sctp_transport_set_priority (WebRTCSCTPTransport * sctp,
+    GstWebRTCPriorityType priority)
+{
+  GstPad *pad;
+
+  pad = gst_element_get_static_pad (sctp->sctpenc, "src");
+  gst_pad_push_event (pad,
+      gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY,
+          gst_structure_new ("GstWebRtcBinUpdateTos", "sctp-priority",
+              GST_TYPE_WEBRTC_PRIORITY_TYPE, priority, NULL)));
+  gst_object_unref (pad);
+}
+
+static void
+webrtc_sctp_transport_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  WebRTCSCTPTransport *sctp = WEBRTC_SCTP_TRANSPORT (object);
+
+  switch (prop_id) {
+    case PROP_TRANSPORT:
+      g_value_set_object (value, sctp->transport);
+      break;
+    case PROP_STATE:
+      g_value_set_enum (value, sctp->state);
+      break;
+    case PROP_MAX_MESSAGE_SIZE:
+      g_value_set_uint64 (value, sctp->max_message_size);
+      break;
+    case PROP_MAX_CHANNELS:
+      g_value_set_uint (value, sctp->max_channels);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+webrtc_sctp_transport_finalize (GObject * object)
+{
+  WebRTCSCTPTransport *sctp = WEBRTC_SCTP_TRANSPORT (object);
+
+  g_signal_handlers_disconnect_by_data (sctp->sctpdec, sctp);
+  g_signal_handlers_disconnect_by_data (sctp->sctpenc, sctp);
+
+  gst_object_unref (sctp->sctpdec);
+  gst_object_unref (sctp->sctpenc);
+
+  g_clear_object (&sctp->transport);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+webrtc_sctp_transport_constructed (GObject * object)
+{
+  WebRTCSCTPTransport *sctp = WEBRTC_SCTP_TRANSPORT (object);
+  guint association_id;
+
+  association_id = g_random_int_range (0, G_MAXUINT16);
+
+  sctp->sctpdec =
+      g_object_ref_sink (gst_element_factory_make ("sctpdec", NULL));
+  g_object_set (sctp->sctpdec, "sctp-association-id", association_id, NULL);
+  sctp->sctpenc =
+      g_object_ref_sink (gst_element_factory_make ("sctpenc", NULL));
+  g_object_set (sctp->sctpenc, "sctp-association-id", association_id, NULL);
+  g_object_set (sctp->sctpenc, "use-sock-stream", TRUE, NULL);
+
+  g_signal_connect (sctp->sctpdec, "pad-removed",
+      G_CALLBACK (_on_sctp_dec_pad_removed), sctp);
+  g_signal_connect (sctp->sctpenc, "sctp-association-established",
+      G_CALLBACK (_on_sctp_association_established), sctp);
+
+  G_OBJECT_CLASS (parent_class)->constructed (object);
+}
+
+static void
+webrtc_sctp_transport_class_init (WebRTCSCTPTransportClass * klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+
+  gobject_class->constructed = webrtc_sctp_transport_constructed;
+  gobject_class->get_property = webrtc_sctp_transport_get_property;
+  gobject_class->finalize = webrtc_sctp_transport_finalize;
+
+  g_object_class_override_property (gobject_class, PROP_TRANSPORT, "transport");
+  g_object_class_override_property (gobject_class, PROP_STATE, "state");
+  g_object_class_override_property (gobject_class,
+      PROP_MAX_MESSAGE_SIZE, "max-message-size");
+  g_object_class_override_property (gobject_class,
+      PROP_MAX_CHANNELS, "max-channels");
+
+  /**
+   * WebRTCSCTPTransport::stream-reset:
+   * @object: the #WebRTCSCTPTransport
+   * @stream_id: the SCTP stream that was reset
+   */
+  webrtc_sctp_transport_signals[ON_STREAM_RESET_SIGNAL] =
+      g_signal_new ("stream-reset", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT);
+}
+
+static void
+webrtc_sctp_transport_init (WebRTCSCTPTransport * nice)
+{
+}
+
+WebRTCSCTPTransport *
+webrtc_sctp_transport_new (void)
+{
+  return g_object_new (TYPE_WEBRTC_SCTP_TRANSPORT, NULL);
+}
diff --git a/ext/webrtc/webrtcsctptransport.h b/ext/webrtc/webrtcsctptransport.h
new file mode 100644 (file)
index 0000000..82a5139
--- /dev/null
@@ -0,0 +1,74 @@
+/* GStreamer
+ * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __WEBRTC_SCTP_TRANSPORT_H__
+#define __WEBRTC_SCTP_TRANSPORT_H__
+
+#include <gst/gst.h>
+#include <gst/webrtc/webrtc.h>
+#include <gst/webrtc/sctptransport.h>
+#include "gstwebrtcice.h"
+
+#include "gst/webrtc/webrtc-priv.h"
+
+G_BEGIN_DECLS
+
+GType webrtc_sctp_transport_get_type(void);
+#define TYPE_WEBRTC_SCTP_TRANSPORT            (webrtc_sctp_transport_get_type())
+#define WEBRTC_SCTP_TRANSPORT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),TYPE_WEBRTC_SCTP_TRANSPORT,WebRTCSCTPTransport))
+#define WEBRTC_IS_SCTP_TRANSPORT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),TYPE_WEBRTC_SCTP_TRANSPORT))
+#define WEBRTC_SCTP_TRANSPORT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,TYPE_WEBRTC_SCTP_TRANSPORT,WebRTCSCTPTransportClass))
+#define WEBRTC_SCTP_IS_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,TYPE_WEBRTC_SCTP_TRANSPORT))
+#define WEBRTC_SCTP_TRANSPORT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,TYPE_WEBRTC_SCTP_TRANSPORT,WebRTCSCTPTransportClass))
+
+typedef struct _WebRTCSCTPTransport WebRTCSCTPTransport;
+typedef struct _WebRTCSCTPTransportClass WebRTCSCTPTransportClass;
+
+struct _WebRTCSCTPTransport
+{
+  GstWebRTCSCTPTransport        parent;
+
+  GstWebRTCDTLSTransport       *transport;
+  GstWebRTCSCTPTransportState   state;
+  guint64                       max_message_size;
+  guint                         max_channels;
+
+  gboolean                      association_established;
+
+  gulong                        sctpdec_block_id;
+  GstElement                   *sctpdec;
+  GstElement                   *sctpenc;
+
+  GstWebRTCBin                 *webrtcbin;
+};
+
+struct _WebRTCSCTPTransportClass
+{
+  GstWebRTCSCTPTransportClass   parent_class;
+};
+
+WebRTCSCTPTransport *           webrtc_sctp_transport_new               (void);
+
+void
+webrtc_sctp_transport_set_priority (WebRTCSCTPTransport *sctp,
+                                    GstWebRTCPriorityType priority);
+
+G_END_DECLS
+
+#endif /* __WEBRTC_SCTP_TRANSPORT_H__ */
index efdba6556c5b7cfa0524faf7285d87352354c0a9..c363828b575721a4fbeeb30eec80dd0dbcc538b1 100644 (file)
@@ -6,6 +6,7 @@ webrtc_sources = [
   'rtpsender.c',
   'rtptransceiver.c',
   'datachannel.c',
+  'sctptransport.c',
 ]
 
 webrtc_headers = [
@@ -18,6 +19,7 @@ webrtc_headers = [
   'datachannel.h',
   'webrtc_fwd.h',
   'webrtc.h',
+  'sctptransport.h',
 ]
 
 webrtc_enumtypes_headers = [
diff --git a/gst-libs/gst/webrtc/sctptransport.c b/gst-libs/gst/webrtc/sctptransport.c
new file mode 100644 (file)
index 0000000..4d0495a
--- /dev/null
@@ -0,0 +1,79 @@
+/* GStreamer
+ * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "sctptransport.h"
+#include "webrtc-priv.h"
+
+G_DEFINE_ABSTRACT_TYPE (GstWebRTCSCTPTransport, gst_webrtc_sctp_transport,
+    GST_TYPE_OBJECT);
+
+static void
+gst_webrtc_sctp_transport_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  /* all properties should by handled by the plugin class */
+  g_assert_not_reached ();
+}
+
+static void
+gst_webrtc_sctp_transport_class_init (GstWebRTCSCTPTransportClass * klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+  guint property_id_dummy = 0;
+
+  gobject_class->get_property = gst_webrtc_sctp_transport_get_property;
+
+  g_object_class_install_property (gobject_class,
+      ++property_id_dummy,
+      g_param_spec_object ("transport",
+          "WebRTC DTLS Transport",
+          "DTLS transport used for this SCTP transport",
+          GST_TYPE_WEBRTC_DTLS_TRANSPORT,
+          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+      ++property_id_dummy,
+      g_param_spec_enum ("state",
+          "WebRTC SCTP Transport state", "WebRTC SCTP Transport state",
+          GST_TYPE_WEBRTC_SCTP_TRANSPORT_STATE,
+          GST_WEBRTC_SCTP_TRANSPORT_STATE_NEW,
+          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+      ++property_id_dummy,
+      g_param_spec_uint64 ("max-message-size",
+          "Maximum message size",
+          "Maximum message size as reported by the transport", 0, G_MAXUINT64,
+          0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class,
+      ++property_id_dummy,
+      g_param_spec_uint ("max-channels",
+          "Maximum number of channels", "Maximum number of channels",
+          0, G_MAXUINT16, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gst_webrtc_sctp_transport_init (GstWebRTCSCTPTransport * nice)
+{
+}
diff --git a/gst-libs/gst/webrtc/sctptransport.h b/gst-libs/gst/webrtc/sctptransport.h
new file mode 100644 (file)
index 0000000..99a46ee
--- /dev/null
@@ -0,0 +1,42 @@
+/* GStreamer
+ * Copyright (C) 2018 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GST_WEBRTC_SCTP_TRANSPORT_H__
+#define __GST_WEBRTC_SCTP_TRANSPORT_H__
+
+#include <gst/gst.h>
+#include <gst/webrtc/webrtc_fwd.h>
+
+G_BEGIN_DECLS
+
+GST_WEBRTC_API
+GType gst_webrtc_sctp_transport_get_type(void);
+
+#define GST_TYPE_WEBRTC_SCTP_TRANSPORT            (gst_webrtc_sctp_transport_get_type())
+#define GST_WEBRTC_SCTP_TRANSPORT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransport))
+#define GST_IS_WEBRTC_SCTP_TRANSPORT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_SCTP_TRANSPORT))
+#define GST_WEBRTC_SCTP_TRANSPORT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransportClass))
+#define GST_IS_WEBRTC_SCTP_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT))
+#define GST_WEBRTC_SCTP_TRANSPORT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_SCTP_TRANSPORT,GstWebRTCSCTPTransportClass))
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstWebRTCSCTPTransport, gst_object_unref)
+
+G_END_DECLS
+
+#endif /* __GST_WEBRTC_SCTP_TRANSPORT_H__ */
index cf8a081c2cb161d581129afdeb37d7cfad759827..7366006b72d130ce1bafb45618bfae8014f9fa7d 100644 (file)
@@ -289,6 +289,27 @@ GST_WEBRTC_API
 void gst_webrtc_data_channel_on_buffered_amount_low (GstWebRTCDataChannel * channel);
 
 
+/**
+ * GstWebRTCSCTPTransport:
+ *
+ * Since: 1.20
+ */
+struct _GstWebRTCSCTPTransport
+{
+  GstObject                     parent;
+};
+
+/**
+ * GstWebRTCSCTPTransportClass:
+ *
+ * Since: 1.20
+ */
+struct _GstWebRTCSCTPTransportClass
+{
+  GstObjectClass                parent_class;
+};
+
+
 G_END_DECLS
 
 #endif /* __GST_WEBRTC_PRIV_H__ */
index f3f9aebb815a5ec6220bd8f3f8966a4b76bb2839..189e7b36c31e7809c54f972b4848069efe6c3552 100644 (file)
@@ -92,6 +92,9 @@ typedef struct _GstWebRTCRTPTransceiverClass GstWebRTCRTPTransceiverClass;
 typedef struct _GstWebRTCDataChannel GstWebRTCDataChannel;
 typedef struct _GstWebRTCDataChannelClass GstWebRTCDataChannelClass;
 
+typedef struct _GstWebRTCSCTPTransport GstWebRTCSCTPTransport;
+typedef struct _GstWebRTCSCTPTransportClass GstWebRTCSCTPTransportClass;
+
 /**
  * GstWebRTCDTLSTransportState:
  * @GST_WEBRTC_DTLS_TRANSPORT_STATE_NEW: new