[mad-user] Playing Internet Streams with Madplay

john cooper john.cooper at third-harmonic.com
Thu Oct 12 14:00:29 PDT 2006

Mark Kane wrote:
> On Thu, Oct 12, 2006, at 11:55:42 -0700, Rob Leslie wrote:
>> On Oct 8, 2006, at 11:30 AM, Mark Kane wrote:
>>> This may be a stupid question, but I've read through the madplay  
>>> man page and online documentation several times and I cannot get
>>> an MP3 Internet radio station (SHOUTcast) to play with madplay.
>>> Every time I try on the command line, I get:
>>> ------------------------------------------------------
>>> [mixx941 at amd64:~]% madplay http://stream.com:8000
>>> MPEG Audio Decoder 0.15.2 (beta) - Copyright (C) 2000-2004 Robert  
>>> Leslie et al.
>>> http://stream.com:8000: No such file or directory
>>> ------------------------------------------------------
>> There's no network streaming support in madplay; to play a stream  
>> this way, you could instead:
>>    % wget -O - http://stream.com:8000 | madplay -
> Thanks. That is what I thought, but someone on an Asterisk mailing list
> kept insisting there is a way to play streams with madplay directly so I
> thought I was missing something. I tried piping it into madplay
> using cURL which worked great on the command line, but pipes wouldn't
> work in Asterisk's music on hold.

I'd written a decode engine wrapped around libmad which treats
the input as a byte stream.  Basically libmad wants to consume
a virtually endless linear buffer of encoded data.  However
you can redirect the location of decode such that a fixed
size buffer can emulate an endless data stream.

mad_frame_decode() returns after consuming a frame which provides
the opportunity to perform seamless relocation of the buffer data.
This requires moving the remaining frame aligned buffer data to
the buffer head and pointing the libmad decode at its new
location.  Along with doing so would be filling the buffer
with additional stream data as presumably the reason for the
relocation was running close to the fixed buffer end.

This isn't too complicated.  But it gets more so when implementing
trick/skip play in an arbitrary direction.  Ie: a stream browsing
operation which continually skips a few seconds fwd/back without
pcm output and then generates a few pcm frames as output.


john.cooper at third-harmonic.com

More information about the mad-user mailing list