]> git.sesse.net Git - vlc/blob - include/stream_output.h
subpicture_t now has a b_pausable attribute. When set to VLC_TRUE (default value...
[vlc] / include / stream_output.h
1 /*****************************************************************************
2  * stream_output.h : stream output module
3  *****************************************************************************
4  * Copyright (C) 2002-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *          Eric Petit <titer@videolan.org>
10  *          Jean-Paul Saman <jpsaman #_at_# m2x.nl>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * sout_instance_t: stream output thread descriptor
29  *****************************************************************************/
30
31 #include "vlc_es.h"
32
33 /****************************************************************************
34  * sout_instance_t: p_sout
35  ****************************************************************************/
36 struct sout_instance_t
37 {
38     VLC_COMMON_MEMBERS
39
40     char *psz_sout;
41     char *psz_chain;
42
43     /* meta data (Read only) XXX it won't be set before the first packet received */
44     vlc_meta_t          *p_meta;
45
46     int                 i_out_pace_nocontrol;   /* count of output that can't control the space */
47
48     vlc_mutex_t         lock;
49     sout_stream_t       *p_stream;
50
51     /* sout private */
52     sout_instance_sys_t *p_sys;
53 };
54
55 /****************************************************************************
56  * sout_cfg_t:
57  ****************************************************************************/
58 struct sout_cfg_t
59 {
60     sout_cfg_t  *p_next;
61
62     char        *psz_name;
63     char        *psz_value;
64 };
65
66 #define sout_CfgParse( a, b, c, d ) __sout_CfgParse( VLC_OBJECT(a), b, c, d )
67 VLC_EXPORT( void,   __sout_CfgParse, ( vlc_object_t *, char *psz_prefix, const char **ppsz_options, sout_cfg_t * ) );
68 VLC_EXPORT( char *, sout_CfgCreate, ( char **, sout_cfg_t **, char * ) );
69
70 /****************************************************************************
71  * sout_stream_id_t: opaque (private for all sout_stream_t)
72  ****************************************************************************/
73 typedef struct sout_stream_id_t  sout_stream_id_t;
74
75 /****************************************************************************
76  * sout_packetizer_input_t: p_sout <-> p_packetizer
77  ****************************************************************************/
78 struct sout_packetizer_input_t
79 {
80     sout_instance_t     *p_sout;
81
82     es_format_t         *p_fmt;
83
84     sout_stream_id_t    *id;
85 };
86
87 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
88 VLC_EXPORT( sout_instance_t *,  __sout_NewInstance,  ( vlc_object_t *, char * ) );
89 VLC_EXPORT( void,               sout_DeleteInstance, ( sout_instance_t * ) );
90
91 VLC_EXPORT( sout_packetizer_input_t *, sout_InputNew,( sout_instance_t *, es_format_t * ) );
92 VLC_EXPORT( int,                sout_InputDelete,      ( sout_packetizer_input_t * ) );
93 VLC_EXPORT( int,                sout_InputSendBuffer,  ( sout_packetizer_input_t *, block_t* ) );
94
95 /****************************************************************************
96  * sout_access_out_t:
97  ****************************************************************************/
98 struct sout_access_out_t
99 {
100     VLC_COMMON_MEMBERS
101
102     module_t                *p_module;
103
104     sout_instance_t         *p_sout;
105
106     char                    *psz_access;
107     sout_cfg_t              *p_cfg;
108
109     int                      i_writes;
110     int64_t                  i_sent_bytes;      ///< This is a "local" counter that is reset each
111                                                 // time it is transferred to stats
112
113     char                    *psz_name;
114     sout_access_out_sys_t   *p_sys;
115     int                     (*pf_seek)( sout_access_out_t *, off_t );
116     int                     (*pf_read)( sout_access_out_t *, block_t * );
117     int                     (*pf_write)( sout_access_out_t *, block_t * );
118 };
119
120 VLC_EXPORT( sout_access_out_t *,sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
121 VLC_EXPORT( void,               sout_AccessOutDelete, ( sout_access_out_t * ) );
122 VLC_EXPORT( int,                sout_AccessOutSeek,   ( sout_access_out_t *, off_t ) );
123 VLC_EXPORT( int,                sout_AccessOutRead,   ( sout_access_out_t *, block_t * ) );
124 VLC_EXPORT( int,                sout_AccessOutWrite,  ( sout_access_out_t *, block_t * ) );
125
126 /****************************************************************************
127  * mux:
128  ****************************************************************************/
129 struct  sout_mux_t
130 {
131     VLC_COMMON_MEMBERS
132     module_t            *p_module;
133
134     sout_instance_t     *p_sout;
135
136     char                *psz_mux;
137     sout_cfg_t          *p_cfg;
138
139     sout_access_out_t   *p_access;
140
141     int                 (*pf_addstream)( sout_mux_t *, sout_input_t * );
142     int                 (*pf_delstream)( sout_mux_t *, sout_input_t * );
143     int                 (*pf_mux)      ( sout_mux_t * );
144     int                 (*pf_control)  ( sout_mux_t *, int, va_list );
145
146     /* here are all inputs accepted by muxer */
147     int                 i_nb_inputs;
148     sout_input_t        **pp_inputs;
149
150
151     /* mux private */
152     sout_mux_sys_t      *p_sys;
153
154     /* XXX private to stream_output.c */
155     /* if muxer doesn't support adding stream at any time then we first wait
156      *  for stream then we refuse all stream and start muxing */
157     vlc_bool_t  b_add_stream_any_time;
158     vlc_bool_t  b_waiting_stream;
159     /* we wait one second after first stream added */
160     mtime_t     i_add_stream_start;
161 };
162
163 enum sout_mux_query_e
164 {
165     /* capabilities */
166     MUX_CAN_ADD_STREAM_WHILE_MUXING,    /* arg1= vlc_bool_t *,      res=cannot fail */
167     /* properties */
168     MUX_GET_ADD_STREAM_WAIT,            /* arg1= vlc_bool_t *,      res=cannot fail */
169     MUX_GET_MIME,                       /* arg1= char **            res=can fail    */
170 };
171
172 struct sout_input_t
173 {
174     sout_instance_t *p_sout;
175
176     es_format_t     *p_fmt;
177     block_fifo_t    *p_fifo;
178
179     void            *p_sys;
180 };
181
182
183 VLC_EXPORT( sout_mux_t *,   sout_MuxNew,          ( sout_instance_t*, char *, sout_access_out_t * ) );
184 VLC_EXPORT( sout_input_t *, sout_MuxAddStream,    ( sout_mux_t *, es_format_t * ) );
185 VLC_EXPORT( void,           sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
186 VLC_EXPORT( void,           sout_MuxDelete,       ( sout_mux_t * ) );
187 VLC_EXPORT( void,           sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t  *, block_t * ) );
188
189 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
190 {
191     va_list args;
192     int     i_result;
193
194     va_start( args, i_query );
195     i_result = p_mux->pf_control( p_mux, i_query, args );
196     va_end( args );
197     return i_result;
198 }
199
200 /****************************************************************************
201  * sout_stream:
202  ****************************************************************************/
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     /* Subpicture unit */
215     spu_t             *p_spu;
216
217     /* add, remove a stream */
218     sout_stream_id_t *(*pf_add)( sout_stream_t *, es_format_t * );
219     int               (*pf_del)( sout_stream_t *, sout_stream_id_t * );
220     /* manage a packet */
221     int               (*pf_send)( sout_stream_t *, sout_stream_id_t *, block_t* );
222
223     /* private */
224     sout_stream_sys_t *p_sys;
225 };
226
227 VLC_EXPORT( sout_stream_t *, sout_StreamNew, ( sout_instance_t *, char *psz_chain ) );
228 VLC_EXPORT( void,            sout_StreamDelete, ( sout_stream_t * ) );
229
230 static inline sout_stream_id_t *sout_StreamIdAdd( sout_stream_t *s, es_format_t *fmt )
231 {
232     return s->pf_add( s, fmt );
233 }
234 static inline int sout_StreamIdDel( sout_stream_t *s, sout_stream_id_t *id )
235 {
236     return s->pf_del( s, id );
237 }
238 static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, block_t *b )
239 {
240     return s->pf_send( s, id, b );
241 }
242
243 /****************************************************************************
244  * Announce handler mess
245  ****************************************************************************/
246 struct sap_session_t;
247
248 struct session_descriptor_t
249 {
250     char *psz_name;
251     char *psz_uri;
252     int i_port;
253     int i_ttl;
254     int i_payload;   /* SAP Payload type */
255
256     char *psz_group;
257
258     sap_session_t *p_sap; /* If we have a sap session, remember it */
259     char *psz_sdp;
260     vlc_bool_t b_rtp;
261 };
262
263 #define METHOD_TYPE_SAP 1
264
265 struct announce_method_t
266 {
267     int i_type;
268 };
269
270
271 /* A SAP session descriptor, enqueued in the SAP handler queue */
272 struct sap_session_t
273 {
274     char          *psz_sdp;
275     uint8_t       *psz_data;
276     unsigned      i_length;
277     sap_address_t *p_address;
278
279     /* Last and next send */
280     mtime_t        i_last;
281     mtime_t        i_next;
282 };
283
284 /* The SAP handler, running in a separate thread */
285 struct sap_handler_t
286 {
287     VLC_COMMON_MEMBERS /* needed to create a thread */
288
289     sap_session_t **pp_sessions;
290     sap_address_t **pp_addresses;
291
292     vlc_bool_t b_control;
293
294     int i_sessions;
295     int i_addresses;
296
297     int i_current_session;
298
299     int (*pf_add)  ( sap_handler_t*, session_descriptor_t *);
300     int (*pf_del)  ( sap_handler_t*, session_descriptor_t *);
301
302     /* private data, not in p_sys as there is one kind of sap_handler_t */
303 };
304
305 /* The main announce handler object */
306 struct announce_handler_t
307 {
308     VLC_COMMON_MEMBERS
309
310     sap_handler_t *p_sap;
311 };
312
313 /* End */
314
315
316 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
317 {
318     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
319     {
320         p_cfg = p_cfg->p_next;
321     }
322
323     return p_cfg;
324 }
325
326 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
327 {
328     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
329     {
330         p_cfg = p_cfg->p_next;
331     }
332
333     if( p_cfg && p_cfg->psz_value )
334     {
335         return( p_cfg->psz_value );
336     }
337
338     return NULL;
339 }
340
341 /* Announce system */
342 VLC_EXPORT( int,                sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
343 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,const char *, const char *, announce_method_t* ) );
344 VLC_EXPORT( int,                sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
345
346 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
347 VLC_EXPORT(void,                 sout_AnnounceSessionDestroy, (session_descriptor_t *) );
348 VLC_EXPORT(announce_method_t*,   sout_AnnounceMethodCreate, (int) );
349
350 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
351 announce_handler_t*  __announce_HandlerCreate( vlc_object_t *);
352
353 /* Private functions for the announce handler */
354 int announce_HandlerDestroy( announce_handler_t * );
355 int announce_Register( announce_handler_t *p_announce,
356                 session_descriptor_t *p_session,
357                 announce_method_t *p_method );
358 int announce_UnRegister( announce_handler_t *p_announce,
359                 session_descriptor_t *p_session );
360
361 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
362 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );