-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7a775a
commit be7a3ff
Showing
2 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import QUnit from 'qunit'; | ||
import { MediaSequenceSync } from '../../src/util/media-sequence-sync'; | ||
|
||
QUnit.module('MediaSequenceSync: update', function(hooks) { | ||
let mediaSequenceSync; | ||
|
||
hooks.beforeEach(function() { | ||
mediaSequenceSync = new MediaSequenceSync(); | ||
}); | ||
|
||
QUnit.test('update calculates correct base time based on mediaSequence of new playlist', function(assert) { | ||
const initialMediaSequence = 10; | ||
const initialSegments = [ | ||
// Segment 10 with duration 5 | ||
{ duration: 5 }, | ||
// Segment 11 with duration 6 | ||
{ duration: 6 }, | ||
// Segment 12 with duration 7 | ||
{ duration: 7 } | ||
]; | ||
|
||
// Initial update with starting playlist | ||
mediaSequenceSync.update( | ||
{ | ||
mediaSequence: initialMediaSequence, | ||
segments: initialSegments | ||
}, | ||
// Current time, value is used for fallback and not significant here | ||
20 | ||
); | ||
|
||
// Confirm that the initial update set the correct start and end times | ||
assert.strictEqual( | ||
mediaSequenceSync.start, | ||
0, | ||
'The start time is set to the initial value of 0.' | ||
); | ||
|
||
// Confirm the end time is the correct sum of the segment durations | ||
// = 18 | ||
const expectedInitialEndTime = 0 + 5 + 6 + 7; | ||
|
||
assert.strictEqual( | ||
mediaSequenceSync.end, | ||
expectedInitialEndTime, | ||
'The end time is calculated correctly after the initial update.' | ||
); | ||
|
||
// New playlist with higher mediaSequence | ||
let newMediaSequence = 11; | ||
let newSegments = [ | ||
// Segment 11 with duration 4 | ||
{ duration: 4 }, | ||
// Segment 12 with duration 5 | ||
{ duration: 5 }, | ||
// Segment 13 with duration 6 | ||
{ duration: 6 } | ||
]; | ||
|
||
// Update with the new playlist | ||
mediaSequenceSync.update( | ||
{ | ||
mediaSequence: newMediaSequence, | ||
segments: newSegments | ||
}, | ||
30 | ||
); | ||
|
||
// Segment 10 with duration 5 has fallen off the start of the playlist | ||
let expectedStartTime = 5; | ||
|
||
assert.strictEqual( | ||
mediaSequenceSync.start, | ||
expectedStartTime, | ||
'The base time is calculated correctly when a new playlist with a higher mediaSequence is loaded.' | ||
); | ||
|
||
// New playlist with lower mediaSequence | ||
newMediaSequence = 10; | ||
newSegments = [ | ||
// Segment 10 with duration 5 | ||
{ duration: 5 }, | ||
// Segment 11 with duration 6 | ||
{ duration: 6 }, | ||
// Segment 12 with duration 7 | ||
{ duration: 7 } | ||
]; | ||
|
||
// Update with the new playlist | ||
mediaSequenceSync.update( | ||
{ | ||
mediaSequence: newMediaSequence, | ||
segments: newSegments | ||
}, | ||
40 | ||
); | ||
|
||
// Expected base time is calculated by extrapolating backwards: | ||
// Segment 11 start time: 5 | ||
// Segment 10 start time: Segment 11 start time (5) - Segment 10 duration (5) = 0 | ||
expectedStartTime = 0; | ||
|
||
assert.strictEqual( | ||
mediaSequenceSync.start, | ||
expectedStartTime, | ||
'The base time is calculated correctly when a new playlist with a lower mediaSequence is loaded.' | ||
); | ||
}); | ||
}); |