MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / isConfigSupported

Method isConfigSupported

src/audio_encoder.ts:155–179  ·  view source on GitHub ↗

* Checks if the encoder can support the given configuration.

(config: AudioEncoderConfig)

Source from the content-addressed store, hash-verified

153 * Checks if the encoder can support the given configuration.
154 */
155 static async isConfigSupported(config: AudioEncoderConfig): Promise<AudioEncoderSupport> {
156 const inferred = inferCodecFromCodecString(config.codec);
157 if (!inferred) {
158 return { config, supported: false };
159 }
160
161 const cacheKey = configToCacheKey(inferred, config.sampleRate, config.numberOfChannels, config.bitrate);
162 if (configSupportCache.has(cacheKey)) {
163 return { config, supported: configSupportCache.get(cacheKey)! };
164 }
165
166 const result = this.createCodecContext(config);
167 if (!result) {
168 return { config, supported: false };
169 }
170
171 const { codecContext } = result;
172 const ret = await codecContext.open2();
173 const supported = ret >= 0;
174 codecContext.freeContext();
175
176 configSupportCache.set(cacheKey, supported);
177
178 return { config, supported };
179 }
180
181 /**
182 * Configures the encoder with the given configuration.

Callers

nothing calls this directly

Calls 3

createCodecContextMethod · 0.95
configToCacheKeyFunction · 0.70

Tested by

no test coverage detected