sdp: pass multicast connection for multicast-only stream
authorWim Taymans <wtaymans@redhat.com>
Mon, 3 Mar 2014 14:12:55 +0000 (15:12 +0100)
committerWim Taymans <wtaymans@redhat.com>
Mon, 3 Mar 2014 14:12:55 +0000 (15:12 +0100)
Pass the multicast address of the stream in the connection info in the
SDP so that clients try a multicast connection first.
Only allow multicast connections in the test-multicast example. Also
increase the TTL a little.

examples/test-multicast.c
gst/rtsp-server/rtsp-sdp.c

index 6d4234e..c7d55fc 100644 (file)
@@ -70,8 +70,11 @@ main (int argc, char *argv[])
   /* make a new address pool */
   pool = gst_rtsp_address_pool_new ();
   gst_rtsp_address_pool_add_range (pool,
-      "224.3.0.0", "224.3.0.10", 5000, 5010, 1);
+      "224.3.0.0", "224.3.0.10", 5000, 5010, 16);
   gst_rtsp_media_factory_set_address_pool (factory, pool);
+  /* only allow multicast */
+  gst_rtsp_media_factory_set_protocols (factory,
+      GST_RTSP_LOWER_TRANS_UDP_MCAST);
   g_object_unref (pool);
 
   /* attach the test factory to the /test url */
index be94d19..e2e98bc 100644 (file)
@@ -108,6 +108,11 @@ gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
     gboolean first;
     GString *fmtp;
     GstCaps *caps;
+    GstRTSPLowerTrans ltrans;
+    GSocketFamily family;
+    const gchar *addrtype;
+    gchar *address;
+    guint ttl;
 
     stream = gst_rtsp_media_get_stream (media, i);
     caps = gst_rtsp_stream_get_caps (stream);
@@ -138,13 +143,40 @@ gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
     gst_sdp_media_set_port_info (smedia, 0, 1);
     gst_sdp_media_set_proto (smedia, "RTP/AVP");
 
-    /* for the c= line */
     if (info->is_ipv6) {
-      gst_sdp_media_add_connection (smedia, "IN", "IP6", "::", 16, 0);
+      addrtype = "IP6";
+      family = G_SOCKET_FAMILY_IPV6;
+    } else {
+      addrtype = "IP4";
+      family = G_SOCKET_FAMILY_IPV4;
+    }
+
+    ltrans = gst_rtsp_stream_get_protocols (stream);
+    if (ltrans == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
+      GstRTSPAddress *addr;
+
+      addr = gst_rtsp_stream_get_multicast_address (stream, family);
+      if (addr == NULL) {
+        gst_sdp_media_free (smedia);
+        gst_caps_unref (caps);
+        g_warning ("ignoring stream %d without multicast address", i);
+        continue;
+      }
+      address = g_strdup (addr->address);
+      ttl = addr->ttl;
+      gst_rtsp_address_free (addr);
     } else {
-      gst_sdp_media_add_connection (smedia, "IN", "IP4", "0.0.0.0", 16, 0);
+      ttl = 16;
+      if (info->is_ipv6)
+        address = g_strdup ("::");
+      else
+        address = g_strdup ("0.0.0.0");
     }
 
+    /* for the c= line */
+    gst_sdp_media_add_connection (smedia, "IN", addrtype, address, ttl, 1);
+    g_free (address);
+
     /* get clock-rate, media type and params for the rtpmap attribute */
     gst_structure_get_int (s, "clock-rate", &caps_rate);
     caps_enc = gst_structure_get_string (s, "encoding-name");