Skip to content

Commit cba83ea

Browse files
committed
Cleanup
1 parent 213f75f commit cba83ea

14 files changed

+794
-704
lines changed

Sources/StreamVideo/Utils/AudioSession/AudioDeviceModule/AudioDeviceModule.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
181181
", isVoiceProcessingAGCEnabled:\(isVoiceProcessingAGCEnabled)" +
182182
", audioLevel:\(audioLevel)" +
183183
", source:\(source)" +
184-
", engineOutput: \(engine?.outputDescription ?? "-")" +
185184
" }"
186185
}
187186

@@ -321,10 +320,6 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
321320
source.refreshStereoPlayoutState()
322321
}
323322

324-
func setVoiceProcessingBypassed(_ value: Bool) {
325-
source.isVoiceProcessingBypassed = value
326-
}
327-
328323
// MARK: - RTCAudioDeviceModuleDelegate
329324

330325
/// Receives speech activity notifications emitted by WebRTC VAD.
@@ -569,32 +564,3 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
569564
)
570565
}
571566
}
572-
573-
extension AVAudioEngine {
574-
575-
/// Human-readable description of the current output node format, used in
576-
/// logs when debugging device routing issues.
577-
var outputDescription: String {
578-
guard let remoteIO = outputNode.audioUnit else {
579-
return "not available"
580-
}
581-
582-
var asbd = AudioStreamBasicDescription()
583-
var size = UInt32(MemoryLayout<AudioStreamBasicDescription>.size)
584-
585-
let status = AudioUnitGetProperty(
586-
remoteIO,
587-
kAudioUnitProperty_StreamFormat,
588-
kAudioUnitScope_Output,
589-
0,
590-
&asbd,
591-
&size
592-
)
593-
594-
guard status == noErr else {
595-
return "failed to fetch information"
596-
}
597-
598-
return "\(asbd.mChannelsPerFrame) ch @ \(asbd.mSampleRate) Hz"
599-
}
600-
}

StreamVideoTests/Mock/MockAudioSession.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class MockAudioSession: AudioSessionProtocol, Mockable, @unchecked Sendabl
2121
case setActive
2222
case overrideOutputAudioPort
2323
case setConfiguration
24+
case setPreferredOutputNumberOfChannels
2425
}
2526

2627
enum MockFunctionInputKey: Payloadable {
@@ -33,6 +34,7 @@ final class MockAudioSession: AudioSessionProtocol, Mockable, @unchecked Sendabl
3334
case setActive(Bool)
3435
case overrideOutputAudioPort(AVAudioSession.PortOverride)
3536
case setConfiguration(RTCAudioSessionConfiguration)
37+
case setPreferredOutputNumberOfChannels(Int)
3638

3739
var payload: Any {
3840
switch self {
@@ -62,6 +64,9 @@ final class MockAudioSession: AudioSessionProtocol, Mockable, @unchecked Sendabl
6264

6365
case let .setConfiguration(configuration):
6466
return configuration
67+
68+
case let .setPreferredOutputNumberOfChannels(value):
69+
return value
6570
}
6671
}
6772
}
@@ -183,4 +188,13 @@ final class MockAudioSession: AudioSessionProtocol, Mockable, @unchecked Sendabl
183188
mode = configuration.mode
184189
categoryOptions = configuration.categoryOptions
185190
}
191+
192+
func setPreferredOutputNumberOfChannels(_ noOfChannels: Int) throws {
193+
stubbedFunctionInput[.setPreferredOutputNumberOfChannels]?
194+
.append(.setPreferredOutputNumberOfChannels(noOfChannels))
195+
196+
if let error = stubbedFunction[.setPreferredOutputNumberOfChannels] as? Error {
197+
throw error
198+
}
199+
}
186200
}

StreamVideoTests/Mock/MockRTCAudioDeviceModule.swift

Lines changed: 134 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,61 @@ final class MockRTCAudioDeviceModule: RTCAudioDeviceModuleControlling, Mockable,
1515
typealias FunctionInputKey = MockFunctionInputKey
1616

1717
enum MockFunctionKey: Hashable, CaseIterable {
18-
case initAndStartRecording
19-
case stopRecording
2018
case setMicrophoneMuted
2119
case microphoneMutedPublisher
20+
case reset
21+
case initAndStartPlayout
22+
case startPlayout
23+
case stopPlayout
24+
case initAndStartRecording
25+
case startRecording
26+
case stopRecording
27+
case refreshStereoPlayoutState
2228
}
2329

2430
enum MockFunctionInputKey: Payloadable {
25-
case initAndStartRecording
26-
case stopRecording
2731
case setMicrophoneMuted(Bool)
2832
case microphoneMutedPublisher
33+
case reset
34+
case initAndStartPlayout
35+
case startPlayout
36+
case stopPlayout
37+
case initAndStartRecording
38+
case startRecording
39+
case stopRecording
40+
case refreshStereoPlayoutState
2941

3042
var payload: Any {
3143
switch self {
44+
45+
case .setMicrophoneMuted(let value):
46+
return value
47+
48+
case .microphoneMutedPublisher:
49+
return ()
50+
51+
case .reset:
52+
return ()
53+
54+
case .initAndStartPlayout:
55+
return ()
56+
57+
case .startPlayout:
58+
return ()
59+
60+
case .stopPlayout:
61+
return ()
62+
3263
case .initAndStartRecording:
3364
return ()
3465

35-
case .stopRecording:
66+
case .startRecording:
3667
return ()
3768

38-
case .setMicrophoneMuted(let value):
39-
return value
69+
case .stopRecording:
70+
return ()
4071

41-
case .microphoneMutedPublisher:
72+
case .refreshStereoPlayoutState:
4273
return ()
4374
}
4475
}
@@ -59,6 +90,26 @@ final class MockRTCAudioDeviceModule: RTCAudioDeviceModuleControlling, Mockable,
5990

6091
init() {
6192
stub(for: \.isMicrophoneMuted, with: false)
93+
stub(for: \.isPlaying, with: false)
94+
stub(for: \.isRecording, with: false)
95+
stub(for: \.isPlayoutInitialized, with: false)
96+
stub(for: \.isRecordingInitialized, with: false)
97+
stub(for: \.isMicrophoneMuted, with: false)
98+
stub(for: \.isStereoPlayoutEnabled, with: false)
99+
stub(for: \.isVoiceProcessingBypassed, with: false)
100+
stub(for: \.isVoiceProcessingEnabled, with: false)
101+
stub(for: \.isVoiceProcessingAGCEnabled, with: false)
102+
stub(for: \.prefersStereoPlayout, with: false)
103+
104+
stub(for: .initAndStartRecording, with: 0)
105+
stub(for: .setMicrophoneMuted, with: 0)
106+
stub(for: .stopRecording, with: 0)
107+
stub(for: .reset, with: 0)
108+
stub(for: .initAndStartPlayout, with: 0)
109+
stub(for: .startPlayout, with: 0)
110+
stub(for: .stopPlayout, with: 0)
111+
stub(for: .startRecording, with: 0)
112+
stub(for: .refreshStereoPlayoutState, with: 0)
62113
}
63114

64115
// MARK: - RTCAudioDeviceModuleControlling
@@ -67,9 +118,46 @@ final class MockRTCAudioDeviceModule: RTCAudioDeviceModuleControlling, Mockable,
67118

68119
var observer: (any RTCAudioDeviceModuleDelegate)?
69120

121+
var isPlaying: Bool {
122+
self[dynamicMember: \.isPlaying]
123+
}
124+
125+
var isRecording: Bool {
126+
self[dynamicMember: \.isRecording]
127+
}
128+
129+
var isPlayoutInitialized: Bool {
130+
self[dynamicMember: \.isPlayoutInitialized]
131+
}
132+
133+
var isRecordingInitialized: Bool {
134+
self[dynamicMember: \.isRecordingInitialized]
135+
}
136+
70137
var isMicrophoneMuted: Bool {
71-
get { self[dynamicMember: \.isMicrophoneMuted] }
72-
set { _ = newValue }
138+
self[dynamicMember: \.isMicrophoneMuted]
139+
}
140+
141+
var isStereoPlayoutEnabled: Bool {
142+
self[dynamicMember: \.isStereoPlayoutEnabled]
143+
}
144+
145+
var isVoiceProcessingBypassed: Bool {
146+
get { self[dynamicMember: \.isVoiceProcessingBypassed] }
147+
set { stub(for: \.isVoiceProcessingBypassed, with: newValue) }
148+
}
149+
150+
var isVoiceProcessingEnabled: Bool {
151+
self[dynamicMember: \.isVoiceProcessingEnabled]
152+
}
153+
154+
var isVoiceProcessingAGCEnabled: Bool {
155+
self[dynamicMember: \.isVoiceProcessingAGCEnabled]
156+
}
157+
158+
var prefersStereoPlayout: Bool {
159+
get { self[dynamicMember: \.prefersStereoPlayout] }
160+
set { stub(for: \.prefersStereoPlayout, with: newValue) }
73161
}
74162

75163
func initAndStartRecording() -> Int {
@@ -81,7 +169,7 @@ final class MockRTCAudioDeviceModule: RTCAudioDeviceModuleControlling, Mockable,
81169
func setMicrophoneMuted(_ isMuted: Bool) -> Int {
82170
stubbedFunctionInput[.setMicrophoneMuted]?
83171
.append(.setMicrophoneMuted(isMuted))
84-
return stubbedFunction[.setMicrophoneMuted] as? Int ?? 0
172+
return stubbedFunction[.setMicrophoneMuted] as! Int
85173
}
86174

87175
func stopRecording() -> Int {
@@ -95,4 +183,39 @@ final class MockRTCAudioDeviceModule: RTCAudioDeviceModuleControlling, Mockable,
95183
.append(.microphoneMutedPublisher)
96184
return microphoneMutedSubject.eraseToAnyPublisher()
97185
}
186+
187+
func reset() -> Int {
188+
stubbedFunctionInput[.reset]?
189+
.append(.reset)
190+
return stubbedFunction[.reset] as! Int
191+
}
192+
193+
func initAndStartPlayout() -> Int {
194+
stubbedFunctionInput[.initAndStartPlayout]?
195+
.append(.initAndStartPlayout)
196+
return stubbedFunction[.initAndStartPlayout] as! Int
197+
}
198+
199+
func startPlayout() -> Int {
200+
stubbedFunctionInput[.startPlayout]?
201+
.append(.startPlayout)
202+
return stubbedFunction[.startPlayout] as! Int
203+
}
204+
205+
func stopPlayout() -> Int {
206+
stubbedFunctionInput[.stopPlayout]?
207+
.append(.stopPlayout)
208+
return stubbedFunction[.stopPlayout] as! Int
209+
}
210+
211+
func startRecording() -> Int {
212+
stubbedFunctionInput[.startRecording]?
213+
.append(.startRecording)
214+
return stubbedFunction[.startRecording] as! Int
215+
}
216+
217+
func refreshStereoPlayoutState() {
218+
stubbedFunctionInput[.refreshStereoPlayoutState]?
219+
.append(.refreshStereoPlayoutState)
220+
}
98221
}

0 commit comments

Comments
 (0)