From 4318954173a6702a549de055fecd468b0658234e Mon Sep 17 00:00:00 2001 From: lukasIO Date: Wed, 24 Apr 2024 08:47:01 +0200 Subject: [PATCH] Remove internal calls to setCodecPreferences on sender transceivers (#1114) * Remove internal calls to setCodecPreferences on senders * Create slimy-flowers-travel.md * remove unneeded ts-ignore --- .changeset/slimy-flowers-travel.md | 5 ++ src/room/PCTransport.ts | 2 - src/room/RTCEngine.ts | 68 +++--------------------- src/room/participant/LocalParticipant.ts | 1 - src/room/utils.ts | 26 --------- 5 files changed, 12 insertions(+), 90 deletions(-) create mode 100644 .changeset/slimy-flowers-travel.md diff --git a/.changeset/slimy-flowers-travel.md b/.changeset/slimy-flowers-travel.md new file mode 100644 index 0000000000..25094d59e8 --- /dev/null +++ b/.changeset/slimy-flowers-travel.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Remove internal calls to setCodecPreferences on senders diff --git a/src/room/PCTransport.ts b/src/room/PCTransport.ts index ca92ba325d..5459b2972f 100644 --- a/src/room/PCTransport.ts +++ b/src/room/PCTransport.ts @@ -474,8 +474,6 @@ export default class PCTransport extends EventEmitter { await this.pc.setLocalDescription(sd); } } catch (e) { - // this error cannot always be caught. - // If the local description has a setCodecPreferences error, this error will be uncaught let msg = 'unknown error'; if (e instanceof Error) { msg = e.message; diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 0f686cc8b9..e6d7e95652 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -53,22 +53,14 @@ import { EngineEvent } from './events'; import CriticalTimers from './timers'; import type LocalTrack from './track/LocalTrack'; import type LocalTrackPublication from './track/LocalTrackPublication'; -import type LocalVideoTrack from './track/LocalVideoTrack'; +import LocalVideoTrack from './track/LocalVideoTrack'; import type { SimulcastTrackInfo } from './track/LocalVideoTrack'; import type RemoteTrackPublication from './track/RemoteTrackPublication'; -import { Track } from './track/Track'; +import type { Track } from './track/Track'; import type { TrackPublishOptions, VideoCodec } from './track/options'; import { getTrackPublicationInfo } from './track/utils'; import type { LoggerOptions } from './types'; -import { - Mutex, - isVideoCodec, - isWeb, - sleep, - supportsAddTrack, - supportsSetCodecPreferences, - supportsTransceiver, -} from './utils'; +import { Mutex, isVideoCodec, isWeb, sleep, supportsAddTrack, supportsTransceiver } from './utils'; const lossyDataChannel = '_lossy'; const reliableDataChannel = '_reliable'; @@ -671,51 +663,6 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit this.updateAndEmitDCBufferStatus(channelKind); }; - private setPreferredCodec( - transceiver: RTCRtpTransceiver, - kind: Track.Kind, - videoCodec: VideoCodec, - ) { - if (!('getCapabilities' in RTCRtpReceiver)) { - return; - } - // when setting codec preferences, the capabilites need to be read from the RTCRtpReceiver - const cap = RTCRtpReceiver.getCapabilities(kind); - if (!cap) return; - this.log.debug('get receiver capabilities', { ...this.logContext, cap }); - const matched: RTCRtpCodecCapability[] = []; - const partialMatched: RTCRtpCodecCapability[] = []; - const unmatched: RTCRtpCodecCapability[] = []; - cap.codecs.forEach((c) => { - const codec = c.mimeType.toLowerCase(); - if (codec === 'audio/opus') { - matched.push(c); - return; - } - const matchesVideoCodec = codec === `video/${videoCodec}`; - if (!matchesVideoCodec) { - unmatched.push(c); - return; - } - // for h264 codecs that have sdpFmtpLine available, use only if the - // profile-level-id is 42e01f for cross-browser compatibility - if (videoCodec === 'h264') { - if (c.sdpFmtpLine && c.sdpFmtpLine.includes('profile-level-id=42e01f')) { - matched.push(c); - } else { - partialMatched.push(c); - } - return; - } - - matched.push(c); - }); - - if (supportsSetCodecPreferences(transceiver)) { - transceiver.setCodecPreferences(matched.concat(partialMatched, unmatched)); - } - } - async createSender( track: LocalTrack, opts: TrackPublishOptions, @@ -766,6 +713,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit streams.push(track.mediaStream); } + if (track instanceof LocalVideoTrack) { + track.codec = opts.videoCodec; + } + const transceiverInit: RTCRtpTransceiverInit = { direction: 'sendonly', streams }; if (encodings) { transceiverInit.sendEncodings = encodings; @@ -776,10 +727,6 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit transceiverInit, ); - if (track.kind === Track.Kind.Video && opts.videoCodec) { - this.setPreferredCodec(transceiver, track.kind, opts.videoCodec); - track.codec = opts.videoCodec; - } return transceiver.sender; } @@ -804,7 +751,6 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit if (!opts.videoCodec) { return; } - this.setPreferredCodec(transceiver, track.kind, opts.videoCodec); track.setSimulcastTrackSender(opts.videoCodec, transceiver.sender); return transceiver.sender; } diff --git a/src/room/participant/LocalParticipant.ts b/src/room/participant/LocalParticipant.ts index cdb5b4a5cf..d385467d2a 100644 --- a/src/room/participant/LocalParticipant.ts +++ b/src/room/participant/LocalParticipant.ts @@ -827,7 +827,6 @@ export default class LocalParticipant extends Participant { ...getLogContextFromTrack(track), codec: updatedCodec, }); - /* @ts-ignore */ opts.videoCodec = updatedCodec; // recompute encodings since bitrates/etc could have changed diff --git a/src/room/utils.ts b/src/room/utils.ts index 052025175e..60cd52e038 100644 --- a/src/room/utils.ts +++ b/src/room/utils.ts @@ -1,5 +1,4 @@ import { ClientInfo, ClientInfo_SDK } from '@livekit/protocol'; -import type { DetectableBrowser } from '../utils/browserParser'; import { getBrowser } from '../utils/browserParser'; import { protocolVersion, version } from '../version'; import CriticalTimers from './timers'; @@ -107,31 +106,6 @@ export function supportsSetSinkId(elm?: HTMLMediaElement): boolean { return 'setSinkId' in elm; } -const setCodecPreferencesVersions: Record = { - Chrome: '100', - Safari: '15', - Firefox: '100', -}; - -export function supportsSetCodecPreferences(transceiver: RTCRtpTransceiver): boolean { - if (!isWeb()) { - return false; - } - if (!('setCodecPreferences' in transceiver)) { - return false; - } - const browser = getBrowser(); - if (!browser?.name || !browser.version) { - // version is required - return false; - } - const v = setCodecPreferencesVersions[browser.name]; - if (v) { - return compareVersions(browser.version, v) >= 0; - } - return false; -} - export function isBrowserSupported() { if (typeof RTCPeerConnection === 'undefined') { return false;