diff --git a/Examples/iOS/IngestViewController.swift b/Examples/iOS/IngestViewController.swift index ee3e637aa..0bc39d647 100644 --- a/Examples/iOS/IngestViewController.swift +++ b/Examples/iOS/IngestViewController.swift @@ -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 diff --git a/Sources/IO/MTHKView.swift b/Sources/IO/MTHKView.swift index 4e44edce5..2bcbc7624 100644 --- a/Sources/IO/MTHKView.swift +++ b/Sources/IO/MTHKView.swift @@ -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() @@ -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 } } @@ -91,6 +96,9 @@ public class MTHKView: MTKView { delegate = self framebufferOnly = false enableSetNeedsDisplay = true + if let device { + context = CIContext(mtlDevice: device) + } } } @@ -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