Skip to content

Commit

Permalink
Change in the option specification method for MediaMixer.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Nov 1, 2024
1 parent 81d83b3 commit 1e95f89
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
1 change: 0 additions & 1 deletion Examples/iOS/IngestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions Examples/iOS/Screencast/SampleHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
45 changes: 30 additions & 15 deletions Sources/Mixer/MediaMixer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1e95f89

Please sign in to comment.