Skip to content

Commit

Permalink
Merge pull request #1474 from shogo4405/feature/remove-feature-falgs
Browse files Browse the repository at this point in the history
Remove FeatureUtil for Swift 6.0.
  • Loading branch information
shogo4405 authored Jun 12, 2024
2 parents c219468 + b53bf86 commit 3494757
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 67 deletions.
5 changes: 3 additions & 2 deletions Examples/iOS/Screencast/SampleHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ open class SampleHandler: RPBroadcastSampleHandler {
}()

private lazy var rtmpStream: RTMPStream = {
FeatureUtil.setEnabled(for: .multiTrackAudioMixing, isEnabled: true)
return RTMPStream(connection: rtmpConnection)
let stream = RTMPStream(connection: rtmpConnection)
stream.isMultiTrackAudioMixingEnabled = true
return stream
}()

private var needVideoConfiguration = true
Expand Down
1 change: 0 additions & 1 deletion Examples/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ aNotification: Notification) {
LBLogger.with(HaishinKitIdentifier).level = .info
FeatureUtil.setEnabled(for: .multiTrackAudioMixing, isEnabled: true)
}
}
4 changes: 3 additions & 1 deletion Examples/macOS/CameraIngestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class CameraIngestViewController: NSViewController {

override func viewDidAppear() {
super.viewDidAppear()

stream.isMultiTrackAudioMixingEnabled = true

stream.videoMixerSettings.mode = .offscreen
stream.screen.startRunning()
Expand Down Expand Up @@ -80,7 +82,7 @@ final class CameraIngestViewController: NSViewController {

var audios = AVCaptureDevice.devices(for: .audio)
audios.removeFirst()
if let device = audios.first, FeatureUtil.isEnabled(for: .multiTrackAudioMixing) {
if let device = audios.first, stream.isMultiTrackAudioMixingEnabled {
stream.attachAudio(device, track: 1)
}

Expand Down
4 changes: 0 additions & 4 deletions HaishinKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
BC4078C42AD5CC7E00BBB4FA /* IOMuxer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4078C32AD5CC7E00BBB4FA /* IOMuxer.swift */; };
BC4231642BCA5F28003A80DC /* IOAudioMixerByMultiTrack.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4231632BCA5F28003A80DC /* IOAudioMixerByMultiTrack.swift */; };
BC42316A2BCA8BE5003A80DC /* IOAudioMixerBySingleTrack.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4231692BCA8BE5003A80DC /* IOAudioMixerBySingleTrack.swift */; };
BC42316C2BCB7084003A80DC /* FeatureUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC42316B2BCB7084003A80DC /* FeatureUtil.swift */; };
BC4914A228DDD33D009E2DF6 /* VTSessionConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4914A128DDD33D009E2DF6 /* VTSessionConvertible.swift */; };
BC4914A628DDD367009E2DF6 /* VTSessionOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4914A528DDD367009E2DF6 /* VTSessionOption.swift */; };
BC4914AE28DDF445009E2DF6 /* VTDecompressionSession+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC4914AD28DDF445009E2DF6 /* VTDecompressionSession+Extension.swift */; };
Expand Down Expand Up @@ -661,7 +660,6 @@
BC4078C32AD5CC7E00BBB4FA /* IOMuxer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOMuxer.swift; sourceTree = "<group>"; };
BC4231632BCA5F28003A80DC /* IOAudioMixerByMultiTrack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOAudioMixerByMultiTrack.swift; sourceTree = "<group>"; };
BC4231692BCA8BE5003A80DC /* IOAudioMixerBySingleTrack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOAudioMixerBySingleTrack.swift; sourceTree = "<group>"; };
BC42316B2BCB7084003A80DC /* FeatureUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureUtil.swift; sourceTree = "<group>"; };
BC4914A128DDD33D009E2DF6 /* VTSessionConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VTSessionConvertible.swift; sourceTree = "<group>"; };
BC4914A528DDD367009E2DF6 /* VTSessionOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VTSessionOption.swift; sourceTree = "<group>"; };
BC4914AD28DDF445009E2DF6 /* VTDecompressionSession+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VTDecompressionSession+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -877,7 +875,6 @@
BC0D236C26331BAB001DDA0C /* DataBuffer.swift */,
29B876671CD70AB300FC07DA /* DataConvertible.swift */,
2976A4851D4903C300B53EF2 /* DeviceUtil.swift */,
BC42316B2BCB7084003A80DC /* FeatureUtil.swift */,
BC32E88729C9971100051507 /* InstanceHolder.swift */,
2942424C1CF4C01300D65DCB /* MD5.swift */,
2942A4F721A9418A004E1BEE /* Running.swift */,
Expand Down Expand Up @@ -1920,7 +1917,6 @@
BC0F1FDC2ACC630400C326FF /* NSView+Extension.swift in Sources */,
BC16019C2BE0E4750061BD3E /* ScreenObject.swift in Sources */,
29EA87E21E79A1E90043A5F8 /* CMVideoFormatDescription+Extension.swift in Sources */,
BC42316C2BCB7084003A80DC /* FeatureUtil.swift in Sources */,
BC110253292DD6E900D48035 /* vImage_Buffer+Extension.swift in Sources */,
BC1DC4A429F4F74F00E928ED /* AVCaptureSession+Extension.swift in Sources */,
29EA87D81E79A0090043A5F8 /* URL+Extension.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ stream.attachAudio(front, track: 0) { audioUnit, error in
```

#### [AudioMixerSettings](https://shogo4405.github.io/HaishinKit.swift/Structs/IOAudioMixerSettings.html)
If you want to mix multiple audio tracks, please enable the Feature flag.
If you want to mix multiple audio tracks, please enable the feature flag.
```swift
FeatureUtil.setEnabled(for: .multiTrackAudioMixing, isEnabled: true)
stream.isMultiTrackAudioMixingEnabled = true
```

When you specify the sampling rate, it will perform resampling. Additionally, in the case of multiple channels, downsampling can be applied.
Expand Down
21 changes: 11 additions & 10 deletions Sources/IO/IOAudioUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ protocol IOAudioUnitDelegate: AnyObject {
final class IOAudioUnit: IOUnit {
let lockQueue = DispatchQueue(label: "com.haishinkit.HaishinKit.IOAudioUnit.lock")
weak var mixer: IOMixer?
var isMonitoringEnabled = false {
didSet {
if isMonitoringEnabled {
monitor.startRunning()
} else {
monitor.stopRunning()
}
}
}
var settings: AudioCodecSettings {
get {
codec.settings
Expand All @@ -50,6 +41,16 @@ final class IOAudioUnit: IOUnit {
audioMixer.settings = newValue
}
}
var isMonitoringEnabled = false {
didSet {
if isMonitoringEnabled {
monitor.startRunning()
} else {
monitor.stopRunning()
}
}
}
var isMultiTrackAudioMixingEnabled = false
var isRunning: Atomic<Bool> {
return codec.isRunning
}
Expand All @@ -65,7 +66,7 @@ final class IOAudioUnit: IOUnit {
return codec
}()
private lazy var audioMixer: any IOAudioMixerConvertible = {
if FeatureUtil.isEnabled(for: .multiTrackAudioMixing) {
if isMultiTrackAudioMixingEnabled {
var audioMixer = IOAudioMixerByMultiTrack()
audioMixer.delegate = self
return audioMixer
Expand Down
11 changes: 11 additions & 0 deletions Sources/IO/IOStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ open class IOStream: NSObject {
}
#endif

/// Specifies the feature to mix multiple audio tracks. For example, it is possible to mix .appAudio and .micAudio from ReplayKit.
/// Warning: If there is a possibility of this feature, please set it to true initially.
public var isMultiTrackAudioMixingEnabled: Bool {
get {
return mixer.audioIO.isMultiTrackAudioMixingEnabled
}
set {
mixer.audioIO.isMultiTrackAudioMixingEnabled = newValue
}
}

/// Specifies the sessionPreset for the AVCaptureSession.
@available(tvOS 17.0, *)
public var sessionPreset: AVCaptureSession.Preset {
Expand Down
4 changes: 0 additions & 4 deletions Sources/IO/PiPHKView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ public class PiPHKView: NSView {
super.init(coder: aDecoder)
}

deinit {
attachStream(nil)
}

/// Prepares the receiver for service after it has been loaded from an Interface Builder archive, or nib file.
override public func awakeFromNib() {
super.awakeFromNib()
Expand Down
43 changes: 0 additions & 43 deletions Sources/Util/FeatureUtil.swift

This file was deleted.

0 comments on commit 3494757

Please sign in to comment.