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

Method outputChunk

src/audio_encoder.ts:251–321  ·  view source on GitHub ↗
(currentConfigId: number)

Source from the content-addressed store, hash-verified

249 }
250
251 private outputChunk(currentConfigId: number) {
252 if (this.currentConfigId !== currentConfigId) {
253 return;
254 }
255
256 assert(this.codecContext);
257 assert(this.config);
258
259 if (!this.packet.data) {
260 return;
261 }
262 let data: Uint8Array = this.packet.data;
263
264 let metadata: EncodedAudioChunkMetadata | undefined;
265 if (this.chunkOutputted) {
266 metadata = {};
267 } else {
268 this.chunkTimestampOffset = Math.max(0, -Number(this.packet.pts)); // So that the chunks aren't negative
269
270 const codecString = this.config.codec;
271 let description = this.codecContext.extraData
272 ? toUint8Array(this.codecContext.extraData)
273 : undefined;
274
275 if (
276 description
277 // eslint-disable-next-line @stylistic/max-len
278 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
279 && this.codecContext.codecId === AV_CODEC_ID_AAC && (this.config as any).aac?.format === 'adts'
280 ) {
281 this.aacAudioSpecificConfig = parseAacAudioSpecificConfig(description);
282 description = undefined; // Not used with 'adts' format
283 }
284
285 if (description && this.codecContext.codecId === AV_CODEC_ID_FLAC) {
286 // FFmpeg uses the STREAMINFO block as the extradata, but WebCodecs wants a different format:
287 // 1. The bytes 0x66 0x4C 0x61 0x43 ("fLaC" in ASCII)
288 // 2. A metadata block (called the STREAMINFO block) as described in section 7 of [FLAC]
289 // 3. Other optional metadata blocks (not included here, because, well, they're optional)
290 description = new Uint8Array([
291 0x66, 0x4c, 0x61, 0x43, // 'fLaC'
292 128, 0, 0, description.byteLength,
293 ...description,
294 ]);
295 }
296
297 metadata = {
298 decoderConfig: {
299 codec: codecString,
300 sampleRate: this.codecContext.sampleRate,
301 numberOfChannels: this.codecContext.channels,
302 description,
303 },
304 };
305 }
306
307 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
308 if (this.aacAudioSpecificConfig && (this.config as any).aac?.format === 'adts') {

Callers 1

Calls 4

assertFunction · 0.85
toUint8ArrayFunction · 0.85
aacToAdtsFunction · 0.85

Tested by

no test coverage detected