Skip to content

Commit

Permalink
audio: add offload underflow msg state
Browse files Browse the repository at this point in the history
Signed-off-by: hanqiyuan <[email protected]>
  • Loading branch information
qiyuan-han authored and W-M-R committed Oct 15, 2024
1 parent 366ede9 commit 0af276b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/nuttx/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 **********************************/

Expand Down

0 comments on commit 0af276b

Please sign in to comment.