Skip to content

Commit

Permalink
Merge pull request #1351 from shogo4405/feature/lock-queque
Browse files Browse the repository at this point in the history
stream#videoCapture performance improvement.
  • Loading branch information
shogo4405 authored Dec 8, 2023
2 parents 71c3da3 + 7c84b1c commit 200785d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
31 changes: 12 additions & 19 deletions Sources/IO/IOVideoUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,14 @@ final class IOVideoUnit: NSObject, IOUnit {
try capture.attachDevice(nil, videoUnit: self)
}
try capture(for: channel)?.attachDevice(device, videoUnit: self)
}
if device != nil {
if drawable != nil {
// Start captureing if not running.
mixer?.session.startRunning()
}
} else {
lockQueue.async {
self.videoMixer.detach(channel)
if device == nil {
videoMixer.detach(channel)
}
}
if device != nil && drawable != nil {
// Start captureing if not running.
mixer?.session.startRunning()
}
}

@available(tvOS 17.0, *)
Expand All @@ -258,19 +255,15 @@ final class IOVideoUnit: NSObject, IOUnit {
@available(tvOS 17.0, *)
func capture(for channel: UInt8) -> IOVideoCaptureUnit? {
#if os(tvOS)
return lockQueue.sync {
if _captures[channel] == nil {
_captures[channel] = IOVideoCaptureUnit()
}
return _captures[channel] as? IOVideoCaptureUnit
if _captures[channel] == nil {
_captures[channel] = IOVideoCaptureUnit()
}
return _captures[channel] as? IOVideoCaptureUnit
#else
return lockQueue.sync {
if captures[channel] == nil {
captures[channel] = .init()
}
return captures[channel]
if captures[channel] == nil {
captures[channel] = .init()
}
return captures[channel]
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Net/NetStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ open class NetStream: NSObject {
/// Returns the IOVideoCaptureUnit by index.
@available(tvOS 17.0, *)
public func videoCapture(for channel: UInt8) -> IOVideoCaptureUnit? {
return lockQueue.sync {
return mixer.videoIO.lockQueue.sync {
return self.mixer.videoIO.capture(for: channel)
}
}
Expand Down

0 comments on commit 200785d

Please sign in to comment.