]> git.sesse.net Git - vlc/blob - include/stream_output.h
Put correct owner address in SAP-generated SDP
[vlc] / include / stream_output.h
1 /*****************************************************************************
2  * stream_output.h : stream output module
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *          Eric Petit <titer@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * sout_instance_t: stream output thread descriptor
28  *****************************************************************************/
29
30 #include "vlc_es.h"
31
32 /****************************************************************************
33  * sout_instance_t: p_sout
34  ****************************************************************************/
35 struct sout_instance_t
36 {
37     VLC_COMMON_MEMBERS
38
39     char *psz_sout;
40     char *psz_chain;
41
42     /* meta data (Read only) XXX it won't be set before the first packet received */
43     vlc_meta_t          *p_meta;
44
45     int                 i_out_pace_nocontrol;   /* count of output that can't control the space */
46
47     vlc_mutex_t         lock;
48     sout_stream_t       *p_stream;
49
50     /* sout private */
51     sout_instance_sys_t *p_sys;
52 };
53
54 /****************************************************************************
55  * sout_cfg_t:
56  ****************************************************************************/
57 struct sout_cfg_t
58 {
59     sout_cfg_t  *p_next;
60
61     char        *psz_name;
62     char        *psz_value;
63 };
64
65 #define sout_CfgParse( a, b, c, d ) __sout_CfgParse( VLC_OBJECT(a), b, c, d )
66 VLC_EXPORT( void,   __sout_CfgParse, ( vlc_object_t *, char *psz_prefix, const char **ppsz_options, sout_cfg_t * ) );
67 VLC_EXPORT( char *, sout_CfgCreate, ( char **, sout_cfg_t **, char * ) );
68
69 /****************************************************************************
70  * sout_stream_id_t: opaque (private for all sout_stream_t)
71  ****************************************************************************/
72 typedef struct sout_stream_id_t  sout_stream_id_t;
73
74 /****************************************************************************
75  * sout_packetizer_input_t: p_sout <-> p_packetizer
76  ****************************************************************************/
77 struct sout_packetizer_input_t
78 {
79     sout_instance_t     *p_sout;
80
81     es_format_t         *p_fmt;
82
83     sout_stream_id_t    *id;
84 };
85
86 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
87 VLC_EXPORT( sout_instance_t *,  __sout_NewInstance,  ( vlc_object_t *, char * ) );
88 VLC_EXPORT( void,               sout_DeleteInstance, ( sout_instance_t * ) );
89
90 VLC_EXPORT( sout_packetizer_input_t *, sout_InputNew,( sout_instance_t *, es_format_t * ) );
91 VLC_EXPORT( int,                sout_InputDelete,      ( sout_packetizer_input_t * ) );
92 VLC_EXPORT( int,                sout_InputSendBuffer,  ( sout_packetizer_input_t *, block_t* ) );
93
94 /****************************************************************************
95  * sout_access_out_t:
96  ****************************************************************************/
97 struct sout_access_out_t
98 {
99     VLC_COMMON_MEMBERS
100
101     module_t                *p_module;
102
103     sout_instance_t         *p_sout;
104
105     char                    *psz_access;
106     sout_cfg_t              *p_cfg;
107
108     char                    *psz_name;
109     sout_access_out_sys_t   *p_sys;
110     int                     (*pf_seek)( sout_access_out_t *, off_t );
111     int                     (*pf_read)( sout_access_out_t *, block_t * );
112     int                     (*pf_write)( sout_access_out_t *, block_t * );
113 };
114
115 VLC_EXPORT( sout_access_out_t *,sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
116 VLC_EXPORT( void,               sout_AccessOutDelete, ( sout_access_out_t * ) );
117 VLC_EXPORT( int,                sout_AccessOutSeek,   ( sout_access_out_t *, off_t ) );
118 VLC_EXPORT( int,                sout_AccessOutRead,   ( sout_access_out_t *, block_t * ) );
119 VLC_EXPORT( int,                sout_AccessOutWrite,  ( sout_access_out_t *, block_t * ) );
120
121 /****************************************************************************
122  * mux:
123  ****************************************************************************/
124 struct  sout_mux_t
125 {
126     VLC_COMMON_MEMBERS
127     module_t            *p_module;
128
129     sout_instance_t     *p_sout;
130
131     char                *psz_mux;
132     sout_cfg_t          *p_cfg;
133
134     sout_access_out_t   *p_access;
135
136     int                 (*pf_addstream)( sout_mux_t *, sout_input_t * );
137     int                 (*pf_delstream)( sout_mux_t *, sout_input_t * );
138     int                 (*pf_mux)      ( sout_mux_t * );
139     int                 (*pf_control)  ( sout_mux_t *, int, va_list );
140
141     /* here are all inputs accepted by muxer */
142     int                 i_nb_inputs;
143     sout_input_t        **pp_inputs;
144
145
146     /* mux private */
147     sout_mux_sys_t      *p_sys;
148
149     /* XXX private to stream_output.c */
150     /* if muxer doesn't support adding stream at any time then we first wait
151      *  for stream then we refuse all stream and start muxing */
152     vlc_bool_t  b_add_stream_any_time;
153     vlc_bool_t  b_waiting_stream;
154     /* we wait one second after first stream added */
155     mtime_t     i_add_stream_start;
156 };
157
158 enum sout_mux_query_e
159 {
160     /* capabilities */
161     MUX_CAN_ADD_STREAM_WHILE_MUXING,    /* arg1= vlc_bool_t *,      res=cannot fail */
162     /* properties */
163     MUX_GET_ADD_STREAM_WAIT,            /* arg1= vlc_bool_t *,      res=cannot fail */
164     MUX_GET_MIME,                       /* arg1= char **            res=can fail    */
165 };
166
167 struct sout_input_t
168 {
169     sout_instance_t *p_sout;
170
171     es_format_t     *p_fmt;
172     block_fifo_t    *p_fifo;
173
174     void            *p_sys;
175 };
176
177
178 VLC_EXPORT( sout_mux_t *,   sout_MuxNew,          ( sout_instance_t*, char *, sout_access_out_t * ) );
179 VLC_EXPORT( sout_input_t *, sout_MuxAddStream,    ( sout_mux_t *, es_format_t * ) );
180 VLC_EXPORT( void,           sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
181 VLC_EXPORT( void,           sout_MuxDelete,       ( sout_mux_t * ) );
182 VLC_EXPORT( void,           sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t  *, block_t * ) );
183
184 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
185 {
186     va_list args;
187     int     i_result;
188
189     va_start( args, i_query );
190     i_result = p_mux->pf_control( p_mux, i_query, args );
191     va_end( args );
192     return i_result;
193 }
194
195 /****************************************************************************
196  * sout_stream:
197  ****************************************************************************/
198 struct sout_stream_t
199 {
200     VLC_COMMON_MEMBERS
201
202     module_t          *p_module;
203     sout_instance_t   *p_sout;
204
205     char              *psz_name;
206     sout_cfg_t        *p_cfg;
207     char              *psz_next;
208
209     /* add, remove a stream */
210     sout_stream_id_t *(*pf_add)( sout_stream_t *, es_format_t * );
211     int               (*pf_del)( sout_stream_t *, sout_stream_id_t * );
212     /* manage a packet */
213     int               (*pf_send)( sout_stream_t *, sout_stream_id_t *, block_t* );
214
215     /* private */
216     sout_stream_sys_t *p_sys;
217 };
218
219 VLC_EXPORT( sout_stream_t *, sout_StreamNew, ( sout_instance_t *, char *psz_chain ) );
220 VLC_EXPORT( void,            sout_StreamDelete, ( sout_stream_t * ) );
221
222 static inline sout_stream_id_t *sout_StreamIdAdd( sout_stream_t *s, es_format_t *fmt )
223 {
224     return s->pf_add( s, fmt );
225 }
226 static inline int sout_StreamIdDel( sout_stream_t *s, sout_stream_id_t *id )
227 {
228     return s->pf_del( s, id );
229 }
230 static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, block_t *b )
231 {
232     return s->pf_send( s, id, b );
233 }
234
235 /****************************************************************************
236  * Announce handler mess
237  ****************************************************************************/
238 struct sap_session_t;
239
240 struct session_descriptor_t
241 {
242     char *psz_name;
243     char *psz_uri;
244     int i_port;
245     int i_ttl;
246     int i_payload;   /* SAP Payload type */
247
248     char *psz_group;
249
250     sap_session_t *p_sap; /* If we have a sap session, remember it */
251     char *psz_sdp;
252 };
253
254 #define METHOD_TYPE_SAP 1
255 #define METHOD_TYPE_SLP 2
256
257 struct announce_method_t
258 {
259     int i_type;
260 };
261
262
263 /* A SAP session descriptor, enqueued in the SAP handler queue */
264 struct sap_session_t
265 {
266     char          *psz_sdp;
267     uint8_t       *psz_data;
268     unsigned      i_length;
269     sap_address_t *p_address;
270
271     /* Last and next send */
272     mtime_t        i_last;
273     mtime_t        i_next;
274 };
275
276 /* The SAP handler, running in a separate thread */
277 struct sap_handler_t
278 {
279     VLC_COMMON_MEMBERS /* needed to create a thread */
280
281     sap_session_t **pp_sessions;
282     sap_address_t **pp_addresses;
283
284     vlc_bool_t b_control;
285
286     int i_sessions;
287     int i_addresses;
288
289     int i_current_session;
290
291     int (*pf_add)  ( sap_handler_t*, session_descriptor_t *);
292     int (*pf_del)  ( sap_handler_t*, session_descriptor_t *);
293
294     /* private data, not in p_sys as there is one kind of sap_handler_t */
295     vlc_iconv_t iconvHandle;
296 };
297
298 /* The main announce handler object */
299 struct announce_handler_t
300 {
301     VLC_COMMON_MEMBERS
302
303     sap_handler_t *p_sap;
304 };
305
306 /* End */
307
308
309 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
310 {
311     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
312     {
313         p_cfg = p_cfg->p_next;
314     }
315
316     return p_cfg;
317 }
318
319 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
320 {
321     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
322     {
323         p_cfg = p_cfg->p_next;
324     }
325
326     if( p_cfg && p_cfg->psz_value )
327     {
328         return( p_cfg->psz_value );
329     }
330
331     return NULL;
332 }
333
334 /* Announce system */
335 VLC_EXPORT( int,                sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
336 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,const char *, announce_method_t* ) );
337 VLC_EXPORT( int,                sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
338
339 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
340 VLC_EXPORT(void,                 sout_AnnounceSessionDestroy, (session_descriptor_t *) );
341 VLC_EXPORT(announce_method_t*,   sout_AnnounceMethodCreate, (int) );
342
343 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
344 announce_handler_t*  __announce_HandlerCreate( vlc_object_t *);
345
346 /* Private functions for the announce handler */
347 int announce_HandlerDestroy( announce_handler_t * );
348 int announce_Register( announce_handler_t *p_announce,
349                 session_descriptor_t *p_session,
350                 announce_method_t *p_method );
351 int announce_UnRegister( announce_handler_t *p_announce,
352                 session_descriptor_t *p_session );
353
354 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
355 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );