mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Ensure extensions work with huge timestamps, fix AC3 and AAC extension's behavior with huge timestamps
This commit is contained in:
@@ -14,6 +14,7 @@ import { AudioSampleSource } from '../../src/media-source.js';
|
||||
import { Mp4OutputFormat } from '../../src/output-format.js';
|
||||
import { AudioSample } from '../../src/sample.js';
|
||||
import { registerAc3Decoder, registerAc3Encoder } from '@mediabunny/ac3';
|
||||
import { assert } from '../../src/misc.js';
|
||||
|
||||
const __dirname = new URL('.', import.meta.url).pathname;
|
||||
|
||||
@@ -329,3 +330,101 @@ test('E-AC-3 encoding', async () => {
|
||||
|
||||
expect(await track.computeDuration()).toBeCloseTo(2, 1);
|
||||
});
|
||||
|
||||
test('AC-3 with huge timestamps', async () => {
|
||||
registerAc3Decoder();
|
||||
registerAc3Encoder();
|
||||
|
||||
const sampleRate = 48000;
|
||||
const channels = 2;
|
||||
const timestamp = 1e9;
|
||||
const durationSeconds = 2;
|
||||
const data = createSineWave(sampleRate, channels, durationSeconds);
|
||||
|
||||
const output = new Output({
|
||||
format: new Mp4OutputFormat({ fastStart: 'fragmented' }),
|
||||
target: new BufferTarget(),
|
||||
});
|
||||
|
||||
const audioSource = new AudioSampleSource({ codec: 'ac3', bitrate: 192000 });
|
||||
output.addAudioTrack(audioSource);
|
||||
|
||||
await output.start();
|
||||
await audioSource.add(new AudioSample({
|
||||
data,
|
||||
format: 'f32',
|
||||
numberOfChannels: channels,
|
||||
sampleRate,
|
||||
timestamp,
|
||||
}));
|
||||
audioSource.close();
|
||||
await output.finalize();
|
||||
|
||||
using input = new Input({
|
||||
source: new BufferSource(output.target.buffer!),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
const track = (await input.getPrimaryAudioTrack())!;
|
||||
const packetSink = new EncodedPacketSink(track);
|
||||
const firstPacket = await packetSink.getFirstPacket();
|
||||
assert(firstPacket);
|
||||
|
||||
expect(firstPacket.timestamp).toBe(timestamp);
|
||||
|
||||
const sampleSink = new AudioSampleSink(track);
|
||||
const iterator = sampleSink.samples(timestamp);
|
||||
const firstSample = (await iterator.next()).value;
|
||||
assert(firstSample);
|
||||
|
||||
expect(firstSample.timestamp).toBe(timestamp);
|
||||
});
|
||||
|
||||
test('E-AC-3 with huge timestamps', async () => {
|
||||
registerAc3Decoder();
|
||||
registerAc3Encoder();
|
||||
|
||||
const sampleRate = 48000;
|
||||
const channels = 2;
|
||||
const timestamp = 1e9;
|
||||
const durationSeconds = 2;
|
||||
const data = createSineWave(sampleRate, channels, durationSeconds);
|
||||
|
||||
const output = new Output({
|
||||
format: new Mp4OutputFormat({ fastStart: 'fragmented' }),
|
||||
target: new BufferTarget(),
|
||||
});
|
||||
|
||||
const audioSource = new AudioSampleSource({ codec: 'eac3', bitrate: 192000 });
|
||||
output.addAudioTrack(audioSource);
|
||||
|
||||
await output.start();
|
||||
await audioSource.add(new AudioSample({
|
||||
data,
|
||||
format: 'f32',
|
||||
numberOfChannels: channels,
|
||||
sampleRate,
|
||||
timestamp,
|
||||
}));
|
||||
audioSource.close();
|
||||
await output.finalize();
|
||||
|
||||
using input = new Input({
|
||||
source: new BufferSource(output.target.buffer!),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
const track = (await input.getPrimaryAudioTrack())!;
|
||||
const packetSink = new EncodedPacketSink(track);
|
||||
const firstPacket = await packetSink.getFirstPacket();
|
||||
assert(firstPacket);
|
||||
|
||||
expect(firstPacket.timestamp).toBe(timestamp);
|
||||
|
||||
const sampleSink = new AudioSampleSink(track);
|
||||
const iterator = sampleSink.samples(timestamp);
|
||||
const firstSample = (await iterator.next()).value;
|
||||
assert(firstSample);
|
||||
|
||||
expect(firstSample.timestamp).toBe(timestamp);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user