@dtelecom/livekit-client 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +175 -0
- package/README.md +315 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js +2 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js.map +1 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs +1633 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.esm.mjs +22545 -0
- package/dist/@dtelecom/livekit-client.esm.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.umd.js +2 -0
- package/dist/@dtelecom/livekit-client.umd.js.map +1 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts +102 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
- package/dist/@dtelecom/src/index.d.ts +38 -0
- package/dist/@dtelecom/src/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/logger.d.ts +29 -0
- package/dist/@dtelecom/src/logger.d.ts.map +1 -0
- package/dist/@dtelecom/src/options.d.ts +104 -0
- package/dist/@dtelecom/src/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts +41 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/@dtelecom/src/room/Room.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/@dtelecom/src/room/defaults.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/@dtelecom/src/room/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/@dtelecom/src/room/events.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/@dtelecom/src/room/stats.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/@dtelecom/src/room/timers.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/create.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/options.d.ts +272 -0
- package/dist/@dtelecom/src/room/track/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/@dtelecom/src/room/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/@dtelecom/src/room/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/@dtelecom/src/test/mocks.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts.map +1 -0
- package/dist/@dtelecom/src/version.d.ts +3 -0
- package/dist/@dtelecom/src/version.d.ts.map +1 -0
- package/dist/ts4.2/@dtelecom/src/api/SignalClient.d.ts +105 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/ts4.2/@dtelecom/src/index.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/logger.d.ts +29 -0
- package/dist/ts4.2/@dtelecom/src/options.d.ts +104 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/ts4.2/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/ts4.2/@dtelecom/src/room/PCTransport.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/ts4.2/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/ts4.2/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/ts4.2/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/ts4.2/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/ts4.2/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/ts4.2/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/ts4.2/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/ts4.2/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/ts4.2/@dtelecom/src/room/track/options.d.ts +280 -0
- package/dist/ts4.2/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/ts4.2/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/ts4.2/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/ts4.2/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/ts4.2/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/version.d.ts +3 -0
- package/package.json +102 -0
- package/src/api/SignalClient.ts +790 -0
- package/src/connectionHelper/ConnectionCheck.ts +90 -0
- package/src/connectionHelper/checks/Checker.ts +163 -0
- package/src/connectionHelper/checks/publishAudio.ts +33 -0
- package/src/connectionHelper/checks/publishVideo.ts +33 -0
- package/src/connectionHelper/checks/reconnect.ts +45 -0
- package/src/connectionHelper/checks/turn.ts +54 -0
- package/src/connectionHelper/checks/webrtc.ts +82 -0
- package/src/connectionHelper/checks/websocket.ts +27 -0
- package/src/e2ee/E2eeManager.ts +375 -0
- package/src/e2ee/KeyProvider.ts +78 -0
- package/src/e2ee/constants.ts +44 -0
- package/src/e2ee/errors.ts +16 -0
- package/src/e2ee/index.ts +3 -0
- package/src/e2ee/types.ts +161 -0
- package/src/e2ee/utils.ts +127 -0
- package/src/e2ee/worker/FrameCryptor.test.ts +19 -0
- package/src/e2ee/worker/FrameCryptor.ts +612 -0
- package/src/e2ee/worker/ParticipantKeyHandler.ts +175 -0
- package/src/e2ee/worker/e2ee.worker.ts +223 -0
- package/src/e2ee/worker/tsconfig.json +6 -0
- package/src/index.ts +85 -0
- package/src/logger.ts +64 -0
- package/src/options.ts +127 -0
- package/src/proto/livekit_models_pb.ts +2096 -0
- package/src/proto/livekit_rtc_pb.ts +2332 -0
- package/src/room/DefaultReconnectPolicy.ts +35 -0
- package/src/room/DeviceManager.ts +88 -0
- package/src/room/PCTransport.ts +452 -0
- package/src/room/RTCEngine.ts +1421 -0
- package/src/room/ReconnectPolicy.ts +27 -0
- package/src/room/RegionUrlProvider.ts +82 -0
- package/src/room/Room.test.ts +30 -0
- package/src/room/Room.ts +1907 -0
- package/src/room/defaults.ts +49 -0
- package/src/room/errors.ts +90 -0
- package/src/room/events.ts +535 -0
- package/src/room/participant/LocalParticipant.ts +1350 -0
- package/src/room/participant/Participant.ts +299 -0
- package/src/room/participant/ParticipantTrackPermission.ts +42 -0
- package/src/room/participant/RemoteParticipant.ts +359 -0
- package/src/room/participant/publishUtils.test.ts +189 -0
- package/src/room/participant/publishUtils.ts +399 -0
- package/src/room/stats.ts +136 -0
- package/src/room/timers.ts +16 -0
- package/src/room/track/LocalAudioTrack.ts +171 -0
- package/src/room/track/LocalTrack.ts +430 -0
- package/src/room/track/LocalTrackPublication.ts +87 -0
- package/src/room/track/LocalVideoTrack.test.ts +73 -0
- package/src/room/track/LocalVideoTrack.ts +513 -0
- package/src/room/track/RemoteAudioTrack.ts +248 -0
- package/src/room/track/RemoteTrack.ts +62 -0
- package/src/room/track/RemoteTrackPublication.ts +311 -0
- package/src/room/track/RemoteVideoTrack.test.ts +152 -0
- package/src/room/track/RemoteVideoTrack.ts +410 -0
- package/src/room/track/Track.ts +452 -0
- package/src/room/track/TrackPublication.ts +158 -0
- package/src/room/track/create.ts +143 -0
- package/src/room/track/facingMode.test.ts +31 -0
- package/src/room/track/facingMode.ts +103 -0
- package/src/room/track/options.ts +362 -0
- package/src/room/track/processor/types.ts +20 -0
- package/src/room/track/types.ts +25 -0
- package/src/room/track/utils.test.ts +111 -0
- package/src/room/track/utils.ts +183 -0
- package/src/room/types.ts +39 -0
- package/src/room/utils.test.ts +16 -0
- package/src/room/utils.ts +501 -0
- package/src/room/worker.d.ts +4 -0
- package/src/test/MockMediaStreamTrack.ts +84 -0
- package/src/test/mocks.ts +19 -0
- package/src/utils/AsyncQueue.test.ts +100 -0
- package/src/utils/AsyncQueue.ts +57 -0
- package/src/utils/browserParser.test.ts +88 -0
- package/src/utils/browserParser.ts +74 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { ScreenSharePresets, VideoPreset, VideoPresets, VideoPresets43 } from '../track/options';
|
|
3
|
+
import {
|
|
4
|
+
computeDefaultScreenShareSimulcastPresets,
|
|
5
|
+
computeVideoEncodings,
|
|
6
|
+
determineAppropriateEncoding,
|
|
7
|
+
presets43,
|
|
8
|
+
presets169,
|
|
9
|
+
presetsForResolution,
|
|
10
|
+
presetsScreenShare,
|
|
11
|
+
sortPresets,
|
|
12
|
+
} from './publishUtils';
|
|
13
|
+
|
|
14
|
+
describe('presetsForResolution', () => {
|
|
15
|
+
it('handles screenshare', () => {
|
|
16
|
+
expect(presetsForResolution(true, 600, 300)).toEqual(presetsScreenShare);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('handles landscape', () => {
|
|
20
|
+
expect(presetsForResolution(false, 600, 300)).toEqual(presets169);
|
|
21
|
+
expect(presetsForResolution(false, 500, 500)).toEqual(presets43);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('handles portrait', () => {
|
|
25
|
+
expect(presetsForResolution(false, 300, 600)).toEqual(presets169);
|
|
26
|
+
expect(presetsForResolution(false, 500, 500)).toEqual(presets43);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('determineAppropriateEncoding', () => {
|
|
31
|
+
it('uses higher encoding', () => {
|
|
32
|
+
expect(determineAppropriateEncoding(false, 600, 300)).toEqual(VideoPresets.h360.encoding);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('handles portrait', () => {
|
|
36
|
+
expect(determineAppropriateEncoding(false, 300, 600)).toEqual(VideoPresets.h360.encoding);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('computeVideoEncodings', () => {
|
|
41
|
+
it('handles non-simulcast', () => {
|
|
42
|
+
const encodings = computeVideoEncodings(false, 640, 480, {
|
|
43
|
+
simulcast: false,
|
|
44
|
+
});
|
|
45
|
+
expect(encodings).toEqual([{}]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('respects client defined bitrate', () => {
|
|
49
|
+
const encodings = computeVideoEncodings(false, 640, 480, {
|
|
50
|
+
simulcast: false,
|
|
51
|
+
videoEncoding: {
|
|
52
|
+
maxBitrate: 1024,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
expect(encodings).toHaveLength(1);
|
|
56
|
+
expect(encodings![0].maxBitrate).toBe(1024);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('returns three encodings for high-res simulcast', () => {
|
|
60
|
+
const encodings = computeVideoEncodings(false, 960, 540, {
|
|
61
|
+
simulcast: true,
|
|
62
|
+
});
|
|
63
|
+
expect(encodings).toHaveLength(3);
|
|
64
|
+
|
|
65
|
+
// ensure they are what we expect
|
|
66
|
+
expect(encodings![0].rid).toBe('q');
|
|
67
|
+
expect(encodings![0].maxBitrate).toBe(VideoPresets.h180.encoding.maxBitrate);
|
|
68
|
+
expect(encodings![0].scaleResolutionDownBy).toBe(3);
|
|
69
|
+
expect(encodings![1].rid).toBe('h');
|
|
70
|
+
expect(encodings![1].scaleResolutionDownBy).toBe(1.5);
|
|
71
|
+
expect(encodings![2].rid).toBe('f');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('handles portrait simulcast', () => {
|
|
75
|
+
const encodings = computeVideoEncodings(false, 540, 960, {
|
|
76
|
+
simulcast: true,
|
|
77
|
+
});
|
|
78
|
+
expect(encodings).toHaveLength(3);
|
|
79
|
+
expect(encodings![0].scaleResolutionDownBy).toBe(3);
|
|
80
|
+
expect(encodings![1].scaleResolutionDownBy).toBe(1.5);
|
|
81
|
+
expect(encodings![2].maxBitrate).toBe(VideoPresets.h540.encoding.maxBitrate);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('returns two encodings for lower-res simulcast', () => {
|
|
85
|
+
const encodings = computeVideoEncodings(false, 640, 360, {
|
|
86
|
+
simulcast: true,
|
|
87
|
+
});
|
|
88
|
+
expect(encodings).toHaveLength(2);
|
|
89
|
+
|
|
90
|
+
// ensure they are what we expect
|
|
91
|
+
expect(encodings![0].rid).toBe('q');
|
|
92
|
+
expect(encodings![0].maxBitrate).toBe(VideoPresets.h180.encoding.maxBitrate);
|
|
93
|
+
expect(encodings![1].rid).toBe('h');
|
|
94
|
+
expect(encodings![1].maxBitrate).toBe(VideoPresets.h360.encoding.maxBitrate);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('returns one encoding if an empty array is provided for custom screen share layers', () => {
|
|
98
|
+
const encodings = computeVideoEncodings(true, 1920, 1080, {
|
|
99
|
+
simulcast: true,
|
|
100
|
+
screenShareSimulcastLayers: [],
|
|
101
|
+
});
|
|
102
|
+
expect(encodings).toHaveLength(1);
|
|
103
|
+
|
|
104
|
+
// ensure they are what we expect
|
|
105
|
+
expect(encodings![0].rid).toBe('q');
|
|
106
|
+
expect(encodings![0].scaleResolutionDownBy).toBe(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('respects provided min resolution', () => {
|
|
110
|
+
const encodings = computeVideoEncodings(false, 100, 120, {
|
|
111
|
+
simulcast: true,
|
|
112
|
+
});
|
|
113
|
+
expect(encodings).toHaveLength(1);
|
|
114
|
+
expect(encodings![0].rid).toBe('q');
|
|
115
|
+
expect(encodings![0].maxBitrate).toBe(VideoPresets43.h120.encoding.maxBitrate);
|
|
116
|
+
expect(encodings![0].scaleResolutionDownBy).toBe(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// it('respects default backup codec encoding', () => {
|
|
120
|
+
// const vp8Encodings = computeTrackBackupEncodings(false, 100, 120, { simulcast: true });
|
|
121
|
+
// const h264Encodings = computeVideoEncodings(false, 100, 120, {
|
|
122
|
+
// simulcast: true,
|
|
123
|
+
// videoCodec: 'h264',
|
|
124
|
+
// });
|
|
125
|
+
// const av1Encodings = computeVideoEncodings(false, 100, 120, {
|
|
126
|
+
// simulcast: true,
|
|
127
|
+
// videoCodec: 'av1',
|
|
128
|
+
// });
|
|
129
|
+
// expect(h264Encodings).toHaveLength(1);
|
|
130
|
+
// expect(h264Encodings![0].rid).toBe('q');
|
|
131
|
+
// expect(h264Encodings![0].maxBitrate).toBe(vp8Encodings[0].maxBitrate! * 1.1);
|
|
132
|
+
// expect(av1Encodings![0].maxBitrate).toBe(vp8Encodings[0].maxBitrate! * 0.7);
|
|
133
|
+
// expect(h264Encodings![0].scaleResolutionDownBy).toBe(1);
|
|
134
|
+
// });
|
|
135
|
+
|
|
136
|
+
// it('respects custom backup codec encoding', () => {
|
|
137
|
+
// const encodings = computeVideoEncodings(false, 100, 120, {
|
|
138
|
+
// simulcast: true,
|
|
139
|
+
// videoCodec: 'h264',
|
|
140
|
+
// backupCodec: {
|
|
141
|
+
// vp8: { maxBitrate: 1_000 },
|
|
142
|
+
// h264: { maxBitrate: 2_000 },
|
|
143
|
+
// },
|
|
144
|
+
// });
|
|
145
|
+
// expect(encodings).toHaveLength(1);
|
|
146
|
+
// expect(encodings![0].rid).toBe('q');
|
|
147
|
+
// expect(encodings![0].maxBitrate).toBe(2_000);
|
|
148
|
+
// expect(encodings![0].scaleResolutionDownBy).toBe(1);
|
|
149
|
+
// });
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('customSimulcastLayers', () => {
|
|
153
|
+
it('sorts presets from lowest to highest', () => {
|
|
154
|
+
const sortedPresets = sortPresets([
|
|
155
|
+
VideoPresets.h1440,
|
|
156
|
+
VideoPresets.h360,
|
|
157
|
+
VideoPresets.h1080,
|
|
158
|
+
VideoPresets.h90,
|
|
159
|
+
]) as Array<VideoPreset>;
|
|
160
|
+
expect(sortPresets).not.toBeUndefined();
|
|
161
|
+
expect(sortedPresets[0]).toBe(VideoPresets.h90);
|
|
162
|
+
expect(sortedPresets[1]).toBe(VideoPresets.h360);
|
|
163
|
+
expect(sortedPresets[2]).toBe(VideoPresets.h1080);
|
|
164
|
+
expect(sortedPresets[3]).toBe(VideoPresets.h1440);
|
|
165
|
+
});
|
|
166
|
+
it('sorts presets from lowest to highest, even when dimensions are the same', () => {
|
|
167
|
+
const sortedPresets = sortPresets([
|
|
168
|
+
new VideoPreset(1920, 1080, 3_000_000, 20),
|
|
169
|
+
new VideoPreset(1920, 1080, 2_000_000, 15),
|
|
170
|
+
new VideoPreset(1920, 1080, 3_000_000, 15),
|
|
171
|
+
]) as Array<VideoPreset>;
|
|
172
|
+
expect(sortPresets).not.toBeUndefined();
|
|
173
|
+
expect(sortedPresets[0].encoding.maxBitrate).toBe(2_000_000);
|
|
174
|
+
expect(sortedPresets[1].encoding.maxFramerate).toBe(15);
|
|
175
|
+
expect(sortedPresets[2].encoding.maxFramerate).toBe(20);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('screenShareSimulcastDefaults', () => {
|
|
180
|
+
it('computes appropriate bitrate from original preset', () => {
|
|
181
|
+
const defaultSimulcastLayers = computeDefaultScreenShareSimulcastPresets(
|
|
182
|
+
ScreenSharePresets.h720fps15,
|
|
183
|
+
);
|
|
184
|
+
expect(defaultSimulcastLayers[0].width).toBe(640);
|
|
185
|
+
expect(defaultSimulcastLayers[0].height).toBe(360);
|
|
186
|
+
expect(defaultSimulcastLayers[0].encoding.maxFramerate).toBe(3);
|
|
187
|
+
expect(defaultSimulcastLayers[0].encoding.maxBitrate).toBe(150_000);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import log from '../../logger';
|
|
2
|
+
import { TrackInvalidError } from '../errors';
|
|
3
|
+
import LocalAudioTrack from '../track/LocalAudioTrack';
|
|
4
|
+
import LocalVideoTrack from '../track/LocalVideoTrack';
|
|
5
|
+
import { Track } from '../track/Track';
|
|
6
|
+
import { ScreenSharePresets, VideoPreset, VideoPresets, VideoPresets43 } from '../track/options';
|
|
7
|
+
import type {
|
|
8
|
+
BackupVideoCodec,
|
|
9
|
+
TrackPublishOptions,
|
|
10
|
+
VideoCodec,
|
|
11
|
+
VideoEncoding,
|
|
12
|
+
} from '../track/options';
|
|
13
|
+
import { getReactNativeOs, isFireFox, isReactNative, isSVCCodec } from '../utils';
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
export function mediaTrackToLocalTrack(
|
|
17
|
+
mediaStreamTrack: MediaStreamTrack,
|
|
18
|
+
constraints?: MediaTrackConstraints,
|
|
19
|
+
): LocalVideoTrack | LocalAudioTrack {
|
|
20
|
+
switch (mediaStreamTrack.kind) {
|
|
21
|
+
case 'audio':
|
|
22
|
+
return new LocalAudioTrack(mediaStreamTrack, constraints, false);
|
|
23
|
+
case 'video':
|
|
24
|
+
return new LocalVideoTrack(mediaStreamTrack, constraints, false);
|
|
25
|
+
default:
|
|
26
|
+
throw new TrackInvalidError(`unsupported track type: ${mediaStreamTrack.kind}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* @internal */
|
|
31
|
+
export const presets169 = Object.values(VideoPresets);
|
|
32
|
+
|
|
33
|
+
/* @internal */
|
|
34
|
+
export const presets43 = Object.values(VideoPresets43);
|
|
35
|
+
|
|
36
|
+
/* @internal */
|
|
37
|
+
export const presetsScreenShare = Object.values(ScreenSharePresets);
|
|
38
|
+
|
|
39
|
+
/* @internal */
|
|
40
|
+
export const defaultSimulcastPresets169 = [VideoPresets.h180, VideoPresets.h360];
|
|
41
|
+
|
|
42
|
+
/* @internal */
|
|
43
|
+
export const defaultSimulcastPresets43 = [VideoPresets43.h180, VideoPresets43.h360];
|
|
44
|
+
|
|
45
|
+
/* @internal */
|
|
46
|
+
export const computeDefaultScreenShareSimulcastPresets = (fromPreset: VideoPreset) => {
|
|
47
|
+
const layers = [{ scaleResolutionDownBy: 2, fps: 3 }];
|
|
48
|
+
return layers.map(
|
|
49
|
+
(t) =>
|
|
50
|
+
new VideoPreset(
|
|
51
|
+
Math.floor(fromPreset.width / t.scaleResolutionDownBy),
|
|
52
|
+
Math.floor(fromPreset.height / t.scaleResolutionDownBy),
|
|
53
|
+
Math.max(
|
|
54
|
+
150_000,
|
|
55
|
+
Math.floor(
|
|
56
|
+
fromPreset.encoding.maxBitrate /
|
|
57
|
+
(t.scaleResolutionDownBy ** 2 * ((fromPreset.encoding.maxFramerate ?? 30) / t.fps)),
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
t.fps,
|
|
61
|
+
fromPreset.encoding.priority,
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// /**
|
|
67
|
+
// *
|
|
68
|
+
// * @internal
|
|
69
|
+
// * @experimental
|
|
70
|
+
// */
|
|
71
|
+
// const computeDefaultMultiCodecSimulcastEncodings = (width: number, height: number) => {
|
|
72
|
+
// // use vp8 as a default
|
|
73
|
+
// const vp8 = determineAppropriateEncoding(false, width, height);
|
|
74
|
+
// const vp9 = { ...vp8, maxBitrate: vp8.maxBitrate * 0.9 };
|
|
75
|
+
// const h264 = { ...vp8, maxBitrate: vp8.maxBitrate * 1.1 };
|
|
76
|
+
// const av1 = { ...vp8, maxBitrate: vp8.maxBitrate * 0.7 };
|
|
77
|
+
// return {
|
|
78
|
+
// vp8,
|
|
79
|
+
// vp9,
|
|
80
|
+
// h264,
|
|
81
|
+
// av1,
|
|
82
|
+
// };
|
|
83
|
+
// };
|
|
84
|
+
|
|
85
|
+
const videoRids = ['q', 'h', 'f'];
|
|
86
|
+
|
|
87
|
+
/* @internal */
|
|
88
|
+
export function computeVideoEncodings(
|
|
89
|
+
isScreenShare: boolean,
|
|
90
|
+
width?: number,
|
|
91
|
+
height?: number,
|
|
92
|
+
options?: TrackPublishOptions,
|
|
93
|
+
): RTCRtpEncodingParameters[] {
|
|
94
|
+
let videoEncoding: VideoEncoding | undefined = options?.videoEncoding;
|
|
95
|
+
|
|
96
|
+
if (isScreenShare) {
|
|
97
|
+
videoEncoding = options?.screenShareEncoding;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const useSimulcast = options?.simulcast;
|
|
101
|
+
const scalabilityMode = options?.scalabilityMode;
|
|
102
|
+
const videoCodec = options?.videoCodec;
|
|
103
|
+
|
|
104
|
+
if ((!videoEncoding && !useSimulcast && !scalabilityMode) || !width || !height) {
|
|
105
|
+
// when we aren't simulcasting or svc, will need to return a single encoding without
|
|
106
|
+
// capping bandwidth. we always require a encoding for dynacast
|
|
107
|
+
return [{}];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!videoEncoding) {
|
|
111
|
+
// find the right encoding based on width/height
|
|
112
|
+
videoEncoding = determineAppropriateEncoding(isScreenShare, width, height, videoCodec);
|
|
113
|
+
log.debug('using video encoding', videoEncoding);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const original = new VideoPreset(
|
|
117
|
+
width,
|
|
118
|
+
height,
|
|
119
|
+
videoEncoding.maxBitrate,
|
|
120
|
+
videoEncoding.maxFramerate,
|
|
121
|
+
videoEncoding.priority,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (scalabilityMode && isSVCCodec(videoCodec)) {
|
|
125
|
+
log.debug(`using svc with scalabilityMode ${scalabilityMode}`);
|
|
126
|
+
|
|
127
|
+
const sm = new ScalabilityMode(scalabilityMode);
|
|
128
|
+
|
|
129
|
+
const encodings: RTCRtpEncodingParameters[] = [];
|
|
130
|
+
|
|
131
|
+
if (sm.spatial > 3) {
|
|
132
|
+
throw new Error(`unsupported scalabilityMode: ${scalabilityMode}`);
|
|
133
|
+
}
|
|
134
|
+
for (let i = 0; i < sm.spatial; i += 1) {
|
|
135
|
+
encodings.push({
|
|
136
|
+
rid: videoRids[2 - i],
|
|
137
|
+
maxBitrate: videoEncoding.maxBitrate / 3 ** i,
|
|
138
|
+
/* @ts-ignore */
|
|
139
|
+
maxFramerate: original.encoding.maxFramerate,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/* @ts-ignore */
|
|
143
|
+
encodings[0].scalabilityMode = scalabilityMode;
|
|
144
|
+
log.debug('encodings', encodings);
|
|
145
|
+
return encodings;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!useSimulcast) {
|
|
149
|
+
return [videoEncoding];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let presets: Array<VideoPreset> = [];
|
|
153
|
+
if (isScreenShare) {
|
|
154
|
+
presets =
|
|
155
|
+
sortPresets(options?.screenShareSimulcastLayers) ??
|
|
156
|
+
defaultSimulcastLayers(isScreenShare, original);
|
|
157
|
+
} else {
|
|
158
|
+
presets =
|
|
159
|
+
sortPresets(options?.videoSimulcastLayers) ?? defaultSimulcastLayers(isScreenShare, original);
|
|
160
|
+
}
|
|
161
|
+
let midPreset: VideoPreset | undefined;
|
|
162
|
+
if (presets.length > 0) {
|
|
163
|
+
const lowPreset = presets[0];
|
|
164
|
+
if (presets.length > 1) {
|
|
165
|
+
[, midPreset] = presets;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// NOTE:
|
|
169
|
+
// 1. Ordering of these encodings is important. Chrome seems
|
|
170
|
+
// to use the index into encodings to decide which layer
|
|
171
|
+
// to disable when CPU constrained.
|
|
172
|
+
// So encodings should be ordered in increasing spatial
|
|
173
|
+
// resolution order.
|
|
174
|
+
// 2. ion-sfu translates rids into layers. So, all encodings
|
|
175
|
+
// should have the base layer `q` and then more added
|
|
176
|
+
// based on other conditions.
|
|
177
|
+
const size = Math.max(width, height);
|
|
178
|
+
if (size >= 960 && midPreset) {
|
|
179
|
+
return encodingsFromPresets(width, height, [lowPreset, midPreset, original]);
|
|
180
|
+
}
|
|
181
|
+
if (size >= 480) {
|
|
182
|
+
return encodingsFromPresets(width, height, [lowPreset, original]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return encodingsFromPresets(width, height, [original]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function computeTrackBackupEncodings(
|
|
189
|
+
track: LocalVideoTrack,
|
|
190
|
+
videoCodec: BackupVideoCodec,
|
|
191
|
+
opts: TrackPublishOptions,
|
|
192
|
+
) {
|
|
193
|
+
if (!opts.backupCodec || opts.backupCodec.codec === opts.videoCodec) {
|
|
194
|
+
// backup codec publishing is disabled
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (videoCodec !== opts.backupCodec.codec) {
|
|
198
|
+
log.warn('requested a different codec than specified as backup', {
|
|
199
|
+
serverRequested: videoCodec,
|
|
200
|
+
backup: opts.backupCodec.codec,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
opts.videoCodec = videoCodec;
|
|
205
|
+
// use backup encoding setting as videoEncoding for backup codec publishing
|
|
206
|
+
opts.videoEncoding = opts.backupCodec.encoding;
|
|
207
|
+
|
|
208
|
+
const settings = track.mediaStreamTrack.getSettings();
|
|
209
|
+
const width = settings.width ?? track.dimensions?.width;
|
|
210
|
+
const height = settings.height ?? track.dimensions?.height;
|
|
211
|
+
|
|
212
|
+
const encodings = computeVideoEncodings(
|
|
213
|
+
track.source === Track.Source.ScreenShare,
|
|
214
|
+
width,
|
|
215
|
+
height,
|
|
216
|
+
opts,
|
|
217
|
+
);
|
|
218
|
+
return encodings;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* @internal */
|
|
222
|
+
export function determineAppropriateEncoding(
|
|
223
|
+
isScreenShare: boolean,
|
|
224
|
+
width: number,
|
|
225
|
+
height: number,
|
|
226
|
+
codec?: VideoCodec,
|
|
227
|
+
): VideoEncoding {
|
|
228
|
+
const presets = presetsForResolution(isScreenShare, width, height);
|
|
229
|
+
let { encoding } = presets[0];
|
|
230
|
+
|
|
231
|
+
// handle portrait by swapping dimensions
|
|
232
|
+
const size = Math.max(width, height);
|
|
233
|
+
|
|
234
|
+
for (let i = 0; i < presets.length; i += 1) {
|
|
235
|
+
const preset = presets[i];
|
|
236
|
+
encoding = preset.encoding;
|
|
237
|
+
if (preset.width >= size) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// presets are based on the assumption of vp8 as a codec
|
|
242
|
+
// for other codecs we adjust the maxBitrate if no specific videoEncoding has been provided
|
|
243
|
+
// TODO make the bitrate multipliers configurable per codec
|
|
244
|
+
if (codec) {
|
|
245
|
+
switch (codec) {
|
|
246
|
+
case 'av1':
|
|
247
|
+
encoding = { ...encoding };
|
|
248
|
+
encoding.maxBitrate = encoding.maxBitrate * 0.7;
|
|
249
|
+
break;
|
|
250
|
+
case 'vp9':
|
|
251
|
+
encoding = { ...encoding };
|
|
252
|
+
encoding.maxBitrate = encoding.maxBitrate * 0.85;
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return encoding;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* @internal */
|
|
263
|
+
export function presetsForResolution(
|
|
264
|
+
isScreenShare: boolean,
|
|
265
|
+
width: number,
|
|
266
|
+
height: number,
|
|
267
|
+
): VideoPreset[] {
|
|
268
|
+
if (isScreenShare) {
|
|
269
|
+
return presetsScreenShare;
|
|
270
|
+
}
|
|
271
|
+
const aspect = width > height ? width / height : height / width;
|
|
272
|
+
if (Math.abs(aspect - 16.0 / 9) < Math.abs(aspect - 4.0 / 3)) {
|
|
273
|
+
return presets169;
|
|
274
|
+
}
|
|
275
|
+
return presets43;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* @internal */
|
|
279
|
+
export function defaultSimulcastLayers(
|
|
280
|
+
isScreenShare: boolean,
|
|
281
|
+
original: VideoPreset,
|
|
282
|
+
): VideoPreset[] {
|
|
283
|
+
if (isScreenShare) {
|
|
284
|
+
return computeDefaultScreenShareSimulcastPresets(original);
|
|
285
|
+
}
|
|
286
|
+
const { width, height } = original;
|
|
287
|
+
const aspect = width > height ? width / height : height / width;
|
|
288
|
+
if (Math.abs(aspect - 16.0 / 9) < Math.abs(aspect - 4.0 / 3)) {
|
|
289
|
+
return defaultSimulcastPresets169;
|
|
290
|
+
}
|
|
291
|
+
return defaultSimulcastPresets43;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// presets should be ordered by low, medium, high
|
|
295
|
+
function encodingsFromPresets(
|
|
296
|
+
width: number,
|
|
297
|
+
height: number,
|
|
298
|
+
presets: VideoPreset[],
|
|
299
|
+
): RTCRtpEncodingParameters[] {
|
|
300
|
+
const encodings: RTCRtpEncodingParameters[] = [];
|
|
301
|
+
presets.forEach((preset, idx) => {
|
|
302
|
+
if (idx >= videoRids.length) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const size = Math.min(width, height);
|
|
306
|
+
const rid = videoRids[idx];
|
|
307
|
+
const encoding: RTCRtpEncodingParameters = {
|
|
308
|
+
rid,
|
|
309
|
+
scaleResolutionDownBy: Math.max(1, size / Math.min(preset.width, preset.height)),
|
|
310
|
+
maxBitrate: preset.encoding.maxBitrate,
|
|
311
|
+
};
|
|
312
|
+
if (preset.encoding.maxFramerate) {
|
|
313
|
+
encoding.maxFramerate = preset.encoding.maxFramerate;
|
|
314
|
+
}
|
|
315
|
+
const canSetPriority = isFireFox() || idx === 0;
|
|
316
|
+
if (preset.encoding.priority && canSetPriority) {
|
|
317
|
+
encoding.priority = preset.encoding.priority;
|
|
318
|
+
encoding.networkPriority = preset.encoding.priority;
|
|
319
|
+
}
|
|
320
|
+
encodings.push(encoding);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// RN ios simulcast requires all same framerates.
|
|
324
|
+
if (isReactNative() && getReactNativeOs() === 'ios') {
|
|
325
|
+
let topFramerate: number | undefined = undefined;
|
|
326
|
+
encodings.forEach((encoding) => {
|
|
327
|
+
if (!topFramerate) {
|
|
328
|
+
topFramerate = encoding.maxFramerate;
|
|
329
|
+
} else if (encoding.maxFramerate && encoding.maxFramerate > topFramerate) {
|
|
330
|
+
topFramerate = encoding.maxFramerate;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
let notifyOnce = true;
|
|
335
|
+
encodings.forEach((encoding) => {
|
|
336
|
+
if (encoding.maxFramerate != topFramerate) {
|
|
337
|
+
if (notifyOnce) {
|
|
338
|
+
notifyOnce = false;
|
|
339
|
+
log.info(
|
|
340
|
+
`Simulcast on iOS React-Native requires all encodings to share the same framerate.`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
log.info(`Setting framerate of encoding \"${encoding.rid ?? ''}\" to ${topFramerate}`);
|
|
344
|
+
encoding.maxFramerate = topFramerate;
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return encodings;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** @internal */
|
|
353
|
+
export function sortPresets(presets: Array<VideoPreset> | undefined) {
|
|
354
|
+
if (!presets) return;
|
|
355
|
+
return presets.sort((a, b) => {
|
|
356
|
+
const { encoding: aEnc } = a;
|
|
357
|
+
const { encoding: bEnc } = b;
|
|
358
|
+
|
|
359
|
+
if (aEnc.maxBitrate > bEnc.maxBitrate) {
|
|
360
|
+
return 1;
|
|
361
|
+
}
|
|
362
|
+
if (aEnc.maxBitrate < bEnc.maxBitrate) return -1;
|
|
363
|
+
if (aEnc.maxBitrate === bEnc.maxBitrate && aEnc.maxFramerate && bEnc.maxFramerate) {
|
|
364
|
+
return aEnc.maxFramerate > bEnc.maxFramerate ? 1 : -1;
|
|
365
|
+
}
|
|
366
|
+
return 0;
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** @internal */
|
|
371
|
+
export class ScalabilityMode {
|
|
372
|
+
spatial: number;
|
|
373
|
+
|
|
374
|
+
temporal: number;
|
|
375
|
+
|
|
376
|
+
suffix: undefined | 'h' | '_KEY' | '_KEY_SHIFT';
|
|
377
|
+
|
|
378
|
+
constructor(scalabilityMode: string) {
|
|
379
|
+
const results = scalabilityMode.match(/^L(\d)T(\d)(h|_KEY|_KEY_SHIFT){0,1}$/);
|
|
380
|
+
if (!results) {
|
|
381
|
+
throw new Error('invalid scalability mode');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
this.spatial = parseInt(results[1]);
|
|
385
|
+
this.temporal = parseInt(results[2]);
|
|
386
|
+
if (results.length > 3) {
|
|
387
|
+
switch (results[3]) {
|
|
388
|
+
case 'h':
|
|
389
|
+
case '_KEY':
|
|
390
|
+
case '_KEY_SHIFT':
|
|
391
|
+
this.suffix = results[3];
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
toString(): string {
|
|
397
|
+
return `L${this.spatial}T${this.temporal}${this.suffix ?? ''}`;
|
|
398
|
+
}
|
|
399
|
+
}
|