From fc5e3b0bce2a1b184ba1cacbec8bf5b22d8a78f2 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sun, 27 Aug 2023 12:47:55 +0200 Subject: [PATCH] Audio stream: cleanup dead streams while searching for an empty slot --- openrtx/src/core/audio_stream.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openrtx/src/core/audio_stream.c b/openrtx/src/core/audio_stream.c index 7e41f021..24bc5979 100644 --- a/openrtx/src/core/audio_stream.c +++ b/openrtx/src/core/audio_stream.c @@ -98,6 +98,17 @@ streamId audioStream_start(const pathId path, stream_sample_t * const buf, streamId id = -1; for(size_t i = 0; i < MAX_NUM_STREAMS; i++) { + // While searching, cleanup dead streams + if(streams[i].path > 0) + { + if(audioPath_getStatus(streams[i].path) != PATH_OPEN) + { + streams[i].dev->driver->terminate(&(streams[i].ctx)); + streams[i].path = 0; + } + } + + // Empty stream found if((streams[i].path <= 0) && (streams[i].ctx.running == 0)) id = i; }