Actions on cropping UI. This doesn't work yet, because I am unsure of the good way...
[vlc.git] / src / stream_output / announce.c
bloba8b383b8ed74065af163a4b1c1011ddb36342939
1 /*****************************************************************************
2 * announce.c : announce handler
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
5 * $Id$
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 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc/vlc.h>
32 #include <vlc_sout.h>
33 #include "stream_output.h"
35 #include <assert.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
47 } sap_method;
49 /****************************************************************************
50 * Sout-side functions
51 ****************************************************************************/
53 /**
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,
69 VLC_OBJECT_ANNOUNCE,
70 FIND_ANYWHERE );
71 if( !p_announce )
73 msg_Dbg( p_sout, "no announce handler found, creating one" );
74 p_announce = announce_HandlerCreate( VLC_OBJECT( p_sout ) );
75 if( !p_announce )
77 msg_Err( p_sout, "Creation failed" );
78 return NULL;
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 */
88 struct addrinfo *res;
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 );
100 return p_session;
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 )
113 int i_ret;
114 announce_handler_t *p_announce = (announce_handler_t*)
115 vlc_object_find( p_sout,
116 VLC_OBJECT_ANNOUNCE,
117 FIND_ANYWHERE );
118 if( !p_announce )
120 msg_Dbg( p_sout, "unable to remove announce: no announce handler" );
121 return VLC_ENOOBJ;
123 i_ret = announce_UnRegister( p_announce, p_session );
124 if( i_ret == 0 )
125 free( p_session );
127 vlc_object_release( p_announce );
129 return i_ret;
133 * \return the SAP announce method
135 announce_method_t * sout_SAPMethod (void)
137 return &sap_method;
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 );
161 if( !p_announce )
163 msg_Err( p_this, "out of memory" );
164 return NULL;
167 p_announce->p_sap = NULL;
168 vlc_object_attach( p_announce, p_this->p_libvlc);
170 return p_announce;
174 * Destroy a announce handler object
176 * \param p_announce the announce handler to destroy
177 * \return VLC_SUCCESS or an error
179 int announce_HandlerDestroy( announce_handler_t *p_announce )
181 if( p_announce->p_sap )
183 /* Exit the SAP */
184 vlc_object_release( p_announce->p_sap );
187 /* Free the structure */
188 vlc_object_release( p_announce );
190 return VLC_SUCCESS;
193 /* Register an announce */
194 static int announce_Register( announce_handler_t *p_announce,
195 session_descriptor_t *p_session,
196 announce_method_t *p_method )
198 if (p_method == NULL)
199 return VLC_EGENERIC;
201 msg_Dbg( p_announce, "registering announce");
202 if( p_method == &sap_method )
204 /* Do we already have a SAP announce handler ? */
205 if( !p_announce->p_sap )
207 sap_handler_t *p_sap = announce_SAPHandlerCreate( p_announce );
208 msg_Dbg( p_announce, "creating SAP announce handler");
209 if( !p_sap )
211 msg_Err( p_announce, "SAP handler creation failed" );
212 return VLC_ENOOBJ;
214 p_announce->p_sap = p_sap;
216 /* this will set p_session->p_sap for later deletion */
217 msg_Dbg( p_announce, "adding SAP session");
218 p_announce->p_sap->pf_add( p_announce->p_sap, p_session );
220 else
222 msg_Err( p_announce, "announce type unsupported" );
223 return VLC_EGENERIC;
225 return VLC_SUCCESS;
229 /* Unregister an announce */
230 static int announce_UnRegister( announce_handler_t *p_announce,
231 session_descriptor_t *p_session )
233 msg_Dbg( p_announce, "unregistering announce" );
234 if( p_announce->p_sap )
235 p_announce->p_sap->pf_del( p_announce->p_sap, p_session );
236 return VLC_SUCCESS;