Skip to content

Commit fe25a04

Browse files
chore: update m3u8-parser version and fix tests (#1407)
1 parent a21182d commit fe25a04

File tree

9 files changed

+135
-104
lines changed

9 files changed

+135
-104
lines changed

package-lock.json

Lines changed: 47 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@videojs/vhs-utils": "4.0.0",
6262
"aes-decrypter": "4.0.1",
6363
"global": "^4.4.0",
64-
"m3u8-parser": "^6.2.0",
64+
"m3u8-parser": "^7.0.0",
6565
"mpd-parser": "^1.1.1",
6666
"mux.js": "6.3.0",
6767
"video.js": "^7 || ^8"

src/segment-loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,8 +3180,7 @@ export default class SegmentLoader extends videojs.EventTarget {
31803180
const Cue = window.WebKitDataCue || window.VTTCue;
31813181
const value = {
31823182
custom: segment.custom,
3183-
dateTimeObject: segment.dateTimeObject,
3184-
dateTimeString: segment.dateTimeString,
3183+
programDateTime: segment.programDateTime,
31853184
bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
31863185
resolution: segmentInfo.playlist.attributes.RESOLUTION,
31873186
codecs: segmentInfo.playlist.attributes.CODECS,

src/sync-controller.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ export const syncPointStrategies = [
5353
const datetimeMapping =
5454
syncController.timelineToDatetimeMappings[segment.timeline];
5555

56-
if (!datetimeMapping || !segment.dateTimeObject) {
56+
if (!datetimeMapping || !segment.programDateTime) {
5757
continue;
5858
}
5959

60-
const segmentTime = segment.dateTimeObject.getTime() / 1000;
60+
const segmentTime = segment.programDateTime / 1000;
6161
let start = segmentTime + datetimeMapping;
6262

6363
// take part duration into account.
@@ -408,9 +408,9 @@ export default class SyncController extends videojs.EventTarget {
408408

409409
if (playlist.segments &&
410410
playlist.segments.length &&
411-
playlist.segments[0].dateTimeObject) {
411+
playlist.segments[0].programDateTime) {
412412
const firstSegment = playlist.segments[0];
413-
const playlistTimestamp = firstSegment.dateTimeObject.getTime() / 1000;
413+
const playlistTimestamp = firstSegment.programDateTime / 1000;
414414

415415
this.timelineToDatetimeMappings[firstSegment.timeline] = -playlistTimestamp;
416416
}
@@ -449,10 +449,10 @@ export default class SyncController extends videojs.EventTarget {
449449
}
450450
}
451451

452-
const dateTime = segment.dateTimeObject;
452+
const dateTime = segment.programDateTime;
453453

454454
if (segment.discontinuity && shouldSaveTimelineMapping && dateTime) {
455-
this.timelineToDatetimeMappings[segment.timeline] = -(dateTime.getTime() / 1000);
455+
this.timelineToDatetimeMappings[segment.timeline] = -(dateTime / 1000);
456456
}
457457
}
458458

src/util/time.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const SEGMENT_END_FUDGE_PERCENT = 0.25;
2626
* @return {Date} program time
2727
*/
2828
export const playerTimeToProgramTime = (playerTime, segment) => {
29-
if (!segment.dateTimeObject) {
29+
if (!segment.programDateTime) {
3030
// Can't convert without an "anchor point" for the program time (i.e., a time that can
3131
// be used to map the start of a segment with a real world time).
3232
return null;
@@ -39,7 +39,7 @@ export const playerTimeToProgramTime = (playerTime, segment) => {
3939
const startOfSegment = transmuxedStart + transmuxerPrependedSeconds;
4040
const offsetFromSegmentStart = playerTime - startOfSegment;
4141

42-
return new Date(segment.dateTimeObject.getTime() + offsetFromSegmentStart * 1000);
42+
return new Date(segment.programDateTime + offsetFromSegmentStart * 1000);
4343
};
4444

4545
export const originalSegmentVideoDuration = (videoTimingInfo) => {
@@ -74,28 +74,28 @@ export const findSegmentForProgramTime = (programTime, playlist) => {
7474

7575
let segment = playlist.segments[0];
7676

77-
if (dateTimeObject < segment.dateTimeObject) {
77+
if (dateTimeObject < segment.programDateTime) {
7878
// Requested time is before stream start.
7979
return null;
8080
}
8181

8282
for (let i = 0; i < playlist.segments.length - 1; i++) {
8383
segment = playlist.segments[i];
8484

85-
const nextSegmentStart = playlist.segments[i + 1].dateTimeObject;
85+
const nextSegmentStart = playlist.segments[i + 1].programDateTime;
8686

8787
if (dateTimeObject < nextSegmentStart) {
8888
break;
8989
}
9090
}
9191

9292
const lastSegment = playlist.segments[playlist.segments.length - 1];
93-
const lastSegmentStart = lastSegment.dateTimeObject;
93+
const lastSegmentStart = lastSegment.programDateTime;
9494
const lastSegmentDuration = lastSegment.videoTimingInfo ?
9595
originalSegmentVideoDuration(lastSegment.videoTimingInfo) :
9696
lastSegment.duration + lastSegment.duration * SEGMENT_END_FUDGE_PERCENT;
9797
const lastSegmentEnd =
98-
new Date(lastSegmentStart.getTime() + lastSegmentDuration * 1000);
98+
new Date(lastSegmentStart + lastSegmentDuration * 1000);
9999

100100
if (dateTimeObject > lastSegmentEnd) {
101101
// Beyond the end of the stream, or our best guess of the end of the stream.
@@ -230,7 +230,7 @@ export const verifyProgramDateTimeTags = (playlist) => {
230230
for (let i = 0; i < playlist.segments.length; i++) {
231231
const segment = playlist.segments[i];
232232

233-
if (!segment.dateTimeObject) {
233+
if (!segment.programDateTime) {
234234
return false;
235235
}
236236
}
@@ -355,7 +355,7 @@ export const seekToProgramTime = ({
355355

356356
const segment = matchedSegment.segment;
357357
const mediaOffset = getOffsetFromTimestamp(
358-
segment.dateTimeObject,
358+
segment.programDateTime,
359359
programTime
360360
);
361361

test/playlist-loader.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ QUnit.module('Playlist Loader', function(hooks) {
10521052
const segment = loader.main.playlists[0].segments[0];
10531053

10541054
assert.strictEqual(segment.custom.test, '#PARSER:parsed', 'parsed custom tag');
1055-
assert.ok(segment.dateTimeObject, 'converted and parsed custom time');
1055+
assert.ok(segment.programDateTime, 'converted and parsed custom time');
10561056

10571057
delete this.fakeVhs.options_;
10581058
});

test/segment-loader.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4560,26 +4560,26 @@ QUnit.module('SegmentLoader', function(hooks) {
45604560

45614561
const segmentDurationMs = targetDuration * 1000;
45624562

4563-
const playlist1Start = new Date('2021-01-01T00:00:00.000-05:00');
4563+
const playlist1Start = new Date('2021-01-01T00:00:00.000-05:00').getTime();
45644564

4565-
playlist1.segments[0].dateTimeObject = playlist1Start;
4566-
playlist1.segments[1].dateTimeObject = new Date(playlist1Start.getTime() + segmentDurationMs);
4565+
playlist1.segments[0].programDateTime = playlist1Start;
4566+
playlist1.segments[1].programDateTime = new Date(playlist1Start + segmentDurationMs).getTime();
45674567
// jump of 0.5 seconds after disco (0.5 seconds of missing real world time, e.g.,
45684568
// an encoder went down briefly), should have a PDT mapping difference of -3.5
45694569
// seconds from first mapping
4570-
playlist1.segments[2].dateTimeObject = new Date(playlist1.segments[1].dateTimeObject.getTime() + segmentDurationMs + 500);
4571-
playlist1.segments[3].dateTimeObject = new Date(playlist1.segments[2].dateTimeObject.getTime() + segmentDurationMs);
4570+
playlist1.segments[2].programDateTime = new Date(playlist1.segments[1].programDateTime + segmentDurationMs + 500).getTime();
4571+
playlist1.segments[3].programDateTime = new Date(playlist1.segments[2].programDateTime + segmentDurationMs).getTime();
45724572

45734573
// offset by 0.25 seconds from playlist1
45744574
const playlist2Start = new Date('2021-01-01T00:00:00.250-05:00');
45754575

4576-
playlist2.segments[0].dateTimeObject = playlist2Start;
4577-
playlist2.segments[1].dateTimeObject = new Date(playlist2Start.getTime() + segmentDurationMs);
4576+
playlist2.segments[0].programDateTime = playlist2Start.getTime();
4577+
playlist2.segments[1].programDateTime = new Date(playlist2Start + segmentDurationMs).getTime();
45784578
// jump of 0.5 seconds after disco (0.5 seconds of missing real world time, e.g.,
45794579
// an encoder went down briefly), should have a PDT mapping difference of -3.5
45804580
// seconds from first mapping
4581-
playlist2.segments[2].dateTimeObject = new Date(playlist2.segments[1].dateTimeObject.getTime() + segmentDurationMs + 500);
4582-
playlist2.segments[3].dateTimeObject = new Date(playlist2.segments[2].dateTimeObject.getTime() + segmentDurationMs);
4581+
playlist2.segments[2].programDateTime = new Date(playlist2.segments[1].programDateTime + segmentDurationMs + 500).getTime();
4582+
playlist2.segments[3].programDateTime = new Date(playlist2.segments[2].programDateTime + segmentDurationMs).getTime();
45834583

45844584
const {
45854585
mediaSource_: mediaSource,
@@ -4680,11 +4680,11 @@ QUnit.module('SegmentLoader', function(hooks) {
46804680
const segment3Start = new Date(segment2Start.getTime() + segmentDurationMs + 500);
46814681

46824682
[playlist1, playlist2].forEach((playlist) => {
4683-
playlist.dateTimeObject = segment0Start;
4684-
playlist.segments[0].dateTimeObject = segment0Start;
4685-
playlist.segments[1].dateTimeObject = segment1Start;
4686-
playlist.segments[2].dateTimeObject = segment2Start;
4687-
playlist.segments[3].dateTimeObject = segment3Start;
4683+
playlist.programDateTime = segment0Start;
4684+
playlist.segments[0].programDateTime = segment0Start;
4685+
playlist.segments[1].programDateTime = segment1Start;
4686+
playlist.segments[2].programDateTime = segment2Start;
4687+
playlist.segments[3].programDateTime = segment3Start;
46884688
});
46894689

46904690
const {

test/sync-controller.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ QUnit.test('returns correct sync point for ProgramDateTime strategy', function(a
4545

4646
assert.equal(syncPoint, null, 'no syncpoint when no date time to display time mapping');
4747

48-
playlist.segments[0].dateTimeObject = datetime;
48+
playlist.segments[0].programDateTime = datetime.getTime();
4949

5050
this.syncController.setDateTimeMappingForStart(playlist);
5151

@@ -55,7 +55,7 @@ QUnit.test('returns correct sync point for ProgramDateTime strategy', function(a
5555

5656
assert.equal(syncPoint, null, 'no syncpoint when datetimeObject not set on playlist');
5757

58-
newPlaylist.segments[0].dateTimeObject = new Date(2012, 11, 12, 12, 12, 22);
58+
newPlaylist.segments[0].programDateTime = new Date(2012, 11, 12, 12, 12, 22).getTime();
5959

6060
syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline);
6161

@@ -78,7 +78,7 @@ QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(a
7878
assert.equal(syncPoint, null, 'no syncpoint when no date time to display time mapping');
7979

8080
playlist.segments.forEach((segment, index) => {
81-
segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 12 + (index * 10));
81+
segment.programDateTime = new Date(2012, 11, 12, 12, 12, 12 + (index * 10)).getTime();
8282
});
8383

8484
this.syncController.setDateTimeMappingForStart(playlist);
@@ -90,7 +90,7 @@ QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(a
9090
assert.equal(syncPoint, null, 'no syncpoint when datetimeObject not set on playlist');
9191

9292
newPlaylist.segments.forEach((segment, index) => {
93-
segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 22 + (index * 10));
93+
segment.programDateTime = new Date(2012, 11, 12, 12, 12, 22 + (index * 10)).getTime();
9494
});
9595

9696
syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 170);
@@ -115,7 +115,7 @@ QUnit.test(
115115
function(assert) {
116116
const playlist = playlistWithDuration(40);
117117

118-
playlist.segments[1].dateTimeObject = new Date(2012, 11, 12, 12, 12, 12);
118+
playlist.segments[1].programDateTime = new Date(2012, 11, 12, 12, 12, 12).getTime();
119119

120120
this.syncController.setDateTimeMappingForStart(playlist);
121121

@@ -125,7 +125,7 @@ QUnit.test(
125125
'did not set datetime mapping'
126126
);
127127

128-
playlist.segments[0].dateTimeObject = new Date(2012, 11, 12, 12, 12, 2);
128+
playlist.segments[0].programDateTime = new Date(2012, 11, 12, 12, 12, 2).getTime();
129129

130130
this.syncController.setDateTimeMappingForStart(playlist);
131131

@@ -140,12 +140,12 @@ QUnit.test(
140140
QUnit.test('uses separate date time to display time mapping for each timeline', function(assert) {
141141
const playlist = playlistWithDuration(40, { discontinuityStarts: [1, 3] });
142142

143-
playlist.segments[0].dateTimeObject = new Date(2020, 1, 1, 1, 1, 1);
143+
playlist.segments[0].programDateTime = new Date(2020, 1, 1, 1, 1, 1).getTime();
144144
// 20 seconds later (10 more than default)
145-
playlist.segments[1].dateTimeObject = new Date(2020, 1, 1, 1, 1, 21);
146-
playlist.segments[2].dateTimeObject = new Date(2020, 1, 1, 1, 1, 31);
145+
playlist.segments[1].programDateTime = new Date(2020, 1, 1, 1, 1, 21).getTime();
146+
playlist.segments[2].programDateTime = new Date(2020, 1, 1, 1, 1, 31).getTime();
147147
// 30 seconds later (20 more than default)
148-
playlist.segments[3].dateTimeObject = new Date(2020, 1, 1, 1, 2, 1);
148+
playlist.segments[3].programDateTime = new Date(2020, 1, 1, 1, 2, 1).getTime();
149149

150150
// after this call, the initial playlist mapping will be provided
151151
this.syncController.setDateTimeMappingForStart(playlist);
@@ -165,7 +165,7 @@ QUnit.test('uses separate date time to display time mapping for each timeline',
165165
assert.deepEqual(
166166
this.syncController.timelineToDatetimeMappings,
167167
{
168-
0: -(playlist.segments[0].dateTimeObject.getTime() / 1000)
168+
0: -(playlist.segments[0].programDateTime / 1000)
169169
},
170170
'has correct mapping for timeline 0'
171171
);
@@ -183,8 +183,8 @@ QUnit.test('uses separate date time to display time mapping for each timeline',
183183
assert.deepEqual(
184184
this.syncController.timelineToDatetimeMappings,
185185
{
186-
0: -(playlist.segments[0].dateTimeObject.getTime() / 1000),
187-
1: -(playlist.segments[1].dateTimeObject.getTime() / 1000)
186+
0: -(playlist.segments[0].programDateTime / 1000),
187+
1: -(playlist.segments[1].programDateTime / 1000)
188188
},
189189
'has correct mapping for timelines 0 and 1'
190190
);
@@ -202,8 +202,8 @@ QUnit.test('uses separate date time to display time mapping for each timeline',
202202
assert.deepEqual(
203203
this.syncController.timelineToDatetimeMappings,
204204
{
205-
0: -(playlist.segments[0].dateTimeObject.getTime() / 1000),
206-
1: -(playlist.segments[1].dateTimeObject.getTime() / 1000)
205+
0: -(playlist.segments[0].programDateTime / 1000),
206+
1: -(playlist.segments[1].programDateTime / 1000)
207207
},
208208
'does not add a new timeline mapping when no disco'
209209
);
@@ -221,9 +221,9 @@ QUnit.test('uses separate date time to display time mapping for each timeline',
221221
assert.deepEqual(
222222
this.syncController.timelineToDatetimeMappings,
223223
{
224-
0: -(playlist.segments[0].dateTimeObject.getTime() / 1000),
225-
1: -(playlist.segments[1].dateTimeObject.getTime() / 1000),
226-
2: -(playlist.segments[3].dateTimeObject.getTime() / 1000)
224+
0: -(playlist.segments[0].programDateTime / 1000),
225+
1: -(playlist.segments[1].programDateTime / 1000),
226+
2: -(playlist.segments[3].programDateTime / 1000)
227227
},
228228
'has correct mappings for timelines 0, 1, and 2'
229229
);
@@ -241,7 +241,7 @@ QUnit.test('ProgramDateTime strategy finds nearest llhls sync point', function(a
241241
assert.equal(syncPoint, null, 'no syncpoint when no date time to display time mapping');
242242

243243
playlist.segments.forEach((segment, index) => {
244-
segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 12 + (index * 10));
244+
segment.programDateTime = new Date(2012, 11, 12, 12, 12, 12 + (index * 10)).getTime();
245245
});
246246

247247
this.syncController.setDateTimeMappingForStart(playlist);

0 commit comments

Comments
 (0)