Fix SourceRef race conditions, fix "source" and "target" getter returning unused instances, add missing validation, make "getDurationFromMetadata" only exist on tracks, fix examples, expand media player to support live playback, change the signatures of some Input APIs

This commit is contained in:
Vanilagy
2026-04-10 13:38:14 +02:00
parent 0813bcab28
commit aa810fc433
24 changed files with 493 additions and 476 deletions
+6 -1
View File
@@ -13,11 +13,14 @@ test.concurrent('Big Buck Bunny', { timeout: 15_000 }, async () => {
let sourceCount = 0;
input.on('source', () => sourceCount++);
let rootReadCount = 0;
input.source.on('read', () => rootReadCount++);
expect(await input.getFormat()).toBeInstanceOf(HlsInputFormat);
expect(await input.getFormat()).toBe(HLS);
expect(await input.getDurationFromMetadata()).toBe(null); // Since it's a master playlist!
expect(sourceCount).toBe(1);
expect(rootReadCount).toBeGreaterThan(0);
// Test descriptors (unhydrated metadata from master playlist)
const descriptors = await input.getTrackDescriptors();
@@ -211,6 +214,8 @@ test.concurrent('Big Buck Bunny', { timeout: 15_000 }, async () => {
// Since they're the highest-bitrate option
expect(primaryVideoTrack).toBe(videoTracks[4]);
expect(primaryAudioTrack).toBe(audioTracks[4]);
expect(await input.getDurationFromMetadata()).not.toBe(null);
});
test.concurrent('Single-variant Big Buck Bunny', { timeout: 15_000 }, async () => {
+6 -1
View File
@@ -1817,7 +1817,7 @@ segment-1-1.ts
);
});
test('onSegment, onPlaylist, onMaster events', async () => {
test('write, onSegment, onPlaylist, onMaster events', async () => {
const onSegment = vi.fn();
const onPlaylist = vi.fn();
const onMaster = vi.fn();
@@ -1832,6 +1832,9 @@ test('onSegment, onPlaylist, onMaster events', async () => {
target: new PathedTarget('', () => new BufferTarget()),
});
let targetWrites = 0;
output.target.on('write', () => targetWrites++);
const source = videoSource();
output.addVideoTrack(source);
@@ -1858,6 +1861,8 @@ test('onSegment, onPlaylist, onMaster events', async () => {
await output.finalize();
expect(targetWrites).toBeGreaterThan(0);
// Second segment finalized on close
expect(onSegment).toHaveBeenCalledTimes(2);
expect(onSegment.mock.calls[1]![1]).toEqual(expect.objectContaining({ n: 2 }));