]> git.sesse.net Git - vlc/commitdiff
* configure.ac : we need to define HAVE_SLP_H
authorClément Stenac <zorglub@videolan.org>
Wed, 13 Aug 2003 14:17:26 +0000 (14:17 +0000)
committerClément Stenac <zorglub@videolan.org>
Wed, 13 Aug 2003 14:17:26 +0000 (14:17 +0000)
* 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
include/announce.h
include/vlc_common.h
modules/stream_out/standard.c
src/stream_output/announce.c

index 2dbd0a019d697dd9eee5b6d14a4607b1b66cda3a..bfc9bbba25855a0f2359e03962a66dbed1c87444 100644 (file)
@@ -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)
index 81f91c96d43c18a6d09a48a087fbcea1573591b0..98c9c533310093921c5970c07dfcd3682c33e20f 100644 (file)
@@ -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 <zorglub@via.ecp.fr>
  *
@@ -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
index b86205167e788fb4ea52c2e862716416e36ff715..608831395832a41fcbc35c2ae7e8a0f00b1eb822 100644 (file)
@@ -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 <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -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;
 
index 1e962d77beab407c37781a2e2f05de29dba16c64..c25e3918b39afac93cd9ffea57839fbcf16eff66 100644 (file)
@@ -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 <fenrir@via.ecp.fr>
  *
@@ -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 );
 
index 90d664b40c258214909e2196614e82a1dcd08ccd..306942b8af5c2e4d77879c049b2fb4283e6cd4af 100644 (file)
 #   include <sys/socket.h>
 #endif
 
+#ifdef HAVE_SLP_H
+# include <slp.h>
+#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
+}