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

Add preferManagedMediaSource API.md doc entry for ManagedMediaSource usage #5828

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ See [API Reference](https://hlsjs-dev.video-dev.org/api-docs/) for a complete li
- [`maxLiveSyncPlaybackRate`](#maxlivesyncplaybackrate)
- [`liveDurationInfinity`](#livedurationinfinity)
- [`liveBackBufferLength` (deprecated)](#livebackbufferlength-deprecated)
- [`preferManagedMediaSource`](#prefermanagedmediasource)
- [`enableWorker`](#enableworker)
- [`workerPath`](#workerpath)
- [`enableSoftwareAES`](#enablesoftwareaes)
Expand Down Expand Up @@ -375,6 +376,7 @@ var config = {
liveSyncDurationCount: 3,
liveMaxLatencyDurationCount: Infinity,
liveDurationInfinity: false,
preferManagedMediaSource: false,
OrenMe marked this conversation as resolved.
Show resolved Hide resolved
enableWorker: true,
enableSoftwareAES: true,
manifestLoadingTimeOut: 10000,
Expand Down Expand Up @@ -672,6 +674,12 @@ If you want to have a native Live UI in environments like iOS Safari, Safari, An

`liveBackBufferLength` has been deprecated. Use `backBufferLength` instead.

### `preferManagedMediaSource`

(default `true`)

HLS.js uses the Managed Media Source API (`ManagedMediaSource` global) instead of the `MediaSource` global by default when present. Setting this to `false` will only use `ManagedMediaSource` when `MediaSource` is undefined.

### `enableWorker`

(default: `true`)
Expand Down
18 changes: 13 additions & 5 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,19 @@ export default class BufferController implements ComponentAPI {
this.addBufferListener(sbName, 'updateend', this._onSBUpdateEnd);
this.addBufferListener(sbName, 'error', this._onSBUpdateError);
// ManagedSourceBuffer bufferedchange event
this.addBufferListener(sbName, 'bufferedchange', (event) => {
this.hls.trigger(Events.BUFFER_FLUSHED, {
type: trackName as SourceBufferName,
});
});
this.addBufferListener(
sbName,
'bufferedchange',
(type: SourceBufferName, event: Event) => {
// If media was ejected check for a change. Added ranges are redundant with changes on 'updateend' event.
const removedRanges = (event as any).removedRanges;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have types for events so it won't be just any?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @OrenMe! Added an interface definition for the event based on the proposal: bc68a10

This event handler and BUFFER_FLUSHED trigger is primarily for internal book-keeping. The stream controllers use it to detect evicted fragments.

if (removedRanges) {
this.hls.trigger(Events.BUFFER_FLUSHED, {
type: trackName as SourceBufferName,
});
}
},
);

this.tracks[trackName] = {
buffer: sb,
Expand Down