1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: es.c,v 1.1 2003/04/13 20:00:21 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc/input.h>
34 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Open ( vlc_object_t * );
39 static void Close ( vlc_object_t * );
41 static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
42 static int Del ( sout_stream_t *, sout_stream_id_t * );
43 static int Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
45 /*****************************************************************************
47 *****************************************************************************/
49 set_description( _("ES stream") );
50 set_capability( "sout stream", 50 );
53 set_callbacks( Open, Close );
56 struct sout_stream_sys_t
67 char *psz_access_audio;
68 char *psz_access_video;
75 /*****************************************************************************
77 *****************************************************************************/
78 static int Open( vlc_object_t *p_this )
80 sout_stream_t *p_stream = (sout_stream_t*)p_this;
81 sout_stream_sys_t *p_sys;
83 //p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
85 p_sys = malloc( sizeof( sout_stream_sys_t ) );
88 p_sys->i_count_audio = 0;
89 p_sys->i_count_video = 0;
91 p_sys->psz_access = sout_cfg_find_value( p_stream->p_cfg, "access" );
92 p_sys->psz_access_audio = sout_cfg_find_value( p_stream->p_cfg, "acesss_audio" );
93 p_sys->psz_access_video = sout_cfg_find_value( p_stream->p_cfg, "access_video" );
96 p_sys->psz_mux = sout_cfg_find_value( p_stream->p_cfg, "mux" );
97 p_sys->psz_mux_audio = sout_cfg_find_value( p_stream->p_cfg, "mux_audio" );
98 p_sys->psz_mux_video = sout_cfg_find_value( p_stream->p_cfg, "mux_video" );
100 p_sys->psz_url = sout_cfg_find_value( p_stream->p_cfg, "url" );
101 p_sys->psz_url_audio = sout_cfg_find_value( p_stream->p_cfg, "url_audio" );
102 p_sys->psz_url_video = sout_cfg_find_value( p_stream->p_cfg, "url_video" );
104 p_stream->pf_add = Add;
105 p_stream->pf_del = Del;
106 p_stream->pf_send = Send;
108 p_stream->p_sys = p_sys;
113 /*****************************************************************************
115 *****************************************************************************/
117 static void Close( vlc_object_t * p_this )
119 sout_stream_t *p_stream = (sout_stream_t*)p_this;
120 sout_stream_sys_t *p_sys = p_stream->p_sys;
125 struct sout_stream_id_t
127 sout_input_t *p_input;
131 static char * es_print_url( char *psz_fmt, vlc_fourcc_t i_fourcc, int i_count, char *psz_access, char *psz_mux )
135 if( psz_fmt == NULL || !*psz_fmt )
137 psz_fmt = "stream-%n-%c.%m";
140 p = psz_url = malloc( 4096 );
141 memset( p, 0, 4096 );
144 if( *psz_fmt == '\0' )
150 if( *psz_fmt != '%' )
156 if( psz_fmt[1] == 'n' )
158 p += sprintf( p, "%d", i_count );
160 else if( psz_fmt[1] == 'c' )
162 p += sprintf( p, "%4.4s", (char*)&i_fourcc );
164 else if( psz_fmt[1] == 'm' )
166 p += sprintf( p, "%s", psz_mux );
168 else if( psz_fmt[1] == 'a' )
170 p += sprintf( p, "%s", psz_access );
172 else if( psz_fmt[1] != '\0' )
174 p += sprintf( p, "%c%c", psz_fmt[0], psz_fmt[1] );
178 p += sprintf( p, "%c", psz_fmt[0] );
189 static sout_stream_id_t * Add ( sout_stream_t *p_stream, sout_format_t *p_fmt )
191 sout_stream_sys_t *p_sys = p_stream->p_sys;
192 sout_instance_t *p_sout = p_stream->p_sout;
193 sout_stream_id_t *id;
199 sout_access_out_t *p_access;
202 /* *** get access name *** */
203 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_access_audio )
205 psz_access = p_sys->psz_access_audio;
207 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_access_video )
209 psz_access = p_sys->psz_access_video;
213 psz_access = p_sys->psz_access;
216 /* *** get mux name *** */
217 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_mux_audio )
219 psz_mux = p_sys->psz_mux_audio;
221 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_mux_video )
223 psz_mux = p_sys->psz_mux_video;
227 psz_mux = p_sys->psz_mux;
230 /* *** get url (%d expanded as a codec count, %c expanded as codec fcc ) *** */
231 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_url_audio )
233 psz_url = es_print_url( p_sys->psz_url_audio, p_fmt->i_fourcc, p_sys->i_count_audio, psz_access, psz_mux );
235 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_url_video )
237 psz_url = es_print_url( p_sys->psz_url_video, p_fmt->i_fourcc, p_sys->i_count_video, psz_access, psz_mux );
242 if( p_fmt->i_cat == VIDEO_ES )
244 i_count = p_sys->i_count_video;
246 else if( p_fmt->i_cat == AUDIO_ES )
248 i_count = p_sys->i_count_audio;
252 i_count = p_sys->i_count;
255 psz_url = es_print_url( p_sys->psz_url, p_fmt->i_fourcc, i_count, psz_access, psz_mux );
259 if( p_fmt->i_cat == VIDEO_ES )
261 p_sys->i_count_video++;
263 else if( p_fmt->i_cat == AUDIO_ES )
265 p_sys->i_count_audio++;
267 msg_Dbg( p_stream, "creating `%s/%s://%s'",
268 psz_access, psz_mux, psz_url );
270 /* *** find and open appropriate access module *** */
271 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
272 if( p_access == NULL )
274 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
275 psz_access, psz_mux, psz_url );
279 /* *** find and open appropriate mux module *** */
280 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
283 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
284 psz_access, psz_mux, psz_url );
285 sout_AccessOutDelete( p_access );
290 p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
292 id = malloc( sizeof( sout_stream_id_t ) );
294 id->p_input = sout_MuxAddStream( p_mux, p_fmt );
296 if( id->p_input == NULL )
300 sout_MuxDelete( p_mux );
301 sout_AccessOutDelete( p_access );
309 static int Del ( sout_stream_t *p_stream, sout_stream_id_t *id )
311 sout_access_out_t *p_access = id->p_mux->p_access;
313 sout_MuxDeleteStream( id->p_mux, id->p_input );
314 sout_AccessOutDelete( p_access );
320 static int Send ( sout_stream_t *p_stream, sout_stream_id_t *id, sout_buffer_t *p_buffer )
322 sout_MuxSendBuffer( id->p_mux, id->p_input, p_buffer );