From c7455e7e8e63df696d1cf772ed2ecf05b50420d8 Mon Sep 17 00:00:00 2001 From: hanqiyuan Date: Tue, 27 Feb 2024 14:35:20 +0800 Subject: [PATCH] audio: add offload underflow msg state Signed-off-by: hanqiyuan --- audio/audio.c | 48 +++++++++++++++++++++++++++++++++++++ include/nuttx/audio/audio.h | 1 + 2 files changed, 49 insertions(+) diff --git a/audio/audio.c b/audio/audio.c index e3e1a7dee57..2027c721be1 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -834,6 +834,43 @@ static inline void audio_ioerr(FAR struct audio_upperhalf_s *upper, } } +/**************************************************************************** + * Name: audio_underrun + * + * Description: + * Send an AUDIO_MSG_UNDERRUN message to the client to indicate that the + * active playback is underrun. The lower-half driver initiates this + * call via its callback pointer to our upper-half driver. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static inline void audio_underrun(FAR struct audio_upperhalf_s *upper, + FAR struct ap_buffer_s *apb, uint16_t status, + FAR void *session) +#else +static inline void audio_underrun(FAR struct audio_upperhalf_s *upper, + FAR struct ap_buffer_s *apb, uint16_t status) +#endif +{ + struct audio_msg_s msg; + + audinfo("Entry\n"); + + /* Send a dequeue message to the user if a message queue is registered */ + + if (upper->usermq != NULL) + { + msg.msg_id = AUDIO_MSG_UNDERRUN; + msg.u.ptr = NULL; +#ifdef CONFIG_AUDIO_MULTI_SESSION + msg.session = session; +#endif + file_mq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg), + CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO); + } +} + /**************************************************************************** * Name: audio_callback * @@ -923,6 +960,17 @@ static void audio_callback(FAR void *handle, uint16_t reason, } break; + case AUDIO_CALLBACK_UNDERRUN: + { + /* send underrun status */ +#ifdef CONFIG_AUDIO_MULTI_SESSION + audio_underrun(upper, apb, status, session); +#else + audio_underrun(upper, apb, status); +#endif + } + break; + default: { auderr("ERROR: Unknown callback reason code %d\n", reason); diff --git a/include/nuttx/audio/audio.h b/include/nuttx/audio/audio.h index 15f69e2ae6f..7aba3dc3161 100644 --- a/include/nuttx/audio/audio.h +++ b/include/nuttx/audio/audio.h @@ -328,6 +328,7 @@ #define AUDIO_CALLBACK_IOERR 0x02 #define AUDIO_CALLBACK_COMPLETE 0x03 #define AUDIO_CALLBACK_MESSAGE 0x04 +#define AUDIO_CALLBACK_UNDERRUN 0x05 /* Audio Pipeline Buffer (AP Buffer) flags **********************************/