Skip to content

Commit

Permalink
Performance improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Dec 9, 2023
1 parent bacaae1 commit a5c0b3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion Examples/iOS/IngestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ final class IngestViewController: UIViewController {
stream.attachAudio(AVCaptureDevice.default(for: .audio), automaticallyConfiguresApplicationAudioSession: false) { error in
logger.warn(error)
}

if #available(iOS 13.0, *) {
let front = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)
stream.videoCapture(for: 1)?.isVideoMirrored = true
Expand Down
14 changes: 11 additions & 3 deletions Sources/IO/MTHKView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ public class MTHKView: MTKView {
}

private var currentSampleBuffer: CMSampleBuffer?

private let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()

private lazy var commandQueue: (any MTLCommandQueue)? = {
return device?.makeCommandQueue()
}()

private var context: CIContext?

private var captureVideoPreview: View? {
willSet {
captureVideoPreview?.removeFromSuperview()
Expand All @@ -67,7 +70,9 @@ public class MTHKView: MTKView {
private weak var currentStream: NetStream? {
didSet {
currentStream.map {
$0.context = CIContext(mtlDevice: device!)
if let context = self.context {
$0.context = context
}
$0.drawable = self
}
}
Expand All @@ -91,6 +96,9 @@ public class MTHKView: MTKView {
delegate = self
framebufferOnly = false
enableSetNeedsDisplay = true
if let device {
context = CIContext(mtlDevice: device)
}
}
}

Expand Down Expand Up @@ -129,9 +137,9 @@ extension MTHKView: MTKViewDelegate {

public func draw(in view: MTKView) {
guard
let context,
let currentDrawable = currentDrawable,
let commandBuffer = commandQueue?.makeCommandBuffer(),
let context = currentStream?.context else {
let commandBuffer = commandQueue?.makeCommandBuffer() else {
return
}
if
Expand Down

0 comments on commit a5c0b3a

Please sign in to comment.