1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.h,v 1.11 2003/07/31 19:14:59 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 * Flags for muxer/access private usage.
44 #define SOUT_BUFFER_FLAGS_PRIVATE_MASK 0xffff0000
45 #define SOUT_BUFFER_FLAGS_PRIVATE_SHIFT 16
49 size_t i_allocated_size;
50 byte_t *p_allocated_buffer;
64 struct sout_buffer_t *p_next;
70 vlc_fourcc_t i_fourcc;
83 uint8_t *p_extra_data;
89 vlc_mutex_t lock; /* fifo data lock */
90 vlc_cond_t wait; /* fifo data conditional variable */
93 sout_buffer_t *p_first;
94 sout_buffer_t **pp_last;
97 typedef struct sout_stream_id_t sout_stream_id_t;
102 sout_instance_t *p_sout;
104 sout_format_t *p_fmt;
111 struct sout_packetizer_input_t
114 sout_instance_t *p_sout;
116 sout_format_t *p_fmt;
118 sout_stream_id_t *id;
122 #define SOUT_METHOD_NONE 0x00
123 #define SOUT_METHOD_FILE 0x10
124 #define SOUT_METHOD_NETWORK 0x20
126 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
127 struct sout_access_out_t
133 sout_instance_t *p_sout;
139 sout_access_out_sys_t *p_sys;
140 int (* pf_seek )( sout_access_out_t *,
142 int (* pf_write )( sout_access_out_t *,
146 * i_query parameter of pf_mux_capacity
148 /* SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME: p_args=NULL, p_answer=&boolean */
149 #define SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME 0x01
150 /* SOUT_MUX_CAP_GET_STREAMABLE: p_args=NULL, p_answer=&boolean */
151 #define SOUT_MUX_CAP_GET_STREAMABLE 0x02
155 #define SOUT_MUX_CAP_ERR_OK 0x00
156 #define SOUT_MUX_CAP_ERR_UNKNOWN 0x01
157 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED 0x02
159 typedef struct sout_mux_sys_t sout_mux_sys_t;
165 sout_instance_t *p_sout;
170 sout_access_out_t *p_access;
173 int (* pf_capacity) ( sout_mux_t *,
174 int, void *, void *);
175 int (* pf_addstream )( sout_mux_t *,
177 int (* pf_delstream )( sout_mux_t *,
179 int (* pf_mux ) ( sout_mux_t * );
182 /* here are all inputs accepted by muxer */
184 sout_input_t **pp_inputs;
188 sout_mux_sys_t *p_sys;
190 // /* creater private */
191 // void *p_sys_owner;
193 /* XXX private to stream_output.c */
194 /* if muxer doesn't support adding stream at any time then we first wait
195 * for stream then we refuse all stream and start muxing */
196 vlc_bool_t b_add_stream_any_time;
197 vlc_bool_t b_waiting_stream;
198 /* we wait one second after first stream added */
199 mtime_t i_add_stream_start;
212 typedef struct sout_stream_sys_t sout_stream_sys_t;
218 sout_instance_t *p_sout;
224 /* add, remove a stream */
225 sout_stream_id_t * (*pf_add) ( sout_stream_t *, sout_format_t * );
226 int (*pf_del) ( sout_stream_t *, sout_stream_id_t * );
228 /* manage a packet */
229 int (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
232 sout_stream_sys_t *p_sys;
235 typedef struct sout_instance_sys_t sout_instance_sys_t;
236 struct sout_instance_t
244 int i_preheader; /* max over all muxer */
247 sout_stream_t *p_stream;
250 sout_instance_sys_t *p_sys;
254 #define TAB_APPEND( count, tab, p ) \
257 (tab) = realloc( (tab), sizeof( void ** ) * ( (count) + 1 ) ); \
261 (tab) = malloc( sizeof( void ** ) ); \
263 (void**)(tab)[(count)] = (void*)(p); \
266 #define TAB_FIND( count, tab, p, index ) \
270 for( _i_ = 0; _i_ < (count); _i_++ ) \
272 if((void**)(tab)[_i_]==(void*)(p)) \
280 #define TAB_REMOVE( count, tab, p ) \
283 TAB_FIND( count, tab, p, i_index ); \
288 memmove( ((void**)tab + i_index), \
289 ((void**)tab + i_index+1), \
290 ( (count) - i_index - 1 ) * sizeof( void* ) );\
301 static inline sout_cfg_t *sout_cfg_find( 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;
311 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
313 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
315 p_cfg = p_cfg->p_next;
318 if( p_cfg && p_cfg->psz_value )
320 return( p_cfg->psz_value );
325 /*****************************************************************************
327 *****************************************************************************/
328 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
329 VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
330 VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
332 VLC_EXPORT( sout_fifo_t *, sout_FifoCreate, ( sout_instance_t * ) );
333 VLC_EXPORT( void, sout_FifoDestroy, ( sout_instance_t *, sout_fifo_t * ) );
334 VLC_EXPORT( void, sout_FifoFree, ( sout_instance_t *,sout_fifo_t * ) );
336 VLC_EXPORT( void, sout_FifoPut, ( sout_fifo_t *, sout_buffer_t* ) );
337 VLC_EXPORT( sout_buffer_t *, sout_FifoGet, ( sout_fifo_t * ) );
338 VLC_EXPORT( sout_buffer_t *, sout_FifoShow, ( sout_fifo_t * ) );
341 #define sout_InputNew( a, b ) __sout_InputNew( VLC_OBJECT(a), b )
342 VLC_EXPORT( sout_packetizer_input_t *, __sout_InputNew, ( vlc_object_t *, sout_format_t * ) );
343 VLC_EXPORT( int, sout_InputDelete, ( sout_packetizer_input_t * ) );
344 VLC_EXPORT( int, sout_InputSendBuffer, ( sout_packetizer_input_t *, sout_buffer_t* ) );
346 VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
347 VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
348 VLC_EXPORT( int, sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
349 VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
350 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
351 VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
353 VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
354 VLC_EXPORT( void, sout_AccessOutDelete, ( sout_access_out_t * ) );
355 VLC_EXPORT( int, sout_AccessOutSeek, ( sout_access_out_t *, off_t ) );
356 VLC_EXPORT( int, sout_AccessOutWrite, ( sout_access_out_t *, sout_buffer_t * ) );
358 VLC_EXPORT( sout_mux_t *, sout_MuxNew, ( sout_instance_t*, char *, sout_access_out_t * ) );
359 VLC_EXPORT( sout_input_t *, sout_MuxAddStream, ( sout_mux_t *, sout_format_t * ) );
360 VLC_EXPORT( void, sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
361 VLC_EXPORT( void, sout_MuxDelete, ( sout_mux_t * ) );
362 VLC_EXPORT( void, sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t *, sout_buffer_t * ) );
364 VLC_EXPORT( char *, sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
365 VLC_EXPORT( sout_stream_t *, sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
366 VLC_EXPORT( void, sout_stream_delete, ( sout_stream_t *p_stream ) );