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