From b83deb14dfba98e2695e437b7f66c65fd8bb2713 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Stenac?= Date: Wed, 13 Aug 2003 14:17:26 +0000 Subject: [PATCH] * configure.ac : we need to define HAVE_SLP_H * include/announce.h & vlc_common.h: slp_session_t structure definition * module/stream_out/standard.c & src/stream_output/announce.c : SLP announcing support by vlc --- configure.ac | 7 +- include/announce.h | 13 +++- include/vlc_common.h | 4 +- modules/stream_out/standard.c | 45 ++++++++++++- src/stream_output/announce.c | 119 ++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 2dbd0a019d..bfc9bbba25 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Autoconf settings for vlc -dnl $Id: configure.ac,v 1.56 2003/08/12 08:19:20 sam Exp $ +dnl $Id: configure.ac,v 1.57 2003/08/13 14:17:25 zorglub Exp $ AC_INIT(vlc,0.6.2) @@ -2829,11 +2829,12 @@ then [ --with-slp=PATH libslp headers and libraries]) if test -z "${with_slp}" then - AC_CHECK_HEADER(slp.h, have_slp="true", have_slp="false") + AC_CHECK_HEADERS(slp.h, have_slp="true", have_slp="false") if test "${have_slp}" = "true" then AX_ADD_PLUGINS([slp]) AX_ADD_LDFLAGS([slp],[-lslp]) + AX_ADD_LDFLAGS([vlc],[-lslp]) fi else AC_MSG_CHECKING(for slp headers in ${with_slp}) @@ -2843,7 +2844,9 @@ then AC_MSG_RESULT(yes) AX_ADD_PLUGINS([slp]) AX_ADD_LDFLAGS([slp],[-L${with_slp} -lslp]) + AX_ADD_LDFLAGS([vlc],[-L${with_slp} -lslp]) AX_ADD_CPPFLAGS([slp],[-I${with_slp}]) + AC_DEFINE(HAVE_SLP_H) else dnl No libslp could be found, sorry AC_MSG_RESULT(no) diff --git a/include/announce.h b/include/announce.h index 81f91c96d4..98c9c53331 100644 --- a/include/announce.h +++ b/include/announce.h @@ -2,7 +2,7 @@ * announce.h : Session announcement ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: announce.h,v 1.7 2003/07/17 14:10:08 sam Exp $ + * $Id: announce.h,v 1.8 2003/08/13 14:17:26 zorglub Exp $ * * Authors: Clément Stenac * @@ -57,6 +57,12 @@ struct sap_session_t }; +struct slp_session_t +{ + char *psz_url; + char *psz_name; +}; + /***************************************************************************** * Prototypes @@ -64,3 +70,8 @@ struct sap_session_t VLC_EXPORT( sap_session_t *, sout_SAPNew, ( sout_instance_t *,char * , char * , int , char *) ); VLC_EXPORT( void, sout_SAPSend, ( sout_instance_t *,sap_session_t *) ); VLC_EXPORT( void, sout_SAPDelete, ( sout_instance_t *,sap_session_t * ) ); + +#ifdef HAVE_SLP_H +VLC_EXPORT( int, sout_SLPReg, (sout_instance_t*,char*,char*) ); +VLC_EXPORT( int, sout_SLPDereg, (sout_instance_t*,char*,char*) ); +#endif diff --git a/include/vlc_common.h b/include/vlc_common.h index b86205167e..6088313958 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -3,7 +3,7 @@ * Collection of useful common types and macros definitions ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN - * $Id: vlc_common.h,v 1.70 2003/08/01 00:00:12 fenrir Exp $ + * $Id: vlc_common.h,v 1.71 2003/08/13 14:17:26 zorglub Exp $ * * Authors: Samuel Hocevar * Vincent Seguin @@ -264,6 +264,8 @@ typedef struct sout_stream_t sout_stream_t; typedef struct sout_cfg_t sout_cfg_t; typedef struct sout_format_t sout_format_t; typedef struct sap_session_t sap_session_t; +typedef struct slp_session_t slp_session_t; + /* Decoders */ typedef struct decoder_fifo_t decoder_fifo_t; diff --git a/modules/stream_out/standard.c b/modules/stream_out/standard.c index 1e962d77be..c25e3918b3 100644 --- a/modules/stream_out/standard.c +++ b/modules/stream_out/standard.c @@ -2,7 +2,7 @@ * standard.c ***************************************************************************** * Copyright (C) 2001, 2002 VideoLAN - * $Id: standard.c,v 1.8 2003/07/07 15:50:43 gbazin Exp $ + * $Id: standard.c,v 1.9 2003/08/13 14:17:26 zorglub Exp $ * * Authors: Laurent Aimar * @@ -58,6 +58,7 @@ vlc_module_end(); struct sout_stream_sys_t { sout_mux_t *p_mux; + slp_session_t *p_slp; sap_session_t *p_sap; }; @@ -75,8 +76,10 @@ static int Open( vlc_object_t *p_this ) char *psz_url = sout_cfg_find_value( p_stream->p_cfg, "url" ); char *psz_ipv = sout_cfg_find_value( p_stream->p_cfg, "sap_ipv" ); char *psz_v6_scope = sout_cfg_find_value( p_stream->p_cfg, "sap_v6scope" ); + sout_cfg_t *p_sap_cfg = sout_cfg_find( p_stream->p_cfg, "sap" ); - + sout_cfg_t *p_slp_cfg = sout_cfg_find( p_stream->p_cfg, "slp" ); + sout_access_out_t *p_access; sout_mux_t *p_mux; @@ -128,6 +131,33 @@ static int Open( vlc_object_t *p_this ) msg_Err( p_sout,"Unable to initialize SAP. SAP disabled"); } + /* *** Register with slp *** */ + #ifdef HAVE_SLP_H + if( p_slp_cfg && ( strstr( psz_access, "udp" ) || + strstr( psz_access , "rtp" ) ) ) + { + p_sys->p_slp = NULL ; + msg_Info( p_this, "SLP Enabled"); + if( sout_SLPReg( p_sout, psz_url, + p_slp_cfg->psz_value ? p_slp_cfg->psz_value : psz_url) ) + { + msg_Warn( p_sout, "SLP Registering failed"); + } + else + { + p_sys->p_slp = (slp_session_t*)malloc(sizeof(slp_session_t)); + if(!p_sys->p_slp) + { + msg_Warn(p_sout,"Out of memory"); + return -1; + } + p_sys->p_slp->psz_url= strdup(psz_url); + p_sys->p_slp->psz_name = strdup( + p_slp_cfg->psz_value ? p_slp_cfg->psz_value : psz_url); + } + } + #endif + /* XXX beurk */ p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader ); @@ -155,6 +185,17 @@ static void Close( vlc_object_t * p_this ) if( p_sys->p_sap ) sout_SAPDelete( (sout_instance_t *)p_this , p_sys->p_sap ); + #ifdef HAVE_SLP_H + if( p_sys->p_slp ) + { + sout_SLPDereg( (sout_instance_t *)p_this, + p_sys->p_slp->psz_url, + p_sys->p_slp->psz_name); + free( p_sys->p_slp); + } + #endif + + sout_MuxDelete( p_sys->p_mux ); sout_AccessOutDelete( p_access ); diff --git a/src/stream_output/announce.c b/src/stream_output/announce.c index 90d664b40c..306942b8af 100644 --- a/src/stream_output/announce.c +++ b/src/stream_output/announce.c @@ -46,6 +46,10 @@ # include #endif +#ifdef HAVE_SLP_H +# include +#endif + #include "announce.h" #include "network.h" @@ -391,3 +395,118 @@ void sout_SAPSend( sout_instance_t *p_sout, sap_session_t * p_sap ) free( psz_head ); } + + +/***************************************************************************** + * sout_SLPBuildName: Builds a service name according to SLP standard + *****************************************************************************/ +char * sout_SLPBuildName(char *psz_url,char *psz_name) +{ + char *psz_service; + unsigned int i_size; + + /* name to build is: service:$(name).videolan://$(url) */ + + i_size = 8 + strlen(psz_name) + 12 + strlen(psz_url) + 1; + + psz_service=(char *)malloc(i_size * sizeof(char)); + + snprintf( psz_service , i_size, + "service:%s.videolan://%s", + psz_name,psz_url); + psz_service[i_size]='\0'; /* Just to make sure */ + + return psz_service; + +} + +/***************************************************************************** + * sout_SLPReport: Reporting function. Unused at the moment but needed + *****************************************************************************/ +#ifdef HAVE_SLP_H +void sout_SLPReport(SLPHandle slp_handle,SLPError slp_error,void* cookie) +{ +} +#endif + +/***************************************************************************** + * sout_SLPReg: Registers the program with SLP + *****************************************************************************/ +int sout_SLPReg( sout_instance_t *p_sout, char * psz_url, + char * psz_name) +{ +#ifdef HAVE_SLP_H + SLPHandle slp_handle; + SLPError slp_res; + char *psz_service= sout_SLPBuildName(psz_url,psz_name); + + if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK) + { + msg_Warn(p_sout,"Unable to initialize SLP"); + return -1; + } + + msg_Info(p_sout , "Registering %s (name: %s) in SLP", + psz_service , psz_name); + + slp_res = SLPReg ( slp_handle, + psz_service, + SLP_LIFETIME_MAXIMUM, + NULL, + psz_name, + SLP_TRUE, + sout_SLPReport, + NULL ); + + if( slp_res != SLP_OK ) + { + msg_Warn(p_sout,"Error while registering service: %i", slp_res ); + return -1; + } + + return 0; + +#else /* This function should never be called if this is false */ + return -1 +#endif +} + + +/***************************************************************************** + * sout_SLDePReg: Unregisters the program from SLP + *****************************************************************************/ +int sout_SLPDereg( sout_instance_t *p_sout, char * psz_url, + char * psz_name) +{ +#ifdef HAVE_SLP_H + + SLPHandle slp_handle; + SLPError slp_res; + char *psz_service= sout_SLPBuildName(psz_url,psz_name); + + if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK) + { + msg_Warn(p_sout,"Unable to initialize SLP"); + return -1; + } + + msg_Info(p_sout , "Unregistering %s from SLP", + psz_service); + + slp_res = SLPDereg ( slp_handle, + psz_service, + sout_SLPReport, + NULL ); + + if( slp_res != SLP_OK ) + { + msg_Warn(p_sout,"Error while registering service: %i", slp_res ); + return -1; + } + + return 0; + +#else /* This function should never be called if this is false */ + return -1 +#endif +} -- 2.39.2