feat: add input priming to verify data flow before streaming

- Read one frame from each non-precoded input to validate audio sources are working
- Store primed frames for drift compensation crossfading when enabled
- Add logging to track successful prime reads and diagnose potential input issues
This commit is contained in:
2025-11-04 14:07:01 +01:00
parent b4a9b4fc8f
commit 2d53e6130b

View File

@@ -703,6 +703,23 @@ class Streamer():
last_stats_log = time.perf_counter()
stats_interval = 5.0 # Log stats every 5 seconds
frame_count = 0
# Prime inputs: read one frame from each non-precoded input to verify data flow
try:
for j, _big in enumerate(bigs.values()):
if not _big.get('precoded'):
gen = _big.get('frames_gen')
if gen is None:
gen = _big['audio_input'].frames(_big['lc3_frame_samples'])
_big['frames_gen'] = gen
test_frame = await anext(gen, None)
logging.info(
f"Prime read BIG{j}: bytes={0 if test_frame is None else len(test_frame)} samples={_big['lc3_frame_samples']}"
)
# Store for crossfade if needed
if enable_drift_compensation and test_frame is not None:
_big['prev_pcm_frame'] = test_frame
except Exception as e:
logging.error(f"Prime read failed: {e}", exc_info=True)
# One streamer fits all
while self.is_streaming: