mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-01 03:24:05 +08:00
fix live view authentication and encoder errors
This commit is contained in:
@@ -156,6 +156,7 @@ class CompanionPublisher:
|
||||
self.last_encoded = 0.0
|
||||
self.capture_error = None
|
||||
self.encoder_error = None
|
||||
self.encoder_stderr = None
|
||||
|
||||
def update(self, ui, gui):
|
||||
if not ENABLED.exists():
|
||||
@@ -197,6 +198,9 @@ class CompanionPublisher:
|
||||
'frameAgeSeconds': round(now - self.last_encoded, 2) if self.last_encoded else None,
|
||||
'queuedImages': self.images.qsize(), 'captureError': self.capture_error,
|
||||
'encoderError': self.encoder_error,
|
||||
'encoderStderr': self.encoder_stderr,
|
||||
'encoderExitCode': self.process.poll() if self.process is not None else None,
|
||||
'videoSize': list(self.video_size) if self.video_size else None,
|
||||
'encoderRunning': self.process is not None and self.process.poll() is None,
|
||||
}
|
||||
atomic_write('capture-status.json', json.dumps(capture_status).encode())
|
||||
@@ -323,6 +327,7 @@ class CompanionPublisher:
|
||||
'-flush_packets', '1', 'pipe:1'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
self.video_size = dimensions
|
||||
self.encoder_error = None
|
||||
self.encoder_stderr = None
|
||||
threading.Thread(target=self.read_encoder_errors, args=(self.process,), daemon=True).start()
|
||||
threading.Thread(target=self.read_encoded, args=(self.process, self.sent_times), daemon=True).start()
|
||||
rl.image_format(image, rl.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
|
||||
@@ -344,7 +349,7 @@ class CompanionPublisher:
|
||||
try:
|
||||
for line in process.stderr:
|
||||
if process is self.process:
|
||||
self.encoder_error = line.decode(errors='replace').strip()[:500]
|
||||
self.encoder_stderr = line.decode(errors='replace').strip()[:500]
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ struct CaptureStatus: Codable {
|
||||
let queuedImages: Int?
|
||||
let captureError: String?
|
||||
let encoderError: String?
|
||||
let encoderStderr: String?
|
||||
let encoderExitCode: Int?
|
||||
let videoSize: [Int]?
|
||||
let encoderRunning: Bool?
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ final class PrivateLANHTTP {
|
||||
let target = components.percentEncodedPath + (components.percentEncodedQuery.map { "?" + $0 } ?? "")
|
||||
let body = request.httpBody ?? Data()
|
||||
var text = "\(request.httpMethod ?? "GET") \(target) HTTP/1.1\r\nHost: \(url.host!):8082\r\nConnection: close\r\nAccept-Encoding: identity\r\nContent-Length: \(body.count)\r\n"
|
||||
for (name, value) in request.allHTTPHeaderFields ?? [:] where ["content-type", "accept", "cookie", "range"].contains(name.lowercased()) {
|
||||
for (name, value) in request.allHTTPHeaderFields ?? [:] where ["content-type", "accept", "cookie", "range", "x-companion-nonce", "x-companion-mac"].contains(name.lowercased()) {
|
||||
guard !value.contains("\r"), !value.contains("\n") else { finish(.failure(BridgeError.message("Invalid request header."))); return }
|
||||
text += "\(name): \(value)\r\n"
|
||||
}
|
||||
|
||||
@@ -118,11 +118,11 @@ class CompanionTests(unittest.TestCase):
|
||||
process = types.SimpleNamespace(stderr=io.BytesIO(b'encoder unavailable\n' + b'x' * 1000 + b'\n'))
|
||||
publisher.process = process
|
||||
publisher.read_encoder_errors(process)
|
||||
self.assertEqual(publisher.encoder_error, 'x' * 500)
|
||||
self.assertEqual(publisher.encoder_stderr, 'x' * 500)
|
||||
publisher.process = None
|
||||
process.stderr = io.BytesIO(b'old encoder error\n')
|
||||
publisher.read_encoder_errors(process)
|
||||
self.assertEqual(publisher.encoder_error, 'x' * 500)
|
||||
self.assertEqual(publisher.encoder_stderr, 'x' * 500)
|
||||
|
||||
def test_capture_queue_is_bounded_and_preserves_aspect(self):
|
||||
companion.ENABLED.touch()
|
||||
|
||||
Reference in New Issue
Block a user