1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.h,v 1.22 2004/03/03 11:12:08 massiot 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
50 * Flags originating from block_t (FIXME: this is temporary).
52 #define SOUT_BUFFER_FLAGS_BLOCK_MASK 0x0000ff00
53 #define SOUT_BUFFER_FLAGS_BLOCK_SHIFT 8
57 size_t i_allocated_size;
58 byte_t *p_allocated_buffer;
72 struct sout_buffer_t *p_next;
77 vlc_mutex_t lock; /* fifo data lock */
78 vlc_cond_t wait; /* fifo data conditional variable */
81 sout_buffer_t *p_first;
82 sout_buffer_t **pp_last;
85 typedef struct sout_stream_id_t sout_stream_id_t;
90 sout_instance_t *p_sout;
99 struct sout_packetizer_input_t
102 sout_instance_t *p_sout;
106 sout_stream_id_t *id;
110 #define SOUT_METHOD_NONE 0x00
111 #define SOUT_METHOD_FILE 0x10
112 #define SOUT_METHOD_NETWORK 0x20
114 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
115 struct sout_access_out_t
121 sout_instance_t *p_sout;
127 sout_access_out_sys_t *p_sys;
128 int (* pf_seek )( sout_access_out_t *,
130 int (* pf_read )( sout_access_out_t *,
132 int (* pf_write )( sout_access_out_t *,
137 * i_query parameter of pf_mux_capacity
139 /* SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME: p_args=NULL, p_answer=&boolean */
140 #define SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME 0x01
141 /* SOUT_MUX_CAP_GET_STREAMABLE: p_args=NULL, p_answer=&boolean */
142 #define SOUT_MUX_CAP_GET_STREAMABLE 0x02
143 /* SOUT_MUX_CAP_GET_ADD_STREAM_WAIT: p_args=NULL, p_answer=&boolean */
144 #define SOUT_MUX_CAP_GET_ADD_STREAM_WAIT 0x03
149 #define SOUT_MUX_CAP_ERR_OK 0x00
150 #define SOUT_MUX_CAP_ERR_UNKNOWN 0x01
151 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED 0x02
153 typedef struct sout_mux_sys_t sout_mux_sys_t;
159 sout_instance_t *p_sout;
164 sout_access_out_t *p_access;
167 int (* pf_capacity) ( sout_mux_t *,
168 int, void *, void *);
169 int (* pf_addstream )( sout_mux_t *,
171 int (* pf_delstream )( sout_mux_t *,
173 int (* pf_mux ) ( sout_mux_t * );
176 /* here are all inputs accepted by muxer */
178 sout_input_t **pp_inputs;
182 sout_mux_sys_t *p_sys;
185 /* creater private */
189 /* XXX private to stream_output.c */
190 /* if muxer doesn't support adding stream at any time then we first wait
191 * for stream then we refuse all stream and start muxing */
192 vlc_bool_t b_add_stream_any_time;
193 vlc_bool_t b_waiting_stream;
194 /* we wait one second after first stream added */
195 mtime_t i_add_stream_start;
208 typedef struct sout_stream_sys_t sout_stream_sys_t;
214 sout_instance_t *p_sout;
220 /* add, remove a stream */
221 sout_stream_id_t * (*pf_add) ( sout_stream_t *, es_format_t * );
222 int (*pf_del) ( sout_stream_t *, sout_stream_id_t * );
224 /* manage a packet */
225 int (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
228 sout_stream_sys_t *p_sys;
231 typedef struct sout_instance_sys_t sout_instance_sys_t;
232 struct sout_instance_t
240 int i_preheader; /* max over all muxer */
242 int i_padding; /* needed by some decoders */
245 sout_stream_t *p_stream;
248 sout_instance_sys_t *p_sys;
251 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
253 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
255 p_cfg = p_cfg->p_next;
261 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
263 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
265 p_cfg = p_cfg->p_next;
268 if( p_cfg && p_cfg->psz_value )
270 return( p_cfg->psz_value );
275 /*****************************************************************************
277 *****************************************************************************/
278 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
279 VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
280 VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
282 VLC_EXPORT( sout_fifo_t *, sout_FifoCreate, ( sout_instance_t * ) );
283 VLC_EXPORT( void, sout_FifoDestroy, ( sout_instance_t *, sout_fifo_t * ) );
284 VLC_EXPORT( void, sout_FifoFree, ( sout_instance_t *,sout_fifo_t * ) );
286 VLC_EXPORT( void, sout_FifoPut, ( sout_fifo_t *, sout_buffer_t* ) );
287 VLC_EXPORT( sout_buffer_t *, sout_FifoGet, ( sout_fifo_t * ) );
288 VLC_EXPORT( sout_buffer_t *, sout_FifoShow, ( sout_fifo_t * ) );
291 VLC_EXPORT( sout_packetizer_input_t *, sout_InputNew,( sout_instance_t *, es_format_t * ) );
292 VLC_EXPORT( int, sout_InputDelete, ( sout_packetizer_input_t * ) );
293 VLC_EXPORT( int, sout_InputSendBuffer, ( sout_packetizer_input_t *, sout_buffer_t* ) );
295 VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
296 VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
297 VLC_EXPORT( int, sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
298 VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
299 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
300 VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
302 VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
303 VLC_EXPORT( void, sout_AccessOutDelete, ( sout_access_out_t * ) );
304 VLC_EXPORT( int, sout_AccessOutSeek, ( sout_access_out_t *, off_t ) );
305 VLC_EXPORT( int, sout_AccessOutRead, ( sout_access_out_t *, sout_buffer_t * ) );
306 VLC_EXPORT( int, sout_AccessOutWrite, ( sout_access_out_t *, sout_buffer_t * ) );
308 VLC_EXPORT( sout_mux_t *, sout_MuxNew, ( sout_instance_t*, char *, sout_access_out_t * ) );
309 VLC_EXPORT( sout_input_t *, sout_MuxAddStream, ( sout_mux_t *, es_format_t * ) );
310 VLC_EXPORT( void, sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
311 VLC_EXPORT( void, sout_MuxDelete, ( sout_mux_t * ) );
312 VLC_EXPORT( void, sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t *, sout_buffer_t * ) );
314 VLC_EXPORT( char *, sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
315 VLC_EXPORT( sout_stream_t *, sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
316 VLC_EXPORT( void, sout_stream_delete, ( sout_stream_t *p_stream ) );