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>
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 /*****************************************************************************
27 * o this only works for ogg streams, and there's no checking about that yet.
28 * o there's a memleak somewhere, quite huge. i'm unsure if its somewhere
29 * in libshout, in vlc or even in this patch...
33 * vlc v4l:/dev/video:input=2:norm=pal:size=192x144 \
34 * --sout '#transcode{vcodec=theora,vb=300,acodec=vorb,ab=96}\
35 * :std{access=shout,mux=ogg,url=localhost:8005}'
37 *****************************************************************************/
39 /*****************************************************************************
41 *****************************************************************************/
47 #include <shout/shout.h>
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Open ( vlc_object_t * );
53 static void Close( vlc_object_t * );
55 #define SOUT_CFG_PREFIX "sout-shout-"
57 #define NAME_TEXT N_("Stream-name")
58 #define NAME_LONGTEXT N_("The name this stream/channel will get on the icecast server." )
60 #define DESCRIPTION_TEXT N_("Stream-description")
61 #define DESCRIPTION_LONGTEXT N_("A description of the stream content. (Information about " \
64 #define MP3_TEXT N_("Stream MP3")
65 #define MP3_LONGTEXT N_("Normally you have to feed the shoutcast module with Ogg streams. " \
66 "This option allows you to feed MP3 streams instead, so you can " \
67 "forward MP3 streams to the icecast server." )
70 set_description( _("libshout (icecast) output") );
71 set_shortname( N_("Shout" ));
72 set_capability( "sout access", 50 );
73 set_category( CAT_SOUT );
74 set_subcategory( SUBCAT_SOUT_ACO );
75 add_shortcut( "shout" );
76 add_string( SOUT_CFG_PREFIX "name", "VLC media player - Live stream", NULL,
77 NAME_TEXT, NAME_LONGTEXT, VLC_FALSE );
78 add_string( SOUT_CFG_PREFIX "description", "Live stream from VLC media player. " \
79 "http://www.videolan.org/vlc", NULL,
80 DESCRIPTION_TEXT, DESCRIPTION_LONGTEXT, VLC_FALSE );
81 add_bool( SOUT_CFG_PREFIX "mp3", VLC_FALSE, NULL,
82 MP3_TEXT, MP3_LONGTEXT, VLC_TRUE );
83 set_callbacks( Open, Close );
86 /*****************************************************************************
88 *****************************************************************************/
89 static const char *ppsz_sout_options[] = {
90 "name", "description", "mp3", NULL
94 /*****************************************************************************
96 *****************************************************************************/
97 static int Write( sout_access_out_t *, block_t * );
98 static int Seek ( sout_access_out_t *, off_t );
99 static int Read ( sout_access_out_t *, block_t * );
101 struct sout_access_out_sys_t
106 /*****************************************************************************
107 * Open: open the shout connection
108 *****************************************************************************/
109 static int Open( vlc_object_t *p_this )
111 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
112 sout_access_out_sys_t *p_sys;
118 char *psz_accessname = NULL;
119 char *psz_parser = NULL;
120 char *psz_user = NULL;
121 char *psz_pass = NULL;
122 char *psz_host = NULL;
123 char *psz_mount = NULL;
124 char *psz_name = NULL;
125 char *psz_description = NULL;
126 char *tmp_port = NULL;
128 sout_CfgParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
130 psz_accessname = psz_parser = strdup( p_access->psz_name );
132 if( !p_access->psz_name )
135 "please specify url=user:password@host:port/mountpoint" );
139 /* Parse connection data user:pwd@host:port/mountpoint */
140 psz_user = psz_parser;
141 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
142 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
143 psz_pass = psz_parser;
144 while( psz_parser[0] && psz_parser[0] != '@' ) psz_parser++;
145 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
146 psz_host = psz_parser;
147 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
148 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
149 tmp_port = psz_parser;
150 while( psz_parser[0] && psz_parser[0] != '/' ) psz_parser++;
151 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
152 psz_mount = psz_parser;
154 i_port = atoi( tmp_port );
156 p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) );
159 msg_Err( p_access, "out of memory" );
160 free( psz_accessname );
164 var_Get( p_access, SOUT_CFG_PREFIX "name", &val );
165 if( *val.psz_string )
166 psz_name = val.psz_string;
168 free( val.psz_string );
170 var_Get( p_access, SOUT_CFG_PREFIX "description", &val );
171 if( *val.psz_string )
172 psz_description = val.psz_string;
174 free( val.psz_string );
176 p_shout = p_sys->p_shout = shout_new();
178 || shout_set_host( p_shout, psz_host ) != SHOUTERR_SUCCESS
179 || shout_set_protocol( p_shout, SHOUT_PROTOCOL_HTTP )
181 || shout_set_port( p_shout, i_port ) != SHOUTERR_SUCCESS
182 || shout_set_password( p_shout, psz_pass ) != SHOUTERR_SUCCESS
183 || shout_set_mount( p_shout, psz_mount ) != SHOUTERR_SUCCESS
184 || shout_set_user( p_shout, psz_user ) != SHOUTERR_SUCCESS
185 || shout_set_agent( p_shout, "VLC media player " VERSION ) != SHOUTERR_SUCCESS
186 || shout_set_name( p_shout, psz_name ) != SHOUTERR_SUCCESS
187 || shout_set_description( p_shout, psz_description ) != SHOUTERR_SUCCESS
188 // || shout_set_nonblocking( p_shout, 1 ) != SHOUTERR_SUCCESS
191 msg_Err( p_access, "failed to initialize shout streaming to %s:%i/%s",
192 psz_host, i_port, psz_mount );
193 free( p_access->p_sys );
194 free( psz_accessname );
198 if( psz_name ) free( psz_name );
199 if( psz_description ) free( psz_description );
201 var_Get( p_access, SOUT_CFG_PREFIX "mp3", &val );
202 if( val.b_bool == VLC_TRUE )
203 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_MP3 );
205 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_OGG );
207 if( i_ret != SHOUTERR_SUCCESS )
209 msg_Err( p_access, "failed to set the shoutcast streaming format" );
210 free( p_access->p_sys );
211 free( psz_accessname );
215 i_ret = shout_open( p_shout );
216 if( i_ret == SHOUTERR_SUCCESS )
218 i_ret = SHOUTERR_CONNECTED;
222 for non-blocking, use:
223 while( i_ret == SHOUTERR_BUSY )
226 i_ret = shout_get_connected( p_shout );
229 if( i_ret != SHOUTERR_CONNECTED )
231 msg_Err( p_access, "failed to open shout stream to %s:%i/%s: %s",
232 psz_host, i_port, psz_mount, shout_get_error(p_shout) );
233 free( p_access->p_sys );
234 free( psz_accessname );
238 p_access->pf_write = Write;
239 p_access->pf_read = Read;
240 p_access->pf_seek = Seek;
242 msg_Dbg( p_access, "shout access output opened (%s@%s:%i/%s)",
243 psz_user, psz_host, i_port, psz_mount );
245 /* Update pace control flag */
246 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
248 p_access->p_sout->i_out_pace_nocontrol++;
251 free( psz_accessname );
256 /*****************************************************************************
257 * Close: close the target
258 *****************************************************************************/
259 static void Close( vlc_object_t * p_this )
261 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
263 if( p_access->p_sys && p_access->p_sys->p_shout )
265 shout_close( p_access->p_sys->p_shout );
268 free( p_access->p_sys );
270 /* Update pace control flag */
271 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
273 p_access->p_sout->i_out_pace_nocontrol--;
276 msg_Dbg( p_access, "shout access output closed" );
279 /*****************************************************************************
280 * Read: standard read -- not supported
281 *****************************************************************************/
282 static int Read( sout_access_out_t *p_access, block_t *p_buffer )
284 msg_Err( p_access, "cannot read from shout" );
288 /*****************************************************************************
289 * Write: standard write
290 *****************************************************************************/
291 static int Write( sout_access_out_t *p_access, block_t *p_buffer )
295 shout_sync( p_access->p_sys->p_shout );
298 block_t *p_next = p_buffer->p_next;
300 if( shout_send( p_access->p_sys->p_shout,
301 p_buffer->p_buffer, p_buffer->i_buffer )
302 == SHOUTERR_SUCCESS )
304 i_write += p_buffer->i_buffer;
308 msg_Err( p_access, "cannot write to stream: %s",
309 shout_get_error(p_access->p_sys->p_shout) );
311 block_Release( p_buffer );
313 /* XXX: Unsure if that's the cause for some audio trouble... */
321 /*****************************************************************************
322 * Seek: seek to a specific location -- not supported
323 *****************************************************************************/
324 static int Seek( sout_access_out_t *p_access, off_t i_pos )
326 msg_Err( p_access, "cannot seek on shout" );