Skip to content

Commit

Permalink
Bugfix: preferManagedMediaSource:false when MSE is not present (#6338)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0d00e7e)
  • Loading branch information
Asen-O-Nikolov authored and robwalch committed Apr 10, 2024
1 parent 1c77fde commit 54d62c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
getCodecCompatibleName,
pickMostCompleteCodecName,
} from '../utils/codecs';
import { getMediaSource } from '../utils/mediasource-helper';
import {
getMediaSource,
isManagedMediaSource,
} from '../utils/mediasource-helper';
import { ElementaryStreamTypes } from '../loader/fragment';
import type { TrackSet } from '../types/track';
import BufferOperationQueue from './buffer-operation-queue';
Expand Down Expand Up @@ -89,10 +92,9 @@ export default class BufferController implements ComponentAPI {
constructor(hls: Hls) {
this.hls = hls;
const logPrefix = '[buffer-controller]';
this.appendSource =
hls.config.preferManagedMediaSource &&
typeof self !== 'undefined' &&
(self as any).ManagedMediaSource;
this.appendSource = isManagedMediaSource(
getMediaSource(hls.config.preferManagedMediaSource),
);
this.log = logger.log.bind(logger, logPrefix);
this.warn = logger.warn.bind(logger, logPrefix);
this.error = logger.error.bind(logger, logPrefix);
Expand Down Expand Up @@ -190,6 +192,7 @@ export default class BufferController implements ComponentAPI {
) {
const media = (this.media = data.media);
const MediaSource = getMediaSource(this.appendSource);

if (media && MediaSource) {
const ms = (this.mediaSource = new MediaSource());
this.log(`created media source: ${ms.constructor?.name}`);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/mediasource-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export function getMediaSource(
((self as any).WebKitMediaSource as typeof MediaSource)
);
}

export function isManagedMediaSource(source: typeof MediaSource | undefined) {
return (
typeof self !== 'undefined' && source === (self as any).ManagedMediaSource
);
}

0 comments on commit 54d62c7

Please sign in to comment.