diff --git a/AUTHORS b/AUTHORS index 558ae8f050..089a37c56b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -67,6 +67,7 @@ Toshihiro Suzuki uStudio Inc. <*@ustudio.com> Verizon Digital Media Services <*@verizondigitalmedia.com> Vincent Valot +Wayne Morgan Prakash diff --git a/CONTRIBUTORS b/CONTRIBUTORS index db37181245..de40a37713 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -102,6 +102,7 @@ Toshihiro Suzuki Vasanth Polipelli Vignesh Venkatasubramanian Vincent Valot +Wayne Morgan Yohann Connell Adrián Gómez Llorente Prakash Duggaraju diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 3d1419bc25..57908079b3 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1188,10 +1188,14 @@ shaka.media.StreamingEngine = class { mediaState.performingUpdate = true; - const initSourceBuffer = this.initSourceBuffer_(mediaState, reference); - - shaka.log.v2(logPrefix, 'fetching segment'); try { + await this.initSourceBuffer_(mediaState, reference); + this.destroyer_.ensureNotDestroyed(); + if (this.fatalError_) { + return; + } + + shaka.log.v2(logPrefix, 'fetching segment'); const isMP4 = stream.mimeType == 'video/mp4' || stream.mimeType == 'audio/mp4'; const isReadableStreamSupported = window.ReadableStream; @@ -1199,7 +1203,6 @@ shaka.media.StreamingEngine = class { if (this.config_.lowLatencyMode && isReadableStreamSupported && isMP4) { let remaining = new Uint8Array(0); const streamDataCallback = async (data) => { - await initSourceBuffer; this.destroyer_.ensureNotDestroyed(); if (this.fatalError_) { return; @@ -1237,7 +1240,7 @@ shaka.media.StreamingEngine = class { 'ReadableStream is not supported by the browser.'); } const fetchSegment = this.fetch_(mediaState, reference); - const results = await Promise.all([initSourceBuffer, fetchSegment]); + const result = await fetchSegment; this.destroyer_.ensureNotDestroyed(); if (this.fatalError_) { return; @@ -1254,7 +1257,7 @@ shaka.media.StreamingEngine = class { return; } await this.append_( - mediaState, presentationTime, stream, reference, results[1]); + mediaState, presentationTime, stream, reference, result); } this.destroyer_.ensureNotDestroyed(); diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index 0ea8af328b..9d9128fcd9 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -835,7 +835,7 @@ describe('StreamingEngine', () => { // This would let some media types buffer faster than others if unchecked. netEngineDelays.text = 0.1; netEngineDelays.audio = 1.0; - netEngineDelays.video = 10.0; + netEngineDelays.video = 5.0; // Need init segment and media segment mediaSourceEngine.appendBuffer.and.callFake((type, data, start, end) => { // Call to the underlying implementation. @@ -2170,13 +2170,13 @@ describe('StreamingEngine', () => { .bind(mediaSourceEngine); mediaSourceEngine.remove.and.callFake((type, start, end) => { - expect(presentationTimeInSeconds).toBe(20); + expect(presentationTimeInSeconds).toBeGreaterThanOrEqual(20); expect(start).toBe(0); expect(end).toBe(10); if (mediaSourceEngine.remove.calls.count() == 3) { mediaSourceEngine.remove.and.callFake((type, start, end) => { - expect(presentationTimeInSeconds).toBe(30); + expect(presentationTimeInSeconds).toBeGreaterThanOrEqual(30); expect(start).toBe(10); expect(end).toBe(20); return originalRemove(type, start, end);