From 2d65a184214a220184d8662f8e19dd9b3fde83f4 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Wed, 14 Sep 2022 19:37:12 +0200 Subject: [PATCH 1/4] fix: allow the playback on platforms when low latency APIs are not supported --- lib/media/streaming_engine.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 3bee682a6a..0f918fac18 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1240,7 +1240,13 @@ shaka.media.StreamingEngine = class { if (this.config_.lowLatencyMode && isReadableStreamSupported && isMP4 && !reference.hlsAes128Key) { let remaining = new Uint8Array(0); + let processingResult = false; + let callbackCalled = false; const streamDataCallback = async (data) => { + if (processingResult) { + return; + } + callbackCalled = true; this.destroyer_.ensureNotDestroyed(); if (this.fatalError_) { return; @@ -1271,7 +1277,30 @@ shaka.media.StreamingEngine = class { } }; - await this.fetch_(mediaState, reference, streamDataCallback); + const result = + await this.fetch_(mediaState, reference, streamDataCallback); + if (!callbackCalled) { + processingResult = true; + this.destroyer_.ensureNotDestroyed(); + if (this.fatalError_) { + return; + } + + // If the text stream gets switched between fetch_() and append_(), + // the new text parser is initialized, but the new init segment is + // not fetched yet. That would cause an error in + // TextParser.parseMedia(). + // See http://b/168253400 + if (mediaState.waitingToClearBuffer) { + shaka.log.info(logPrefix, 'waitingToClearBuffer, skip append'); + mediaState.performingUpdate = false; + this.scheduleUpdate_(mediaState, 0); + return; + } + + await this.append_( + mediaState, presentationTime, stream, reference, result); + } } else { if (this.config_.lowLatencyMode && !isReadableStreamSupported) { shaka.log.warning('Low latency streaming mode is enabled, but ' + From ad617403defb8ee50e8aca78cf76116f9061dc3f Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Mon, 19 Sep 2022 16:49:01 +0200 Subject: [PATCH 2/4] Add comments --- lib/media/streaming_engine.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 0f918fac18..eac5ae9b50 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1244,6 +1244,8 @@ shaka.media.StreamingEngine = class { let callbackCalled = false; const streamDataCallback = async (data) => { if (processingResult) { + // If the fallback result processing was triggered, don't also + // append the buffer here. return; } callbackCalled = true; @@ -1280,6 +1282,9 @@ shaka.media.StreamingEngine = class { const result = await this.fetch_(mediaState, reference, streamDataCallback); if (!callbackCalled) { + // In some environments, we might be forced to use network plugins + // that don't support streamDataCallback. In those cases, as a + // fallback, append the buffer here. processingResult = true; this.destroyer_.ensureNotDestroyed(); if (this.fatalError_) { From 30bddadeb60866228024ed8544e426f20780fd82 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Thu, 22 Sep 2022 19:21:02 +0200 Subject: [PATCH 3/4] Add clarification --- lib/media/streaming_engine.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index eac5ae9b50..d981b5017d 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1246,6 +1246,7 @@ shaka.media.StreamingEngine = class { if (processingResult) { // If the fallback result processing was triggered, don't also // append the buffer here. + // In theory this should never happen, but it does on some older TVs. return; } callbackCalled = true; From 288b9fbe821a6e954b5c902900fe70aa1a482258 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Thu, 22 Sep 2022 19:24:25 +0200 Subject: [PATCH 4/4] fix typo --- lib/media/streaming_engine.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index d981b5017d..fbb94d872f 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1245,8 +1245,8 @@ shaka.media.StreamingEngine = class { const streamDataCallback = async (data) => { if (processingResult) { // If the fallback result processing was triggered, don't also - // append the buffer here. - // In theory this should never happen, but it does on some older TVs. + // append the buffer here. In theory this should never happen, + // but it does on some older TVs. return; } callbackCalled = true;