diff --git a/CaptureEngine.swift b/CaptureEngine.swift index b6720a1..f049dab 100644 --- a/CaptureEngine.swift +++ b/CaptureEngine.swift @@ -37,11 +37,16 @@ class CaptureEngine: NSObject { streamOutput.pcmBufferHandler = { print($0) } do { + streamOutput.frameBufferHandler = { frame in +// print("got frame \(frame.size) at \(frame.contentRect)") + continuation.yield(frame) + } stream = SCStream(filter: filter, configuration: config, delegate: streamOutput) try stream?.addStreamOutput(streamOutput, type: .screen, sampleHandlerQueue: videoSampleBufferQueue) - try stream?.addStreamOutput(streamOutput, type: .audio, sampleHandlerQueue: audioSampleBufferQueue) - try stream?.addStreamOutput(streamOutput, type: .microphone, sampleHandlerQueue: videoSampleBufferQueue) +// try stream?.addStreamOutput(streamOutput, type: .audio, sampleHandlerQueue: audioSampleBufferQueue) +// try stream?.addStreamOutput(streamOutput, type: .microphone, sampleHandlerQueue: videoSampleBufferQueue) + stream?.startCapture() } catch { continuation.finish(throwing: error) } diff --git a/Scream.xcodeproj/project.pbxproj b/Scream.xcodeproj/project.pbxproj index 204167c..a1332ec 100644 --- a/Scream.xcodeproj/project.pbxproj +++ b/Scream.xcodeproj/project.pbxproj @@ -462,6 +462,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 12.3; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.Scream; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -506,6 +507,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 12.3; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.Scream; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Scream/AppDelegate.swift b/Scream/AppDelegate.swift index 4c35482..3c311d5 100644 --- a/Scream/AppDelegate.swift +++ b/Scream/AppDelegate.swift @@ -21,6 +21,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application + let preview = CaptureVideoPreview(layer: sr.contentLayer) + preview.frame.size = window.contentView!.frame.size + window.contentView?.addSubview(preview) } func applicationWillTerminate(_ aNotification: Notification) { @@ -34,3 +37,15 @@ class AppDelegate: NSObject, NSApplicationDelegate { } +class CaptureVideoPreview: NSView { + init(layer: CALayer) { + super.init(frame: .zero) + wantsLayer = true + self.layer = layer + layer.autoresizingMask = [.layerWidthSizable, .layerHeightSizable] + } + + required init?(coder: NSCoder) { + fatalError() + } +} diff --git a/Scream/ScreenRecorder.swift b/Scream/ScreenRecorder.swift index abeaf75..782d8b8 100644 --- a/Scream/ScreenRecorder.swift +++ b/Scream/ScreenRecorder.swift @@ -10,7 +10,7 @@ import ScreenCaptureKit class ScreenRecorder: NSObject { var isRunning: Bool = false - var isAppExluded: Bool = false + var isAppExluded: Bool = true var isAudioEnabled: Bool = false var filter: SCContentFilter? @@ -30,8 +30,8 @@ class ScreenRecorder: NSObject { var streamConfig: SCStreamConfiguration { var streamConfig = SCStreamConfiguration() //TODO: hdr - streamConfig.capturesAudio = isAudioEnabled - streamConfig.excludesCurrentProcessAudio = false +// streamConfig.capturesAudio = isAudioEnabled +// streamConfig.excludesCurrentProcessAudio = false // streamConfig.captureMicrophone = true streamConfig.width = Int(NSScreen.main?.frame.width ?? 100) @@ -43,6 +43,8 @@ class ScreenRecorder: NSObject { } let captureEngine = CaptureEngine() + var contentLayer = CALayer() + var canRecord: Bool { true } @@ -70,7 +72,7 @@ class ScreenRecorder: NSObject { do { isRunning = true for try await frame in captureEngine.startCapture(config: streamConfig, filter: filter!) { - print(frame) + contentLayer.contents = frame.surface } } catch { isRunning = false @@ -87,10 +89,11 @@ class ScreenRecorder: NSObject { } extension ScreenRecorder: SCContentSharingPickerObserver { + @available(macOS 14, *) func contentSharingPicker(_ picker: SCContentSharingPicker, didCancelFor stream: SCStream?) { print("canceleed picker") } - + @available(macOS 14, *) func contentSharingPicker(_ picker: SCContentSharingPicker, didUpdateWith filter: SCContentFilter, for stream: SCStream?) { print(picker.description) }