Skip to content

Commit

Permalink
Always use MediaSource returned by utils module (#5448)
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch authored May 3, 2023
1 parent 4aec275 commit 2105ade
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils/codecs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getMediaSource } from './mediasource-helper';

// from http://mp4ra.org/codecs.html
const sampleEntryCodesISO = {
audio: {
Expand Down Expand Up @@ -71,6 +73,8 @@ const sampleEntryCodesISO = {
},
};

const MediaSource = getMediaSource();

export type CodecType = 'audio' | 'video';

export function isCodecType(codec: string, type: CodecType): boolean {
Expand All @@ -79,7 +83,8 @@ export function isCodecType(codec: string, type: CodecType): boolean {
}

export function isCodecSupportedInMp4(codec: string, type: CodecType): boolean {
return MediaSource.isTypeSupported(
`${type || 'video'}/mp4;codecs="${codec}"`
return (
MediaSource?.isTypeSupported(`${type || 'video'}/mp4;codecs="${codec}"`) ??
false
);
}
4 changes: 4 additions & 0 deletions tests/unit/controller/content-steering-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import type { LoaderResponse } from '../../../src/types/loader';
import sinon from 'sinon';
import chai from 'chai';
import sinonChai from 'sinon-chai';
import { getMediaSource } from '../../../src/utils/mediasource-helper';

chai.use(sinonChai);
const expect = chai.expect;

const MediaSource = getMediaSource();

type ConentSteeringControllerTestable = Omit<
ContentSteeringController,
| 'enabled'
Expand Down Expand Up @@ -70,6 +73,7 @@ describe('ContentSteeringController', function () {
contentSteeringController = new ContentSteeringController(
hls as any
) as unknown as ConentSteeringControllerTestable;
// @ts-ignore
sandbox.stub(MediaSource, 'isTypeSupported').returns(true);
});

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ import type { Fragment } from '../../../src/loader/fragment';
import sinon from 'sinon';
import chai from 'chai';
import sinonChai from 'sinon-chai';
import { getMediaSource } from '../../../src/utils/mediasource-helper';

chai.use(sinonChai);
const expect = chai.expect;

const MediaSource = getMediaSource();

type LevelControllerTestable = Omit<LevelController, 'onManifestLoaded'> & {
onManifestLoaded: (event: string, data: Partial<ManifestLoadedData>) => void;
onAudioTrackSwitched: (event: string, data: { id: number }) => void;
Expand Down Expand Up @@ -90,6 +93,7 @@ describe('LevelController', function () {
) as unknown as LevelControllerTestable;
levelController.onParsedComplete = () => {};
hls.levelController = levelController;
// @ts-ignore
sandbox.stub(MediaSource, 'isTypeSupported').returns(true);
});

Expand Down

0 comments on commit 2105ade

Please sign in to comment.