mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 19:33:51 +02:00
Migrate WAVE demuxer to new packet system
This commit is contained in:
+51
-19
@@ -3,7 +3,7 @@ import { Input } from '../../src/input.js';
|
||||
import { BufferSource, FilePathSource } from '../../src/source.js';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { ALL_FORMATS, MP3, MP4, QTFF, WEBM } from '../../src/input-format.js';
|
||||
import { ALL_FORMATS, MP3, MP4, QTFF, WAVE, WEBM } from '../../src/input-format.js';
|
||||
import { PacketReader } from '../../src/cursors.js';
|
||||
import { InputAudioTrack, InputTrack } from '../../src/input-track.js';
|
||||
import { assert } from '../../src/misc.js';
|
||||
@@ -47,6 +47,24 @@ const testBasicPacketReading = async (track: InputTrack) => {
|
||||
expect(afterLast).toBe(null);
|
||||
};
|
||||
|
||||
const testSyncPacketReading = (track: InputTrack) => {
|
||||
const reader = new PacketReader(track);
|
||||
|
||||
let current = reader.readFirst() as EncodedPacket | null;
|
||||
expect(current).toBeInstanceOf(EncodedPacket);
|
||||
|
||||
let count = 0;
|
||||
while (current) {
|
||||
current = reader.readNext(current) as EncodedPacket | null;
|
||||
expect(current instanceof EncodedPacket || current === null).toBe(true);
|
||||
count++;
|
||||
}
|
||||
|
||||
expect(count).toBeGreaterThan(0);
|
||||
|
||||
return count;
|
||||
};
|
||||
|
||||
test('Regular ISOBMFF demuxing', async () => {
|
||||
using input = new Input({
|
||||
source: new FilePathSource(path.join(__dirname, '../public/trim-buck-bunny.mov')),
|
||||
@@ -177,24 +195,6 @@ test('MP3 demuxing', async () => {
|
||||
expect(duration).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
const testSyncPacketReading = (track: InputTrack) => {
|
||||
const reader = new PacketReader(track);
|
||||
|
||||
let current = reader.readFirst() as EncodedPacket | null;
|
||||
expect(current).toBeInstanceOf(EncodedPacket);
|
||||
|
||||
let count = 0;
|
||||
while (current) {
|
||||
current = reader.readNext(current) as EncodedPacket | null;
|
||||
expect(current instanceof EncodedPacket || current === null).toBe(true);
|
||||
count++;
|
||||
}
|
||||
|
||||
expect(count).toBeGreaterThan(0);
|
||||
|
||||
return count;
|
||||
};
|
||||
|
||||
test('MP3 sync reading', async () => {
|
||||
using input = new Input({
|
||||
source: new BufferSource(fs.readFileSync(path.join(__dirname, '../public/AudacityTest1.mp3'))),
|
||||
@@ -207,3 +207,35 @@ test('MP3 sync reading', async () => {
|
||||
const count = testSyncPacketReading(audioTrack);
|
||||
expect(count).toBe(475);
|
||||
});
|
||||
|
||||
test('WAVE demuxing', async () => {
|
||||
using input = new Input({
|
||||
source: new FilePathSource(path.join(__dirname, '../public/glitch-hop-is-dead.wav')),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
expect(await input.getFormat()).toBe(WAVE);
|
||||
|
||||
const tracks = await input.getTracks();
|
||||
expect(tracks).toHaveLength(1);
|
||||
|
||||
const audioTrack = await input.getPrimaryAudioTrack();
|
||||
assert(audioTrack);
|
||||
|
||||
await testBasicPacketReading(audioTrack);
|
||||
|
||||
expect(await input.computeDuration()).toBeCloseTo(9.637188208616779);
|
||||
});
|
||||
|
||||
test('WAVE sync reading', async () => {
|
||||
using input = new Input({
|
||||
source: new BufferSource(fs.readFileSync(path.join(__dirname, '../public/glitch-hop-is-dead.wav'))),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
const audioTrack = await input.getPrimaryAudioTrack();
|
||||
assert(audioTrack);
|
||||
|
||||
const count = testSyncPacketReading(audioTrack);
|
||||
expect(count).toBe(208);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user