Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

announce.c

00001 /*****************************************************************************
00002  * announce.c : announce handler
00003  *****************************************************************************
00004  * Copyright (C) 2002-2004 the VideoLAN team
00005  * $Id: announce.c 12932 2005-10-23 10:58:24Z zorglub $
00006  *
00007  * Authors: Clément Stenac <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                                /* free() */
00028 #include <stdio.h>                                              /* sprintf() */
00029 #include <string.h>                                            /* strerror() */
00030 
00031 #include <vlc/vlc.h>
00032 #include <vlc/sout.h>
00033 
00034 /*****************************************************************************
00035  * Local prototypes
00036  *****************************************************************************/
00037 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
00038 
00039 
00040 /****************************************************************************
00041  * Sout-side functions
00042  ****************************************************************************/
00043 
00052 int sout_AnnounceRegister( sout_instance_t *p_sout,
00053                        session_descriptor_t *p_session,
00054                        announce_method_t *p_method )
00055 {
00056     int i_ret;
00057     announce_handler_t *p_announce = (announce_handler_t*)
00058                               vlc_object_find( p_sout,
00059                                               VLC_OBJECT_ANNOUNCE,
00060                                               FIND_ANYWHERE );
00061 
00062     if( !p_announce )
00063     {
00064         msg_Dbg( p_sout, "No announce handler found, creating one" );
00065         p_announce = announce_HandlerCreate( p_sout );
00066         if( !p_announce )
00067         {
00068             msg_Err( p_sout, "Creation failed" );
00069             return VLC_ENOMEM;
00070         }
00071         vlc_object_yield( p_announce );
00072         msg_Dbg( p_sout,"Creation done" );
00073     }
00074 
00075     i_ret = announce_Register( p_announce, p_session, p_method );
00076     vlc_object_release( p_announce );
00077 
00078     return i_ret;
00079 }
00080 
00090 session_descriptor_t *sout_AnnounceRegisterSDP( sout_instance_t *p_sout,
00091                           const char *psz_sdp, const char *psz_uri,
00092                           announce_method_t *p_method )
00093 {
00094     session_descriptor_t *p_session;
00095     announce_handler_t *p_announce = (announce_handler_t*)
00096                                      vlc_object_find( p_sout,
00097                                               VLC_OBJECT_ANNOUNCE,
00098                                               FIND_ANYWHERE );
00099     if( !p_announce )
00100     {
00101         msg_Dbg( p_sout, "no announce handler found, creating one" );
00102         p_announce = announce_HandlerCreate( p_sout );
00103         if( !p_announce )
00104         {
00105             msg_Err( p_sout, "Creation failed" );
00106             return NULL;
00107         }
00108         vlc_object_yield( p_announce );
00109     }
00110 
00111     if( p_method->i_type != METHOD_TYPE_SAP )
00112     {
00113         msg_Warn( p_sout,"forcing SAP announcement");
00114     }
00115 
00116     p_session = sout_AnnounceSessionCreate();
00117     p_session->psz_sdp = strdup( psz_sdp );
00118     p_session->psz_uri = strdup( psz_uri );
00119     announce_Register( p_announce, p_session, p_method );
00120 
00121     vlc_object_release( p_announce );
00122     return p_session;
00123 }
00124 
00132 int sout_AnnounceUnRegister( sout_instance_t *p_sout,
00133                              session_descriptor_t *p_session )
00134 {
00135     int i_ret;
00136     announce_handler_t *p_announce = (announce_handler_t*)
00137                               vlc_object_find( p_sout,
00138                                               VLC_OBJECT_ANNOUNCE,
00139                                               FIND_ANYWHERE );
00140     if( !p_announce )
00141     {
00142         msg_Dbg( p_sout, "Unable to remove announce: no announce handler" );
00143         return VLC_ENOOBJ;
00144     }
00145     i_ret  = announce_UnRegister( p_announce, p_session );
00146 
00147     vlc_object_release( p_announce );
00148 
00149     return i_ret;
00150 }
00151 
00157 session_descriptor_t * sout_AnnounceSessionCreate(void)
00158 {
00159     session_descriptor_t *p_session;
00160 
00161     p_session = (session_descriptor_t *)malloc( sizeof(session_descriptor_t));
00162 
00163     if( p_session)
00164     {
00165         p_session->p_sap = NULL;
00166         p_session->psz_sdp = NULL;
00167         p_session->psz_name = NULL;
00168         p_session->psz_uri = NULL;
00169         p_session->i_port = 0;
00170         p_session->psz_group = NULL;
00171     }
00172 
00173     return p_session;
00174 }
00175 
00182 void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
00183 {
00184     if( p_session )
00185     {
00186         FREE( p_session->psz_name );
00187         FREE( p_session->psz_group );
00188         FREE( p_session->psz_uri );
00189         FREE( p_session->psz_sdp );
00190         free( p_session );
00191     }
00192 }
00193 
00200 announce_method_t * sout_AnnounceMethodCreate( int i_type )
00201 {
00202     announce_method_t *p_method;
00203 
00204     p_method = (announce_method_t *)malloc( sizeof(announce_method_t) );
00205     if( p_method == NULL )
00206         return NULL;
00207 
00208     p_method->i_type = i_type;
00209     return p_method;
00210 }
00211 
00212 /************************************************************************
00213  * Announce handler functions (private)
00214  ************************************************************************/
00215 
00222 announce_handler_t *__announce_HandlerCreate( vlc_object_t *p_this )
00223 {
00224     announce_handler_t *p_announce;
00225 
00226     p_announce = vlc_object_create( p_this, VLC_OBJECT_ANNOUNCE );
00227 
00228     if( !p_announce )
00229     {
00230         msg_Err( p_this, "out of memory" );
00231         return NULL;
00232     }
00233 
00234     p_announce->p_sap = NULL;
00235 
00236     vlc_object_attach( p_announce, p_this->p_vlc);
00237 
00238 
00239     return p_announce;
00240 }
00241 
00248 int announce_HandlerDestroy( announce_handler_t *p_announce )
00249 {
00250 
00251     if( p_announce->p_sap )
00252     {
00253         p_announce->p_sap->b_die = VLC_TRUE;
00254         /* Wait for the SAP thread to exit */
00255         vlc_thread_join( p_announce->p_sap );
00256         announce_SAPHandlerDestroy( p_announce->p_sap );
00257     }
00258 
00259     /* Free the structure */
00260     vlc_object_destroy( p_announce );
00261 
00262     return VLC_SUCCESS;
00263 }
00264 
00265 /* Register an announce */
00266 int announce_Register( announce_handler_t *p_announce,
00267                        session_descriptor_t *p_session,
00268                        announce_method_t *p_method )
00269 {
00270 
00271     msg_Dbg( p_announce, "registering announce");
00272     if( p_method->i_type == METHOD_TYPE_SAP )
00273     {
00274         /* Do we already have a SAP announce handler ? */
00275         if( !p_announce->p_sap )
00276         {
00277             sap_handler_t *p_sap = announce_SAPHandlerCreate( p_announce );
00278             msg_Dbg( p_announce, "creating SAP announce handler");
00279             if( !p_sap )
00280             {
00281                 msg_Err( p_announce, "SAP handler creation failed" );
00282                 return VLC_ENOOBJ;
00283             }
00284             p_announce->p_sap = p_sap;
00285         }
00286         /* this will set p_session->p_sap for later deletion */
00287         msg_Dbg( p_announce, "adding SAP session");
00288         p_announce->p_sap->pf_add( p_announce->p_sap, p_session );
00289     }
00290     else if( p_method->i_type == METHOD_TYPE_SLP )
00291     {
00292         msg_Dbg( p_announce, "SLP unsupported at the moment" );
00293         return VLC_EGENERIC;
00294     }
00295     else
00296     {
00297         msg_Dbg( p_announce, "Announce type unsupported" );
00298         return VLC_EGENERIC;
00299     }
00300     return VLC_SUCCESS;;
00301 }
00302 
00303 
00304 /* Unregister an announce */
00305 int announce_UnRegister( announce_handler_t *p_announce,
00306                   session_descriptor_t *p_session )
00307 {
00308     msg_Dbg( p_announce, "unregistering announce" );
00309     if( p_session->p_sap != NULL ) /* SAP Announce */
00310     {
00311         if( !p_announce->p_sap )
00312         {
00313             msg_Err( p_announce, "can't remove announce, no SAP handler");
00314             return VLC_ENOOBJ;
00315         }
00316         p_announce->p_sap->pf_del( p_announce->p_sap, p_session );
00317     }
00318     return VLC_SUCCESS;
00319 }

Generated on Tue Dec 20 10:14:49 2005 for vlc-0.8.4a by  doxygen 1.4.2