Move PacketReader elsewhere

This commit is contained in:
Vanilagy
2025-12-30 12:31:33 +01:00
parent ba26367529
commit 51b9de1c6f
17 changed files with 244 additions and 297 deletions
-28
View File
@@ -3,7 +3,6 @@ import { Input } from '../../src/input.js';
import { BufferSource, UrlSource } from '../../src/source.js';
import { ALL_FORMATS } from '../../src/input-format.js';
import {
audioBufferTransformer,
AudioSampleCursor,
canvasTransformer,
VideoSampleCursor,
@@ -1115,33 +1114,6 @@ test('Canvas transformer', async () => {
await cursor2.close();
});
test('AudioBuffer transformer', async () => {
using input = new Input({
source: new UrlSource('/trim-buck-bunny.mov'),
formats: ALL_FORMATS,
});
const audioTrack = (await input.getPrimaryAudioTrack())!;
const cursor = new AudioSampleCursor(audioTrack, {
transform: audioBufferTransformer(),
});
const firstSample = (await cursor.seekToFirst())!;
expect(firstSample.buffer).toBeInstanceOf(AudioBuffer);
expect(firstSample.timestamp).toBe(0);
expect(firstSample.duration).toBeGreaterThan(0);
expect(firstSample.buffer.duration).toBe(firstSample.duration);
const nextSample = (await cursor.next())!;
expect(nextSample.buffer).toBeInstanceOf(AudioBuffer);
expect(nextSample.timestamp).toBeGreaterThan(firstSample.timestamp);
expect(nextSample.buffer).not.toBe(firstSample.buffer);
expect(nextSample.buffer.duration).toBe(nextSample.duration);
await cursor.close();
});
test('Unthrottled decoder', async () => {
// While the decoder is throttled in practice, these tests simulate what happens when the decoder naturally reaches
// the end of the encodable packets without having been stopped; in this case, we still expect the cursor to keep