@meframe/core 0.6.13 → 0.7.2
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.
- package/CHANGELOG.md +83 -0
- package/README.md +17 -5
- package/dist/Meframe.d.ts +14 -3
- package/dist/Meframe.d.ts.map +1 -1
- package/dist/Meframe.js +22 -12
- package/dist/Meframe.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +2 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +5 -0
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/l1/VideoL1Cache.d.ts +2 -0
- package/dist/cache/l1/VideoL1Cache.d.ts.map +1 -1
- package/dist/cache/l1/VideoL1Cache.js +13 -7
- package/dist/cache/l1/VideoL1Cache.js.map +1 -1
- package/dist/cache/l2/IndexedDBStore.d.ts +1 -2
- package/dist/cache/l2/IndexedDBStore.d.ts.map +1 -1
- package/dist/cache/l2/L2Cache.d.ts +3 -2
- package/dist/cache/l2/L2Cache.d.ts.map +1 -1
- package/dist/cache/l2/L2OPFSStore.d.ts +3 -3
- package/dist/cache/l2/L2OPFSStore.d.ts.map +1 -1
- package/dist/cache/l2/OPFSStore.d.ts +1 -2
- package/dist/cache/l2/OPFSStore.d.ts.map +1 -1
- package/dist/cache/resource/AudioSampleCache.d.ts +12 -0
- package/dist/cache/resource/AudioSampleCache.d.ts.map +1 -1
- package/dist/cache/resource/AudioSampleCache.js +39 -5
- package/dist/cache/resource/AudioSampleCache.js.map +1 -1
- package/dist/cache/resource/ResourceCache.d.ts +4 -12
- package/dist/cache/resource/ResourceCache.d.ts.map +1 -1
- package/dist/cache/resource/ResourceCache.js +7 -24
- package/dist/cache/resource/ResourceCache.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +4 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/types.d.ts +29 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/validation.d.ts.map +1 -1
- package/dist/config/validation.js +3 -0
- package/dist/config/validation.js.map +1 -1
- package/dist/controllers/PlaybackController.d.ts +38 -9
- package/dist/controllers/PlaybackController.d.ts.map +1 -1
- package/dist/controllers/PlaybackController.js +269 -154
- package/dist/controllers/PlaybackController.js.map +1 -1
- package/dist/controllers/PlaybackStateMachine.d.ts.map +1 -1
- package/dist/controllers/PlaybackStateMachine.js +2 -1
- package/dist/controllers/PlaybackStateMachine.js.map +1 -1
- package/dist/controllers/types.d.ts +10 -2
- package/dist/controllers/types.d.ts.map +1 -1
- package/dist/controllers/types.js.map +1 -1
- package/dist/event/events.d.ts +2 -0
- package/dist/event/events.d.ts.map +1 -1
- package/dist/event/events.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/CompositionModel.d.ts +0 -1
- package/dist/model/CompositionModel.d.ts.map +1 -1
- package/dist/model/CompositionModel.js +0 -6
- package/dist/model/CompositionModel.js.map +1 -1
- package/dist/model/patch.js +12 -12
- package/dist/model/patch.js.map +1 -1
- package/dist/node_modules/.pnpm/{mp4-muxer@5.2.2 → mp4-muxer@5.2.2_patch_hash_452653ac44da4ef32d244694e500e34d084eaa3c4232515ddec962eacc5f30ea}/node_modules/mp4-muxer/build/mp4-muxer.js +17 -3
- package/dist/node_modules/.pnpm/mp4-muxer@5.2.2_patch_hash_452653ac44da4ef32d244694e500e34d084eaa3c4232515ddec962eacc5f30ea/node_modules/mp4-muxer/build/mp4-muxer.js.map +1 -0
- package/dist/orchestrator/AudioExportSession.d.ts +28 -3
- package/dist/orchestrator/AudioExportSession.d.ts.map +1 -1
- package/dist/orchestrator/AudioExportSession.js +131 -15
- package/dist/orchestrator/AudioExportSession.js.map +1 -1
- package/dist/orchestrator/AudioPreviewSession.d.ts +6 -1
- package/dist/orchestrator/AudioPreviewSession.d.ts.map +1 -1
- package/dist/orchestrator/AudioPreviewSession.js +57 -18
- package/dist/orchestrator/AudioPreviewSession.js.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.d.ts +6 -4
- package/dist/orchestrator/AudioWindowPreparer.d.ts.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.js +247 -54
- package/dist/orchestrator/AudioWindowPreparer.js.map +1 -1
- package/dist/orchestrator/CompositionPlanner.d.ts +5 -2
- package/dist/orchestrator/CompositionPlanner.d.ts.map +1 -1
- package/dist/orchestrator/CompositionPlanner.js +8 -3
- package/dist/orchestrator/CompositionPlanner.js.map +1 -1
- package/dist/orchestrator/ExportScheduler.d.ts +1 -0
- package/dist/orchestrator/ExportScheduler.d.ts.map +1 -1
- package/dist/orchestrator/ExportScheduler.js +177 -106
- package/dist/orchestrator/ExportScheduler.js.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts +30 -4
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +264 -111
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/PreviewFrameScheduler.d.ts +21 -1
- package/dist/orchestrator/PreviewFrameScheduler.d.ts.map +1 -1
- package/dist/orchestrator/PreviewFrameScheduler.js +129 -30
- package/dist/orchestrator/PreviewFrameScheduler.js.map +1 -1
- package/dist/orchestrator/VideoWindowDecodeSession.d.ts +22 -1
- package/dist/orchestrator/VideoWindowDecodeSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoWindowDecodeSession.js +426 -198
- package/dist/orchestrator/VideoWindowDecodeSession.js.map +1 -1
- package/dist/orchestrator/aac-window-timeline.d.ts +6 -2
- package/dist/orchestrator/aac-window-timeline.d.ts.map +1 -1
- package/dist/orchestrator/aac-window-timeline.js +156 -19
- package/dist/orchestrator/aac-window-timeline.js.map +1 -1
- package/dist/orchestrator/types.d.ts +5 -1
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/stages/compose/FrameRateConverter.d.ts +2 -1
- package/dist/stages/compose/FrameRateConverter.d.ts.map +1 -1
- package/dist/stages/compose/LayerRenderPolicy.d.ts +14 -0
- package/dist/stages/compose/LayerRenderPolicy.d.ts.map +1 -0
- package/dist/stages/compose/LayerRenderPolicy.js +18 -0
- package/dist/stages/compose/LayerRenderPolicy.js.map +1 -0
- package/dist/stages/compose/OfflineAudioMixer.d.ts +2 -0
- package/dist/stages/compose/OfflineAudioMixer.d.ts.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.js +14 -2
- package/dist/stages/compose/OfflineAudioMixer.js.map +1 -1
- package/dist/stages/compose/OwnedFrameTransform.d.ts +52 -0
- package/dist/stages/compose/OwnedFrameTransform.d.ts.map +1 -0
- package/dist/stages/compose/OwnedFrameTransform.js +154 -0
- package/dist/stages/compose/OwnedFrameTransform.js.map +1 -0
- package/dist/stages/compose/TransitionProcessor.js +0 -1
- package/dist/stages/compose/TransitionProcessor.js.map +1 -1
- package/dist/stages/compose/VideoComposer.d.ts +12 -2
- package/dist/stages/compose/VideoComposer.d.ts.map +1 -1
- package/dist/stages/compose/VideoComposer.js +100 -92
- package/dist/stages/compose/VideoComposer.js.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.js +24 -21
- package/dist/stages/compose/text-renderers/basic-text-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js +110 -99
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js +41 -38
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js +47 -39
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js +54 -48
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js.map +1 -1
- package/dist/stages/compose/text-utils/text-metrics.d.ts.map +1 -1
- package/dist/stages/compose/text-utils/text-metrics.js +6 -4
- package/dist/stages/compose/text-utils/text-metrics.js.map +1 -1
- package/dist/stages/compose/types.d.ts +12 -0
- package/dist/stages/compose/types.d.ts.map +1 -1
- package/dist/stages/decode/BaseDecoder.d.ts +5 -0
- package/dist/stages/decode/BaseDecoder.d.ts.map +1 -1
- package/dist/stages/decode/BaseDecoder.js +52 -10
- package/dist/stages/decode/BaseDecoder.js.map +1 -1
- package/dist/stages/decode/preview-video-decoder.d.ts +48 -2
- package/dist/stages/decode/preview-video-decoder.d.ts.map +1 -1
- package/dist/stages/decode/preview-video-decoder.js +241 -71
- package/dist/stages/decode/preview-video-decoder.js.map +1 -1
- package/dist/stages/decode/video-decoder.d.ts +2 -11
- package/dist/stages/decode/video-decoder.d.ts.map +1 -1
- package/dist/stages/decode/video-decoder.js +60 -61
- package/dist/stages/decode/video-decoder.js.map +1 -1
- package/dist/stages/demux/MP3FrameParser.d.ts +18 -0
- package/dist/stages/demux/MP3FrameParser.d.ts.map +1 -1
- package/dist/stages/demux/MP3FrameParser.js +143 -11
- package/dist/stages/demux/MP3FrameParser.js.map +1 -1
- package/dist/stages/demux/MP4IndexParser.d.ts +32 -21
- package/dist/stages/demux/MP4IndexParser.d.ts.map +1 -1
- package/dist/stages/demux/MP4IndexParser.js +202 -309
- package/dist/stages/demux/MP4IndexParser.js.map +1 -1
- package/dist/stages/demux/sample-collector.d.ts +35 -0
- package/dist/stages/demux/sample-collector.d.ts.map +1 -0
- package/dist/stages/demux/sample-collector.js +105 -0
- package/dist/stages/demux/sample-collector.js.map +1 -0
- package/dist/stages/encode/BaseEncoder.d.ts +9 -2
- package/dist/stages/encode/BaseEncoder.d.ts.map +1 -1
- package/dist/stages/encode/BaseEncoder.js +90 -59
- package/dist/stages/encode/BaseEncoder.js.map +1 -1
- package/dist/stages/load/ResourceLoader.d.ts +71 -18
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +369 -143
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/stages/load/TaskManager.d.ts.map +1 -1
- package/dist/stages/load/TaskManager.js +9 -3
- package/dist/stages/load/TaskManager.js.map +1 -1
- package/dist/stages/load/types.d.ts +2 -2
- package/dist/stages/load/types.d.ts.map +1 -1
- package/dist/stages/mux/MP4Muxer.d.ts +7 -1
- package/dist/stages/mux/MP4Muxer.d.ts.map +1 -1
- package/dist/stages/mux/MP4Muxer.js +8 -10
- package/dist/stages/mux/MP4Muxer.js.map +1 -1
- package/dist/stages/mux/MuxManager.d.ts +7 -0
- package/dist/stages/mux/MuxManager.d.ts.map +1 -1
- package/dist/stages/mux/MuxManager.js +9 -0
- package/dist/stages/mux/MuxManager.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +10 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/until-aborted.d.ts +8 -0
- package/dist/utils/until-aborted.d.ts.map +1 -0
- package/dist/utils/until-aborted.js +33 -0
- package/dist/utils/until-aborted.js.map +1 -0
- package/dist/worker/WorkerChannel.d.ts.map +1 -1
- package/dist/worker/WorkerChannel.js +45 -10
- package/dist/worker/WorkerChannel.js.map +1 -1
- package/dist/worker/worker-manifest.js +1 -1
- package/dist/worker/worker-manifest.js.map +1 -1
- package/dist/workers/stages/export/{export.worker.C8jKSbVj.js → export.worker.BG8HA7dY.js} +745 -450
- package/dist/workers/stages/export/export.worker.BG8HA7dY.js.map +1 -0
- package/dist/workers/worker-manifest.json +1 -1
- package/package.json +23 -22
- package/dist/node_modules/.pnpm/mp4-muxer@5.2.2/node_modules/mp4-muxer/build/mp4-muxer.js.map +0 -1
- package/dist/workers/stages/export/export.worker.C8jKSbVj.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoL1Cache.js","sources":["../../../src/cache/l1/VideoL1Cache.ts"],"sourcesContent":["import type { TimeUs } from '../../model/types';\nimport { RcFrame } from '../../model';\nimport { binarySearchNearest, binarySearchFirst } from '../../utils/binary-search';\nimport { allocatePreviewFrames, type PreviewCacheDemand } from './preview-cache-budget';\n\nconst BYTES_PER_MB = 1024 * 1024;\n\ninterface L1Config {\n maxMemoryMB: number;\n maxFrames?: number;\n /** 播放头【前方】保留时长,默认 ±20s 的那个 20s。见 DEFAULT_FORWARD_WINDOW_US。 */\n windowSizeUs?: TimeUs;\n /** 播放头【后方】保留时长,默认 2s。见 DEFAULT_BACKWARD_WINDOW_US。 */\n backwardWindowSizeUs?: TimeUs;\n}\n\n/**\n * 前方窗口:解码好、等着被播的帧。\n *\n * 历史上这里曾是 20s:音频 5s 小块混音每 5s 抢一次主线程造成抖动,视频帧必须\n * 大量囤货硬扛(2c4f4da)。音频已改为 30s 大块 + 空闲时段混音(见\n * AudioPreviewSession),抖动源消除,囤货失去必要性。\n *\n * 保险取值:供给节奏为「触发距离 6s + 批次 6s」,前方存货峰值 ≈ 12s;\n * 窗口 14s 略高于峰值,顺序播放不浪费解码,同时垫子足够厚,可吸收\n * 主线程突发(混音/GC/业务负载)造成的供给间歇。\n */\nconst DEFAULT_FORWARD_WINDOW_US: TimeUs = 20_000_000;\n\n/**\n * 后方窗口:已经播过的帧。\n *\n * 原先前后对称各 20s,但后方帧只在\"往回小幅 seek\"时有用,实际很少发生,\n * 却占掉整整一半内存。收到 2s 后窗口跨度 40s→22s,稳态内存降约 45%,\n * 而前方存货一帧不动,2c4f4da 那次为吸收 5s 小块混音抖动而加大窗口的收益完整保留。\n */\nconst DEFAULT_BACKWARD_WINDOW_US: TimeUs = 2_000_000;\n\nexport interface L1CacheMetadata {\n size: number;\n maxSize: number;\n entries: number;\n clipCount: number;\n maxFrames: number;\n}\n\n/**\n * Simplified VideoL1Cache - Single-layer frame storage per clip\n *\n * Each clip stores frames in a sorted array by timestamp.\n * No GOP management - frames are directly stored and retrieved via binary search.\n */\nexport class VideoL1Cache {\n private readonly framesByClip = new Map<string, RcFrame[]>();\n private readonly maxMemoryBytes: number;\n private currentBytes = 0;\n private currentFrames = 0;\n private readonly maxFrames: number;\n private previewBudgetConfigured = false;\n private previewLimits = new Map<string, number>();\n private previewTargets = new Map<string, number>();\n private observedFrameBytes = new Map<string, number>();\n private windowCenter: TimeUs = 0;\n // Larger video-frame cache window so playback can absorb main-thread jitter\n // (e.g. frequent small-block audio mixing) without dropping frames.\n private readonly forwardWindowSize: TimeUs;\n private readonly backwardWindowSize: TimeUs;\n private lastEvictTime = 0;\n private readonly EVICT_THROTTLE_MS = 500;\n\n constructor(config: L1Config) {\n this.maxMemoryBytes = config.maxMemoryMB * BYTES_PER_MB;\n this.maxFrames = config.maxFrames === undefined ? Infinity : Math.floor(config.maxFrames);\n // 原先 windowSize 是硬编码的类字段,config.cache.l1.windowSizeUs 从不被读取,\n // 于是公开配置形同虚设。这里接上,默认值与原行为一致。\n this.forwardWindowSize = config.windowSizeUs ?? DEFAULT_FORWARD_WINDOW_US;\n this.backwardWindowSize = config.backwardWindowSizeUs ?? DEFAULT_BACKWARD_WINDOW_US;\n }\n\n setPreviewDemands(demands: PreviewCacheDemand[]): void {\n this.previewLimits = allocatePreviewFrames(demands, this.maxMemoryBytes, this.maxFrames);\n this.previewBudgetConfigured = true;\n this.previewTargets.clear();\n for (const demand of demands) this.previewTargets.set(demand.clipId, demand.targetUs);\n for (const [clipId, limit] of this.previewLimits) {\n while ((this.framesByClip.get(clipId)?.length ?? 0) > limit) this.evictFarthest(clipId);\n }\n this.evictIfOverBudget();\n }\n\n getPreviewFrameLimit(clipId: string): number {\n return this.previewLimits.get(clipId) ?? (this.previewBudgetConfigured ? 0 : this.maxFrames);\n }\n\n getObservedFrameBytes(clipId: string): number {\n return this.observedFrameBytes.get(clipId) ?? 0;\n }\n\n /**\n * Set window center and trigger eviction\n * Window management helps limit memory usage for long clips\n */\n setWindow(centerTimeUs: TimeUs): void {\n this.windowCenter = centerTimeUs;\n\n // Throttle eviction to avoid excessive processing\n const now = Date.now();\n if (now - this.lastEvictTime > this.EVICT_THROTTLE_MS) {\n this.evictOutOfWindow();\n this.lastEvictTime = now;\n }\n }\n\n /**\n * Evict frames outside the window.\n *\n * 窗口是【不对称】的:前方留足抗抖动存货,后方只留少量供小幅回退。\n * 对称保留会让已播过的帧占掉一半内存,而那部分几乎用不到。\n */\n private evictOutOfWindow(): void {\n const minTime = Math.max(0, this.windowCenter - this.backwardWindowSize);\n const maxTime = this.windowCenter + this.forwardWindowSize;\n this.evictOutsideBounds(minTime, maxTime);\n }\n\n /**\n * Evict down to a tight window around the current center, immediately (no throttle).\n *\n * Used when playback stays paused for a while: hoarded frames serve no one while\n * idle, and the editor spends most of its lifetime paused. Does not change the\n * standing window - the next setWindow() restores normal bounds and playback\n * refills on demand through the regular miss/preheat paths.\n */\n shrink(forwardUs: TimeUs = 2_000_000, backwardUs: TimeUs = 2_000_000): void {\n const minTime = Math.max(0, this.windowCenter - backwardUs);\n const maxTime = this.windowCenter + forwardUs;\n this.evictOutsideBounds(minTime, maxTime);\n }\n\n private evictOutsideBounds(minTime: TimeUs, maxTime: TimeUs): void {\n for (const [clipId, frames] of this.framesByClip) {\n const toEvict: RcFrame[] = [];\n const toKeep: RcFrame[] = [];\n\n for (const frame of frames) {\n const globalTime = frame.globalTimeUs;\n\n // Frames without globalTimeUs (legacy) are kept (will be evicted by clip-level logic)\n if (globalTime === undefined) {\n toKeep.push(frame);\n continue;\n }\n\n // Evict frames outside window\n if (\n (globalTime < minTime || globalTime > maxTime) &&\n this.evictionDistance(frame, clipId) !== -1\n ) {\n toEvict.push(frame);\n } else {\n toKeep.push(frame);\n }\n }\n\n // Release evicted frames\n if (toEvict.length > 0) {\n for (const frame of toEvict) {\n this.currentBytes -= frame.sizeEstimate;\n this.currentFrames--;\n frame.close();\n }\n\n this.framesByClip.set(clipId, toKeep);\n }\n }\n }\n\n get(timeUs: TimeUs, clipId: string): RcFrame | null {\n const frames = this.framesByClip.get(clipId);\n if (!frames || frames.length === 0) {\n return null;\n }\n\n // Use nearest frame search (instead of exact range match)\n return binarySearchNearest(frames, timeUs, (frame) => frame.timestampUs ?? 0);\n }\n\n /** Return only a frame whose presentation interval contains the requested time. */\n getCovering(clipId: string, timeUs: TimeUs): RcFrame | null {\n const frames = this.framesByClip.get(clipId);\n if (!frames?.length) return null;\n const next = binarySearchFirst(frames, (frame) => frame.timestampUs > timeUs + 1);\n const frame = frames[next - 1];\n return frame && frame.timestampUs + frame.durationUs > timeUs ? frame : null;\n }\n\n /** A count cannot establish continuity: cached frames may all lie after a hole. */\n covers(clipId: string, startUs: TimeUs, endUs: TimeUs): boolean {\n let coveredUntil = startUs;\n for (const frame of this.framesByClip.get(clipId) ?? []) {\n const end = frame.timestampUs + frame.durationUs;\n if (end <= coveredUntil) continue;\n if (frame.timestampUs > coveredUntil + 1) return false;\n coveredUntil = end;\n if (coveredUntil >= endUs - 1) return true;\n }\n return false;\n }\n\n addFrame(\n frame: VideoFrame,\n clipId: string,\n frameDuration: TimeUs,\n trackId: string,\n globalTimeUs?: TimeUs\n ): RcFrame {\n const rcFrame = RcFrame.wrap(frame, {\n trackId,\n clipId,\n timestampUs: frame.timestamp ?? 0,\n durationUs: frame.duration ?? frameDuration,\n globalTimeUs, // Store global timestamp for window eviction\n });\n this.observedFrameBytes.set(\n clipId,\n Math.max(this.getObservedFrameBytes(clipId), rcFrame.sizeEstimate)\n );\n\n let frames = this.framesByClip.get(clipId);\n if (!frames) {\n frames = [];\n this.framesByClip.set(clipId, frames);\n }\n\n const timestamp = rcFrame.timestampUs ?? 0;\n const insertIndex = this.findInsertIndex(frames, timestamp);\n\n // Check for duplicate timestamp\n if (insertIndex < frames.length && (frames[insertIndex]?.timestampUs ?? 0) === timestamp) {\n const oldFrame = frames[insertIndex];\n frames[insertIndex] = rcFrame;\n this.currentBytes -= oldFrame?.sizeEstimate ?? 0;\n oldFrame?.close?.();\n } else {\n frames.splice(insertIndex, 0, rcFrame);\n this.currentFrames++;\n }\n\n this.currentBytes += rcFrame.sizeEstimate;\n const limit = this.previewBudgetConfigured ? this.getPreviewFrameLimit(clipId) : undefined;\n if (limit !== undefined && frames.length > limit) this.evictFarthest(clipId);\n // Byte-budget fuse: the time window bounds seconds, but seconds × resolution\n // × layers can still explode (4K multi-layer compositions). Whenever the\n // estimate exceeds maxMemoryBytes, drop frames farthest from the playhead\n // first - hoard tails are redundant, frames near the playhead are the ones\n // playback actually needs, so normal projects never feel this path.\n this.evictIfOverBudget();\n\n return rcFrame;\n }\n\n private evictIfOverBudget(): void {\n if (this.currentBytes <= this.maxMemoryBytes && this.currentFrames <= this.maxFrames) return;\n\n // Collect all frames with distance-to-playhead; frames without a global\n // timestamp (legacy first-frame covers) are treated as farthest - they must\n // not stay exempt forever while the budget is blown.\n const candidates: Array<{ frame: RcFrame; clipId: string; distance: number }> = [];\n for (const [clipId, frames] of this.framesByClip) {\n for (const frame of frames) {\n const distance = this.evictionDistance(frame, clipId);\n candidates.push({ frame, clipId, distance });\n }\n }\n candidates.sort((a, b) => b.distance - a.distance);\n\n let evicted = 0;\n for (const c of candidates) {\n if (this.currentBytes <= this.maxMemoryBytes && this.currentFrames <= this.maxFrames) break;\n this.currentBytes -= c.frame.sizeEstimate;\n this.currentFrames--;\n c.frame.close();\n this.removeFrameFrom(c.clipId, c.frame);\n evicted++;\n }\n\n void evicted;\n }\n\n private evictionDistance(frame: RcFrame, clipId: string): number {\n const target = this.previewTargets.get(clipId);\n if (\n (this.previewLimits.get(clipId) ?? 0) > 0 &&\n target !== undefined &&\n frame.timestampUs <= target + 1 &&\n frame.timestampUs + frame.durationUs > target\n )\n return -1;\n const gt = frame.globalTimeUs;\n if (gt === undefined) return Infinity;\n const distance = Math.abs(gt - this.windowCenter);\n if (this.previewTargets.size && !this.previewTargets.has(clipId)) return 2e15 + distance;\n if (target !== undefined && gt < this.windowCenter) return 1e15 + distance;\n return distance;\n }\n\n private evictFarthest(clipId: string): void {\n const frames = this.framesByClip.get(clipId);\n if (!frames?.length) return;\n let candidate = frames[0]!;\n for (const frame of frames) {\n if (this.evictionDistance(frame, clipId) > this.evictionDistance(candidate, clipId))\n candidate = frame;\n }\n this.currentBytes -= candidate.sizeEstimate;\n this.currentFrames--;\n candidate.close();\n this.removeFrameFrom(clipId, candidate);\n }\n\n private removeFrameFrom(clipId: string, frame: RcFrame): void {\n const frames = this.framesByClip.get(clipId);\n if (!frames) return;\n const idx = frames.indexOf(frame);\n if (idx >= 0) frames.splice(idx, 1);\n if (frames.length === 0) this.framesByClip.delete(clipId);\n }\n\n invalidateClip(clipId: string): void {\n this.observedFrameBytes.delete(clipId);\n const frames = this.framesByClip.get(clipId);\n if (!frames) return;\n\n for (const frame of frames) {\n this.currentBytes -= frame.sizeEstimate;\n this.currentFrames--;\n frame?.close?.();\n }\n\n this.framesByClip.delete(clipId);\n }\n\n hasClip(clipId: string): boolean {\n const frames = this.framesByClip.get(clipId);\n return !!frames && frames.length > 0;\n }\n\n getClipFrameCount(clipId: string, startTimeUs?: TimeUs): number {\n const frames = this.framesByClip.get(clipId);\n if (!frames) return 0;\n\n if (startTimeUs === undefined) {\n return frames.length;\n }\n\n // Count frames >= startTimeUs\n let count = 0;\n for (const frame of frames) {\n if ((frame.timestampUs ?? 0) >= startTimeUs) {\n count++;\n }\n }\n return count;\n }\n\n /**\n * Check whether L1 already has enough frames for a resource-time window.\n * Used to skip redundant preheat decode sessions.\n */\n hasFramesInRange(clipId: string, startUs: TimeUs, endUs: TimeUs, minFrames: number): boolean {\n if (minFrames <= 0 || endUs <= startUs) return true;\n\n const frames = this.framesByClip.get(clipId);\n if (!frames || frames.length === 0) return false;\n\n let count = 0;\n for (const frame of frames) {\n const ts = frame.timestampUs ?? 0;\n if (ts >= startUs && ts < endUs) {\n count++;\n if (count >= minFrames) return true;\n }\n }\n return false;\n }\n\n clear(): void {\n for (const frames of this.framesByClip.values()) {\n for (const frame of frames) {\n frame?.close?.();\n }\n }\n this.framesByClip.clear();\n this.currentBytes = 0;\n this.currentFrames = 0;\n this.previewBudgetConfigured = false;\n this.previewLimits.clear();\n this.previewTargets.clear();\n this.observedFrameBytes.clear();\n }\n\n getMetadata(): L1CacheMetadata {\n return {\n size: this.currentBytes,\n maxSize: this.maxMemoryBytes,\n entries: this.currentFrames,\n clipCount: this.framesByClip.size,\n maxFrames: this.maxFrames,\n };\n }\n\n private findInsertIndex(frames: RcFrame[], timestamp: TimeUs): number {\n return binarySearchFirst(frames, (frame) => (frame.timestampUs ?? 0) >= timestamp);\n }\n}\n"],"names":["frame"],"mappings":";;;AAKA,MAAM,eAAe,OAAO;AAsB5B,MAAM,4BAAoC;AAS1C,MAAM,6BAAqC;AAgBpC,MAAM,aAAa;AAAA,EACP,mCAAmB,IAAA;AAAA,EACnB;AAAA,EACT,eAAe;AAAA,EACf,gBAAgB;AAAA,EACP;AAAA,EACT,0BAA0B;AAAA,EAC1B,oCAAoB,IAAA;AAAA,EACpB,qCAAqB,IAAA;AAAA,EACrB,yCAAyB,IAAA;AAAA,EACzB,eAAuB;AAAA;AAAA;AAAA,EAGd;AAAA,EACA;AAAA,EACT,gBAAgB;AAAA,EACP,oBAAoB;AAAA,EAErC,YAAY,QAAkB;AAC5B,SAAK,iBAAiB,OAAO,cAAc;AAC3C,SAAK,YAAY,OAAO,cAAc,SAAY,WAAW,KAAK,MAAM,OAAO,SAAS;AAGxF,SAAK,oBAAoB,OAAO,gBAAgB;AAChD,SAAK,qBAAqB,OAAO,wBAAwB;AAAA,EAC3D;AAAA,EAEA,kBAAkB,SAAqC;AACrD,SAAK,gBAAgB,sBAAsB,SAAS,KAAK,gBAAgB,KAAK,S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AM,eAAe;AAChC,UAAI,MAAM,WAAW,KAAK,OAAO;AAC/B;AACA,YAAI,SAAS,UAAW,QAAO;AAAA,MACjC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,eAAW,UAAU,KAAK,aAAa,OAAA,GAAU;AAC/C,iBAAW,SAAS,QAAQ;AAC1B,eAAO,QAAA;AAAA,MACT;AAAA,IACF;AACA,SAAK,aAAa,MAAA;AAClB,SAAK,eAAe;AACpB,SAAK,gBAAgB;AACrB,SAAK,0BAA0B;AAC/B,SAAK,cAAc,MAAA;AACnB,SAAK,eAAe,MAAA;AACpB,SAAK,mBAAmB,MAAA;AAAA,EAC1B;AAAA,EAEA,cAA+B;AAC7B,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,MACd,WAAW,KAAK,aAAa;AAAA,MAC7B,WAAW,KAAK;AAAA,IAAA;AAAA,EAEpB;AAAA,EAEQ,gBAAgB,QAAmB,WAA2B;AACpE,WAAO,kBAAkB,QAAQ,CAAC,WAAW,MAAM,eAAe,MAAM,SAAS;AAAA,EACnF;AACF;"}
|
|
1
|
+
{"version":3,"file":"VideoL1Cache.js","sources":["../../../src/cache/l1/VideoL1Cache.ts"],"sourcesContent":["import type { TimeUs } from '../../model/types';\nimport { RcFrame } from '../../model';\nimport { binarySearchNearest, binarySearchFirst } from '../../utils/binary-search';\nimport { allocatePreviewFrames, type PreviewCacheDemand } from './preview-cache-budget';\n\nconst BYTES_PER_MB = 1024 * 1024;\n\ninterface L1Config {\n maxMemoryMB: number;\n maxFrames?: number;\n /** 播放头【前方】保留时长,默认 ±20s 的那个 20s。见 DEFAULT_FORWARD_WINDOW_US。 */\n windowSizeUs?: TimeUs;\n /** 播放头【后方】保留时长,默认 2s。见 DEFAULT_BACKWARD_WINDOW_US。 */\n backwardWindowSizeUs?: TimeUs;\n}\n\n/**\n * 前方窗口:解码好、等着被播的帧。\n *\n * 历史上这里曾是 20s:音频 5s 小块混音每 5s 抢一次主线程造成抖动,视频帧必须\n * 大量囤货硬扛(2c4f4da)。音频已改为 30s 大块 + 空闲时段混音(见\n * AudioPreviewSession),抖动源消除,囤货失去必要性。\n *\n * 保险取值:供给节奏为「触发距离 6s + 批次 6s」,前方存货峰值 ≈ 12s;\n * 窗口 14s 略高于峰值,顺序播放不浪费解码,同时垫子足够厚,可吸收\n * 主线程突发(混音/GC/业务负载)造成的供给间歇。\n */\nconst DEFAULT_FORWARD_WINDOW_US: TimeUs = 20_000_000;\n\n/**\n * 后方窗口:已经播过的帧。\n *\n * 原先前后对称各 20s,但后方帧只在\"往回小幅 seek\"时有用,实际很少发生,\n * 却占掉整整一半内存。收到 2s 后窗口跨度 40s→22s,稳态内存降约 45%,\n * 而前方存货一帧不动,2c4f4da 那次为吸收 5s 小块混音抖动而加大窗口的收益完整保留。\n */\nconst DEFAULT_BACKWARD_WINDOW_US: TimeUs = 2_000_000;\n\nexport interface L1CacheMetadata {\n size: number;\n maxSize: number;\n entries: number;\n clipCount: number;\n maxFrames: number;\n}\n\n/**\n * Simplified VideoL1Cache - Single-layer frame storage per clip\n *\n * Each clip stores frames in a sorted array by timestamp.\n * No GOP management - frames are directly stored and retrieved via binary search.\n */\nexport class VideoL1Cache {\n private readonly framesByClip = new Map<string, RcFrame[]>();\n private readonly maxMemoryBytes: number;\n private currentBytes = 0;\n private currentFrames = 0;\n private readonly maxFrames: number;\n private previewBudgetConfigured = false;\n private previewLimits = new Map<string, number>();\n private previewTargets = new Map<string, number>();\n private observedFrameBytes = new Map<string, number>();\n private windowCenter: TimeUs = 0;\n // Larger video-frame cache window so playback can absorb main-thread jitter\n // (e.g. frequent small-block audio mixing) without dropping frames.\n private readonly forwardWindowSize: TimeUs;\n private readonly backwardWindowSize: TimeUs;\n private lastEvictTime = 0;\n private readonly EVICT_THROTTLE_MS = 500;\n\n constructor(config: L1Config) {\n this.maxMemoryBytes = config.maxMemoryMB * BYTES_PER_MB;\n this.maxFrames = config.maxFrames === undefined ? Infinity : Math.floor(config.maxFrames);\n // 原先 windowSize 是硬编码的类字段,config.cache.l1.windowSizeUs 从不被读取,\n // 于是公开配置形同虚设。这里接上,默认值与原行为一致。\n this.forwardWindowSize = config.windowSizeUs ?? DEFAULT_FORWARD_WINDOW_US;\n this.backwardWindowSize = config.backwardWindowSizeUs ?? DEFAULT_BACKWARD_WINDOW_US;\n }\n\n setPreviewDemands(demands: PreviewCacheDemand[]): void {\n this.previewLimits = allocatePreviewFrames(demands, this.maxMemoryBytes, this.maxFrames);\n this.previewBudgetConfigured = true;\n this.previewTargets.clear();\n for (const demand of demands) this.previewTargets.set(demand.clipId, demand.targetUs);\n for (const [clipId, limit] of this.previewLimits) {\n while ((this.framesByClip.get(clipId)?.length ?? 0) > limit) this.evictFarthest(clipId);\n }\n this.evictIfOverBudget();\n }\n\n getPreviewFrameLimit(clipId: string): number {\n return this.previewLimits.get(clipId) ?? (this.previewBudgetConfigured ? 0 : this.maxFrames);\n }\n\n getObservedFrameBytes(clipId: string): number {\n return this.observedFrameBytes.get(clipId) ?? 0;\n }\n\n /**\n * Set window center and trigger eviction\n * Window management helps limit memory usage for long clips\n */\n setWindow(centerTimeUs: TimeUs): void {\n this.windowCenter = centerTimeUs;\n\n // Throttle eviction to avoid excessive processing\n const now = Date.now();\n if (now - this.lastEvictTime > this.EVICT_THROTTLE_MS) {\n this.evictOutOfWindow();\n this.lastEvictTime = now;\n }\n }\n\n /**\n * Evict frames outside the window.\n *\n * 窗口是【不对称】的:前方留足抗抖动存货,后方只留少量供小幅回退。\n * 对称保留会让已播过的帧占掉一半内存,而那部分几乎用不到。\n */\n private evictOutOfWindow(): void {\n const minTime = Math.max(0, this.windowCenter - this.backwardWindowSize);\n const maxTime = this.windowCenter + this.forwardWindowSize;\n this.evictOutsideBounds(minTime, maxTime);\n }\n\n /**\n * Evict down to a tight window around the current center, immediately (no throttle).\n *\n * Used when playback stays paused for a while: hoarded frames serve no one while\n * idle, and the editor spends most of its lifetime paused. Does not change the\n * standing window - the next setWindow() restores normal bounds and playback\n * refills on demand through the regular miss/preheat paths.\n */\n shrink(forwardUs: TimeUs = 2_000_000, backwardUs: TimeUs = 2_000_000): void {\n const minTime = Math.max(0, this.windowCenter - backwardUs);\n const maxTime = this.windowCenter + forwardUs;\n this.evictOutsideBounds(minTime, maxTime);\n }\n\n private evictOutsideBounds(minTime: TimeUs, maxTime: TimeUs): void {\n for (const [clipId, frames] of this.framesByClip) {\n const toEvict: RcFrame[] = [];\n const toKeep: RcFrame[] = [];\n\n for (const frame of frames) {\n const globalTime = frame.globalTimeUs;\n\n // Frames without globalTimeUs (legacy) are kept (will be evicted by clip-level logic)\n if (globalTime === undefined) {\n toKeep.push(frame);\n continue;\n }\n\n // Evict frames outside window\n if (\n (globalTime < minTime || globalTime > maxTime) &&\n this.evictionDistance(frame, clipId) !== -1\n ) {\n toEvict.push(frame);\n } else {\n toKeep.push(frame);\n }\n }\n\n // Release evicted frames\n if (toEvict.length > 0) {\n for (const frame of toEvict) {\n this.currentBytes -= frame.sizeEstimate;\n this.currentFrames--;\n frame.close();\n }\n\n this.framesByClip.set(clipId, toKeep);\n }\n }\n }\n\n get(timeUs: TimeUs, clipId: string): RcFrame | null {\n const frames = this.framesByClip.get(clipId);\n if (!frames || frames.length === 0) {\n return null;\n }\n\n // Use nearest frame search (instead of exact range match)\n return binarySearchNearest(frames, timeUs, (frame) => frame.timestampUs ?? 0);\n }\n\n /** Return only a frame whose presentation interval contains the requested time. */\n getCovering(clipId: string, timeUs: TimeUs): RcFrame | null {\n const frames = this.framesByClip.get(clipId);\n if (!frames?.length) return null;\n const next = binarySearchFirst(frames, (frame) => frame.timestampUs > timeUs + 1);\n const frame = frames[next - 1];\n return frame && frame.timestampUs + frame.durationUs + 1 > timeUs ? frame : null;\n }\n\n /** First timestamp inside [startUs, endUs) not covered by contiguous L1 frames (or endUs when fully covered). */\n firstUncovered(clipId: string, startUs: TimeUs, endUs: TimeUs): TimeUs {\n if (endUs <= startUs) return endUs;\n let coveredUntil = startUs;\n for (const frame of this.framesByClip.get(clipId) ?? []) {\n const end = frame.timestampUs + frame.durationUs;\n if (end <= coveredUntil) continue;\n if (frame.timestampUs > coveredUntil + 1) return coveredUntil;\n coveredUntil = end;\n if (coveredUntil >= endUs - 1) return endUs;\n }\n return coveredUntil;\n }\n\n /** A count cannot establish continuity: cached frames may all lie after a hole. */\n covers(clipId: string, startUs: TimeUs, endUs: TimeUs): boolean {\n if (endUs <= startUs) return false;\n return this.firstUncovered(clipId, startUs, endUs) >= endUs - 1;\n }\n\n addFrame(\n frame: VideoFrame,\n clipId: string,\n frameDuration: TimeUs,\n trackId: string,\n globalTimeUs?: TimeUs\n ): RcFrame {\n const rcFrame = RcFrame.wrap(frame, {\n trackId,\n clipId,\n timestampUs: frame.timestamp ?? 0,\n durationUs: frame.duration !== null && frame.duration > 0 ? frame.duration : frameDuration,\n globalTimeUs, // Store global timestamp for window eviction\n });\n this.observedFrameBytes.set(\n clipId,\n Math.max(this.getObservedFrameBytes(clipId), rcFrame.sizeEstimate)\n );\n\n let frames = this.framesByClip.get(clipId);\n if (!frames) {\n frames = [];\n this.framesByClip.set(clipId, frames);\n }\n\n const timestamp = rcFrame.timestampUs ?? 0;\n const insertIndex = this.findInsertIndex(frames, timestamp);\n\n // Check for duplicate timestamp\n if (insertIndex < frames.length && (frames[insertIndex]?.timestampUs ?? 0) === timestamp) {\n const oldFrame = frames[insertIndex];\n frames[insertIndex] = rcFrame;\n this.currentBytes -= oldFrame?.sizeEstimate ?? 0;\n oldFrame?.close?.();\n } else {\n frames.splice(insertIndex, 0, rcFrame);\n this.currentFrames++;\n }\n\n this.currentBytes += rcFrame.sizeEstimate;\n const limit = this.previewBudgetConfigured ? this.getPreviewFrameLimit(clipId) : undefined;\n if (limit !== undefined && frames.length > limit) this.evictFarthest(clipId);\n // Byte-budget fuse: the time window bounds seconds, but seconds × resolution\n // × layers can still explode (4K multi-layer compositions). Whenever the\n // estimate exceeds maxMemoryBytes, drop frames farthest from the playhead\n // first - hoard tails are redundant, frames near the playhead are the ones\n // playback actually needs, so normal projects never feel this path.\n this.evictIfOverBudget();\n\n return rcFrame;\n }\n\n private evictIfOverBudget(): void {\n if (this.currentBytes <= this.maxMemoryBytes && this.currentFrames <= this.maxFrames) return;\n\n // Collect all frames with distance-to-playhead; frames without a global\n // timestamp (legacy first-frame covers) are treated as farthest - they must\n // not stay exempt forever while the budget is blown.\n const candidates: Array<{ frame: RcFrame; clipId: string; distance: number }> = [];\n for (const [clipId, frames] of this.framesByClip) {\n for (const frame of frames) {\n const distance = this.evictionDistance(frame, clipId);\n candidates.push({ frame, clipId, distance });\n }\n }\n candidates.sort((a, b) => b.distance - a.distance);\n\n let evicted = 0;\n for (const c of candidates) {\n if (this.currentBytes <= this.maxMemoryBytes && this.currentFrames <= this.maxFrames) break;\n this.currentBytes -= c.frame.sizeEstimate;\n this.currentFrames--;\n c.frame.close();\n this.removeFrameFrom(c.clipId, c.frame);\n evicted++;\n }\n\n void evicted;\n }\n\n private evictionDistance(frame: RcFrame, clipId: string): number {\n const target = this.previewTargets.get(clipId);\n if (\n (this.previewLimits.get(clipId) ?? 0) > 0 &&\n target !== undefined &&\n frame.timestampUs <= target + 1 &&\n frame.timestampUs + frame.durationUs > target\n )\n return -1;\n const gt = frame.globalTimeUs;\n if (gt === undefined) return Infinity;\n const distance = Math.abs(gt - this.windowCenter);\n if (this.previewTargets.size && !this.previewTargets.has(clipId)) return 2e15 + distance;\n if (target !== undefined && gt < this.windowCenter) return 1e15 + distance;\n return distance;\n }\n\n private evictFarthest(clipId: string): void {\n const frames = this.framesByClip.get(clipId);\n if (!frames?.length) return;\n let candidate = frames[0]!;\n for (const frame of frames) {\n if (this.evictionDistance(frame, clipId) > this.evictionDistance(candidate, clipId))\n candidate = frame;\n }\n this.currentBytes -= candidate.sizeEstimate;\n this.currentFrames--;\n candidate.close();\n this.removeFrameFrom(clipId, candidate);\n }\n\n private removeFrameFrom(clipId: string, frame: RcFrame): void {\n const frames = this.framesByClip.get(clipId);\n if (!frames) return;\n const idx = frames.indexOf(frame);\n if (idx >= 0) frames.splice(idx, 1);\n if (frames.length === 0) this.framesByClip.delete(clipId);\n }\n\n invalidateClip(clipId: string): void {\n this.observedFrameBytes.delete(clipId);\n const frames = this.framesByClip.get(clipId);\n if (!frames) return;\n\n for (const frame of frames) {\n this.currentBytes -= frame.sizeEstimate;\n this.currentFrames--;\n frame?.close?.();\n }\n\n this.framesByClip.delete(clipId);\n }\n\n hasClip(clipId: string): boolean {\n const frames = this.framesByClip.get(clipId);\n return !!frames && frames.length > 0;\n }\n\n getClipFrameCount(clipId: string, startTimeUs?: TimeUs): number {\n const frames = this.framesByClip.get(clipId);\n if (!frames) return 0;\n\n if (startTimeUs === undefined) {\n return frames.length;\n }\n\n // Count frames >= startTimeUs\n let count = 0;\n for (const frame of frames) {\n if ((frame.timestampUs ?? 0) >= startTimeUs) {\n count++;\n }\n }\n return count;\n }\n\n /**\n * Check whether L1 already has enough frames for a resource-time window.\n * Used to skip redundant preheat decode sessions.\n */\n hasFramesInRange(clipId: string, startUs: TimeUs, endUs: TimeUs, minFrames: number): boolean {\n if (minFrames <= 0 || endUs <= startUs) return true;\n\n const frames = this.framesByClip.get(clipId);\n if (!frames || frames.length === 0) return false;\n\n let count = 0;\n for (const frame of frames) {\n const ts = frame.timestampUs ?? 0;\n if (ts >= startUs && ts < endUs) {\n count++;\n if (count >= minFrames) return true;\n }\n }\n return false;\n }\n\n clear(): void {\n for (const frames of this.framesByClip.values()) {\n for (const frame of frames) {\n frame?.close?.();\n }\n }\n this.framesByClip.clear();\n this.currentBytes = 0;\n this.currentFrames = 0;\n this.previewBudgetConfigured = false;\n this.previewLimits.clear();\n this.previewTargets.clear();\n this.observedFrameBytes.clear();\n }\n\n getMetadata(): L1CacheMetadata {\n return {\n size: this.currentBytes,\n maxSize: this.maxMemoryBytes,\n entries: this.currentFrames,\n clipCount: this.framesByClip.size,\n maxFrames: this.maxFrames,\n };\n }\n\n private findInsertIndex(frames: RcFrame[], timestamp: TimeUs): number {\n return binarySearchFirst(frames, (frame) => (frame.timestampUs ?? 0) >= timestamp);\n }\n}\n"],"names":["frame"],"mappings":";;;AAKA,MAAM,eAAe,OAAO;AAsB5B,MAAM,4BAAoC;AAS1C,MAAM,6BAAqC;AAgBpC,MAAM,aAAa;AAAA,EACP,mCAAmB,IAAA;AAAA,EACnB;AAAA,EACT,eAAe;AAAA,EACf,gBAAgB;AAAA,EACP;AAAA,EACT,0BAA0B;AAAA,EAC1B,oCAAoB,IAAA;AAAA,EACpB,qCAAqB,IAAA;AAAA,EACrB,yCAAyB,IAAA;AAAA,EACzB,eAAuB;AAAA;AAAA;AAAA,EAGd;AAAA,EACA;AAAA,EACT,gBAAgB;AAAA,EACP,oBAAoB;AAAA,EAErC,YAAY,QAAkB;AAC5B,SAAK,iBAAiB,OAAO,cAAc;AAC3C,SAAK,YAAY,OAAO,cAAc,SAAY,WAAW,KAAK,MAAM,OAAO,SAAS;AAGxF,SAAK,oBAAoB,OAAO,gBAAgB;AAChD,SAAK,qBAAqB,OAAO,wBAAwB;AAAA,EAC3D;AAAA,EAEA,kBAAkB,SAAqC;AACrD,SAAK,gBAAgB,sBAAsB,SAAS,KAAK,gBAAgB,KAAK,SAAS;AACvF,SAAK,0BAA0B;AAC/B,SAAK,eAAe,MAAA;AACpB,eAAW,UAAU,QAAS,MAAK,eAAe,IAAI,OAAO,QAAQ,OAAO,QAAQ;AACpF,eAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,eAAe;AAChD,cAAQ,KAAK,aAAa,IAAI,MAAM,GAAG,UAAU,KAAK,MAAO,MAAK,cAAc,MAAM;AAAA,IACxF;AACA,SAAK,kBAAA;AAAA,EACP;AAAA,EAEA,qBAAqB,QAAwB;AAC3C,WAAO,KAAK,cAAc,IAAI,MAAM,MAAM,KAAK,0BAA0B,IAAI,KAAK;AAAA,EACpF;AAAA,EAEA,sBAAsB,QAAwB;AAC5C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;AAC1B,eAAO,QAAA;AAAA,MACT;AAAA,IACF;AACA,SAAK,aAAa,MAAA;AAClB,SAAK,eAAe;AACpB,SAAK,gBAAgB;AACrB,SAAK,0BAA0B;AAC/B,SAAK,cAAc,MAAA;AACnB,SAAK,eAAe,MAAA;AACpB,SAAK,mBAAmB,MAAA;AAAA,EAC1B;AAAA,EAEA,cAA+B;AAC7B,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,MACd,WAAW,KAAK,aAAa;AAAA,MAC7B,WAAW,KAAK;AAAA,IAAA;AAAA,EAEpB;AAAA,EAEQ,gBAAgB,QAAmB,WAA2B;AACpE,WAAO,kBAAkB,QAAQ,CAAC,WAAW,MAAM,eAAe,MAAM,SAAS;AAAA,EACnF;AACF;"}
|
|
@@ -25,8 +25,7 @@ export interface ChunkRecord {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* IndexedDB
|
|
29
|
-
* Handles all database operations for chunk records
|
|
28
|
+
* @deprecated Legacy IndexedDB store for L2 chunks; Window Cache does not persist chunk metadata here.
|
|
30
29
|
*/
|
|
31
30
|
export declare class IndexedDBStore {
|
|
32
31
|
private db;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDBStore.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/IndexedDBStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CA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O,CAAC,gBAAgB;CAMzB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { TimeUs } from '../../model/types';
|
|
2
|
+
import { MeframeOpfsGateway } from '../storage/opfs/gateway';
|
|
2
3
|
|
|
3
4
|
interface L2Config {
|
|
4
5
|
maxSizeMB: number;
|
|
5
6
|
projectId: string;
|
|
7
|
+
opfsGateway?: MeframeOpfsGateway;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
|
-
* L2 Cache
|
|
9
|
-
* Uses OPFSStore for file storage and IndexedDBStore for metadata
|
|
10
|
+
* @deprecated Legacy L2 cache coordinator superseded by Window Cache (`VideoL1Cache` + `ResourceCache`).
|
|
10
11
|
*/
|
|
11
12
|
export declare class L2Cache {
|
|
12
13
|
private readonly opfsStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"L2Cache.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/L2Cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"L2Cache.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/L2Cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,UAAU,QAAQ;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAA8B;gBAErC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IAqB5B,OAAO,CAAC,WAAW;YAwBL,WAAW;YAeX,YAAY;IAuC1B,WAAW,IAAI;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB;IAWK,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWzD;;OAEG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAOpF;;OAEG;IACG,YAAY,IAAI,OAAO,CAC3B,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CACxF;IA8BD;;OAEG;IACG,YAAY,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D;;OAEG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMzD"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { MeframeOpfsGateway } from '../storage/opfs/gateway';
|
|
1
2
|
import { ChunkBatch } from '../storage/opfs/types';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* L2
|
|
5
|
-
* Adapts OPFSManager for L2 cache chunk operations
|
|
5
|
+
* @deprecated Legacy L2 OPFS wrapper; Window Cache reads directly from ResourceCache + MeframeOpfsGateway.
|
|
6
6
|
*/
|
|
7
7
|
export declare class L2OPFSStore {
|
|
8
8
|
private opfsManager;
|
|
9
|
-
constructor();
|
|
9
|
+
constructor(opfsGateway?: MeframeOpfsGateway);
|
|
10
10
|
init(): Promise<void>;
|
|
11
11
|
/**
|
|
12
12
|
* Read chunk data from OPFS file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"L2OPFSStore.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/L2OPFSStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"L2OPFSStore.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/L2OPFSStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,WAAW,CAAc;gBAErB,WAAW,CAAC,EAAE,kBAAkB;IAItC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;OAEG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAe/F;;OAEG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,KAAK,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,EACpD,eAAe,EAAE,UAAU,EAAE,GAAG,SAAS,EACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE;;OAEG;IACG,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvE;;OAEG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAI/B,kBAAkB;CAOjC"}
|
|
@@ -8,8 +8,7 @@ export interface ChunkBatch {
|
|
|
8
8
|
type: 'key' | 'delta';
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* OPFS
|
|
12
|
-
* Handles all file operations in Origin Private File System
|
|
11
|
+
* @deprecated Legacy OPFS store superseded by host `MeframeOpfsGateway` and `OPFSManager`.
|
|
13
12
|
*/
|
|
14
13
|
export declare class OPFSStore {
|
|
15
14
|
private opfsRoot;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OPFSStore.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/OPFSStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;CACvB;AAED
|
|
1
|
+
{"version":3,"file":"OPFSStore.d.ts","sourceRoot":"","sources":["../../../src/cache/l2/OPFSStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAA0C;IAC1D,OAAO,CAAC,WAAW,CAA8B;IAE3C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAOb,WAAW;IAIzB;;OAEG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmB/F;;;OAGG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,KAAK,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,EACpD,eAAe,EAAE,UAAU,EAAE,GAAG,SAAS,EACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,EAAE,CAAC;IAwCxB;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAepE;;OAEG;IACG,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe9D;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBvE;;OAEG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAI/B,kBAAkB;CAOjC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { TimeUs } from '../../model/types';
|
|
2
|
+
import { Sample } from '../../stages/demux/types';
|
|
2
3
|
import { WAVIndex } from '../../stages/demux/WAVIndexParser';
|
|
3
4
|
|
|
5
|
+
export interface IndexedAudioSource {
|
|
6
|
+
samples: Sample[];
|
|
7
|
+
readRange: (start: number, end: number) => Promise<ArrayBuffer>;
|
|
8
|
+
mainDataBytes?: Uint16Array;
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* 无缝播放(gapless)裁剪参数:MP3/LAME 编码的解码输出首尾含编码器预填充
|
|
6
12
|
* 静音(见 meframe issue #22)。skipSamples/trimEndSamples 为解码后应丢弃的
|
|
@@ -21,6 +27,8 @@ export interface AudioSampleRecord {
|
|
|
21
27
|
gapless?: GaplessTrim;
|
|
22
28
|
/** WAV sources retain only an OPFS index; samples are read on demand. */
|
|
23
29
|
pcm?: WAVIndex;
|
|
30
|
+
/** Indexed MP4/M4A audio retains the sample table and reads windows on demand via readRange. */
|
|
31
|
+
indexed?: IndexedAudioSource;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* AudioSampleCache - Resource-level audio sample cache
|
|
@@ -38,6 +46,10 @@ export declare class AudioSampleCache {
|
|
|
38
46
|
get size(): number;
|
|
39
47
|
private cache;
|
|
40
48
|
hasAudioData(): boolean;
|
|
49
|
+
setIndexed(resourceId: string, samples: Sample[], metadata: AudioDecoderConfig, readRange: IndexedAudioSource['readRange'], options?: {
|
|
50
|
+
gapless?: GaplessTrim;
|
|
51
|
+
mainDataBytes?: Uint16Array;
|
|
52
|
+
}): void;
|
|
41
53
|
setPCM(resourceId: string, pcm: WAVIndex): void;
|
|
42
54
|
/**
|
|
43
55
|
* Set audio samples for a resource
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioSampleCache.d.ts","sourceRoot":"","sources":["../../../src/cache/resource/AudioSampleCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"AudioSampleCache.d.ts","sourceRoot":"","sources":["../../../src/cache/resource/AudioSampleCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAGlE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,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AI;IAIjD;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAsB1F;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAShC;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,aAAa,IAAI,MAAM;CAOxB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { binarySearchFirst } from "../../utils/binary-search.js";
|
|
1
2
|
class AudioSampleCache {
|
|
2
3
|
get size() {
|
|
3
4
|
return this.cache.size;
|
|
@@ -5,10 +6,34 @@ class AudioSampleCache {
|
|
|
5
6
|
cache = /* @__PURE__ */ new Map();
|
|
6
7
|
hasAudioData() {
|
|
7
8
|
for (const record of this.cache.values()) {
|
|
8
|
-
if (record.totalBytes > 0 || (record.pcm?.numberOfFrames ?? 0) > 0)
|
|
9
|
+
if (record.totalBytes > 0 || (record.pcm?.numberOfFrames ?? 0) > 0 || (record.indexed?.samples.length ?? 0) > 0) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
13
|
return false;
|
|
11
14
|
}
|
|
15
|
+
setIndexed(resourceId, samples, metadata, readRange, options) {
|
|
16
|
+
const last = samples[samples.length - 1];
|
|
17
|
+
let durationUs = last ? last.timestamp + last.duration : 0;
|
|
18
|
+
const gapless = options?.gapless;
|
|
19
|
+
if (gapless) {
|
|
20
|
+
const keptSamples = samples.length * gapless.samplesPerFrame - gapless.skipSamples - gapless.trimEndSamples;
|
|
21
|
+
durationUs = Math.round(Math.max(0, keptSamples) * 1e6 / metadata.sampleRate);
|
|
22
|
+
}
|
|
23
|
+
this.cache.set(resourceId, {
|
|
24
|
+
resourceId,
|
|
25
|
+
samples: [],
|
|
26
|
+
metadata,
|
|
27
|
+
totalBytes: 0,
|
|
28
|
+
durationUs,
|
|
29
|
+
...gapless !== void 0 ? { gapless } : {},
|
|
30
|
+
indexed: {
|
|
31
|
+
samples,
|
|
32
|
+
readRange,
|
|
33
|
+
...options?.mainDataBytes !== void 0 ? { mainDataBytes: options.mainDataBytes } : {}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
12
37
|
setPCM(resourceId, pcm) {
|
|
13
38
|
this.cache.set(resourceId, {
|
|
14
39
|
resourceId,
|
|
@@ -61,10 +86,19 @@ class AudioSampleCache {
|
|
|
61
86
|
const record = this.cache.get(resourceId);
|
|
62
87
|
if (!record) return [];
|
|
63
88
|
const offsetUs = record.gapless ? record.gapless.skipSamples * 1e6 / record.metadata.sampleRate : 0;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
const targetStart = startUs + offsetUs;
|
|
90
|
+
const targetEnd = endUs + offsetUs;
|
|
91
|
+
const first = binarySearchFirst(
|
|
92
|
+
record.samples,
|
|
93
|
+
(s) => s.timestamp + (s.duration ?? 0) > targetStart
|
|
94
|
+
);
|
|
95
|
+
const out = [];
|
|
96
|
+
for (let i = first; i < record.samples.length; i++) {
|
|
97
|
+
const s = record.samples[i];
|
|
98
|
+
if (s.timestamp >= targetEnd) break;
|
|
99
|
+
if (s.timestamp + (s.duration ?? 0) > targetStart) out.push(s);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
68
102
|
}
|
|
69
103
|
/**
|
|
70
104
|
* Delete audio samples for a resource
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioSampleCache.js","sources":["../../../src/cache/resource/AudioSampleCache.ts"],"sourcesContent":["import type { TimeUs } from '../../model/types';\nimport type { WAVIndex } from '../../stages/demux/WAVIndexParser';\n\n/**\n * 无缝播放(gapless)裁剪参数:MP3/LAME 编码的解码输出首尾含编码器预填充\n * 静音(见 meframe issue #22)。skipSamples/trimEndSamples 为解码后应丢弃的\n * 首尾样本数;为 undefined 表示无 gapless 信息(保持原行为)。\n */\nexport interface GaplessTrim {\n skipSamples: number;\n trimEndSamples: number;\n /** Number of decoded samples per compressed frame. */\n samplesPerFrame: number;\n}\n\nexport interface AudioSampleRecord {\n resourceId: string;\n samples: EncodedAudioChunk[];\n metadata: AudioDecoderConfig;\n totalBytes: number;\n durationUs: TimeUs;\n gapless?: GaplessTrim;\n /** WAV sources retain only an OPFS index; samples are read on demand. */\n pcm?: WAVIndex;\n}\n\n/**\n * AudioSampleCache - Resource-level audio sample cache\n *\n * Caches encoded audio samples from MP4/MP3, or a small WAV PCM index\n * Audio data is small (~100KB for 30s AAC, ~6MB for 30min)\n *\n * Strategy:\n * - Extract all audio samples during moov parsing (one-time cost)\n * - Keep encoded chunks in memory (compressed)\n * - Decode to PCM on-demand when clip is played\n * - Keep WAV payload in OPFS and read only requested PCM blocks\n */\nexport class AudioSampleCache {\n get size(): number {\n return this.cache.size;\n }\n\n private cache = new Map<string, AudioSampleRecord>();\n\n hasAudioData(): boolean {\n for (const record of this.cache.values()) {\n if (record.totalBytes > 0
|
|
1
|
+
{"version":3,"file":"AudioSampleCache.js","sources":["../../../src/cache/resource/AudioSampleCache.ts"],"sourcesContent":["import type { TimeUs } from '../../model/types';\nimport type { Sample } from '../../stages/demux/types';\nimport type { WAVIndex } from '../../stages/demux/WAVIndexParser';\nimport { binarySearchFirst } from '../../utils/binary-search';\n\nexport interface IndexedAudioSource {\n samples: Sample[];\n readRange: (start: number, end: number) => Promise<ArrayBuffer>;\n mainDataBytes?: Uint16Array;\n}\n\n/**\n * 无缝播放(gapless)裁剪参数:MP3/LAME 编码的解码输出首尾含编码器预填充\n * 静音(见 meframe issue #22)。skipSamples/trimEndSamples 为解码后应丢弃的\n * 首尾样本数;为 undefined 表示无 gapless 信息(保持原行为)。\n */\nexport interface GaplessTrim {\n skipSamples: number;\n trimEndSamples: number;\n /** Number of decoded samples per compressed frame. */\n samplesPerFrame: number;\n}\n\nexport interface AudioSampleRecord {\n resourceId: string;\n samples: EncodedAudioChunk[];\n metadata: AudioDecoderConfig;\n totalBytes: number;\n durationUs: TimeUs;\n gapless?: GaplessTrim;\n /** WAV sources retain only an OPFS index; samples are read on demand. */\n pcm?: WAVIndex;\n /** Indexed MP4/M4A audio retains the sample table and reads windows on demand via readRange. */\n indexed?: IndexedAudioSource;\n}\n\n/**\n * AudioSampleCache - Resource-level audio sample cache\n *\n * Caches encoded audio samples from MP4/MP3, or a small WAV PCM index\n * Audio data is small (~100KB for 30s AAC, ~6MB for 30min)\n *\n * Strategy:\n * - Extract all audio samples during moov parsing (one-time cost)\n * - Keep encoded chunks in memory (compressed)\n * - Decode to PCM on-demand when clip is played\n * - Keep WAV payload in OPFS and read only requested PCM blocks\n */\nexport class AudioSampleCache {\n get size(): number {\n return this.cache.size;\n }\n\n private cache = new Map<string, AudioSampleRecord>();\n\n hasAudioData(): boolean {\n for (const record of this.cache.values()) {\n if (\n record.totalBytes > 0 ||\n (record.pcm?.numberOfFrames ?? 0) > 0 ||\n (record.indexed?.samples.length ?? 0) > 0\n ) {\n return true;\n }\n }\n return false;\n }\n\n setIndexed(\n resourceId: string,\n samples: Sample[],\n metadata: AudioDecoderConfig,\n readRange: IndexedAudioSource['readRange'],\n options?: { gapless?: GaplessTrim; mainDataBytes?: Uint16Array }\n ): void {\n const last = samples[samples.length - 1];\n let durationUs = last ? last.timestamp + last.duration : 0;\n const gapless = options?.gapless;\n if (gapless) {\n const keptSamples =\n samples.length * gapless.samplesPerFrame - gapless.skipSamples - gapless.trimEndSamples;\n durationUs = Math.round((Math.max(0, keptSamples) * 1_000_000) / metadata.sampleRate);\n }\n this.cache.set(resourceId, {\n resourceId,\n samples: [],\n metadata,\n totalBytes: 0,\n durationUs,\n ...(gapless !== undefined ? { gapless } : {}),\n indexed: {\n samples,\n readRange,\n ...(options?.mainDataBytes !== undefined ? { mainDataBytes: options.mainDataBytes } : {}),\n },\n });\n }\n\n setPCM(resourceId: string, pcm: WAVIndex): void {\n this.cache.set(resourceId, {\n resourceId,\n samples: [],\n metadata: {\n codec: 'pcm',\n sampleRate: pcm.sampleRate,\n numberOfChannels: pcm.numberOfChannels,\n },\n totalBytes: 0,\n durationUs: Math.round((pcm.numberOfFrames * 1_000_000) / pcm.sampleRate),\n pcm,\n });\n }\n\n /**\n * Set audio samples for a resource\n */\n set(\n resourceId: string,\n samples: EncodedAudioChunk[],\n metadata: AudioDecoderConfig,\n gapless?: GaplessTrim\n ): void {\n const totalBytes = samples.reduce((sum, s) => sum + s.byteLength, 0);\n let durationUs =\n samples.length > 0\n ? samples[samples.length - 1]!.timestamp + (samples[samples.length - 1]!.duration ?? 0)\n : 0;\n // Encoded timestamps remain physical; expose the trimmed resource duration.\n if (gapless) {\n const keptSamples =\n samples.length * gapless.samplesPerFrame - gapless.skipSamples - gapless.trimEndSamples;\n durationUs = Math.round((Math.max(0, keptSamples) * 1_000_000) / metadata.sampleRate);\n }\n\n this.cache.set(resourceId, {\n resourceId,\n samples,\n metadata,\n totalBytes,\n durationUs,\n ...(gapless !== undefined ? { gapless } : {}),\n });\n }\n\n /**\n * Get audio record for a resource\n */\n get(resourceId: string): AudioSampleRecord | null {\n return this.cache.get(resourceId) || null;\n }\n\n /**\n * Check if resource has audio samples\n */\n has(resourceId: string): boolean {\n return this.cache.has(resourceId);\n }\n\n /**\n * Get samples in time range (for clip trimming)\n */\n getSamplesInRange(resourceId: string, startUs: TimeUs, endUs: TimeUs): EncodedAudioChunk[] {\n const record = this.cache.get(resourceId);\n if (!record) return [];\n\n const offsetUs = record.gapless\n ? (record.gapless.skipSamples * 1_000_000) / record.metadata.sampleRate\n : 0;\n const targetStart = startUs + offsetUs;\n const targetEnd = endUs + offsetUs;\n const first = binarySearchFirst(\n record.samples,\n (s) => s.timestamp + (s.duration ?? 0) > targetStart\n );\n const out: EncodedAudioChunk[] = [];\n for (let i = first; i < record.samples.length; i++) {\n const s = record.samples[i]!;\n if (s.timestamp >= targetEnd) break;\n if (s.timestamp + (s.duration ?? 0) > targetStart) out.push(s);\n }\n return out;\n }\n\n /**\n * Delete audio samples for a resource\n */\n delete(resourceId: string): void {\n const record = this.cache.get(resourceId);\n if (record) {\n // Note: EncodedAudioChunk doesn't have close() method\n // Chunks will be garbage collected automatically\n this.cache.delete(resourceId);\n }\n }\n\n /**\n * Clear all cached audio samples\n */\n clear(): void {\n // Note: EncodedAudioChunk doesn't have close() method\n // Chunks will be garbage collected automatically\n this.cache.clear();\n }\n\n /**\n * Get total memory usage\n */\n getTotalBytes(): number {\n let total = 0;\n for (const record of this.cache.values()) {\n total += record.totalBytes;\n }\n return total;\n }\n}\n"],"names":[],"mappings":";AAgDO,MAAM,iBAAiB;AAAA,EAC5B,IAAI,OAAe;AACjB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEQ,4BAAY,IAAA;AAAA,EAEpB,eAAwB;AACtB,eAAW,UAAU,KAAK,MAAM,OAAA,GAAU;AACxC,UACE,OAAO,aAAa,MACnB,OAAO,KAAK,kBAAkB,KAAK,MACnC,OAAO,SAAS,QAAQ,UAAU,KAAK,GACxC;AACA,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,WACE,YACA,SACA,UACA,WACA,SACM;AACN,UAAM,OAAO,QAAQ,QAAQ,SAAS,CAAC;AACvC,QAAI,aAAa,OAAO,KAAK,YAAY,KAAK,WAAW;AACzD,UAAM,UAAU,SAAS;AACzB,QAAI,SAAS;AACX,YAAM,cACJ,QAAQ,SAAS,QAAQ,kBAAkB,QAAQ,cAAc,QAAQ;AAC3E,mBAAa,KAAK,MAAO,KAAK,IAAI,GAAG,WAAW,IAAI,MAAa,SAAS,UAAU;AAAA,IACtF;AACA,SAAK,MAAM,IAAI,YAAY;AAAA,MACzB;AAAA,MACA,SAAS,CAAA;AAAA,MACT;AAAA,MACA,YAAY;AAAA,MACZ;AAAA,MACA,GAAI,YAAY,SAAY,EAAE,QAAA,IAAY,CAAA;AAAA,MAC1C,SAAS;AAAA,QAC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KA,kBAAkB,YAAoB,SAAiB,OAAoC;AACzF,UAAM,SAAS,KAAK,MAAM,IAAI,UAAU;AACxC,QAAI,CAAC,OAAQ,QAAO,CAAA;AAEpB,UAAM,WAAW,OAAO,UACnB,OAAO,QAAQ,cAAc,MAAa,OAAO,SAAS,aAC3D;AACJ,UAAM,cAAc,UAAU;AAC9B,UAAM,YAAY,QAAQ;AAC1B,UAAM,QAAQ;AAAA,MACZ,OAAO;AAAA,MACP,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,KAAK;AAAA,IAAA;AAE3C,UAAM,MAA2B,CAAA;AACjC,aAAS,IAAI,OAAO,IAAI,OAAO,QAAQ,QAAQ,KAAK;AAClD,YAAM,IAAI,OAAO,QAAQ,CAAC;AAC1B,UAAI,EAAE,aAAa,UAAW;AAC9B,UAAI,EAAE,aAAa,EAAE,YAAY,KAAK,YAAa,KAAI,KAAK,CAAC;AAAA,IAC/D;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,YAA0B;AAC/B,UAAM,SAAS,KAAK,MAAM,IAAI,UAAU;AACxC,QAAI,QAAQ;AAGV,WAAK,MAAM,OAAO,UAAU;AAAA,IAC9B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AAGZ,SAAK,MAAM,MAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAwB;AACtB,QAAI,QAAQ;AACZ,eAAW,UAAU,KAAK,MAAM,OAAA,GAAU;AACxC,eAAS,OAAO;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -26,14 +26,6 @@ export declare class ResourceCache {
|
|
|
26
26
|
* Open a readable stream for the video resource file in OPFS.
|
|
27
27
|
*/
|
|
28
28
|
openResourceReadStream(resourceId: string): Promise<ReadableStream<Uint8Array>>;
|
|
29
|
-
/**
|
|
30
|
-
* Delete a resource from OPFS
|
|
31
|
-
*/
|
|
32
|
-
deleteResource(resourceId: string): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Clear all resources for current project
|
|
35
|
-
*/
|
|
36
|
-
clear(): Promise<void>;
|
|
37
29
|
private getFileName;
|
|
38
30
|
private audioPath;
|
|
39
31
|
/**
|
|
@@ -48,12 +40,12 @@ export declare class ResourceCache {
|
|
|
48
40
|
readAudioRange(resourceId: string, start: number, end: number): Promise<ArrayBuffer>;
|
|
49
41
|
getAudioResourceSize(resourceId: string): Promise<number>;
|
|
50
42
|
/**
|
|
51
|
-
*
|
|
43
|
+
* Open a readable stream for an audio resource file in OPFS.
|
|
52
44
|
*/
|
|
53
|
-
|
|
45
|
+
openAudioResourceReadStream(resourceId: string): Promise<ReadableStream<Uint8Array>>;
|
|
54
46
|
/**
|
|
55
|
-
*
|
|
47
|
+
* Check if an audio resource exists in OPFS and has content.
|
|
56
48
|
*/
|
|
57
|
-
|
|
49
|
+
hasAudioResource(resourceId: string): Promise<boolean>;
|
|
58
50
|
}
|
|
59
51
|
//# sourceMappingURL=ResourceCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceCache.d.ts","sourceRoot":"","sources":["../../../src/cache/resource/ResourceCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAc1D,qBAAa,aAAa;IACxB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM;IAKjD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;OAGG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB1F;;OAEG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,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EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAWhF;;OAEG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAI3D,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIpF,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/D;;OAEG;IACG,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAK1F;;OAEG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAW7D"}
|
|
@@ -91,24 +91,6 @@ class ResourceCache {
|
|
|
91
91
|
const file = await this.opfsManager.getFile(path);
|
|
92
92
|
return file.stream();
|
|
93
93
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Delete a resource from OPFS
|
|
96
|
-
*/
|
|
97
|
-
async deleteResource(resourceId) {
|
|
98
|
-
const fileName = this.getFileName(resourceId);
|
|
99
|
-
const path = {
|
|
100
|
-
projectId: this.projectId,
|
|
101
|
-
prefix: "resource",
|
|
102
|
-
fileName
|
|
103
|
-
};
|
|
104
|
-
await this.opfsManager.deleteFile(path);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Clear all resources for current project
|
|
108
|
-
*/
|
|
109
|
-
async clear() {
|
|
110
|
-
await this.opfsManager.deleteProjectDirectory(this.projectId, "resource");
|
|
111
|
-
}
|
|
112
94
|
getFileName(resourceId, kind = "video") {
|
|
113
95
|
return `${resourceId}.${kind === "audio" ? "mp3" : "mp4"}`;
|
|
114
96
|
}
|
|
@@ -147,6 +129,13 @@ class ResourceCache {
|
|
|
147
129
|
async getAudioResourceSize(resourceId) {
|
|
148
130
|
return await this.opfsManager.getFileSize(this.audioPath(resourceId));
|
|
149
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Open a readable stream for an audio resource file in OPFS.
|
|
134
|
+
*/
|
|
135
|
+
async openAudioResourceReadStream(resourceId) {
|
|
136
|
+
const file = await this.opfsManager.getFile(this.audioPath(resourceId));
|
|
137
|
+
return file.stream();
|
|
138
|
+
}
|
|
150
139
|
/**
|
|
151
140
|
* Check if an audio resource exists in OPFS and has content.
|
|
152
141
|
*/
|
|
@@ -161,12 +150,6 @@ class ResourceCache {
|
|
|
161
150
|
return false;
|
|
162
151
|
}
|
|
163
152
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Delete an audio resource from OPFS.
|
|
166
|
-
*/
|
|
167
|
-
async deleteAudioResource(resourceId) {
|
|
168
|
-
await this.opfsManager.deleteFile(this.audioPath(resourceId));
|
|
169
|
-
}
|
|
170
153
|
}
|
|
171
154
|
export {
|
|
172
155
|
ResourceCache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceCache.js","sources":["../../../src/cache/resource/ResourceCache.ts"],"sourcesContent":["import { OPFSManager } from '../storage/opfs/OPFSManager';\nimport type { OPFSPath } from '../storage/opfs/types';\nimport { OPFSQuotaExceededError } from '../../utils/errors';\n\n/**\n * ResourceCache - Original media resource OPFS cache\n *\n * Stores original media files for on-demand decoding:\n * - video: MP4 files, read by byte range (GOP-level)\n * - audio: encoded files read whole, PCM WAV read by sample-aligned byte ranges\n * Both share the same `resource` OPFS directory; the file extension keeps them apart.\n * Project-level quota management handled by OPFSManager\n */\ntype ResourceKind = 'video' | 'audio';\nexport class ResourceCache {\n readonly opfsManager: OPFSManager;\n readonly projectId: string;\n\n constructor(opfsManager: OPFSManager, projectId: string) {\n this.opfsManager = opfsManager;\n this.projectId = projectId;\n }\n\n async init(): Promise<void> {\n await this.opfsManager.init();\n }\n\n /**\n * Write resource to OPFS (streaming)\n * OPFSManager handles quota management automatically\n */\n async writeResource(resourceId: string, stream: ReadableStream<Uint8Array>): Promise<void> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n try {\n await this.opfsManager.writeFile(path, stream);\n } catch (error) {\n if (error instanceof OPFSQuotaExceededError) {\n if (error.retryable) {\n throw new Error(\n `Failed to write resource ${resourceId}: ${error.message} Please retry with a fresh stream.`\n );\n }\n throw new Error(\n `Failed to write resource ${resourceId}: No space available and no old projects to evict.`\n );\n }\n throw error;\n }\n }\n\n /**\n * Read byte range from resource (for GOP-level access)\n */\n async readRange(resourceId: string, start: number, end: number): Promise<ArrayBuffer> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n return await this.opfsManager.readRange(path, start, end);\n }\n\n /**\n * Check if resource exists in OPFS and has content\n */\n async hasResource(resourceId: string): Promise<boolean> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n // Check if file exists\n const exists = await this.opfsManager.exists(path);\n if (!exists) return false;\n\n // Check file size to avoid empty files (race condition protection)\n try {\n const size = await this.opfsManager.getFileSize(path);\n return size > 0;\n } catch {\n return false;\n }\n }\n\n /**\n * Get resource file size\n */\n async getResourceSize(resourceId: string): Promise<number> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n return await this.opfsManager.getFileSize(path);\n }\n\n /**\n * Open a readable stream for the video resource file in OPFS.\n */\n async openResourceReadStream(resourceId: string): Promise<ReadableStream<Uint8Array>> {\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName: this.getFileName(resourceId),\n };\n const file = await this.opfsManager.getFile(path);\n return file.stream();\n }\n\n
|
|
1
|
+
{"version":3,"file":"ResourceCache.js","sources":["../../../src/cache/resource/ResourceCache.ts"],"sourcesContent":["import { OPFSManager } from '../storage/opfs/OPFSManager';\nimport type { OPFSPath } from '../storage/opfs/types';\nimport { OPFSQuotaExceededError } from '../../utils/errors';\n\n/**\n * ResourceCache - Original media resource OPFS cache\n *\n * Stores original media files for on-demand decoding:\n * - video: MP4 files, read by byte range (GOP-level)\n * - audio: encoded files read whole, PCM WAV read by sample-aligned byte ranges\n * Both share the same `resource` OPFS directory; the file extension keeps them apart.\n * Project-level quota management handled by OPFSManager\n */\ntype ResourceKind = 'video' | 'audio';\nexport class ResourceCache {\n readonly opfsManager: OPFSManager;\n readonly projectId: string;\n\n constructor(opfsManager: OPFSManager, projectId: string) {\n this.opfsManager = opfsManager;\n this.projectId = projectId;\n }\n\n async init(): Promise<void> {\n await this.opfsManager.init();\n }\n\n /**\n * Write resource to OPFS (streaming)\n * OPFSManager handles quota management automatically\n */\n async writeResource(resourceId: string, stream: ReadableStream<Uint8Array>): Promise<void> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n try {\n await this.opfsManager.writeFile(path, stream);\n } catch (error) {\n if (error instanceof OPFSQuotaExceededError) {\n if (error.retryable) {\n throw new Error(\n `Failed to write resource ${resourceId}: ${error.message} Please retry with a fresh stream.`\n );\n }\n throw new Error(\n `Failed to write resource ${resourceId}: No space available and no old projects to evict.`\n );\n }\n throw error;\n }\n }\n\n /**\n * Read byte range from resource (for GOP-level access)\n */\n async readRange(resourceId: string, start: number, end: number): Promise<ArrayBuffer> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n return await this.opfsManager.readRange(path, start, end);\n }\n\n /**\n * Check if resource exists in OPFS and has content\n */\n async hasResource(resourceId: string): Promise<boolean> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n // Check if file exists\n const exists = await this.opfsManager.exists(path);\n if (!exists) return false;\n\n // Check file size to avoid empty files (race condition protection)\n try {\n const size = await this.opfsManager.getFileSize(path);\n return size > 0;\n } catch {\n return false;\n }\n }\n\n /**\n * Get resource file size\n */\n async getResourceSize(resourceId: string): Promise<number> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n return await this.opfsManager.getFileSize(path);\n }\n\n /**\n * Open a readable stream for the video resource file in OPFS.\n */\n async openResourceReadStream(resourceId: string): Promise<ReadableStream<Uint8Array>> {\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName: this.getFileName(resourceId),\n };\n const file = await this.opfsManager.getFile(path);\n return file.stream();\n }\n\n private getFileName(resourceId: string, kind: ResourceKind = 'video'): string {\n return `${resourceId}.${kind === 'audio' ? 'mp3' : 'mp4'}`;\n }\n\n // ── Audio resource (standalone voiceover / BGM) ────────────────────────────\n // Preserve the existing .mp3 OPFS key for all standalone audio containers.\n\n private audioPath(resourceId: string): OPFSPath {\n return {\n projectId: this.projectId,\n prefix: 'resource',\n fileName: this.getFileName(resourceId, 'audio'),\n };\n }\n\n /**\n * Write an audio resource (whole buffer) to OPFS.\n * OPFSManager handles quota management automatically.\n */\n async writeAudioResource(resourceId: string, buffer: ArrayBuffer): Promise<void> {\n try {\n await this.opfsManager.writeFile(this.audioPath(resourceId), buffer);\n } catch (error) {\n if (error instanceof OPFSQuotaExceededError) {\n throw new Error(`Failed to write audio resource ${resourceId}: ${error.message}`);\n }\n throw error;\n }\n }\n\n /**\n * Read a whole audio resource file from OPFS.\n */\n async readAudioResource(resourceId: string): Promise<ArrayBuffer> {\n return await this.opfsManager.readFile(this.audioPath(resourceId));\n }\n\n async readAudioRange(resourceId: string, start: number, end: number): Promise<ArrayBuffer> {\n return await this.opfsManager.readRange(this.audioPath(resourceId), start, end);\n }\n\n async getAudioResourceSize(resourceId: string): Promise<number> {\n return await this.opfsManager.getFileSize(this.audioPath(resourceId));\n }\n\n /**\n * Open a readable stream for an audio resource file in OPFS.\n */\n async openAudioResourceReadStream(resourceId: string): Promise<ReadableStream<Uint8Array>> {\n const file = await this.opfsManager.getFile(this.audioPath(resourceId));\n return file.stream();\n }\n\n /**\n * Check if an audio resource exists in OPFS and has content.\n */\n async hasAudioResource(resourceId: string): Promise<boolean> {\n const path = this.audioPath(resourceId);\n const exists = await this.opfsManager.exists(path);\n if (!exists) return false;\n try {\n const size = await this.opfsManager.getFileSize(path);\n return size > 0;\n } catch {\n return false;\n }\n }\n}\n"],"names":[],"mappings":";AAcO,MAAM,cAAc;AAAA,EAChB;AAAA,EACA;AAAA,EAET,YAAY,aAA0B,WAAmB;AACvD,SAAK,cAAc;AACnB,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,OAAsB;AAC1B,UAAM,KAAK,YAAY,KAAA;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,cAAc,YAAoB,QAAmD;AACzF,UAAM,WAAW,KAAK,YAAY,UAAU;AAC5C,UAAM,OAAiB;AAAA,MACrB,WAAW,KAAK;AAAA,MAChB,QAAQ;AAAA,MACR;AAAA,IAAA;AAGF,QAAI;AACF,YAAM,KAAK,YAAY,UAAU,MAAM,MAAM;AAAA,IAC/C,SAAS,OAAO;AACd,UAAI,iBAAiB,wBAAwB;AAC3C,YAAI,MAAM,WAAW;AACnB,gBAAM,IAAI;AAAA,YACR,4BAA4B,UAAU,KAAK,MAAM,OAAO;AAAA,UAAA;AAAA,QAE5D;AACA,cAAM,IAAI;AAAA,UACR,4BAA4B,UAAU;AAAA,QAAA;AAAA,MAE1C;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAU,YAAoB,OAAe,KAAmC;AACpF,UAAM,WAAW,KAAK,YAAY,UAAU;AAC5C,UAAM,OAAiB;AAAA,MACrB,WAAW,KAAK;AAAA,MAChB,QAAQ;AAAA,MACR;AAAA,IAAA;AAGF,WAAO,MAAM,KAAK,YAAY,UAAU,M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AM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAAE,cA6F5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8BH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;qCAyBmC,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE;;;;;;;;;;;;;;IAezD;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BK,CAAC"}
|
package/dist/config/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sources":["../../src/config/defaults.ts"],"sourcesContent":["import type { ResolvedConfig } from './types';\nimport { CANVAS_PRESETS } from './presets';\n\n/**\n * Detect if running in development mode\n * In dev mode, workers are loaded from source (Vite dev server)\n * In prod mode, workers are loaded from dist\n */\nconst isDev = import.meta.env?.DEV ?? false;\n\n/**\n * Default configuration values based on 1080p30 memory budget\n *\n * Note: Canvas dimensions are fixed for the entire project.\n * All video clips will be scaled/fitted to this resolution.\n * Choose based on your primary content type:\n * - 720×1280: Mobile vertical video\n * - 1080×1920: HD vertical video (TikTok, Instagram Reels) ← default\n * - 1920×1080: HD horizontal video (YouTube)\n */\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n global: {\n projectId: `project-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,\n logLevel: 'info',\n enablePerfMonitor: false,\n defaultCanvasWidth: CANVAS_PRESETS.HD_PORTRAIT.width,\n defaultCanvasHeight: CANVAS_PRESETS.HD_PORTRAIT.height,\n defaultFps: 30,\n workerPath: isDev ? '/src' : '/meframe-workers',\n workerExtension: isDev ? '.ts' : '.js',\n },\n\n load: {\n maxConcurrent: 3,\n backpressure: {\n highWaterMark: 64 * 1024, // 64 KB\n stallTimeoutMs: 500,\n },\n retry: {\n maxAttempts: 3,\n baseDelayMs: 500,\n },\n window: {\n maxInflightPerClip: 1,\n maxInflight: 4,\n chunkSize: 1 * 1024 * 1024, // 1 MB\n },\n },\n\n demux: {\n backpressure: {\n highWaterMark: 10, // 10 EncodedChunks\n },\n },\n\n decode: {\n video: {\n backpressure: {\n highWaterMark: 4, // 4 EncodedVideoChunks\n decodeQueueThreshold: 16, // Pause when decoder has 16+ chunks\n },\n maxGOPs: 4, // Cache 4 GOPs for seeking\n },\n audio: {\n backpressure: {\n highWaterMark: 20, // 20 EncodedAudioChunks\n },\n },\n },\n\n compose: {\n visual: {},\n audio: {\n enableDucking: false, // Default: no ducking\n },\n },\n\n encode: {\n video: {},\n audio: {},\n },\n\n cache: {\n audio: { pcmMaxBytes: 64 * 1024 * 1024, mixMaxBytes: 48 * 1024 * 1024 },\n l1: {\n // 前方 14s(保险取值)。历史沿革:曾硬编码 ±20s(2c4f4da 为吸收音频\n // 5s 小块混音的主线程抖动而加大);音频改为 30s 大块 + 空闲混音后\n // 抖动源已消除。供给节奏为触发距离 6s + 批次 6s(存货峰值 ~12s),\n // 窗口 14s 覆盖峰值并保留抗主线程突发的垫子。\n windowSizeUs: 20_000_000,\n // 后方 2s:已播过的帧只服务小幅回退,实测很少发生,\n // 而前后对称保留会占掉一半内存。\n backwardWindowSizeUs: 2_000_000,\n maxMemoryMB: 2400, // 字节预算保险丝(估算口径RGBA,折实际I420约900MB):普通多层1080p不触发,4K/失控场景兜底,勿设小(会变相收紧窗口引起卡顿)\n },\n l2: {\n autoFill: true,\n fillPriority: 'low' as const,\n },\n opfs: {\n enabled: true,\n resource: {\n evictionPolicy: 'lru' as const,\n },\n l2: {},\n },\n },\n\n mux: {},\n};\n\n/**\n * Tuning presets for common scenarios\n */\nexport const TUNING_PRESETS = {\n /**\n * Low-latency live streaming\n * Minimize buffering for real-time playback\n */\n lowLatency: {\n global: {\n logLevel: 'info' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 16 * 1024, // 16 KB\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 3,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 2,\n decodeQueueThreshold: 4,\n },\n },\n audio: {\n backpressure: {\n highWaterMark: 10,\n },\n },\n },\n },\n\n /**\n * 4K60 playback/export\n * Larger buffers for high bitrate content\n */\n highQuality: {\n global: {\n logLevel: 'info' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 256 * 1024, // 256 KB\n },\n retry: {\n maxAttempts: 3,\n baseDelayMs: 500,\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 20,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 8,\n decodeQueueThreshold: 24,\n },\n codecHints: ['h264', 'hevc'] as ('h264' | 'hevc')[],\n },\n audio: {\n backpressure: {\n highWaterMark: 30,\n },\n },\n },\n cache: {\n l2: {\n quotaGb: 1,\n },\n },\n },\n\n /**\n * Batch offline transcode\n * Maximum throughput, memory not a concern\n */\n offline: {\n global: {\n logLevel: 'warn' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 512 * 1024, // 512 KB\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 25,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 12,\n decodeQueueThreshold: 32,\n },\n },\n audio: {\n backpressure: {\n highWaterMark: 40,\n },\n },\n },\n },\n} as const;\n"],"names":[],"mappings":";AAoBO,MAAM,iBAAiC;AAAA,EAC5C,QAAQ;AAAA,IACN,WAAW,WAAW,KAAK,IAAA,CAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAAA,IAC1E,UAAU;AAAA,IACV,mBAAmB;AAAA,IACnB,oBAAoB,eAAe,YAAY;AAAA,IAC/C,qBAAqB,eAAe,YAAY;AAAA,IAChD,YAAY;AAAA,IACZ,YAA6B;AAAA,IAC7B,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AA,EACP;AAAA,EAGF,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"defaults.js","sources":["../../src/config/defaults.ts"],"sourcesContent":["import type { ResolvedConfig } from './types';\nimport { CANVAS_PRESETS } from './presets';\n\n/**\n * Detect if running in development mode\n * In dev mode, workers are loaded from source (Vite dev server)\n * In prod mode, workers are loaded from dist\n */\nconst isDev = import.meta.env?.DEV ?? false;\n\n/**\n * Default configuration values based on 1080p30 memory budget\n *\n * Note: Canvas dimensions are fixed for the entire project.\n * All video clips will be scaled/fitted to this resolution.\n * Choose based on your primary content type:\n * - 720×1280: Mobile vertical video\n * - 1080×1920: HD vertical video (TikTok, Instagram Reels) ← default\n * - 1920×1080: HD horizontal video (YouTube)\n */\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n global: {\n projectId: `project-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,\n logLevel: 'info',\n enablePerfMonitor: false,\n defaultCanvasWidth: CANVAS_PRESETS.HD_PORTRAIT.width,\n defaultCanvasHeight: CANVAS_PRESETS.HD_PORTRAIT.height,\n defaultFps: 30,\n workerPath: isDev ? '/src' : '/meframe-workers',\n workerExtension: isDev ? '.ts' : '.js',\n },\n\n load: {\n maxConcurrent: 3,\n backpressure: {\n highWaterMark: 64 * 1024, // 64 KB\n stallTimeoutMs: 500,\n },\n retry: {\n maxAttempts: 3,\n baseDelayMs: 500,\n },\n window: {\n maxInflightPerClip: 1,\n maxInflight: 4,\n chunkSize: 1 * 1024 * 1024, // 1 MB\n },\n },\n\n demux: {\n backpressure: {\n highWaterMark: 10, // 10 EncodedChunks\n },\n },\n\n decode: {\n video: {\n backpressure: {\n highWaterMark: 4, // 4 EncodedVideoChunks\n decodeQueueThreshold: 16, // Pause when decoder has 16+ chunks\n },\n maxGOPs: 4, // Cache 4 GOPs for seeking\n },\n audio: {\n backpressure: {\n highWaterMark: 20, // 20 EncodedAudioChunks\n },\n },\n },\n\n compose: {\n visual: {},\n audio: {\n enableDucking: false, // Default: no ducking\n },\n },\n\n encode: {\n video: {},\n audio: {},\n },\n\n cache: {\n audio: { pcmMaxBytes: 64 * 1024 * 1024, mixMaxBytes: 48 * 1024 * 1024 },\n l1: {\n // 前方 14s(保险取值)。历史沿革:曾硬编码 ±20s(2c4f4da 为吸收音频\n // 5s 小块混音的主线程抖动而加大);音频改为 30s 大块 + 空闲混音后\n // 抖动源已消除。供给节奏为触发距离 6s + 批次 6s(存货峰值 ~12s),\n // 窗口 14s 覆盖峰值并保留抗主线程突发的垫子。\n windowSizeUs: 20_000_000,\n // 后方 2s:已播过的帧只服务小幅回退,实测很少发生,\n // 而前后对称保留会占掉一半内存。\n backwardWindowSizeUs: 2_000_000,\n maxMemoryMB: 2400, // 字节预算保险丝(估算口径RGBA,折实际I420约900MB):普通多层1080p不触发,4K/失控场景兜底,勿设小(会变相收紧窗口引起卡顿)\n },\n l2: {\n autoFill: true,\n fillPriority: 'low' as const,\n },\n opfs: {\n enabled: true,\n resource: {\n evictionPolicy: 'lru' as const,\n },\n l2: {},\n },\n },\n\n mux: {},\n\n preview: {\n layerFailure: 'skip-layer',\n },\n};\n\n/**\n * Tuning presets for common scenarios\n */\nexport const TUNING_PRESETS = {\n /**\n * Low-latency live streaming\n * Minimize buffering for real-time playback\n */\n lowLatency: {\n global: {\n logLevel: 'info' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 16 * 1024, // 16 KB\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 3,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 2,\n decodeQueueThreshold: 4,\n },\n },\n audio: {\n backpressure: {\n highWaterMark: 10,\n },\n },\n },\n },\n\n /**\n * 4K60 playback/export\n * Larger buffers for high bitrate content\n */\n highQuality: {\n global: {\n logLevel: 'info' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 256 * 1024, // 256 KB\n },\n retry: {\n maxAttempts: 3,\n baseDelayMs: 500,\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 20,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 8,\n decodeQueueThreshold: 24,\n },\n codecHints: ['h264', 'hevc'] as ('h264' | 'hevc')[],\n },\n audio: {\n backpressure: {\n highWaterMark: 30,\n },\n },\n },\n cache: {\n l2: {\n quotaGb: 1,\n },\n },\n },\n\n /**\n * Batch offline transcode\n * Maximum throughput, memory not a concern\n */\n offline: {\n global: {\n logLevel: 'warn' as const,\n },\n load: {\n backpressure: {\n highWaterMark: 512 * 1024, // 512 KB\n },\n },\n demux: {\n backpressure: {\n highWaterMark: 25,\n },\n },\n decode: {\n video: {\n backpressure: {\n highWaterMark: 12,\n decodeQueueThreshold: 32,\n },\n },\n audio: {\n backpressure: {\n highWaterMark: 40,\n },\n },\n },\n },\n} as const;\n"],"names":[],"mappings":";AAoBO,MAAM,iBAAiC;AAAA,EAC5C,QAAQ;AAAA,IACN,WAAW,WAAW,KAAK,IAAA,CAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAAA,IAC1E,UAAU;AAAA,IACV,mBAAmB;AAAA,IACnB,oBAAoB,eAAe,YAAY;AAAA,IAC/C,qBAAqB,eAAe,YAAY;AAAA,IAChD,YAAY;AAAA,IACZ,YAA6B;AAAA,IAC7B,iBAAiC;AAAA,EAAA;AAAA,EAGnC,MAAM;AAAA,IACJ,eAAe;AAAA,IACf,cAAc;AAAA,MACZ,eAAe,KAAK;AAAA;AAAA,MACpB,gBAAgB;AAAA,IAAA;AAAA,IAElB,OAAO;AAAA,MACL,aAAa;AAAA,MACb,aAAa;AAAA,IAAA;AAAA,IAEf,QAAQ;AAAA,MACN,oBAAoB;AAAA,MACpB,aAAa;AAAA,MACb,WAAW,IAAI,OAAO;AAAA;AAAA,IAAA;AAAA,EACxB;AAAA,EAGF,OAAO;AAAA,IACL,cAAc;AAAA,MACZ,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EAGF,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,cA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ACF;AAAA,EACF;AAEJ;"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { LoadBackpressure, VideoDecodeBackpressure, MeframeConfig, ResolvedConfig, ConfigLoaderOptions, } from './types';
|
|
1
|
+
export type { LoadBackpressure, VideoDecodeBackpressure, MeframeConfig, ResolvedConfig, ConfigLoaderOptions, PreviewLayerFailurePolicy, } from './types';
|
|
2
2
|
export { validateConfig, validateBackpressureValue } from './validation';
|
|
3
3
|
export type { ValidationResult } from './validation';
|
|
4
4
|
export { DEFAULT_CONFIG, TUNING_PRESETS } from './defaults';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|