]> git.sesse.net Git - vlc/commitdiff
Partial announce API cleanup
authorRémi Denis-Courmont <rem@videolan.org>
Fri, 9 Feb 2007 21:51:43 +0000 (21:51 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Fri, 9 Feb 2007 21:51:43 +0000 (21:51 +0000)
To be continued

include/vlc_sout.h
modules/stream_out/rtp.c
modules/stream_out/standard.c
src/stream_output/announce.c
src/stream_output/sap.c
src/stream_output/stream_output.h

index 839861c9229665fbc12506425228deae873f4288..512be41dd6cbde2c4625c246872968b06bca852c 100644 (file)
@@ -220,25 +220,17 @@ struct session_descriptor_t
 
     char *psz_group;
 
-    sap_session_t *p_sap; /* If we have a sap session, remember it */
     char *psz_sdp;
     vlc_bool_t b_rtp;
 };
 
-#define METHOD_TYPE_SAP 1
-
-struct announce_method_t
-{
-    int i_type;
-};
-
 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( int,                sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
 
 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
 VLC_EXPORT(void,                 sout_AnnounceSessionDestroy, (session_descriptor_t *) );
-VLC_EXPORT(announce_method_t*,   sout_AnnounceMethodCreate, (int) );
+VLC_EXPORT(announce_method_t*,   sout_SAPMethod, (void) );
 
 #ifdef __cplusplus
 }
index 6f08d41f8a8ab851e86ce8f6ddeee34c7e6819ba..0e25c2d223e66cb0b932670f989c5ea0e42acade 100644 (file)
@@ -1533,7 +1533,7 @@ static int SapSetup( sout_stream_t *p_stream )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     sout_instance_t   *p_sout = p_stream->p_sout;
-    announce_method_t *p_method = sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
+    announce_method_t *p_method = sout_SAPMethod();
 
     /* Remove the previous session */
     if( p_sys->p_session != NULL)
index 51e718b78256bf5ff8259d67fb94e450a820af08..1f7d019eedf2a08c39af28f436d9cc4b0bbbd3e5 100644 (file)
@@ -316,8 +316,7 @@ static int Open( vlc_object_t *p_this )
         ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
     {
         session_descriptor_t *p_session = sout_AnnounceSessionCreate();
-        announce_method_t *p_method =
-            sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
+        announce_method_t *p_method = sout_SAPMethod();
         vlc_url_t url;
 
         var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
index ca1007896a2cda83bcb897bf23f6539bd363117f..168258c8d74097f25328615705a10c618a6e67a1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * announce.c : announce handler
  *****************************************************************************
- * Copyright (C) 2002-2004 the VideoLAN team
+ * Copyright (C) 2002-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
 #include <vlc_sout.h>
 #include "stream_output.h"
 
+struct announce_method_t
+{
+} sap_method;
+
 /****************************************************************************
  * Sout-side functions
  ****************************************************************************/
@@ -103,11 +107,6 @@ session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout,
         vlc_object_yield( p_announce );
     }
 
-    if( p_method->i_type != METHOD_TYPE_SAP )
-    {
-        msg_Warn( p_sout, "forcing SAP announcement");
-    }
-
     p_session = sout_AnnounceSessionCreate();
     p_session->psz_sdp = strdup( psz_sdp );
     p_session->psz_uri = strdup( psz_uri );
@@ -180,21 +179,11 @@ void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
 }
 
 /**
- * Create and initialize an announcement method structure
- *
- * \param i_type METHOD_TYPE_SAP
- * \return a new announce_method structure
+ * \return the SAP announce method
  */
-announce_method_t * sout_AnnounceMethodCreate( int i_type )
+announce_method_t * sout_SAPMethod (void)
 {
-    announce_method_t *p_method;
-
-    p_method = (announce_method_t *)malloc( sizeof(announce_method_t) );
-    if( p_method == NULL )
-        return NULL;
-
-    p_method->i_type = i_type;
-    return p_method;
+    return &sap_method;
 }
 
 /************************************************************************
@@ -233,12 +222,11 @@ announce_handler_t *__announce_HandlerCreate( vlc_object_t *p_this )
  */
 int announce_HandlerDestroy( announce_handler_t *p_announce )
 {
-
     if( p_announce->p_sap )
     {
-        p_announce->p_sap->b_die = VLC_TRUE;
+        ((vlc_object_t *)p_announce->p_sap)->b_die = VLC_TRUE;
         /* Wait for the SAP thread to exit */
-        vlc_thread_join( p_announce->p_sap );
+        vlc_thread_join( (vlc_object_t *)p_announce->p_sap );
         announce_SAPHandlerDestroy( p_announce->p_sap );
     }
 
@@ -255,7 +243,7 @@ int announce_Register( announce_handler_t *p_announce,
 {
 
     msg_Dbg( p_announce, "registering announce");
-    if( p_method->i_type == METHOD_TYPE_SAP )
+    if( p_method == &sap_method )
     {
         /* Do we already have a SAP announce handler ? */
         if( !p_announce->p_sap )
@@ -275,7 +263,7 @@ int announce_Register( announce_handler_t *p_announce,
     }
     else
     {
-        msg_Dbg( p_announce, "announce type unsupported" );
+        msg_Err( p_announce, "announce type unsupported" );
         return VLC_EGENERIC;
     }
     return VLC_SUCCESS;;
@@ -287,14 +275,7 @@ int announce_UnRegister( announce_handler_t *p_announce,
                   session_descriptor_t *p_session )
 {
     msg_Dbg( p_announce, "unregistering announce" );
-    if( p_session->p_sap != NULL ) /* SAP Announce */
-    {
-        if( !p_announce->p_sap )
-        {
-            msg_Err( p_announce, "can't remove announce, no SAP handler");
-            return VLC_ENOOBJ;
-        }
+    if( p_announce->p_sap )
         p_announce->p_sap->pf_del( p_announce->p_sap, p_session );
-    }
     return VLC_SUCCESS;
 }
index 8617f7fa7e591aac39ada529a36db67a42372c06..5eae84d65937bd42a509da55191ab50c5a2d0a31 100644 (file)
@@ -72,6 +72,19 @@ struct sap_address_t
     int i_limit;
 };
 
+/* A SAP session descriptor, enqueued in the SAP handler queue */
+struct sap_session_t {
+    char          *psz_sdp;
+    uint8_t       *psz_data;
+    unsigned      i_length;
+    sap_address_t *p_address;
+    session_descriptor_t *p_sd;
+
+    /* Last and next send */
+    mtime_t        i_last;
+    mtime_t        i_next;
+};
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -252,7 +265,6 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
         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;
@@ -296,7 +308,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                 /* SSM <=> ff3x::/32 */
                 b_ssm = (U32_AT (a6->s6_addr) & 0xfff0ffff) == 0xff300000;
 
-               /* force flags to zero, preserve scope */
+                /* force flags to zero, preserve scope */
                 a6->s6_addr[1] &= 0xf;
             }
             else
@@ -369,6 +381,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 
     /* XXX: Check for dupes */
     p_sap_session = (sap_session_t*)malloc(sizeof(sap_session_t));
+    p_sap_session->p_sd = p_session;
     p_sap_session->p_address = NULL;
 
     /* Add the address to the buffer */
@@ -510,9 +523,6 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
     msg_Dbg( p_sap,"%i addresses, %i sessions",
                    p_sap->i_addresses,p_sap->i_sessions);
 
-    /* Remember the SAP session for later deletion */
-    p_session->p_sap = p_sap_session;
-
     vlc_mutex_unlock( &p_sap->object_lock );
 
     return VLC_SUCCESS;
@@ -525,20 +535,21 @@ static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
     int i;
     vlc_mutex_lock( &p_sap->object_lock );
 
-    msg_Dbg( p_sap,"removing SAP announce %p",p_session->p_sap);
+    msg_Dbg( p_sap, "removing session %p from SAP", p_session);
 
     /* Dequeue the announce */
     for( i = 0; i< p_sap->i_sessions; i++)
     {
-        if( p_session->p_sap == p_sap->pp_sessions[i] )
+        if( p_session == p_sap->pp_sessions[i]->p_sd )
         {
+            sap_session_t *p_mysession = p_sap->pp_sessions[i];
             REMOVE_ELEM( p_sap->pp_sessions,
                          p_sap->i_sessions,
                          i );
 
-            FREENULL( p_session->p_sap->psz_sdp );
-            FREENULL( p_session->p_sap->psz_data );
-            free( p_session->p_sap );
+            free( p_mysession->psz_sdp );
+            free( p_mysession->psz_data );
+            free( p_mysession );
             break;
         }
     }
index 0a6aace002d297999dac05cf8e7128289ecce8ab..98d64c4788050e59f0345ff631a3226c63034f8d 100644 (file)
@@ -47,18 +47,6 @@ VLC_EXPORT( int,                sout_InputSendBuffer,  ( sout_packetizer_input_t
 
 /* Announce system */
 
-/* A SAP session descriptor, enqueued in the SAP handler queue */
-struct sap_session_t {
-    char          *psz_sdp;
-    uint8_t       *psz_data;
-    unsigned      i_length;
-    sap_address_t *p_address;
-
-    /* Last and next send */
-    mtime_t        i_last;
-    mtime_t        i_next;
-};
-
 /* The SAP handler, running in a separate thread */
 struct sap_handler_t
 {