bad:srtsrc: add "keep-listening" property to avoid EOS on disconnect 85/280285/1
authorStéphane Cerveau <scerveau@collabora.com>
Wed, 19 May 2021 14:03:22 +0000 (16:03 +0200)
committerEunhye Choi <eunhae1.choi@samsung.com>
Fri, 26 Aug 2022 07:37:19 +0000 (16:37 +0900)
The property 'keep-listening' avoids EOS
when the remote client disconnects.

It can be useful to a keep a pipeline alive
when the srt connection drops remotely.

Change-Id: I5dbdc4858ea4bf944dcae021709a0b45fcbe00a8
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/967>

packaging/gstreamer.spec
subprojects/gst-plugins-bad/ext/srt/gstsrtsrc.c
subprojects/gst-plugins-bad/ext/srt/gstsrtsrc.h

index 4ad7a0e..a3add70 100644 (file)
@@ -62,7 +62,7 @@
 
 Name:           %{_name}
 Version:        1.20.0
-Release:        33
+Release:        34
 Summary:        Streaming-Media Framework Runtime
 License:        LGPL-2.0+
 Group:          Multimedia/Framework
index 7c08b20..2cd3c10 100644 (file)
@@ -65,6 +65,11 @@ enum
   LAST_SIGNAL
 };
 
+enum
+{
+  PROP_KEEP_LISTENING = 128
+};
+
 static guint signals[LAST_SIGNAL] = { 0 };
 
 static void gst_srt_src_uri_handler_init (gpointer g_iface,
@@ -151,6 +156,7 @@ gst_srt_src_fill (GstPushSrc * src, GstBuffer * outbuf)
   int64_t srt_time;
   SRT_MSGCTRL mctrl;
 
+retry:
   if (g_cancellable_is_cancelled (self->cancellable)) {
     ret = GST_FLOW_FLUSHING;
   }
@@ -202,8 +208,17 @@ gst_srt_src_fill (GstPushSrc * src, GstBuffer * outbuf)
     g_clear_error (&err);
     goto out;
   } else if (recv_len == 0) {
-    ret = GST_FLOW_EOS;
-    goto out;
+    gst_srt_src_stop (GST_BASE_SRC (self));
+    if (self->keep_listening && gst_srt_src_start (GST_BASE_SRC (self))) {
+      /* FIXME: Should send GAP event(s) downstream */
+      gst_element_post_message (GST_ELEMENT_CAST (self),
+          gst_message_new_element (GST_OBJECT_CAST (self),
+              gst_structure_new_empty ("connection-removed")));
+      goto retry;
+    } else {
+      ret = GST_FLOW_EOS;
+      goto out;
+    }
   }
 
   /* Detect discontinuities */
@@ -311,7 +326,13 @@ gst_srt_src_set_property (GObject * object,
 
   if (!gst_srt_object_set_property_helper (self->srtobject, prop_id, value,
           pspec)) {
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    switch (prop_id) {
+      case PROP_KEEP_LISTENING:
+        self->keep_listening = g_value_get_boolean (value);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
   }
 }
 
@@ -323,7 +344,13 @@ gst_srt_src_get_property (GObject * object,
 
   if (!gst_srt_object_get_property_helper (self->srtobject, prop_id, value,
           pspec)) {
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    switch (prop_id) {
+      case PROP_KEEP_LISTENING:
+        g_value_set_boolean (value, self->keep_listening);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
   }
 }
 
@@ -422,6 +449,22 @@ gst_srt_src_class_init (GstSRTSrcClass * klass)
 
   gst_srt_object_install_properties_helper (gobject_class);
 
+  /**
+   * GstSRTSrc:keep-listening:
+   *
+   * If FALSE, the element will return GST_FLOW_EOS when the remote client disconnects.
+   * If TRUE, the element will keep waiting for the client to reconnect. An element
+   * message named 'connection-removed' will be sent on disconnection.
+   *
+   * Since: 1.22
+   *
+   */
+  g_object_class_install_property (gobject_class, PROP_KEEP_LISTENING,
+      g_param_spec_boolean ("keep-listening",
+          "Keep listening",
+          "Toggle keep-listening for connection reuse",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gst_element_class_add_static_pad_template (gstelement_class, &src_template);
   gst_element_class_set_metadata (gstelement_class,
       "SRT source", "Source/Network",
index 34a5be7..5093c71 100644 (file)
@@ -51,6 +51,7 @@ struct _GstSRTSrc {
   GCancellable *cancellable;
 
   guint32       next_pktseq;
+  gboolean      keep_listening;
 };
 
 struct _GstSRTSrcClass {