1 /*****************************************************************************
2 * es.c: Elementary stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 #define ACCESS_TEXT N_("Output access method")
38 #define ACCESS_LONGTEXT N_( \
39 "This is the default output access method that will be used." )
41 #define ACCESSA_TEXT N_("Audio output access method")
42 #define ACCESSA_LONGTEXT N_( \
43 "This is the output access method that will be used for audio." )
44 #define ACCESSV_TEXT N_("Video output access method")
45 #define ACCESSV_LONGTEXT N_( \
46 "This is the output access method that will be used for video." )
48 #define MUX_TEXT N_("Output muxer")
49 #define MUX_LONGTEXT N_( \
50 "This is the default muxer method that will be used." )
51 #define MUXA_TEXT N_("Audio output muxer")
52 #define MUXA_LONGTEXT N_( \
53 "This is the muxer that will be used for audio." )
54 #define MUXV_TEXT N_("Video output muxer")
55 #define MUXV_LONGTEXT N_( \
56 "This is the muxer that will be used for video." )
58 #define DEST_TEXT N_("Output URL")
59 #define DEST_LONGTEXT N_( \
60 "This is the default output URI." )
61 #define DESTA_TEXT N_("Audio output URL")
62 #define DESTA_LONGTEXT N_( \
63 "This is the output URI that will be used for audio." )
64 #define DESTV_TEXT N_("Video output URL")
65 #define DESTV_LONGTEXT N_( \
66 "This is the output URI that will be used for video." )
68 static int Open ( vlc_object_t * );
69 static void Close ( vlc_object_t * );
71 #define SOUT_CFG_PREFIX "sout-es-"
74 set_shortname( "ES" );
75 set_description( _("Elementary stream output") );
76 set_capability( "sout stream", 50 );
78 set_category( CAT_SOUT );
79 set_subcategory( SUBCAT_SOUT_STREAM );
81 add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
82 ACCESS_LONGTEXT, VLC_TRUE );
83 add_string( SOUT_CFG_PREFIX "access-audio", "", NULL, ACCESSA_TEXT,
84 ACCESSA_LONGTEXT, VLC_TRUE );
85 add_string( SOUT_CFG_PREFIX "access-video", "", NULL, ACCESSV_TEXT,
86 ACCESSV_LONGTEXT, VLC_TRUE );
88 add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
89 MUX_LONGTEXT, VLC_TRUE );
90 add_string( SOUT_CFG_PREFIX "mux-audio", "", NULL, MUXA_TEXT,
91 MUXA_LONGTEXT, VLC_TRUE );
92 add_string( SOUT_CFG_PREFIX "mux-video", "", NULL, MUXV_TEXT,
93 MUXV_LONGTEXT, VLC_TRUE );
95 add_string( SOUT_CFG_PREFIX "dst", "", NULL, DEST_TEXT,
96 DEST_LONGTEXT, VLC_TRUE );
97 add_string( SOUT_CFG_PREFIX "dst-audio", "", NULL, DESTA_TEXT,
98 DESTA_LONGTEXT, VLC_TRUE );
99 add_string( SOUT_CFG_PREFIX "dst-video", "", NULL, DESTV_TEXT,
100 DESTV_LONGTEXT, VLC_TRUE );
102 set_callbacks( Open, Close );
105 /*****************************************************************************
106 * Exported prototypes
107 *****************************************************************************/
108 static const char *ppsz_sout_options[] = {
109 "access", "access-audio", "access-video",
110 "mux", "mux-audio", "mux-video",
111 "dst", "dst-audio", "dst-video",
115 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
116 static int Del ( sout_stream_t *, sout_stream_id_t * );
117 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
119 struct sout_stream_sys_t
130 char *psz_access_audio;
131 char *psz_access_video;
138 /*****************************************************************************
140 *****************************************************************************/
141 static int Open( vlc_object_t *p_this )
143 sout_stream_t *p_stream = (sout_stream_t*)p_this;
144 sout_stream_sys_t *p_sys;
147 sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options, p_stream->p_cfg );
148 p_sys = malloc( sizeof( sout_stream_sys_t ) );
151 p_sys->i_count_audio = 0;
152 p_sys->i_count_video = 0;
154 var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
155 p_sys->psz_access = val.psz_string;
156 var_Get( p_stream, SOUT_CFG_PREFIX "access-audio", &val );
157 p_sys->psz_access_audio = val.psz_string;
158 var_Get( p_stream, SOUT_CFG_PREFIX "access-video", &val );
159 p_sys->psz_access_video = val.psz_string;
161 var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
162 p_sys->psz_mux = val.psz_string;
163 var_Get( p_stream, SOUT_CFG_PREFIX "mux-audio", &val );
164 p_sys->psz_mux_audio = val.psz_string;
165 var_Get( p_stream, SOUT_CFG_PREFIX "mux-video", &val );
166 p_sys->psz_mux_video = val.psz_string;
168 var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
169 p_sys->psz_dst = val.psz_string;
170 var_Get( p_stream, SOUT_CFG_PREFIX "dst-audio", &val );
171 p_sys->psz_dst_audio = val.psz_string;
172 var_Get( p_stream, SOUT_CFG_PREFIX "dst-video", &val );
173 p_sys->psz_dst_video = val.psz_string;
175 p_stream->pf_add = Add;
176 p_stream->pf_del = Del;
177 p_stream->pf_send = Send;
179 p_stream->p_sys = p_sys;
184 /*****************************************************************************
186 *****************************************************************************/
188 static void Close( vlc_object_t * p_this )
190 sout_stream_t *p_stream = (sout_stream_t*)p_this;
191 sout_stream_sys_t *p_sys = p_stream->p_sys;
193 free( p_sys->psz_access );
194 free( p_sys->psz_access_audio );
195 free( p_sys->psz_access_video );
197 free( p_sys->psz_mux );
198 free( p_sys->psz_mux_audio );
199 free( p_sys->psz_mux_video );
201 free( p_sys->psz_dst );
202 free( p_sys->psz_dst_audio );
203 free( p_sys->psz_dst_video );
208 struct sout_stream_id_t
210 sout_input_t *p_input;
214 static char * es_print_url( char *psz_fmt, vlc_fourcc_t i_fourcc, int i_count,
215 char *psz_access, char *psz_mux )
219 if( psz_fmt == NULL || !*psz_fmt )
221 psz_fmt = "stream-%n-%c.%m";
224 p = psz_dst = malloc( 4096 );
225 memset( p, 0, 4096 );
228 if( *psz_fmt == '\0' )
234 if( *psz_fmt != '%' )
240 if( psz_fmt[1] == 'n' )
242 p += sprintf( p, "%d", i_count );
244 else if( psz_fmt[1] == 'c' )
246 p += sprintf( p, "%4.4s", (char*)&i_fourcc );
248 else if( psz_fmt[1] == 'm' )
250 p += sprintf( p, "%s", psz_mux );
252 else if( psz_fmt[1] == 'a' )
254 p += sprintf( p, "%s", psz_access );
256 else if( psz_fmt[1] != '\0' )
258 p += sprintf( p, "%c%c", psz_fmt[0], psz_fmt[1] );
262 p += sprintf( p, "%c", psz_fmt[0] );
273 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
275 sout_stream_sys_t *p_sys = p_stream->p_sys;
276 sout_instance_t *p_sout = p_stream->p_sout;
277 sout_stream_id_t *id;
283 sout_access_out_t *p_access;
286 /* *** get access name *** */
287 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_access_audio && *p_sys->psz_access_audio )
289 psz_access = p_sys->psz_access_audio;
291 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_access_video && *p_sys->psz_access_video )
293 psz_access = p_sys->psz_access_video;
297 psz_access = p_sys->psz_access;
300 /* *** get mux name *** */
301 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_mux_audio && *p_sys->psz_mux_audio )
303 psz_mux = p_sys->psz_mux_audio;
305 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_mux_video && *p_sys->psz_mux_video )
307 psz_mux = p_sys->psz_mux_video;
311 psz_mux = p_sys->psz_mux;
314 /* Get url (%d expanded as a codec count, %c expanded as codec fcc ) */
315 if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_dst_audio && *p_sys->psz_dst_audio )
317 psz_dst = es_print_url( p_sys->psz_dst_audio, p_fmt->i_codec,
318 p_sys->i_count_audio, psz_access, psz_mux );
320 else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_dst_video && *p_sys->psz_dst_video )
322 psz_dst = es_print_url( p_sys->psz_dst_video, p_fmt->i_codec,
323 p_sys->i_count_video, psz_access, psz_mux );
328 if( p_fmt->i_cat == VIDEO_ES )
330 i_count = p_sys->i_count_video;
332 else if( p_fmt->i_cat == AUDIO_ES )
334 i_count = p_sys->i_count_audio;
338 i_count = p_sys->i_count;
341 psz_dst = es_print_url( p_sys->psz_dst, p_fmt->i_codec,
342 i_count, psz_access, psz_mux );
346 if( p_fmt->i_cat == VIDEO_ES )
348 p_sys->i_count_video++;
350 else if( p_fmt->i_cat == AUDIO_ES )
352 p_sys->i_count_audio++;
354 msg_Dbg( p_stream, "creating `%s/%s://%s'",
355 psz_access, psz_mux, psz_dst );
357 /* *** find and open appropriate access module *** */
358 p_access = sout_AccessOutNew( p_sout, psz_access, psz_dst );
359 if( p_access == NULL )
361 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
362 psz_access, psz_mux, psz_dst );
366 /* *** find and open appropriate mux module *** */
367 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
370 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
371 psz_access, psz_mux, psz_dst );
372 sout_AccessOutDelete( p_access );
376 id = malloc( sizeof( sout_stream_id_t ) );
378 id->p_input = sout_MuxAddStream( p_mux, p_fmt );
380 if( id->p_input == NULL )
384 sout_MuxDelete( p_mux );
385 sout_AccessOutDelete( p_access );
393 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
395 sout_access_out_t *p_access = id->p_mux->p_access;
396 sout_MuxDelete( id->p_mux );
397 sout_MuxDeleteStream( id->p_mux, id->p_input );
398 sout_AccessOutDelete( p_access );
404 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
407 sout_MuxSendBuffer( id->p_mux, id->p_input, p_buffer );