]> git.sesse.net Git - vlc/blob - src/stream_output/announce.c
Remove dead code
[vlc] / src / stream_output / announce.c
1 /*****************************************************************************
2  * announce.c : announce handler
3  *****************************************************************************
4  * Copyright (C) 2002-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc_sout.h>
29 #include "stream_output.h"
30
31 #include <assert.h>
32
33 /* Private functions for the announce handler */
34 static announce_handler_t*  announce_HandlerCreate( vlc_object_t *);
35 static int announce_Register( announce_handler_t *p_announce,
36                               session_descriptor_t *p_session,
37                               announce_method_t *p_method );
38 static int announce_UnRegister( announce_handler_t *p_announce,
39                                 session_descriptor_t *p_session );
40
41 struct announce_method_t
42 {
43 } sap_method;
44
45 /****************************************************************************
46  * Sout-side functions
47  ****************************************************************************/
48
49 /**
50  * Create and initialize a session descriptor
51  *
52  * \return a new session descriptor
53  */
54 static session_descriptor_t * sout_AnnounceSessionCreate (vlc_object_t *obj,
55                                                    const char *cfgpref)
56 {
57     return calloc (1, sizeof (session_descriptor_t));
58 }
59
60 /**
61  *  Register a new session with the announce handler, using a pregenerated SDP
62  *
63  * \param p_sout a sout instance structure
64  * \param psz_sdp the SDP to register
65  * \param psz_uri session address (needed for SAP address auto detection)
66  * \param p_method an announce method descriptor
67  * \return the new session descriptor structure
68  */
69 session_descriptor_t *
70 sout_AnnounceRegisterSDP( sout_instance_t *p_sout, const char *cfgpref,
71                           const char *psz_sdp, const char *psz_uri,
72                           announce_method_t *p_method )
73 {
74     session_descriptor_t *p_session;
75     announce_handler_t *p_announce = (announce_handler_t*)
76                                      vlc_object_find( p_sout,
77                                               VLC_OBJECT_ANNOUNCE,
78                                               FIND_ANYWHERE );
79     if( !p_announce )
80     {
81         msg_Dbg( p_sout, "no announce handler found, creating one" );
82         p_announce = announce_HandlerCreate( VLC_OBJECT( p_sout ) );
83         if( !p_announce )
84         {
85             msg_Err( p_sout, "Creation failed" );
86             return NULL;
87         }
88         vlc_object_yield( p_announce );
89     }
90
91     p_session = sout_AnnounceSessionCreate(VLC_OBJECT (p_sout), cfgpref);
92     p_session->psz_sdp = strdup( psz_sdp );
93
94     /* GRUIK. We should not convert back-and-forth from string to numbers */
95     struct addrinfo *res;
96     if (vlc_getaddrinfo (VLC_OBJECT (p_sout), psz_uri, 0, NULL, &res) == 0)
97     {
98         if (res->ai_addrlen <= sizeof (p_session->addr))
99             memcpy (&p_session->addr, res->ai_addr,
100                     p_session->addrlen = res->ai_addrlen);
101         vlc_freeaddrinfo (res);
102     }
103
104     announce_Register( p_announce, p_session, p_method );
105
106     vlc_object_release( p_announce );
107     return p_session;
108 }
109
110 /**
111  *  UnRegister an existing session
112  *
113  * \param p_sout a sout instance structure
114  * \param p_session the session descriptor
115  * \return VLC_SUCCESS or an error
116  */
117 int sout_AnnounceUnRegister( sout_instance_t *p_sout,
118                              session_descriptor_t *p_session )
119 {
120     int i_ret;
121     announce_handler_t *p_announce = (announce_handler_t*)
122                               vlc_object_find( p_sout,
123                                               VLC_OBJECT_ANNOUNCE,
124                                               FIND_ANYWHERE );
125     if( !p_announce )
126     {
127         msg_Dbg( p_sout, "unable to remove announce: no announce handler" );
128         return VLC_ENOOBJ;
129     }
130     i_ret  = announce_UnRegister( p_announce, p_session );
131
132     vlc_object_release( p_announce );
133
134     return i_ret;
135 }
136
137 /**
138  * Destroy a session descriptor and free all
139  *
140  * \param p_session the session to destroy
141  * \return Nothing
142  */
143 void sout_AnnounceSessionDestroy( session_descriptor_t *p_session )
144 {
145     free( p_session );
146 }
147
148 /**
149  * \return the SAP announce method
150  */
151 announce_method_t * sout_SAPMethod (void)
152 {
153     return &sap_method;
154 }
155
156 void sout_MethodRelease (announce_method_t *m)
157 {
158     assert (m == &sap_method);
159 }
160
161 /************************************************************************
162  * Announce handler functions (private)
163  ************************************************************************/
164
165 /**
166  * Create the announce handler object
167  *
168  * \param p_this a vlc_object structure
169  * \return the new announce handler or NULL on error
170  */
171 static announce_handler_t *announce_HandlerCreate( vlc_object_t *p_this )
172 {
173     announce_handler_t *p_announce;
174
175     p_announce = vlc_object_create( p_this, VLC_OBJECT_ANNOUNCE );
176
177     if( !p_announce )
178     {
179         msg_Err( p_this, "out of memory" );
180         return NULL;
181     }
182
183     p_announce->p_sap = NULL;
184     vlc_object_attach( p_announce, p_this->p_libvlc);
185
186     return p_announce;
187 }
188
189 /**
190  * Destroy a  announce handler object
191  *
192  * \param p_announce the announce handler to destroy
193  * \return VLC_SUCCESS or an error
194  */
195 int announce_HandlerDestroy( announce_handler_t *p_announce )
196 {
197     if( p_announce->p_sap )
198     {
199         vlc_object_kill ((vlc_object_t *)p_announce->p_sap);
200         /* Wait for the SAP thread to exit */
201         vlc_thread_join( (vlc_object_t *)p_announce->p_sap );
202         announce_SAPHandlerDestroy( p_announce->p_sap );
203     }
204
205     /* Free the structure */
206     vlc_object_destroy( p_announce );
207
208     return VLC_SUCCESS;
209 }
210
211 /* Register an announce */
212 static int announce_Register( announce_handler_t *p_announce,
213                               session_descriptor_t *p_session,
214                               announce_method_t *p_method )
215 {
216     if (p_method == NULL)
217         return VLC_EGENERIC;
218
219     msg_Dbg( p_announce, "registering announce");
220     if( p_method == &sap_method )
221     {
222         /* Do we already have a SAP announce handler ? */
223         if( !p_announce->p_sap )
224         {
225             sap_handler_t *p_sap = announce_SAPHandlerCreate( p_announce );
226             msg_Dbg( p_announce, "creating SAP announce handler");
227             if( !p_sap )
228             {
229                 msg_Err( p_announce, "SAP handler creation failed" );
230                 return VLC_ENOOBJ;
231             }
232             p_announce->p_sap = p_sap;
233         }
234         /* this will set p_session->p_sap for later deletion */
235         msg_Dbg( p_announce, "adding SAP session");
236         p_announce->p_sap->pf_add( p_announce->p_sap, p_session );
237     }
238     else
239     {
240         msg_Err( p_announce, "announce type unsupported" );
241         return VLC_EGENERIC;
242     }
243     return VLC_SUCCESS;
244 }
245
246
247 /* Unregister an announce */
248 static int announce_UnRegister( announce_handler_t *p_announce,
249                                 session_descriptor_t *p_session )
250 {
251     msg_Dbg( p_announce, "unregistering announce" );
252     if( p_announce->p_sap )
253         p_announce->p_sap->pf_del( p_announce->p_sap, p_session );
254     return VLC_SUCCESS;
255 }