1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Eric Petit <titer@videolan.org>
10 * Jean-Paul Saman <jpsaman #_at_# m2x.nl>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * sout_instance_t: stream output thread descriptor
29 *****************************************************************************/
33 /****************************************************************************
34 * sout_instance_t: p_sout
35 ****************************************************************************/
36 struct sout_instance_t
43 /* meta data (Read only) XXX it won't be set before the first packet received */
46 int i_out_pace_nocontrol; /* count of output that can't control the space */
49 sout_stream_t *p_stream;
52 sout_instance_sys_t *p_sys;
55 /****************************************************************************
57 ****************************************************************************/
66 #define sout_CfgParse( a, b, c, d ) __sout_CfgParse( VLC_OBJECT(a), b, c, d )
67 VLC_EXPORT( void, __sout_CfgParse, ( vlc_object_t *, char *psz_prefix, const char **ppsz_options, sout_cfg_t * ) );
68 VLC_EXPORT( char *, sout_CfgCreate, ( char **, sout_cfg_t **, char * ) );
70 /****************************************************************************
71 * sout_stream_id_t: opaque (private for all sout_stream_t)
72 ****************************************************************************/
73 typedef struct sout_stream_id_t sout_stream_id_t;
75 /****************************************************************************
76 * sout_packetizer_input_t: p_sout <-> p_packetizer
77 ****************************************************************************/
78 struct sout_packetizer_input_t
80 sout_instance_t *p_sout;
87 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
88 VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
89 VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
91 VLC_EXPORT( sout_packetizer_input_t *, sout_InputNew,( sout_instance_t *, es_format_t * ) );
92 VLC_EXPORT( int, sout_InputDelete, ( sout_packetizer_input_t * ) );
93 VLC_EXPORT( int, sout_InputSendBuffer, ( sout_packetizer_input_t *, block_t* ) );
95 /****************************************************************************
97 ****************************************************************************/
98 struct sout_access_out_t
104 sout_instance_t *p_sout;
110 int64_t i_sent_bytes; ///< This is a "local" counter that is reset each
111 // time it is transferred to stats
114 sout_access_out_sys_t *p_sys;
115 int (*pf_seek)( sout_access_out_t *, off_t );
116 int (*pf_read)( sout_access_out_t *, block_t * );
117 int (*pf_write)( sout_access_out_t *, block_t * );
120 VLC_EXPORT( sout_access_out_t *,sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
121 VLC_EXPORT( void, sout_AccessOutDelete, ( sout_access_out_t * ) );
122 VLC_EXPORT( int, sout_AccessOutSeek, ( sout_access_out_t *, off_t ) );
123 VLC_EXPORT( int, sout_AccessOutRead, ( sout_access_out_t *, block_t * ) );
124 VLC_EXPORT( int, sout_AccessOutWrite, ( sout_access_out_t *, block_t * ) );
126 /****************************************************************************
128 ****************************************************************************/
134 sout_instance_t *p_sout;
139 sout_access_out_t *p_access;
141 int (*pf_addstream)( sout_mux_t *, sout_input_t * );
142 int (*pf_delstream)( sout_mux_t *, sout_input_t * );
143 int (*pf_mux) ( sout_mux_t * );
144 int (*pf_control) ( sout_mux_t *, int, va_list );
146 /* here are all inputs accepted by muxer */
148 sout_input_t **pp_inputs;
152 sout_mux_sys_t *p_sys;
154 /* XXX private to stream_output.c */
155 /* if muxer doesn't support adding stream at any time then we first wait
156 * for stream then we refuse all stream and start muxing */
157 vlc_bool_t b_add_stream_any_time;
158 vlc_bool_t b_waiting_stream;
159 /* we wait one second after first stream added */
160 mtime_t i_add_stream_start;
163 enum sout_mux_query_e
166 MUX_CAN_ADD_STREAM_WHILE_MUXING, /* arg1= vlc_bool_t *, res=cannot fail */
168 MUX_GET_ADD_STREAM_WAIT, /* arg1= vlc_bool_t *, res=cannot fail */
169 MUX_GET_MIME, /* arg1= char ** res=can fail */
174 sout_instance_t *p_sout;
177 block_fifo_t *p_fifo;
183 VLC_EXPORT( sout_mux_t *, sout_MuxNew, ( sout_instance_t*, char *, sout_access_out_t * ) );
184 VLC_EXPORT( sout_input_t *, sout_MuxAddStream, ( sout_mux_t *, es_format_t * ) );
185 VLC_EXPORT( void, sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
186 VLC_EXPORT( void, sout_MuxDelete, ( sout_mux_t * ) );
187 VLC_EXPORT( void, sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t *, block_t * ) );
189 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
194 va_start( args, i_query );
195 i_result = p_mux->pf_control( p_mux, i_query, args );
200 /****************************************************************************
202 ****************************************************************************/
208 sout_instance_t *p_sout;
214 /* Subpicture unit */
217 /* add, remove a stream */
218 sout_stream_id_t *(*pf_add)( sout_stream_t *, es_format_t * );
219 int (*pf_del)( sout_stream_t *, sout_stream_id_t * );
220 /* manage a packet */
221 int (*pf_send)( sout_stream_t *, sout_stream_id_t *, block_t* );
224 sout_stream_sys_t *p_sys;
227 VLC_EXPORT( sout_stream_t *, sout_StreamNew, ( sout_instance_t *, char *psz_chain ) );
228 VLC_EXPORT( void, sout_StreamDelete, ( sout_stream_t * ) );
230 static inline sout_stream_id_t *sout_StreamIdAdd( sout_stream_t *s, es_format_t *fmt )
232 return s->pf_add( s, fmt );
234 static inline int sout_StreamIdDel( sout_stream_t *s, sout_stream_id_t *id )
236 return s->pf_del( s, id );
238 static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, block_t *b )
240 return s->pf_send( s, id, b );
243 /****************************************************************************
244 * Announce handler mess
245 ****************************************************************************/
246 struct sap_session_t;
248 struct session_descriptor_t
254 int i_payload; /* SAP Payload type */
258 sap_session_t *p_sap; /* If we have a sap session, remember it */
263 #define METHOD_TYPE_SAP 1
265 struct announce_method_t
271 /* A SAP session descriptor, enqueued in the SAP handler queue */
277 sap_address_t *p_address;
279 /* Last and next send */
284 /* The SAP handler, running in a separate thread */
287 VLC_COMMON_MEMBERS /* needed to create a thread */
289 sap_session_t **pp_sessions;
290 sap_address_t **pp_addresses;
292 vlc_bool_t b_control;
297 int i_current_session;
299 int (*pf_add) ( sap_handler_t*, session_descriptor_t *);
300 int (*pf_del) ( sap_handler_t*, session_descriptor_t *);
302 /* private data, not in p_sys as there is one kind of sap_handler_t */
305 /* The main announce handler object */
306 struct announce_handler_t
310 sap_handler_t *p_sap;
316 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
318 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
320 p_cfg = p_cfg->p_next;
326 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
328 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
330 p_cfg = p_cfg->p_next;
333 if( p_cfg && p_cfg->psz_value )
335 return( p_cfg->psz_value );
341 /* Announce system */
342 VLC_EXPORT( int, sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
343 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,const char *, const char *, announce_method_t* ) );
344 VLC_EXPORT( int, sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
346 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
347 VLC_EXPORT(void, sout_AnnounceSessionDestroy, (session_descriptor_t *) );
348 VLC_EXPORT(announce_method_t*, sout_AnnounceMethodCreate, (int) );
350 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
351 announce_handler_t* __announce_HandlerCreate( vlc_object_t *);
353 /* Private functions for the announce handler */
354 int announce_HandlerDestroy( announce_handler_t * );
355 int announce_Register( announce_handler_t *p_announce,
356 session_descriptor_t *p_session,
357 announce_method_t *p_method );
358 int announce_UnRegister( announce_handler_t *p_announce,
359 session_descriptor_t *p_session );
361 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
362 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );