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

feat: Add support for ManagedMediaSource 'startstreaming' and 'endstream' event handling #1542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-barstow
Copy link
Contributor

Description

This PR adds onto the experimental support for ManagedMediaSource. When the user agent determines that a ManagedMediaSource has enough data buffered to ensure uninterrupted playback, or does not have enough to ensure it, it will fire a endstreaming or startstreaming event, indicating that the player should stop loading new segments or start loading new segments, respectively.

Specific Changes proposed

Add 2 new event handlers for startstreaming and endstreaming. The former will call playlistController.load(), which was a preexisting method that calls load() on all active segment loaders. The latter calls playlistController.pause(), which is a new method that calls pause() on all active segment loaders.

Requirements Checklist

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

References

https://www.w3.org/TR/media-source-2/#dom-managedmediasource-streaming
w3c/media-source#320

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.37%. Comparing base (f6a4f79) to head (3a0add4).

Files with missing lines Patch % Lines
src/playlist-controller.js 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1542      +/-   ##
==========================================
+ Coverage   86.36%   86.37%   +0.01%     
==========================================
  Files          43       43              
  Lines       11148    11165      +17     
  Branches     2545     2548       +3     
==========================================
+ Hits         9628     9644      +16     
- Misses       1520     1521       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -192,6 +192,7 @@ export class PlaylistController extends videojs.EventTarget {
this.playlistExclusionDuration = playlistExclusionDuration;
this.maxPlaylistRetries = maxPlaylistRetries;
this.enableLowInitialPlaylist = enableLowInitialPlaylist;
this.hasManagedMediaSource_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: To save a few lines of code, you could change this to:

this.hasManagedMediaSource_ = experimentalUseMMS && window.ManagedMediaSource;

Copy link
Contributor Author

@alex-barstow alex-barstow Oct 3, 2024

Choose a reason for hiding this comment

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

The intent of the flag was to signal that the ManagedMediaSource has been created and currently exists. If we set it here we should rename the flag to useManagedMediaSource_ or createManagedMediaSource_, as it hasn't been created yet.

@@ -215,6 +216,8 @@ export class PlaylistController extends videojs.EventTarget {
// Airplay source not yet implemented. Remote playback must be disabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can change the above if statement to:

if (this.hasManagedMediaSource_) {

@@ -232,6 +235,14 @@ export class PlaylistController extends videojs.EventTarget {
// we don't have to handle sourceclose since dispose will handle termination of
// everything, and the MediaSource should not be detached without a proper disposal

if (this.hasManagedMediaSource_) {
this.handleStartStreaming_ = this.handleStartStreaming_.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add the content of this if statement to the above pre-existing if statement. All nits, but saves a few lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean to the if (experimentalUseMMS && window.ManagedMediaSource) {...} block? It is more concise but I opted against it because to my eye it made the code slightly less organized by putting the new addEventListener calls inside the block where the MediaSource is set rather than in the subsequent step/section where the other MediaSource event handlers are added. Minor issue, I'm happy to change it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, all my comments were basically to save some lines of code by moving this code to where you set the hasManagedMediaSource flag and making the flag unnecessary, but fine with me if it keeps it cleaner in your eyes. 👍

Copy link
Contributor

@wseymour15 wseymour15 left a comment

Choose a reason for hiding this comment

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

Good work! Looks good to me

@@ -232,6 +235,14 @@ export class PlaylistController extends videojs.EventTarget {
// we don't have to handle sourceclose since dispose will handle termination of
// everything, and the MediaSource should not be detached without a proper disposal

if (this.hasManagedMediaSource_) {
this.handleStartStreaming_ = this.handleStartStreaming_.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, all my comments were basically to save some lines of code by moving this code to where you set the hasManagedMediaSource flag and making the flag unnecessary, but fine with me if it keeps it cleaner in your eyes. 👍

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