1 /*****************************************************************************
2 * announce.c : announce handler
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
33 #include "stream_output.h"
37 /* Private functions for the announce handler */
38 static announce_handler_t* announce_HandlerCreate( vlc_object_t *);
39 static int announce_Register( announce_handler_t *p_announce,
40 session_descriptor_t *p_session,
41 announce_method_t *p_method );
42 static int announce_UnRegister( announce_handler_t *p_announce,
43 session_descriptor_t *p_session );
45 struct announce_method_t
49 /****************************************************************************
51 ****************************************************************************/
54 * Register a new session with the announce handler, using a pregenerated SDP
56 * \param p_sout a sout instance structure
57 * \param psz_sdp the SDP to register
58 * \param psz_dst session address (needed for SAP address auto detection)
59 * \param p_method an announce method descriptor
60 * \return the new session descriptor structure
62 session_descriptor_t *
63 sout_AnnounceRegisterSDP( sout_instance_t *p_sout, const char *psz_sdp,
64 const char *psz_dst, announce_method_t *p_method )
66 session_descriptor_t *p_session;
67 announce_handler_t *p_announce = (announce_handler_t*)
68 vlc_object_find( p_sout,
73 msg_Dbg( p_sout, "no announce handler found, creating one" );
74 p_announce = announce_HandlerCreate( VLC_OBJECT( p_sout ) );
77 msg_Err( p_sout, "Creation failed" );
80 vlc_object_yield( p_announce );
83 p_session = malloc( sizeof( *p_session ) );
84 memset( p_session, 0, sizeof( *p_session ) );
85 p_session->psz_sdp = strdup( psz_sdp );
87 /* GRUIK. We should not convert back-and-forth from string to numbers */
89 if (vlc_getaddrinfo (VLC_OBJECT (p_sout), psz_dst, 0, NULL, &res) == 0)
91 if (res->ai_addrlen <= sizeof (p_session->addr))
92 memcpy (&p_session->addr, res->ai_addr,
93 p_session->addrlen = res->ai_addrlen);
94 vlc_freeaddrinfo (res);
97 announce_Register( p_announce, p_session, p_method );
99 vlc_object_release( p_announce );
104 * UnRegister an existing session
106 * \param p_sout a sout instance structure
107 * \param p_session the session descriptor
108 * \return VLC_SUCCESS or an error
110 int sout_AnnounceUnRegister( sout_instance_t *p_sout,
111 session_descriptor_t *p_session )
114 announce_handler_t *p_announce = (announce_handler_t*)
115 vlc_object_find( p_sout,
120 msg_Dbg( p_sout, "unable to remove announce: no announce handler" );
123 i_ret = announce_UnRegister( p_announce, p_session );
127 vlc_object_release( p_announce );
133 * \return the SAP announce method
135 announce_method_t * sout_SAPMethod (void)
140 void sout_MethodRelease (announce_method_t *m)
142 assert (m == &sap_method);
145 /************************************************************************
146 * Announce handler functions (private)
147 ************************************************************************/
150 * Create the announce handler object
152 * \param p_this a vlc_object structure
153 * \return the new announce handler or NULL on error
155 static announce_handler_t *announce_HandlerCreate( vlc_object_t *p_this )
157 announce_handler_t *p_announce;
159 p_announce = vlc_object_create( p_this, VLC_OBJECT_ANNOUNCE );
164 p_announce->p_sap = NULL;
165 vlc_object_attach( p_announce, p_this->p_libvlc);
171 * Destroy a announce handler object
173 * \param p_announce the announce handler to destroy
174 * \return VLC_SUCCESS or an error
176 int announce_HandlerDestroy( announce_handler_t *p_announce )
178 if( p_announce->p_sap )
181 vlc_object_release( p_announce->p_sap );
184 /* Free the structure */
185 vlc_object_release( p_announce );
190 /* Register an announce */
191 static int announce_Register( announce_handler_t *p_announce,
192 session_descriptor_t *p_session,
193 announce_method_t *p_method )
195 if (p_method == NULL)
198 msg_Dbg( p_announce, "registering announce");
199 if( p_method == &sap_method )
201 /* Do we already have a SAP announce handler ? */
202 if( !p_announce->p_sap )
204 sap_handler_t *p_sap = announce_SAPHandlerCreate( p_announce );
205 msg_Dbg( p_announce, "creating SAP announce handler");
208 msg_Err( p_announce, "SAP handler creation failed" );
211 p_announce->p_sap = p_sap;
213 /* this will set p_session->p_sap for later deletion */
214 msg_Dbg( p_announce, "adding SAP session");
215 p_announce->p_sap->pf_add( p_announce->p_sap, p_session );
219 msg_Err( p_announce, "announce type unsupported" );
226 /* Unregister an announce */
227 static int announce_UnRegister( announce_handler_t *p_announce,
228 session_descriptor_t *p_session )
230 msg_Dbg( p_announce, "unregistering announce" );
231 if( p_announce->p_sap )
232 p_announce->p_sap->pf_del( p_announce->p_sap, p_session );