Skip to content

Commit

Permalink
rework it, we cannot use sourceupdater
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Feb 11, 2020
1 parent f5410b7 commit 7e825dc
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 48 deletions.
11 changes: 7 additions & 4 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
130 changes: 86 additions & 44 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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, {
Expand All @@ -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'
}
}
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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',
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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(
{
Expand All @@ -4937,8 +4980,7 @@ QUnit.test('emeKeySystems overwrites content types', function(assert) {
videoContentType: 'd'
}
},
{},
sourceUpdater
{ attributes: { CODECS: 'avc1.420015, mp4a.40.2c' } },
),
{
keySystem1: {
Expand Down

0 comments on commit 7e825dc

Please sign in to comment.