]> git.sesse.net Git - vlc/blob - include/stream_output.h
b01779c5b5ec7e688885806adc2ff2001f026d77
[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.15 2003/11/07 16:53:54 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 /*
31  * i_allocated_size: size of allocated buffer
32  * p_allocated_buffer: where data has been allocated
33  *
34  * i_buffer_size: sizeof buffer from p_buffer
35  * p_buffer: where data begins
36  * i_size: size of valid data
37  *
38  */
39 #define SOUT_BUFFER_FLAGS_HEADER    0x0001
40 #define SOUT_BUFFER_FLAGS_GOP       0x0002
41
42 /*
43  * Flags for muxer/access private usage.
44  */
45 #define SOUT_BUFFER_FLAGS_PRIVATE_MASK  0xffff0000
46 #define SOUT_BUFFER_FLAGS_PRIVATE_SHIFT 16
47
48 struct sout_buffer_t
49 {
50     size_t                  i_allocated_size;
51     byte_t                  *p_allocated_buffer;
52
53     size_t                  i_buffer_size;
54     byte_t                  *p_buffer;
55
56     size_t                  i_size;
57     mtime_t                 i_length;
58
59     mtime_t                 i_dts;
60     mtime_t                 i_pts;
61
62     uint32_t                i_flags;
63     int                     i_bitrate;
64
65     struct sout_buffer_t    *p_next;
66 };
67
68 struct sout_format_t
69 {
70     int             i_cat;
71     vlc_fourcc_t    i_fourcc;
72
73     /* audio */
74     int             i_sample_rate;
75     int             i_channels;
76     int             i_block_align;
77
78     /* video */
79     int             i_width;
80     int             i_height;
81
82     int             i_bitrate;
83     int             i_extra_data;
84     uint8_t         *p_extra_data;
85
86 };
87
88 struct sout_fifo_t
89 {
90     vlc_mutex_t         lock;                         /* fifo data lock */
91     vlc_cond_t          wait;         /* fifo data conditional variable */
92
93     int                 i_depth;
94     sout_buffer_t       *p_first;
95     sout_buffer_t       **pp_last;
96 };
97
98 typedef struct sout_stream_id_t  sout_stream_id_t;
99
100 /* for mux */
101 struct sout_input_t
102 {
103     sout_instance_t *p_sout;
104
105     sout_format_t   *p_fmt;
106     sout_fifo_t     *p_fifo;
107
108     void            *p_sys;
109 };
110
111 /* for packetizer */
112 struct sout_packetizer_input_t
113 {
114
115     sout_instance_t     *p_sout;
116
117     sout_format_t       *p_fmt;
118
119     sout_stream_id_t    *id;
120 };
121
122
123 #define SOUT_METHOD_NONE        0x00
124 #define SOUT_METHOD_FILE        0x10
125 #define SOUT_METHOD_NETWORK     0x20
126
127 typedef struct sout_access_out_sys_t   sout_access_out_sys_t;
128 struct sout_access_out_t
129 {
130     VLC_COMMON_MEMBERS
131
132     module_t                *p_module;
133
134     sout_instance_t         *p_sout;
135
136     char                    *psz_access;
137     sout_cfg_t              *p_cfg;
138
139     char                    *psz_name;
140     sout_access_out_sys_t   *p_sys;
141     int                     (* pf_seek  )( sout_access_out_t *,
142                                            off_t );
143     int                     (* pf_write )( sout_access_out_t *,
144                                            sout_buffer_t * );
145 };
146 /*
147  * i_query parameter of pf_mux_capacity
148  */
149 /* SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME:    p_args=NULL, p_answer=&boolean */
150 #define SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME    0x01
151 /* SOUT_MUX_CAP_GET_STREAMABLE:             p_args=NULL, p_answer=&boolean */
152 #define SOUT_MUX_CAP_GET_STREAMABLE             0x02
153 /*
154  * return error code
155  */
156 #define SOUT_MUX_CAP_ERR_OK                 0x00
157 #define SOUT_MUX_CAP_ERR_UNKNOWN            0x01
158 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED      0x02
159
160 typedef struct sout_mux_sys_t sout_mux_sys_t;
161 struct  sout_mux_t
162 {
163     VLC_COMMON_MEMBERS
164     module_t                *p_module;
165
166     sout_instance_t         *p_sout;
167
168     char                    *psz_mux;
169     sout_cfg_t              *p_cfg;
170
171     sout_access_out_t       *p_access;
172
173     int                     i_preheader;
174     int                     (* pf_capacity)  ( sout_mux_t *,
175                                                int, void *, void *);
176     int                     (* pf_addstream )( sout_mux_t *,
177                                                sout_input_t * );
178     int                     (* pf_delstream )( sout_mux_t *,
179                                                sout_input_t * );
180     int                     (* pf_mux )      ( sout_mux_t * );
181
182
183     /* here are all inputs accepted by muxer */
184     int                     i_nb_inputs;
185     sout_input_t            **pp_inputs;
186
187
188     /* mux private */
189     sout_mux_sys_t          *p_sys;
190
191 #if 0
192     /* creater private */
193     void                    *p_sys_owner;
194 #endif
195     
196     /* XXX private to stream_output.c */
197     /* if muxer doesn't support adding stream at any time then we first wait
198      *  for stream then we refuse all stream and start muxing */
199     vlc_bool_t  b_add_stream_any_time;
200     vlc_bool_t  b_waiting_stream;
201     /* we wait one second after first stream added */
202     mtime_t     i_add_stream_start;
203 };
204
205
206
207 struct sout_cfg_t
208 {
209     sout_cfg_t  *p_next;
210
211     char        *psz_name;
212     char        *psz_value;
213 };
214
215 typedef struct sout_stream_sys_t sout_stream_sys_t;
216 struct sout_stream_t
217 {
218     VLC_COMMON_MEMBERS
219
220     module_t                *p_module;
221     sout_instance_t         *p_sout;
222
223     char                    *psz_name;
224     sout_cfg_t              *p_cfg;
225     char                    *psz_next;
226
227     /* add, remove a stream */
228     sout_stream_id_t *      (*pf_add) ( sout_stream_t *, sout_format_t * );
229     int                     (*pf_del) ( sout_stream_t *, sout_stream_id_t * );
230
231     /* manage a packet */
232     int                     (*pf_send)( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
233
234     /* private */
235     sout_stream_sys_t       *p_sys;
236 };
237
238 typedef struct sout_instance_sys_t sout_instance_sys_t;
239 struct sout_instance_t
240 {
241     VLC_COMMON_MEMBERS
242
243     char * psz_sout;
244     char * psz_chain;
245
246     /* muxer data */
247     int                     i_preheader;    /* max over all muxer */
248
249     int                     i_padding;      /* needed by some decoders */
250
251     vlc_mutex_t             lock;
252     sout_stream_t           *p_stream;
253
254     /* sout private */
255     sout_instance_sys_t     *p_sys;
256 };
257
258 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
259 {
260     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
261     {
262         p_cfg = p_cfg->p_next;
263     }
264
265     return p_cfg;
266 }
267
268 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
269 {
270     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
271     {
272         p_cfg = p_cfg->p_next;
273     }
274
275     if( p_cfg && p_cfg->psz_value )
276     {
277         return( p_cfg->psz_value );
278     }
279
280     return NULL;
281 }
282 /*****************************************************************************
283  * Prototypes
284  *****************************************************************************/
285 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
286 VLC_EXPORT( sout_instance_t *, __sout_NewInstance,  ( vlc_object_t *, char * ) );
287 VLC_EXPORT( void,              sout_DeleteInstance, ( sout_instance_t * ) );
288
289 VLC_EXPORT( sout_fifo_t *,   sout_FifoCreate,     ( sout_instance_t * ) );
290 VLC_EXPORT( void,            sout_FifoDestroy,    ( sout_instance_t *, sout_fifo_t * ) );
291 VLC_EXPORT( void,            sout_FifoFree,       ( sout_instance_t *,sout_fifo_t * ) );
292
293 VLC_EXPORT( void,            sout_FifoPut,        ( sout_fifo_t *, sout_buffer_t* ) );
294 VLC_EXPORT( sout_buffer_t *, sout_FifoGet,        ( sout_fifo_t * ) );
295 VLC_EXPORT( sout_buffer_t *, sout_FifoShow,       ( sout_fifo_t * ) );
296
297
298 #define sout_InputNew( a, b ) __sout_InputNew( VLC_OBJECT(a), b )
299 VLC_EXPORT( sout_packetizer_input_t *, __sout_InputNew,       ( vlc_object_t *, sout_format_t * ) );
300 VLC_EXPORT( int,            sout_InputDelete,      ( sout_packetizer_input_t * ) );
301 VLC_EXPORT( int,            sout_InputSendBuffer,  ( sout_packetizer_input_t *, sout_buffer_t* ) );
302
303 VLC_EXPORT( sout_buffer_t*, sout_BufferNew,    ( sout_instance_t *, size_t ) );
304 VLC_EXPORT( int,            sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
305 VLC_EXPORT( int,            sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
306 VLC_EXPORT( int,            sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
307 VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
308 VLC_EXPORT( void,           sout_BufferChain,  ( sout_buffer_t **, sout_buffer_t * ) );
309
310 VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
311 VLC_EXPORT( void,                sout_AccessOutDelete, ( sout_access_out_t * ) );
312 VLC_EXPORT( int,                 sout_AccessOutSeek,   ( sout_access_out_t *, off_t ) );
313 VLC_EXPORT( int,                 sout_AccessOutWrite,  ( sout_access_out_t *, sout_buffer_t * ) );
314
315 VLC_EXPORT( sout_mux_t *,       sout_MuxNew,          ( sout_instance_t*, char *, sout_access_out_t * ) );
316 VLC_EXPORT( sout_input_t *,     sout_MuxAddStream,    ( sout_mux_t *, sout_format_t * ) );
317 VLC_EXPORT( void,               sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
318 VLC_EXPORT( void,               sout_MuxDelete,       ( sout_mux_t * ) );
319 VLC_EXPORT( void,               sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t  *, sout_buffer_t * ) );
320
321 VLC_EXPORT( char *,             sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
322 VLC_EXPORT( sout_stream_t *,    sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
323 VLC_EXPORT( void,               sout_stream_delete, ( sout_stream_t *p_stream ) );
324