Skip to content

fix range for bogus mp4 streams#655

Merged
mherger merged 1 commit intoLMS-Community:public/8.3from
philippe44:8.2.1-misc
Sep 3, 2021
Merged

fix range for bogus mp4 streams#655
mherger merged 1 commit intoLMS-Community:public/8.3from
philippe44:8.2.1-misc

Conversation

@philippe44
Copy link
Contributor

According to this discussion https://forums.slimdevices.com/showthread.php?115070-Global-Player-Remote-M4A-(containing-AAC)-streams-no-longer-working-in-LMS, some site might have bogus mp4 header or HTTP content-length which cause stream GET using a range request to fail. This PR forces audio_size to make sure audio_offset+size do not overshoot content_range

According to this discussion https://forums.slimdevices.com/showthread.php?115070-Global-Player-Remote-M4A-(containing-AAC)-streams-no-longer-working-in-LMS, some site migth have bogus mp4 header or content-length HTTP which causes stream GET using a range requets to fail. This PR forces audio_size to make sure audio_offset+size do not overshoot content_range
Comment on lines +892 to +897
if ($info->{audio_offset} + $info->{audio_size} > $http->response->content_length) {
$log->warn("inconsistent audio offset/size $info->{audio_offset}+$info->{audio_size}and content_length ", $http->response->content_length);
$track->audio_size($http->response->content_length - $info->{audio_offset});
} else {
$track->audio_size($info->{audio_size});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help my limited understanding: when doing a range get, wouldn't the content length always be shorter than offset plus size? Basically: is the content length reporting the chunk size, or the full file's size?

Ok, but this change is about them being larger, so this shouldn't even matter.

Copy link
Contributor Author

@philippe44 philippe44 Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content_length is always the full size, never the chunk size. In fact when you use chunked mode, the content_length must not be indicated.

When scanning a stream, I'm memorizing the audio_offset and audio_size and then during actual streaming I'm making a range request starting at the offset and up to offset+size-1 which must be less than content_length. I have to do a range request with a precise last byte because some files have crap at the end and I just want the audio.

The issue he is that this server sends a mp4 with (eg) 100b of header (offset) 1kB of audio_size, so I make a request of 100-(1100-1). The file should be at least 1100 bytes long but in fact the content_length of the http response is 1020 bytes, so my range request fails. It looks like an incorrect encoding or (much less likely) an HTTP error when content_length is set

@mherger
Copy link
Contributor

mherger commented Sep 3, 2021

Let's give this a try - thanks!

@mherger mherger merged commit 739f2cc into LMS-Community:public/8.3 Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants