1 /*****************************************************************************
2 * shout.c: This module forwards vorbis streams to an icecast server
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
7 * Authors: Daniel Fischer <dan at subsignal dot org>
8 * Derk-Jan Hartman <hartman at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
28 * - this only works for ogg and/or mp3, and we don't check this yet.
29 * - MP3 metadata is not passed along, since metadata is only available after
30 * this module is opened.
34 * vlc v4l:/dev/video:input=2:norm=pal:size=192x144 \
35 * --sout '#transcode{vcodec=theora,vb=300,acodec=vorb,ab=96}\
36 * :std{access=shout,mux=ogg,dst=localhost:8005}'
38 *****************************************************************************/
40 /*****************************************************************************
42 *****************************************************************************/
48 #include <shout/shout.h>
50 /*****************************************************************************
52 *****************************************************************************/
53 static int Open ( vlc_object_t * );
54 static void Close( vlc_object_t * );
56 #define SOUT_CFG_PREFIX "sout-shout-"
58 #define NAME_TEXT N_("Stream name")
59 #define NAME_LONGTEXT N_("Name to give to this stream/channel on the " \
62 #define DESCRIPTION_TEXT N_("Stream description")
63 #define DESCRIPTION_LONGTEXT N_("Description of the stream content or " \
64 "information about your channel." )
66 #define MP3_TEXT N_("Stream MP3")
67 #define MP3_LONGTEXT N_("You normally have to feed the shoutcast module " \
68 "with Ogg streams. It is also possible to stream " \
69 "MP3 instead, so you can "\
70 "forward MP3 streams to the icecast server." )
73 set_description( _("IceCAST output") );
74 set_shortname( "Shoutcast" );
75 set_capability( "sout access", 50 );
76 set_category( CAT_SOUT );
77 set_subcategory( SUBCAT_SOUT_ACO );
78 add_shortcut( "shout" );
79 add_string( SOUT_CFG_PREFIX "name", "VLC media player - Live stream", NULL,
80 NAME_TEXT, NAME_LONGTEXT, VLC_FALSE );
81 add_string( SOUT_CFG_PREFIX "description",
82 "Live stream from VLC media player. " \
83 "http://www.videolan.org/vlc", NULL,
84 DESCRIPTION_TEXT, DESCRIPTION_LONGTEXT, VLC_FALSE );
85 add_bool( SOUT_CFG_PREFIX "mp3", VLC_FALSE, NULL,
86 MP3_TEXT, MP3_LONGTEXT, VLC_TRUE );
87 set_callbacks( Open, Close );
90 /*****************************************************************************
92 *****************************************************************************/
93 static const char *ppsz_sout_options[] = {
94 "name", "description", "mp3", NULL
98 /*****************************************************************************
100 *****************************************************************************/
101 static int Write( sout_access_out_t *, block_t * );
102 static int Seek ( sout_access_out_t *, off_t );
103 static int Read ( sout_access_out_t *, block_t * );
105 struct sout_access_out_sys_t
110 /*****************************************************************************
111 * Open: open the shout connection
112 *****************************************************************************/
113 static int Open( vlc_object_t *p_this )
115 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
116 sout_access_out_sys_t *p_sys;
122 char *psz_accessname = NULL;
123 char *psz_parser = NULL;
124 char *psz_user = NULL;
125 char *psz_pass = NULL;
126 char *psz_host = NULL;
127 char *psz_mount = NULL;
128 char *psz_name = NULL;
129 char *psz_description = NULL;
130 char *tmp_port = NULL;
132 sout_CfgParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
134 psz_accessname = psz_parser = strdup( p_access->psz_name );
136 if( !p_access->psz_name )
139 "please specify url=user:password@host:port/mountpoint" );
143 /* Parse connection data user:pwd@host:port/mountpoint */
144 psz_user = psz_parser;
145 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
146 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
147 psz_pass = psz_parser;
148 while( psz_parser[0] && psz_parser[0] != '@' ) psz_parser++;
149 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
150 psz_host = psz_parser;
151 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
152 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
153 tmp_port = psz_parser;
154 while( psz_parser[0] && psz_parser[0] != '/' ) psz_parser++;
155 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
156 psz_mount = psz_parser;
158 i_port = atoi( tmp_port );
160 p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) );
163 msg_Err( p_access, "out of memory" );
164 free( psz_accessname );
168 var_Get( p_access, SOUT_CFG_PREFIX "name", &val );
169 if( *val.psz_string )
170 psz_name = val.psz_string;
172 free( val.psz_string );
174 var_Get( p_access, SOUT_CFG_PREFIX "description", &val );
175 if( *val.psz_string )
176 psz_description = val.psz_string;
178 free( val.psz_string );
180 p_shout = p_sys->p_shout = shout_new();
182 || shout_set_host( p_shout, psz_host ) != SHOUTERR_SUCCESS
183 || shout_set_protocol( p_shout, SHOUT_PROTOCOL_HTTP )
185 || shout_set_port( p_shout, i_port ) != SHOUTERR_SUCCESS
186 || shout_set_password( p_shout, psz_pass ) != SHOUTERR_SUCCESS
187 || shout_set_mount( p_shout, psz_mount ) != SHOUTERR_SUCCESS
188 || shout_set_user( p_shout, psz_user ) != SHOUTERR_SUCCESS
189 || shout_set_agent( p_shout, "VLC media player " VERSION ) != SHOUTERR_SUCCESS
190 || shout_set_name( p_shout, psz_name ) != SHOUTERR_SUCCESS
191 || shout_set_description( p_shout, psz_description ) != SHOUTERR_SUCCESS
192 // || shout_set_nonblocking( p_shout, 1 ) != SHOUTERR_SUCCESS
195 msg_Err( p_access, "failed to initialize shout streaming to %s:%i/%s",
196 psz_host, i_port, psz_mount );
197 free( p_access->p_sys );
198 free( psz_accessname );
202 if( psz_name ) free( psz_name );
203 if( psz_description ) free( psz_description );
205 var_Get( p_access, SOUT_CFG_PREFIX "mp3", &val );
206 if( val.b_bool == VLC_TRUE )
207 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_MP3 );
209 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_OGG );
211 if( i_ret != SHOUTERR_SUCCESS )
213 msg_Err( p_access, "failed to set the shoutcast streaming format" );
214 free( p_access->p_sys );
215 free( psz_accessname );
219 i_ret = shout_open( p_shout );
220 if( i_ret == SHOUTERR_SUCCESS )
222 i_ret = SHOUTERR_CONNECTED;
226 for non-blocking, use:
227 while( i_ret == SHOUTERR_BUSY )
230 i_ret = shout_get_connected( p_shout );
233 if( i_ret != SHOUTERR_CONNECTED )
235 msg_Err( p_access, "failed to open shout stream to %s:%i/%s: %s",
236 psz_host, i_port, psz_mount, shout_get_error(p_shout) );
237 free( p_access->p_sys );
238 free( psz_accessname );
242 p_access->pf_write = Write;
243 p_access->pf_read = Read;
244 p_access->pf_seek = Seek;
246 msg_Dbg( p_access, "shout access output opened (%s@%s:%i/%s)",
247 psz_user, psz_host, i_port, psz_mount );
249 /* Update pace control flag */
250 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
252 p_access->p_sout->i_out_pace_nocontrol++;
255 free( psz_accessname );
260 /*****************************************************************************
261 * Close: close the target
262 *****************************************************************************/
263 static void Close( vlc_object_t * p_this )
265 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
267 if( p_access->p_sys && p_access->p_sys->p_shout )
269 shout_close( p_access->p_sys->p_shout );
272 free( p_access->p_sys );
274 /* Update pace control flag */
275 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
277 p_access->p_sout->i_out_pace_nocontrol--;
280 msg_Dbg( p_access, "shout access output closed" );
283 /*****************************************************************************
284 * Read: standard read -- not supported
285 *****************************************************************************/
286 static int Read( sout_access_out_t *p_access, block_t *p_buffer )
288 msg_Err( p_access, "cannot read from shout" );
292 /*****************************************************************************
293 * Write: standard write
294 *****************************************************************************/
295 static int Write( sout_access_out_t *p_access, block_t *p_buffer )
299 shout_sync( p_access->p_sys->p_shout );
302 block_t *p_next = p_buffer->p_next;
304 if( shout_send( p_access->p_sys->p_shout,
305 p_buffer->p_buffer, p_buffer->i_buffer )
306 == SHOUTERR_SUCCESS )
308 i_write += p_buffer->i_buffer;
312 msg_Err( p_access, "cannot write to stream: %s",
313 shout_get_error(p_access->p_sys->p_shout) );
315 block_Release( p_buffer );
317 /* XXX: Unsure if that's the cause for some audio trouble... */
325 /*****************************************************************************
326 * Seek: seek to a specific location -- not supported
327 *****************************************************************************/
328 static int Seek( sout_access_out_t *p_access, off_t i_pos )
330 msg_Err( p_access, "cannot seek on shout" );