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
…pported
  • Loading branch information
avelad committed Sep 14, 2022
1 parent 89777dd commit 2d65a18
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ' +
Expand Down

0 comments on commit 2d65a18

Please sign in to comment.