Skip to content

Commit

Permalink
[Fix]AudioProcessingModule deinit issues (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Apr 24, 2024
1 parent fda094c commit 87b4205
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ open class StreamAudioFilterProcessingModule: NSObject, RTCAudioProcessingModule
self.capturePostProcessingDelegate = capturePostProcessingDelegate
}

deinit {
processingModule.capturePostProcessingDelegate = nil
processingModule.renderPreProcessingDelegate = nil
capturePostProcessingDelegate.audioProcessingRelease()
}

public func apply(_ config: RTCAudioProcessingConfig) {
processingModule.apply(config)
}
Expand Down
8 changes: 8 additions & 0 deletions StreamVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
407F29FF2AA6011500C3EAF8 /* MemoryLogViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4093861E2AA0A21800FF5AF4 /* MemoryLogViewer.swift */; };
407F2A002AA6011B00C3EAF8 /* LogQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4093861B2AA0A11500FF5AF4 /* LogQueue.swift */; };
408679F72BD12F1000D027E0 /* AudioFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408679F62BD12F1000D027E0 /* AudioFilter.swift */; };
408CE0F72BD95EB60052EC3A /* VideoConfig+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408CE0F62BD95EB60052EC3A /* VideoConfig+Dummy.swift */; };
408CE0F82BD95F170052EC3A /* VideoConfig+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408CE0F62BD95EB60052EC3A /* VideoConfig+Dummy.swift */; };
408CE0F92BD95F1B0052EC3A /* VideoConfig+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408CE0F62BD95EB60052EC3A /* VideoConfig+Dummy.swift */; };
408D29A22B6D209700885473 /* SnapshotViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408D29A12B6D209700885473 /* SnapshotViewModifier.swift */; };
408D29A42B6D251600885473 /* UIView+Snapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408D29A32B6D251600885473 /* UIView+Snapshot.swift */; };
408D29AD2B6D680D00885473 /* SnapshotTrigger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408D29AB2B6D638100885473 /* SnapshotTrigger.swift */; };
Expand Down Expand Up @@ -1131,6 +1134,7 @@
407AF7192B6163DD00E9E3E7 /* StreamMediaDurationFormatter_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamMediaDurationFormatter_Tests.swift; sourceTree = "<group>"; };
407D5D3C2ACEF0C500B5044E /* VisibilityThresholdModifier_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibilityThresholdModifier_Tests.swift; sourceTree = "<group>"; };
408679F62BD12F1000D027E0 /* AudioFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioFilter.swift; sourceTree = "<group>"; };
408CE0F62BD95EB60052EC3A /* VideoConfig+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VideoConfig+Dummy.swift"; sourceTree = "<group>"; };
408D29A12B6D209700885473 /* SnapshotViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotViewModifier.swift; sourceTree = "<group>"; };
408D29A32B6D251600885473 /* UIView+Snapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Snapshot.swift"; sourceTree = "<group>"; };
408D29AB2B6D638100885473 /* SnapshotTrigger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotTrigger.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3334,6 +3338,7 @@
842747F229EED8D900E063AD /* InternetConnection_Mock.swift */,
82E3BA522A0BAF4B001AB93E /* WebSocketClientEnvironment_Mock.swift */,
406303412AD848000091AE77 /* CallParticipant_Mock.swift */,
408CE0F62BD95EB60052EC3A /* VideoConfig+Dummy.swift */,
);
path = Mock;
sourceTree = "<group>";
Expand Down Expand Up @@ -5029,6 +5034,7 @@
84F58B7829EE945900010C4C /* RetryStrategy_Tests.swift in Sources */,
84DCA2182A398C53000C3411 /* Call_Tests.swift in Sources */,
40F017472BBEEF5100E89FD1 /* ThumbnailResponse+Dummy.swift in Sources */,
408CE0F72BD95EB60052EC3A /* VideoConfig+Dummy.swift in Sources */,
84F58B7029EE914400010C4C /* BackgroundTaskScheduler_Tests.swift in Sources */,
842747F329EED8D900E063AD /* InternetConnection_Mock.swift in Sources */,
8478A0EC29F2604A0001F860 /* ControllerTestCase.swift in Sources */,
Expand Down Expand Up @@ -5318,6 +5324,7 @@
82E3BA4C2A0BAE40001AB93E /* EquatableEvent.swift in Sources */,
40914C9C2B56AA6600F6A13E /* StreamBufferTransformerTests.swift in Sources */,
82FF40C42A17C74D00B4D95E /* IncomingCallView_Tests.swift in Sources */,
408CE0F82BD95F170052EC3A /* VideoConfig+Dummy.swift in Sources */,
829F7BFA29FABC0E003EBACE /* ViewFactory.swift in Sources */,
8457BF802A5C18A7000AE567 /* ToastView_Tests.swift in Sources */,
82FF40C82A17C75C00B4D95E /* LobbyView_Tests.swift in Sources */,
Expand Down Expand Up @@ -5347,6 +5354,7 @@
82E3BA512A0BAEAB001AB93E /* MockFunc.swift in Sources */,
82E3BA472A0BAE1F001AB93E /* VirtualTime.swift in Sources */,
82E3BA392A0BADB9001AB93E /* CallController_Mock.swift in Sources */,
408CE0F92BD95F1B0052EC3A /* VideoConfig+Dummy.swift in Sources */,
82E3BA432A0BAE0A001AB93E /* EventBatcher_Mock.swift in Sources */,
8493227E29093A420013C029 /* StreamVideo_Mock.swift in Sources */,
82E3BA4F2A0BAE4E001AB93E /* VirtualTimer.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ParticipantsGridLayout_Tests: StreamVideoUITestCase {
callId: callId,
callType: callType,
apiKey: "123",
videoConfig: VideoConfig(),
videoConfig: .dummy(),
cachedLocation: nil
)

Expand Down
2 changes: 1 addition & 1 deletion StreamVideoTests/Call/Call_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class Call_Tests: StreamVideoTestCase {

func test_updateState_fromPermissionsEvent() {
// Given
let videoConfig = VideoConfig()
let videoConfig = VideoConfig.dummy()
let userResponse = mockResponseBuilder.makeUserResponse(id: "testuser")
let defaultAPI = DefaultAPI(
basePath: "https://example.com",
Expand Down
76 changes: 37 additions & 39 deletions StreamVideoTests/CallSettings/MicrophoneManager_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,61 @@
//

@testable import StreamVideo
import StreamWebRTC
import XCTest

final class MicrophoneManager_Tests: XCTestCase {

func test_microphoneManager_toggle() async throws {
// Given
let microphoneManager = MicrophoneManager(
callController: CallController_Mock.make(),
initialStatus: .enabled
try await assertStatus(
.disabled,
initialStatus: .enabled,
action: { try await $0.toggle() }
)

// When
try await microphoneManager.toggle()

// Then
XCTAssert(microphoneManager.status == .disabled)
}

func test_microphoneManager_enable() async throws {
// Given
let microphoneManager = MicrophoneManager(
callController: CallController_Mock.make(),
initialStatus: .disabled
try await assertStatus(
.enabled,
initialStatus: .disabled,
action: { try await $0.enable() }
)

// When
try await microphoneManager.enable()

// Then
XCTAssert(microphoneManager.status == .enabled)
}

func test_microphoneManager_disable() async throws {
// Given
let microphoneManager = MicrophoneManager(
callController: CallController_Mock.make(),
initialStatus: .enabled
try await assertStatus(
.disabled,
initialStatus: .enabled,
action: { try await $0.disable() }
)

// When
try await microphoneManager.disable()

// Then
XCTAssert(microphoneManager.status == .disabled)
}

func test_microphoneManager_sameState() async throws {
// Given
try await assertStatus(
.enabled,
initialStatus: .enabled,
action: { try await $0.enable() }
)
}

// MARK: - Private helpers

private func assertStatus(
_ expected: CallSettingsStatus,
initialStatus: CallSettingsStatus,
action: @escaping (MicrophoneManager) async throws -> Void,
file: StaticString = #file,
line: UInt = #line
) async throws {
let microphoneManager = MicrophoneManager(
callController: CallController_Mock.make(),
initialStatus: .enabled
initialStatus: initialStatus
)

// When
try await microphoneManager.enable()
try await action(microphoneManager)

// Then
XCTAssert(microphoneManager.status == .enabled)
XCTAssert(microphoneManager.status == expected)
}
}
2 changes: 1 addition & 1 deletion StreamVideoTests/Controllers/CallController_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ final class CallController_Tests: ControllerTestCase {
callCid: callCid,
sessionID: nil,
ownCapabilities: [.sendAudio, .sendVideo],
videoConfig: VideoConfig(),
videoConfig: .dummy(),
audioSettings: AudioSettings(
accessRequestEnabled: true,
defaultDevice: .speaker,
Expand Down
2 changes: 1 addition & 1 deletion StreamVideoTests/Controllers/ControllerTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ControllerTestCase: StreamVideoTestCase {
let callId = "123"
let callType: String = .default
let apiKey = "123"
let videoConfig = VideoConfig()
let videoConfig = VideoConfig.dummy()
var callCid: String {
"\(callType):\(callId)"
}
Expand Down
5 changes: 3 additions & 2 deletions StreamVideoTests/Mock/CallController_Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

@testable import StreamVideo
import StreamWebRTC

class CallController_Mock: CallController {

Expand All @@ -17,7 +18,7 @@ class CallController_Mock: CallController {
callCid: "default:test",
sessionID: nil,
ownCapabilities: [.sendAudio, .sendVideo],
videoConfig: VideoConfig(),
videoConfig: .dummy(),
audioSettings: AudioSettings(
accessRequestEnabled: true,
defaultDevice: .speaker,
Expand Down Expand Up @@ -75,7 +76,7 @@ extension CallController_Mock {
callId: "123",
callType: "default",
apiKey: "key1",
videoConfig: VideoConfig(),
videoConfig: .dummy(),
cachedLocation: nil
)
}
Expand Down
1 change: 1 addition & 0 deletions StreamVideoTests/Mock/StreamVideo_Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension StreamVideo {
apiKey: apiKey,
user: mockUser,
token: mockToken,
videoConfig: .dummy(),
tokenProvider: { result in
result(.success(mockToken))
},
Expand Down
21 changes: 21 additions & 0 deletions StreamVideoTests/Mock/VideoConfig+Dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//

import Foundation
import StreamVideo
import StreamWebRTC

extension VideoConfig {
static func dummy(
audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule()
) -> VideoConfig {
.init(audioProcessingModule: audioProcessingModule)
}
}

final class MockAudioProcessingModule: NSObject, AudioProcessingModule {
var activeAudioFilterId: String? { nil }
func setAudioFilter(_ filter: AudioFilter?) {}
func apply(_ config: RTCAudioProcessingConfig) {}
}
2 changes: 1 addition & 1 deletion StreamVideoTests/WebRTC/WebRTCClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ final class WebRTCClient_Tests: StreamVideoTestCase {
callCid: callCid,
sessionID: nil,
ownCapabilities: ownCapabilities,
videoConfig: VideoConfig(),
videoConfig: .dummy(),
audioSettings: AudioSettings(
accessRequestEnabled: true,
defaultDevice: .speaker,
Expand Down

0 comments on commit 87b4205

Please sign in to comment.