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

Method configureInternal

src/audio_encoder.ts:198–229  ·  view source on GitHub ↗
(config: AudioEncoderConfig)

Source from the content-addressed store, hash-verified

196 }
197
198 private async configureInternal(config: AudioEncoderConfig) {
199 const currentConfigId = this.currentConfigId;
200
201 using lock = this.mutex.lock();
202 if (lock.pending) await lock.ready;
203
204 // Check if reset/close happened while waiting for lock
205 if (this.currentConfigId !== currentConfigId) {
206 return;
207 }
208
209 if (this.codecContext) {
210 this.codecContext.freeContext();
211 this.codecContext = null;
212 }
213
214 const result = AudioEncoderPolyfill.createCodecContext(config);
215 if (!result) {
216 throw new DOMException('Unsupported configuration', 'NotSupportedError');
217 }
218
219 this.codecContext = result.codecContext;
220
221 const ret = await this.codecContext.open2();
222 if (ret < 0) {
223 throw new DOMException('Failed to open codec', 'NotSupportedError');
224 }
225
226 this.config = config;
227 this.resampledSampleCount = 0;
228 this.lastResamplerKey = null; // Force resampler reconfiguration
229 }
230
231 /**
232 * Queues audio data to be encoded.

Callers 1

configureMethod · 0.95

Calls 2

lockMethod · 0.80
createCodecContextMethod · 0.45

Tested by

no test coverage detected