Skip to content

Commit f5a5958

Browse files
authored
Update engine observer methods (#572)
1 parent 20f8c3e commit f5a5958

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
],
1919
dependencies: [
2020
// LK-Prefixed Dynamic WebRTC XCFramework
21-
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.15"),
21+
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.16"),
2222
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
2323
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
2424
// Only used for DocC generation

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
],
2121
dependencies: [
2222
// LK-Prefixed Dynamic WebRTC XCFramework
23-
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.15"),
23+
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.16"),
2424
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
2525
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
2626
// Only used for DocC generation

Sources/LiveKit/Audio/AudioDeviceModuleDelegateAdapter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ class AudioDeviceModuleDelegateAdapter: NSObject, LKRTCAudioDeviceModuleDelegate
7474
entryPoint?.engineWillRelease(engine)
7575
}
7676

77-
func audioDeviceModule(_: LKRTCAudioDeviceModule, engine: AVAudioEngine, configureInputFromSource src: AVAudioNode?, toDestination dst: AVAudioNode, format: AVAudioFormat) -> Bool {
78-
guard let audioManager else { return false }
77+
func audioDeviceModule(_: LKRTCAudioDeviceModule, engine: AVAudioEngine, configureInputFromSource src: AVAudioNode?, toDestination dst: AVAudioNode, format: AVAudioFormat, context: [AnyHashable: Any]) {
78+
guard let audioManager else { return }
7979
let entryPoint = audioManager.buildEngineObserverChain()
80-
return entryPoint?.engineWillConnectInput(engine, src: src, dst: dst, format: format) ?? false
80+
entryPoint?.engineWillConnectInput(engine, src: src, dst: dst, format: format, context: context)
8181
}
8282

83-
func audioDeviceModule(_: LKRTCAudioDeviceModule, engine: AVAudioEngine, configureOutputFromSource src: AVAudioNode, toDestination dst: AVAudioNode?, format: AVAudioFormat) -> Bool {
84-
guard let audioManager else { return false }
83+
func audioDeviceModule(_: LKRTCAudioDeviceModule, engine: AVAudioEngine, configureOutputFromSource src: AVAudioNode, toDestination dst: AVAudioNode?, format: AVAudioFormat, context: [AnyHashable: Any]) {
84+
guard let audioManager else { return }
8585
let entryPoint = audioManager.buildEngineObserverChain()
86-
return entryPoint?.engineWillConnectOutput(engine, src: src, dst: dst, format: format) ?? false
86+
entryPoint?.engineWillConnectOutput(engine, src: src, dst: dst, format: format, context: context)
8787
}
8888
}

Sources/LiveKit/Audio/AudioEngineObserver.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
import AVFAudio
1818

19+
#if swift(>=5.9)
20+
internal import LiveKitWebRTC
21+
#else
22+
@_implementationOnly import LiveKitWebRTC
23+
#endif
24+
25+
public let AudioEngineInputMixerNodeKey = kRTCAudioEngineInputMixerNodeKey
26+
1927
/// Do not retain the engine object.
2028
public protocol AudioEngineObserver: NextInvokable, Sendable {
2129
associatedtype Next = any AudioEngineObserver
@@ -31,11 +39,11 @@ public protocol AudioEngineObserver: NextInvokable, Sendable {
3139
/// Provide custom implementation for internal AVAudioEngine's output configuration.
3240
/// Buffers flow from `src` to `dst`. Preferred format to connect node is provided as `format`.
3341
/// Return true if custom implementation is provided, otherwise default implementation will be used.
34-
func engineWillConnectOutput(_ engine: AVAudioEngine, src: AVAudioNode, dst: AVAudioNode?, format: AVAudioFormat) -> Bool
42+
func engineWillConnectOutput(_ engine: AVAudioEngine, src: AVAudioNode, dst: AVAudioNode?, format: AVAudioFormat, context: [AnyHashable: Any])
3543
/// Provide custom implementation for internal AVAudioEngine's input configuration.
3644
/// Buffers flow from `src` to `dst`. Preferred format to connect node is provided as `format`.
3745
/// Return true if custom implementation is provided, otherwise default implementation will be used.
38-
func engineWillConnectInput(_ engine: AVAudioEngine, src: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat) -> Bool
46+
func engineWillConnectInput(_ engine: AVAudioEngine, src: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat, context: [AnyHashable: Any])
3947
}
4048

4149
/// Default implementation to make it optional.
@@ -64,11 +72,11 @@ public extension AudioEngineObserver {
6472
next?.engineWillRelease(engine)
6573
}
6674

67-
func engineWillConnectOutput(_ engine: AVAudioEngine, src: AVAudioNode, dst: AVAudioNode?, format: AVAudioFormat) -> Bool {
68-
next?.engineWillConnectOutput(engine, src: src, dst: dst, format: format) ?? false
75+
func engineWillConnectOutput(_ engine: AVAudioEngine, src: AVAudioNode, dst: AVAudioNode?, format: AVAudioFormat, context: [AnyHashable: Any]) {
76+
next?.engineWillConnectOutput(engine, src: src, dst: dst, format: format, context: context)
6977
}
7078

71-
func engineWillConnectInput(_ engine: AVAudioEngine, src: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat) -> Bool {
72-
next?.engineWillConnectInput(engine, src: src, dst: dst, format: format) ?? false
79+
func engineWillConnectInput(_ engine: AVAudioEngine, src: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat, context: [AnyHashable: Any]) {
80+
next?.engineWillConnectInput(engine, src: src, dst: dst, format: format, context: context)
7381
}
7482
}

Tests/LiveKitTests/AudioEngineTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,9 @@ final class SineWaveNodeHook: AudioEngineObserver {
294294
engine.detach(sineWaveNode)
295295
}
296296

297-
func engineWillConnectInput(_ engine: AVAudioEngine, src _: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat) -> Bool {
297+
func engineWillConnectInput(_ engine: AVAudioEngine, src _: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat, context _: [AnyHashable: Any]) {
298298
print("engineWillConnectInput")
299299
engine.connect(sineWaveNode, to: dst, format: format)
300-
return true
301300
}
302301
}
303302

@@ -322,10 +321,9 @@ final class PlayerNodeHook: AudioEngineObserver {
322321
engine.detach(playerMixerNode)
323322
}
324323

325-
func engineWillConnectInput(_ engine: AVAudioEngine, src _: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat) -> Bool {
324+
func engineWillConnectInput(_ engine: AVAudioEngine, src _: AVAudioNode?, dst: AVAudioNode, format: AVAudioFormat, context _: [AnyHashable: Any]) {
326325
print("engineWillConnectInput")
327326
engine.connect(playerNode, to: playerMixerNode, format: playerNodeFormat)
328327
engine.connect(playerMixerNode, to: dst, format: format)
329-
return true
330328
}
331329
}

0 commit comments

Comments
 (0)