diff --git a/src/dash-adapter.js b/src/dash-adapter.js index a2891146..1da05c88 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -243,7 +243,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { } if (Utils.Object.hasPropertyPath(config, 'streaming')) { adapterConfig.forceBreakStall = Utils.Object.getPropertyPath(config, 'streaming.forceBreakStall'); - adapterConfig.shakaConfig.streaming.lowLatencyMode = Utils.Object.getPropertyPath(config, 'streaming.lowLatencyMode'); + adapterConfig.lowLatencyMode = Utils.Object.getPropertyPath(config, 'streaming.lowLatencyMode'); } if (Utils.Object.hasPropertyPath(config, 'sources.options')) { const options = config.sources.options; @@ -755,6 +755,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { } _onLoadedData(): void { + this._setLowLatencyMode(); const segmentDuration = this.getSegmentDuration(); this._seekRangeStart = this._shaka.seekRange().start; this._startOverTimeout = setTimeout(() => { @@ -765,6 +766,14 @@ export default class DashAdapter extends BaseMediaSourceAdapter { }, (segmentDuration + 1) * 1000); } + _setLowLatencyMode() { + this._shaka.configure({ + streaming: { + lowLatencyMode: typeof this._config.lowLatencyMode === 'boolean' ? this._config.lowLatencyMode : this.isLive() + } + }); + } + /** * Custom parser to retrieve image adaptation sets. * @param {ArrayBuffer} manifestBuffer - The array buffer manifest from the response. diff --git a/test/src/dash-adapter.spec.js b/test/src/dash-adapter.spec.js index e03e4ee6..4b3de118 100644 --- a/test/src/dash-adapter.spec.js +++ b/test/src/dash-adapter.spec.js @@ -213,6 +213,72 @@ describe('DashAdapter: load', () => { }); }); + it('should set streaming.lowLatencyMode config to false on vod by default', done => { + try { + dashInstance = DashAdapter.createAdapter(video, vodSource, config); + video.addEventListener(EventType.LOADED_DATA, () => { + dashInstance._shaka.getConfiguration().streaming.lowLatencyMode.should.equal(false); + done(); + }); + + dashInstance.load().then(() => { + video.play(); + }); + } catch (e) { + done(e); + } + }); + + it('should set streaming.lowLatencyMode config to true on live by default', done => { + try { + dashInstance = DashAdapter.createAdapter(video, liveSource, config); + video.addEventListener(EventType.LOADED_DATA, () => { + dashInstance._shaka.getConfiguration().streaming.lowLatencyMode.should.equal(true); + done(); + }); + + dashInstance.load().then(() => { + video.play(); + }); + } catch (e) { + done(e); + } + }); + + it('should take the streaming.lowLatencyMode value from config when configured manually - vod', done => { + try { + const playerConfig = {...config, streaming: {lowLatencyMode: true}}; + dashInstance = DashAdapter.createAdapter(video, vodSource, playerConfig); + video.addEventListener(EventType.LOADED_DATA, () => { + dashInstance._shaka.getConfiguration().streaming.lowLatencyMode.should.equal(true); + done(); + }); + + dashInstance.load().then(() => { + video.play(); + }); + } catch (e) { + done(e); + } + }); + + it('should take the streaming.lowLatencyMode value from config when configured manually - live', done => { + try { + const playerConfig = {...config, streaming: {lowLatencyMode: false}}; + dashInstance = DashAdapter.createAdapter(video, vodSource, playerConfig); + video.addEventListener(EventType.LOADED_DATA, () => { + dashInstance._shaka.getConfiguration().streaming.lowLatencyMode.should.equal(false); + done(); + }); + + dashInstance.load().then(() => { + video.play(); + }); + } catch (e) { + done(e); + } + }); + it('should load successfully when given a valid video to play', done => { dashInstance = DashAdapter.createAdapter(video, vodSource, config); dashInstance