`live record <link> [-o base] [--put --server URL]` writes what a channel carries until the channel ends or Ctrl-C: - text goes to base.txt; - video and sound go to base.webm or base.mp4: the init, then every chunk in the order sent. A chunk that arrives late is left out and counted. A new init continues in base-2.…; - pictures go to base-images/. ffmpeg then rewrites each recording with -c copy, which adds an index for seeking and starts the clock at 0:00. `--put` seals and uploads the recording under the channel's name (several files become an album). LiveRecorder is exported from @shade/media/node. `live video` now sends a sticky meta frame like text and picture channels do. The browser and Android players ignore it. Verified against a real relay: - A 30 s VP8/Opus broadcast was recorded and is 29–32 s long, starting at 0. - It was uploaded as "Kveldssending.webm" and plays in Chromium, with a seek to 22 s (frame 14). - Live playback with the meta frame still plays, with 2.4 s latency. Tests: - object-store's memory test now runs in its own process. RSS is process-wide, and other test files in the same `bun test` made it flaky (192 MiB). It now compares memory held after a collection at 128 MiB and 512 MiB, ~85 vs ~103 MiB, instead of using a magic number. - The sweep test has its own prefix. - tests/live-record.test.ts (4). - media 122 green, 3 runs in a row. All 27 packages type-check. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
41 lines
1.9 KiB
TypeScript
41 lines
1.9 KiB
TypeScript
/**
|
|
* For object-store.test.ts: <mib> MiB through ObjectMediaStore.begin() in a
|
|
* process of its own, so the RSS it reports is this upload's alone and not
|
|
* whatever other test files left for the collector. `retainedMiB` is RSS
|
|
* after a full collection at every 32 MiB written: what the upload holds,
|
|
* not how lazily garbage is returned (`peakMiB`). Prints JSON.
|
|
*
|
|
* bun tests/fixtures/object-upload-rss.ts <s3 url> <prefix> <mib>
|
|
*/
|
|
import { MemoryMediaIndex, ObjectMediaStore, S3Bucket } from '../../src/server.js';
|
|
import { toHex } from '../../src/bytes.js';
|
|
|
|
const [url, prefix, mib] = process.argv.slice(2) as [string, string, string];
|
|
const { bucket: s3 } = S3Bucket.fromUrl(url);
|
|
const store = new ObjectMediaStore(s3, new MemoryMediaIndex(), { prefix, partSize: 8 * 1024 * 1024 });
|
|
const chunk = new Uint8Array(1024 * 1024);
|
|
const total = Number(mib) * 1024 * 1024;
|
|
Bun.gc(true);
|
|
const before = process.memoryUsage().rss;
|
|
let peak = before;
|
|
let retained = before;
|
|
const id = toHex(new Uint8Array(16).fill(0x5a));
|
|
const up = await store.begin(id);
|
|
for (let off = 0; off < total; off += chunk.length) {
|
|
chunk.fill((off / chunk.length) & 0xff);
|
|
await up.write(chunk);
|
|
peak = Math.max(peak, process.memoryUsage().rss);
|
|
if ((off / chunk.length) % 32 === 31) {
|
|
Bun.gc(true);
|
|
retained = Math.max(retained, process.memoryUsage().rss);
|
|
}
|
|
}
|
|
await up.commit({ id, owner: 'o', size: total, readTokenHash: null, createdAt: Date.now() });
|
|
const at = Math.floor(total / 2);
|
|
const body = await store.body(id, at - 1, at + 1);
|
|
const probe = [...new Uint8Array(await new Response(body).arrayBuffer())];
|
|
await store.delete(id);
|
|
const expect = [((at - 1) / chunk.length) & 0xff, (at / chunk.length) & 0xff];
|
|
const MiB = 1024 * 1024;
|
|
console.log(JSON.stringify({ retainedMiB: (retained - before) / MiB, peakMiB: (peak - before) / MiB, readBack: probe.join() === expect.join() }));
|