@blockcast/mmt-render 0.1.0 → 0.3.0-main.d9354616fdf2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/audio/audio-render-pipeline.ts", "../../src/pacing/frame-pacer.ts", "../../src/pacing/au-duration.ts", "../../src/audio/worklet-url.ts"],
4
- "sourcesContent": ["/**\n * AudioRenderPipeline \u2014 end-to-end audio render for MoQ/MMT players.\n *\n * Pipeline: MoQ object \u2192 MmtpDecodePipeline \u2192 WebCodecs AudioDecoder\n * \u2192 AudioWorkletNode (exact-timestamp FIFO)\n *\n * The consumer:\n * 1. constructs with codec/sampleRate/channels/mapper from catalog\n * 2. awaits ready()\n * 3. calls feedMoqObject(packet) for each arriving MoQ object\n * 4. between objects, awaits paceSleepMs() to throttle burst delivery\n * 5. connects rootNode to an AudioContext destination (or a GainNode)\n * 6. close() on teardown\n *\n * Pacing uses FrameCountPacer (anchor on first decoded AU, frame count \u00D7 AU\n * duration) with threshold = mapper.pacingThresholdMs \u2014 NOT MPU timestamps\n * (ambiguous under FEC interleave).\n */\n\nimport { MmtpDecodePipeline, type PipelineFecClient } from '@blockcast/mmt-container/mmtp-decode-pipeline'\nimport type { MfuReassemblyPolicy } from '@blockcast/mmt-container/mfu-reassembly-policy'\nimport type { FecBlockMapper } from '@blockcast/mmt-fec'\nimport { FrameCountPacer } from '../pacing/frame-pacer.js'\nimport { auDurationMsFromCodec } from '../pacing/au-duration.js'\nimport type {\n ToMain,\n DataMessage,\n InitMessage,\n ResetMessage,\n StartMessage,\n} from './render-messages.js'\nimport { WORKLET_PROCESSOR_NAME, workletModuleUrl } from './worklet-url.js'\n\nexport interface AudioRenderPipelineOpts {\n context: AudioContext\n codec: string\n /** MMTP packet_id for this audio track \u2014 from catalog. */\n packetId?: number\n sampleRate: number\n channels: number\n description?: Uint8Array\n mapper: FecBlockMapper\n fecClient?: PipelineFecClient\n /** Reliable MoQ is clock-free; datagram deadlines come from catalog/in-band timing. */\n reassemblyPolicy: MfuReassemblyPolicy\n /** Catalog-derived PCM startup buffer in milliseconds. */\n latencyMs: number\n /** Exact PCM startup threshold when catalog grouping is codec-aligned. */\n startupFrames?: number\n /** Exact PCM storage ceiling, including one successor delivery burst. */\n capacityFrames?: number\n /** Enable ring-buffer telemetry messages. Default false. */\n diag?: boolean\n /** Called when worklet reports state (playback timestamp + exact buffer accounting). Optional. */\n onState?: (state: {\n timestampUs: number | undefined\n stalled: boolean\n bufferedFrames: number\n writtenFrames: number\n }) => void\n /** Called when worklet reports ring-buffer diag (telemetry). Optional. */\n onDiag?: (diag: {\n reads: number; avgFill: number; capacity: number\n skipsPerSec: number; dupsPerSec: number; overflowSamplesPerSec: number\n underflowSamplesPerSec: number\n }) => void\n /** Warmup frames before pacing engages. Default 0 (audio tolerates instant pacing). */\n warmupFrames?: number\n /** Audio underflow / config event logger. Optional. */\n onError?: (err: unknown) => void\n}\n\nexport class AudioRenderPipeline {\n readonly #context: AudioContext\n readonly #pacer: FrameCountPacer\n readonly #mapper: FecBlockMapper\n readonly #codec: string\n readonly #packetId: number | undefined\n readonly #sampleRate: number\n readonly #channels: number\n readonly #description?: Uint8Array\n readonly #latencyMs: number\n readonly #startupFrames?: number\n readonly #startupThresholdFrames: number\n readonly #capacityFrames?: number\n readonly #diag: boolean\n readonly #warmupFrames: number\n readonly #onState?: AudioRenderPipelineOpts['onState']\n readonly #onDiag?: AudioRenderPipelineOpts['onDiag']\n readonly #onError?: AudioRenderPipelineOpts['onError']\n readonly #reassemblyPolicy: MfuReassemblyPolicy\n\n #decoder: AudioDecoder | null = null\n #pipeline: MmtpDecodePipeline | null = null\n #worklet: AudioWorkletNode | null = null\n #fecClient?: PipelineFecClient\n #closed = false\n #readyPromise: Promise<void> | null = null\n #workletGeneration = 0\n #startupReleased = false\n\n constructor(opts: AudioRenderPipelineOpts) {\n this.#context = opts.context\n this.#mapper = opts.mapper\n this.#codec = opts.codec\n this.#packetId = opts.packetId\n this.#sampleRate = opts.sampleRate\n this.#channels = opts.channels\n this.#description = opts.description\n this.#latencyMs = opts.latencyMs\n this.#startupFrames = opts.startupFrames\n this.#startupThresholdFrames = opts.startupFrames\n ?? Math.ceil(opts.sampleRate * (opts.latencyMs / 1000))\n this.#capacityFrames = opts.capacityFrames\n this.#diag = opts.diag ?? false\n this.#warmupFrames = opts.warmupFrames ?? 0\n this.#onState = opts.onState\n this.#onDiag = opts.onDiag\n this.#onError = opts.onError\n this.#fecClient = opts.fecClient\n this.#reassemblyPolicy = opts.reassemblyPolicy\n\n // AU duration from codec + sampleRate. Keep inside the lib so consumers\n // don't re-derive it.\n const auDurationMs = auDurationMsFromCodec(opts.codec, opts.sampleRate)\n this.#pacer = new FrameCountPacer({\n frameDurationMs: auDurationMs,\n mapper: opts.mapper,\n warmupFrames: this.#warmupFrames,\n })\n }\n\n /** Load worklet module + create decoder + pipeline. Call once. */\n async ready(): Promise<void> {\n if (this.#readyPromise) return this.#readyPromise\n this.#readyPromise = this.#initialize()\n return this.#readyPromise\n }\n\n async #initialize(): Promise<void> {\n // 1. Load shared worklet module.\n await this.#context.audioWorklet.addModule(workletModuleUrl())\n\n // 2. Create worklet node.\n const worklet = new AudioWorkletNode(this.#context, WORKLET_PROCESSOR_NAME, {\n numberOfInputs: 0,\n numberOfOutputs: 1,\n outputChannelCount: [this.#channels],\n })\n const initMsg: InitMessage = {\n type: 'init',\n generation: ++this.#workletGeneration,\n channels: this.#channels,\n rate: this.#sampleRate,\n latencyMs: this.#latencyMs,\n startupFrames: this.#startupFrames,\n capacityFrames: this.#capacityFrames,\n holdUntilStart: true,\n diag: this.#diag,\n }\n worklet.port.postMessage(initMsg)\n worklet.port.onmessage = (ev: MessageEvent<ToMain>) => {\n const m = ev.data\n if (m.type === 'state') {\n if (m.generation !== this.#workletGeneration) return\n this.#onState?.({\n timestampUs: m.timestamp,\n stalled: m.stalled,\n bufferedFrames: m.bufferedFrames,\n writtenFrames: m.writtenFrames,\n })\n } else if (m.type === 'ringBufDiag') {\n if (m.generation !== this.#workletGeneration) return\n this.#onDiag?.({\n reads: m.reads, avgFill: m.avgFill, capacity: m.capacity,\n skipsPerSec: m.skipsPerSec, dupsPerSec: m.dupsPerSec,\n overflowSamplesPerSec: m.overflowSamplesPerSec,\n underflowSamplesPerSec: m.underflowSamplesPerSec,\n })\n } else if (m.type === 'writeAck') {\n if (\n m.generation !== this.#workletGeneration ||\n this.#startupReleased ||\n m.bufferedFrames < this.#startupThresholdFrames\n ) return\n this.#startupReleased = true\n const start: StartMessage = {\n type: 'start',\n generation: this.#workletGeneration,\n }\n worklet.port.postMessage(start)\n }\n }\n this.#worklet = worklet\n\n // 3. Create decoder.\n const decoder = new AudioDecoder({\n output: (data) => this.#onDecoded(data),\n error: (err) => this.#onError?.(err),\n })\n const config: AudioDecoderConfig = {\n codec: this.#codec,\n sampleRate: this.#sampleRate,\n numberOfChannels: this.#channels,\n ...(this.#description ? { description: this.#description } : {}),\n }\n decoder.configure(config)\n this.#decoder = decoder\n\n // 4. Create decode pipeline.\n const pipeline = new MmtpDecodePipeline()\n pipeline.configure({\n codec: this.#codec,\n packetId: this.#packetId,\n description: this.#description,\n reorderWindow: 0, // audio doesn't need reorder \u2014 AAC/Opus frames are self-contained\n reassemblyPolicy: this.#reassemblyPolicy,\n })\n if (this.#fecClient) pipeline.setFecClient(this.#fecClient)\n pipeline.onFrame((codecData, meta) => {\n if (!this.#decoder || this.#decoder.state !== 'configured') return\n if (codecData.byteLength === 0) return\n this.#pacer.notifyFrame()\n try {\n this.#decoder.decode(new EncodedAudioChunk({\n type: 'key',\n data: codecData,\n timestamp: meta.timestamp,\n }))\n } catch (err) {\n this.#onError?.(err)\n }\n })\n this.#pipeline = pipeline\n }\n\n /** Feed one MoQ object (raw MMTP packet). */\n feedMoqObject(packet: Uint8Array): void {\n this.#pipeline?.feedMoqObject(packet)\n }\n\n /** ms to sleep before the next object read. 0 when not anchored / not ahead. */\n paceSleepMs(): number {\n return this.#pacer.computeSleepMs()\n }\n\n /** Pacer snapshot (for diagnostics / UI). */\n get pacerSnapshot() {\n return this.#pacer.snapshot\n }\n\n /** Reset pacer on source switch (MoQ \u2194 multicast). */\n resetPacer(): void {\n this.#pacer.reset()\n }\n\n /** Drop queued PCM and its timestamp epoch at an explicit source boundary. */\n resetPlayout(startUnstalled = false): void {\n this.#pacer.reset()\n // The explicit gate owns only the initial prefill. Source-boundary resets\n // use the worklet's one-frame resume threshold.\n this.#startupReleased = true\n const message: ResetMessage = {\n type: 'reset',\n generation: ++this.#workletGeneration,\n startUnstalled,\n }\n this.#worklet?.port.postMessage(message)\n }\n\n /** Node to connect to destination / gain. */\n get rootNode(): AudioNode {\n if (!this.#worklet) throw new Error('AudioRenderPipeline.ready() must resolve first')\n return this.#worklet\n }\n\n close(): void {\n if (this.#closed) return\n this.#closed = true\n try { this.#decoder?.close() } catch { /* already closed */ }\n try { this.#pipeline?.dispose() } catch { /* noop */ }\n try { this.#worklet?.disconnect() } catch { /* noop */ }\n this.#decoder = null\n this.#pipeline = null\n this.#worklet = null\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n #onDecoded(sample: AudioData): void {\n if (this.#closed || !this.#worklet) { sample.close(); return }\n\n const timestamp = sample.timestamp\n const channelData: Float32Array[] = []\n for (let ch = 0; ch < sample.numberOfChannels; ch++) {\n const data = new Float32Array(sample.numberOfFrames)\n sample.copyTo(data, { format: 'f32-planar', planeIndex: ch })\n channelData.push(data)\n }\n sample.close()\n\n const msg: DataMessage = {\n type: 'data',\n data: channelData,\n timestamp,\n }\n this.#worklet.port.postMessage(msg, channelData.map((d) => d.buffer))\n }\n}\n\n// auDurationMsFromCodec lives in ../pacing/au-duration.ts (canonical, no\n// mmt-container dep). Import it from '@blockcast/mmt-render/pacing' directly\n// or via the top-level '@blockcast/mmt-render' export.\n", "/**\n * FrameCountPacer \u2014 media-agnostic wall-clock pacer for MMT A/V decode loops.\n *\n * Why not use MPU timestamps? Under FEC interleaving, encoders pack multiple\n * Access Units (AUs) per MMTP MPU with a single mpu_timestamp. The observed\n * timestamp delta between MPUs is a fraction of the real per-AU duration\n * (e.g. 10.22ms between MPUs for 21.33ms AAC frames at D=2 interleave).\n * Pacing on that delta sees \"media \u2248 wall\" and never sleeps, letting burst\n * relay delivery saturate the decoder / ring buffer.\n *\n * The Sony libatsc3 pattern (atsc3_mmt_context_mfu_depacketizer) solves this\n * by anchoring wall-clock time to the first received AU and counting AUs:\n * media_elapsed_ms = au_count \u00D7 nominal_au_duration_ms\n * The MPU timestamp is used elsewhere as an absolute-time anchor, never as\n * an incremental clock.\n *\n * The sleep threshold comes from the catalog's FEC interleaveDepthMs (via\n * FecBlockMapper.pacingThresholdMs). When no FEC is configured, a\n * NullBlockMapper yields threshold=0 and this pacer never sleeps.\n *\n * One pacer instance = one track (e.g. audio, video) on one player.\n */\n\nimport type { FecBlockMapper } from '@blockcast/mmt-fec'\n\nexport interface FrameCountPacerOpts {\n /** Required: AU duration (audio) or picture interval (video), in ms. */\n frameDurationMs: number\n /** FEC mapper from @blockcast/mmt-fec. NullBlockMapper disables pacing. */\n mapper: FecBlockMapper\n /**\n * Number of frames to let through before pacing starts. Lets startup\n * burst drain populate the ring buffer / decoder queue. Default 0.\n */\n warmupFrames?: number\n}\n\nexport interface PacerSnapshot {\n /** Frames observed (from notifyFrame). */\n frameCount: number\n /** Computed media time: frameCount \u00D7 frameDurationMs. */\n mediaMs: number\n /** Wall-clock time since anchor. */\n wallMs: number\n /** mediaMs - wallMs. Positive \u2192 decoder ahead of realtime. */\n aheadMs: number\n /** Pacing threshold (ms) from the FEC mapper. */\n thresholdMs: number\n /** Has the first frame been observed (wall anchor set)? */\n anchored: boolean\n}\n\nexport class FrameCountPacer {\n readonly frameDurationMs: number\n readonly thresholdMs: number\n readonly warmupFrames: number\n\n #frameCount = 0\n #anchorWallMs = 0\n #anchored = false\n\n constructor(opts: FrameCountPacerOpts) {\n if (!(opts.frameDurationMs > 0)) {\n throw new Error('frameDurationMs must be > 0')\n }\n this.frameDurationMs = opts.frameDurationMs\n this.thresholdMs = opts.mapper.pacingThresholdMs\n this.warmupFrames = Math.max(0, opts.warmupFrames ?? 0)\n }\n\n /** Call on every emitted decoded frame (AU or picture). Anchors on first call. */\n notifyFrame(): void {\n if (!this.#anchored) {\n this.#anchorWallMs = now()\n this.#anchored = true\n }\n this.#frameCount++\n }\n\n /**\n * Compute sleep ms before reading the next MoQ object.\n * Returns 0 when:\n * - pacing is disabled (NullBlockMapper \u2192 threshold=0)\n * - the anchor is not yet set\n * - still in warmup\n * - decoder is not ahead of wall clock by more than threshold\n * Otherwise returns aheadMs - thresholdMs/2 (leaves half the threshold as headroom).\n */\n computeSleepMs(): number {\n if (this.thresholdMs <= 0) return 0\n if (!this.#anchored) return 0\n if (this.#frameCount <= this.warmupFrames) return 0\n\n const mediaMs = this.#frameCount * this.frameDurationMs\n const wallMs = now() - this.#anchorWallMs\n const aheadMs = mediaMs - wallMs\n if (aheadMs <= this.thresholdMs) return 0\n return aheadMs - this.thresholdMs / 2\n }\n\n /** Reset anchor + counter. Call on source switch (MoQ \u2194 multicast). */\n reset(): void {\n this.#frameCount = 0\n this.#anchorWallMs = 0\n this.#anchored = false\n }\n\n get snapshot(): PacerSnapshot {\n const mediaMs = this.#frameCount * this.frameDurationMs\n const wallMs = this.#anchored ? now() - this.#anchorWallMs : 0\n return {\n frameCount: this.#frameCount,\n mediaMs,\n wallMs,\n aheadMs: mediaMs - wallMs,\n thresholdMs: this.thresholdMs,\n anchored: this.#anchored,\n }\n }\n}\n\nfunction now(): number {\n // performance.now() is available in main thread, workers, and AudioWorklet.\n // Fall back to Date.now() for exotic runtimes (shouldn't happen in browsers).\n if (typeof performance !== 'undefined' && typeof performance.now === 'function') {\n return performance.now()\n }\n return Date.now()\n}\n", "/**\n * Nominal Access Unit duration helpers for common audio + video codecs.\n *\n * Kept in the pacing subpath (no mmt-container dep) so lean consumers like\n * moqtail's player.ts can import the pacer + AU duration without pulling\n * in the full audio-render-pipeline (which depends on @blockcast/mmt-container).\n */\n\n/**\n * Nominal AU duration in ms for common audio codecs at the given sample rate.\n * AAC-LC: 1024 samples. Opus (default 20ms): 960 samples @ 48kHz.\n * Throws for unknown codecs so callers supply correct timing.\n */\nexport function auDurationMsFromCodec(codec: string, sampleRate: number): number {\n if (!(sampleRate > 0)) throw new Error('sampleRate must be > 0')\n if (codec.startsWith('opus') || codec.startsWith('Opus')) {\n return (960 / sampleRate) * 1000\n }\n if (codec.startsWith('mp4a') || codec.startsWith('AAC') || codec.startsWith('aac')) {\n return (1024 / sampleRate) * 1000\n }\n if (codec.startsWith('flac') || codec.startsWith('fLaC')) {\n return (4096 / sampleRate) * 1000\n }\n throw new Error(`unknown audio codec for AU duration derivation: ${codec}`)\n}\n\n/**\n * Nominal picture duration in ms from framerate.\n */\nexport function pictureDurationMs(framerate: number): number {\n if (!(framerate > 0)) throw new Error('framerate must be > 0')\n return 1000 / framerate\n}\n", "/**\n * Helper for loading the prebuilt AudioWorklet bundle.\n *\n * Two equivalent loading patterns supported:\n *\n * 1. Vite-style static URL (recommended for bundled apps):\n * import workletUrl from '@blockcast/mmt-render/audio/worklet.js?url'\n * await ctx.audioWorklet.addModule(workletUrl)\n * Vite resolves the `?url` suffix + the package's \"./audio/worklet.js\"\n * export to the prebuilt IIFE file.\n *\n * 2. Runtime import.meta.url resolution (no bundler):\n * import { workletModuleUrl } from '@blockcast/mmt-render/audio/worklet-url'\n * await ctx.audioWorklet.addModule(workletModuleUrl())\n *\n * Both resolve to dist/worklet/render-worklet.js.\n */\n\n/**\n * Returns a URL (or URL string) pointing to the prebuilt worklet bundle.\n * Resolves relative to this module's location via import.meta.url.\n */\nexport function workletModuleUrl(): string {\n // dist layout: dist/audio/worklet-url.js \u2192 dist/worklet/render-worklet.js\n const base = new URL('../worklet/render-worklet.js', import.meta.url)\n return base.href\n}\n\n/** Processor name registered in the worklet bundle. */\nexport const WORKLET_PROCESSOR_NAME = 'mmt-render'\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAmBA,SAAS,0BAAkD;;;ACnB3D;AAoDO,IAAM,kBAAN,MAAsB;AAAA,EAS3B,YAAY,MAA2B;AAJvC,oCAAc;AACd,sCAAgB;AAChB,kCAAY;AAGV,QAAI,EAAE,KAAK,kBAAkB,IAAI;AAC/B,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,SAAK,kBAAkB,KAAK;AAC5B,SAAK,cAAc,KAAK,OAAO;AAC/B,SAAK,eAAe,KAAK,IAAI,GAAG,KAAK,gBAAgB,CAAC;AAAA,EACxD;AAAA;AAAA,EAGA,cAAoB;AAClB,QAAI,CAAC,mBAAK,YAAW;AACnB,yBAAK,eAAgB,IAAI;AACzB,yBAAK,WAAY;AAAA,IACnB;AACA,2BAAK,aAAL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,iBAAyB;AACvB,QAAI,KAAK,eAAe,EAAG,QAAO;AAClC,QAAI,CAAC,mBAAK,WAAW,QAAO;AAC5B,QAAI,mBAAK,gBAAe,KAAK,aAAc,QAAO;AAElD,UAAM,UAAU,mBAAK,eAAc,KAAK;AACxC,UAAM,SAAS,IAAI,IAAI,mBAAK;AAC5B,UAAM,UAAU,UAAU;AAC1B,QAAI,WAAW,KAAK,YAAa,QAAO;AACxC,WAAO,UAAU,KAAK,cAAc;AAAA,EACtC;AAAA;AAAA,EAGA,QAAc;AACZ,uBAAK,aAAc;AACnB,uBAAK,eAAgB;AACrB,uB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AI;AAAA,EACvB;AACA,SAAO,MAAM;AAEb,QAAM,MAAmB;AAAA,IACvB,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACF;AACA,qBAAK,UAAS,KAAK,YAAY,KAAK,YAAY,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;AACtE;",
4
+ "sourcesContent": ["/**\n * AudioRenderPipeline \u2014 end-to-end audio render for MoQ/MMT players.\n *\n * Pipeline: MoQ object \u2192 MmtpDecodePipeline \u2192 WebCodecs AudioDecoder\n * \u2192 AudioWorkletNode (exact-timestamp FIFO)\n *\n * The consumer:\n * 1. constructs with codec/sampleRate/channels/mapper from catalog\n * 2. awaits ready()\n * 3. calls feedMoqObject(packet) for each arriving MoQ object\n * 4. between objects, awaits paceSleepMs() to throttle burst delivery\n * 5. connects rootNode to an AudioContext destination (or a GainNode)\n * 6. close() on teardown\n *\n * Pacing uses FrameCountPacer (anchor on first decoded AU, frame count \u00D7 AU\n * duration) with threshold = mapper.pacingThresholdMs \u2014 NOT MPU timestamps\n * (ambiguous under FEC interleave).\n */\n\nimport { MmtpDecodePipeline, type PipelineFecClient } from '@blockcast/mmt-container/mmtp-decode-pipeline'\nimport type { MfuReassemblyPolicy } from '@blockcast/mmt-container/mfu-reassembly-policy'\nimport type { FecBlockMapper } from '@blockcast/mmt-fec'\nimport { FrameCountPacer } from '../pacing/frame-pacer.js'\nimport { auDurationMsFromCodec } from '../pacing/au-duration.js'\nimport type {\n ToMain,\n DataMessage,\n InitMessage,\n ResetMessage,\n StartMessage,\n} from './render-messages.js'\nimport { WORKLET_PROCESSOR_NAME, workletModuleUrl } from './worklet-url.js'\n\nexport interface AudioRenderPipelineOpts {\n context: AudioContext\n codec: string\n /** MMTP packet_id for this audio track \u2014 from catalog. */\n packetId?: number\n sampleRate: number\n channels: number\n description?: Uint8Array\n mapper: FecBlockMapper\n fecClient?: PipelineFecClient\n /** Reliable MoQ is clock-free; datagram deadlines come from catalog/in-band timing. */\n reassemblyPolicy: MfuReassemblyPolicy\n /** Catalog-derived PCM startup buffer in milliseconds. */\n latencyMs: number\n /** Exact PCM startup threshold when catalog grouping is codec-aligned. */\n startupFrames?: number\n /** Exact PCM storage ceiling, including one successor delivery burst. */\n capacityFrames?: number\n /** Enable ring-buffer telemetry messages. Default false. */\n diag?: boolean\n /** Called when worklet reports state (playback timestamp + exact buffer accounting). Optional. */\n onState?: (state: {\n timestampUs: number | undefined\n stalled: boolean\n bufferedFrames: number\n writtenFrames: number\n }) => void\n /** Called when worklet reports ring-buffer diag (telemetry). Optional. */\n onDiag?: (diag: {\n reads: number; avgFill: number; capacity: number\n skipsPerSec: number; dupsPerSec: number; overflowSamplesPerSec: number\n underflowSamplesPerSec: number\n }) => void\n /** Warmup frames before pacing engages. Default 0 (audio tolerates instant pacing). */\n warmupFrames?: number\n /** Audio underflow / config event logger. Optional. */\n onError?: (err: unknown) => void\n}\n\nexport class AudioRenderPipeline {\n readonly #context: AudioContext\n readonly #pacer: FrameCountPacer\n readonly #mapper: FecBlockMapper\n readonly #codec: string\n readonly #packetId: number | undefined\n readonly #sampleRate: number\n readonly #channels: number\n readonly #description?: Uint8Array\n readonly #latencyMs: number\n readonly #startupFrames?: number\n readonly #startupThresholdFrames: number\n readonly #capacityFrames?: number\n readonly #diag: boolean\n readonly #warmupFrames: number\n readonly #onState?: AudioRenderPipelineOpts['onState']\n readonly #onDiag?: AudioRenderPipelineOpts['onDiag']\n readonly #onError?: AudioRenderPipelineOpts['onError']\n readonly #reassemblyPolicy: MfuReassemblyPolicy\n\n #decoder: AudioDecoder | null = null\n #pipeline: MmtpDecodePipeline | null = null\n #worklet: AudioWorkletNode | null = null\n #fecClient?: PipelineFecClient\n #closed = false\n #readyPromise: Promise<void> | null = null\n #workletGeneration = 0\n #startupReleased = false\n\n constructor(opts: AudioRenderPipelineOpts) {\n this.#context = opts.context\n this.#mapper = opts.mapper\n this.#codec = opts.codec\n this.#packetId = opts.packetId\n this.#sampleRate = opts.sampleRate\n this.#channels = opts.channels\n this.#description = opts.description\n this.#latencyMs = opts.latencyMs\n this.#startupFrames = opts.startupFrames\n this.#startupThresholdFrames = opts.startupFrames\n ?? Math.ceil(opts.sampleRate * (opts.latencyMs / 1000))\n this.#capacityFrames = opts.capacityFrames\n this.#diag = opts.diag ?? false\n this.#warmupFrames = opts.warmupFrames ?? 0\n this.#onState = opts.onState\n this.#onDiag = opts.onDiag\n this.#onError = opts.onError\n this.#fecClient = opts.fecClient\n this.#reassemblyPolicy = opts.reassemblyPolicy\n\n // AU duration from codec + sampleRate. Keep inside the lib so consumers\n // don't re-derive it.\n const auDurationMs = auDurationMsFromCodec(opts.codec, opts.sampleRate)\n this.#pacer = new FrameCountPacer({\n frameDurationMs: auDurationMs,\n mapper: opts.mapper,\n warmupFrames: this.#warmupFrames,\n })\n }\n\n /** Load worklet module + create decoder + pipeline. Call once. */\n async ready(): Promise<void> {\n if (this.#readyPromise) return this.#readyPromise\n this.#readyPromise = this.#initialize()\n return this.#readyPromise\n }\n\n async #initialize(): Promise<void> {\n // 1. Load shared worklet module.\n await this.#context.audioWorklet.addModule(workletModuleUrl())\n\n // 2. Create worklet node.\n const worklet = new AudioWorkletNode(this.#context, WORKLET_PROCESSOR_NAME, {\n numberOfInputs: 0,\n numberOfOutputs: 1,\n outputChannelCount: [this.#channels],\n })\n const initMsg: InitMessage = {\n type: 'init',\n generation: ++this.#workletGeneration,\n channels: this.#channels,\n rate: this.#sampleRate,\n latencyMs: this.#latencyMs,\n startupFrames: this.#startupFrames,\n capacityFrames: this.#capacityFrames,\n holdUntilStart: true,\n diag: this.#diag,\n }\n worklet.port.postMessage(initMsg)\n worklet.port.onmessage = (ev: MessageEvent<ToMain>) => {\n const m = ev.data\n if (m.type === 'state') {\n if (m.generation !== this.#workletGeneration) return\n this.#onState?.({\n timestampUs: m.timestamp,\n stalled: m.stalled,\n bufferedFrames: m.bufferedFrames,\n writtenFrames: m.writtenFrames,\n })\n } else if (m.type === 'ringBufDiag') {\n if (m.generation !== this.#workletGeneration) return\n this.#onDiag?.({\n reads: m.reads, avgFill: m.avgFill, capacity: m.capacity,\n skipsPerSec: m.skipsPerSec, dupsPerSec: m.dupsPerSec,\n overflowSamplesPerSec: m.overflowSamplesPerSec,\n underflowSamplesPerSec: m.underflowSamplesPerSec,\n })\n } else if (m.type === 'writeAck') {\n if (\n m.generation !== this.#workletGeneration ||\n this.#startupReleased ||\n m.bufferedFrames < this.#startupThresholdFrames\n ) return\n this.#startupReleased = true\n const start: StartMessage = {\n type: 'start',\n generation: this.#workletGeneration,\n }\n worklet.port.postMessage(start)\n }\n }\n this.#worklet = worklet\n\n // 3. Create decoder.\n const decoder = new AudioDecoder({\n output: (data) => this.#onDecoded(data),\n error: (err) => this.#onError?.(err),\n })\n const config: AudioDecoderConfig = {\n codec: this.#codec,\n sampleRate: this.#sampleRate,\n numberOfChannels: this.#channels,\n ...(this.#description ? { description: this.#description } : {}),\n }\n decoder.configure(config)\n this.#decoder = decoder\n\n // 4. Create decode pipeline.\n const pipeline = new MmtpDecodePipeline()\n pipeline.configure({\n codec: this.#codec,\n packetId: this.#packetId,\n description: this.#description,\n reorderWindow: 0, // audio doesn't need reorder \u2014 AAC/Opus frames are self-contained\n reassemblyPolicy: this.#reassemblyPolicy,\n })\n if (this.#fecClient) pipeline.setFecClient(this.#fecClient)\n pipeline.onFrame((codecData, meta) => {\n if (!this.#decoder || this.#decoder.state !== 'configured') return\n if (codecData.byteLength === 0) return\n this.#pacer.notifyFrame()\n try {\n this.#decoder.decode(new EncodedAudioChunk({\n type: 'key',\n data: codecData,\n timestamp: meta.timestamp,\n }))\n } catch (err) {\n this.#onError?.(err)\n }\n })\n this.#pipeline = pipeline\n }\n\n /** Feed one MoQ object (raw MMTP packet). */\n feedMoqObject(packet: Uint8Array): void {\n this.#pipeline?.feedMoqObject(packet)\n }\n\n /** ms to sleep before the next object read. 0 when not anchored / not ahead. */\n paceSleepMs(): number {\n return this.#pacer.computeSleepMs()\n }\n\n /** Pacer snapshot (for diagnostics / UI). */\n get pacerSnapshot() {\n return this.#pacer.snapshot\n }\n\n /** Reset pacer on source switch (MoQ \u2194 multicast). */\n resetPacer(): void {\n this.#pacer.reset()\n }\n\n /** Drop queued PCM and its timestamp epoch at an explicit source boundary. */\n resetPlayout(startUnstalled = false): void {\n this.#pacer.reset()\n // The explicit gate owns only the initial prefill. Source-boundary resets\n // use the worklet's one-frame resume threshold.\n this.#startupReleased = true\n const message: ResetMessage = {\n type: 'reset',\n generation: ++this.#workletGeneration,\n startUnstalled,\n }\n this.#worklet?.port.postMessage(message)\n }\n\n /** Node to connect to destination / gain. */\n get rootNode(): AudioNode {\n if (!this.#worklet) throw new Error('AudioRenderPipeline.ready() must resolve first')\n return this.#worklet\n }\n\n close(): void {\n if (this.#closed) return\n this.#closed = true\n try { this.#decoder?.close() } catch { /* already closed */ }\n try { this.#pipeline?.dispose() } catch { /* noop */ }\n try { this.#worklet?.disconnect() } catch { /* noop */ }\n this.#decoder = null\n this.#pipeline = null\n this.#worklet = null\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n #onDecoded(sample: AudioData): void {\n if (this.#closed || !this.#worklet) { sample.close(); return }\n\n const timestamp = sample.timestamp\n const channelData: Float32Array[] = []\n for (let ch = 0; ch < sample.numberOfChannels; ch++) {\n const data = new Float32Array(sample.numberOfFrames)\n sample.copyTo(data, { format: 'f32-planar', planeIndex: ch })\n channelData.push(data)\n }\n sample.close()\n\n const msg: DataMessage = {\n type: 'data',\n data: channelData,\n timestamp,\n }\n this.#worklet.port.postMessage(msg, channelData.map((d) => d.buffer))\n }\n}\n\n// auDurationMsFromCodec lives in ../pacing/au-duration.ts (canonical, no\n// mmt-container dep). Import it from '@blockcast/mmt-render/pacing' directly\n// or via the top-level '@blockcast/mmt-render' export.\n", "/**\n * FrameCountPacer \u2014 media-agnostic wall-clock pacer for MMT A/V decode loops.\n *\n * Why not use MPU timestamps? Under FEC interleaving, encoders pack multiple\n * Access Units (AUs) per MMTP MPU with a single mpu_timestamp. The observed\n * timestamp delta between MPUs is a fraction of the real per-AU duration\n * (e.g. 10.22ms between MPUs for 21.33ms AAC frames at D=2 interleave).\n * Pacing on that delta sees \"media \u2248 wall\" and never sleeps, letting burst\n * relay delivery saturate the decoder / ring buffer.\n *\n * The Sony libatsc3 pattern (atsc3_mmt_context_mfu_depacketizer) solves this\n * by anchoring wall-clock time to the first received AU and counting AUs:\n * media_elapsed_ms = au_count \u00D7 nominal_au_duration_ms\n * The MPU timestamp is used elsewhere as an absolute-time anchor, never as\n * an incremental clock.\n *\n * The sleep threshold comes from the catalog's FEC interleaveDepthMs (via\n * FecBlockMapper.pacingThresholdMs). When no FEC is configured, a\n * NullBlockMapper yields threshold=0 and this pacer never sleeps.\n *\n * One pacer instance = one track (e.g. audio, video) on one player.\n */\n\nimport type { FecBlockMapper } from '@blockcast/mmt-fec'\n\nexport interface FrameCountPacerOpts {\n /** Required: AU duration (audio) or picture interval (video), in ms. */\n frameDurationMs: number\n /** FEC mapper from @blockcast/mmt-fec. NullBlockMapper disables pacing. */\n mapper: FecBlockMapper\n /**\n * Number of frames to let through before pacing starts. Lets startup\n * burst drain populate the ring buffer / decoder queue. Default 0.\n */\n warmupFrames?: number\n}\n\nexport interface PacerSnapshot {\n /** Frames observed (from notifyFrame). */\n frameCount: number\n /** Computed media time: frameCount \u00D7 frameDurationMs. */\n mediaMs: number\n /** Wall-clock time since anchor. */\n wallMs: number\n /** mediaMs - wallMs. Positive \u2192 decoder ahead of realtime. */\n aheadMs: number\n /** Pacing threshold (ms) from the FEC mapper. */\n thresholdMs: number\n /** Has the first frame been observed (wall anchor set)? */\n anchored: boolean\n}\n\nexport class FrameCountPacer {\n readonly frameDurationMs: number\n readonly thresholdMs: number\n readonly warmupFrames: number\n\n #frameCount = 0\n #anchorWallMs = 0\n #anchored = false\n\n constructor(opts: FrameCountPacerOpts) {\n if (!(opts.frameDurationMs > 0)) {\n throw new Error('frameDurationMs must be > 0')\n }\n this.frameDurationMs = opts.frameDurationMs\n this.thresholdMs = opts.mapper.pacingThresholdMs\n this.warmupFrames = Math.max(0, opts.warmupFrames ?? 0)\n }\n\n /** Call on every emitted decoded frame (AU or picture). Anchors on first call. */\n notifyFrame(): void {\n if (!this.#anchored) {\n this.#anchorWallMs = now()\n this.#anchored = true\n }\n this.#frameCount++\n }\n\n /**\n * Compute sleep ms before reading the next MoQ object.\n * Returns 0 when:\n * - pacing is disabled (NullBlockMapper \u2192 threshold=0)\n * - the anchor is not yet set\n * - still in warmup\n * - the caller reports a standing backlog (see `observedDelayMs`)\n * - decoder is not ahead of wall clock by more than threshold\n * Otherwise returns aheadMs - thresholdMs/2 (leaves half the threshold as headroom).\n *\n * `observedDelayMs` is how far this frame is behind the producer's own clock,\n * measured by the caller against a producer-supplied sending instant (for\n * MMTP, the header send-wall timestamp). It is optional because the anchored\n * rate below is blind to it: `#anchorWallMs` is the wall time of the FIRST\n * frame read, so `aheadMs` measures consumption against the join instant and\n * not against the producer. Once `aheadMs` reaches the threshold the loop\n * consumes at exactly the source rate, and recovering latency present at join\n * requires consuming FASTER than the source rate. So without this argument a\n * consumer that joined a live stream mid-block keeps that join latency for the\n * life of the subscription.\n *\n * A caller that can measure the real distance from the producer passes it and\n * gets a drain: while the backlog exceeds the threshold there is nothing to\n * pace against, so return 0 and let the transport set the rate. At the live\n * edge the anchored-rate behavior below applies unchanged.\n *\n * Callers with no producer clock omit it and keep the pure ATSC3-style\n * anchored pacing (see the class doc), where a first-frame anchor is correct\n * because a broadcast push has no live edge to catch up to.\n */\n computeSleepMs(observedDelayMs?: number): number {\n if (this.thresholdMs <= 0) return 0\n if (!this.#anchored) return 0\n if (this.#frameCount <= this.warmupFrames) return 0\n // Only a finite measurement can license the drain. NaN/Infinity mean the\n // caller could not measure the distance, which is not the same claim as\n // \"the consumer is at the edge\", so fall through to anchored pacing.\n if (observedDelayMs !== undefined && Number.isFinite(observedDelayMs) && observedDelayMs > this.thresholdMs) {\n return 0\n }\n\n const mediaMs = this.#frameCount * this.frameDurationMs\n const wallMs = now() - this.#anchorWallMs\n const aheadMs = mediaMs - wallMs\n if (aheadMs <= this.thresholdMs) return 0\n return aheadMs - this.thresholdMs / 2\n }\n\n /** Reset anchor + counter. Call on source switch (MoQ \u2194 multicast). */\n reset(): void {\n this.#frameCount = 0\n this.#anchorWallMs = 0\n this.#anchored = false\n }\n\n get snapshot(): PacerSnapshot {\n const mediaMs = this.#frameCount * this.frameDurationMs\n const wallMs = this.#anchored ? now() - this.#anchorWallMs : 0\n return {\n frameCount: this.#frameCount,\n mediaMs,\n wallMs,\n aheadMs: mediaMs - wallMs,\n thresholdMs: this.thresholdMs,\n anchored: this.#anchored,\n }\n }\n}\n\nfunction now(): number {\n // performance.now() is available in main thread, workers, and AudioWorklet.\n // Fall back to Date.now() for exotic runtimes (shouldn't happen in browsers).\n if (typeof performance !== 'undefined' && typeof performance.now === 'function') {\n return performance.now()\n }\n return Date.now()\n}\n", "/**\n * Nominal Access Unit duration helpers for common audio + video codecs.\n *\n * Kept in the pacing subpath (no mmt-container dep) so lean consumers like\n * moqtail's player.ts can import the pacer + AU duration without pulling\n * in the full audio-render-pipeline (which depends on @blockcast/mmt-container).\n */\n\n/**\n * Nominal AU duration in ms for common audio codecs at the given sample rate.\n * AAC-LC: 1024 samples. Opus (default 20ms): 960 samples @ 48kHz.\n * Throws for unknown codecs so callers supply correct timing.\n */\nexport function auDurationMsFromCodec(codec: string, sampleRate: number): number {\n if (!(sampleRate > 0)) throw new Error('sampleRate must be > 0')\n if (codec.startsWith('opus') || codec.startsWith('Opus')) {\n return (960 / sampleRate) * 1000\n }\n if (codec.startsWith('mp4a') || codec.startsWith('AAC') || codec.startsWith('aac')) {\n return (1024 / sampleRate) * 1000\n }\n if (codec.startsWith('flac') || codec.startsWith('fLaC')) {\n return (4096 / sampleRate) * 1000\n }\n throw new Error(`unknown audio codec for AU duration derivation: ${codec}`)\n}\n\n/**\n * Nominal picture duration in ms from framerate.\n */\nexport function pictureDurationMs(framerate: number): number {\n if (!(framerate > 0)) throw new Error('framerate must be > 0')\n return 1000 / framerate\n}\n", "/**\n * Helper for loading the prebuilt AudioWorklet bundle.\n *\n * Two equivalent loading patterns supported:\n *\n * 1. Vite-style static URL (recommended for bundled apps):\n * import workletUrl from '@blockcast/mmt-render/audio/worklet.js?url'\n * await ctx.audioWorklet.addModule(workletUrl)\n * Vite resolves the `?url` suffix + the package's \"./audio/worklet.js\"\n * export to the prebuilt IIFE file.\n *\n * 2. Runtime import.meta.url resolution (no bundler):\n * import { workletModuleUrl } from '@blockcast/mmt-render/audio/worklet-url'\n * await ctx.audioWorklet.addModule(workletModuleUrl())\n *\n * Both resolve to dist/worklet/render-worklet.js.\n */\n\n/**\n * Returns a URL (or URL string) pointing to the prebuilt worklet bundle.\n * Resolves relative to this module's location via import.meta.url.\n */\nexport function workletModuleUrl(): string {\n // dist layout: dist/audio/worklet-url.js \u2192 dist/worklet/render-worklet.js\n const base = new URL('../worklet/render-worklet.js', import.meta.url)\n return base.href\n}\n\n/** Processor name registered in the worklet bundle. */\nexport const WORKLET_PROCESSOR_NAME = 'mmt-render'\n"],
5
+ "mappings": ";AAmBA,SAAS,0BAAkD;;;ACiCpD,IAAM,kBAAN,MAAsB;AAAA,EAK3B,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,YAAY;AAAA,EAEZ,YAAY,MAA2B;AACrC,QAAI,EAAE,KAAK,kBAAkB,IAAI;AAC/B,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,SAAK,kBAAkB,KAAK;AAC5B,SAAK,cAAc,KAAK,OAAO;AAC/B,SAAK,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D,QAAI;AAAE,WAAK,WAAW,QAAQ;AAAA,IAAE,QAAQ;AAAA,IAAa;AACrD,QAAI;AAAE,WAAK,UAAU,WAAW;AAAA,IAAE,QAAQ;AAAA,IAAa;AACvD,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA,EAIA,WAAW,QAAyB;AAClC,QAAI,KAAK,WAAW,CAAC,KAAK,UAAU;AAAE,aAAO,MAAM;AAAG;AAAA,IAAO;AAE7D,UAAM,YAAY,OAAO;AACzB,UAAM,cAA8B,CAAC;AACrC,aAAS,KAAK,GAAG,KAAK,OAAO,kBAAkB,MAAM;AACnD,YAAM,OAAO,IAAI,aAAa,OAAO,cAAc;AACnD,aAAO,OAAO,MAAM,EAAE,QAAQ,cAAc,YAAY,GAAG,CAAC;AAC5D,kBAAY,KAAK,IAAI;AAAA,IACvB;AACA,WAAO,MAAM;AAEb,UAAM,MAAmB;AAAA,MACvB,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,IACF;AACA,SAAK,SAAS,KAAK,YAAY,KAAK,YAAY,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;AAAA,EACtE;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,39 +1,20 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- var __privateWrapper = (obj, member, setter, getter) => ({
10
- set _(value) {
11
- __privateSet(obj, member, value, setter);
12
- },
13
- get _() {
14
- return __privateGet(obj, member, getter);
15
- }
16
- });
17
-
18
1
  // src/audio/audio-ring-buffer.ts
19
- var _buffer, _writeIndex, _readIndex, _stalled, _startupFrames, _resumeFrames, _resumeFollowsStartup, _hasStarted, _capacityHeadroomFrames, _timestampAnchors, _diagEnabled, _diagReads, _diagFillSum, _diagOverflowSamples, _AudioRingBuffer_instances, pruneTimestampAnchors_fn, refillFrames_fn;
20
2
  var AudioRingBuffer = class {
3
+ #buffer;
4
+ #writeIndex = 0;
5
+ #readIndex = 0;
6
+ #stalled;
7
+ #startupFrames;
8
+ #resumeFrames;
9
+ #resumeFollowsStartup;
10
+ #hasStarted;
11
+ #capacityHeadroomFrames;
12
+ #timestampAnchors = [];
13
+ #diagEnabled;
14
+ #diagReads = 0;
15
+ #diagFillSum = 0;
16
+ #diagOverflowSamples = 0;
21
17
  constructor(config) {
22
- __privateAdd(this, _AudioRingBuffer_instances);
23
- __privateAdd(this, _buffer);
24
- __privateAdd(this, _writeIndex, 0);
25
- __privateAdd(this, _readIndex, 0);
26
- __privateAdd(this, _stalled);
27
- __privateAdd(this, _startupFrames);
28
- __privateAdd(this, _resumeFrames);
29
- __privateAdd(this, _resumeFollowsStartup);
30
- __privateAdd(this, _hasStarted);
31
- __privateAdd(this, _capacityHeadroomFrames);
32
- __privateAdd(this, _timestampAnchors, []);
33
- __privateAdd(this, _diagEnabled);
34
- __privateAdd(this, _diagReads, 0);
35
- __privateAdd(this, _diagFillSum, 0);
36
- __privateAdd(this, _diagOverflowSamples, 0);
37
18
  if (!Number.isInteger(config.channels) || config.channels <= 0) {
38
19
  throw new Error("invalid channels");
39
20
  }
@@ -59,35 +40,35 @@ var AudioRingBuffer = class {
59
40
  }
60
41
  this.channels = config.channels;
61
42
  this.rate = config.rate;
62
- __privateSet(this, _startupFrames, startupFrames);
63
- __privateSet(this, _resumeFrames, resumeFrames);
64
- __privateSet(this, _resumeFollowsStartup, config.resumeFrames === void 0);
65
- __privateSet(this, _hasStarted, config.startUnstalled ?? false);
66
- __privateSet(this, _capacityHeadroomFrames, capacityFrames - thresholdFrames);
67
- __privateSet(this, _stalled, !(config.startUnstalled ?? false));
68
- __privateSet(this, _diagEnabled, config.diag ?? false);
69
- __privateSet(this, _buffer, Array.from(
43
+ this.#startupFrames = startupFrames;
44
+ this.#resumeFrames = resumeFrames;
45
+ this.#resumeFollowsStartup = config.resumeFrames === void 0;
46
+ this.#hasStarted = config.startUnstalled ?? false;
47
+ this.#capacityHeadroomFrames = capacityFrames - thresholdFrames;
48
+ this.#stalled = !(config.startUnstalled ?? false);
49
+ this.#diagEnabled = config.diag ?? false;
50
+ this.#buffer = Array.from(
70
51
  { length: config.channels },
71
52
  () => new Float32Array(capacityFrames)
72
- ));
53
+ );
73
54
  }
74
55
  get stalled() {
75
- return __privateGet(this, _stalled);
56
+ return this.#stalled;
76
57
  }
77
58
  get startupFrames() {
78
- return __privateGet(this, _startupFrames);
59
+ return this.#startupFrames;
79
60
  }
80
61
  get capacity() {
81
- return __privateGet(this, _buffer)[0].length;
62
+ return this.#buffer[0].length;
82
63
  }
83
64
  get length() {
84
- return __privateGet(this, _writeIndex) - __privateGet(this, _readIndex);
65
+ return this.#writeIndex - this.#readIndex;
85
66
  }
86
67
  /** Timestamp of the next media sample after the PCM already emitted. */
87
68
  get timestampUs() {
88
- const anchor = __privateGet(this, _timestampAnchors)[0];
89
- if (!anchor || anchor.sampleIndex > __privateGet(this, _readIndex)) return void 0;
90
- return anchor.timestampUs + (__privateGet(this, _readIndex) - anchor.sampleIndex) / this.rate * 1e6;
69
+ const anchor = this.#timestampAnchors[0];
70
+ if (!anchor || anchor.sampleIndex > this.#readIndex) return void 0;
71
+ return anchor.timestampUs + (this.#readIndex - anchor.sampleIndex) / this.rate * 1e6;
91
72
  }
92
73
  write(timestampUs, data) {
93
74
  if (data.length !== this.channels) throw new Error("wrong channel count");
@@ -97,68 +78,68 @@ var AudioRingBuffer = class {
97
78
  if (data.some((channel) => channel.length !== samples)) {
98
79
  throw new Error("mismatched channel lengths");
99
80
  }
100
- const start = __privateGet(this, _writeIndex);
81
+ const start = this.#writeIndex;
101
82
  const end = start + samples;
102
- __privateGet(this, _timestampAnchors).push({ sampleIndex: start, timestampUs });
103
- const overflow = end - __privateGet(this, _readIndex) - this.capacity;
83
+ this.#timestampAnchors.push({ sampleIndex: start, timestampUs });
84
+ const overflow = end - this.#readIndex - this.capacity;
104
85
  if (overflow > 0) {
105
- __privateSet(this, _stalled, false);
106
- __privateSet(this, _hasStarted, true);
107
- __privateSet(this, _readIndex, __privateGet(this, _readIndex) + overflow);
108
- if (__privateGet(this, _diagEnabled)) __privateSet(this, _diagOverflowSamples, __privateGet(this, _diagOverflowSamples) + overflow);
109
- __privateMethod(this, _AudioRingBuffer_instances, pruneTimestampAnchors_fn).call(this);
86
+ this.#stalled = false;
87
+ this.#hasStarted = true;
88
+ this.#readIndex += overflow;
89
+ if (this.#diagEnabled) this.#diagOverflowSamples += overflow;
90
+ this.#pruneTimestampAnchors();
110
91
  }
111
- const refillFrames = __privateGet(this, _hasStarted) ? __privateGet(this, _resumeFrames) : __privateGet(this, _startupFrames);
112
- if (__privateGet(this, _stalled) && end - __privateGet(this, _readIndex) >= refillFrames) {
113
- __privateSet(this, _stalled, false);
114
- __privateSet(this, _hasStarted, true);
92
+ const refillFrames = this.#hasStarted ? this.#resumeFrames : this.#startupFrames;
93
+ if (this.#stalled && end - this.#readIndex >= refillFrames) {
94
+ this.#stalled = false;
95
+ this.#hasStarted = true;
115
96
  }
116
97
  for (let channel = 0; channel < this.channels; channel++) {
117
98
  const src = data[channel];
118
- const dst = __privateGet(this, _buffer)[channel];
99
+ const dst = this.#buffer[channel];
119
100
  for (let i = 0; i < samples; i++) {
120
101
  dst[(start + i) % dst.length] = src[i];
121
102
  }
122
103
  }
123
- __privateSet(this, _writeIndex, end);
104
+ this.#writeIndex = end;
124
105
  }
125
106
  read(output) {
126
107
  if (output.length !== this.channels) throw new Error("wrong channel count");
127
- if (__privateGet(this, _stalled)) return 0;
108
+ if (this.#stalled) return 0;
128
109
  const available = this.length;
129
110
  if (available === 0) {
130
- __privateSet(this, _stalled, true);
111
+ this.#stalled = true;
131
112
  return 0;
132
113
  }
133
114
  const requested = output[0].length;
134
115
  const readSamples = Math.min(available, requested);
135
116
  for (let channel = 0; channel < this.channels; channel++) {
136
117
  const dst = output[channel];
137
- const src = __privateGet(this, _buffer)[channel];
118
+ const src = this.#buffer[channel];
138
119
  for (let i = 0; i < readSamples; i++) {
139
- dst[i] = src[(__privateGet(this, _readIndex) + i) % src.length];
120
+ dst[i] = src[(this.#readIndex + i) % src.length];
140
121
  }
141
122
  for (let i = readSamples; i < requested; i++) dst[i] = 0;
142
123
  }
143
- __privateSet(this, _readIndex, __privateGet(this, _readIndex) + readSamples);
144
- __privateMethod(this, _AudioRingBuffer_instances, pruneTimestampAnchors_fn).call(this);
145
- if (readSamples < requested) __privateSet(this, _stalled, true);
146
- if (__privateGet(this, _diagEnabled)) {
147
- __privateWrapper(this, _diagReads)._++;
148
- __privateSet(this, _diagFillSum, __privateGet(this, _diagFillSum) + available);
124
+ this.#readIndex += readSamples;
125
+ this.#pruneTimestampAnchors();
126
+ if (readSamples < requested) this.#stalled = true;
127
+ if (this.#diagEnabled) {
128
+ this.#diagReads++;
129
+ this.#diagFillSum += available;
149
130
  }
150
131
  return readSamples;
151
132
  }
152
133
  /** Clear queued PCM; optionally treat the next fill as post-start recovery. */
153
134
  reset(startUnstalled = false, resumeAfterReset = false) {
154
- __privateSet(this, _writeIndex, 0);
155
- __privateSet(this, _readIndex, 0);
156
- __privateSet(this, _stalled, !startUnstalled);
157
- __privateSet(this, _hasStarted, startUnstalled || resumeAfterReset);
158
- __privateSet(this, _timestampAnchors, []);
159
- __privateSet(this, _diagReads, 0);
160
- __privateSet(this, _diagFillSum, 0);
161
- __privateSet(this, _diagOverflowSamples, 0);
135
+ this.#writeIndex = 0;
136
+ this.#readIndex = 0;
137
+ this.#stalled = !startUnstalled;
138
+ this.#hasStarted = startUnstalled || resumeAfterReset;
139
+ this.#timestampAnchors = [];
140
+ this.#diagReads = 0;
141
+ this.#diagFillSum = 0;
142
+ this.#diagOverflowSamples = 0;
162
143
  }
163
144
  /**
164
145
  * Change the startup latency while preserving the configured storage
@@ -173,18 +154,18 @@ var AudioRingBuffer = class {
173
154
  if (!Number.isSafeInteger(newStartupFrames) || newStartupFrames <= 0) {
174
155
  throw new Error("invalid latency");
175
156
  }
176
- const newResumeFrames = __privateGet(this, _resumeFollowsStartup) ? newStartupFrames : __privateGet(this, _resumeFrames);
177
- const newCapacity = Math.max(newStartupFrames, newResumeFrames) + __privateGet(this, _capacityHeadroomFrames);
157
+ const newResumeFrames = this.#resumeFollowsStartup ? newStartupFrames : this.#resumeFrames;
158
+ const newCapacity = Math.max(newStartupFrames, newResumeFrames) + this.#capacityHeadroomFrames;
178
159
  if (!Number.isSafeInteger(newCapacity) || newCapacity < Math.max(newStartupFrames, newResumeFrames)) {
179
160
  throw new Error("invalid capacity frames");
180
161
  }
181
- const wasStalled = __privateGet(this, _stalled);
182
- __privateSet(this, _startupFrames, newStartupFrames);
183
- __privateSet(this, _resumeFrames, newResumeFrames);
162
+ const wasStalled = this.#stalled;
163
+ this.#startupFrames = newStartupFrames;
164
+ this.#resumeFrames = newResumeFrames;
184
165
  if (newCapacity === this.capacity) {
185
- if (wasStalled && this.length >= __privateMethod(this, _AudioRingBuffer_instances, refillFrames_fn).call(this)) {
186
- __privateSet(this, _stalled, false);
187
- __privateSet(this, _hasStarted, true);
166
+ if (wasStalled && this.length >= this.#refillFrames()) {
167
+ this.#stalled = false;
168
+ this.#hasStarted = true;
188
169
  }
189
170
  return;
190
171
  }
@@ -193,61 +174,46 @@ var AudioRingBuffer = class {
193
174
  () => new Float32Array(newCapacity)
194
175
  );
195
176
  const samplesToKeep = Math.min(this.length, newCapacity);
196
- const copyStart = __privateGet(this, _writeIndex) - samplesToKeep;
177
+ const copyStart = this.#writeIndex - samplesToKeep;
197
178
  for (let channel = 0; channel < this.channels; channel++) {
198
- const src = __privateGet(this, _buffer)[channel];
179
+ const src = this.#buffer[channel];
199
180
  const dst = next[channel];
200
181
  for (let i = 0; i < samplesToKeep; i++) {
201
182
  const sampleIndex = copyStart + i;
202
183
  dst[sampleIndex % dst.length] = src[sampleIndex % src.length];
203
184
  }
204
185
  }
205
- __privateSet(this, _buffer, next);
206
- __privateSet(this, _readIndex, copyStart);
207
- __privateMethod(this, _AudioRingBuffer_instances, pruneTimestampAnchors_fn).call(this);
208
- __privateSet(this, _stalled, samplesToKeep === 0 || wasStalled && samplesToKeep < __privateMethod(this, _AudioRingBuffer_instances, refillFrames_fn).call(this));
209
- if (!__privateGet(this, _stalled)) __privateSet(this, _hasStarted, true);
186
+ this.#buffer = next;
187
+ this.#readIndex = copyStart;
188
+ this.#pruneTimestampAnchors();
189
+ this.#stalled = samplesToKeep === 0 || wasStalled && samplesToKeep < this.#refillFrames();
190
+ if (!this.#stalled) this.#hasStarted = true;
210
191
  }
211
192
  getDiagAndReset() {
212
- if (!__privateGet(this, _diagEnabled) || __privateGet(this, _diagReads) === 0) return null;
193
+ if (!this.#diagEnabled || this.#diagReads === 0) return null;
213
194
  const result = {
214
- reads: __privateGet(this, _diagReads),
215
- avgFill: Math.round(__privateGet(this, _diagFillSum) / __privateGet(this, _diagReads)),
195
+ reads: this.#diagReads,
196
+ avgFill: Math.round(this.#diagFillSum / this.#diagReads),
216
197
  capacity: this.capacity,
217
198
  skips: 0,
218
199
  dups: 0,
219
- overflowSamples: __privateGet(this, _diagOverflowSamples)
200
+ overflowSamples: this.#diagOverflowSamples
220
201
  };
221
- __privateSet(this, _diagReads, 0);
222
- __privateSet(this, _diagFillSum, 0);
223
- __privateSet(this, _diagOverflowSamples, 0);
202
+ this.#diagReads = 0;
203
+ this.#diagFillSum = 0;
204
+ this.#diagOverflowSamples = 0;
224
205
  return result;
225
206
  }
226
- };
227
- _buffer = new WeakMap();
228
- _writeIndex = new WeakMap();
229
- _readIndex = new WeakMap();
230
- _stalled = new WeakMap();
231
- _startupFrames = new WeakMap();
232
- _resumeFrames = new WeakMap();
233
- _resumeFollowsStartup = new WeakMap();
234
- _hasStarted = new WeakMap();
235
- _capacityHeadroomFrames = new WeakMap();
236
- _timestampAnchors = new WeakMap();
237
- _diagEnabled = new WeakMap();
238
- _diagReads = new WeakMap();
239
- _diagFillSum = new WeakMap();
240
- _diagOverflowSamples = new WeakMap();
241
- _AudioRingBuffer_instances = new WeakSet();
242
- pruneTimestampAnchors_fn = function() {
243
- let keep = 0;
244
- while (keep + 1 < __privateGet(this, _timestampAnchors).length && __privateGet(this, _timestampAnchors)[keep + 1].sampleIndex <= __privateGet(this, _readIndex)) {
245
- keep++;
207
+ #pruneTimestampAnchors() {
208
+ let keep = 0;
209
+ while (keep + 1 < this.#timestampAnchors.length && this.#timestampAnchors[keep + 1].sampleIndex <= this.#readIndex) {
210
+ keep++;
211
+ }
212
+ if (keep > 0) this.#timestampAnchors.splice(0, keep);
213
+ }
214
+ #refillFrames() {
215
+ return this.#hasStarted ? this.#resumeFrames : this.#startupFrames;
246
216
  }
247
- if (keep > 0) __privateGet(this, _timestampAnchors).splice(0, keep);
248
- };
249
- refillFrames_fn = function() {
250
- return __privateGet(this, _hasStarted) ? __privateGet(this, _resumeFrames) : __privateGet(this, _startupFrames);
251
217
  };
252
218
  export {
253
219
  AudioRingBuffer
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/audio/audio-ring-buffer.ts"],
4
4
  "sourcesContent": ["/**\n * Timestamp-anchored FIFO shared by MMT AudioWorklet consumers.\n *\n * PCM remains in decoder emission order. Media timestamps are exact anchors\n * for playout reporting only; they never reposition samples or trigger a\n * guessed discontinuity. The FIFO starts after its full catalog-derived\n * latency is buffered and performs no sample skip/dup clock recovery.\n */\n\nexport interface AudioRingBufferConfig {\n channels: number\n rate: number\n latencyMs: number\n /** Exact PCM startup threshold. Overrides latencyMs when provided. */\n startupFrames?: number\n /** PCM refill threshold after the first underrun. Defaults to startupFrames. */\n resumeFrames?: number\n /** Exact PCM storage ceiling. Must cover the startup and resume thresholds. */\n capacityFrames?: number\n startUnstalled?: boolean\n /** Deprecated compatibility input. Clock recovery is not performed. */\n warmupReads?: number\n diag?: boolean\n}\n\nexport interface AudioRingBufferDiag {\n reads: number\n avgFill: number\n capacity: number\n skips: number\n dups: number\n overflowSamples: number\n}\n\ntype TimestampAnchor = {\n sampleIndex: number\n timestampUs: number\n}\n\nexport class AudioRingBuffer {\n readonly channels: number\n readonly rate: number\n\n #buffer: Float32Array[]\n #writeIndex = 0\n #readIndex = 0\n #stalled: boolean\n #startupFrames: number\n #resumeFrames: number\n #resumeFollowsStartup: boolean\n #hasStarted: boolean\n #capacityHeadroomFrames: number\n #timestampAnchors: TimestampAnchor[] = []\n\n #diagEnabled: boolean\n #diagReads = 0\n #diagFillSum = 0\n #diagOverflowSamples = 0\n\n constructor(config: AudioRingBufferConfig) {\n if (!Number.isInteger(config.channels) || config.channels <= 0) {\n throw new Error('invalid channels')\n }\n if (!Number.isFinite(config.rate) || config.rate <= 0) {\n throw new Error('invalid sample rate')\n }\n if (!Number.isFinite(config.latencyMs) || config.latencyMs <= 0) {\n throw new Error('invalid latency')\n }\n\n const latencyFrames = Math.ceil(config.rate * (config.latencyMs / 1000))\n const startupFrames = config.startupFrames ?? latencyFrames\n const resumeFrames = config.resumeFrames ?? startupFrames\n const thresholdFrames = Math.max(startupFrames, resumeFrames)\n const capacityFrames = config.capacityFrames ?? Math.max(latencyFrames, thresholdFrames)\n if (!Number.isSafeInteger(startupFrames) || startupFrames <= 0) {\n throw new Error('invalid startup frames')\n }\n if (!Number.isSafeInteger(resumeFrames) || resumeFrames <= 0) {\n throw new Error('invalid resume frames')\n }\n if (!Number.isSafeInteger(capacityFrames) || capacityFrames < thresholdFrames) {\n throw new Error('invalid capacity frames')\n }\n\n this.channels = config.channels\n this.rate = config.rate\n this.#startupFrames = startupFrames\n this.#resumeFrames = resumeFrames\n this.#resumeFollowsStartup = config.resumeFrames === undefined\n this.#hasStarted = config.startUnstalled ?? false\n this.#capacityHeadroomFrames = capacityFrames - thresholdFrames\n this.#stalled = !(config.startUnstalled ?? false)\n this.#diagEnabled = config.diag ?? false\n this.#buffer = Array.from(\n { length: config.channels },\n () => new Float32Array(capacityFrames),\n )\n }\n\n get stalled(): boolean { return this.#stalled }\n get startupFrames(): number { return this.#startupFrames }\n get capacity(): number { return this.#buffer[0].length }\n get length(): number { return this.#writeIndex - this.#readIndex }\n\n /** Timestamp of the next media sample after the PCM already emitted. */\n get timestampUs(): number | undefined {\n const anchor = this.#timestampAnchors[0]\n if (!anchor || anchor.sampleIndex > this.#readIndex) return undefined\n return anchor.timestampUs + ((this.#readIndex - anchor.sampleIndex) / this.rate) * 1_000_000\n }\n\n write(timestampUs: number, data: Float32Array[]): void {\n if (data.length !== this.channels) throw new Error('wrong channel count')\n if (!Number.isFinite(timestampUs)) throw new Error('invalid timestamp')\n const samples = data[0].length\n if (samples === 0) return\n if (data.some((channel) => channel.length !== samples)) {\n throw new Error('mismatched channel lengths')\n }\n\n const start = this.#writeIndex\n const end = start + samples\n this.#timestampAnchors.push({ sampleIndex: start, timestampUs })\n\n const overflow = end - this.#readIndex - this.capacity\n if (overflow > 0) {\n this.#stalled = false\n this.#hasStarted = true\n this.#readIndex += overflow\n if (this.#diagEnabled) this.#diagOverflowSamples += overflow\n this.#pruneTimestampAnchors()\n }\n\n const refillFrames = this.#hasStarted ? this.#resumeFrames : this.#startupFrames\n if (this.#stalled && end - this.#readIndex >= refillFrames) {\n this.#stalled = false\n this.#hasStarted = true\n }\n\n for (let channel = 0; channel < this.channels; channel++) {\n const src = data[channel]\n const dst = this.#buffer[channel]\n for (let i = 0; i < samples; i++) {\n dst[(start + i) % dst.length] = src[i]\n }\n }\n this.#writeIndex = end\n }\n\n read(output: Float32Array[]): number {\n if (output.length !== this.channels) throw new Error('wrong channel count')\n if (this.#stalled) return 0\n\n const available = this.length\n if (available === 0) {\n this.#stalled = true\n return 0\n }\n\n const requested = output[0].length\n const readSamples = Math.min(available, requested)\n\n for (let channel = 0; channel < this.channels; channel++) {\n const dst = output[channel]\n const src = this.#buffer[channel]\n for (let i = 0; i < readSamples; i++) {\n dst[i] = src[(this.#readIndex + i) % src.length]\n }\n for (let i = readSamples; i < requested; i++) dst[i] = 0\n }\n\n this.#readIndex += readSamples\n this.#pruneTimestampAnchors()\n if (readSamples < requested) this.#stalled = true\n\n if (this.#diagEnabled) {\n this.#diagReads++\n this.#diagFillSum += available\n }\n return readSamples\n }\n\n /** Clear queued PCM; optionally treat the next fill as post-start recovery. */\n reset(startUnstalled = false, resumeAfterReset = false): void {\n this.#writeIndex = 0\n this.#readIndex = 0\n this.#stalled = !startUnstalled\n this.#hasStarted = startUnstalled || resumeAfterReset\n this.#timestampAnchors = []\n this.#diagReads = 0\n this.#diagFillSum = 0\n this.#diagOverflowSamples = 0\n }\n\n /**\n * Change the startup latency while preserving the configured storage\n * headroom above its buffering thresholds. Active playout keeps draining\n * retained PCM; a stalled buffer waits for its startup or resume threshold.\n */\n resize(latencyMs: number): void {\n if (!Number.isFinite(latencyMs) || latencyMs <= 0) {\n throw new Error('invalid latency')\n }\n const newStartupFrames = Math.ceil(this.rate * (latencyMs / 1000))\n if (!Number.isSafeInteger(newStartupFrames) || newStartupFrames <= 0) {\n throw new Error('invalid latency')\n }\n const newResumeFrames = this.#resumeFollowsStartup ? newStartupFrames : this.#resumeFrames\n const newCapacity =\n Math.max(newStartupFrames, newResumeFrames) + this.#capacityHeadroomFrames\n if (\n !Number.isSafeInteger(newCapacity) ||\n newCapacity < Math.max(newStartupFrames, newResumeFrames)\n ) {\n throw new Error('invalid capacity frames')\n }\n const wasStalled = this.#stalled\n this.#startupFrames = newStartupFrames\n this.#resumeFrames = newResumeFrames\n if (newCapacity === this.capacity) {\n if (wasStalled && this.length >= this.#refillFrames()) {\n this.#stalled = false\n this.#hasStarted = true\n }\n return\n }\n\n const next = Array.from(\n { length: this.channels },\n () => new Float32Array(newCapacity),\n )\n const samplesToKeep = Math.min(this.length, newCapacity)\n const copyStart = this.#writeIndex - samplesToKeep\n for (let channel = 0; channel < this.channels; channel++) {\n const src = this.#buffer[channel]\n const dst = next[channel]\n for (let i = 0; i < samplesToKeep; i++) {\n const sampleIndex = copyStart + i\n dst[sampleIndex % dst.length] = src[sampleIndex % src.length]\n }\n }\n\n this.#buffer = next\n this.#readIndex = copyStart\n this.#pruneTimestampAnchors()\n this.#stalled = samplesToKeep === 0 || (wasStalled && samplesToKeep < this.#refillFrames())\n if (!this.#stalled) this.#hasStarted = true\n }\n\n getDiagAndReset(): AudioRingBufferDiag | null {\n if (!this.#diagEnabled || this.#diagReads === 0) return null\n const result: AudioRingBufferDiag = {\n reads: this.#diagReads,\n avgFill: Math.round(this.#diagFillSum / this.#diagReads),\n capacity: this.capacity,\n skips: 0,\n dups: 0,\n overflowSamples: this.#diagOverflowSamples,\n }\n this.#diagReads = 0\n this.#diagFillSum = 0\n this.#diagOverflowSamples = 0\n return result\n }\n\n #pruneTimestampAnchors(): void {\n let keep = 0\n while (\n keep + 1 < this.#timestampAnchors.length &&\n this.#timestampAnchors[keep + 1].sampleIndex <= this.#readIndex\n ) {\n keep++\n }\n if (keep > 0) this.#timestampAnchors.splice(0, keep)\n }\n\n #refillFrames(): number {\n return this.#hasStarted ? this.#resumeFrames : this.#startupFrames\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAuCO,IAAM,kBAAN,MAAsB;AAAA,EAoB3B,YAAY,QAA+B;AApBtC;AAIL;AACA,oCAAc;AACd,mCAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA,0CAAuC,CAAC;AAExC;AACA,mCAAa;AACb,qCAAe;AACf,6CAAuB;AAGrB,QAAI,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,YAAY,GAAG;AAC9D,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,QAAI,CAAC,O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