Commit 861ef85c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Big SAP/announce cleanup

plus several minor bugfixes in SAP announce

OTOH, SAP is currently broken for standard output (and untested for RTP)
parent 4c858d7e
...@@ -209,28 +209,14 @@ static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, blo ...@@ -209,28 +209,14 @@ static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, blo
/**************************************************************************** /****************************************************************************
* Announce handler mess * Announce handler mess
****************************************************************************/ ****************************************************************************/
struct sap_session_t;
struct session_descriptor_t
{
char *psz_name;
char *psz_uri;
int i_port;
int i_payload; /* SAP Payload type */
char *psz_group;
char *psz_sdp;
vlc_bool_t b_rtp;
};
VLC_EXPORT( int, sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) ); VLC_EXPORT( int, sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,const char *, const char *, announce_method_t* ) ); VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *, const char *, const char *, const char *, announce_method_t* ) );
VLC_EXPORT( int, sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) ); VLC_EXPORT( int, sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) ); VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (vlc_object_t *obj, const char *cfgpref) );
VLC_EXPORT(void, sout_AnnounceSessionDestroy, (session_descriptor_t *) ); VLC_EXPORT(void, sout_AnnounceSessionDestroy, (session_descriptor_t *) );
VLC_EXPORT(announce_method_t*, sout_SAPMethod, (void) ); VLC_EXPORT(announce_method_t*, sout_SAPMethod, (void) );
VLC_EXPORT(void, sout_MethodRelease, (announce_method_t *) );
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -399,7 +399,7 @@ static int Write( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -399,7 +399,7 @@ static int Write( sout_access_out_t *p_access, block_t *p_buffer )
int i_payload_size = p_sys->i_mtu; int i_payload_size = p_sys->i_mtu;
if( p_sys->b_rtpts ) if( p_sys->b_rtpts )
i_payload_size -= RTP_HEADER_LENGTH; i_payload_size -= RTP_HEADER_LENGTH;
int i_write = __MIN( p_buffer->i_buffer, i_payload_size ); int i_write = __MIN( p_buffer->i_buffer, i_payload_size );
i_packets++; i_packets++;
......
...@@ -1545,12 +1545,13 @@ static int SapSetup( sout_stream_t *p_stream ) ...@@ -1545,12 +1545,13 @@ static int SapSetup( sout_stream_t *p_stream )
if( ( p_sys->i_es > 0 || p_sys->p_mux ) && p_sys->psz_sdp && *p_sys->psz_sdp ) if( ( p_sys->i_es > 0 || p_sys->p_mux ) && p_sys->psz_sdp && *p_sys->psz_sdp )
{ {
p_sys->p_session = sout_AnnounceRegisterSDP( p_sout, p_sys->psz_sdp, p_sys->p_session = sout_AnnounceRegisterSDP( p_sout, SOUT_CFG_PREFIX,
p_sys->psz_sdp,
p_sys->psz_destination, p_sys->psz_destination,
p_method ); p_method );
} }
free( p_method ); sout_MethodRelease( p_method );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -58,6 +58,25 @@ ...@@ -58,6 +58,25 @@
"This allows you to specify a group for the session, that will be announced "\ "This allows you to specify a group for the session, that will be announced "\
"if you choose to use SAP." ) "if you choose to use SAP." )
#define DESC_TEXT N_("Session descriptipn")
#define DESC_LONGTEXT N_( \
"This allows you to give a short description with details about the stream, " \
"that will be announced in the SDP (Session Descriptor)." )
#define URL_TEXT N_("Session URL")
#define URL_LONGTEXT N_( \
"This allows you to give an URL with more details about the stream " \
"(often the website of the streaming organization), that will " \
"be announced in the SDP (Session Descriptor)." )
#define EMAIL_TEXT N_("Session email")
#define EMAIL_LONGTEXT N_( \
"This allows you to give a contact mail address for the stream, that will " \
"be announced in the SDP (Session Descriptor)." )
#define PHONE_TEXT N_("Session phone number")
#define PHONE_LONGTEXT N_( \
"This allows you to give a contact telephone number for the stream, that will " \
"be announced in the SDP (Session Descriptor)." )
#define SAP_TEXT N_("SAP announcing") #define SAP_TEXT N_("SAP announcing")
#define SAP_LONGTEXT N_("Announce this session with SAP.") #define SAP_LONGTEXT N_("Announce this session with SAP.")
...@@ -81,13 +100,20 @@ vlc_module_begin(); ...@@ -81,13 +100,20 @@ vlc_module_begin();
MUX_LONGTEXT, VLC_FALSE ); MUX_LONGTEXT, VLC_FALSE );
add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT, add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
DST_LONGTEXT, VLC_FALSE ); DST_LONGTEXT, VLC_FALSE );
add_deprecated( SOUT_CFG_PREFIX "url", VLC_FALSE );
add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE ); add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE );
add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT, add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT,
VLC_TRUE ); VLC_TRUE );
add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT, add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT,
VLC_TRUE ); VLC_TRUE );
add_string( SOUT_CFG_PREFIX "description", "", NULL, DESC_TEXT, DESC_LONGTEXT,
VLC_TRUE );
add_string( SOUT_CFG_PREFIX "url", "", NULL, URL_TEXT, URL_LONGTEXT,
VLC_TRUE );
add_string( SOUT_CFG_PREFIX "email", "", NULL, EMAIL_TEXT, EMAIL_LONGTEXT,
VLC_TRUE );
add_string( SOUT_CFG_PREFIX "phone", "", NULL, PHONE_TEXT, PHONE_LONGTEXT,
VLC_TRUE );
add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" ); add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" );
set_callbacks( Open, Close ); set_callbacks( Open, Close );
...@@ -99,7 +125,7 @@ vlc_module_end(); ...@@ -99,7 +125,7 @@ vlc_module_end();
*****************************************************************************/ *****************************************************************************/
static const char *ppsz_sout_options[] = { static const char *ppsz_sout_options[] = {
"access", "mux", "url", "dst", "access", "mux", "url", "dst",
"sap", "name", "group", NULL "sap", "name", "group", "description", "url", "email", "phone", NULL
}; };
#define DEFAULT_PORT 1234 #define DEFAULT_PORT 1234
...@@ -310,29 +336,14 @@ static int Open( vlc_object_t *p_this ) ...@@ -310,29 +336,14 @@ static int Open( vlc_object_t *p_this )
} }
msg_Dbg( p_stream, "mux opened" ); msg_Dbg( p_stream, "mux opened" );
/* *** Create the SAP Session structure *** */ /* *** Create the SAP Session structure *** */
var_Get( p_stream, SOUT_CFG_PREFIX "sap", &val ); if( var_GetBool( p_stream, SOUT_CFG_PREFIX"sap" ) &&
if( val.b_bool && ( strncmp( psz_access, "udp", 3 ) || strncmp( psz_access , "rtp", 3 ) ) )
( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
{ {
session_descriptor_t *p_session = sout_AnnounceSessionCreate(); session_descriptor_t *p_session;
announce_method_t *p_method = sout_SAPMethod(); announce_method_t *p_method = sout_SAPMethod ();
vlc_url_t url; vlc_url_t url;
p_session = sout_AnnounceSessionCreate (VLC_OBJECT (p_stream), SOUT_CFG_PREFIX);
var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
if( *val.psz_string )
p_session->psz_name = val.psz_string;
else
{
p_session->psz_name = strdup( psz_url );
free( val.psz_string );
}
var_Get( p_stream, SOUT_CFG_PREFIX "group", &val );
if( *val.psz_string )
p_session->psz_group = val.psz_string;
else
free( val.psz_string );
/* Now, parse the URL to extract host and port */ /* Now, parse the URL to extract host and port */
vlc_UrlParse( &url, psz_url , 0); vlc_UrlParse( &url, psz_url , 0);
...@@ -341,20 +352,20 @@ static int Open( vlc_object_t *p_this ) ...@@ -341,20 +352,20 @@ static int Open( vlc_object_t *p_this )
{ {
if( url.i_port == 0 ) url.i_port = DEFAULT_PORT; if( url.i_port == 0 ) url.i_port = DEFAULT_PORT;
#if 0
p_session->psz_uri = strdup( url.psz_host ); p_session->psz_uri = strdup( url.psz_host );
p_session->i_port = url.i_port; p_session->i_port = url.i_port;
p_session->psz_sdp = NULL; p_session->psz_sdp = NULL;
p_session->i_payload = 33; p_session->i_payload = 33;
p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0; p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0;
#endif
msg_Info( p_this, "SAP Enabled"); msg_Info( p_this, "SAP Enabled");
sout_AnnounceRegister( p_sout, p_session, p_method ); sout_AnnounceRegister( p_sout, p_session, p_method );
p_stream->p_sys->p_session = p_session; p_stream->p_sys->p_session = p_session;
} }
vlc_UrlClean( &url ); vlc_UrlClean( &url );
sout_MethodRelease (p_method);
free( p_method );
} }
p_stream->pf_add = Add; p_stream->pf_add = Add;
......
...@@ -27,9 +27,11 @@ ...@@ -27,9 +27,11 @@
#include <stdlib.h> /* free() */ #include <stdlib.h> /* free() */
#include <stdio.h> /* sprintf() */ #include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */ #include <string.h> /* strerror() */
#include <assert.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_sout.h> #include <vlc_sout.h>
#include <vlc_network.h> /* FIXME: fix RegisterSDP() and remove this */
#include "stream_output.h" #include "stream_output.h"
struct announce_method_t struct announce_method_t
...@@ -82,11 +84,12 @@ int sout_AnnounceRegister( sout_instance_t *p_sout, ...@@ -82,11 +84,12 @@ int sout_AnnounceRegister( sout_instance_t *p_sout,
* *
* \param p_sout a sout instance structure * \param p_sout a sout instance structure
* \param psz_sdp the SDP to register * \param psz_sdp the SDP to register
* \param psz_uri session URI (needed for SAP address auto detection * \param psz_uri session address (needed for SAP address auto detection)
* \param p_method an announce method descriptor * \param p_method an announce method descriptor
* \return the new session descriptor structure * \return the new session descriptor structure
*/ */
session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout, session_descriptor_t *
sout_AnnounceRegisterSDP( sout_instance_t *p_sout, const char *cfgpref,
const char *psz_sdp, const char *psz_uri, const char *psz_sdp, const char *psz_uri,
announce_method_t *p_method ) announce_method_t *p_method )
{ {
...@@ -107,9 +110,19 @@ session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout, ...@@ -107,9 +110,19 @@ session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout,
vlc_object_yield( p_announce ); vlc_object_yield( p_announce );
} }
p_session = sout_AnnounceSessionCreate(); p_session = sout_AnnounceSessionCreate(VLC_OBJECT (p_sout), cfgpref);
p_session->psz_sdp = strdup( psz_sdp ); p_session->psz_sdp = strdup( psz_sdp );
p_session->psz_uri = strdup( psz_uri );
/* GRUIK. We should not convert back-and-forth from string to numbers */
struct addrinfo *res;
if (vlc_getaddrinfo (VLC_OBJECT (p_sout), psz_uri, 0, NULL, &res) == 0)
{
if (res->ai_addrlen <= sizeof (p_session->addr))
memcpy (&p_session->addr, res->ai_addr,
p_session->addrlen = res->ai_addrlen);
freeaddrinfo (res);
}
announce_Register( p_announce, p_session, p_method ); announce_Register( p_announce, p_session, p_method );
vlc_object_release( p_announce ); vlc_object_release( p_announce );
...@@ -148,15 +161,34 @@ int sout_AnnounceUnRegister( sout_instance_t *p_sout, ...@@ -148,15 +161,34 @@ int sout_AnnounceUnRegister( sout_instance_t *p_sout,
* *
* \return a new session descriptor * \return a new session descriptor
*/ */
session_descriptor_t * sout_AnnounceSessionCreate(void) session_descriptor_t * sout_AnnounceSessionCreate (vlc_object_t *obj,
const char *cfgpref)
{ {
session_descriptor_t *p_session; size_t cfglen = strlen (cfgpref);
if (cfglen > 100)
return NULL;
char varname[cfglen + sizeof ("description")], *subvar = varname + cfglen;
strcpy (varname, cfgpref);
p_session = (session_descriptor_t *)malloc( sizeof(session_descriptor_t)); session_descriptor_t *p_session = calloc (1, sizeof (*p_session));
if (p_session == NULL) if (p_session == NULL)
return NULL; return NULL;
memset (p_session, 0, sizeof (*p_session)); strcpy (subvar, "name");
p_session->psz_name = var_GetNonEmptyString (obj, varname);
strcpy (subvar, "group");
p_session->psz_group = var_GetNonEmptyString (obj, varname);
strcpy (subvar, "description");
p_session->description = var_GetNonEmptyString (obj, varname);
strcpy (subvar, "url");
p_session->url = var_GetNonEmptyString (obj, varname);
strcpy (subvar, "email");
p_session->email = var_GetNonEmptyString (obj, varname);
strcpy (subvar, "phone");
p_session->phone = var_GetNonEmptyString (obj, varname);
return p_session; return p_session;
} }
...@@ -170,10 +202,13 @@ void sout_AnnounceSessionDestroy( session_descriptor_t *p_session ) ...@@ -170,10 +202,13 @@ void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
{ {
if( p_session ) if( p_session )
{ {
FREENULL( p_session->psz_name ); free (p_session->psz_name);
FREENULL( p_session->psz_group ); free (p_session->psz_group);
FREENULL( p_session->psz_uri ); free (p_session->psz_sdp);
FREENULL( p_session->psz_sdp ); free (p_session->description);
free (p_session->url);
free (p_session->email);
free (p_session->phone);
free( p_session ); free( p_session );
} }
} }
...@@ -186,6 +221,11 @@ announce_method_t * sout_SAPMethod (void) ...@@ -186,6 +221,11 @@ announce_method_t * sout_SAPMethod (void)
return &sap_method; return &sap_method;
} }
void sout_MethodRelease (announce_method_t *m)
{
assert (m == &sap_method);
}
/************************************************************************ /************************************************************************
* Announce handler functions (private) * Announce handler functions (private)
************************************************************************/ ************************************************************************/
...@@ -241,6 +281,8 @@ int announce_Register( announce_handler_t *p_announce, ...@@ -241,6 +281,8 @@ int announce_Register( announce_handler_t *p_announce,
session_descriptor_t *p_session, session_descriptor_t *p_session,
announce_method_t *p_method ) announce_method_t *p_method )
{ {
if (p_method == NULL)
return VLC_EGENERIC;
msg_Dbg( p_announce, "registering announce"); msg_Dbg( p_announce, "registering announce");
if( p_method == &sap_method ) if( p_method == &sap_method )
......
...@@ -59,7 +59,8 @@ ...@@ -59,7 +59,8 @@
struct sap_address_t struct sap_address_t
{ {
char *psz_address; char *psz_address;
char psz_machine[NI_MAXNUMERICHOST]; struct sockaddr_storage orig;
socklen_t origlen;
int i_rfd; /* Read socket */ int i_rfd; /* Read socket */
int i_wfd; /* Write socket */ int i_wfd; /* Write socket */
...@@ -74,7 +75,6 @@ struct sap_address_t ...@@ -74,7 +75,6 @@ struct sap_address_t
/* A SAP session descriptor, enqueued in the SAP handler queue */ /* A SAP session descriptor, enqueued in the SAP handler queue */
struct sap_session_t { struct sap_session_t {
char *psz_sdp;
uint8_t *psz_data; uint8_t *psz_data;
unsigned i_length; unsigned i_length;
sap_address_t *p_address; sap_address_t *p_address;
...@@ -160,7 +160,6 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap ) ...@@ -160,7 +160,6 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
for( i = 0 ; i< p_sap->i_sessions ; i++) for( i = 0 ; i< p_sap->i_sessions ; i++)
{ {
sap_session_t *p_session = p_sap->pp_sessions[i]; sap_session_t *p_session = p_sap->pp_sessions[i];
FREENULL( p_session->psz_sdp );
FREENULL( p_session->psz_data ); FREENULL( p_session->psz_data );
REMOVE_ELEM( p_sap->pp_sessions, p_sap->i_sessions , i ); REMOVE_ELEM( p_sap->pp_sessions, p_sap->i_sessions , i );
FREENULL( p_session ); FREENULL( p_session );
...@@ -247,53 +246,27 @@ static void RunThread( vlc_object_t *p_this) ...@@ -247,53 +246,27 @@ static void RunThread( vlc_object_t *p_this)
static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
session_descriptor_t *p_session ) session_descriptor_t *p_session )
{ {
int i_header_size, i; int i;
char *psz_head, psz_addr[NI_MAXNUMERICHOST]; char psz_addr[NI_MAXNUMERICHOST];
vlc_bool_t b_ipv6 = VLC_FALSE, b_ssm = VLC_FALSE; vlc_bool_t b_ipv6 = VLC_FALSE, b_ssm = VLC_FALSE;
sap_session_t *p_sap_session; sap_session_t *p_sap_session;
mtime_t i_hash; mtime_t i_hash;
struct addrinfo hints, *res;
struct sockaddr_storage addr; struct sockaddr_storage addr;
socklen_t addrlen; socklen_t addrlen;
vlc_mutex_lock( &p_sap->object_lock ); vlc_mutex_lock( &p_sap->object_lock );
addrlen = p_session->addrlen;
if( p_session->psz_uri == NULL ) if ((addrlen == 0) || (addrlen > sizeof (addr)))
{
vlc_mutex_unlock( &p_sap->object_lock );
msg_Err( p_sap, "*FIXME* unexpected NULL URI for SAP announce" );
msg_Err( p_sap, "This should not happen. VLC needs fixing." );
return VLC_EGENERIC;
}
/* Determine SAP multicast address automatically */
memset( &hints, 0, sizeof( hints ) );
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_NUMERICHOST;
i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0,
&hints, &res );
if( i )
{ {
vlc_mutex_unlock( &p_sap->object_lock ); vlc_mutex_unlock( &p_sap->object_lock );
msg_Err( p_sap, "Invalid URI for SAP announce: %s: %s", msg_Err( p_sap, "No/invalid address specified for SAP announce" );
p_session->psz_uri, vlc_gai_strerror( i ) );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
addrlen = res->ai_addrlen; /* Determine SAP multicast address automatically */
if ((unsigned)addrlen > sizeof (addr)) memcpy (&addr, &p_session->addr, addrlen);
{
vlc_mutex_unlock( &p_sap->object_lock );
vlc_freeaddrinfo( res );
msg_Err( p_sap, "Unsupported address family of size %d > %u",
res->ai_addrlen, (unsigned) sizeof( addr ) );
return VLC_EGENERIC;
}
memcpy (&addr, res->ai_addr, addrlen);
vlc_freeaddrinfo (res);
switch( addr.ss_family ) switch( p_session->addr.ss_family )
{ {
#if defined (HAVE_INET_PTON) || defined (WIN32) #if defined (HAVE_INET_PTON) || defined (WIN32)
case AF_INET6: case AF_INET6:
...@@ -348,10 +321,11 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -348,10 +321,11 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
ipv4 = 0xe0027ffe; ipv4 = 0xe0027ffe;
} }
/* FIXME FIXME FIXME */
if( ipv4 == 0 ) if( ipv4 == 0 )
{ {
msg_Err( p_sap, "Out-of-scope multicast address " msg_Err( p_sap, "Out-of-scope multicast address "
"not supported by SAP: %s", p_session->psz_uri ); "not supported by SAP" );
vlc_mutex_unlock( &p_sap->object_lock ); vlc_mutex_unlock( &p_sap->object_lock );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -400,23 +374,16 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -400,23 +374,16 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
malloc( sizeof(sap_address_t) ); malloc( sizeof(sap_address_t) );
if( !p_address ) if( !p_address )
{ {
msg_Err( p_sap, "out of memory" ); vlc_mutex_unlock( &p_sap->object_lock );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
p_address->psz_address = strdup( psz_addr ); p_address->psz_address = strdup( psz_addr );
p_address->i_wfd = net_ConnectUDP( VLC_OBJECT(p_sap), psz_addr, SAP_PORT, 255 ); p_address->i_wfd = net_ConnectUDP( VLC_OBJECT(p_sap), psz_addr, SAP_PORT, 255 );
if( p_address->i_wfd != -1 ) if( p_address->i_wfd != -1 )
{ {
char *ptr;
net_StopRecv( p_address->i_wfd ); net_StopRecv( p_address->i_wfd );
net_GetSockAddress( p_address->i_wfd, p_address->psz_machine, getsockname (p_address->i_wfd, (struct sockaddr *)&p_address->orig,
NULL ); &p_address->origlen);
/* removes scope if present */
ptr = strchr( p_address->psz_machine, '%' );
if( ptr != NULL )
*ptr = '\0';
} }
if( p_sap->b_control == VLC_TRUE ) if( p_sap->b_control == VLC_TRUE )
...@@ -452,41 +419,28 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -452,41 +419,28 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
p_sap_session->p_address = p_address; p_sap_session->p_address = p_address;
} }
if (p_session->origlen == 0)
memcpy (&p_session->orig, &p_sap_session->p_address->orig,
p_session->origlen = p_sap_session->p_address->origlen);
/* Build the SAP Headers */ size_t headsize = 20;
i_header_size = ( b_ipv6 ? 16 : 4 ) + 20; switch (p_session->orig.ss_family)
psz_head = (char *) malloc( i_header_size * sizeof( char ) );
if( psz_head == NULL )
{
msg_Err( p_sap, "out of memory" );
return VLC_ENOMEM;
}
/* SAPv1, not encrypted, not compressed */
psz_head[0] = b_ipv6 ? 0x30 : 0x20;
psz_head[1] = 0x00; /* No authentification length */
i_hash = mdate();
psz_head[2] = (i_hash & 0xFF00) >> 8; /* Msg id hash */
psz_head[3] = (i_hash & 0xFF); /* Msg id hash 2 */
#if defined (HAVE_INET_PTON) || defined (WIN32)
if( b_ipv6 )
{ {
inet_pton( AF_INET6, /* can't fail */ #ifdef AF_INET6
p_sap_session->p_address->psz_machine, case AF_INET6:
psz_head + 4 ); headsize += 16;
} break;
else
#endif #endif
{ case AF_INET:
inet_pton( AF_INET, /* can't fail */ headsize =+ 4;
p_sap_session->p_address->psz_machine, break;
psz_head + 4 ); default:
msg_Err( p_sap, "Address family %d not supported by SAP",
addr.ss_family );
vlc_mutex_unlock( &p_sap->object_lock );
return VLC_EGENERIC;
} }
memcpy( psz_head + (b_ipv6 ? 20 : 8), "application/sdp", 15 );
/* If needed, build the SDP */ /* If needed, build the SDP */
if( p_session->psz_sdp == NULL ) if( p_session->psz_sdp == NULL )
{ {
...@@ -499,21 +453,57 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, ...@@ -499,21 +453,57 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
} }
} }
p_sap_session->psz_sdp = strdup( p_session->psz_sdp );
p_sap_session->i_last = 0; p_sap_session->i_last = 0;
p_sap_session->i_length = headsize + strlen (p_session->psz_sdp);
p_sap_session->psz_data = malloc (p_sap_session->i_length + 1);
if (p_sap_session->psz_data == NULL)
{
free (p_session->psz_sdp);
vlc_mutex_unlock( &p_sap->object_lock );
return VLC_ENOMEM;
}
psz_head[ i_header_size-1 ] = '\0'; /* Build the SAP Headers */
p_sap_session->i_length = i_header_size + strlen( p_sap_session->psz_sdp); uint8_t *psz_head = p_sap_session->psz_data;
p_sap_session->psz_data = (uint8_t *)malloc( sizeof(char)* /* SAPv1, not encrypted, not compressed */
p_sap_session->i_length ); psz_head[0] = 0x20;
psz_head[1] = 0x00; /* No authentification length */
/* Build the final message */ i_hash = mdate();
memcpy( p_sap_session->psz_data, psz_head, i_header_size ); psz_head[2] = i_hash >> 8; /* Msg id hash */
memcpy( p_sap_session->psz_data+i_header_size, p_sap_session->psz_sdp, psz_head[3] = i_hash; /* Msg id hash 2 */
strlen( p_sap_session->psz_sdp) );
headsize = 4;
switch (p_session->orig.ss_family)
{
#ifdef AF_INET6
case AF_INET6:
{
struct in6_addr *a6 =
&((struct sockaddr_in6 *)&p_session->orig)->sin6_addr;
memcpy (psz_head + headsize, a6, 16);
psz_head[0] |= 0x10; /* IPv6 flag */
headsize += 16;
break;
}
#endif
case AF_INET:
{
uint32_t ipv4 =
(((struct sockaddr_in *)&p_session->orig)->sin_addr.s_addr);
memcpy (psz_head + headsize, &ipv4, 4);
headsize += 4;
break;
}
free( psz_head ); }
memcpy (psz_head + headsize, "application/sdp", 16);
headsize += 16;
/* Build the final message */
strcpy( (char *)psz_head + headsize, p_session->psz_sdp);
/* Enqueue the announce */ /* Enqueue the announce */
INSERT_ELEM( p_sap->pp_sessions, INSERT_ELEM( p_sap->pp_sessions,
...@@ -547,7 +537,6 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap, ...@@ -547,7 +537,6 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
p_sap->i_sessions, p_sap->i_sessions,
i ); i );
free( p_mysession->psz_sdp );
free( p_mysession->psz_data ); free( p_mysession->psz_data );
free( p_mysession ); free( p_mysession );
break; break;
...@@ -607,65 +596,43 @@ static char *SDPGenerate( sap_handler_t *p_sap, ...@@ -607,65 +596,43 @@ static char *SDPGenerate( sap_handler_t *p_sap,
const session_descriptor_t *p_session, const session_descriptor_t *p_session,
const sap_address_t *p_addr, vlc_bool_t b_ssm ) const sap_address_t *p_addr, vlc_bool_t b_ssm )
{ {
int64_t i_sdp_id = mdate(); char *psz_group, *psz_name, *psz_sdp;
int i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff);
char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri, char *head = StartSDP (p_session->psz_name, p_session->description,
*psz_sdp; p_session->url, p_session->email, p_session->phone,
char ipv; (const struct sockaddr *)&p_session->orig, p_session->origlen,
(const struct sockaddr *)&p_session->addr, p_session->addrlen);
if (head == NULL)
return NULL;
psz_group = p_session->psz_group; psz_group = p_session->psz_group;
psz_name = p_session->psz_name; psz_name = p_session->psz_name;
/* FIXME: really check that psz_uri is a real IP address char *plgroup;
* FIXME: make a common function to obtain a canonical IP address */ if ((psz_group == NULL)
ipv = ( strchr( p_session->psz_uri, ':' ) != NULL) ? '6' : '4'; || (asprintf (&plgroup, "a=x-plgroup:%s\r\n", psz_group) == -1))
if( *p_session->psz_uri == '[' ) plgroup = NULL;
{
char *ptr; char *sfilter;
#if 0
strlcpy( psz_uribuf, p_session->psz_uri + 1, sizeof( psz_uribuf ) ); if ((!b_ssm)
ptr = strchr( psz_uribuf, '%' ); || (asprintf (&sfilter, "a=source-filter: incl IN IP%c * %s\r\n",
if( ptr != NULL) ipv, p_addr->psz_machine) == -1))
*ptr = '\0'; #else
ptr = strchr( psz_uribuf, ']' ); # warning FIXME: repair Source Specific Multicast
if( ptr != NULL) #endif
*ptr = '\0'; sfilter = NULL;
psz_uri = psz_uribuf;
} int res = asprintf (&psz_sdp, "%s" "%s" "%s"
else "m=video %d %s %d\r\n",
psz_uri = p_session->psz_uri; head,
plgroup ?: "",
char *sfilter = NULL; sfilter ?: "",
if (b_ssm) net_GetPort ((const struct sockaddr *)&p_session->addr),
{
if (asprintf (&sfilter, "a=source-filter: incl IN IP%c * %s\r\n",
ipv, p_addr->psz_machine) == -1)
return NULL;
}
int res = asprintf (&psz_sdp,
"v=0\r\n"
"o=- "I64Fd" %d IN IP%c %s\r\n"
"s=%s\r\n"
"c=IN IP%c %s/255\r\n"
"t=0 0\r\n"
"a=tool:"PACKAGE_STRING"\r\n"
"a=recvonly\r\n"
"a=type:broadcast\n"
"%s"
"m=video %d %s %d\r\n"
"%s%s%s",
i_sdp_id, i_sdp_version,
ipv, p_addr->psz_machine,
psz_name, ipv, psz_uri,
(sfilter != NULL) ? sfilter : "",
p_session->i_port,
p_session->b_rtp ? "RTP/AVP" : "udp", p_session->b_rtp ? "RTP/AVP" : "udp",
p_session->i_payload, p_session->i_payload);
psz_group ? "a=x-plgroup:" : "", free (plgroup);
psz_group ? psz_group : "", psz_group ? "\r\n" : ""); free (sfilter);
if (sfilter != NULL)
free (sfilter);
if (res == -1) if (res == -1)
return NULL; return NULL;
......
...@@ -68,6 +68,28 @@ struct sap_handler_t ...@@ -68,6 +68,28 @@ struct sap_handler_t
/* private data, not in p_sys as there is one kind of sap_handler_t */ /* private data, not in p_sys as there is one kind of sap_handler_t */
}; };
struct session_descriptor_t
{
char *psz_name;
char *psz_group;
char *description;
char *url; // meta URL for SAP, potentially real URL for other cases
char *email;
char *phone;
struct sockaddr_storage orig;
socklen_t origlen;
struct sockaddr_storage addr;
socklen_t addrlen;
int i_payload; /* SAP Payload type */
char *psz_sdp;
vlc_bool_t b_rtp;
vlc_bool_t b_ssm;
};
/* The main announce handler object */ /* The main announce handler object */
struct announce_handler_t struct announce_handler_t
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment