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"
38 struct announce_method_t
42 /****************************************************************************
44 ****************************************************************************/
46 static void sap_destroy (vlc_object_t *p_this)
48 libvlc_priv (p_this->p_libvlc)->p_sap = NULL;
51 #undef sout_AnnounceRegisterSDP
53 * Registers a new session with the announce handler, using a pregenerated SDP
55 * \param obj a VLC object
56 * \param psz_sdp the SDP to register
57 * \param psz_dst session address (needed for SAP address auto detection)
58 * \param p_method an announce method descriptor
59 * \return the new session descriptor structure
61 session_descriptor_t *
62 sout_AnnounceRegisterSDP( vlc_object_t *obj, const char *psz_sdp,
63 const char *psz_dst, announce_method_t *p_method )
65 assert (p_method == &sap_method);
68 session_descriptor_t *p_session = malloc (sizeof (*p_session));
73 memset( p_session, 0, sizeof( *p_session ) );
74 p_session->psz_sdp = strdup( psz_sdp );
76 /* GRUIK. We should not convert back-and-forth from string to numbers */
78 if (vlc_getaddrinfo (obj, psz_dst, 0, NULL, &res) == 0)
80 if (res->ai_addrlen <= sizeof (p_session->addr))
81 memcpy (&p_session->addr, res->ai_addr,
82 p_session->addrlen = res->ai_addrlen);
83 vlc_freeaddrinfo (res);
87 if (var_Create (obj->p_libvlc, "sap_mutex", VLC_VAR_MUTEX)
88 || var_Get (obj->p_libvlc, "sap_mutex", &lockval))
91 vlc_mutex_lock (lockval.p_address);
92 sap_handler_t *p_sap = libvlc_priv (obj->p_libvlc)->p_sap;
95 p_sap = SAP_Create (VLC_OBJECT (obj->p_libvlc));
96 libvlc_priv (obj->p_libvlc)->p_sap = p_sap;
97 vlc_object_set_destructor ((vlc_object_t *)p_sap, sap_destroy);
100 vlc_object_hold ((vlc_object_t *)p_sap);
101 vlc_mutex_unlock (lockval.p_address);
106 msg_Dbg (obj, "adding SAP session");
107 SAP_Add (p_sap, p_session );
111 free (p_session->psz_sdp);
116 #undef sout_AnnounceUnRegister
118 * Unregisters an existing session
120 * \param obj a VLC object
121 * \param p_session the session descriptor
122 * \return VLC_SUCCESS or an error
124 int sout_AnnounceUnRegister( vlc_object_t *obj,
125 session_descriptor_t *p_session )
127 sap_handler_t *p_sap = libvlc_priv (obj->p_libvlc)->p_sap;
129 msg_Dbg (obj, "removing SAP session");
130 SAP_Del (p_sap, p_session);
133 var_Create (obj->p_libvlc, "sap_mutex", VLC_VAR_MUTEX);
134 var_Get (obj->p_libvlc, "sap_mutex", &lockval);
135 vlc_mutex_lock (lockval.p_address);
136 vlc_object_release ((vlc_object_t *)p_sap);
137 vlc_mutex_unlock (lockval.p_address);
139 free (p_session->psz_sdp);
146 * \return the SAP announce method
148 announce_method_t * sout_SAPMethod (void)
153 void sout_MethodRelease (announce_method_t *m)
155 assert (m == &sap_method);