Skip to content

HLS byte range issue

When using HLS with byte ranges over multiple mp4 chunks, the byte range request is not reseted when moving to a new segment:

adaptive debug: Retrieving https://example.com:443/e2c4220c-3cf4-4499-ab3a-ea5e904d0406/358sc9mqoalko8ybc2jz8j43u/stream/52V8HB/main-pres/audio/default/default/665.hspc @730857-809578
http debug: outgoing request: GET /e2c4220c-3cf4-4499-ab3a-ea5e904d0406/358sc9mqoalko8ybc2jz8j43u/stream/52V8HB/main-pres/audio/default/default/665.hspc HTTP/1.1 Host: example.com:443 Accept: */* Accept-Language: en_US User-Agent: VLC/3.0.21 LibVLC/3.0.21 Accept-Encoding: deflate, gzip Cache-Control: no-cache Range: bytes=730857-809578 
adaptive debug: Retrieving https://example.com:443/e2c4220c-3cf4-4499-ab3a-ea5e904d0406/358sc9mqoalko8ybc2jz8j43u/stream/52V8HB/main-pres/audio/default/default/666.hspc @809579-890544
http debug: outgoing request: GET /e2c4220c-3cf4-4499-ab3a-ea5e904d0406/358sc9mqoalko8ybc2jz8j43u/stream/52V8HB/main-pres/audio/default/default/666.hspc HTTP/1.1 Host: example.com:443 Accept: */* Accept-Language: en_US User-Agent: VLC/3.0.21 LibVLC/3.0.21 Accept-Encoding: deflate, gzip Cache-Control: no-cache Range: bytes=809579-890544 

As you can see the initial offset of the new segment is the continuation of the previous one insteado of 0.

I think there is a typo at https://github.com/videolan/vlc/blob/166a07af151a732baa4b36e8a20fffe648b3444d/modules/demux/hls/playlist/Parser.cpp#L366

 std::pair<std::size_t,std::size_t> range = ctx_byterange->getValue().getByteRange();
 if(range.first == 0) /* first == size, second = offset */

As the getByteRange() returns a std::make_pair(offset, length);, so just reversting the range.first and range.second at the Parser should solve the issue.

Edited by Sergio Garcia Murillo
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information