web/webcodecs: always preload polyfill

This commit is contained in:
dumbmoron 2024-09-06 15:15:55 +00:00
parent cfbbe84bd4
commit 694a3303d0
No known key found for this signature in database

View file

@ -26,13 +26,11 @@ export default class WebCodecsWrapper {
// FIXME: save me generics. generics save me // FIXME: save me generics. generics save me
async #getDecoder(config: VideoDecoderConfig | AudioDecoderConfig) { async #getDecoder(config: VideoDecoderConfig | AudioDecoderConfig) {
await this.load();
if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) { if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) {
const audioConfig = config as AudioDecoderConfig; const audioConfig = config as AudioDecoderConfig;
for (const source of [ window, LibAVPolyfill ]) { for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}
try { try {
const { supported } = await source.AudioDecoder.isConfigSupported(audioConfig); const { supported } = await source.AudioDecoder.isConfigSupported(audioConfig);
if (supported) return source.AudioDecoder; if (supported) return source.AudioDecoder;
@ -44,10 +42,6 @@ export default class WebCodecsWrapper {
} else { } else {
const videoConfig = config as VideoDecoderConfig; const videoConfig = config as VideoDecoderConfig;
for (const source of [ window, LibAVPolyfill ]) { for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}
try { try {
const { supported } = await source.VideoDecoder.isConfigSupported(videoConfig); const { supported } = await source.VideoDecoder.isConfigSupported(videoConfig);
if (supported) return source.VideoDecoder; if (supported) return source.VideoDecoder;
@ -62,13 +56,10 @@ export default class WebCodecsWrapper {
} }
async #getEncoder(config: VideoEncoderConfig | AudioEncoderConfig) { async #getEncoder(config: VideoEncoderConfig | AudioEncoderConfig) {
await this.load();
if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) { if (has(config, 'numberOfChannels') && has(config, 'sampleRate')) {
const audioConfig = config as AudioEncoderConfig; const audioConfig = config as AudioEncoderConfig;
for (const source of [ window, LibAVPolyfill ]) { for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}
try { try {
const { supported } = await source.AudioEncoder.isConfigSupported(audioConfig); const { supported } = await source.AudioEncoder.isConfigSupported(audioConfig);
if (supported) return source.AudioEncoder; if (supported) return source.AudioEncoder;
@ -80,10 +71,6 @@ export default class WebCodecsWrapper {
} else if (has(config, 'width') && has(config, 'height')) { } else if (has(config, 'width') && has(config, 'height')) {
const videoConfig = config as VideoEncoderConfig; const videoConfig = config as VideoEncoderConfig;
for (const source of [ window, LibAVPolyfill ]) { for (const source of [ window, LibAVPolyfill ]) {
if (source === LibAVPolyfill) {
await this.load();
}
try { try {
const { supported } = await source.VideoEncoder.isConfigSupported(videoConfig); const { supported } = await source.VideoEncoder.isConfigSupported(videoConfig);
if (supported) return source.VideoEncoder; if (supported) return source.VideoEncoder;