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 )
......
This diff is collapsed.
...@@ -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