1 /*****************************************************************************
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 i have lots of problems with audio, but i think they are not caused
30 * o there's a memleak somewhere, quite huge. i'm unsure if its somewhere
31 * in libshout, in vlc or even in this patch...
35 * vlc v4l:/dev/video:input=2:norm=pal:size=192x144 \
36 * --sout '#transcode{vcodec=theora,vb=300,acodec=vorb,ab=96}\
37 * :std{access=shout,mux=ogg,url=localhost:8005}'
39 *****************************************************************************/
41 /*****************************************************************************
43 *****************************************************************************/
49 #include <shout/shout.h>
51 /*****************************************************************************
53 *****************************************************************************/
54 static int Open ( vlc_object_t * );
55 static void Close( vlc_object_t * );
57 #define SOUT_CFG_PREFIX "sout-shout-"
60 set_description( _("libshout (icecast) output") );
61 set_shortname( N_("Shout" ));
62 set_capability( "sout access", 50 );
63 set_category( CAT_SOUT );
64 set_subcategory( SUBCAT_SOUT_ACO );
65 add_shortcut( "shout" );
66 set_callbacks( Open, Close );
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Write( sout_access_out_t *, block_t * );
74 static int Seek ( sout_access_out_t *, off_t );
75 static int Read ( sout_access_out_t *, block_t * );
77 struct sout_access_out_sys_t
82 /*****************************************************************************
83 * Open: open the shout connection
84 *****************************************************************************/
85 static int Open( vlc_object_t *p_this )
87 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
88 sout_access_out_sys_t *p_sys;
92 char *psz_user, *psz_pass, *psz_host, *psz_mount;
95 char *parser = strdup( p_access->psz_name );
98 if( !p_access->psz_name )
101 "please specify url=user:password@host:port/mountpoint" );
105 /* Parse connection data user:pwd@host:port/mountpoint */
107 while( parser[0] && parser[0] != ':' ) parser++;
108 if( parser[0] ) { parser[0] = 0; parser++; }
110 while( parser[0] && parser[0] != '@' ) parser++;
111 if( parser[0] ) { parser[0] = 0; parser++; }
113 while( parser[0] && parser[0] != ':' ) parser++;
114 if( parser[0] ) { parser[0] = 0; parser++; }
116 while( parser[0] && parser[0] != '/' ) parser++;
117 if( parser[0] ) { parser[0] = 0; parser++; }
120 i_port = atoi( tmp_port );
122 p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) );
125 msg_Err( p_access, "out of memory" );
130 p_shout = p_sys->p_shout = shout_new();
132 || shout_set_host( p_shout, psz_host ) != SHOUTERR_SUCCESS
133 || shout_set_protocol( p_shout, SHOUT_PROTOCOL_HTTP )
135 || shout_set_port( p_shout, i_port ) != SHOUTERR_SUCCESS
136 || shout_set_password( p_shout, psz_pass ) != SHOUTERR_SUCCESS
137 || shout_set_mount( p_shout, psz_mount ) != SHOUTERR_SUCCESS
138 || shout_set_user( p_shout, psz_user ) != SHOUTERR_SUCCESS
139 || shout_set_format( p_shout, SHOUT_FORMAT_OGG ) != SHOUTERR_SUCCESS
140 // || shout_set_nonblocking( p_shout, 1 ) != SHOUTERR_SUCCESS
143 msg_Err( p_access, "failed to initialize shout streaming to %s:%i%s",
144 psz_host, i_port, psz_mount );
145 free( p_access->p_sys );
150 i_ret = shout_open( p_shout );
151 if( i_ret == SHOUTERR_SUCCESS )
153 i_ret = SHOUTERR_CONNECTED;
157 for non-blocking, use:
158 while( i_ret == SHOUTERR_BUSY )
161 i_ret = shout_get_connected( p_shout );
164 if( i_ret != SHOUTERR_CONNECTED )
166 msg_Err( p_access, "failed to open shout stream to %s:%i%s: %s",
167 psz_host, i_port, psz_mount, shout_get_error(p_shout) );
168 free( p_access->p_sys );
173 p_access->pf_write = Write;
174 p_access->pf_read = Read;
175 p_access->pf_seek = Seek;
177 msg_Dbg( p_access, "shout access output opened (%s@%s:%i%s)",
178 psz_user, psz_host, i_port, psz_mount );
180 /* Update pace control flag */
181 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
183 p_access->p_sout->i_out_pace_nocontrol++;
186 /* FIXME: it should be free()d somewhere, but not here.... ? */
192 /*****************************************************************************
193 * Close: close the target
194 *****************************************************************************/
195 static void Close( vlc_object_t * p_this )
197 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
199 if( p_access->p_sys && p_access->p_sys->p_shout )
201 shout_close( p_access->p_sys->p_shout );
204 free( p_access->p_sys );
206 /* Update pace control flag */
207 if( p_access->psz_access && !strcmp( p_access->psz_access, "stream" ) )
209 p_access->p_sout->i_out_pace_nocontrol--;
212 msg_Dbg( p_access, "shout access output closed" );
215 /*****************************************************************************
216 * Read: standard read -- not supported
217 *****************************************************************************/
218 static int Read( sout_access_out_t *p_access, block_t *p_buffer )
220 msg_Err( p_access, "cannot read from shout" );
224 /*****************************************************************************
225 * Write: standard write
226 *****************************************************************************/
227 static int Write( sout_access_out_t *p_access, block_t *p_buffer )
233 block_t *p_next = p_buffer->p_next;
235 if( shout_send( p_access->p_sys->p_shout,
236 p_buffer->p_buffer, p_buffer->i_buffer )
237 == SHOUTERR_SUCCESS )
239 i_write += p_buffer->i_buffer;
243 msg_Err( p_access, "cannot write to stream: %s",
244 shout_get_error(p_access->p_sys->p_shout) );
246 block_Release( p_buffer );
248 /* XXX: Unsure if that's the cause for some audio trouble... */
249 //shout_sync( p_access->p_sys->p_shout );
257 /*****************************************************************************
258 * Seek: seek to a specific location -- not supported
259 *****************************************************************************/
260 static int Seek( sout_access_out_t *p_access, off_t i_pos )
262 msg_Err( p_access, "cannot seek on shout" );