Skip to content

Commit

Permalink
Fix: Forcing HD/SD should disable adaptation (#292)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bhh1988 authored Aug 10, 2017
1 parent 9b97fd7 commit 8cd67c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
}
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 6 additions & 4 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -277,34 +277,36 @@ 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');
});

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');
});

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;
});
});
Expand Down

0 comments on commit 8cd67c1

Please sign in to comment.