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

Method outputChunk

src/video_encoder.ts:329–432  ·  view source on GitHub ↗
(currentConfigId: number)

Source from the content-addressed store, hash-verified

327 }
328
329 private outputChunk(currentConfigId: number) {
330 if (this.currentConfigId !== currentConfigId) {
331 return;
332 }
333
334 assert(this.codecContext);
335 assert(this.config);
336
337 if (!this.packet.data) {
338 return;
339 }
340 let data: Uint8Array = this.packet.data;
341
342 const needsAnnexBToLengthPrefixConversion
343 = (this.codecContext.codecId === AV_CODEC_ID_H264 && this.config.avc?.format !== 'annexb')
344 // eslint-disable-next-line @stylistic/max-len
345 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
346 || (this.codecContext.codecId === AV_CODEC_ID_HEVC && (this.config as any).hevc?.format !== 'annexb');
347 if (needsAnnexBToLengthPrefixConversion) {
348 data = transformAnnexBToLengthPrefixed(data) ?? data;
349 }
350
351 const chunk = new EncodedVideoChunkPolyfill({
352 type: this.packet.isKeyframe ? 'key' : 'delta',
353 timestamp: Number(this.packet.pts),
354 duration: Number(this.packet.duration),
355 data,
356 });
357
358 let metadata: EncodedVideoChunkMetadata | undefined;
359 if (this.chunkOutputted) {
360 metadata = {};
361 } else {
362 let codecString: string;
363 let description: Uint8Array | undefined = undefined;
364
365 if (this.codecContext.codecId === AV_CODEC_ID_H264) {
366 const record = extractAvcDecoderConfigurationRecord(this.packet.data);
367 if (!record) {
368 throw new Error('Invalid AVC data, could not extract decoder configuration record.');
369 }
370
371 codecString = generateAvcCodecString(record);
372
373 if (this.config.avc?.format !== 'annexb') {
374 description = serializeAvcDecoderConfigurationRecord(record);
375 }
376 } else if (this.codecContext.codecId === AV_CODEC_ID_HEVC) {
377 const record = extractHevcDecoderConfigurationRecord(this.packet.data);
378 if (!record) {
379 throw new Error('Invalid HEVC data, could not extract decoder configuration record.');
380 }
381
382 codecString = generateHevcCodecString(record);
383
384 // eslint-disable-next-line @stylistic/max-len
385 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
386 if ((this.config as any).hevc?.format !== 'annexb') {

Callers 2

encodeInternalMethod · 0.95
flushInternalMethod · 0.95

Tested by

no test coverage detected