From d215eac6b99c6e0b6d1c9efd19b2a10e82b75bf4 Mon Sep 17 00:00:00 2001 From: Ilias Pavlidakis Date: Mon, 30 Dec 2024 18:23:21 +0200 Subject: [PATCH] Updates --- Sources/StreamVideo/Models/AudioCodec.swift | 2 +- Sources/StreamVideo/Models/PublishOptions.swift | 13 +------------ ...eam_Video_Sfu_Models_Codec+Convenience.swift | 17 +++++++++++++++++ .../LocalScreenShareMediaAdapter.swift | 2 +- .../LocalVideoMediaAdapter.swift | 2 +- .../CallViewModel_Tests.swift | 2 +- ...PictureInPictureTrackStateAdapterTests.swift | 2 +- .../Mock/MockRTCPeerConnectionCoordinator.swift | 2 +- .../Mock/PeerConnectionFactory+Mock.swift | 2 +- StreamVideoTests/Mock/VideoConfig+Dummy.swift | 4 +++- .../LocalAudioMediaAdapter_Tests.swift | 2 ++ 11 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Sources/StreamVideo/Models/AudioCodec.swift b/Sources/StreamVideo/Models/AudioCodec.swift index c817becca..91cd98891 100644 --- a/Sources/StreamVideo/Models/AudioCodec.swift +++ b/Sources/StreamVideo/Models/AudioCodec.swift @@ -6,7 +6,7 @@ import Foundation import StreamWebRTC /// Represents different audio codecs. -public enum AudioCodec: String, CustomStringConvertible { +public enum AudioCodec: String, CustomStringConvertible, Sendable { case opus case red case unknown diff --git a/Sources/StreamVideo/Models/PublishOptions.swift b/Sources/StreamVideo/Models/PublishOptions.swift index db098bba7..d2d4d1d64 100644 --- a/Sources/StreamVideo/Models/PublishOptions.swift +++ b/Sources/StreamVideo/Models/PublishOptions.swift @@ -91,8 +91,7 @@ struct PublishOptions: Sendable, Hashable { /// A string representation of the capturing layers. var description: String { - "CapturingLayers(spatial: \(spatialLayers), temporal: \(temporalLayers), " + - "scalabilityMode: \(scalabilityMode))" + "CapturingLayers(spatial: \(spatialLayers), temporal: \(temporalLayers), scalabilityMode: \(scalabilityMode))" } } @@ -171,16 +170,6 @@ struct PublishOptions: Sendable, Hashable { lhs.id == rhs.id && lhs.codec == rhs.codec } - /// Returns the codec for the specified track type. - /// - Parameter trackType: The type of track for which to get the codec. - /// - Returns: The codec for the specified track type. - func codec(for trackType: TrackType) -> Stream_Video_Sfu_Models_Codec { - Stream_Video_Sfu_Models_PublishOption( - self, - trackType: trackType == .video ? .video : .screenShare - ).codec - } - /// Builds video layers for the specified track type. /// /// This method creates an array of `Stream_Video_Sfu_Models_VideoLayer` diff --git a/Sources/StreamVideo/WebRTC/v2/Extensions/Protobuf/Stream_Video_Sfu_Models_Codec+Convenience.swift b/Sources/StreamVideo/WebRTC/v2/Extensions/Protobuf/Stream_Video_Sfu_Models_Codec+Convenience.swift index dbf986dce..c128072fa 100644 --- a/Sources/StreamVideo/WebRTC/v2/Extensions/Protobuf/Stream_Video_Sfu_Models_Codec+Convenience.swift +++ b/Sources/StreamVideo/WebRTC/v2/Extensions/Protobuf/Stream_Video_Sfu_Models_Codec+Convenience.swift @@ -38,3 +38,20 @@ extension Stream_Video_Sfu_Models_Codec { payloadType = source.preferredPayloadType?.uint32Value ?? 0 } } + +/// Extension adding a convenience initializer for `Stream_Video_Sfu_Models_Codec`. +extension Stream_Video_Sfu_Models_Codec { + + /// Initializes a `Stream_Video_Sfu_Models_Codec` from a `VideoCodec`. + /// + /// This initializer converts the codec information from the `VideoCodec` + /// enumeration into a `Stream_Video_Sfu_Models_Codec` model. + /// + /// - Parameter source: The `VideoCodec` to convert. + /// + /// - Note: + /// - `name` is mapped directly from the codec's raw value. + init(_ source: VideoCodec) { + self.name = source.rawValue + } +} diff --git a/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalScreenShareMediaAdapter.swift b/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalScreenShareMediaAdapter.swift index 7f07efdb6..dbc10c192 100644 --- a/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalScreenShareMediaAdapter.swift +++ b/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalScreenShareMediaAdapter.swift @@ -305,7 +305,7 @@ final class LocalScreenShareMediaAdapter: LocalMediaAdapting, @unchecked Sendabl trackInfo.layers = publishOptions.buildLayers(for: .screenshare) trackInfo.mid = transceiver.mid trackInfo.muted = !(transceiver.sender.track?.isEnabled ?? false) - trackInfo.codec = publishOptions.codec(for: .screenshare) + trackInfo.codec = .init(publishOptions.codec) return trackInfo } } diff --git a/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalVideoMediaAdapter.swift b/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalVideoMediaAdapter.swift index 34a6bdb65..eb4536b0e 100644 --- a/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalVideoMediaAdapter.swift +++ b/Sources/StreamVideo/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalVideoMediaAdapter.swift @@ -346,7 +346,7 @@ final class LocalVideoMediaAdapter: LocalMediaAdapting, @unchecked Sendable { trackInfo.layers = publishOptions.buildLayers(for: .video) trackInfo.mid = transceiver.mid trackInfo.muted = !(transceiver.sender.track?.isEnabled ?? false) - trackInfo.codec = publishOptions.codec(for: .video) + trackInfo.codec = .init(publishOptions.codec) return trackInfo } } diff --git a/StreamVideoSwiftUITests/CallViewModel_Tests.swift b/StreamVideoSwiftUITests/CallViewModel_Tests.swift index cce8642bf..e9d268457 100644 --- a/StreamVideoSwiftUITests/CallViewModel_Tests.swift +++ b/StreamVideoSwiftUITests/CallViewModel_Tests.swift @@ -17,7 +17,7 @@ final class CallViewModel_Tests: StreamVideoTestCase { private lazy var eventNotificationCenter = streamVideo?.eventNotificationCenter private lazy var callId: String! = UUID().uuidString private lazy var participants: [Member]! = [firstUser, secondUser] - private lazy var peerConnectionFactory: PeerConnectionFactory! = .build(audioProcessingModule: MockAudioProcessingModule()) + private lazy var peerConnectionFactory: PeerConnectionFactory! = .build(audioProcessingModule: MockAudioProcessingModule.shared) private var cId: String { callCid(from: callId, callType: callType) } diff --git a/StreamVideoSwiftUITests/Utils/PictureInPicture/StreamPictureInPictureTrackStateAdapterTests.swift b/StreamVideoSwiftUITests/Utils/PictureInPicture/StreamPictureInPictureTrackStateAdapterTests.swift index d56f9ab12..cb1123ae4 100644 --- a/StreamVideoSwiftUITests/Utils/PictureInPicture/StreamPictureInPictureTrackStateAdapterTests.swift +++ b/StreamVideoSwiftUITests/Utils/PictureInPicture/StreamPictureInPictureTrackStateAdapterTests.swift @@ -10,7 +10,7 @@ import XCTest final class StreamPictureInPictureTrackStateAdapterTests: XCTestCase, @unchecked Sendable { - private var factory: PeerConnectionFactory! = .build(audioProcessingModule: MockAudioProcessingModule()) + private var factory: PeerConnectionFactory! = .build(audioProcessingModule: MockAudioProcessingModule.shared) private var adapter: StreamPictureInPictureTrackStateAdapter! = .init() private lazy var trackA: RTCVideoTrack! = factory.makeVideoTrack(source: factory.makeVideoSource(forScreenShare: false)) diff --git a/StreamVideoTests/Mock/MockRTCPeerConnectionCoordinator.swift b/StreamVideoTests/Mock/MockRTCPeerConnectionCoordinator.swift index 87b82f418..56c76d575 100644 --- a/StreamVideoTests/Mock/MockRTCPeerConnectionCoordinator.swift +++ b/StreamVideoTests/Mock/MockRTCPeerConnectionCoordinator.swift @@ -144,7 +144,7 @@ final class MockRTCPeerConnectionCoordinator: screenShareSessionProvider: ScreenShareSessionProvider = .init() ) throws { let peerConnectionFactory = PeerConnectionFactory.build( - audioProcessingModule: MockAudioProcessingModule() + audioProcessingModule: MockAudioProcessingModule.shared ) self.init( sessionId: .unique, diff --git a/StreamVideoTests/Mock/PeerConnectionFactory+Mock.swift b/StreamVideoTests/Mock/PeerConnectionFactory+Mock.swift index 44cc01354..af9d7cc27 100644 --- a/StreamVideoTests/Mock/PeerConnectionFactory+Mock.swift +++ b/StreamVideoTests/Mock/PeerConnectionFactory+Mock.swift @@ -9,7 +9,7 @@ private var _pc: RTCPeerConnection? extension PeerConnectionFactory { static func mock( - _ audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule() + _ audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule.shared ) -> PeerConnectionFactory { .build( audioProcessingModule: audioProcessingModule diff --git a/StreamVideoTests/Mock/VideoConfig+Dummy.swift b/StreamVideoTests/Mock/VideoConfig+Dummy.swift index 842829647..463900cdc 100644 --- a/StreamVideoTests/Mock/VideoConfig+Dummy.swift +++ b/StreamVideoTests/Mock/VideoConfig+Dummy.swift @@ -8,13 +8,15 @@ import StreamWebRTC extension VideoConfig { static func dummy( - audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule() + audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule.shared ) -> VideoConfig { .init(audioProcessingModule: audioProcessingModule) } } final class MockAudioProcessingModule: NSObject, AudioProcessingModule { + static let shared = MockAudioProcessingModule() + override private init() {} var activeAudioFilter: AudioFilter? { nil } func setAudioFilter(_ filter: AudioFilter?) {} func apply(_ config: RTCAudioProcessingConfig) {} diff --git a/StreamVideoTests/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalAudioMediaAdapter_Tests.swift b/StreamVideoTests/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalAudioMediaAdapter_Tests.swift index 2b263a7dc..62560d895 100644 --- a/StreamVideoTests/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalAudioMediaAdapter_Tests.swift +++ b/StreamVideoTests/WebRTC/v2/PeerConnection/MediaAdapters/LocalMediaAdapters/LocalAudioMediaAdapter_Tests.swift @@ -128,6 +128,7 @@ final class LocalAudioMediaAdapter_Tests: XCTestCase, @unchecked Sendable { ) try await subject.didUpdateCallSettings(.init(audioOn: true)) + await fulfillment { self.mockSFUStack.service.updateMuteStatesWasCalledWithRequest != nil } let request = try XCTUnwrap(mockSFUStack.service.updateMuteStatesWasCalledWithRequest) XCTAssertEqual(request.sessionID, sessionId) @@ -144,6 +145,7 @@ final class LocalAudioMediaAdapter_Tests: XCTestCase, @unchecked Sendable { subject.primaryTrack.isEnabled = true try await subject.didUpdateCallSettings(.init(audioOn: false)) + await fulfillment { self.mockSFUStack.service.updateMuteStatesWasCalledWithRequest != nil } let request = try XCTUnwrap(mockSFUStack.service.updateMuteStatesWasCalledWithRequest) XCTAssertEqual(request.sessionID, sessionId)