]> git.sesse.net Git - vlc/blob - include/stream_output.h
* ALL: Better announce system
[vlc] / include / stream_output.h
1 /*****************************************************************************
2  * stream_output.h : stream output module
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
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  *
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 typedef struct sout_stream_id_t  sout_stream_id_t;
34
35 /* for mux */
36 struct sout_input_t
37 {
38     sout_instance_t *p_sout;
39
40     es_format_t     *p_fmt;
41     block_fifo_t    *p_fifo;
42
43     void            *p_sys;
44 };
45
46 /* for packetizer */
47 struct sout_packetizer_input_t
48 {
49     sout_instance_t     *p_sout;
50
51     es_format_t         *p_fmt;
52
53     sout_stream_id_t    *id;
54 };
55
56
57 #define SOUT_METHOD_NONE        0x00
58 #define SOUT_METHOD_FILE        0x10
59 #define SOUT_METHOD_NETWORK     0x20
60
61 typedef struct sout_access_out_sys_t   sout_access_out_sys_t;
62 struct sout_access_out_t
63 {
64     VLC_COMMON_MEMBERS
65
66     module_t                *p_module;
67
68     sout_instance_t         *p_sout;
69
70     char                    *psz_access;
71     sout_cfg_t              *p_cfg;
72
73     char                    *psz_name;
74     sout_access_out_sys_t   *p_sys;
75     int                     (*pf_seek)( sout_access_out_t *, off_t );
76     int                     (*pf_read)( sout_access_out_t *, block_t * );
77     int                     (*pf_write)( sout_access_out_t *, block_t * );
78 };
79
80 /*
81  * i_query parameter of pf_mux_capacity
82  */
83 /* SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME:    p_args=NULL, p_answer=&boolean */
84 #define SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME    0x01
85 /* SOUT_MUX_CAP_GET_STREAMABLE:             p_args=NULL, p_answer=&boolean */
86 #define SOUT_MUX_CAP_GET_STREAMABLE             0x02
87 /* SOUT_MUX_CAP_GET_ADD_STREAM_WAIT:        p_args=NULL, p_answer=&boolean */
88 #define SOUT_MUX_CAP_GET_ADD_STREAM_WAIT        0x03
89
90 /*
91  * return error code
92  */
93 #define SOUT_MUX_CAP_ERR_OK                 0x00
94 #define SOUT_MUX_CAP_ERR_UNKNOWN            0x01
95 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED      0x02
96
97 typedef struct sout_mux_sys_t sout_mux_sys_t;
98 struct  sout_mux_t
99 {
100     VLC_COMMON_MEMBERS
101     module_t            *p_module;
102
103     sout_instance_t     *p_sout;
104
105     char                *psz_mux;
106     sout_cfg_t          *p_cfg;
107
108     sout_access_out_t   *p_access;
109
110     int                 (*pf_capacity)( sout_mux_t *, int, void *, void *);
111     int                 (*pf_addstream)( sout_mux_t *, sout_input_t * );
112     int                 (*pf_delstream)( sout_mux_t *, sout_input_t * );
113     int                 (*pf_mux)      ( sout_mux_t * );
114
115     /* here are all inputs accepted by muxer */
116     int                 i_nb_inputs;
117     sout_input_t        **pp_inputs;
118
119
120     /* mux private */
121     sout_mux_sys_t      *p_sys;
122
123     /* XXX private to stream_output.c */
124     /* if muxer doesn't support adding stream at any time then we first wait
125      *  for stream then we refuse all stream and start muxing */
126     vlc_bool_t  b_add_stream_any_time;
127     vlc_bool_t  b_waiting_stream;
128     /* we wait one second after first stream added */
129     mtime_t     i_add_stream_start;
130 };
131
132
133
134 struct sout_cfg_t
135 {
136     sout_cfg_t  *p_next;
137
138     char        *psz_name;
139     char        *psz_value;
140 };
141
142 typedef struct sout_stream_sys_t sout_stream_sys_t;
143 struct sout_stream_t
144 {
145     VLC_COMMON_MEMBERS
146
147     module_t          *p_module;
148     sout_instance_t   *p_sout;
149
150     char              *psz_name;
151     sout_cfg_t        *p_cfg;
152     char              *psz_next;
153
154     /* add, remove a stream */
155     sout_stream_id_t *(*pf_add)( sout_stream_t *, es_format_t * );
156     int               (*pf_del)( sout_stream_t *, sout_stream_id_t * );
157     /* manage a packet */
158     int               (*pf_send)( sout_stream_t *, sout_stream_id_t *, block_t* );
159
160     /* private */
161     sout_stream_sys_t *p_sys;
162 };
163
164 typedef struct sout_instance_sys_t sout_instance_sys_t;
165 struct sout_instance_t
166 {
167     VLC_COMMON_MEMBERS
168
169     char *psz_sout;
170     char *psz_chain;
171
172     /* meta data (Read only) XXX it won't be set before the first packet received */
173     vlc_meta_t          *p_meta;
174
175     int                 i_out_pace_nocontrol;   /* count of output that can't control the space */
176
177     vlc_mutex_t         lock;
178     sout_stream_t       *p_stream;
179
180     /* sout private */
181     sout_instance_sys_t *p_sys;
182 };
183
184
185 /* Announce handler structures */
186
187 /* Session and method descriptors */
188
189 struct sap_session_t;
190
191 struct session_descriptor_t
192 {
193     char *psz_name;
194     char *psz_uri;
195     int i_port;
196     int i_ttl;
197     int i_payload;   /* SAP Payload type */
198
199     sap_session_t *p_sap; /* If we have a sap session, remember it */
200     char *psz_sdp;
201 };
202
203 #define METHOD_TYPE_SAP 1
204 #define METHOD_TYPE_SLP 2
205
206 struct announce_method_t
207 {
208     int i_type;
209
210     /* For SAP */
211     int i_ip_version;
212     char *psz_ipv6_scope;
213     char *psz_address; /* If we use a custom address */
214 };
215
216
217 /* SAP Specific structures */
218
219 /* 100ms */
220 #define SAP_IDLE ((mtime_t)(0.100*CLOCK_FREQ))
221 #define SAP_MAX_BUFFER 65534
222 #define MIN_INTERVAL 2
223 #define MAX_INTERVAL 300
224
225 /* A SAP announce address. For each of these, we run the
226  * control flow algorithm */
227 struct sap_address_t
228 {
229     char *psz_address;
230     int i_port;
231     int i_rfd; /* Read socket */
232     int i_wfd; /* Write socket */
233
234     /* Used for flow control */
235     mtime_t t1;
236     vlc_bool_t b_enabled;
237     vlc_bool_t b_ready;
238     int i_interval;
239     int i_buff;
240     int i_limit;
241 };
242
243 /* A SAP session descriptor, enqueued in the SAP handler queue */
244 struct sap_session_t
245 {
246     char          *psz_sdp;
247     char          *psz_data;
248     int            i_length;
249     sap_address_t *p_address;
250
251     /* Last and next send */
252     mtime_t        i_last;
253     mtime_t        i_next;
254 };
255
256 /* The SAP handler, running in a separate thread */
257 struct sap_handler_t
258 {
259     VLC_COMMON_MEMBERS /* needed to create a thread */
260
261     sap_session_t **pp_sessions;
262     sap_address_t **pp_addresses;
263
264     vlc_bool_t b_control;
265
266     int i_sessions;
267     int i_addresses;
268
269     int i_current_session;
270
271     int (*pf_add)  ( sap_handler_t*, session_descriptor_t *,announce_method_t*);
272     int (*pf_del)  ( sap_handler_t*, session_descriptor_t *);
273 };
274
275 /* The main announce handler object */
276 struct announce_handler_t
277 {
278     VLC_COMMON_MEMBERS
279
280     sap_handler_t *p_sap;
281 };
282
283 /* End */
284
285
286 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
287 {
288     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
289     {
290         p_cfg = p_cfg->p_next;
291     }
292
293     return p_cfg;
294 }
295
296 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
297 {
298     while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
299     {
300         p_cfg = p_cfg->p_next;
301     }
302
303     if( p_cfg && p_cfg->psz_value )
304     {
305         return( p_cfg->psz_value );
306     }
307
308     return NULL;
309 }
310
311
312
313 /*****************************************************************************
314  * Prototypes
315  *****************************************************************************/
316 #define sout_NewInstance(a,b) __sout_NewInstance(VLC_OBJECT(a),b)
317 VLC_EXPORT( sout_instance_t *,  __sout_NewInstance,  ( vlc_object_t *, char * ) );
318 VLC_EXPORT( void,               sout_DeleteInstance, ( sout_instance_t * ) );
319
320 VLC_EXPORT( sout_packetizer_input_t *, sout_InputNew,( sout_instance_t *, es_format_t * ) );
321 VLC_EXPORT( int,                sout_InputDelete,      ( sout_packetizer_input_t * ) );
322 VLC_EXPORT( int,                sout_InputSendBuffer,  ( sout_packetizer_input_t *, block_t* ) );
323
324 VLC_EXPORT( sout_access_out_t *,sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
325 VLC_EXPORT( void,               sout_AccessOutDelete, ( sout_access_out_t * ) );
326 VLC_EXPORT( int,                sout_AccessOutSeek,   ( sout_access_out_t *, off_t ) );
327 VLC_EXPORT( int,                sout_AccessOutRead,   ( sout_access_out_t *, block_t * ) );
328 VLC_EXPORT( int,                sout_AccessOutWrite,  ( sout_access_out_t *, block_t * ) );
329
330 VLC_EXPORT( sout_mux_t *,       sout_MuxNew,          ( sout_instance_t*, char *, sout_access_out_t * ) );
331 VLC_EXPORT( sout_input_t *,     sout_MuxAddStream,    ( sout_mux_t *, es_format_t * ) );
332 VLC_EXPORT( void,               sout_MuxDeleteStream, ( sout_mux_t *, sout_input_t * ) );
333 VLC_EXPORT( void,               sout_MuxDelete,       ( sout_mux_t * ) );
334 VLC_EXPORT( void,               sout_MuxSendBuffer, ( sout_mux_t *, sout_input_t  *, block_t * ) );
335
336 VLC_EXPORT( char *,             sout_cfg_parser, ( char **, sout_cfg_t **, char * ) );
337 VLC_EXPORT( sout_stream_t *,    sout_stream_new, ( sout_instance_t *, char *psz_chain ) );
338 VLC_EXPORT( void,               sout_stream_delete, ( sout_stream_t *p_stream ) );
339
340 /* Announce system */
341 VLC_EXPORT( int,                sout_AnnounceRegister, (sout_instance_t *,session_descriptor_t*, announce_method_t* ) );
342 VLC_EXPORT(session_descriptor_t*,sout_AnnounceRegisterSDP, (sout_instance_t *,char *, announce_method_t* ) );
343 VLC_EXPORT( int,                sout_AnnounceUnRegister, (sout_instance_t *,session_descriptor_t* ) );
344
345 VLC_EXPORT(session_descriptor_t*,sout_AnnounceSessionCreate, () );
346 VLC_EXPORT(void,                 sout_AnnounceSessionDestroy, (session_descriptor_t *) );
347 VLC_EXPORT(announce_method_t*,   sout_AnnounceMethodCreate, (int) );
348
349 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
350 announce_handler_t*  __announce_HandlerCreate( vlc_object_t *);
351
352 /* Private functions for the announce handler */
353 int announce_HandlerDestroy( announce_handler_t * );
354 int announce_Register( announce_handler_t *p_announce,
355                 session_descriptor_t *p_session,
356                 announce_method_t *p_method );
357 int announce_UnRegister( announce_handler_t *p_announce,
358                 session_descriptor_t *p_session );
359
360 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
361 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );