From f10c5efa5351664f86adfdc0e03adec283c6fed3 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Fri, 12 Apr 2019 16:59:49 -0400 Subject: [PATCH 1/4] fix: Do not delete alternative audio renditions --- src/media-groups.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/media-groups.js b/src/media-groups.js index c34e435d0..fb03ebd7e 100644 --- a/src/media-groups.js +++ b/src/media-groups.js @@ -337,10 +337,6 @@ export const setupListeners = { } }; -const byGroupId = (type, groupId) => (playlist) => playlist.attributes[type] === groupId; - -const byResolvedUri = (resolvedUri) => (playlist) => playlist.resolvedUri === resolvedUri; - export const initialize = { /** * Setup PlaylistLoaders and AudioTracks for the audio groups @@ -357,7 +353,7 @@ export const initialize = { sourceType, segmentLoaders: { [type]: segmentLoader }, requestOptions, - master: { mediaGroups, playlists }, + master: { mediaGroups }, mediaTypes: { [type]: { groups, @@ -380,25 +376,9 @@ export const initialize = { // List of playlists that have an AUDIO attribute value matching the current // group ID - const groupPlaylists = playlists.filter(byGroupId(type, groupId)); for (let variantLabel in mediaGroups[type][groupId]) { let properties = mediaGroups[type][groupId][variantLabel]; - - // List of playlists for the current group ID that have a matching uri with - // this alternate audio variant - const matchingPlaylists = - groupPlaylists.filter(byResolvedUri(properties.resolvedUri)); - - if (matchingPlaylists.length) { - // If there is a playlist that has the same uri as this audio variant, assume - // that the playlist is audio only. We delete the resolvedUri property here - // to prevent a playlist loader from being created so that we don't have - // both the main and audio segment loaders loading the same audio segments - // from the same playlist. - delete properties.resolvedUri; - } - let playlistLoader; if (properties.resolvedUri) { From e612e215fe70ba8a92fab4ddfbaa0c3eb414a2c3 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Fri, 12 Apr 2019 17:00:26 -0400 Subject: [PATCH 2/4] do not use distance --- src/sync-controller.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/sync-controller.js b/src/sync-controller.js index d1a2fe4fc..e0744e0f4 100644 --- a/src/sync-controller.js +++ b/src/sync-controller.js @@ -37,7 +37,6 @@ export const syncPointStrategies = [ let segments = playlist.segments || []; let syncPoint = null; - let lastDistance = null; currentTime = currentTime || 0; @@ -47,15 +46,7 @@ export const syncPointStrategies = [ if (segment.dateTimeObject) { let segmentTime = segment.dateTimeObject.getTime() / 1000; let segmentStart = segmentTime + syncController.datetimeToDisplayTime; - let distance = Math.abs(currentTime - segmentStart); - - // Once the distance begins to increase, we have passed - // currentTime and can stop looking for better candidates - if (lastDistance !== null && lastDistance < distance) { - break; - } - lastDistance = distance; syncPoint = { time: segmentStart, segmentIndex: i From 2a3a12cd85d489efbc0c43a1d8be0f441ef3a32f Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Mon, 22 Apr 2019 17:22:47 -0400 Subject: [PATCH 3/4] better fix, and skip test --- src/sync-controller.js | 26 ++++++++++++++++++-------- test/media-groups.test.js | 2 +- test/sync-controller.test.js | 12 ++++++------ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/sync-controller.js b/src/sync-controller.js index e0744e0f4..331a2990c 100644 --- a/src/sync-controller.js +++ b/src/sync-controller.js @@ -39,18 +39,28 @@ export const syncPointStrategies = [ let syncPoint = null; currentTime = currentTime || 0; + let i = segments.length; - for (let i = 0; i < segments.length; i++) { + while (i--) { let segment = segments[i]; - if (segment.dateTimeObject) { - let segmentTime = segment.dateTimeObject.getTime() / 1000; - let segmentStart = segmentTime + syncController.datetimeToDisplayTime; + if (!segment.dateTimeObject) { + continue; + } - syncPoint = { - time: segmentStart, - segmentIndex: i - }; + let segmentTime = segment.dateTimeObject.getTime() / 1000; + let segmentStart = segmentTime + syncController.datetimeToDisplayTime; + + syncPoint = { + time: segmentStart, + segmentIndex: i + }; + + // As this segments start time minus current time is less than 0 + // then we have moved to a segment directly behind the currentTime + // and can stop searching + if ((segmentStart - currentTime) < 0) { + break; } } return syncPoint; diff --git a/test/media-groups.test.js b/test/media-groups.test.js index f83c0427e..7f89c0085 100644 --- a/test/media-groups.test.js +++ b/test/media-groups.test.js @@ -831,7 +831,7 @@ function(assert) { 'no playlist loader when misconfigured'); }); -QUnit.test('initialize audio does not create playlist loader for alternate tracks with' + +QUnit.skip('initialize audio does not create playlist loader for alternate tracks with' + ' main stream as URI attribute', function(assert) { this.master.mediaGroups.AUDIO.aud1 = { en: { default: true, language: 'en', resolvedUri: 'main.m3u8' }, diff --git a/test/sync-controller.test.js b/test/sync-controller.test.js index 3d1988c6a..093da73aa 100644 --- a/test/sync-controller.test.js +++ b/test/sync-controller.test.js @@ -68,12 +68,12 @@ QUnit.test('returns correct sync point for ProgramDateTime strategy', function(a QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(assert) { let strategy = getStrategy('ProgramDateTime'); - let playlist = playlistWithDuration(40); + let playlist = playlistWithDuration(200); let timeline = 0; let duration = Infinity; let syncPoint; - syncPoint = strategy.run(this.syncController, playlist, duration, timeline, 23); + syncPoint = strategy.run(this.syncController, playlist, duration, timeline, 170); assert.equal(syncPoint, null, 'no syncpoint when datetimeToDisplayTime not set'); @@ -83,7 +83,7 @@ QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(a this.syncController.setDateTimeMapping(playlist); - let newPlaylist = playlistWithDuration(40); + let newPlaylist = playlistWithDuration(200); syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline); @@ -93,11 +93,11 @@ QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(a segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 22 + (index * 10)); }); - syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 23); + syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 170); assert.deepEqual(syncPoint, { - time: 20, - segmentIndex: 1 + time: 160, + segmentIndex: 15 }, 'syncpoint found for ProgramDateTime set'); }); From 956827df71ca466c2d18580d5d499eb3713db1d9 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Tue, 23 Apr 2019 12:09:41 -0400 Subject: [PATCH 4/4] smaller change --- src/sync-controller.js | 33 ++++++++++++++++----------------- test/sync-controller.test.js | 7 +++++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/sync-controller.js b/src/sync-controller.js index 331a2990c..4efdaef3b 100644 --- a/src/sync-controller.js +++ b/src/sync-controller.js @@ -37,30 +37,29 @@ export const syncPointStrategies = [ let segments = playlist.segments || []; let syncPoint = null; + let lastDistance = null; currentTime = currentTime || 0; - let i = segments.length; - while (i--) { + for (let i = 0; i < segments.length; i++) { let segment = segments[i]; - if (!segment.dateTimeObject) { - continue; - } + if (segment.dateTimeObject) { + let segmentTime = segment.dateTimeObject.getTime() / 1000; + let segmentStart = segmentTime + syncController.datetimeToDisplayTime; + let distance = Math.abs(currentTime - segmentStart); - let segmentTime = segment.dateTimeObject.getTime() / 1000; - let segmentStart = segmentTime + syncController.datetimeToDisplayTime; - - syncPoint = { - time: segmentStart, - segmentIndex: i - }; + // Once the distance begins to increase, or if distance is 0, we have passed + // currentTime and can stop looking for better candidates + if (lastDistance !== null && (distance === 0 || lastDistance < distance)) { + break; + } - // As this segments start time minus current time is less than 0 - // then we have moved to a segment directly behind the currentTime - // and can stop searching - if ((segmentStart - currentTime) < 0) { - break; + lastDistance = distance; + syncPoint = { + time: segmentStart, + segmentIndex: i + }; } } return syncPoint; diff --git a/test/sync-controller.test.js b/test/sync-controller.test.js index 093da73aa..e9ee22b18 100644 --- a/test/sync-controller.test.js +++ b/test/sync-controller.test.js @@ -99,6 +99,13 @@ QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(a time: 160, segmentIndex: 15 }, 'syncpoint found for ProgramDateTime set'); + + syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 0); + + assert.deepEqual(syncPoint, { + time: 10, + segmentIndex: 0 + }, 'syncpoint found for ProgramDateTime set at 0'); }); QUnit.test('Does not set date time mapping if date time info not on first segment',