Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Jan 3, 2025
1 parent 6f4783c commit d215eac
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Sources/StreamVideo/Models/AudioCodec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions Sources/StreamVideo/Models/PublishOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
}
}

Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion StreamVideoSwiftUITests/CallViewModel_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ final class MockRTCPeerConnectionCoordinator:
screenShareSessionProvider: ScreenShareSessionProvider = .init()
) throws {
let peerConnectionFactory = PeerConnectionFactory.build(
audioProcessingModule: MockAudioProcessingModule()
audioProcessingModule: MockAudioProcessingModule.shared
)
self.init(
sessionId: .unique,
Expand Down
2 changes: 1 addition & 1 deletion StreamVideoTests/Mock/PeerConnectionFactory+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private var _pc: RTCPeerConnection?

extension PeerConnectionFactory {
static func mock(
_ audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule()
_ audioProcessingModule: AudioProcessingModule = MockAudioProcessingModule.shared
) -> PeerConnectionFactory {
.build(
audioProcessingModule: audioProcessingModule
Expand Down
4 changes: 3 additions & 1 deletion StreamVideoTests/Mock/VideoConfig+Dummy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d215eac

Please sign in to comment.