1 /*****************************************************************************
2 * stream_output.h : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Eric Petit <titer@videolan.org>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
27 * sout_instance_t: stream output thread descriptor
28 *****************************************************************************/
33 typedef struct sout_stream_id_t sout_stream_id_t;
38 sout_instance_t *p_sout;
47 struct sout_packetizer_input_t
49 sout_instance_t *p_sout;
57 #define SOUT_METHOD_NONE 0x00
58 #define SOUT_METHOD_FILE 0x10
59 #define SOUT_METHOD_NETWORK 0x20
61 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
62 struct sout_access_out_t
68 sout_instance_t *p_sout;
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 * );
81 * i_query parameter of pf_mux_capacity
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
93 #define SOUT_MUX_CAP_ERR_OK 0x00
94 #define SOUT_MUX_CAP_ERR_UNKNOWN 0x01
95 #define SOUT_MUX_CAP_ERR_UNIMPLEMENTED 0x02
97 typedef struct sout_mux_sys_t sout_mux_sys_t;
103 sout_instance_t *p_sout;
108 sout_access_out_t *p_access;
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 * );
115 /* here are all inputs accepted by muxer */
117 sout_input_t **pp_inputs;
121 sout_mux_sys_t *p_sys;
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;
142 typedef struct sout_stream_sys_t sout_stream_sys_t;
148 sout_instance_t *p_sout;
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* );
161 sout_stream_sys_t *p_sys;
164 typedef struct sout_instance_sys_t sout_instance_sys_t;
165 struct sout_instance_t
172 /* meta data (Read only) XXX it won't be set before the first packet received */
175 int i_out_pace_nocontrol; /* count of output that can't control the space */
178 sout_stream_t *p_stream;
181 sout_instance_sys_t *p_sys;
185 /* Announce handler structures */
187 /* Session and method descriptors */
189 struct sap_session_t;
191 struct session_descriptor_t
197 int i_payload; /* SAP Payload type */
199 sap_session_t *p_sap; /* If we have a sap session, remember it */
203 #define METHOD_TYPE_SAP 1
204 #define METHOD_TYPE_SLP 2
206 struct announce_method_t
212 char *psz_ipv6_scope;
213 char *psz_address; /* If we use a custom address */
217 /* SAP Specific structures */
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
225 /* A SAP announce address. For each of these, we run the
226 * control flow algorithm */
231 int i_rfd; /* Read socket */
232 int i_wfd; /* Write socket */
234 /* Used for flow control */
236 vlc_bool_t b_enabled;
243 /* A SAP session descriptor, enqueued in the SAP handler queue */
249 sap_address_t *p_address;
251 /* Last and next send */
256 /* The SAP handler, running in a separate thread */
259 VLC_COMMON_MEMBERS /* needed to create a thread */
261 sap_session_t **pp_sessions;
262 sap_address_t **pp_addresses;
264 vlc_bool_t b_control;
269 int i_current_session;
271 int (*pf_add) ( sap_handler_t*, session_descriptor_t *,announce_method_t*);
272 int (*pf_del) ( sap_handler_t*, session_descriptor_t *);
275 /* The main announce handler object */
276 struct announce_handler_t
280 sap_handler_t *p_sap;
286 static inline sout_cfg_t *sout_cfg_find( sout_cfg_t *p_cfg, char *psz_name )
288 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
290 p_cfg = p_cfg->p_next;
296 static inline char *sout_cfg_find_value( sout_cfg_t *p_cfg, char *psz_name )
298 while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) )
300 p_cfg = p_cfg->p_next;
303 if( p_cfg && p_cfg->psz_value )
305 return( p_cfg->psz_value );
313 /*****************************************************************************
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 * ) );
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* ) );
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 * ) );
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 * ) );
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 ) );
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* ) );
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) );
349 #define announce_HandlerCreate(a) __announce_HandlerCreate(VLC_OBJECT(a))
350 announce_handler_t* __announce_HandlerCreate( vlc_object_t *);
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 );
360 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
361 void announce_SAPHandlerDestroy( sap_handler_t *p_sap );