diff --git a/Examples/iOS/IngestViewController.swift b/Examples/iOS/IngestViewController.swift index 00d005c05..a3abf058a 100644 --- a/Examples/iOS/IngestViewController.swift +++ b/Examples/iOS/IngestViewController.swift @@ -36,7 +36,6 @@ final class IngestViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() Task { - await mixer.setMultiCamSessionEnabled(true) // If you want to use the multi-camera feature, please make sure stream.isMultiCamSessionEnabled = true. Before attachCamera or attachAudio. // mixer.isMultiCamSessionEnabled = true if let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) { diff --git a/Examples/iOS/Screencast/SampleHandler.swift b/Examples/iOS/Screencast/SampleHandler.swift index 50191fc59..5e824622d 100644 --- a/Examples/iOS/Screencast/SampleHandler.swift +++ b/Examples/iOS/Screencast/SampleHandler.swift @@ -30,7 +30,7 @@ final class SampleHandler: RPBroadcastSampleHandler, @unchecked Sendable { } } } - private var mixer = MediaMixer() + private var mixer = MediaMixer(multiCamSessionEnabled: false, multiTrackAudioMixingEnabled: true) private let netStreamSwitcher = HKStreamSwitcher() private var needVideoConfiguration = true @@ -49,7 +49,6 @@ final class SampleHandler: RPBroadcastSampleHandler, @unchecked Sendable { // mixer.audioMixerSettings.tracks[1] = .default isVideoRotationEnabled = false Task { - await mixer.setMultiTrackAudioMixingEnabled(true) await netStreamSwitcher.setPreference(Preference.default) // ReplayKit is sensitive to memory, so we limit the queue to a maximum of five items. if let stream = await netStreamSwitcher.stream { diff --git a/Sources/Mixer/MediaMixer.swift b/Sources/Mixer/MediaMixer.swift index 0da0ea2a7..f6d00cf95 100644 --- a/Sources/Mixer/MediaMixer.swift +++ b/Sources/Mixer/MediaMixer.swift @@ -99,12 +99,31 @@ public final actor MediaMixer { @ScreenActor private lazy var displayLink = DisplayLinkChoreographer() + #if os(iOS) || os(tvOS) + /// Creates a new instance. + /// + /// - Parameters: + /// - multiCamSessionEnabled: Specifies the AVCaptureMultiCamSession enabled. + /// - multiTrackAudioMixingEnabled: Specifies the feature to mix multiple audio tracks. For example, it is possible to mix .appAudio and .micAudio from ReplayKit. + public init(multiCamSessionEnabled: Bool = true, multiTrackAudioMixingEnabled: Bool = false) { + Task { + await setMultiCamSessionEnabled(multiCamSessionEnabled) + await setMultiTrackAudioMixingEnabled(multiTrackAudioMixingEnabled) + await startRunning() + } + } + #else /// Creates a new instance. - public init() { + /// + /// - Parameters: + /// - multiTrackAudioMixingEnabled: Specifies the feature to mix multiple audio tracks. For example, it is possible to mix .appAudio and .micAudio from ReplayKit. + public init(multiTrackAudioMixingEnabled: Bool = false) { Task { + await setMultiTrackAudioMixingEnabled(multiTrackAudioMixingEnabled) await startRunning() } } + #endif /// Attaches a video device. @available(tvOS 17.0, *) @@ -246,20 +265,6 @@ public final actor MediaMixer { session.stopRunning() } - #if os(iOS) || os(tvOS) - /// Specifies the AVCaptureMultiCamSession enabled. - /// - Attention: If there is a possibility of using multiple cameras, please set it to true initially. - public func setMultiCamSessionEnabled(_ multiCamSessionEnabled: Bool) { - session.isMultiCamSessionEnabled = multiCamSessionEnabled - } - #endif - - /// Specifies the feature to mix multiple audio tracks. For example, it is possible to mix .appAudio and .micAudio from ReplayKit. - /// - Attention: If there is a possibility of this feature, please set it to true initially. - public func setMultiTrackAudioMixingEnabled(_ multiTrackAudioMixingEnabled: Bool) { - audioIO.isMultiTrackAudioMixingEnabled = multiTrackAudioMixingEnabled - } - /// Appends an AVAudioBuffer. /// - Parameters: /// - audioBuffer:The audio buffer to append. @@ -296,6 +301,16 @@ public final actor MediaMixer { } } + #if os(iOS) || os(tvOS) + func setMultiCamSessionEnabled(_ multiCamSessionEnabled: Bool) { + session.isMultiCamSessionEnabled = multiCamSessionEnabled + } + #endif + + func setMultiTrackAudioMixingEnabled(_ multiTrackAudioMixingEnabled: Bool) { + audioIO.isMultiTrackAudioMixingEnabled = multiTrackAudioMixingEnabled + } + func setVideoRenderingMode(_ mode: VideoMixerSettings.Mode) { switch mode { case .passthrough: