-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathUnknownVideoDecoderImplementationDetector.spec.ts
171 lines (147 loc) · 4.94 KB
/
UnknownVideoDecoderImplementationDetector.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import faker from 'faker';
import { expect } from 'chai';
import UnknownVideoDecoderImplementationDetector from '../../src/detectors/UnknownVideoDecoderImplementationDetector';
import { ParsedInboundVideoStreamStats, WebRTCStatsParsed } from '../../src';
interface CreateStatsForDetectorTestPayload {
connectionId?: string;
ssrc?: number;
decoderImplementation?: string;
mimeType?: string;
trackIdentifier?: string;
}
interface CreateIssueDetectorResultTestPayload {
ssrc: number;
trackIdentifier: string;
mimeType: string;
decoderImplementation: string;
}
const createInboundVideoStreamStats = (
payload: Omit<CreateStatsForDetectorTestPayload, 'connectionId'>,
): ParsedInboundVideoStreamStats => ({
ssrc: payload.ssrc ?? faker.datatype.number({ min: 1 }),
decoderImplementation: payload.decoderImplementation ?? faker.lorem.slug(),
mimeType: payload.mimeType ?? faker.system.mimeType(),
track: {
trackIdentifier: payload.trackIdentifier ?? faker.datatype.uuid(),
},
} as ParsedInboundVideoStreamStats);
const createStatsForDetector = (payload: CreateStatsForDetectorTestPayload = {}): WebRTCStatsParsed => ({
connection: {
id: payload.connectionId ?? faker.datatype.uuid(),
},
video: {
inbound: [createInboundVideoStreamStats(payload)],
},
} as WebRTCStatsParsed);
const createIssueDetectorResult = (payload: CreateIssueDetectorResultTestPayload) => ({
ssrc: payload.ssrc,
trackIdentifier: payload.trackIdentifier,
statsSample: {
mimeType: payload.mimeType,
decoderImplementation: payload.decoderImplementation,
},
reason: 'unknown-video-decoder',
type: 'stream',
});
describe('wid/detectors/UnknownVideoDecoderImplementationDetector', () => {
const detector = new UnknownVideoDecoderImplementationDetector();
it('should detect unknown decoder on the second iteration', () => {
const mimeType = faker.lorem.slug();
const decoderImplementation = 'unknown';
const ssrc = faker.datatype.number({ min: 1 });
const trackIdentifier = faker.datatype.uuid();
const stats = createStatsForDetector({
ssrc,
mimeType,
trackIdentifier,
decoderImplementation,
});
detector.detect(stats);
const results = detector.detect(stats);
expect(results).to.deep.eq([createIssueDetectorResult({
ssrc,
mimeType,
trackIdentifier,
decoderImplementation,
})]);
});
it('should detect unknown decoders for each ssrc in stats', () => {
const mimeType = faker.lorem.slug();
const decoderImplementation = 'unknown';
const trackIdentifier = faker.datatype.uuid();
const ssrc1 = faker.datatype.number({ min: 1 });
const ssrc2 = faker.datatype.number({ min: 1 });
const stats = createStatsForDetector({
ssrc: ssrc1,
mimeType,
trackIdentifier,
decoderImplementation,
});
stats.video.inbound.push(createInboundVideoStreamStats({
ssrc: ssrc2,
mimeType,
trackIdentifier,
decoderImplementation,
}));
detector.detect(stats);
const results = detector.detect(stats);
expect(results).to.deep.eq([
createIssueDetectorResult({
ssrc: ssrc1,
mimeType,
trackIdentifier,
decoderImplementation,
}),
createIssueDetectorResult({
ssrc: ssrc2,
mimeType,
trackIdentifier,
decoderImplementation,
}),
]);
});
it('should detect decoder "degradation" after the second check', () => {
const mimeType = faker.lorem.slug();
const ssrc = faker.datatype.number({ min: 1 });
const trackIdentifier = faker.datatype.uuid();
const stats = createStatsForDetector({
ssrc,
mimeType,
trackIdentifier,
});
const firstCheckResults = detector.detect(stats);
const secondCheckResults = detector.detect(stats);
stats.video.inbound[0].decoderImplementation = 'unknown';
const checkResultsWithDegradedDecoder = detector.detect(stats);
expect(firstCheckResults).to.be.empty;
expect(secondCheckResults).to.be.empty;
expect(checkResultsWithDegradedDecoder).to.deep.eq([createIssueDetectorResult({
ssrc,
mimeType,
trackIdentifier,
decoderImplementation: 'unknown',
})]);
});
it('should skip unknown decoder detection on the first iteration', () => {
const stats = createStatsForDetector({
decoderImplementation: 'unknown',
});
const results = detector.detect(stats);
expect(results).to.be.empty;
});
it('should skip issue detection if codec is not unknown', () => {
const stats = createStatsForDetector();
detector.detect(stats);
const results = detector.detect(stats);
expect(results).to.be.empty;
});
it('should skip unknown decoder detection if detected previously', () => {
const stats = createStatsForDetector({
decoderImplementation: 'unknown',
});
detector.detect(stats);
detector.detect(stats);
const results = detector.detect(stats);
expect(results).to.be.empty;
});
});