(configId: number, resolve: () => void)
| 588 | } |
| 589 | |
| 590 | private async flushInternal(configId: number, resolve: () => void) { |
| 591 | using lock = this.mutex.lock(); |
| 592 | if (lock.pending) await lock.ready; |
| 593 | |
| 594 | if (this.currentConfigId !== configId) { |
| 595 | // Reset/Close happened, promise already rejected |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | assert(this.codecContext); |
| 600 | |
| 601 | // Drain any remaining samples from the resampler |
| 602 | if (this.resampler && this.dstFrame && this.codecContext.frameSize > 0) { |
| 603 | await this.pullResampledFrames(configId, true); |
| 604 | } |
| 605 | |
| 606 | // Signal flush to the encoder |
| 607 | await this.sendFrameAndReceivePackets(null, configId); |
| 608 | |
| 609 | this.codecContext.flushBuffers(); |
| 610 | this.chunkOutputted = false; |
| 611 | this.nextPts = 0n; |
| 612 | this.resampledSampleCount = 0; |
| 613 | |
| 614 | // Spec: Remove promise from [[pending flush promises]]. Resolve promise. |
| 615 | const index = this.pendingFlushResolvers.findIndex(p => p.resolve === resolve); |
| 616 | if (index !== -1) this.pendingFlushResolvers.splice(index, 1); |
| 617 | resolve(); |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Closes the encoder and releases all resources. |
no test coverage detected