Skip to content

Commit

Permalink
nxaudio: fix audio stop logic to prevent buffer addition after STOP s…
Browse files Browse the repository at this point in the history
…ignal

- 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 <[email protected]>
  • Loading branch information
W-Mai authored and xiaoxiang781216 committed Nov 7, 2024
1 parent 40a5e47 commit febd738
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions audioutils/nxaudio/nxaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit febd738

Please sign in to comment.