fix: handle broken pipe and filter graph failures in playback loop

Co-authored-by: aider (gemini/gemini-3.1-pro-preview) <aider@aider.chat>
This commit is contained in:
Tanner
2026-07-28 17:12:04 -06:00
parent c100dada93
commit 5fab94c06c
+23 -11
View File
@@ -75,19 +75,24 @@ def playback_thread(file_path, state):
graph = build_graph(frame)
except Exception as e:
print(f"Filter graph error: {e}", file=sys.stderr)
break
graph = "FAILED"
try:
graph.push(frame)
except av.AVError:
continue
while True:
if graph == "FAILED":
frames_to_process = [frame]
else:
try:
filtered_frame = graph.pull()
except (av.AVError, BlockingIOError):
break
graph.push(frame)
except av.AVError:
continue
frames_to_process = []
while True:
try:
frames_to_process.append(graph.pull())
except (av.AVError, BlockingIOError):
break
for filtered_frame in frames_to_process:
resampled_frames = resampler.resample(filtered_frame)
for r_frame in resampled_frames:
arr = r_frame.to_ndarray()
@@ -98,7 +103,11 @@ def playback_thread(file_path, state):
arr = arr.astype(np.float32) * multiplier
arr = np.clip(arr, -32768, 32767).astype(np.int16)
fifo.write(arr.tobytes())
try:
fifo.write(arr.tobytes())
except BrokenPipeError:
state.running = False
return
def handle_ipc_client(conn, state):
buffer = ""
@@ -199,6 +208,9 @@ def main():
try:
playback_thread(args.file, state)
# Keep the main thread alive until Navidrome explicitly sends 'quit'
while state.running:
time.sleep(0.1)
except KeyboardInterrupt:
pass
finally: