]> git.sesse.net Git - vlc/commitdiff
Add SDP generation helper with a bunch of would-be conformance fixes
authorRémi Denis-Courmont <rem@videolan.org>
Fri, 9 Feb 2007 19:15:38 +0000 (19:15 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Fri, 9 Feb 2007 19:15:38 +0000 (19:15 +0000)
(at least: i= is mandatory, TTL notation is forbidden for IPv6)

src/Makefile.am
src/stream_output/sdp.c [new file with mode: 0644]

index 1d4d2315d76832d05024a9729732369c808ce4c5..a1cf8c733fc754fb6a4a9a6c5e2e48eaedd72efb 100644 (file)
@@ -261,6 +261,7 @@ SOURCES_libvlc_common = \
        stream_output/announce.c \
        stream_output/profiles.c \
        stream_output/sap.c \
+       stream_output/sdp.c \
        osd/osd.c \
        osd/osd_parser.c \
        osd/osd_text.c \
diff --git a/src/stream_output/sdp.c b/src/stream_output/sdp.c
new file mode 100644 (file)
index 0000000..5d6dadb
--- /dev/null
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * sdp.c : SDP creation helpers
+ *****************************************************************************
+ * Copyright © 2007 Rémi Denis-Courmont
+ * $Id$
+ *
+ * Authors: Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+# include <vlc/vlc.h>
+
+# include <string.h>
+# include <vlc_network.h>
+# include <vlc_charset.h>
+
+# define MAXSDPADDRESS 47
+
+static
+char *AddressToSDP (const struct sockaddr *addr, socklen_t addrlen, char *buf)
+{
+    const char *ttl = NULL;
+    strcpy (buf, "IN IP* ");
+
+    switch (addr->sa_family)
+    {
+        case AF_INET:
+        {
+            if (net_SockAddrIsMulticast (addr, addrlen))
+                ttl = "/255"; // obsolete in RFC4566, dummy value
+            buf[5] = '4';
+            break;
+        }
+
+#ifdef AF_INET6
+        case AF_INET6:
+            buf[5] = '6';
+            break;
+#endif
+
+        default:
+            return NULL;
+    }
+
+    if (vlc_getnameinfo (addr, addrlen, buf + 4, MAXSDPADDRESS - 4, NULL,
+                         NI_NUMERICHOST))
+        return NULL;
+
+    if (ttl != NULL)
+        strcat (buf, ttl);
+
+    return buf;
+}
+
+
+char *StartSDP (const char *name,
+                const struct sockaddr *orig, socklen_t origlen,
+                const struct sockaddr *addr, socklen_t addrlen)
+{
+    uint64_t t = NTPtime64 ();
+    char *sdp, machine[MAXSDPADDRESS], conn[MAXSDPADDRESS];
+
+    if (strchr (name, '\r') || strchr (name, '\n') || !IsUTF8 (name)
+     || (AddressToSDP ((struct sockaddr *)&orig, origlen, machine) == NULL)
+     || (AddressToSDP ((struct sockaddr *)&addr, addrlen, conn) == NULL))
+        return NULL;
+
+    if (asprintf (&sdp, "v=0\r\n"
+                        "o=- "I64Fu" "I64Fu" %s\r\n"
+                        "s=%s\r\n"
+                        "i=N/A\r\n" // must be there even if useless
+                        // no URL, email and phone here */
+                        "c=%s\r\n"
+                        // bandwidth not specified
+                        "t= 0 0" // one dummy time span
+                        // no repeating
+                        // no time zone adjustment (silly idea anyway)
+                        // no encryption key (deprecated)
+                        "a=tool:"PACKAGE_STRING"\r\n"
+                        "a=recvonly\r\n"
+                        "a=type:broadcast\r\n"
+                        "a=charset:UTF-8\r\n",
+               /* o= */ t, t, machine,
+               /* s= */ name,
+               /* c= */ conn) == -1)
+        return NULL;
+    return sdp;
+}
+