From 7e825dc10f3fe12f4c5c4e2af8e69c26c071ccd0 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Tue, 11 Feb 2020 16:30:50 -0500 Subject: [PATCH] rework it, we cannot use sourceupdater --- src/videojs-http-streaming.js | 11 ++- test/videojs-http-streaming.test.js | 130 ++++++++++++++++++---------- 2 files changed, 93 insertions(+), 48 deletions(-) diff --git a/src/videojs-http-streaming.js b/src/videojs-http-streaming.js index 148cff5b5..2d5ec5e7d 100644 --- a/src/videojs-http-streaming.js +++ b/src/videojs-http-streaming.js @@ -145,12 +145,15 @@ Hls.canPlaySource = function() { 'your player\'s techOrder.'); }; -const emeKeySystems = (keySystemOptions, videoPlaylist, sourceUpdater) => { +const emeKeySystems = (keySystemOptions, videoPlaylist, audioPlaylist) => { if (!keySystemOptions) { return keySystemOptions; } - const codecs = Object.assign({}, sourceUpdater.codecs); + const codecs = { + video: videoPlaylist && videoPlaylist.attributes && videoPlaylist.attributes.CODECS, + audio: audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS + }; if (!codecs.audio && codecs.video.split(',').length > 1) { codecs.video.split(',').forEach(function(codec) { @@ -190,14 +193,14 @@ const emeKeySystems = (keySystemOptions, videoPlaylist, sourceUpdater) => { }; const setupEmeOptions = (hlsHandler) => { - const sourceUpdater = hlsHandler.masterPlaylistController_.sourceUpdater_; const player = hlsHandler.player_; if (player.eme) { + const audioPlaylistLoader = hlsHandler.masterPlaylistController_.mediaTypes_.AUDIO.activePlaylistLoader; const sourceOptions = emeKeySystems( hlsHandler.source_.keySystems, hlsHandler.playlists.media(), - sourceUpdater + audioPlaylistLoader && audioPlaylistLoader.media() ); if (sourceOptions) { diff --git a/test/videojs-http-streaming.test.js b/test/videojs-http-streaming.test.js index c79d4d48b..803b049e8 100644 --- a/test/videojs-http-streaming.test.js +++ b/test/videojs-http-streaming.test.js @@ -3732,13 +3732,11 @@ QUnit.test('configures eme for DASH if present on selectedinitialmedia', functio this.clock.tick(1); - this.player.tech_.hls.masterPlaylistController_.sourceUpdater_.codecs = { - audio: 'audio-codec', - video: 'video-codec' - }; - this.player.tech_.hls.playlists = { media: () => ({ + attributes: { + CODECS: 'avc1.420015' + }, contentProtection: { keySystem1: { pssh: 'test' @@ -3747,6 +3745,21 @@ QUnit.test('configures eme for DASH if present on selectedinitialmedia', functio }) }; + this.player.tech_.hls.masterPlaylistController_.mediaTypes_ = { + SUBTITLES: {}, + AUDIO: { + activePlaylistLoader: { + media: () => { + return { + attributes: { + CODECS: 'mp4a.40.2c' + } + }; + } + } + } + }; + this.player.tech_.hls.masterPlaylistController_.trigger('selectedinitialmedia'); assert.deepEqual(this.player.eme.options, { @@ -3759,8 +3772,8 @@ QUnit.test('configures eme for DASH if present on selectedinitialmedia', functio keySystems: { keySystem1: { url: 'url1', - audioContentType: 'audio/mp4;codecs="audio-codec"', - videoContentType: 'video/mp4;codecs="video-codec"', + audioContentType: 'audio/mp4;codecs="mp4a.40.2c"', + videoContentType: 'video/mp4;codecs="avc1.420015"', pssh: 'test' } } @@ -3774,8 +3787,8 @@ QUnit.test('configures eme for HLS if present on selectedinitialmedia', function } }; this.player.src({ - src: 'manifest/master.mpd', - type: 'application/dash+xml', + src: 'manifest/master.m3u8', + type: 'application/x-mpegURL', keySystems: { keySystem1: { url: 'url1' @@ -3785,12 +3798,11 @@ QUnit.test('configures eme for HLS if present on selectedinitialmedia', function this.clock.tick(1); - this.player.tech_.hls.masterPlaylistController_.sourceUpdater_.codecs = { - video: 'avc1.420015, mp4a.40.2c' - }; - this.player.tech_.hls.playlists = { media: () => ({ + attributes: { + CODECS: 'avc1.420015, mp4a.40.2c' + }, contentProtection: { keySystem1: { pssh: 'test' @@ -3806,8 +3818,8 @@ QUnit.test('configures eme for HLS if present on selectedinitialmedia', function }, 'did not modify plugin options'); assert.deepEqual(this.player.currentSource(), { - src: 'manifest/master.mpd', - type: 'application/dash+xml', + src: 'manifest/master.m3u8', + type: 'application/x-mpegURL', keySystems: { keySystem1: { url: 'url1', @@ -3819,7 +3831,7 @@ QUnit.test('configures eme for HLS if present on selectedinitialmedia', function }, 'set source eme options'); }); -QUnit.test('integration: configures eme if present on selectedinitialmedia', function(assert) { +QUnit.test('integration: configures eme for DASH if present on selectedinitialmedia', function(assert) { assert.timeout(3000); const done = assert.async(); @@ -3839,10 +3851,6 @@ QUnit.test('integration: configures eme if present on selectedinitialmedia', fun }); this.clock.tick(1); - this.player.tech_.hls.masterPlaylistController_.sourceUpdater_.codecs = { - video: 'avc1.420015, mp4a.40.2' - }; - this.player.tech_.hls.masterPlaylistController_.on('selectedinitialmedia', () => { assert.deepEqual(this.player.eme.options, { previousSetting: 1 @@ -3868,6 +3876,59 @@ QUnit.test('integration: configures eme if present on selectedinitialmedia', fun this.clock.tick(1); }); +QUnit.test('integration: configures eme for HLS if present on selectedinitialmedia', function(assert) { + assert.timeout(3000); + const done = assert.async(); + + this.player.eme = { + options: { + previousSetting: 1 + } + }; + this.player.src({ + src: 'demuxed.m3u8', + type: 'application/x-mpegURL', + keySystems: { + keySystem1: { + url: 'url1' + } + } + }); + this.clock.tick(1); + + this.player.tech_.hls.masterPlaylistController_.on('selectedinitialmedia', () => { + assert.deepEqual(this.player.eme.options, { + previousSetting: 1 + }, 'did not modify plugin options'); + + assert.deepEqual(this.player.currentSource(), { + src: 'demuxed.m3u8', + type: 'application/x-mpegURL', + keySystems: { + keySystem1: { + url: 'url1', + audioContentType: 'audio/mp4;codecs="mp4a.40.2"', + videoContentType: 'video/mp4;codecs="avc1.420015"' + } + } + }, 'set source eme options'); + + done(); + }); + + // master manifest + this.standardXHRResponse(this.requests.shift()); + + // video manifest + this.standardXHRResponse(this.requests.shift()); + + // audio manifest + this.standardXHRResponse(this.requests.shift()); + + // this allows the audio playlist loader to load + this.clock.tick(1); +}); + QUnit.test( 'does not set source keySystems if keySystems not provided by source', function(assert) { @@ -4845,15 +4906,10 @@ QUnit.module('videojs-contrib-hls isolated functions'); QUnit.test('emeKeySystems adds content types for all keySystems', function(assert) { // muxed content - const sourceUpdater = { - codecs: {video: 'avc1.420015, mp4a.40.2c'} - }; - assert.deepEqual( emeKeySystems( { keySystem1: {}, keySystem2: {} }, - {}, - sourceUpdater, + { attributes: { CODECS: 'avc1.420015, mp4a.40.2c' } }, ), { keySystem1: { @@ -4869,15 +4925,11 @@ QUnit.test('emeKeySystems adds content types for all keySystems', function(asser ); // unmuxed content - const sourceUpdater2 = { - codecs: {video: 'avc1.420015', audio: 'mp4a.40.2c'} - }; - assert.deepEqual( emeKeySystems( { keySystem1: {}, keySystem2: {} }, - {}, - sourceUpdater2 + { attributes: { CODECS: 'avc1.420015' } }, + { attributes: { CODECS: 'mp4a.40.2c' } }, ), { keySystem1: { @@ -4894,15 +4946,10 @@ QUnit.test('emeKeySystems adds content types for all keySystems', function(asser }); QUnit.test('emeKeySystems retains non content type properties', function(assert) { - const sourceUpdater = { - codecs: {video: 'avc1.420015, mp4a.40.2c'} - }; - assert.deepEqual( emeKeySystems( { keySystem1: { url: '1' }, keySystem2: { url: '2'} }, - {}, - sourceUpdater + { attributes: { CODECS: 'avc1.420015, mp4a.40.2c' } }, ), { keySystem1: { @@ -4921,10 +4968,6 @@ QUnit.test('emeKeySystems retains non content type properties', function(assert) }); QUnit.test('emeKeySystems overwrites content types', function(assert) { - const sourceUpdater = { - codecs: {video: 'avc1.420015, mp4a.40.2c'} - }; - assert.deepEqual( emeKeySystems( { @@ -4937,8 +4980,7 @@ QUnit.test('emeKeySystems overwrites content types', function(assert) { videoContentType: 'd' } }, - {}, - sourceUpdater + { attributes: { CODECS: 'avc1.420015, mp4a.40.2c' } }, ), { keySystem1: {