diff --git a/CaptureSample/CaptureEngine.swift b/CaptureSample/CaptureEngine.swift index ae66243..8a91db3 100644 --- a/CaptureSample/CaptureEngine.swift +++ b/CaptureSample/CaptureEngine.swift @@ -233,7 +233,8 @@ class CaptureEngineStreamOutput: NSObject, SCStreamOutput, SCStreamDelegate { let contentScale = attachments[.contentScale] as? CGFloat, let scaleFactor = attachments[.scaleFactor] as? CGFloat else { return nil } - let encoderFrame = self.encoder?.videoSink?.mostRecentSampleBuffer + //let encoderFrame = self.encoder?.videoSink?.mostRecentSampleBuffer + let encoderFrame: CMSampleBuffer? = nil // Create a new frame with the relevant data. let frame = CapturedFrame(surface: surface, diff --git a/CaptureSample/Encoder.swift b/CaptureSample/Encoder.swift index bed9288..4f9f573 100644 --- a/CaptureSample/Encoder.swift +++ b/CaptureSample/Encoder.swift @@ -30,6 +30,8 @@ class VTEncoder { var stoppingEncoding = false var pixelTransferBuffer: CVPixelBuffer! + var hasStartedLock = NSLock() + var destWidth: Int var destHeight: Int @@ -180,10 +182,13 @@ class VTEncoder { } func startSession(buffer: CVImageBuffer, timeStamp: CMTime, duration: CMTime, properties: CFDictionary?, infoFlags: UnsafeMutablePointer?) throws { + self.hasStartedLock.lock() guard !self.isStarting else { + self.hasStartedLock.unlock() return } self.isStarting = true + self.hasStartedLock.unlock() guard !self.criticalErrorEncountered else { throw self.currentError! } @@ -205,7 +210,9 @@ class VTEncoder { if sbuf != nil { do { try self.videoSink.startSession(sbuf!) + self.hasStartedLock.lock() self.hasStarted = true + self.hasStartedLock.unlock() self.isStarting = false } catch { self.currentError = error @@ -249,10 +256,10 @@ class VTEncoder { (status: OSStatus, infoFlags: VTEncodeInfoFlags, sbuf: CMSampleBuffer?) -> Void in if sbuf != nil { self.videoSink.sendSampleBuffer(sbuf!) - if self.decodes { + /*if self.decodes { self.videoSink.mostRecentSampleBuffer = sbuf! VTDecompressionSessionDecodeFrame(self.decodeSession, sampleBuffer: sbuf!, flags: [._1xRealTimePlayback], infoFlagsOut: nil, outputHandler: self.outputHandler) - } + }*/ } } } else { diff --git a/CaptureSample/VideoSink.swift b/CaptureSample/VideoSink.swift index 9a70da8..4621d6d 100644 --- a/CaptureSample/VideoSink.swift +++ b/CaptureSample/VideoSink.swift @@ -18,7 +18,7 @@ public class VideoSink { var hasStarted = false var mostRecentImageBuffer: CVImageBuffer? - var mostRecentSampleBuffer: CMSampleBuffer? + //var mostRecentSampleBuffer: CMSampleBuffer? private var bookmarkedURL: URL? @@ -33,6 +33,7 @@ public class VideoSink { private let usesReplayBuffer: Bool private let replayBufferDuration: Int private var isActive: Bool + private var replayBufferLock = NSLock() var accessingBookmarkURL = false @@ -265,8 +266,10 @@ public class VideoSink { } func stopReplayBuffer() throws { + self.replayBufferLock.lock() self.videoReplayBuffer = nil self.audioReplayBuffer = nil + self.replayBufferLock.unlock() } /// Closes the destination movie file. diff --git a/README.md b/README.md index 19720b7..081d173 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Record -Record aims to be a low-overhead macOS screen recorder that emphasizes not missing frames, color correctness and color-matching between output color spaces, and a variety of encoder options for size and quality flexibility. +Record aims to be a low-overhead macOS screen recorder that emphasizes not missing frames, color correctness, and a variety of encoder options for size and quality flexibility. Screenshot 2023-08-25 at 7 58 44 PM