-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid target duration error on float values #4464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a Contribution
TARGETDURATION is defined in the HLS spec as a decimal-integer: https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.1
As such, the parsing regex should not be modified. However, we can define a minimum value of 1 to prevent the error you encountered. If your live stream requires sub-second manifest requests, you should adopt Low-Latency HLS. LL-HLS partial segments have decimal-floating-point PART-TARGET durations.
From 34a55a9346a4a07fbed7a8960c355d30a54b524a Mon Sep 17 00:00:00 2001
From: Rob Walch <rwalch@apple.com>
Date: Tue, 11 Jan 2022 16:38:42 -0800
Subject: [PATCH] Treat TARGETDURATION as a decimal-integer assigned a minimum
value of 1 #4464
---
src/loader/m3u8-parser.ts | 2 +-
tests/unit/loader/playlist-loader.js | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/loader/m3u8-parser.ts b/src/loader/m3u8-parser.ts
index 00950812..ddb9a4a5 100644
--- a/src/loader/m3u8-parser.ts
+++ b/src/loader/m3u8-parser.ts
@@ -322,7 +322,7 @@ export default class M3U8Parser {
break;
}
case 'TARGETDURATION':
- level.targetduration = parseFloat(value1);
+ level.targetduration = Math.max(parseInt(value1), 1);
break;
case 'VERSION':
level.version = parseInt(value1);
diff --git a/tests/unit/loader/playlist-loader.js b/tests/unit/loader/playlist-loader.js
index fcf102c1..7855cb55 100644
--- a/tests/unit/loader/playlist-loader.js
+++ b/tests/unit/loader/playlist-loader.js
@@ -300,6 +300,32 @@ http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/video/107/
expect(result.totalduration).to.equal(0);
});
+ it('TARGETDURATION is a decimal-integer', function () {
+ const level = `#EXTM3U
+#EXT-X-VERSION:3
+#EXT-X-PLAYLIST-TYPE:VOD
+#EXT-X-TARGETDURATION:2.5`;
+ const result = M3U8Parser.parseLevelPlaylist(
+ level,
+ 'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/video/107/282/158282701_mp4_h264_aac_hq.m3u8#cell=core',
+ 0
+ );
+ expect(result.targetduration).to.equal(2);
+ });
+
+ it('TARGETDURATION is a decimal-integer which HLS.js assigns a minimum value of 1', function () {
+ const level = `#EXTM3U
+#EXT-X-VERSION:3
+#EXT-X-PLAYLIST-TYPE:VOD
+#EXT-X-TARGETDURATION:0.5`;
+ const result = M3U8Parser.parseLevelPlaylist(
+ level,
+ 'http://proxy-62.dailymotion.com/sec(3ae40f708f79ca9471f52b86da76a3a8)/video/107/282/158282701_mp4_h264_aac_hq.m3u8#cell=core',
+ 0
+ );
+ expect(result.targetduration).to.equal(1);
+ });
+
it('parse level with several fragments', function () {
const level = `#EXTM3U
#EXT-X-VERSION:3
--
2.31.0
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This issue has been automatically closed because it has not had recent activity. If this issue is still valid, please ping a maintainer and ask them to label it accordingly. |
This PR will...
This fixes
Error while parsing manifest:invalid target duration
error when loaded playlist contains floating values. It turns out that current regexp treats TARGETDURATION numbers as integer and so doesn't work with values below 1.0Sample playlist:
Checklist