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_("The name this stream/channel will get on the icecast server." )
61 #define DESCRIPTION_TEXT N_("Stream-description")
62 #define DESCRIPTION_LONGTEXT N_("A description of the stream content. (Information about " \
65 #define MP3_TEXT N_("Stream MP3")
66 #define MP3_LONGTEXT N_("Normally you have to feed the shoutcast module with Ogg streams. " \
67 "This option allows you to feed MP3 streams instead, so you can " \
68 "forward MP3 streams to the icecast server." )
71 set_description( _("libshout (icecast) output") );
72 set_shortname( "Shout" );
73 set_capability( "sout access", 50 );
74 set_category( CAT_SOUT );
75 set_subcategory( SUBCAT_SOUT_ACO );
76 add_shortcut( "shout" );
77 add_string( SOUT_CFG_PREFIX "name", "VLC media player - Live stream", NULL,
78 NAME_TEXT, NAME_LONGTEXT, VLC_FALSE );
79 add_string( SOUT_CFG_PREFIX "description", "Live stream from VLC media player. " \
80 "http://www.videolan.org/vlc", NULL,
81 DESCRIPTION_TEXT, DESCRIPTION_LONGTEXT, VLC_FALSE );
82 add_bool( SOUT_CFG_PREFIX "mp3", VLC_FALSE, NULL,
83 MP3_TEXT, MP3_LONGTEXT, VLC_TRUE );
84 set_callbacks( Open, Close );
87 /*****************************************************************************
89 *****************************************************************************/
90 static const char *ppsz_sout_options[] = {
91 "name", "description", "mp3", NULL
95 /*****************************************************************************
97 *****************************************************************************/
98 static int Write( sout_access_out_t *, block_t * );
99 static int Seek ( sout_access_out_t *, off_t );
100 static int Read ( sout_access_out_t *, block_t * );
102 struct sout_access_out_sys_t
107 /*****************************************************************************
108 * Open: open the shout connection
109 *****************************************************************************/
110 static int Open( vlc_object_t *p_this )
112 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
113 sout_access_out_sys_t *p_sys;
119 char *psz_accessname = NULL;
120 char *psz_parser = NULL;
121 char *psz_user = NULL;
122 char *psz_pass = NULL;
123 char *psz_host = NULL;
124 char *psz_mount = NULL;
125 char *psz_name = NULL;
126 char *psz_description = NULL;
127 char *tmp_port = NULL;
129 sout_CfgParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
131 psz_accessname = psz_parser = strdup( p_access->psz_name );
133 if( !p_access->psz_name )
136 "please specify url=user:password@host:port/mountpoint" );
140 /* Parse connection data user:pwd@host:port/mountpoint */
141 psz_user = psz_parser;
142 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
143 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
144 psz_pass = 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_host = psz_parser;
148 while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
149 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
150 tmp_port = psz_parser;
151 while( psz_parser[0] && psz_parser[0] != '/' ) psz_parser++;
152 if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
153 psz_mount = psz_parser;
155 i_port = atoi( tmp_port );
157 p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) );
160 msg_Err( p_access, "out of memory" );
161 free( psz_accessname );
165 var_Get( p_access, SOUT_CFG_PREFIX "name", &val );
166 if( *val.psz_string )
167 psz_name = val.psz_string;
169 free( val.psz_string );
171 var_Get( p_access, SOUT_CFG_PREFIX "description", &val );
172 if( *val.psz_string )
173 psz_description = val.psz_string;
175 free( val.psz_string );
177 p_shout = p_sys->p_shout = shout_new();
179 || shout_set_host( p_shout, psz_host ) != SHOUTERR_SUCCESS
180 || shout_set_protocol( p_shout, SHOUT_PROTOCOL_HTTP )
182 || shout_set_port( p_shout, i_port ) != SHOUTERR_SUCCESS
183 || shout_set_password( p_shout, psz_pass ) != SHOUTERR_SUCCESS
184 || shout_set_mount( p_shout, psz_mount ) != SHOUTERR_SUCCESS
185 || shout_set_user( p_shout, psz_user ) != SHOUTERR_SUCCESS
186 || shout_set_agent( p_shout, "VLC media player " VERSION ) != SHOUTERR_SUCCESS
187 || shout_set_name( p_shout, psz_name ) != SHOUTERR_SUCCESS
188 || shout_set_description( p_shout, psz_description ) != SHOUTERR_SUCCESS
189 // || shout_set_nonblocking( p_shout, 1 ) != SHOUTERR_SUCCESS
192 msg_Err( p_access, "failed to initialize shout streaming to %s:%i/%s",
193 psz_host, i_port, psz_mount );
194 free( p_access->p_sys );
195 free( psz_accessname );
199 if( psz_name ) free( psz_name );
200 if( psz_description ) free( psz_description );
202 var_Get( p_access, SOUT_CFG_PREFIX "mp3", &val );
203 if( val.b_bool == VLC_TRUE )
204 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_MP3 );
206 i_ret = shout_set_format( p_shout, SHOUT_FORMAT_OGG );
208 if( i_ret != SHOUTERR_SUCCESS )
210 msg_Err( p_access, "failed to set the shoutcast streaming format" );
211 free( p_access->p_sys );
212 free( psz_accessname );
216 i_ret = shout_open( p_shout );
217 if( i_ret == SHOUTERR_SUCCESS )
219 i_ret = SHOUTERR_CONNECTED;
223 for non-blocking, use:
224 while( i_ret == SHOUTERR_BUSY )
227 i_ret = shout_get_connected( p_shout );
230 if( i_ret != SHOUTERR_CONNECTED )
232 msg_Err( p_access, "failed to open shout stream to %s:%i/%s: %s",
233 psz_host, i_port, psz_mount, shout_get_error(p_shout) );
234 free( p_access->p_sys );
235 free( psz_accessname );
239 p_access->pf_write = Write;
240 p_access->pf_read = Read;
241 p_access->pf_seek = Seek;
243 msg_Dbg( p_access, "shout access output opened (%s@%s:%i/%s)",
244 psz_user, psz_host, i_port, psz_mount );
246 /* Update pace control flag */
247 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
249 p_access->p_sout->i_out_pace_nocontrol++;
252 free( psz_accessname );
257 /*****************************************************************************
258 * Close: close the target
259 *****************************************************************************/
260 static void Close( vlc_object_t * p_this )
262 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
264 if( p_access->p_sys && p_access->p_sys->p_shout )
266 shout_close( p_access->p_sys->p_shout );
269 free( p_access->p_sys );
271 /* Update pace control flag */
272 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
274 p_access->p_sout->i_out_pace_nocontrol--;
277 msg_Dbg( p_access, "shout access output closed" );
280 /*****************************************************************************
281 * Read: standard read -- not supported
282 *****************************************************************************/
283 static int Read( sout_access_out_t *p_access, block_t *p_buffer )
285 msg_Err( p_access, "cannot read from shout" );
289 /*****************************************************************************
290 * Write: standard write
291 *****************************************************************************/
292 static int Write( sout_access_out_t *p_access, block_t *p_buffer )
296 shout_sync( p_access->p_sys->p_shout );
299 block_t *p_next = p_buffer->p_next;
301 if( shout_send( p_access->p_sys->p_shout,
302 p_buffer->p_buffer, p_buffer->i_buffer )
303 == SHOUTERR_SUCCESS )
305 i_write += p_buffer->i_buffer;
309 msg_Err( p_access, "cannot write to stream: %s",
310 shout_get_error(p_access->p_sys->p_shout) );
312 block_Release( p_buffer );
314 /* XXX: Unsure if that's the cause for some audio trouble... */
322 /*****************************************************************************
323 * Seek: seek to a specific location -- not supported
324 *****************************************************************************/
325 static int Seek( sout_access_out_t *p_access, off_t i_pos )
327 msg_Err( p_access, "cannot seek on shout" );