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;
52 * Registers a new session with the announce handler, using a pregenerated SDP
54 * \param p_sout a sout instance structure
55 * \param psz_sdp the SDP to register
56 * \param psz_dst session address (needed for SAP address auto detection)
57 * \param p_method an announce method descriptor
58 * \return the new session descriptor structure
60 session_descriptor_t *
61 sout_AnnounceRegisterSDP( sout_instance_t *p_sout, const char *psz_sdp,
62 const char *psz_dst, announce_method_t *p_method )
64 assert (p_method == &sap_method);
67 session_descriptor_t *p_session = malloc (sizeof (*p_session));
72 memset( p_session, 0, sizeof( *p_session ) );
73 p_session->psz_sdp = strdup( psz_sdp );
75 /* GRUIK. We should not convert back-and-forth from string to numbers */
77 if (vlc_getaddrinfo (VLC_OBJECT (p_sout), psz_dst, 0, NULL, &res) == 0)
79 if (res->ai_addrlen <= sizeof (p_session->addr))
80 memcpy (&p_session->addr, res->ai_addr,
81 p_session->addrlen = res->ai_addrlen);
82 vlc_freeaddrinfo (res);
86 if (var_Create (p_sout->p_libvlc, "sap_mutex", VLC_VAR_MUTEX)
87 || var_Get (p_sout->p_libvlc, "sap_mutex", &lockval))
90 vlc_mutex_lock (lockval.p_address);
91 sap_handler_t *p_sap = libvlc_priv (p_sout->p_libvlc)->p_sap;
94 p_sap = SAP_Create (VLC_OBJECT (p_sout->p_libvlc));
95 libvlc_priv (p_sout->p_libvlc)->p_sap = p_sap;
96 vlc_object_set_destructor ((vlc_object_t *)p_sap, sap_destroy);
99 vlc_object_yield ((vlc_object_t *)p_sap);
100 vlc_mutex_unlock (lockval.p_address);
105 msg_Dbg (p_sout, "adding SAP session");
106 SAP_Add (p_sap, p_session );
110 free (p_session->psz_sdp);
116 * Unregisters an existing session
118 * \param p_sout a sout instance structure
119 * \param p_session the session descriptor
120 * \return VLC_SUCCESS or an error
122 int sout_AnnounceUnRegister( sout_instance_t *p_sout,
123 session_descriptor_t *p_session )
125 sap_handler_t *p_sap = libvlc_priv (p_sout->p_libvlc)->p_sap;
127 msg_Dbg (p_sout, "removing SAP session");
128 SAP_Del (p_sap, p_session);
131 var_Create (p_sout->p_libvlc, "sap_mutex", VLC_VAR_MUTEX);
132 var_Get (p_sout->p_libvlc, "sap_mutex", &lockval);
133 vlc_mutex_lock (lockval.p_address);
134 vlc_object_release ((vlc_object_t *)p_sap);
135 vlc_mutex_unlock (lockval.p_address);
137 free (p_session->psz_sdp);
144 * \return the SAP announce method
146 announce_method_t * sout_SAPMethod (void)
151 void sout_MethodRelease (announce_method_t *m)
153 assert (m == &sap_method);