Skip to content

Commit

Permalink
fix: allow the playback on platforms when low latency APIs are not su…
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Sep 22, 2022
1 parent e826eb8 commit c1753e1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/media/streaming_engine.js
Expand Up @@ -1240,7 +1240,16 @@ 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) {
// 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;
this.destroyer_.ensureNotDestroyed();
if (this.fatalError_) {
return;
Expand Down Expand Up @@ -1271,7 +1280,33 @@ shaka.media.StreamingEngine = class {
}
};

await this.fetch_(mediaState, reference, streamDataCallback);
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_) {
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 ' +
Expand Down

0 comments on commit c1753e1

Please sign in to comment.