From 8cd67c1cbb5ff2ce73d617a2dfe5a380ce8221d9 Mon Sep 17 00:00:00 2001 From: bhh1988 Date: Thu, 10 Aug 2017 16:07:23 -0700 Subject: [PATCH] Fix: Forcing HD/SD should disable adaptation (#292) Shaka-player changed its behavior when selecting a variant. We now have to explicitly disable adaptation. See notes below (which also apply to upgrade from 2.0 to 2.1): https://github.com/google/shaka-player/blob/master/docs/tutorials/upgrade-v2-0.md --- src/lib/viewers/media/DashViewer.js | 8 +++++--- src/lib/viewers/media/__tests__/DashViewer-test.js | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/viewers/media/DashViewer.js b/src/lib/viewers/media/DashViewer.js index f8e982550..a1c258c21 100644 --- a/src/lib/viewers/media/DashViewer.js +++ b/src/lib/viewers/media/DashViewer.js @@ -216,10 +216,10 @@ class DashViewer extends VideoBaseViewer { * Enables or disables automatic adaptation * * @private - * @param {boolean} [adapt] - Enable or disable adaptation + * @param {boolean} adapt - Enable or disable adaptation * @return {void} */ - enableAdaptation(adapt = true) { + enableAdaptation(adapt) { this.adapting = adapt; this.player.configure({ abr: { enabled: adapt } }); } @@ -256,14 +256,16 @@ class DashViewer extends VideoBaseViewer { switch (quality) { case 'hd': + this.enableAdaptation(false); this.enableHD(); break; case 'sd': + this.enableAdaptation(false); this.enableSD(); break; case 'auto': default: - this.enableAdaptation(); + this.enableAdaptation(true); break; } diff --git a/src/lib/viewers/media/__tests__/DashViewer-test.js b/src/lib/viewers/media/__tests__/DashViewer-test.js index 9514e7da9..4def90693 100644 --- a/src/lib/viewers/media/__tests__/DashViewer-test.js +++ b/src/lib/viewers/media/__tests__/DashViewer-test.js @@ -264,7 +264,7 @@ describe('lib/viewers/media/DashViewer', () => { describe('enableAdaptation()', () => { it('should configure player to enable adaptation by default', () => { stubs.mockPlayer.expects('configure').withArgs({ abr: { enabled: true } }); - dash.enableAdaptation(); + dash.enableAdaptation(true); }); it('should configure player to disable adaptation', () => { @@ -277,12 +277,13 @@ describe('lib/viewers/media/DashViewer', () => { beforeEach(() => { stubs.hd = sandbox.stub(dash, 'enableHD'); stubs.sd = sandbox.stub(dash, 'enableSD'); - stubs.auto = sandbox.stub(dash, 'enableAdaptation'); + stubs.adapt = sandbox.stub(dash, 'enableAdaptation'); }); it('should enable HD video', () => { sandbox.stub(dash.cache, 'get').returns('hd'); dash.handleQuality(); + expect(stubs.adapt).to.be.calledWith(false); expect(stubs.hd).to.be.called; expect(dash.emit).to.be.calledWith('qualitychange', 'hd'); }); @@ -290,6 +291,7 @@ describe('lib/viewers/media/DashViewer', () => { it('should enable SD video', () => { sandbox.stub(dash.cache, 'get').returns('sd'); dash.handleQuality(); + expect(stubs.adapt).to.be.calledWith(false); expect(stubs.sd).to.be.called; expect(dash.emit).to.be.calledWith('qualitychange', 'sd'); }); @@ -297,14 +299,14 @@ describe('lib/viewers/media/DashViewer', () => { it('should enable auto video', () => { sandbox.stub(dash.cache, 'get').returns('auto'); dash.handleQuality(); - expect(stubs.auto).to.be.called; + expect(stubs.adapt).to.be.calledWith(true); expect(dash.emit).to.be.calledWith('qualitychange', 'auto'); }); it('should not emit "qualitychange" event if no quality was cached', () => { sandbox.stub(dash.cache, 'get'); dash.handleQuality(); - expect(stubs.auto).to.be.called; + expect(stubs.adapt).to.be.calledWith(true); // default to adapt=true expect(dash.emit).to.not.be.called; }); });