1 /*****************************************************************************
2 * announce.c : announce handler
3 *****************************************************************************
4 * Copyright (C) 2002-2007 VLC authors and VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * 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 /****************************************************************************
40 ****************************************************************************/
42 static void sap_destroy (vlc_object_t
*p_this
)
44 libvlc_priv (p_this
->p_libvlc
)->p_sap
= NULL
;
47 #undef sout_AnnounceRegisterSDP
49 static vlc_mutex_t sap_mutex
= VLC_STATIC_MUTEX
;
52 * Registers a new session with the announce handler, using a pregenerated SDP
54 * \param obj a VLC object
55 * \param psz_sdp the SDP to register
56 * \param psz_dst session address (needed for SAP address auto detection)
57 * \return the new session descriptor structure
59 session_descriptor_t
*
60 sout_AnnounceRegisterSDP( vlc_object_t
*obj
, const char *psz_sdp
,
63 session_descriptor_t
*p_session
= calloc( 1, sizeof (*p_session
) );
67 p_session
->psz_sdp
= strdup( psz_sdp
);
69 /* GRUIK. We should not convert back-and-forth from string to numbers */
71 if (vlc_getaddrinfo (obj
, psz_dst
, 0, NULL
, &res
) == 0)
73 if (res
->ai_addrlen
<= sizeof (p_session
->addr
))
74 memcpy (&p_session
->addr
, res
->ai_addr
,
75 p_session
->addrlen
= res
->ai_addrlen
);
79 vlc_mutex_lock (&sap_mutex
);
80 sap_handler_t
*p_sap
= libvlc_priv (obj
->p_libvlc
)->p_sap
;
83 p_sap
= SAP_Create (VLC_OBJECT (obj
->p_libvlc
));
84 libvlc_priv (obj
->p_libvlc
)->p_sap
= p_sap
;
85 vlc_object_set_destructor ((vlc_object_t
*)p_sap
, sap_destroy
);
88 vlc_object_hold ((vlc_object_t
*)p_sap
);
89 vlc_mutex_unlock (&sap_mutex
);
94 msg_Dbg (obj
, "adding SAP session");
95 if (SAP_Add (p_sap
, p_session
))
97 vlc_mutex_lock (&sap_mutex
);
98 vlc_object_release ((vlc_object_t
*)p_sap
);
99 vlc_mutex_unlock (&sap_mutex
);
106 free (p_session
->psz_sdp
);
111 #undef sout_AnnounceUnRegister
113 * Unregisters an existing session
115 * \param obj a VLC object
116 * \param p_session the session descriptor
117 * \return VLC_SUCCESS or an error
119 int sout_AnnounceUnRegister( vlc_object_t
*obj
,
120 session_descriptor_t
*p_session
)
122 sap_handler_t
*p_sap
= libvlc_priv (obj
->p_libvlc
)->p_sap
;
124 msg_Dbg (obj
, "removing SAP session");
125 SAP_Del (p_sap
, p_session
);
127 vlc_mutex_lock (&sap_mutex
);
128 vlc_object_release ((vlc_object_t
*)p_sap
);
129 vlc_mutex_unlock (&sap_mutex
);
131 free (p_session
->psz_sdp
);