From e37e0fa988590add17872f2eb09502b5492772e4 Mon Sep 17 00:00:00 2001 From: xinbingnan Date: Thu, 7 Nov 2024 18:37:28 +0800 Subject: [PATCH] nxaudio: fix audio stop logic to prevent buffer addition after STOP signal - Ensure `AUDIO_STOP` via `ioctrl` is followed by `mq_send STOP` without race conditions. - Modify loop condition to correctly handle `running = false` upon receiving STOP signal. - Resolve potential issue where `AUDIO_MSG_DEQUEUE` could still accept buffers after STOP signal due to timing. Before: - `nxaudio_stop` would call `ioctrl AUDIO_STOP` followed by `mq_send STOP`, which might lead to `AUDIO_MSG_DEQUEUE` accepting buffers after STOP. After: - Synchronized the sequence of `ioctrl AUDIO_STOP` and `mq_send STOP` to prevent buffer addition after STOP. - Enhanced loop condition to accurately reflect the STOP state. Signed-off-by: xinbingnan --- audioutils/nxaudio/nxaudio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/audioutils/nxaudio/nxaudio.c b/audioutils/nxaudio/nxaudio.c index 1ac3d09797..e6101fff88 100644 --- a/audioutils/nxaudio/nxaudio.c +++ b/audioutils/nxaudio/nxaudio.c @@ -282,12 +282,12 @@ int nxaudio_stop(FAR struct nxaudio_s *nxaudio) { struct audio_msg_s term_msg; - ioctl(nxaudio->fd, AUDIOIOC_STOP, 0); - term_msg.msg_id = AUDIO_MSG_STOP; term_msg.u.data = 0; mq_send(nxaudio->mq, (FAR const char *)&term_msg, sizeof(term_msg), 0); + ioctl(nxaudio->fd, AUDIOIOC_STOP, 0); + return OK; }