]> git.sesse.net Git - vlc/blob - include/stream_output.h
Export URI from RTP module . Closes:#403
[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., 59 Temple Place - Suite 330, Boston, MA  02111, 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     char                    *psz_name;
110     sout_access_out_sys_t   *p_sys;
111     int                     (*pf_seek)( sout_access_out_t *, off_t );
112     int                     (*pf_read)( sout_access_out_t *, block_t * );
113     int                     (*pf_write)( sout_access_out_t *, block_t * );
114 };
115
116 VLC_EXPORT( sout_access_out_t *,sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
117 VLC_EXPORT( void,               sout_AccessOutDelete, ( sout_access_out_t * ) );
118 VLC_EXPORT( int,                sout_AccessOutSeek,   ( sout_access_out_t *, off_t ) );
119 VLC_EXPORT( int,                sout_AccessOutRead,   ( sout_access_out_t *, block_t * ) );
120 VLC_EXPORT( int,                sout_AccessOutWrite,  ( sout_access_out_t *, block_t * ) );
121
122 /****************************************************************************
123  * mux:
124  ****************************************************************************/
125 struct  sout_mux_t
126 {
127     VLC_COMMON_MEMBERS
128     module_t            *p_module;
129
130     sout_instance_t     *p_sout;
131
132     char                *psz_mux;
133     sout_cfg_t          *p_cfg;
134
135     sout_access_out_t   *p_access;
136
137     int                 (*pf_addstream)( sout_mux_t *, sout_input_t * );
138     int                 (*pf_delstream)( sout_mux_t *, sout_input_t * );
139     int                 (*pf_mux)      ( sout_mux_t * );
140     int                 (*pf_control)  ( sout_mux_t *, int, va_list );
141
142     /* here are all inputs accepted by muxer */
143     int                 i_nb_inputs;
144     sout_input_t        **pp_inputs;
145
146
147     /* mux private */
148     sout_mux_sys_t      *p_sys;
149
150     /* XXX private to stream_output.c */
151     /* if muxer doesn't support adding stream at any time then we first wait
152      *  for stream then we refuse all stream and start muxing */
153     vlc_bool_t  b_add_stream_any_time;
154     vlc_bool_t  b_waiting_stream;
155     /* we wait one second after first stream added */
156     mtime_t     i_add_stream_start;
157 };
158
159 enum sout_mux_query_e
160 {
161     /* capabilities */
162     MUX_CAN_ADD_STREAM_WHILE_MUXING,    /* arg1= vlc_bool_t *,      res=cannot fail */
163     /* properties */
164     MUX_GET_ADD_STREAM_WAIT,            /* arg1= vlc_bool_t *,      res=cannot fail */
165     MUX_GET_MIME,                       /* arg1= char **            res=can fail    */
166 };
167
168 struct sout_input_t
169 {
170     sout_instance_t *p_sout;
171
172     es_format_t     *p_fmt;
173     block_fifo_t    *p_fifo;
174
175     void            *p_sys;
176 };
177
178
179 VLC_EXPORT( sout_mux_t *,   sout_MuxNew,          ( sout_instance_t*, char *, sout_access_out_t * ) );
180 VLC_EXPORT( sout_input_t *, sout_MuxAddStream,    ( sout_mux_t *, es_format_t * ) );
181 VLC_EXPORT( void,           sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
182 VLC_EXPORT( void,           sout_MuxDelete,       ( sout_mux_t * ) );
183 VLC_EXPORT( void,           sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t  *, block_t * ) );
184
185 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
186 {
187     va_list args;
188     int     i_result;
189
190     va_start( args, i_query );
191     i_result = p_mux->pf_control( p_mux, i_query, args );
192     va_end( args );
193     return i_result;
194 }
195
196 /****************************************************************************
197  * sout_stream:
198  ****************************************************************************/
199 struct sout_stream_t
200 {
201     VLC_COMMON_MEMBERS
202
203     module_t          *p_module;
204     sout_instance_t   *p_sout;
205
206     char              *psz_name;
207     sout_cfg_t        *p_cfg;
208     char              *psz_next;
209
210     /* Subpicture unit */
211     spu_t             *p_spu;
212     
213     /* add, remove a stream */
214     sout_stream_id_t *(*pf_add)( sout_stream_t *, es_format_t * );
215     int               (*pf_del)( sout_stream_t *, sout_stream_id_t * );
216     /* manage a packet */
217     int               (*pf_send)( sout_stream_t *, sout_stream_id_t *, block_t* );
218
219     /* private */
220     sout_stream_sys_t *p_sys;
221 };
222
223 VLC_EXPORT( sout_stream_t *, sout_StreamNew, ( sout_instance_t *, char *psz_chain ) );
224 VLC_EXPORT( void,            sout_StreamDelete, ( sout_stream_t * ) );
225
226 static inline sout_stream_id_t *sout_StreamIdAdd( sout_stream_t *s, es_format_t *fmt )
227 {
228     return s->pf_add( s, fmt );
229 }
230 static inline int sout_StreamIdDel( sout_stream_t *s, sout_stream_id_t *id )
231 {
232     return s->pf_del( s, id );
233 }
234 static inline int sout_StreamIdSend( sout_stream_t *s, sout_stream_id_t *id, block_t *b )
235 {
236     return s->pf_send( s, id, b );
237 }
238
239 /****************************************************************************
240  * Announce handler mess
241  ****************************************************************************/
242 struct sap_session_t;
243
244 struct session_descriptor_t
245 {
246     char *psz_name;
247     char *psz_uri;
248     int i_port;
249     int i_ttl;
250     int i_payload;   /* SAP Payload type */
251
252     char *psz_group;
253
254     sap_session_t *p_sap; /* If we have a sap session, remember it */
255     char *psz_sdp;
256     vlc_bool_t b_rtp;
257 };
258
259 #define METHOD_TYPE_SAP 1
260 #define METHOD_TYPE_SLP 2
261
262 struct announce_method_t
263 {
264     int i_type;
265 };
266
267
268 /* A SAP session descriptor, enqueued in the SAP handler queue */
269 struct sap_session_t
270 {
271     char          *psz_sdp;
272     uint8_t       *psz_data;
273     unsigned      i_length;
274     sap_address_t *p_address;
275
276     /* Last and next send */
277     mtime_t        i_last;
278     mtime_t        i_next;
279 };
280
281 /* The SAP handler, running in a separate thread */
282 struct sap_handler_t
283 {
284     VLC_COMMON_MEMBERS /* needed to create a thread */
285
286     sap_session_t **pp_sessions;
287     sap_address_t **pp_addresses;
288
289     vlc_bool_t b_control;
290
291     int i_sessions;
292     int i_addresses;
293
294     int i_current_session;
295
296     int (*pf_add)  ( sap_handler_t*, session_descriptor_t *);
297     int (*pf_del)  ( sap_handler_t*, session_descriptor_t *);
298
299     /* private data, not in p_sys as there is one kind of sap_handler_t */
300 };
301
302 /* The main announce handler object */
303 struct announce_handler_t
304 {
305     VLC_COMMON_MEMBERS
306
307     sap_handler_t *p_sap;
308 };
309
310 /* End */
311
312
313 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
314 {
315     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
316     {
317         p_cfg = p_cfg->p_next;
318     }
319
320     return p_cfg;
321 }
322
323 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
324 {
325     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
326     {
327         p_cfg = p_cfg->p_next;
328     }
329
330     if( p_cfg && p_cfg->psz_value )
331     {
332         return( p_cfg->psz_value );
333     }
334
335     return NULL;
336 }
337
338 /* Announce system */
339 VLC_EXPORT( int,                sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
340 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,const char *, const char *, announce_method_t* ) );
341 VLC_EXPORT( int,                sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
342
343 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, (void) );
344 VLC_EXPORT(void,                 sout_AnnounceSessionDestroy, (session_descriptor_t *) );
345 VLC_EXPORT(announce_method_t*,   sout_AnnounceMethodCreate, (int) );
346
347 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
348 announce_handler_t*  __announce_HandlerCreate( vlc_object_t *);
349
350 /* Private functions for the announce handler */
351 int announce_HandlerDestroy( announce_handler_t * );
352 int announce_Register( announce_handler_t *p_announce,
353                 session_descriptor_t *p_session,
354                 announce_method_t *p_method );
355 int announce_UnRegister( announce_handler_t *p_announce,
356                 session_descriptor_t *p_session );
357
358 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
359 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );