(configId: number, resolve: () => void)
| 289 | } |
| 290 | |
| 291 | private async flushInternal(configId: number, resolve: () => void) { |
| 292 | using lock = this.mutex.lock(); |
| 293 | if (lock.pending) await lock.ready; |
| 294 | |
| 295 | if (this.currentConfigId !== configId) { |
| 296 | // Reset/Close happened, promise already rejected |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | assert(this.codecContext); |
| 301 | |
| 302 | // Send null packet to signal flush |
| 303 | const ret = await this.codecContext.sendPacket(null); |
| 304 | if (ret < 0) { |
| 305 | throw new DOMException('Flush failed', 'EncodingError'); |
| 306 | } |
| 307 | |
| 308 | // Keep receiving frames until no more are available |
| 309 | while (true) { |
| 310 | const receiveRet = await this.codecContext.receiveFrame(this.frame); |
| 311 | if (receiveRet < 0) { |
| 312 | // No more frames available |
| 313 | break; |
| 314 | } |
| 315 | |
| 316 | this.outputData(configId); |
| 317 | } |
| 318 | |
| 319 | this.codecContext.flushBuffers(); |
| 320 | |
| 321 | // Spec: Remove promise from [[pending flush promises]]. Resolve promise. |
| 322 | const index = this._pendingFlushResolvers.findIndex(p => p.resolve === resolve); |
| 323 | if (index !== -1) this._pendingFlushResolvers.splice(index, 1); |
| 324 | resolve(); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Closes the decoder and releases all resources. |
no test coverage detected