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: run callbacks after setting timestampOffset #480

Merged
merged 2 commits into from
Apr 26, 2019

Conversation

squarebracket
Copy link
Contributor

Description

Long story short, I hit a condition where non-muxed HLS wouldn't start playing sometimes. This is because it's possible to end up in a condition where one SourceUpdater gets both a timestampOffset and an appendBuffer call before the other SourceBuffer is added to the MediaSource. Since timestampOffset queues a callback, but does not trigger an updateend on the SourceBuffer, the already-queued appendBuffer call is never processed, and thus a SegmentLoader ends up waiting forever.

For easy reproduction of the problem, you can simply delay the creation of the audio SourceBuffer, like so:

diff --git i/src/source-updater.js w/src/source-updater.js
index b89993d..f0e8c4b 100644
--- i/src/source-updater.js
+++ w/src/source-updater.js
@@ -35,7 +35,13 @@ export default class SourceUpdater {
       mediaSource.addEventListener(
         'sourceopen', this.createSourceBuffer_.bind(this, mimeType, sourceBufferEmitter));
     } else {
-      this.createSourceBuffer_(mimeType, sourceBufferEmitter);
+      if (mimeType === 'audio/mp2t; codecs="mp4a.40.2"') {
+        setTimeout(() => {
+          this.createSourceBuffer_(mimeType, sourceBufferEmitter);
+        }, 2000);
+      } else {
+        this.createSourceBuffer_(mimeType, sourceBufferEmitter);
+      }
     }
   }

Specific Changes proposed

Simply call this.runCallback_() in the queued callback so that any other queued callbacks are run. I'm not sure if this is bad form; perhaps this.runCallback_() should be inside a setTimeout()?

Note: I'm adding the fix on a separate commit so you can see the change from fail -> pass.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
  • Reviewed by Two Core Contributors

@squarebracket
Copy link
Contributor Author

Rebased to my fork's master instead of upstream 🤦‍♂️

Let's try this again.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Seems like runCallback_ gets called directly in a few places, so, don't have a problem with it being called here.
LGTM.

@squarebracket squarebracket merged commit 6ecf859 into videojs:master Apr 26, 2019
@squarebracket squarebracket deleted the fix/unstuck-demuxed-hls branch April 26, 2019 21:33
@gkatsev
Copy link
Member

gkatsev commented Apr 29, 2019

tested, looks fine

brandonocasey added a commit that referenced this pull request May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants