(config: VideoEncoderConfig)
| 272 | } |
| 273 | |
| 274 | private async configureInternal(config: VideoEncoderConfig) { |
| 275 | const currentConfigId = this.currentConfigId; |
| 276 | |
| 277 | using lock = this.mutex.lock(); |
| 278 | if (lock.pending) await lock.ready; |
| 279 | |
| 280 | // Check if reset/close happened while waiting for lock |
| 281 | if (this.currentConfigId !== currentConfigId) { |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | // Spec 6.5: If supported is false, queue a task to run the Close VideoEncoder algorithm with NotSupportedError. |
| 286 | // Emulated by trying to open the context. |
| 287 | |
| 288 | if (this.codecContext) { |
| 289 | this.codecContext.freeContext(); |
| 290 | this.codecContext = null; |
| 291 | } |
| 292 | |
| 293 | this.codecContext = VideoEncoderPolyfill.createCodecContext(config); |
| 294 | if (!this.codecContext) { |
| 295 | throw new DOMException('Unsupported configuration', 'NotSupportedError'); |
| 296 | } |
| 297 | |
| 298 | const ret = await this.codecContext.open2(); |
| 299 | if (ret < 0) { |
| 300 | throw new DOMException('Failed to open codec', 'NotSupportedError'); |
| 301 | } |
| 302 | |
| 303 | this.config = config; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Queues a video frame to be encoded. |
no test coverage detected