1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.h,v 1.10 2003/04/13 20:00:20 fenrir 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 *****************************************************************************/
31 * i_allocated_size: size of allocated buffer
32 * p_allocated_buffer: where data has been allocated
34 * i_buffer_size: sizeof buffer from p_buffer
35 * p_buffer: where data begins
36 * i_size: size of valid data
39 #define SOUT_BUFFER_FLAGS_HEADER 0x0001
42 size_t i_allocated_size;
43 byte_t *p_allocated_buffer;
57 struct sout_buffer_t *p_next;
63 vlc_fourcc_t i_fourcc;
76 uint8_t *p_extra_data;
82 vlc_mutex_t lock; /* fifo data lock */
83 vlc_cond_t wait; /* fifo data conditional variable */
86 sout_buffer_t *p_first;
87 sout_buffer_t **pp_last;
90 typedef struct sout_stream_id_t sout_stream_id_t;
95 sout_instance_t *p_sout;
104 struct sout_packetizer_input_t
107 sout_instance_t *p_sout;
109 sout_format_t *p_fmt;
111 sout_stream_id_t *id;
115 #define SOUT_METHOD_NONE 0x00
116 #define SOUT_METHOD_FILE 0x10
117 #define SOUT_METHOD_NETWORK 0x20
119 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
120 struct sout_access_out_t
126 sout_instance_t *p_sout;
130 sout_access_out_sys_t *p_sys;
131 int (* pf_seek )( sout_access_out_t *,
133 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
146 #define SOUT_MUX_CAP_ERR_OK 0x00
147 #define SOUT_MUX_CAP_ERR_UNKNOWN 0x01
148 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED 0x02
150 typedef struct sout_mux_sys_t sout_mux_sys_t;
156 sout_instance_t *p_sout;
160 sout_access_out_t *p_access;
163 int (* pf_capacity) ( sout_mux_t *,
164 int, void *, void *);
165 int (* pf_addstream )( sout_mux_t *,
167 int (* pf_delstream )( sout_mux_t *,
169 int (* pf_mux ) ( sout_mux_t * );
172 /* here are all inputs accepted by muxer */
174 sout_input_t **pp_inputs;
178 sout_mux_sys_t *p_sys;
180 // /* creater private */
181 // void *p_sys_owner;
183 /* XXX private to stream_output.c */
184 /* if muxer doesn't support adding stream at any time then we first wait
185 * for stream then we refuse all stream and start muxing */
186 vlc_bool_t b_add_stream_any_time;
187 vlc_bool_t b_waiting_stream;
188 /* we wait one second after first stream added */
189 mtime_t i_add_stream_start;
202 typedef struct sout_stream_sys_t sout_stream_sys_t;
208 sout_instance_t *p_sout;
214 /* add, remove a stream */
215 sout_stream_id_t * (*pf_add) ( sout_stream_t *, sout_format_t * );
216 int (*pf_del) ( sout_stream_t *, sout_stream_id_t * );
218 /* manage a packet */
219 int (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
222 sout_stream_sys_t *p_sys;
225 typedef struct sout_instance_sys_t sout_instance_sys_t;
226 struct sout_instance_t
234 int i_preheader; /* max over all muxer */
237 sout_stream_t *p_stream;
240 sout_instance_sys_t *p_sys;
244 #define TAB_APPEND( count, tab, p ) \
247 (tab) = realloc( (tab), sizeof( void ** ) * ( (count) + 1 ) ); \
251 (tab) = malloc( sizeof( void ** ) ); \
253 (void**)(tab)[(count)] = (void*)(p); \
256 #define TAB_FIND( count, tab, p, index ) \
260 for( _i_ = 0; _i_ < (count); _i_++ ) \
262 if((void**)(tab)[_i_]==(void*)(p)) \
270 #define TAB_REMOVE( count, tab, p ) \
273 TAB_FIND( count, tab, p, i_index ); \
278 memmove( ((void**)tab + i_index), \
279 ((void**)tab + i_index+1), \
280 ( (count) - i_index - 1 ) * sizeof( void* ) );\
291 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
293 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
295 p_cfg = p_cfg->p_next;
301 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
303 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
305 p_cfg = p_cfg->p_next;
308 if( p_cfg && p_cfg->psz_value )
310 return( p_cfg->psz_value );
315 /*****************************************************************************
317 *****************************************************************************/
318 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
319 VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
320 VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
322 VLC_EXPORT( sout_fifo_t *, sout_FifoCreate, ( sout_instance_t * ) );
323 VLC_EXPORT( void, sout_FifoDestroy, ( sout_instance_t *, sout_fifo_t * ) );
324 VLC_EXPORT( void, sout_FifoFree, ( sout_instance_t *,sout_fifo_t * ) );
326 VLC_EXPORT( void, sout_FifoPut, ( sout_fifo_t *, sout_buffer_t* ) );
327 VLC_EXPORT( sout_buffer_t *, sout_FifoGet, ( sout_fifo_t * ) );
328 VLC_EXPORT( sout_buffer_t *, sout_FifoShow, ( sout_fifo_t * ) );
331 #define sout_InputNew( a, b ) __sout_InputNew( VLC_OBJECT(a), b )
332 VLC_EXPORT( sout_packetizer_input_t *, __sout_InputNew, ( vlc_object_t *, sout_format_t * ) );
333 VLC_EXPORT( int, sout_InputDelete, ( sout_packetizer_input_t * ) );
334 VLC_EXPORT( int, sout_InputSendBuffer, ( sout_packetizer_input_t *, sout_buffer_t* ) );
336 VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
337 VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
338 VLC_EXPORT( int, sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
339 VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
340 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
341 VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
343 VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
344 VLC_EXPORT( void, sout_AccessOutDelete, ( sout_access_out_t * ) );
345 VLC_EXPORT( int, sout_AccessOutSeek, ( sout_access_out_t *, off_t ) );
346 VLC_EXPORT( int, sout_AccessOutWrite, ( sout_access_out_t *, sout_buffer_t * ) );
348 VLC_EXPORT( sout_mux_t *, sout_MuxNew, ( sout_instance_t*, char *, sout_access_out_t * ) );
349 VLC_EXPORT( sout_input_t *, sout_MuxAddStream, ( sout_mux_t *, sout_format_t * ) );
350 VLC_EXPORT( void, sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
351 VLC_EXPORT( void, sout_MuxDelete, ( sout_mux_t * ) );
352 VLC_EXPORT( void, sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t *, sout_buffer_t * ) );
354 VLC_EXPORT( char *, sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
355 VLC_EXPORT( sout_stream_t *, sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
356 VLC_EXPORT( void, sout_stream_delete, ( sout_stream_t *p_stream ) );