Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Fix invalid target duration error on float values #4464

wants to merge 2 commits into from

Conversation

widgetii
Copy link

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.0

Sample playlist:

#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:0.500089
#EXT-X-MAP:URI="init.mp4"
#EXT-X-MEDIA-SEQUENCE:1639765123
#EXTINF:0.500089,
video1639765123.m4s
#EXTINF:0.500089,
video1639765124.m4s
#EXTINF:0.500089,
video1639765125.m4s

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

Copy link
Collaborator

@robwalch robwalch left a 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

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the Stale label Apr 16, 2022
@stale
Copy link

stale bot commented Apr 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants