mirror of
https://github.com/neon443/Scream.git
synced 2026-03-11 05:19:14 +00:00
uh did some stuff to make packets, now i gotta actually transmit
This commit is contained in:
@@ -10,8 +10,8 @@ import Cocoa
|
|||||||
@main
|
@main
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
let sr = ScreenRecorder()
|
let sr = ScreenRecorder()
|
||||||
let udpclient = UDPClientImplementation(port: 03067)
|
// let udpclient = UDPClientImplementation(port: 03067)
|
||||||
let udpserver = UDPServerImplementation(host: "localhost", port: 03067, initialMessage: "kys")
|
// let udpserver = UDPServerImplementation(host: "localhost", port: 03067, initialMessage: "kys")
|
||||||
|
|
||||||
@IBOutlet var window: NSWindow!
|
@IBOutlet var window: NSWindow!
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
await sr.start()
|
await sr.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@IBAction func Button2(_ sender: Any) {
|
// @IBAction func Button2(_ sender: Any) {
|
||||||
udpclient.start()
|
// udpclient.start()
|
||||||
udpserver.start()
|
// udpserver.start()
|
||||||
}
|
// }
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
// Insert code here to initialize your application
|
// Insert code here to initialize your application
|
||||||
@@ -31,7 +31,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
preview.frame.size = window.contentView!.frame.size
|
preview.frame.size = window.contentView!.frame.size
|
||||||
window.contentView?.addSubview(preview)
|
window.contentView?.addSubview(preview)
|
||||||
Button(self)
|
Button(self)
|
||||||
Button2(self)
|
// Button2(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ aNotification: Notification) {
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ class CaptureEngine: NSObject {
|
|||||||
let audioSampleBufferQueue = DispatchQueue(label: "audioSampleBufferQueue")
|
let audioSampleBufferQueue = DispatchQueue(label: "audioSampleBufferQueue")
|
||||||
let micSampleBufferQueue = DispatchQueue(label: "micSampleBufferQueue")
|
let micSampleBufferQueue = DispatchQueue(label: "micSampleBufferQueue")
|
||||||
|
|
||||||
|
let udpServer = UDPServerImplementation(host: "localhost", port: 03067, initialMessage: nil)
|
||||||
|
|
||||||
private var continuation: AsyncThrowingStream<CapturedFrame, Error>.Continuation?
|
private var continuation: AsyncThrowingStream<CapturedFrame, Error>.Continuation?
|
||||||
|
|
||||||
func startCapture(config: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream<CapturedFrame, Error> {
|
func startCapture(config: SCStreamConfiguration, filter: SCContentFilter) -> AsyncThrowingStream<CapturedFrame, Error> {
|
||||||
@@ -71,8 +73,17 @@ class CaptureEngine: NSObject {
|
|||||||
frameProperties: nil,
|
frameProperties: nil,
|
||||||
infoFlagsOut: nil
|
infoFlagsOut: nil
|
||||||
) { status, infoFlags, sampleBuffer in
|
) { status, infoFlags, sampleBuffer in
|
||||||
// print()
|
guard let sampleBuffer else { return }
|
||||||
|
let packet = ScreamPacket(
|
||||||
|
timestamp: sampleBuffer.presentationTimeStamp.seconds,
|
||||||
|
data: try! sampleBuffer.dataBuffer!.dataBytes(),
|
||||||
|
index: 1,
|
||||||
|
packetsInChunk: 1,
|
||||||
|
isKeyframe: true
|
||||||
|
)
|
||||||
|
let data = try! JSONEncoder().encode(packet)
|
||||||
|
self.udpServer.send(data)
|
||||||
|
print(packet)
|
||||||
}
|
}
|
||||||
// outputHandler: self.outputHandler)
|
// outputHandler: self.outputHandler)
|
||||||
continuation.yield(frame)
|
continuation.yield(frame)
|
||||||
@@ -150,10 +161,10 @@ class CaptureEngine: NSObject {
|
|||||||
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_AverageBitRate, value: 10 as CFNumber)
|
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_AverageBitRate, value: 10 as CFNumber)
|
||||||
if err != noErr { print("failed to set to framerte \(err)") }
|
if err != noErr { print("failed to set to framerte \(err)") }
|
||||||
|
|
||||||
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_MaxKeyFrameInterval, value: 60 as CFNumber)
|
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_MaxKeyFrameInterval, value: 0 as CFNumber)
|
||||||
if err != noErr { print("failed to set to keyframe interval \(err)") }
|
if err != noErr { print("failed to set to keyframe interval \(err)") }
|
||||||
|
|
||||||
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, value: 1 as CFNumber)
|
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, value: 0 as CFNumber)
|
||||||
if err != noErr { print("failed to set to keyframe interval duratation \(err)") }
|
if err != noErr { print("failed to set to keyframe interval duratation \(err)") }
|
||||||
|
|
||||||
// err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_SuggestedLookAheadFrameCount, value: 1 as CFNumber)
|
// err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_SuggestedLookAheadFrameCount, value: 1 as CFNumber)
|
||||||
|
|||||||
@@ -16,4 +16,12 @@ struct ScreamPacket: Codable, Identifiable {
|
|||||||
var index: Int
|
var index: Int
|
||||||
var packetsInChunk: Int
|
var packetsInChunk: Int
|
||||||
var isKeyframe: Bool
|
var isKeyframe: Bool
|
||||||
|
|
||||||
|
init(timestamp: Double, data: Data, index: Int, packetsInChunk: Int, isKeyframe: Bool) {
|
||||||
|
self.id = timestamp
|
||||||
|
self.data = data
|
||||||
|
self.index = index
|
||||||
|
self.packetsInChunk = packetsInChunk
|
||||||
|
self.isKeyframe = isKeyframe
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Foundation
|
|||||||
import Network
|
import Network
|
||||||
|
|
||||||
final class UDPClientImplementation: Sendable {
|
final class UDPClientImplementation: Sendable {
|
||||||
|
// public static let shared: UDPClientImplementation = .init(port: 03067)
|
||||||
private let connectionListener: NWListener
|
private let connectionListener: NWListener
|
||||||
|
|
||||||
//init a udp client at x port
|
//init a udp client at x port
|
||||||
@@ -26,6 +27,7 @@ final class UDPClientImplementation: Sendable {
|
|||||||
connectionListener.stateUpdateHandler = { state in
|
connectionListener.stateUpdateHandler = { state in
|
||||||
print("state: \(state)")
|
print("state: \(state)")
|
||||||
}
|
}
|
||||||
|
start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ protocol UDPServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class UDPServerImplementation: Sendable {
|
final class UDPServerImplementation: Sendable {
|
||||||
|
// public static let shared: UDPServerImplementation = .init(host: "localhost", port: 03067, initialMessage: nil)
|
||||||
private let connection: NWConnection
|
private let connection: NWConnection
|
||||||
|
|
||||||
init(host: String, port: UInt16, initialMessage: String) {
|
init(host: String, port: UInt16, initialMessage: String?) {
|
||||||
connection = NWConnection(
|
connection = NWConnection(
|
||||||
host: NWEndpoint.Host(host),
|
host: NWEndpoint.Host(host),
|
||||||
port: NWEndpoint.Port(integerLiteral: port),
|
port: NWEndpoint.Port(integerLiteral: port),
|
||||||
@@ -26,6 +27,7 @@ final class UDPServerImplementation: Sendable {
|
|||||||
connection.stateUpdateHandler = { [weak self] state in
|
connection.stateUpdateHandler = { [weak self] state in
|
||||||
print("server state is \(state)")
|
print("server state is \(state)")
|
||||||
if state == .ready {
|
if state == .ready {
|
||||||
|
guard let initialMessage else { return }
|
||||||
self?.send(message: initialMessage)
|
self?.send(message: initialMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +45,16 @@ extension UDPServerImplementation: UDPServer {
|
|||||||
print("server stopped")
|
print("server stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func send(_ data: Data) {
|
||||||
|
connection.send(content: data, completion: .contentProcessed({ error in
|
||||||
|
if let error {
|
||||||
|
print("server: fialed to send \(error)")
|
||||||
|
} else {
|
||||||
|
print("server: message sent")
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
func send(message: String) {
|
func send(message: String) {
|
||||||
guard let data = message.data(using: .utf8) else {
|
guard let data = message.data(using: .utf8) else {
|
||||||
print("server: encode message failed")
|
print("server: encode message failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user