]> git.sesse.net Git - vlc/blob - include/stream_output.h
* src/input/input_dec.c: Copy block_t::i_flags to sout_buffer_t::i_flags
[vlc] / include / stream_output.h
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 $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *          Eric Petit <titer@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * sout_instance_t: stream output thread descriptor
28  *****************************************************************************/
29
30 #include "vlc_es.h"
31
32 /*
33  * i_allocated_size: size of allocated buffer
34  * p_allocated_buffer: where data has been allocated
35  *
36  * i_buffer_size: sizeof buffer from p_buffer
37  * p_buffer: where data begins
38  * i_size: size of valid data
39  *
40  */
41 #define SOUT_BUFFER_FLAGS_HEADER    0x0001
42
43 /*
44  * Flags for muxer/access private usage.
45  */
46 #define SOUT_BUFFER_FLAGS_PRIVATE_MASK  0xffff0000
47 #define SOUT_BUFFER_FLAGS_PRIVATE_SHIFT 16
48
49 /*
50  * Flags originating from block_t (FIXME: this is temporary).
51  */
52 #define SOUT_BUFFER_FLAGS_BLOCK_MASK    0x0000ff00
53 #define SOUT_BUFFER_FLAGS_BLOCK_SHIFT   8
54
55 struct sout_buffer_t
56 {
57     size_t                  i_allocated_size;
58     byte_t                  *p_allocated_buffer;
59
60     size_t                  i_buffer_size;
61     byte_t                  *p_buffer;
62
63     size_t                  i_size;
64     mtime_t                 i_length;
65
66     mtime_t                 i_dts;
67     mtime_t                 i_pts;
68
69     uint32_t                i_flags;
70     int                     i_bitrate;
71
72     struct sout_buffer_t    *p_next;
73 };
74
75 struct sout_fifo_t
76 {
77     vlc_mutex_t         lock;                         /* fifo data lock */
78     vlc_cond_t          wait;         /* fifo data conditional variable */
79
80     int                 i_depth;
81     sout_buffer_t       *p_first;
82     sout_buffer_t       **pp_last;
83 };
84
85 typedef struct sout_stream_id_t  sout_stream_id_t;
86
87 /* for mux */
88 struct sout_input_t
89 {
90     sout_instance_t *p_sout;
91
92     es_format_t     *p_fmt;
93     sout_fifo_t     *p_fifo;
94
95     void            *p_sys;
96 };
97
98 /* for packetizer */
99 struct sout_packetizer_input_t
100 {
101
102     sout_instance_t     *p_sout;
103
104     es_format_t         *p_fmt;
105
106     sout_stream_id_t    *id;
107 };
108
109
110 #define SOUT_METHOD_NONE        0x00
111 #define SOUT_METHOD_FILE        0x10
112 #define SOUT_METHOD_NETWORK     0x20
113
114 typedef struct sout_access_out_sys_t   sout_access_out_sys_t;
115 struct sout_access_out_t
116 {
117     VLC_COMMON_MEMBERS
118
119     module_t                *p_module;
120
121     sout_instance_t         *p_sout;
122
123     char                    *psz_access;
124     sout_cfg_t              *p_cfg;
125
126     char                    *psz_name;
127     sout_access_out_sys_t   *p_sys;
128     int                     (* pf_seek  )( sout_access_out_t *,
129                                            off_t );
130     int                     (* pf_read  )( sout_access_out_t *,
131                                            sout_buffer_t * );
132     int                     (* pf_write )( sout_access_out_t *,
133                                            sout_buffer_t * );
134 };
135
136 /*
137  * i_query parameter of pf_mux_capacity
138  */
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
145
146 /*
147  * return error code
148  */
149 #define SOUT_MUX_CAP_ERR_OK                 0x00
150 #define SOUT_MUX_CAP_ERR_UNKNOWN            0x01
151 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED      0x02
152
153 typedef struct sout_mux_sys_t sout_mux_sys_t;
154 struct  sout_mux_t
155 {
156     VLC_COMMON_MEMBERS
157     module_t                *p_module;
158
159     sout_instance_t         *p_sout;
160
161     char                    *psz_mux;
162     sout_cfg_t              *p_cfg;
163
164     sout_access_out_t       *p_access;
165
166     int                     i_preheader;
167     int                     (* pf_capacity)  ( sout_mux_t *,
168                                                int, void *, void *);
169     int                     (* pf_addstream )( sout_mux_t *,
170                                                sout_input_t * );
171     int                     (* pf_delstream )( sout_mux_t *,
172                                                sout_input_t * );
173     int                     (* pf_mux )      ( sout_mux_t * );
174
175
176     /* here are all inputs accepted by muxer */
177     int                     i_nb_inputs;
178     sout_input_t            **pp_inputs;
179
180
181     /* mux private */
182     sout_mux_sys_t          *p_sys;
183
184 #if 0
185     /* creater private */
186     void                    *p_sys_owner;
187 #endif
188
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;
196 };
197
198
199
200 struct sout_cfg_t
201 {
202     sout_cfg_t  *p_next;
203
204     char        *psz_name;
205     char        *psz_value;
206 };
207
208 typedef struct sout_stream_sys_t sout_stream_sys_t;
209 struct sout_stream_t
210 {
211     VLC_COMMON_MEMBERS
212
213     module_t                *p_module;
214     sout_instance_t         *p_sout;
215
216     char                    *psz_name;
217     sout_cfg_t              *p_cfg;
218     char                    *psz_next;
219
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 * );
223
224     /* manage a packet */
225     int                     (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
226
227     /* private */
228     sout_stream_sys_t       *p_sys;
229 };
230
231 typedef struct sout_instance_sys_t sout_instance_sys_t;
232 struct sout_instance_t
233 {
234     VLC_COMMON_MEMBERS
235
236     char * psz_sout;
237     char * psz_chain;
238
239     /* muxer data */
240     int                     i_preheader;    /* max over all muxer */
241
242     int                     i_padding;      /* needed by some decoders */
243
244     vlc_mutex_t             lock;
245     sout_stream_t           *p_stream;
246
247     /* sout private */
248     sout_instance_sys_t     *p_sys;
249 };
250
251 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
252 {
253     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
254     {
255         p_cfg = p_cfg->p_next;
256     }
257
258     return p_cfg;
259 }
260
261 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
262 {
263     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
264     {
265         p_cfg = p_cfg->p_next;
266     }
267
268     if( p_cfg && p_cfg->psz_value )
269     {
270         return( p_cfg->psz_value );
271     }
272
273     return NULL;
274 }
275 /*****************************************************************************
276  * Prototypes
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 * ) );
281
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 * ) );
285
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 * ) );
289
290
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* ) );
294
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 * ) );
301
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 * ) );
307
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 * ) );
313
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 ) );
317