mirror of
https://github.com/smittix/intercept.git
synced 2026-07-23 16:38:11 -07:00
Use buffered read path for Morse PCM stream stability
This commit is contained in:
+24
-49
@@ -744,7 +744,6 @@ def morse_decoder_thread(
|
|||||||
CHUNK = 4096
|
CHUNK = 4096
|
||||||
SCOPE_INTERVAL = 0.10
|
SCOPE_INTERVAL = 0.10
|
||||||
WAITING_INTERVAL = 0.25
|
WAITING_INTERVAL = 0.25
|
||||||
IDLE_SLEEP = 0.04
|
|
||||||
STALLED_AFTER_DATA_SECONDS = 1.5
|
STALLED_AFTER_DATA_SECONDS = 1.5
|
||||||
|
|
||||||
cfg = dict(decoder_config or {})
|
cfg = dict(decoder_config or {})
|
||||||
@@ -773,14 +772,8 @@ def morse_decoder_thread(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
fd: int | None
|
fd: int | None
|
||||||
non_blocking = False
|
|
||||||
try:
|
try:
|
||||||
fd = rtl_stdout.fileno()
|
fd = rtl_stdout.fileno()
|
||||||
try:
|
|
||||||
os.set_blocking(fd, False)
|
|
||||||
non_blocking = True
|
|
||||||
except Exception:
|
|
||||||
non_blocking = False
|
|
||||||
except Exception:
|
except Exception:
|
||||||
fd = None
|
fd = None
|
||||||
|
|
||||||
@@ -790,53 +783,35 @@ def morse_decoder_thread(
|
|||||||
|
|
||||||
data = b''
|
data = b''
|
||||||
if fd is not None:
|
if fd is not None:
|
||||||
if non_blocking:
|
try:
|
||||||
|
ready, _, _ = select.select([fd], [], [], 0.20)
|
||||||
|
except Exception:
|
||||||
|
break
|
||||||
|
|
||||||
|
if ready:
|
||||||
try:
|
try:
|
||||||
data = os.read(fd, CHUNK)
|
# Use buffered stream read first for cross-platform stability.
|
||||||
except BlockingIOError:
|
if hasattr(rtl_stdout, 'read1'):
|
||||||
data = None
|
data = rtl_stdout.read1(CHUNK)
|
||||||
|
else:
|
||||||
|
data = os.read(fd, CHUNK)
|
||||||
except Exception:
|
except Exception:
|
||||||
break
|
break
|
||||||
|
|
||||||
if data is None:
|
|
||||||
now = time.monotonic()
|
|
||||||
should_emit_waiting = False
|
|
||||||
if last_pcm_at is None:
|
|
||||||
should_emit_waiting = True
|
|
||||||
elif (now - last_pcm_at) >= STALLED_AFTER_DATA_SECONDS:
|
|
||||||
should_emit_waiting = True
|
|
||||||
|
|
||||||
if should_emit_waiting and waiting_since is None:
|
|
||||||
waiting_since = now
|
|
||||||
now = time.monotonic()
|
|
||||||
if should_emit_waiting and now - last_waiting_emit >= WAITING_INTERVAL:
|
|
||||||
last_waiting_emit = now
|
|
||||||
_emit_waiting_scope(output_queue, waiting_since)
|
|
||||||
time.sleep(IDLE_SLEEP)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
try:
|
now = time.monotonic()
|
||||||
ready, _, _ = select.select([fd], [], [], 0.20)
|
should_emit_waiting = False
|
||||||
except Exception:
|
if last_pcm_at is None:
|
||||||
break
|
should_emit_waiting = True
|
||||||
|
elif (now - last_pcm_at) >= STALLED_AFTER_DATA_SECONDS:
|
||||||
|
should_emit_waiting = True
|
||||||
|
|
||||||
if ready:
|
if should_emit_waiting and waiting_since is None:
|
||||||
data = os.read(fd, CHUNK)
|
waiting_since = now
|
||||||
else:
|
now = time.monotonic()
|
||||||
now = time.monotonic()
|
if should_emit_waiting and now - last_waiting_emit >= WAITING_INTERVAL:
|
||||||
should_emit_waiting = False
|
last_waiting_emit = now
|
||||||
if last_pcm_at is None:
|
_emit_waiting_scope(output_queue, waiting_since)
|
||||||
should_emit_waiting = True
|
continue
|
||||||
elif (now - last_pcm_at) >= STALLED_AFTER_DATA_SECONDS:
|
|
||||||
should_emit_waiting = True
|
|
||||||
|
|
||||||
if should_emit_waiting and waiting_since is None:
|
|
||||||
waiting_since = now
|
|
||||||
now = time.monotonic()
|
|
||||||
if should_emit_waiting and now - last_waiting_emit >= WAITING_INTERVAL:
|
|
||||||
last_waiting_emit = now
|
|
||||||
_emit_waiting_scope(output_queue, waiting_since)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
# Fallback for test streams without fileno().
|
# Fallback for test streams without fileno().
|
||||||
data = rtl_stdout.read(CHUNK)
|
data = rtl_stdout.read(CHUNK)
|
||||||
|
|||||||
Reference in New Issue
Block a user