rtsp-stream: Add functions for using rtsp-stream from the client
authorJan Schmidt <jan@centricular.com>
Mon, 16 Nov 2015 14:12:28 +0000 (01:12 +1100)
committerJan Schmidt <jan@centricular.com>
Thu, 28 Jan 2016 14:44:26 +0000 (01:44 +1100)
Add a boolean to indicate that the rtsp-stream is running on the
'client' side of an RTSP connection, for sending streams via
RECORD. In that case, the roles of the client/server ports
in transport setup are swapped.

https://bugzilla.gnome.org/show_bug.cgi?id=758180

gst/rtsp-server/rtsp-stream.c
gst/rtsp-server/rtsp-stream.h

index 883cbcf..4034a5c 100644 (file)
@@ -80,6 +80,10 @@ struct _GstRTSPStreamPrivate
   GstElement *payloader;
   guint buffer_size;
   gboolean is_joined;
   GstElement *payloader;
   guint buffer_size;
   gboolean is_joined;
+
+  /* TRUE if this stream is running on
+   * the client side of an RTSP link (for RECORD) */
+  gboolean client_side;
   gchar *control;
 
   GstRTSPProfile profiles;
   gchar *control;
 
   GstRTSPProfile profiles;
@@ -1289,6 +1293,54 @@ alloc_ports (GstRTSPStream * stream)
 }
 
 /**
 }
 
 /**
+ * gst_rtsp_stream_set_client_side:
+ * @stream: a #GstRTSPStream
+ * @client_side: TRUE if this #GstRTSPStream is running on the 'client' side of
+ * an RTSP connection.
+ *
+ * Sets the #GstRTSPStream as a 'client side' stream - used for sending
+ * streams to an RTSP server via RECORD. This has the practical effect
+ * of changing which UDP port numbers are used when setting up the local
+ * side of the stream sending to be either the 'server' or 'client' pair
+ * of a configured UDP transport.
+ */
+void
+gst_rtsp_stream_set_client_side (GstRTSPStream * stream, gboolean client_side)
+{
+  GstRTSPStreamPrivate *priv;
+
+  g_return_if_fail (GST_IS_RTSP_STREAM (stream));
+  priv = stream->priv;
+  g_mutex_lock (&priv->lock);
+  priv->client_side = client_side;
+  g_mutex_unlock (&priv->lock);
+}
+
+/**
+ * gst_rtsp_stream_set_client_side:
+ * @stream: a #GstRTSPStream
+ *
+ * See gst_rtsp_stream_set_client_side()
+ *
+ * Returns: TRUE if this #GstRTSPStream is client-side.
+ */
+gboolean
+gst_rtsp_stream_is_client_side (GstRTSPStream * stream)
+{
+  GstRTSPStreamPrivate *priv;
+  gboolean ret;
+
+  g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
+
+  priv = stream->priv;
+  g_mutex_lock (&priv->lock);
+  ret = priv->client_side;
+  g_mutex_unlock (&priv->lock);
+
+  return ret;
+}
+
+/**
  * gst_rtsp_stream_get_server_port:
  * @stream: a #GstRTSPStream
  * @server_port: (out): result server port
  * gst_rtsp_stream_get_server_port:
  * @stream: a #GstRTSPStream
  * @server_port: (out): result server port
@@ -1562,8 +1614,15 @@ find_transport (GstRTSPStream * stream, const gchar * rtcp_from)
 
     tr = gst_rtsp_stream_transport_get_transport (trans);
 
 
     tr = gst_rtsp_stream_transport_get_transport (trans);
 
-    min = tr->client_port.min;
-    max = tr->client_port.max;
+    if (priv->client_side) {
+      /* In client side mode the 'destination' is the RTSP server, so send
+       * to those ports */
+      min = tr->server_port.min;
+      max = tr->server_port.max;
+    } else {
+      min = tr->client_port.min;
+      max = tr->client_port.max;
+    }
 
     if ((strcmp (tr->destination, dest) == 0) && (min == port || max == port)) {
       result = trans;
 
     if ((strcmp (tr->destination, dest) == 0) && (min == port || max == port)) {
       result = trans;
@@ -3001,6 +3060,11 @@ update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
         min = tr->port.min;
         max = tr->port.max;
         ttl = tr->ttl;
         min = tr->port.min;
         max = tr->port.max;
         ttl = tr->ttl;
+      } else if (priv->client_side) {
+        /* In client side mode the 'destination' is the RTSP server, so send
+         * to those ports */
+        min = tr->server_port.min;
+        max = tr->server_port.max;
       } else {
         min = tr->client_port.min;
         max = tr->client_port.max;
       } else {
         min = tr->client_port.min;
         max = tr->client_port.max;
index c045ebd..bd1d7e5 100644 (file)
@@ -112,6 +112,9 @@ gboolean          gst_rtsp_stream_set_blocked      (GstRTSPStream * stream,
                                                     gboolean blocked);
 gboolean          gst_rtsp_stream_is_blocking      (GstRTSPStream * stream);
 
                                                     gboolean blocked);
 gboolean          gst_rtsp_stream_is_blocking      (GstRTSPStream * stream);
 
+void              gst_rtsp_stream_set_client_side (GstRTSPStream *stream, gboolean client_side);
+gboolean          gst_rtsp_stream_is_client_side (GstRTSPStream *stream);
+
 void              gst_rtsp_stream_get_server_port  (GstRTSPStream *stream,
                                                     GstRTSPRange *server_port,
                                                     GSocketFamily family);
 void              gst_rtsp_stream_get_server_port  (GstRTSPStream *stream,
                                                     GstRTSPRange *server_port,
                                                     GSocketFamily family);