Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow the playback on platforms when low latency APIs are not supported #4485

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
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) {
avelad marked this conversation as resolved.
Show resolved Hide resolved
// If the fallback result processing was triggered, don't also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in my understanding, that this shouldn't happen? In theory, if the fallback has executed, the streamDataCallback shouldn't fire after that, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theory tells me that it should never happen, but... I have found a case in an old TV :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yikes. Well, maybe add some mention of that in the comments. Otherwise, some well-meaning person might "optimize" this check away later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

// 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) {
avelad marked this conversation as resolved.
Show resolved Hide resolved
// 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