#ifdef HAVE_ZLIB_H
# include <zlib.h>
#endif
+#include <net/if.h>
/************************************************************************
* Macros and definitions
#define SAP_V4_LINK_ADDRESS "224.0.0.255"
#define ADD_SESSION 1
-#define SAP_V6_1 "FF0"
-/* Scope is inserted between them */
-#define SAP_V6_2 "::2:7FFE"
-/* See RFC3513 for list of valid scopes */
-/* FIXME: find a way to listen to link-local scope */
-static const char ipv6_scopes[] = "1456789ABCDE";
-
-
/*****************************************************************************
* Module descriptor
*****************************************************************************/
/* The structure that contains sdp information */
struct sdp_t
{
- char *psz_sdp;
+ const char *psz_sdp;
/* o field */
char username[64];
/* medias (well, we only support one atm) */
unsigned mediac;
- struct sdp_media_t mediav[1];
+ struct sdp_media_t *mediav;
};
struct attribute_t
static inline attribute_t *MakeAttribute (const char *str);
static const char *GetAttribute (attribute_t **tab, unsigned n, const char *name);
static inline void FreeAttribute (attribute_t *a);
+ static const char *FindAttribute (const sdp_t *sdp, unsigned media,
+ const char *name);
static vlc_bool_t IsSameSession( sdp_t *p_sdp1, sdp_t *p_sdp2 );
static int InitSocket( services_discovery_t *p_sd, const char *psz_address, int i_port );
}
if( var_CreateGetInteger( p_sd, "sap-ipv6" ) )
{
- char psz_address[] = SAP_V6_1"0"SAP_V6_2;
- const char *c_scope;
+ char psz_address[NI_MAXNUMERICHOST] = "ff02::2:7ffe%";
+
+ struct if_nameindex *l = if_nameindex ();
+ if (l != NULL)
+ {
+ char *ptr = strchr (psz_address, '%') + 1;
+ for (unsigned i = 0; l[i].if_index; i++)
+ {
+ strcpy (ptr, l[i].if_name);
+ InitSocket (p_sd, psz_address, SAP_PORT);
+ }
+ if_freenameindex (l);
+ }
+ *strchr (psz_address, '%') = '\0';
- for( c_scope = ipv6_scopes; *c_scope; c_scope++ )
+ static const char ipv6_scopes[] = "1456789ABCDE";
+ for (const char *c_scope = ipv6_scopes; *c_scope; c_scope++)
{
- psz_address[sizeof(SAP_V6_1) - 1] = *c_scope;
+ psz_address[3] = *c_scope;
InitSocket( p_sd, psz_address, SAP_PORT );
}
}
int i_read;
uint8_t p_buffer[MAX_SAP_BUFFER+1];
- i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, NULL,
+ i_read = net_Select( p_sd, p_sd->p_sys->pi_fd,
p_sd->p_sys->i_fd, p_buffer,
- MAX_SAP_BUFFER, 500000 );
+ MAX_SAP_BUFFER );
/* Check for items that need deletion */
for( i = 0; i < p_sd->p_sys->i_announces; i++ )
int newsize = Decompress (buf, &decomp, end - buf);
if (newsize < 0)
{
- msg_Warn( p_sd, "decompression of sap packet failed" );
+ msg_Dbg( p_sd, "decompression of SAP packet failed" );
return VLC_EGENERIC;
}
decomp = realloc (decomp, newsize + 1);
decomp[newsize] = '\0';
-
psz_sdp = (const char *)decomp;
len = newsize;
}
if( p_sdp == NULL )
return VLC_EGENERIC;
+ p_sdp->psz_sdp = psz_sdp;
+
/* Decide whether we should add a playlist item for this SDP */
/* Parse connection information (c= & m= ) */
if( ParseConnection( VLC_OBJECT(p_sd), p_sdp ) )
}
/* Handle group */
- psz_value = GetAttribute( p_sap->p_sdp->pp_attributes, p_sap->p_sdp->i_attributes, "x-plgroup" );
- if( psz_value == NULL )
- psz_value = GetAttribute( p_sap->p_sdp->pp_attributes, p_sap->p_sdp->i_attributes, "plgroup" );
+ if (p_sap->p_sdp->mediac >= 1)
+ psz_value = FindAttribute (p_sap->p_sdp, 0, "x-plgroup");
+ else
+ psz_value = GetAttribute( p_sap->p_sdp->pp_attributes, p_sap->p_sdp->i_attributes, "x-plgroup" );
if( psz_value != NULL )
{
}
p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input, p_child,
- PLAYLIST_APPEND, PLAYLIST_END );
+ PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
p_sap->i_item_id_cat = p_item->i_id;
p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input,
- p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
+ p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
+ VLC_FALSE );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
p_sap->i_item_id_one = p_item->i_id;
return p_sap;
}
+
+static const char *FindAttribute (const sdp_t *sdp, unsigned media,
+ const char *name)
+{
+ /* Look for media attribute, and fallback to session */
+ return GetAttribute (sdp->mediav[media].pp_attributes,
+ sdp->mediav[media].i_attributes, name)
+ ?: GetAttribute (sdp->pp_attributes, sdp->i_attributes, name);
+}
+
+
/* Fill p_sdp->psz_uri */
static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
{
- if (p_sdp->mediac != 1)
+ if (p_sdp->mediac == 0)
+ {
+ msg_Dbg (p_obj, "Ignoring SDP with no media");
+ return VLC_EGENERIC;
+ }
+
+ for (unsigned i = 1; i < p_sdp->mediac; i++)
+ {
+ if ((p_sdp->mediav[i].n_addr != p_sdp->mediav->n_addr)
+ || (p_sdp->mediav[i].addrlen != p_sdp->mediav->addrlen)
+ || memcmp (&p_sdp->mediav[i].addr, &p_sdp->mediav->addr,
+ p_sdp->mediav->addrlen))
+ {
+ msg_Dbg (p_obj, "Multiple media ports not supported -> live555");
+ return VLC_EGENERIC;
+ }
+ }
+
+ if (p_sdp->mediav->n_addr != 1)
+ {
+ msg_Dbg (p_obj, "Layered encoding not supported -> live555");
return VLC_EGENERIC;
+ }
char psz_uri[1026];
const char *host;
int port;
psz_uri[0] = '[';
- if (vlc_getnameinfo ((struct sockaddr *)&(p_sdp->mediav[0].addr),
- p_sdp->mediav[0].addrlen, psz_uri + 1,
+ if (vlc_getnameinfo ((struct sockaddr *)&(p_sdp->mediav->addr),
+ p_sdp->mediav->addrlen, psz_uri + 1,
sizeof (psz_uri) - 2, &port, NI_NUMERICHOST))
return VLC_EGENERIC;
return VLC_ENOMEM;
char *subtype = strchr (sdp_proto, ' ');
- if (sdp_proto == NULL)
+ if (subtype == NULL)
{
msg_Dbg (p_obj, "missing SDP media subtype: %s", sdp_proto);
p_sdp->i_media_type = 0;
if (p_sdp->i_media_type == 0)
p_sdp->i_media_type = 33;
+ /* RTP protocol, nul, VLC shortcut, nul, flags byte as follow:
+ * 0x1: Connection-Oriented media. */
static const char proto_match[] =
- "udp\0" "udp\0"
- "RTP/AVP\0" "rtp\0"
- "UDPLite/RTP/AVP\0" "udplite\0"
- "DCCP/RTP/AVP\0" "dccp\0"
- "TCP/RTP/AVP\0" "tcp\0"
+ "udp\0" "udp\0\0"
+ "RTP/AVP\0" "rtp\0\0"
+ "UDPLite/RTP/AVP\0" "udplite\0\0"
+ "DCCP/RTP/AVP\0" "dccp\0\1"
+ "TCP/RTP/AVP\0" "rtptcp\0\1"
"\0";
const char *vlc_proto = NULL;
+ uint8_t flags = 0;
for (const char *proto = proto_match; *proto;)
{
- if (strcasecmp (proto, sdp_proto))
+ if (strcasecmp (proto, sdp_proto) == 0)
{
vlc_proto = proto + strlen (proto) + 1;
+ flags = vlc_proto[strlen (vlc_proto) + 1];
break;
}
proto += strlen (proto) + 1;
- proto += strlen (proto) + 1;
+ proto += strlen (proto) + 2;
}
free (sdp_proto);
return VLC_EGENERIC;
}
- /* handle SSM case */
- const char *sfilter = GetAttribute( p_sdp->mediav[0].pp_attributes,
- p_sdp->mediav[0].i_attributes,
- "source-filter" );
- if (sfilter == NULL)
- sfilter = GetAttribute( p_sdp->pp_attributes, p_sdp->i_attributes,
- "source-filter" );
-
- char psz_source[258] = "";
- if (sfilter != NULL)
+ if (flags & 1)
{
- char psz_source_ip[256];
+ /* Connection-oriented media */
+ const char *setup = FindAttribute (p_sdp, 0, "setup");
+ if (setup == NULL)
+ setup = "active"; /* default value */
- if (sscanf (sfilter, " incl IN IP%*c %*s %255s ", psz_source_ip) == 1)
+ if (strcmp (setup, "actpass") && strcmp (setup, "passive"))
{
- if (strchr (psz_source_ip, ':') != NULL)
- sprintf (psz_source, "[%s]", psz_source_ip);
- else
- strcpy (psz_source, psz_source_ip);
+ msg_Dbg (p_obj, "unsupported COMEDIA mode: %s", setup);
+ return VLC_EGENERIC;
}
+
+ if (asprintf (&p_sdp->psz_uri, "%s://%s:%d", vlc_proto,
+ host, port) == -1)
+ return VLC_ENOMEM;
}
+ else
+ {
+ /* Non-connected (normally multicast) media */
+
+ char psz_source[258] = "";
+ const char *sfilter = FindAttribute (p_sdp, 0, "source-filter");
+ if (sfilter != NULL)
+ {
+ char psz_source_ip[256];
+ unsigned ipv;
+
+ if (sscanf (sfilter, " incl IN IP%u %*s %255s ", &ipv,
+ psz_source_ip) == 2)
+ {
+ /* According to RFC4570, FQDNs can be used for source-filters,
+ * but -seriously- this is impractical */
+ switch (ipv)
+ {
+#ifdef AF_INET6
+ case 6:
+ {
+ struct in6_addr addr;
+ if ((inet_pton (AF_INET6, psz_source_ip, &addr) > 0)
+ && (inet_ntop (AF_INET6, &addr, psz_source + 1,
+ sizeof (psz_source) - 2) != NULL))
+ {
+ psz_source[0] = '[';
+ psz_source[strlen (psz_source)] = ']';
+ }
+ break;
+ }
+#endif
+ case 4:
+ {
+ struct in_addr addr;
+ if ((inet_pton (AF_INET, psz_source_ip, &addr) > 0)
+ && (inet_ntop (AF_INET, &addr, psz_source,
+ sizeof (psz_source)) == NULL))
+ *psz_source = '\0';
+ break;
+ }
+ }
+ }
+ }
- asprintf( &p_sdp->psz_uri, "%s://%s@%s:%i", vlc_proto, psz_source,
- host, port );
+ if (asprintf (&p_sdp->psz_uri, "%s://%s@%s:%i", vlc_proto, psz_source,
+ host, port) == -1)
+ return VLC_ENOMEM;
+ }
return VLC_SUCCESS;
}
memset (&glob_addr, 0, sizeof (glob_addr));
socklen_t glob_len = 0;
unsigned glob_count = 1;
+ int port = 0;
/* TODO: use iconv and charset attribute instead of EnsureUTF8 */
while (*psz_sdp)
/* Media description */
case 'm':
+ media:
{
expect = 'i';
if (cat != 'm')
msg_Dbg (p_obj, "missing SDP media description");
goto error;
}
- struct sdp_media_t *m = p_sdp->mediav + p_sdp->mediac;
+ struct sdp_media_t *m;
+ m = realloc (p_sdp->mediav, (p_sdp->mediac + 1) * sizeof (*m));
+ if (m == NULL)
+ goto error;
+
+ p_sdp->mediav = m;
+ m += p_sdp->mediac;
+ p_sdp->mediac++;
+ memset (m, 0, sizeof (*m));
memcpy (&m->addr, &glob_addr, m->addrlen = glob_len);
m->n_addr = glob_count;
msg_Dbg (p_obj, "missing SDP media port");
goto error;
}
- int port = atoi (++data);
+ port = atoi (++data);
if (port <= 0 || port >= 65536)
{
msg_Dbg (p_obj, "invalid transport port %d", port);
if (m->fmt == NULL)
goto error;
- p_sdp->mediac++;
break;
}
case 'i':
expect = 'b';
if (cat == 'c')
{
- struct sdp_media_t *m = p_sdp->mediav + p_sdp->mediac;
+ struct sdp_media_t *m = p_sdp->mediav + p_sdp->mediac - 1;
if (ParseSDPConnection (data, &m->addr, &m->addrlen,
&m->n_addr))
{
"%s", data);
goto error;
}
+ net_SetPort ((struct sockaddr *)&m->addr, htons (port));
break;
}
case 'b':
}
if (cat == 'm')
- {
- /* TODO */
- msg_Dbg (p_obj, "multi-media SDP not implemented -> live555");
- goto error;
- }
+ goto media;
if (cat != 'm')
{
if (i_fd == -1)
return VLC_EGENERIC;
- net_StopSend( i_fd );
+ shutdown( i_fd, SHUT_WR );
INSERT_ELEM (p_sd->p_sys->pi_fd, p_sd->p_sys->i_fd,
p_sd->p_sys->i_fd, i_fd);
return VLC_SUCCESS;
static void FreeSDP( sdp_t *p_sdp )
{
- FREENULL( p_sdp->psz_sdp );
- FREENULL( p_sdp->psz_sessionname );
- FREENULL( p_sdp->psz_uri );
+ free( p_sdp->psz_sessionname );
+ free( p_sdp->psz_uri );
for (unsigned j = 0; j < p_sdp->mediac; j++)
{
free (p_sdp->mediav[j].fmt);
for (int i = 0; i < p_sdp->mediav[j].i_attributes; i++)
FreeAttribute (p_sdp->mediav[j].pp_attributes[i]);
+ free (p_sdp->mediav[j].pp_attributes);
}
+ free (p_sdp->mediav);
for (int i = 0; i < p_sdp->i_attributes; i++)
FreeAttribute (p_sdp->pp_attributes[i]);