From 0336f13424548f4028f40c57cd1ed534cb58d26f Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 9 Feb 2007 21:51:43 +0000 Subject: [PATCH] Partial announce API cleanup To be continued --- include/vlc_sout.h | 10 +------ modules/stream_out/rtp.c | 2 +- modules/stream_out/standard.c | 3 +-- src/stream_output/announce.c | 45 +++++++++---------------------- src/stream_output/sap.c | 31 ++++++++++++++------- src/stream_output/stream_output.h | 12 --------- 6 files changed, 37 insertions(+), 66 deletions(-) diff --git a/include/vlc_sout.h b/include/vlc_sout.h index 839861c922..512be41dd6 100644 --- a/include/vlc_sout.h +++ b/include/vlc_sout.h @@ -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 } diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c index 6f08d41f8a..0e25c2d223 100644 --- a/modules/stream_out/rtp.c +++ b/modules/stream_out/rtp.c @@ -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) diff --git a/modules/stream_out/standard.c b/modules/stream_out/standard.c index 51e718b782..1f7d019eed 100644 --- a/modules/stream_out/standard.c +++ b/modules/stream_out/standard.c @@ -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 ); diff --git a/src/stream_output/announce.c b/src/stream_output/announce.c index ca1007896a..168258c8d7 100644 --- a/src/stream_output/announce.c +++ b/src/stream_output/announce.c @@ -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 @@ -32,6 +32,10 @@ #include #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; } diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c index 8617f7fa7e..5eae84d659 100644 --- a/src/stream_output/sap.c +++ b/src/stream_output/sap.c @@ -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; } } diff --git a/src/stream_output/stream_output.h b/src/stream_output/stream_output.h index 0a6aace002..98d64c4788 100644 --- a/src/stream_output/stream_output.h +++ b/src/stream_output/stream_output.h @@ -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 { -- 2.39.2