almost back to working state with rust transport
This commit is contained in:
@@ -57,14 +57,29 @@ class StreamLifecycle:
|
||||
def tracker(self) -> RecordingTracker | None:
|
||||
return self._tracker
|
||||
|
||||
def start(self, session_id=None) -> StreamManager:
|
||||
"""Start recording and all background processes. Returns the StreamManager."""
|
||||
def start(self, session_id=None, rust_transport=False) -> StreamManager:
|
||||
"""Start recording and all background processes. Returns the StreamManager.
|
||||
|
||||
rust_transport=True: skip StreamRecorder (Rust cht-server handles TCP +
|
||||
fMP4 + UDP relay). Session dir is discovered from data/active-session
|
||||
written by cht-server on first client connection.
|
||||
"""
|
||||
self._streaming = True
|
||||
self._gone_live = False
|
||||
self._rust_transport = rust_transport
|
||||
|
||||
self._stream_mgr = StreamManager(session_id=session_id)
|
||||
self._stream_mgr.setup_dirs()
|
||||
self._stream_mgr.start_recorder()
|
||||
if rust_transport:
|
||||
# Wait for cht-server to write the active session path.
|
||||
session_dir = self._wait_for_rust_session()
|
||||
if session_dir is None:
|
||||
log.error("Timed out waiting for cht-server session")
|
||||
self._streaming = False
|
||||
return None
|
||||
self._stream_mgr = StreamManager.from_rust_session(session_dir)
|
||||
else:
|
||||
self._stream_mgr = StreamManager(session_id=session_id)
|
||||
self._stream_mgr.setup_dirs()
|
||||
self._stream_mgr.start_recorder()
|
||||
|
||||
self._tracker = RecordingTracker(
|
||||
get_segments=lambda: self._stream_mgr.recording_segments if self._stream_mgr else [],
|
||||
@@ -76,10 +91,28 @@ class StreamLifecycle:
|
||||
self._stream_mgr.start_audio_extractor(on_new_audio=self._handle_new_audio)
|
||||
|
||||
GLib.timeout_add(1000, self._tick_live)
|
||||
GLib.timeout_add(2000, self._check_recorder)
|
||||
if not rust_transport:
|
||||
GLib.timeout_add(2000, self._check_recorder)
|
||||
|
||||
return self._stream_mgr
|
||||
|
||||
def _wait_for_rust_session(self, timeout=30, poll_interval=0.5):
|
||||
"""Poll data/active-session until cht-server writes it."""
|
||||
import time
|
||||
from pathlib import Path
|
||||
from cht.config import DATA_DIR
|
||||
marker = DATA_DIR / "active-session"
|
||||
elapsed = 0.0
|
||||
while elapsed < timeout:
|
||||
if marker.exists():
|
||||
session_dir = Path(marker.read_text().strip())
|
||||
if session_dir.exists():
|
||||
log.info("Rust session dir: %s", session_dir)
|
||||
return session_dir
|
||||
time.sleep(poll_interval)
|
||||
elapsed += poll_interval
|
||||
return None
|
||||
|
||||
def stop(self):
|
||||
"""Stop all processes and reset state. Does NOT touch UI — caller handles that."""
|
||||
if self._tracker:
|
||||
|
||||
Reference in New Issue
Block a user