From a01e9386f728b445bc328f8e19c4e560387ca653 Mon Sep 17 00:00:00 2001 From: shogo4405 Date: Thu, 15 Aug 2024 10:00:44 +0900 Subject: [PATCH] Add (start|stop)Capturing() --- Sources/IO/IOStream.swift | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Sources/IO/IOStream.swift b/Sources/IO/IOStream.swift index ed7073838..0c63c0cae 100644 --- a/Sources/IO/IOStream.swift +++ b/Sources/IO/IOStream.swift @@ -96,6 +96,14 @@ open class IOStream: NSObject { } } + /// The capture session is in a running state or not. + @available(tvOS 17.0, *) + public var isCapturing: Bool { + lockQueue.sync { + mixer.session.isRunning.value + } + } + /// Specifies the audio monitoring enabled or not. public var isMonitoringEnabled: Bool { get { @@ -107,7 +115,7 @@ open class IOStream: NSObject { } #if os(iOS) || os(macOS) || os(tvOS) - /// Specifiet the device torch indicating wheter the turn on(TRUE) or not(FALSE). + /// Specifies the device torch indicating wheter the turn on(TRUE) or not(FALSE). public var torch: Bool { get { return lockQueue.sync { self.mixer.videoIO.torch } @@ -466,6 +474,24 @@ open class IOStream: NSObject { } } + /// Starts capturing from input devices. + /// + /// Internally, it is called either when the view is attached or just before publishing. In other cases, please call this method if you want to manually start the capture. + @available(tvOS 17.0, *) + public func startCapturing() { + lockQueue.async { + self.mixer.session.startRunning() + } + } + + /// Stops capturing from input devices. + @available(tvOS 17.0, *) + public func stopCapturing() { + lockQueue.async { + self.mixer.session.stopRunning() + } + } + #if os(iOS) || os(tvOS) || os(visionOS) @objc private func didEnterBackground(_ notification: Notification) {