feat: Add experimental rewrite of go2rtc live provider (MSE/WebRTC/MP4/MJPEG) (#2580)
- Closes #2556 - Closes #2450 **Key intended features:** - go2rtc compatible - 100% test coverage to significantly improve ability to test, maintain and work around browser weirdnesses (e.g. Safari). - Written from the ground up in the style of the rest of the project. **To use:** - Change `live_provider` from `go2rtc` to `go2rtc-experimental`.
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
import { assert, describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
LAG_SAMPLE_WINDOW_SIZE,
|
||||
NonWebKitLiveEdgeStrategy,
|
||||
} from '../../../../../../../src/components-lib/live/providers/go2rtc-experimental/utils/live-edge-tracker/non-webkit';
|
||||
import { createStatus } from './test-utils';
|
||||
|
||||
describe('NonWebKitLiveEdgeStrategy', () => {
|
||||
it('should play at realtime when close to the live edge', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
expect(strategy.next(createStatus(20, 18))).toEqual({ action: 'rate', rate: 1 });
|
||||
});
|
||||
|
||||
it('should nudge the rate up when lag exceeds the stream norm', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
for (let i = 0; i < LAG_SAMPLE_WINDOW_SIZE; ++i) {
|
||||
strategy.next(createStatus(20, 19));
|
||||
}
|
||||
|
||||
const action = strategy.next(createStatus(20, 15));
|
||||
|
||||
assert(action.action === 'rate');
|
||||
expect(action.rate).toBeGreaterThan(1);
|
||||
expect(action.rate).toBeLessThanOrEqual(2);
|
||||
});
|
||||
|
||||
it('should cap the catch-up rate', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
for (let i = 0; i < LAG_SAMPLE_WINDOW_SIZE; ++i) {
|
||||
strategy.next(createStatus(20, 20));
|
||||
}
|
||||
|
||||
expect(strategy.next(createStatus(60, 10))).toEqual({ action: 'rate', rate: 2 });
|
||||
});
|
||||
|
||||
it('should stay near realtime within the stream normal lag', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
for (let i = 0; i < LAG_SAMPLE_WINDOW_SIZE; ++i) {
|
||||
strategy.next(createStatus(24, 20));
|
||||
}
|
||||
|
||||
const action = strategy.next(createStatus(24, 20));
|
||||
|
||||
assert(action.action === 'rate');
|
||||
expect(action.rate).toBeCloseTo(1, 2);
|
||||
});
|
||||
|
||||
it('should catch up hard before any baseline samples exist', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
|
||||
// The very first sample is taken while already catching up, so it is
|
||||
// excluded and there is no average to temper the threshold.
|
||||
expect(strategy.next(createStatus(20, 15, { playbackRate: 2 }))).toEqual({
|
||||
action: 'rate',
|
||||
rate: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('should drop stale lag samples as the stream recovers', () => {
|
||||
const strategy = new NonWebKitLiveEdgeStrategy();
|
||||
for (let i = 0; i < LAG_SAMPLE_WINDOW_SIZE; ++i) {
|
||||
strategy.next(createStatus(26, 20));
|
||||
}
|
||||
// A full window of low lag evicts the earlier high-lag samples.
|
||||
for (let i = 0; i < LAG_SAMPLE_WINDOW_SIZE; ++i) {
|
||||
strategy.next(createStatus(21, 20));
|
||||
}
|
||||
|
||||
const action = strategy.next(createStatus(25, 20));
|
||||
|
||||
assert(action.action === 'rate');
|
||||
expect(action.rate).toBeGreaterThan(1.1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user