@meframe/core 0.6.10 → 0.6.12
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 +22 -0
- package/README.md +13 -0
- package/dist/cache/resource/AudioSampleCache.d.ts +7 -1
- package/dist/cache/resource/AudioSampleCache.d.ts.map +1 -1
- package/dist/cache/resource/AudioSampleCache.js +20 -0
- package/dist/cache/resource/AudioSampleCache.js.map +1 -1
- package/dist/cache/resource/ResourceCache.d.ts +2 -0
- package/dist/cache/resource/ResourceCache.d.ts.map +1 -1
- package/dist/cache/resource/ResourceCache.js +7 -2
- package/dist/cache/resource/ResourceCache.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.d.ts +4 -0
- package/dist/orchestrator/AudioWindowPreparer.d.ts.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.js +124 -2
- package/dist/orchestrator/AudioWindowPreparer.js.map +1 -1
- package/dist/orchestrator/ExportScheduler.d.ts.map +1 -1
- package/dist/orchestrator/ExportScheduler.js +1 -1
- package/dist/orchestrator/ExportScheduler.js.map +1 -1
- package/dist/orchestrator/aac-window-timeline.d.ts +12 -0
- package/dist/orchestrator/aac-window-timeline.d.ts.map +1 -0
- package/dist/orchestrator/aac-window-timeline.js +75 -0
- package/dist/orchestrator/aac-window-timeline.js.map +1 -0
- package/dist/stages/demux/WAVIndexParser.d.ts +20 -0
- package/dist/stages/demux/WAVIndexParser.d.ts.map +1 -0
- package/dist/stages/demux/WAVIndexParser.js +113 -0
- package/dist/stages/demux/WAVIndexParser.js.map +1 -0
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +24 -1
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/utils/errors.js +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.12] - 2026-10-15
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Measure anomalously stretched AAC prefix duration and select bounded audio windows on the decoded PCM timeline. Fragmented MP4 audio now covers a two-second export and cold seeks retain synthesis preroll; missing interior packets still fail the PCM coverage guard (issue #30).
|
|
15
|
+
|
|
16
|
+
## [0.6.11] - 2026-10-13
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Support little-endian RIFF/WAVE integer PCM (8/16/24/32-bit), IEEE float (32/64-bit), and matching extensible subformats for playback and export (issue #27). Retain only an OPFS index and decode bounded PCM windows under the existing audio cache budget.
|
|
21
|
+
- Accept RIFF/data length placeholders of `0` or `0xFFFFFFFF` from non-seekable WAV writers. Ignore inconsistent advisory byteRate with a warning. Explicitly sized, truncated PCM or headers still fail validation; sized data excludes trailing metadata.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Recognize WAV audio during export even though its index retains no encoded payload bytes.
|
|
26
|
+
- Coalesce consecutive WAV cache misses into bounded OPFS reads while retaining reusable PCM slots and cancellation checks.
|
|
27
|
+
|
|
28
|
+
### Integration
|
|
29
|
+
|
|
30
|
+
- Audio format/parser errors now preserve cached source bytes and report their original error. Unsupported audio formats report a terminal `UnsupportedAudioContainerError` so preview can skip that audio rather than fail model readiness with a misleading `ResourceNotCachedError`; strict export still fails. This also applies to unrecognized MP3 input. Missing/corrupt OPFS recovery remains separate.
|
|
31
|
+
|
|
10
32
|
## [0.6.10] - 2026-10-12
|
|
11
33
|
|
|
12
34
|
### Fixed
|
package/README.md
CHANGED
|
@@ -62,6 +62,19 @@ export default defineConfig({
|
|
|
62
62
|
失败通过 `export:error` 和导出 Promise 上报。`ResourceSupersededError` 表示
|
|
63
63
|
处理期间资源被替换,不能按用户主动取消的 `AbortError` 忽略。
|
|
64
64
|
|
|
65
|
+
独立音频支持 MP3、MP4/M4A 和小端 RIFF/WAVE:整数 PCM 8/16/24/32 位、
|
|
66
|
+
IEEE 浮点 PCM 32/64 位,以及对应的 WAVE_FORMAT_EXTENSIBLE 子格式。
|
|
67
|
+
格式按文件内容识别,WAV 仍通过 `writeAudioResource` 交付,不需要修改宿主接口。
|
|
68
|
+
WAV 只加载格式和数据位置索引,播放、Seek、循环、倍速和导出按窗口读取 PCM,
|
|
69
|
+
继续受 `cache.audio.pcmMaxBytes` 限制,不将整份 WAV 或全量 PCM 留在内存。
|
|
70
|
+
压缩 WAV(如 ADPCM)、RIFX 和 RF64 暂不支持,会报告 `UnsupportedAudioContainerError`,
|
|
71
|
+
保留已交付的源文件。
|
|
72
|
+
|
|
73
|
+
兼容流式写出器未回填的 RIFF/data 长度(`0` 或 `0xFFFFFFFF`),按容器剩余字节
|
|
74
|
+
计算完整采样帧;这种文件要求 `fmt` 在 `data` 前,且 `data` 延续至容器末尾。
|
|
75
|
+
`byteRate` 不一致时记录警告,实际时长按采样率与完整帧数计算。明确声明长度的
|
|
76
|
+
截断数据、损坏块头仍会报错;正常文件的尾部元数据不作为 PCM 读取。
|
|
77
|
+
|
|
65
78
|
```typescript
|
|
66
79
|
import { Meframe } from '@meframe/core';
|
|
67
80
|
import { parseDSL } from '@meframe/dsl-parser'; // 可选:DSL 解析
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TimeUs } from '../../model/types';
|
|
2
|
+
import { WAVIndex } from '../../stages/demux/WAVIndexParser';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 无缝播放(gapless)裁剪参数:MP3/LAME 编码的解码输出首尾含编码器预填充
|
|
@@ -18,21 +19,26 @@ export interface AudioSampleRecord {
|
|
|
18
19
|
totalBytes: number;
|
|
19
20
|
durationUs: TimeUs;
|
|
20
21
|
gapless?: GaplessTrim;
|
|
22
|
+
/** WAV sources retain only an OPFS index; samples are read on demand. */
|
|
23
|
+
pcm?: WAVIndex;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* AudioSampleCache - Resource-level audio sample cache
|
|
24
27
|
*
|
|
25
|
-
* Caches
|
|
28
|
+
* Caches encoded audio samples from MP4/MP3, or a small WAV PCM index
|
|
26
29
|
* Audio data is small (~100KB for 30s AAC, ~6MB for 30min)
|
|
27
30
|
*
|
|
28
31
|
* Strategy:
|
|
29
32
|
* - Extract all audio samples during moov parsing (one-time cost)
|
|
30
33
|
* - Keep encoded chunks in memory (compressed)
|
|
31
34
|
* - Decode to PCM on-demand when clip is played
|
|
35
|
+
* - Keep WAV payload in OPFS and read only requested PCM blocks
|
|
32
36
|
*/
|
|
33
37
|
export declare class AudioSampleCache {
|
|
34
38
|
get size(): number;
|
|
35
39
|
private cache;
|
|
40
|
+
hasAudioData(): boolean;
|
|
41
|
+
setPCM(resourceId: string, pcm: WAVIndex): void;
|
|
36
42
|
/**
|
|
37
43
|
* Set audio samples for a resource
|
|
38
44
|
*/
|
|
@@ -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;
|
|
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;AAElE;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,yEAAyE;IACzE,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAgB;IAC3B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,KAAK,CAAwC;IAErD,YAAY,IAAI,OAAO;IAOvB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI;IAe/C;;OAEG;IACH,GAAG,CACD,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iBAAiB,EAAE,EAC5B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE,WAAW,GACpB,IAAI;IAuBP;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;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;IAc1F;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAShC;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,aAAa,IAAI,MAAM;CAOxB"}
|
|
@@ -3,6 +3,26 @@ class AudioSampleCache {
|
|
|
3
3
|
return this.cache.size;
|
|
4
4
|
}
|
|
5
5
|
cache = /* @__PURE__ */ new Map();
|
|
6
|
+
hasAudioData() {
|
|
7
|
+
for (const record of this.cache.values()) {
|
|
8
|
+
if (record.totalBytes > 0 || (record.pcm?.numberOfFrames ?? 0) > 0) return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
setPCM(resourceId, pcm) {
|
|
13
|
+
this.cache.set(resourceId, {
|
|
14
|
+
resourceId,
|
|
15
|
+
samples: [],
|
|
16
|
+
metadata: {
|
|
17
|
+
codec: "pcm",
|
|
18
|
+
sampleRate: pcm.sampleRate,
|
|
19
|
+
numberOfChannels: pcm.numberOfChannels
|
|
20
|
+
},
|
|
21
|
+
totalBytes: 0,
|
|
22
|
+
durationUs: Math.round(pcm.numberOfFrames * 1e6 / pcm.sampleRate),
|
|
23
|
+
pcm
|
|
24
|
+
});
|
|
25
|
+
}
|
|
6
26
|
/**
|
|
7
27
|
* Set audio samples for a resource
|
|
8
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioSampleCache.js","sources":["../../../src/cache/resource/AudioSampleCache.ts"],"sourcesContent":["import type { TimeUs } from '../../model/types';\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}\n\n/**\n * AudioSampleCache - Resource-level audio sample cache\n *\n * Caches
|
|
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 || (record.pcm?.numberOfFrames ?? 0) > 0) return true;\n }\n return false;\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 return record.samples.filter((s) => {\n const sampleEndUs = s.timestamp + (s.duration ?? 0);\n // Include sample if it overlaps with range\n return s.timestamp < endUs + offsetUs && sampleEndUs > startUs + offsetUs;\n });\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":"AAsCO,MAAM,iBAAiB;AAAA,EAC5B,IAAI,OAAe;AACjB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEQ,4BAAY,IAAA;AAAA,EAEpB,eAAwB;AACt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AA;AAAA;AAAA,EAKA,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,WAAO,OAAO,QAAQ,OAAO,CAAC,MAAM;AAClC,YAAM,cAAc,EAAE,aAAa,EAAE,YAAY;AAEjD,aAAO,EAAE,YAAY,QAAQ,YAAY,cAAc,UAAU;AAAA,IACnE,CAAC;AAAA,EACH;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;"}
|
|
@@ -45,6 +45,8 @@ export declare class ResourceCache {
|
|
|
45
45
|
* Read a whole audio resource file from OPFS.
|
|
46
46
|
*/
|
|
47
47
|
readAudioResource(resourceId: string): Promise<ArrayBuffer>;
|
|
48
|
+
readAudioRange(resourceId: string, start: number, end: number): Promise<ArrayBuffer>;
|
|
49
|
+
getAudioResourceSize(resourceId: string): Promise<number>;
|
|
48
50
|
/**
|
|
49
51
|
* Check if an audio resource exists in OPFS and has content.
|
|
50
52
|
*/
|
|
@@ -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,CAA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
|
@@ -113,8 +113,7 @@ class ResourceCache {
|
|
|
113
113
|
return `${resourceId}.${kind === "audio" ? "mp3" : "mp4"}`;
|
|
114
114
|
}
|
|
115
115
|
// ── Audio resource (standalone voiceover / BGM) ────────────────────────────
|
|
116
|
-
//
|
|
117
|
-
// file rather than byte ranges. Same `resource` prefix, distinct extension.
|
|
116
|
+
// Preserve the existing .mp3 OPFS key for all standalone audio containers.
|
|
118
117
|
audioPath(resourceId) {
|
|
119
118
|
return {
|
|
120
119
|
projectId: this.projectId,
|
|
@@ -142,6 +141,12 @@ class ResourceCache {
|
|
|
142
141
|
async readAudioResource(resourceId) {
|
|
143
142
|
return await this.opfsManager.readFile(this.audioPath(resourceId));
|
|
144
143
|
}
|
|
144
|
+
async readAudioRange(resourceId, start, end) {
|
|
145
|
+
return await this.opfsManager.readRange(this.audioPath(resourceId), start, end);
|
|
146
|
+
}
|
|
147
|
+
async getAudioResourceSize(resourceId) {
|
|
148
|
+
return await this.opfsManager.getFileSize(this.audioPath(resourceId));
|
|
149
|
+
}
|
|
145
150
|
/**
|
|
146
151
|
* Check if an audio resource exists in OPFS and has content.
|
|
147
152
|
*/
|
|
@@ -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:
|
|
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 /**\n * Delete a resource from OPFS\n */\n async deleteResource(resourceId: string): Promise<void> {\n const fileName = this.getFileName(resourceId);\n const path: OPFSPath = {\n projectId: this.projectId,\n prefix: 'resource',\n fileName,\n };\n\n await this.opfsManager.deleteFile(path);\n }\n\n /**\n * Clear all resources for current project\n */\n async clear(): Promise<void> {\n await this.opfsManager.deleteProjectDirectory(this.projectId, 'resource');\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 * 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 /**\n * Delete an audio resource from OPFS.\n */\n async deleteAudioResource(resourceId: string): Promise<void> {\n await this.opfsManager.deleteFile(this.audioPath(resourceId));\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,K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,OAAO;AAAA,IAChB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAoB,YAAmC;AAC3D,UAAM,KAAK,YAAY,WAAW,KAAK,UAAU,UAAU,CAAC;AAAA,EAC9D;AACF;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export { ResourceNotCachedError, ResourceCorruptedError, ResourceSupersededError
|
|
|
16
16
|
export type { EnsureResourceCachedContext, EnsureResourceCachedHandler, ResourceCacheAdapters, ResourceNetworkPolicy, VideoParseStreamHandler, } from './stages/load/types';
|
|
17
17
|
export { BrowserCompatibilityError } from './utils/errors';
|
|
18
18
|
export type { MeframeOpfsGateway } from './cache/storage/opfs/gateway';
|
|
19
|
-
export declare const VERSION = "0.
|
|
19
|
+
export declare const VERSION = "0.6.12";
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,KAAK,EACL,IAAI,EACJ,SAAS,EACT,SAAS,EACT,WAAW,EACX,QAAQ,EACR,MAAM,EACN,UAAU,EACV,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,WAAW,GACZ,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG7D,YAAY,EAAE,MAAM,EAAE,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MAAM,iBAAiB,CAAC;AAG1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { CompositionModel } from "./model/CompositionModel.js";
|
|
|
4
4
|
import { computeCaptionLayout } from "./stages/compose/text-utils/caption-layout.js";
|
|
5
5
|
import { checkCanvasDPI, createHiDPICanvas, setupCanvasDPI } from "./utils/canvas-utils.js";
|
|
6
6
|
import { BrowserCompatibilityError, ResourceCorruptedError, ResourceNotCachedError, ResourceSupersededError } from "./utils/errors.js";
|
|
7
|
-
const VERSION = "0.
|
|
7
|
+
const VERSION = "0.6.12";
|
|
8
8
|
export {
|
|
9
9
|
BrowserCompatibilityError,
|
|
10
10
|
CompositionModel,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * @meframe/core - Next generation media processing framework\n * Based on WebCodecs API for high-performance video/audio processing\n */\n\n// Core exports\nexport { Meframe } from './Meframe';\nexport type { MeframeConfig, MeframeState } from './types';\nexport { MeframeEvent } from './event/events';\n\n// Model exports\nexport { CompositionModel } from './model/CompositionModel';\nexport type {\n CompositionModelData,\n CompositionPatch,\n DirtyRange,\n TimeUs,\n Track,\n Clip,\n VideoClip,\n AudioClip,\n CaptionClip,\n Resource,\n Effect,\n Transition,\n Attachment,\n AnimationEffect,\n AnimationKeyframe,\n Transform2D,\n} from './model/types';\n\n// Cache exports\nexport type { CacheConfig, CacheStats } from './cache/types';\n\n// Plugin exports\nexport type { Plugin, PluginHook } from './plugins/types';\n\n// Caption layout exports\nexport { computeCaptionLayout } from './stages/compose/text-utils/caption-layout';\nexport type {\n CaptionLayoutInput,\n CaptionLayout,\n CaptionLine,\n CaptionWord,\n CaptionStyle,\n CaptionContainer,\n} from './stages/compose/text-utils/caption-layout';\n\n// Utility exports\nexport { setupCanvasDPI, createHiDPICanvas, checkCanvasDPI } from './utils/canvas-utils';\nexport {\n ResourceNotCachedError,\n ResourceCorruptedError,\n ResourceSupersededError,\n} from './utils/errors';\nexport type {\n EnsureResourceCachedContext,\n EnsureResourceCachedHandler,\n ResourceCacheAdapters,\n ResourceNetworkPolicy,\n VideoParseStreamHandler,\n} from './stages/load/types';\n\nexport { BrowserCompatibilityError } from './utils/errors';\nexport type { MeframeOpfsGateway } from './cache/storage/opfs/gateway';\n\n// Re-export version\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * @meframe/core - Next generation media processing framework\n * Based on WebCodecs API for high-performance video/audio processing\n */\n\n// Core exports\nexport { Meframe } from './Meframe';\nexport type { MeframeConfig, MeframeState } from './types';\nexport { MeframeEvent } from './event/events';\n\n// Model exports\nexport { CompositionModel } from './model/CompositionModel';\nexport type {\n CompositionModelData,\n CompositionPatch,\n DirtyRange,\n TimeUs,\n Track,\n Clip,\n VideoClip,\n AudioClip,\n CaptionClip,\n Resource,\n Effect,\n Transition,\n Attachment,\n AnimationEffect,\n AnimationKeyframe,\n Transform2D,\n} from './model/types';\n\n// Cache exports\nexport type { CacheConfig, CacheStats } from './cache/types';\n\n// Plugin exports\nexport type { Plugin, PluginHook } from './plugins/types';\n\n// Caption layout exports\nexport { computeCaptionLayout } from './stages/compose/text-utils/caption-layout';\nexport type {\n CaptionLayoutInput,\n CaptionLayout,\n CaptionLine,\n CaptionWord,\n CaptionStyle,\n CaptionContainer,\n} from './stages/compose/text-utils/caption-layout';\n\n// Utility exports\nexport { setupCanvasDPI, createHiDPICanvas, checkCanvasDPI } from './utils/canvas-utils';\nexport {\n ResourceNotCachedError,\n ResourceCorruptedError,\n ResourceSupersededError,\n} from './utils/errors';\nexport type {\n EnsureResourceCachedContext,\n EnsureResourceCachedHandler,\n ResourceCacheAdapters,\n ResourceNetworkPolicy,\n VideoParseStreamHandler,\n} from './stages/load/types';\n\nexport { BrowserCompatibilityError } from './utils/errors';\nexport type { MeframeOpfsGateway } from './cache/storage/opfs/gateway';\n\n// Re-export version\nexport const VERSION = '0.6.12';\n"],"names":[],"mappings":";;;;;;AAmEO,MAAM,UAAU;"}
|
|
@@ -6,6 +6,7 @@ import { EventPayloadMap } from '../event/events';
|
|
|
6
6
|
import { CacheManager } from '../cache/CacheManager';
|
|
7
7
|
import { AudioSampleRecord } from '../cache/resource/AudioSampleCache';
|
|
8
8
|
import { RequestMode } from './types';
|
|
9
|
+
import { AACWindowTimeline } from './aac-window-timeline';
|
|
9
10
|
|
|
10
11
|
interface AudioWindowPreparerDeps {
|
|
11
12
|
cacheManager: CacheManager;
|
|
@@ -21,6 +22,7 @@ export interface AudioSourceSnapshot {
|
|
|
21
22
|
export interface PreparedAudioSource extends AudioSourceSnapshot {
|
|
22
23
|
record: AudioSampleRecord;
|
|
23
24
|
cacheKey: string;
|
|
25
|
+
aacTimeline?: AACWindowTimeline;
|
|
24
26
|
}
|
|
25
27
|
export type AudioPCM = {
|
|
26
28
|
planes: Float32Array[];
|
|
@@ -39,6 +41,7 @@ export declare class AudioWindowPreparer {
|
|
|
39
41
|
private decoding;
|
|
40
42
|
private recordIds;
|
|
41
43
|
private nextRecordId;
|
|
44
|
+
private aacTimelines;
|
|
42
45
|
private lifecycle;
|
|
43
46
|
get generation(): number;
|
|
44
47
|
getStats(): {
|
|
@@ -86,6 +89,7 @@ export declare class AudioWindowPreparer {
|
|
|
86
89
|
* Decode audio window for a clip
|
|
87
90
|
*/
|
|
88
91
|
private decodeAudioWindow;
|
|
92
|
+
private decodeWavWindow;
|
|
89
93
|
/** Restore two synthesis frames plus their maximum bit reservoir before a seek. */
|
|
90
94
|
private mp3PrerollStart;
|
|
91
95
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioWindowPreparer.d.ts","sourceRoot":"","sources":["../../src/orchestrator/AudioWindowPreparer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"AudioWindowPreparer.d.ts","sourceRoot":"","sources":["../../src/orchestrator/AudioWindowPreparer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAA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EAAE,WAAW,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAC5E,OAAO,CAAC,IAAI,CAAC;IAiIhB;;OAEG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,OAAe,GAC1B,OAAO,CAAC,IAAI,CAAC;IAiBhB;;OAEG;YACW,iBAAiB;YAgIjB,eAAe;IAqF7B,mFAAmF;IACnF,OAAO,CAAC,eAAe;IAgBvB;;;OAGG;YACW,mBAAmB;IAgBjC;;OAEG;YACW,kBAAkB;IA2GhC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAqBzB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { MeframeEvent } from "../event/events.js";
|
|
2
2
|
import { AudioChunkDecoder } from "../stages/decode/AudioChunkDecoder.js";
|
|
3
|
+
import { decodeWavPCM } from "../stages/demux/WAVIndexParser.js";
|
|
3
4
|
import { hasResourceId, isAudioClip, clipPlaybackRate } from "../model/types.js";
|
|
4
5
|
import { buildLoopedResourceSegments } from "../utils/loop-utils.js";
|
|
5
6
|
import { isTerminalMediaResourceError } from "../utils/errors.js";
|
|
7
|
+
import { prepareAACTimeline, getAACWindow } from "./aac-window-timeline.js";
|
|
6
8
|
class AudioWindowPreparer {
|
|
7
9
|
activeClips = /* @__PURE__ */ new Set();
|
|
8
10
|
/** 解码确定失败的 clip(坏包等):本会话不再重试,避免重试风暴;reset 清空 */
|
|
@@ -15,6 +17,7 @@ class AudioWindowPreparer {
|
|
|
15
17
|
decoding = 0;
|
|
16
18
|
recordIds = /* @__PURE__ */ new WeakMap();
|
|
17
19
|
nextRecordId = 0;
|
|
20
|
+
aacTimelines = /* @__PURE__ */ new WeakMap();
|
|
18
21
|
lifecycle = new AbortController();
|
|
19
22
|
get generation() {
|
|
20
23
|
return this.revision;
|
|
@@ -76,7 +79,37 @@ class AudioWindowPreparer {
|
|
|
76
79
|
}
|
|
77
80
|
const cacheKey = JSON.stringify([resource.id, resource.uri, recordId]);
|
|
78
81
|
this.deps.cacheManager.setAudioSource(clip.id, cacheKey);
|
|
79
|
-
|
|
82
|
+
let pendingTimeline = this.aacTimelines.get(record);
|
|
83
|
+
if (!pendingTimeline) {
|
|
84
|
+
pendingTimeline = this.decodeQueue.then(async () => {
|
|
85
|
+
this.decoding++;
|
|
86
|
+
try {
|
|
87
|
+
return await prepareAACTimeline(record);
|
|
88
|
+
} finally {
|
|
89
|
+
this.decoding--;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
this.decodeQueue = pendingTimeline.then(
|
|
93
|
+
() => void 0,
|
|
94
|
+
() => void 0
|
|
95
|
+
);
|
|
96
|
+
this.aacTimelines.set(record, pendingTimeline);
|
|
97
|
+
}
|
|
98
|
+
let aacTimeline;
|
|
99
|
+
try {
|
|
100
|
+
aacTimeline = await pendingTimeline;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.checkCurrent(source);
|
|
103
|
+
await this.handleDecodeFailure(clip.id, error, strictMode);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
this.checkCurrent(source);
|
|
107
|
+
return {
|
|
108
|
+
...source,
|
|
109
|
+
record: aacTimeline ? { ...record, durationUs: aacTimeline.durationUs } : record,
|
|
110
|
+
cacheKey,
|
|
111
|
+
aacTimeline
|
|
112
|
+
};
|
|
80
113
|
}
|
|
81
114
|
maxReadDurationUs(source) {
|
|
82
115
|
const bytesPerSecond = source.record.metadata.sampleRate * source.record.metadata.numberOfChannels * 4;
|
|
@@ -379,6 +412,24 @@ class AudioWindowPreparer {
|
|
|
379
412
|
if (!audioRecord) {
|
|
380
413
|
return;
|
|
381
414
|
}
|
|
415
|
+
if (audioRecord.pcm) {
|
|
416
|
+
try {
|
|
417
|
+
await this.decodeWavWindow(
|
|
418
|
+
clipId,
|
|
419
|
+
audioRecord,
|
|
420
|
+
startUs,
|
|
421
|
+
endUs,
|
|
422
|
+
clip.durationUs,
|
|
423
|
+
clip.startUs,
|
|
424
|
+
source
|
|
425
|
+
);
|
|
426
|
+
} catch (error) {
|
|
427
|
+
if (source) this.checkCurrent(source);
|
|
428
|
+
if (error instanceof RangeError) throw error;
|
|
429
|
+
await this.handleDecodeFailure(clipId, error, strictMode);
|
|
430
|
+
}
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
382
433
|
if (audioRecord.gapless) {
|
|
383
434
|
const { skipSamples, trimEndSamples, samplesPerFrame } = audioRecord.gapless;
|
|
384
435
|
const sampleRate = audioRecord.metadata.sampleRate;
|
|
@@ -416,7 +467,7 @@ class AudioWindowPreparer {
|
|
|
416
467
|
);
|
|
417
468
|
return;
|
|
418
469
|
}
|
|
419
|
-
const windowChunks = audioRecord.samples.filter((s) => {
|
|
470
|
+
const windowChunks = source?.aacTimeline ? getAACWindow(audioRecord.samples, source.aacTimeline, startUs, endUs) : audioRecord.samples.filter((s) => {
|
|
420
471
|
const sampleEndUs = s.timestamp + (s.duration ?? 0);
|
|
421
472
|
return s.timestamp < endUs && sampleEndUs > startUs;
|
|
422
473
|
});
|
|
@@ -434,6 +485,77 @@ class AudioWindowPreparer {
|
|
|
434
485
|
source
|
|
435
486
|
);
|
|
436
487
|
}
|
|
488
|
+
async decodeWavWindow(clipId, record, startUs, endUs, clipDurationUs, clipStartUs, source) {
|
|
489
|
+
const index = record.pcm;
|
|
490
|
+
const first = Math.max(0, Math.floor(startUs * index.sampleRate / 1e6));
|
|
491
|
+
const last = Math.min(index.numberOfFrames, Math.ceil(endUs * index.sampleRate / 1e6));
|
|
492
|
+
const blockFrames = Math.max(
|
|
493
|
+
1,
|
|
494
|
+
Math.min(
|
|
495
|
+
2048,
|
|
496
|
+
Math.floor(
|
|
497
|
+
this.deps.cacheManager.getAudioCacheStats().maxBytes / (16 * index.numberOfChannels * 4)
|
|
498
|
+
)
|
|
499
|
+
)
|
|
500
|
+
);
|
|
501
|
+
const maxReadBytes = Math.max(
|
|
502
|
+
blockFrames * index.blockAlign,
|
|
503
|
+
Math.min(256 * 1024, Math.floor(this.deps.cacheManager.getAudioCacheStats().maxBytes / 8))
|
|
504
|
+
);
|
|
505
|
+
const batchFrames = blockFrames * Math.max(1, Math.floor(maxReadBytes / (blockFrames * index.blockAlign)));
|
|
506
|
+
const cacheKey = source?.cacheKey ?? clipId;
|
|
507
|
+
const covered = (frame) => this.deps.cacheManager.getAudioRangeCoverage(
|
|
508
|
+
cacheKey,
|
|
509
|
+
Math.round(frame * 1e6 / index.sampleRate),
|
|
510
|
+
Math.round(
|
|
511
|
+
Math.min(index.numberOfFrames, frame + blockFrames) * 1e6 / index.sampleRate
|
|
512
|
+
),
|
|
513
|
+
0.99
|
|
514
|
+
).covered;
|
|
515
|
+
for (let frame = Math.floor(first / blockFrames) * blockFrames; frame < last; ) {
|
|
516
|
+
if (source) this.checkCurrent(source);
|
|
517
|
+
if (covered(frame)) {
|
|
518
|
+
frame += blockFrames;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
let batchEnd = Math.min(index.numberOfFrames, frame + blockFrames);
|
|
522
|
+
while (batchEnd < last && batchEnd - frame < batchFrames && !covered(batchEnd))
|
|
523
|
+
batchEnd = Math.min(index.numberOfFrames, batchEnd + blockFrames);
|
|
524
|
+
const bytes = await this.deps.cacheManager.resourceCache.readAudioRange(
|
|
525
|
+
record.resourceId,
|
|
526
|
+
index.dataOffset + frame * index.blockAlign,
|
|
527
|
+
index.dataOffset + batchEnd * index.blockAlign
|
|
528
|
+
);
|
|
529
|
+
if (source) this.checkCurrent(source);
|
|
530
|
+
if (bytes.byteLength !== (batchEnd - frame) * index.blockAlign)
|
|
531
|
+
throw new Error("Truncated WAV PCM range");
|
|
532
|
+
for (let slot = frame; slot < batchEnd; slot += blockFrames) {
|
|
533
|
+
if (source) this.checkCurrent(source);
|
|
534
|
+
const end = Math.min(batchEnd, slot + blockFrames);
|
|
535
|
+
const timestamp = Math.round(slot * 1e6 / index.sampleRate);
|
|
536
|
+
const range = new Uint8Array(
|
|
537
|
+
bytes,
|
|
538
|
+
(slot - frame) * index.blockAlign,
|
|
539
|
+
(end - slot) * index.blockAlign
|
|
540
|
+
);
|
|
541
|
+
const data = new AudioData({
|
|
542
|
+
format: "f32-planar",
|
|
543
|
+
sampleRate: index.sampleRate,
|
|
544
|
+
numberOfChannels: index.numberOfChannels,
|
|
545
|
+
numberOfFrames: end - slot,
|
|
546
|
+
timestamp,
|
|
547
|
+
data: decodeWavPCM(index, range).buffer
|
|
548
|
+
});
|
|
549
|
+
this.deps.cacheManager.putClipAudioData(
|
|
550
|
+
cacheKey,
|
|
551
|
+
data,
|
|
552
|
+
clipDurationUs,
|
|
553
|
+
clipStartUs + timestamp
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
frame = batchEnd;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
437
559
|
/** Restore two synthesis frames plus their maximum bit reservoir before a seek. */
|
|
438
560
|
mp3PrerollStart(record, first) {
|
|
439
561
|
let start = Math.max(0, first - 2);
|