Skip to content

Commit

Permalink
web/webcodecs: always preload polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmoron committed Sep 6, 2024
1 parent cdcf8b9 commit 6b674a1
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions web/src/lib/libav/webcodecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ export default class WebCodecsWrapper {

// FIXME: save me generics. generics save me
async #getDecoder(config: VideoDecoderConfig | AudioDecoderConfig) {
await this.load();

if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) {
const audioConfig = config as AudioDecoderConfig;
for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}

try {
const { supported } = await source.AudioDecoder.isConfigSupported(audioConfig);
if (supported) return source.AudioDecoder;
Expand All @@ -44,10 +42,6 @@ export default class WebCodecsWrapper {
} else {
const videoConfig = config as VideoDecoderConfig;
for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}

try {
const { supported } = await source.VideoDecoder.isConfigSupported(videoConfig);
if (supported) return source.VideoDecoder;
Expand All @@ -62,13 +56,10 @@ export default class WebCodecsWrapper {
}

async #getEncoder(config: VideoEncoderConfig | AudioEncoderConfig) {
await this.load();
if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) {
const audioConfig = config as AudioEncoderConfig;
for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}

try {
const { supported } = await source.AudioEncoder.isConfigSupported(audioConfig);
if (supported) return source.AudioEncoder;
Expand All @@ -80,10 +71,6 @@ export default class WebCodecsWrapper {
} else if (has(config, 'width') && has(config, 'height')) {
const videoConfig = config as VideoEncoderConfig;
for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}

try {
const { supported } = await source.VideoEncoder.isConfigSupported(videoConfig);
if (supported) return source.VideoEncoder;
Expand Down

0 comments on commit 6b674a1

Please sign in to comment.