Skip to content

Commit

Permalink
Warn if you set bypassVoiceProcessing after creation of PeerConnectio…
Browse files Browse the repository at this point in the history
…nFactory (#531)

This is an implementation trap as it is, since this property has no
effect once the PCF is initialized, and the PCF is also a static
property that gets initialized very early in app lifecycle.

In this PR I've just added a warning log, but alternatives worth
considering:
- Change the API to be a throwing function and deprecate the original
property
- Recreate the PCF if you change this property (implications unknown to
me)
  • Loading branch information
bcherry authored Dec 13, 2024
1 parent 9c5242f commit 0c9c239
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/LiveKit/Core/RTC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ private class VideoEncoderFactorySimulcast: LKRTCVideoEncoderFactorySimulcast {
}

class RTC {
static var bypassVoiceProcessing: Bool = false
private static var _bypassVoiceProcessing: Bool = false
private static var _peerConnectionFactoryInitialized = false

static var bypassVoiceProcessing: Bool {
get { _bypassVoiceProcessing }
set {
if _peerConnectionFactoryInitialized {
logger.log("Warning: Setting bypassVoiceProcessing after PeerConnectionFactory initialization has no effect. Set it at application launch.", .warning, type: Room.self)
}
_bypassVoiceProcessing = newValue
}
}

static let h264BaselineLevel5CodecInfo: LKRTCVideoCodecInfo = {
// this should never happen
Expand Down Expand Up @@ -89,6 +100,7 @@ class RTC {

logger.log("Initializing PeerConnectionFactory...", type: Room.self)

_peerConnectionFactoryInitialized = true
return LKRTCPeerConnectionFactory(bypassVoiceProcessing: bypassVoiceProcessing,
encoderFactory: encoderFactory,
decoderFactory: decoderFactory,
Expand Down
1 change: 1 addition & 0 deletions Sources/LiveKit/Core/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ extension Room: AppStateDelegate {
public extension Room {
/// Set this to true to bypass initialization of voice processing.
/// Must be set before RTCPeerConnectionFactory gets initialized.
/// The most reliable place to set this is in your application's initialization process.
@objc
static var bypassVoiceProcessing: Bool {
get { RTC.bypassVoiceProcessing }
Expand Down

0 comments on commit 0c9c239

Please sign in to comment.