From c9cd620530a8fb88159a57aa626ea4f232e6e93c Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 30 Aug 2023 18:01:44 +0200 Subject: [PATCH] Audio codec: added function returning the codec's current operational status --- openrtx/include/core/audio_codec.h | 7 +++++++ openrtx/src/core/audio_codec.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/openrtx/include/core/audio_codec.h b/openrtx/include/core/audio_codec.h index 3fe525b7..ab3b8a74 100644 --- a/openrtx/include/core/audio_codec.h +++ b/openrtx/include/core/audio_codec.h @@ -72,6 +72,13 @@ bool codec_startDecode(const pathId path); */ void codec_stop(const pathId path); +/** + * Get current oprational status of the codec thread. + * + * @return true if the codec thread is active. + */ +bool codec_running(); + /** * Get a compressed audio frame from the internal queue. Each frame is composed * of 8 bytes. diff --git a/openrtx/src/core/audio_codec.c b/openrtx/src/core/audio_codec.c index d67826ef..fad1af83 100644 --- a/openrtx/src/core/audio_codec.c +++ b/openrtx/src/core/audio_codec.c @@ -109,6 +109,11 @@ void codec_stop(const pathId path) stopThread(); } +bool codec_running() +{ + return running; +} + int codec_popFrame(uint8_t *frame, const bool blocking) { if(running == false) @@ -351,6 +356,13 @@ static bool startThread(const pathId path, void *(*func) (void *)) pthread_mutex_lock(&init_mutex); if(running) { + // Same path as before, path open, codec already running: all good. + if(path == audioPath) + { + pthread_mutex_unlock(&init_mutex); + return true; + } + // New path takes over the current one only if it has an higher priority // or the current one is closed/suspended. pathInfo_t newPath = audioPath_getInfo(path);