Skip to content

Commit

Permalink
make public drawable.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Dec 3, 2023
1 parent a3a4f5d commit 1660479
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
5 changes: 1 addition & 4 deletions Sources/IO/MTHKView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,10 @@ public class MTHKView: MTKView {
}

private weak var currentStream: NetStream? {
willSet {
currentStream?.setNetStreamDrawable(nil)
}
didSet {
currentStream.map {
$0.context = CIContext(mtlDevice: device!)
$0.setNetStreamDrawable(self)
$0.drawable = self
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions Sources/IO/PiPHKView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ public class PiPHKView: UIView {
#endif

private weak var currentStream: NetStream? {
willSet {
currentStream?.setNetStreamDrawable(nil)
}
didSet {
currentStream?.setNetStreamDrawable(self)
currentStream?.drawable = self
}
}

Expand Down Expand Up @@ -195,11 +192,8 @@ public class PiPHKView: NSView {
}

private weak var currentStream: NetStream? {
willSet {
currentStream?.setNetStreamDrawable(nil)
}
didSet {
currentStream?.setNetStreamDrawable(self)
currentStream?.drawable = self
}
}

Expand Down
36 changes: 21 additions & 15 deletions Sources/Net/NetStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,29 @@ open class NetStream: NSObject {
/// The number of frames per second being displayed.
@objc public internal(set) dynamic var currentFPS: UInt16 = 0

/// Specifies the delegate..
/// Specifies the delegate.
public weak var delegate: (any NetStreamDelegate)?

/// Specifies the drawable.
public var drawable: (any NetStreamDrawable)? {
get {
mixer.videoIO.drawable
}
set {
mixer.videoIO.drawable = newValue
guard #available(tvOS 17.0, *) else {
return
}
lockQueue.async {
#if os(iOS) || os(tvOS) || os(macOS)
if self.mixer.videoIO.hasDevice {
self.mixer.session.startRunning()
}
#endif
}
}
}

/// The current state of the stream.
public var readyState: ReadyState = .initialized {
willSet {
Expand Down Expand Up @@ -438,20 +458,6 @@ open class NetStream: NSObject {
}
}

func setNetStreamDrawable(_ drawable: (any NetStreamDrawable)?) {
lockQueue.async {
self.mixer.videoIO.drawable = drawable
guard #available(tvOS 17.0, *) else {
return
}
#if os(iOS) || os(tvOS) || os(macOS)
if self.mixer.videoIO.hasDevice {
self.mixer.session.startRunning()
}
#endif
}
}

#if os(iOS) || os(tvOS)
@objc
private func didEnterBackground(_ notification: Notification) {
Expand Down

0 comments on commit 1660479

Please sign in to comment.