(config: AudioEncoderConfig)
| 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. |
no test coverage detected