* Copyright © 2007 Rémi Denis-Courmont
* $Id$
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser 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.
+ * You should have received a copy of the GNU Lesser 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>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
}
-static vlc_bool_t IsSDPString (const char *str)
+static bool IsSDPString (const char *str)
{
if (strchr (str, '\r') != NULL)
- return VLC_FALSE;
+ return false;
if (strchr (str, '\n') != NULL)
- return VLC_FALSE;
+ return false;
if (!IsUTF8 (str))
- return VLC_FALSE;
- return VLC_TRUE;
+ return false;
+ return true;
}
+static
char *sdp_Start (const char *name, const char *description, const char *url,
- const char *email, const char *phone,
- const struct sockaddr *src, socklen_t srclen,
- const struct sockaddr *addr, socklen_t addrlen)
+ const char *email, const char *phone,
+ const struct sockaddr *src, size_t srclen,
+ const struct sockaddr *addr, size_t addrlen)
{
uint64_t now = NTPtime64 ();
char *sdp;
}
if (asprintf (&sdp, "v=0"
- "\r\no=- "I64Fu" "I64Fu" IN IP%c %s"
+ "\r\no=- %"PRIu64" %"PRIu64" IN IP%c %s"
"\r\ns=%s"
"\r\ni=%s"
"%s%s" // optional URL
char *sdp_AddMedia (char **sdp,
const char *type, const char *protocol, int dport,
- unsigned pt, vlc_bool_t bw_indep, unsigned bw,
- const char *rtpmap, const char *fmtp)
+ unsigned pt, bool bw_indep, unsigned bw,
+ const char *ptname, unsigned clock, unsigned chans,
+ const char *fmtp)
{
char *newsdp, *ptr;
size_t inlen = strlen (*sdp), outlen = inlen;
ptr += sprintf (ptr, "b=RR:0\r\n");
/* RTP payload type map */
- if (rtpmap != NULL)
- sdp_AddAttribute (sdp, "rtpmap", "%u %s", pt, rtpmap);
+ if (ptname != NULL)
+ {
+ if ((strcmp (type, "audio") == 0) && (chans != 1))
+ sdp_AddAttribute (sdp, "rtpmap", "%u %s/%u/%u", pt, ptname, clock,
+ chans);
+ else
+ sdp_AddAttribute (sdp, "rtpmap", "%u %s/%u", pt, ptname, clock);
+ }
/* Format parameters */
if (fmtp != NULL)
sdp_AddAttribute (sdp, "fmtp", "%u %s", pt, fmtp);
return newsdp;
}
+
+
+char *vlc_sdp_Start (vlc_object_t *obj, const char *cfgpref,
+ const struct sockaddr *src, size_t srclen,
+ const struct sockaddr *addr, size_t addrlen)
+{
+ size_t cfglen = strlen (cfgpref);
+ if (cfglen > 100)
+ return NULL;
+
+ char varname[cfglen + sizeof ("description")], *subvar = varname + cfglen;
+ strcpy (varname, cfgpref);
+
+ strcpy (subvar, "name");
+ char *name = var_GetNonEmptyString (obj, varname);
+ strcpy (subvar, "description");
+ char *description = var_GetNonEmptyString (obj, varname);
+ strcpy (subvar, "url");
+ char *url = var_GetNonEmptyString (obj, varname);
+ strcpy (subvar, "email");
+ char *email = var_GetNonEmptyString (obj, varname);
+ strcpy (subvar, "phone");
+ char *phone = var_GetNonEmptyString (obj, varname);
+
+ char *sdp = sdp_Start (name, description, url, email, phone,
+ src, srclen, addr, addrlen);
+ free (name);
+ free (description);
+ free (url);
+ free (email);
+ free (phone);
+
+ if (sdp == NULL)
+ return NULL;
+
+ strcpy (subvar, "cat");
+ char *cat = var_GetNonEmptyString (obj, varname);
+ if (cat != NULL)
+ {
+ sdp_AddAttribute (&sdp, "cat", "%s", cat);
+ /* Totally non-standard */
+ sdp_AddAttribute (&sdp, "x-plgroup", "%s", cat);
+ free (cat);
+ }
+
+ return sdp;
+}