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

Method flushInternal

src/video_decoder.ts:342–376  ·  view source on GitHub ↗
(configId: number, resolve: () => void)

Source from the content-addressed store, hash-verified

340 }
341
342 private async flushInternal(configId: number, resolve: () => void) {
343 using lock = this.mutex.lock();
344 if (lock.pending) await lock.ready;
345
346 if (this.currentConfigId !== configId) {
347 // Reset/Close happened, promise already rejected
348 return;
349 }
350
351 assert(this.codecContext);
352
353 // Send null packet to signal flush
354 const ret = await this.codecContext.sendPacket(null);
355 if (ret < 0) {
356 throw new DOMException('Flush failed', 'EncodingError');
357 }
358
359 // Keep receiving frames until no more are available
360 while (true) {
361 const receiveRet = await this.codecContext.receiveFrame(this.frame);
362 if (receiveRet < 0) {
363 // No more frames available
364 break;
365 }
366
367 this.outputFrame(configId);
368 }
369
370 this.codecContext.flushBuffers();
371
372 // Spec 4.5: Remove promise from [[pending flush promises]]. Resolve promise.
373 const index = this.pendingFlushResolvers.findIndex(p => p.resolve === resolve);
374 if (index !== -1) this.pendingFlushResolvers.splice(index, 1);
375 resolve();
376 }
377
378 /**
379 * Closes the decoder and releases all resources.

Callers 1

flushMethod · 0.95

Calls 3

outputFrameMethod · 0.95
assertFunction · 0.85
lockMethod · 0.80

Tested by

no test coverage detected