1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.h,v 1.18 2003/12/07 17:09:33 gbazin Exp $
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 *****************************************************************************/
33 * i_allocated_size: size of allocated buffer
34 * p_allocated_buffer: where data has been allocated
36 * i_buffer_size: sizeof buffer from p_buffer
37 * p_buffer: where data begins
38 * i_size: size of valid data
41 #define SOUT_BUFFER_FLAGS_HEADER 0x0001
44 * Flags for muxer/access private usage.
46 #define SOUT_BUFFER_FLAGS_PRIVATE_MASK 0xffff0000
47 #define SOUT_BUFFER_FLAGS_PRIVATE_SHIFT 16
51 size_t i_allocated_size;
52 byte_t *p_allocated_buffer;
66 struct sout_buffer_t *p_next;
71 vlc_mutex_t lock; /* fifo data lock */
72 vlc_cond_t wait; /* fifo data conditional variable */
75 sout_buffer_t *p_first;
76 sout_buffer_t **pp_last;
79 typedef struct sout_stream_id_t sout_stream_id_t;
84 sout_instance_t *p_sout;
93 struct sout_packetizer_input_t
96 sout_instance_t *p_sout;
100 sout_stream_id_t *id;
104 #define SOUT_METHOD_NONE 0x00
105 #define SOUT_METHOD_FILE 0x10
106 #define SOUT_METHOD_NETWORK 0x20
108 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
109 struct sout_access_out_t
115 sout_instance_t *p_sout;
121 sout_access_out_sys_t *p_sys;
122 int (* pf_seek )( sout_access_out_t *,
124 int (* pf_write )( sout_access_out_t *,
129 * i_query parameter of pf_mux_capacity
131 /* SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME: p_args=NULL, p_answer=&boolean */
132 #define SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME 0x01
133 /* SOUT_MUX_CAP_GET_STREAMABLE: p_args=NULL, p_answer=&boolean */
134 #define SOUT_MUX_CAP_GET_STREAMABLE 0x02
135 /* SOUT_MUX_CAP_GET_ADD_STREAM_WAIT: p_args=NULL, p_answer=&boolean */
136 #define SOUT_MUX_CAP_GET_ADD_STREAM_WAIT 0x03
141 #define SOUT_MUX_CAP_ERR_OK 0x00
142 #define SOUT_MUX_CAP_ERR_UNKNOWN 0x01
143 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED 0x02
145 typedef struct sout_mux_sys_t sout_mux_sys_t;
151 sout_instance_t *p_sout;
156 sout_access_out_t *p_access;
159 int (* pf_capacity) ( sout_mux_t *,
160 int, void *, void *);
161 int (* pf_addstream )( sout_mux_t *,
163 int (* pf_delstream )( sout_mux_t *,
165 int (* pf_mux ) ( sout_mux_t * );
168 /* here are all inputs accepted by muxer */
170 sout_input_t **pp_inputs;
174 sout_mux_sys_t *p_sys;
177 /* creater private */
181 /* XXX private to stream_output.c */
182 /* if muxer doesn't support adding stream at any time then we first wait
183 * for stream then we refuse all stream and start muxing */
184 vlc_bool_t b_add_stream_any_time;
185 vlc_bool_t b_waiting_stream;
186 /* we wait one second after first stream added */
187 mtime_t i_add_stream_start;
200 typedef struct sout_stream_sys_t sout_stream_sys_t;
206 sout_instance_t *p_sout;
212 /* add, remove a stream */
213 sout_stream_id_t * (*pf_add) ( sout_stream_t *, es_format_t * );
214 int (*pf_del) ( sout_stream_t *, sout_stream_id_t * );
216 /* manage a packet */
217 int (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
220 sout_stream_sys_t *p_sys;
223 typedef struct sout_instance_sys_t sout_instance_sys_t;
224 struct sout_instance_t
232 int i_preheader; /* max over all muxer */
234 int i_padding; /* needed by some decoders */
237 sout_stream_t *p_stream;
240 sout_instance_sys_t *p_sys;
243 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
245 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
247 p_cfg = p_cfg->p_next;
253 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
255 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
257 p_cfg = p_cfg->p_next;
260 if( p_cfg && p_cfg->psz_value )
262 return( p_cfg->psz_value );
267 /*****************************************************************************
269 *****************************************************************************/
270 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
271 VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
272 VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
274 VLC_EXPORT( sout_fifo_t *, sout_FifoCreate, ( sout_instance_t * ) );
275 VLC_EXPORT( void, sout_FifoDestroy, ( sout_instance_t *, sout_fifo_t * ) );
276 VLC_EXPORT( void, sout_FifoFree, ( sout_instance_t *,sout_fifo_t * ) );
278 VLC_EXPORT( void, sout_FifoPut, ( sout_fifo_t *, sout_buffer_t* ) );
279 VLC_EXPORT( sout_buffer_t *, sout_FifoGet, ( sout_fifo_t * ) );
280 VLC_EXPORT( sout_buffer_t *, sout_FifoShow, ( sout_fifo_t * ) );
283 #define sout_InputNew( a, b ) __sout_InputNew( VLC_OBJECT(a), b )
284 VLC_EXPORT( sout_packetizer_input_t *, __sout_InputNew, ( vlc_object_t *, es_format_t * ) );
285 VLC_EXPORT( int, sout_InputDelete, ( sout_packetizer_input_t * ) );
286 VLC_EXPORT( int, sout_InputSendBuffer, ( sout_packetizer_input_t *, sout_buffer_t* ) );
288 VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
289 VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
290 VLC_EXPORT( int, sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
291 VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
292 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
293 VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
295 VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
296 VLC_EXPORT( void, sout_AccessOutDelete, ( sout_access_out_t * ) );
297 VLC_EXPORT( int, sout_AccessOutSeek, ( sout_access_out_t *, off_t ) );
298 VLC_EXPORT( int, sout_AccessOutWrite, ( sout_access_out_t *, sout_buffer_t * ) );
300 VLC_EXPORT( sout_mux_t *, sout_MuxNew, ( sout_instance_t*, char *, sout_access_out_t * ) );
301 VLC_EXPORT( sout_input_t *, sout_MuxAddStream, ( sout_mux_t *, es_format_t * ) );
302 VLC_EXPORT( void, sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
303 VLC_EXPORT( void, sout_MuxDelete, ( sout_mux_t * ) );
304 VLC_EXPORT( void, sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t *, sout_buffer_t * ) );
306 VLC_EXPORT( char *, sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
307 VLC_EXPORT( sout_stream_t *, sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
308 VLC_EXPORT( void, sout_stream_delete, ( sout_stream_t *p_stream ) );