Skip to content

Commit

Permalink
Fix can't compile tvOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Apr 16, 2024
1 parent aeff5de commit c927f04
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
29 changes: 28 additions & 1 deletion Sources/IO/IOAudioUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ protocol IOAudioUnitDelegate: AnyObject {
func audioUnit(_ audioUnit: IOAudioUnit, didOutput audioBuffer: AVAudioPCMBuffer, when: AVAudioTime)
}

final class IOAudioUnit: IOUnit<IOAudioCaptureUnit> {
final class IOAudioUnit: IOUnit {
let lockQueue = DispatchQueue(label: "com.haishinkit.HaishinKit.IOAudioUnit.lock")
weak var mixer: IOMixer?

var muted = false
var isMonitoringEnabled = false {
didSet {
Expand Down Expand Up @@ -62,6 +65,15 @@ final class IOAudioUnit: IOUnit<IOAudioCaptureUnit> {
}
}()
private var monitor: IOAudioMonitor = .init()
#if os(tvOS)
private var _captures: [UInt8: Any] = [:]
@available(tvOS 17.0, *)
var captures: [UInt8: IOAudioCaptureUnit] {
return _captures as! [UInt8: IOAudioCaptureUnit]
}
#elseif os(iOS) || os(macOS) || os(visionOS)
var captures: [UInt8: IOAudioCaptureUnit] = [:]
#endif

#if os(iOS) || os(macOS) || os(tvOS)
@available(tvOS 17.0, *)
Expand Down Expand Up @@ -110,6 +122,21 @@ final class IOAudioUnit: IOUnit<IOAudioCaptureUnit> {
func makeDataOutput(_ track: UInt8) -> IOAudioCaptureUnitDataOutput {
return .init(track: track, audioMixer: audioMixer)
}

@available(tvOS 17.0, *)
func capture(for track: UInt8) -> IOAudioCaptureUnit? {
#if os(tvOS)
if _captures[track] == nil {
_captures[track] = .init(track)
}
return _captures[track] as? IOAudioCaptureUnit
#else
if captures[track] == nil {
captures[track] = .init(track)
}
return captures[track]
#endif
}
}

extension IOAudioUnit: Running {
Expand Down
31 changes: 3 additions & 28 deletions Sources/IO/IOUnit.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import AVFAudio
import Foundation

class IOUnit<C: IOCaptureUnit> {
let lockQueue = DispatchQueue(label: "com.haishinkit.HaishinKit.IOUnit.lock")
weak var mixer: IOMixer?

#if os(tvOS)
private var _captures: [UInt8: Any] = [:]
@available(tvOS 17.0, *)
var captures: [UInt8: C] {
return _captures as! [UInt8: C]
}
#elseif os(iOS) || os(macOS) || os(visionOS)
var captures: [UInt8: C] = [:]
#endif

@available(tvOS 17.0, *)
func capture(for track: UInt8) -> C? {
#if os(tvOS)
if _captures[track] == nil {
_captures[track] = .init(track)
}
return _captures[track] as? C
#else
if captures[track] == nil {
captures[track] = .init(track)
}
return captures[track]
#endif
}
protocol IOUnit {
var lockQueue: DispatchQueue { get }
var mixer: IOMixer? { get }
}
30 changes: 29 additions & 1 deletion Sources/IO/IOVideoUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ protocol IOVideoUnitDelegate: AnyObject {
func videoUnit(_ videoUnit: IOVideoUnit, didOutput sampleBuffer: CMSampleBuffer)
}

final class IOVideoUnit: IOUnit<IOVideoCaptureUnit> {
final class IOVideoUnit: IOUnit {
enum Error: Swift.Error {
case multiCamNotSupported
}

let lockQueue = DispatchQueue(label: "com.haishinkit.HaishinKit.IOVideoUnit.lock")
weak var mixer: IOMixer?

weak var drawable: (any IOStreamView)? {
didSet {
#if os(iOS) || os(macOS)
Expand Down Expand Up @@ -136,6 +139,16 @@ final class IOVideoUnit: IOUnit<IOVideoCaptureUnit> {
return codec
}()

#if os(tvOS)
private var _captures: [UInt8: Any] = [:]
@available(tvOS 17.0, *)
var captures: [UInt8: IOVideoCaptureUnit] {
return _captures as! [UInt8: IOVideoCaptureUnit]
}
#elseif os(iOS) || os(macOS) || os(visionOS)
var captures: [UInt8: IOVideoCaptureUnit] = [:]
#endif

deinit {
if Thread.isMainThread {
self.drawable?.attachStream(nil)
Expand Down Expand Up @@ -217,6 +230,21 @@ final class IOVideoUnit: IOUnit<IOVideoCaptureUnit> {
func makeDataOutput(_ track: UInt8) -> IOVideoCaptureUnitDataOutput {
return .init(track: track, videoMixer: videoMixer)
}

@available(tvOS 17.0, *)
func capture(for track: UInt8) -> IOVideoCaptureUnit? {
#if os(tvOS)
if _captures[track] == nil {
_captures[track] = .init(track)
}
return _captures[track] as? IOVideoCaptureUnit
#else
if captures[track] == nil {
captures[track] = .init(track)
}
return captures[track]
#endif
}
}

extension IOVideoUnit: Running {
Expand Down

0 comments on commit c927f04

Please sign in to comment.