Does MPD support HLS streams?

Discuss client development (or even MPD development if you feel so inclined), ask questions about the client libs, MPD feature requests from client developers, etc...
Post Reply
lordpixel
Posts: 6
Joined: April 7th, 2015, 3:40 am

Does MPD support HLS streams?

Post by lordpixel »

Hi all,

I’ve been experimenting with mpd and in particular I have been trying to get it to play HLS streams. My initial attempts failed but in the end I was able to get them to play. As you’ll see I have a couple of questions about what I should expect mpd to be able to do. Depending on the responses I get I may go file a bug, otherwise perhaps this will at least help others understand what is going on.

Let me explain how I was able to get the stream to play. I started with the international stream for BBC 6 music:

Code: Select all

http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/llnw/bbc_6music.m3u8
The direct approach returns an error about not being able to decode the stream:

Code: Select all

mpc load http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/llnw/bbc_6music.m3u8
mlc play
So I decided to use curl to debug. Fetching the first URI return a second playlist URI, in my case for the Lime Light Networks Content Distribution Network:

Code: Select all

$ curl http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/llnw/bbc_6music.m3u8
#EXTM3U
#EXT-X-VERSION:2
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=101760,CODECS="mp4a.40.5"
http://as-hls-ww-live.bbcfmt.vo.llnwd.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24
Curling that URI gives me a 302 redirect

Code: Select all

curl -v http://as-hls-ww-live.bbcfmt.vo.llnwd.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24
* Hostname was NOT found in DNS cache
*   Trying 208.111.128.7...
* Connected to as-hls-ww-live.bbcfmt.vo.llnwd.net (208.111.128.7) port 80 (#0)
> GET /pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24 HTTP/1.1
> User-Agent: curl/7.37.1
> Host: as-hls-ww-live.bbcfmt.vo.llnwd.net
> Accept: */*
> 
< HTTP/1.1 302 Moved Temporarily
* Server EdgePrism/4.2.4.1 is not blacklisted
< Server: EdgePrism/4.2.4.1
< Date: Sun, 05 Apr 2015 13:05:58 GMT
< Location: http://ic.8eff4641.0b657a.as-hls-ww-live.bbcfmt.vo.llnwi.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24
< Content-Length: 0
< Connection: keep-alive
< Access-Control-Allow-Headers: Origin, Range, Accept-Encoding, Referer
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: Server, Range, Content-Length, Content-Range
< 
* Connection #0 to host as-hls-ww-live.bbcfmt.vo.llnwd.net left intact
And Curling that gets me the first 5 URIs in an HLS stream as you might expect

Code: Select all

curl http://ic.8eff4641.0b657a.as-hls-ww-live.bbcfmt.vo.llnwi.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24
#EXTM3U
#EXT-X-VERSION:2
## Created with Unified Streaming Platform(version=1.7.3)
#EXT-X-MEDIA-SEQUENCE:223162378
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:7
#USP-X-TIMESTAMP-MAP:MPEGTS=1748817312,LOCAL=2015-04-05T13:06:52.800000Z
#EXT-X-PROGRAM-DATE-TIME:2015-04-05T13:06:52.800000Z
#EXTINF:6, no desc
bbc_6music-audio=96000-223162378.ts?dvr_window_length=24
#EXTINF:6, no desc
bbc_6music-audio=96000-223162379.ts?dvr_window_length=24
#EXTINF:6, no desc
bbc_6music-audio=96000-223162380.ts?dvr_window_length=24
#EXTINF:6, no desc
bbc_6music-audio=96000-223162381.ts?dvr_window_length=24
#EXTINF:6, no desc
bbc_6music-audio=96000-223162382.ts?dvr_window_length=24
If this URI is curled repeatedly one sees the number in the .ts filenames and #EXT-X-MEDIA-SEQUENCE incrementing regularly, 83, 84, 85 as per the published HLS spec. If I do

Code: Select all

mpc load http://ic.8eff4641.0b657a.as-hls-ww-live.bbcfmt.vo.llnwi.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length=24
mpc play
The music starts and runs for a few seconds before stopping. If then every few seconds I re-run the “mpc load” the new entries are added to the end of the mpd playlist and the stream plays reliably enough, so long as I keep up manually (though it did duplicate one segment one time).

Now for my two questions:

1/ It seems pretty reasonable to have nested playlists to support content distribution networks. It feels desirable that mpd should be able to follow a playlist within a playlist and do the right thing to find the files to play?

2/ Regarding HLS. Should I expect mpd to be able to poll the playlist and fetch the segments by itself - i.e. to handle the HLS live streaming format?

I guess really the question is, how much of this should be the responsibility of the client and how much should be supported by mpd itself? Clearly all the “difficult parts” of fetching the data and decoding it work just great, but what should be responsible for dealing with the HLS streaming segmentation and the redirects?

max
Forum team
Posts: 1029
Joined: January 15th, 2013, 3:43 pm

Re: Does MPD support HLS streams?

Post by max »

No, it does not. HLS is a pretty brain-dead protocol and I have never heard of anybody trying to write code for HLS with MPD.

lordpixel
Posts: 6
Joined: April 7th, 2015, 3:40 am

Re: Does MPD support HLS streams?

Post by lordpixel »

Thanks for confirming.

It is brain dead in its simplicity, but I guess that's the point. Like many of the truths we cling to, it depends almost entirely on your point of view :)

On the positive side
- it goes though firewalls like they're not there
- mpd and mpc are well enough designed that I can get the stream to play even though they don't really support it, which is impressive

I have my answer now so I'll see what my level of motivation is. I might well program up a client which can get mpd to play the streams.

max
Forum team
Posts: 1029
Joined: January 15th, 2013, 3:43 pm

Re: Does MPD support HLS streams?

Post by max »

lordpixel wrote:It is brain dead in its simplicity, but I guess that's the point.
Simplicity? It is much more complex than simple HTTP streaming, which goes through the same firewalls. (That is not my point of view - it's a provable fact.)

lordpixel
Posts: 6
Joined: April 7th, 2015, 3:40 am

Re: Does MPD support HLS streams?

Post by lordpixel »

I see what you mean for a podcast or a song.

It's not obvious to me though how you'd do a truly continuous live stream without some kind of framing protocol around HTTP.

But, again, thanks for the info.

max
Forum team
Posts: 1029
Joined: January 15th, 2013, 3:43 pm

Re: Does MPD support HLS streams?

Post by max »

lordpixel wrote:It's not obvious to me though how you'd do a truly continuous live stream without some kind of framing protocol around HTTP.
Then obviously you have no idea about audio streaming. The obvious (and trivial) way to do it is to just have a never-ending HTTP response body. Just like people have been doing it for more than two decades. This is so simple and trivial, it can't be any simpler. (Unless you want to drop HTTP, which would also be a good idea - but we're talking about HTTP-based protocols).

lordpixel
Posts: 6
Joined: April 7th, 2015, 3:40 am

Re: Does MPD support HLS streams?

Post by lordpixel »

You're quite right. I don't know much about audio streaming. But I know a little about mpeg video and I've build financial data streams that required mid-stream reconnection. So actually now I put my mind to it I guess you'd pick up the equivalent of an MPEG I-Frame and latch onto the ongoing stream like that.

I'm curious - in your opinion is there any point to HLS, Smooth Streaming and MPEG-DASH etc? The adaptive bitrate stuff, presumably?

max
Forum team
Posts: 1029
Joined: January 15th, 2013, 3:43 pm

Re: Does MPD support HLS streams?

Post by max »

HLS is completely pointless. Nobody has ever explained to me an advantage of HLS compared to plain HTTP, but there are unnecessary disadvantages. Therefore it must be pointless. I've never heard of the others you named.

DuffyMoon
Posts: 11
Joined: May 12th, 2015, 10:31 pm

Re: Does MPD support HLS streams?

Post by DuffyMoon »

lordpixel, if you can manage to program an HLS mpd client that would be great. I really hope it gets integrated into mpd at some point as there are nice, high bitrate BBC streams that I'd love to be able to play (I can only get the 128 Kbps mp3 stream working currently).

DuffyMoon
Posts: 11
Joined: May 12th, 2015, 10:31 pm

Re: Does MPD support HLS streams?

Post by DuffyMoon »

BTW, I found a workaround by installing Minimstreamer on my NAS and Bubble UPNP on my phone to control it. Works like a charm.

TimeZlicer
Posts: 2
Joined: January 3rd, 2016, 4:47 am

Re: Does MPD support HLS streams?

Post by TimeZlicer »

ffplay could play the steam, it implies that ffmpeg can decode it

Code: Select all

ffplay http://ic.8eff4641.0b657a.as-hls-ww-live.bbcfmt.vo.llnwi.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d96000.m3u8?dvr_window_length
Made the following changes and MPD can now play the HLS

Code: Select all

diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx
index 3ba7922..2abbe4c 100644
--- a/src/decoder/DecoderThread.cxx
+++ b/src/decoder/DecoderThread.cxx
@@ -236,7 +236,7 @@ decoder_run_stream_fallback(Decoder &decoder, InputStream &is)
 {
        const struct DecoderPlugin *plugin;
 
-       plugin = decoder_plugin_from_name("mad");
+       plugin = decoder_plugin_from_name("ffmpeg");
        return plugin != nullptr && plugin->stream_decode != nullptr &&
                decoder_stream_decode(*plugin, decoder, is);
 }

lordpixel
Posts: 6
Joined: April 7th, 2015, 3:40 am

Re: Does MPD support HLS streams?

Post by lordpixel »

Thanks TimeZlicer!

To be clear, that's a change you made in your local copy or something you committed to mpd permanently?

TimeZlicer
Posts: 2
Joined: January 3rd, 2016, 4:47 am

Re: Does MPD support HLS streams?

Post by TimeZlicer »

It is on my local copy, I am not sure if this would be approved, I can submit a request

Post Reply