1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Eric Petit <titer@videolan.org>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
27 * sout_instance_t: stream output thread descriptor
28 *****************************************************************************/
32 /****************************************************************************
33 * sout_instance_t: p_sout
34 ****************************************************************************/
35 struct sout_instance_t
42 /* meta data (Read only) XXX it won't be set before the first packet received */
45 int i_out_pace_nocontrol; /* count of output that can't control the space */
48 sout_stream_t *p_stream;
51 sout_instance_sys_t *p_sys;
54 /****************************************************************************
56 ****************************************************************************/
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 * ) );
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;
74 /****************************************************************************
75 * sout_packetizer_input_t: p_sout <-> p_packetizer
76 ****************************************************************************/
77 struct sout_packetizer_input_t
79 sout_instance_t *p_sout;
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 * ) );
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* ) );
94 /****************************************************************************
96 ****************************************************************************/
97 struct sout_access_out_t
103 sout_instance_t *p_sout;
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 * );
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 * ) );
121 /****************************************************************************
123 ****************************************************************************/
129 sout_instance_t *p_sout;
134 sout_access_out_t *p_access;
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 );
141 /* here are all inputs accepted by muxer */
143 sout_input_t **pp_inputs;
147 sout_mux_sys_t *p_sys;
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;
158 enum sout_mux_query_e
161 MUX_CAN_ADD_STREAM_WHILE_MUXING, /* arg1= vlc_bool_t *, res=cannot fail */
163 MUX_GET_ADD_STREAM_WAIT, /* arg1= vlc_bool_t *, res=cannot fail */
164 MUX_GET_MIME, /* arg1= char ** res=can fail */
169 sout_instance_t *p_sout;
172 block_fifo_t *p_fifo;
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 * ) );
184 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
189 va_start( args, i_query );
190 i_result = p_mux->pf_control( p_mux, i_query, args );
195 /****************************************************************************
197 ****************************************************************************/
203 sout_instance_t *p_sout;
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* );
216 sout_stream_sys_t *p_sys;
219 VLC_EXPORT( sout_stream_t *, sout_StreamNew, ( sout_instance_t *, char *psz_chain ) );
220 VLC_EXPORT( void, sout_StreamDelete, ( sout_stream_t * ) );
222 static inline sout_stream_id_t *sout_StreamIdAdd( sout_stream_t *s, es_format_t *fmt )
224 return s->pf_add( s, fmt );
226 static inline int sout_StreamIdDel( sout_stream_t *s, sout_stream_id_t *id )
228 return s->pf_del( s, id );
230 static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, block_t *b )
232 return s->pf_send( s, id, b );
235 /****************************************************************************
236 * Announce handler mess
237 ****************************************************************************/
238 struct sap_session_t;
240 struct session_descriptor_t
246 int i_payload; /* SAP Payload type */
250 sap_session_t *p_sap; /* If we have a sap session, remember it */
254 #define METHOD_TYPE_SAP 1
255 #define METHOD_TYPE_SLP 2
257 struct announce_method_t
263 char *psz_address; /* If we use a custom address */
268 /* SAP Specific structures */
271 #define SAP_IDLE ((mtime_t)(0.100*CLOCK_FREQ))
272 #define SAP_MAX_BUFFER 65534
273 #define MIN_INTERVAL 2
274 #define MAX_INTERVAL 300
276 /* A SAP announce address. For each of these, we run the
277 * control flow algorithm */
283 int i_rfd; /* Read socket */
284 int i_wfd; /* Write socket */
286 /* Used for flow control */
288 vlc_bool_t b_enabled;
295 /* A SAP session descriptor, enqueued in the SAP handler queue */
301 sap_address_t *p_address;
303 /* Last and next send */
308 /* The SAP handler, running in a separate thread */
311 VLC_COMMON_MEMBERS /* needed to create a thread */
313 sap_session_t **pp_sessions;
314 sap_address_t **pp_addresses;
316 vlc_bool_t b_control;
321 int i_current_session;
323 int (*pf_add) ( sap_handler_t*, session_descriptor_t *,announce_method_t*);
324 int (*pf_del) ( sap_handler_t*, session_descriptor_t *);
326 /* private data, not in p_sys as there is one kind of sap_handler_t */
327 vlc_iconv_t iconvHandle;
330 /* The main announce handler object */
331 struct announce_handler_t
335 sap_handler_t *p_sap;
341 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
343 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
345 p_cfg = p_cfg->p_next;
351 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
353 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
355 p_cfg = p_cfg->p_next;
358 if( p_cfg && p_cfg->psz_value )
360 return( p_cfg->psz_value );
366 /* Announce system */
367 VLC_EXPORT( int, sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
368 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,char *, announce_method_t* ) );
369 VLC_EXPORT( int, sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
371 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
372 VLC_EXPORT(void, sout_AnnounceSessionDestroy, (session_descriptor_t *) );
373 VLC_EXPORT(announce_method_t*, sout_AnnounceMethodCreate, (int) );
375 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
376 announce_handler_t* __announce_HandlerCreate( vlc_object_t *);
378 /* Private functions for the announce handler */
379 int announce_HandlerDestroy( announce_handler_t * );
380 int announce_Register( announce_handler_t *p_announce,
381 session_descriptor_t *p_session,
382 announce_method_t *p_method );
383 int announce_UnRegister( announce_handler_t *p_announce,
384 session_descriptor_t *p_session );
386 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
387 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );