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