nuttx/audio: ALLOCATE_BUFFER & BUFFERINFO support multiple calling

support multiple applications simultaneously calling ALLOCATE_BUFFER

Signed-off-by: fangyibo <fangyibo@xiaomi.com>
This commit is contained in:
fangyibo 2025-11-20 17:04:29 +08:00 committed by Alan C. Assis
parent 904f391982
commit b13defe9e4

View file

@ -88,6 +88,7 @@ struct audio_upperhalf_s
{
struct audio_info_s info; /* Record the last playing audio format */
mutex_t lock; /* Supports mutual exclusion */
uint8_t nbuffers; /* Max ap buffers number */
spinlock_t spinlock; /* Supports spin lock */
uint8_t periods; /* Ap buffers number */
FAR struct ap_buffer_s **apbs; /* Ap buffers list */
@ -767,6 +768,11 @@ static int audio_allocbuffer(FAR struct audio_upperhalf_s *upper,
FAR void *newaddr;
int ret;
if (upper->periods >= upper->nbuffers)
{
return 0;
}
if (bufdesc->u.pbuffer == NULL)
{
bufdesc->u.pbuffer = &apb;
@ -1180,6 +1186,40 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
break;
/* AUDIOIOC_SETBUFFERINFO - Set buffer information
*
* ioctl argument - pointer to set the buffer information
*/
case AUDIOIOC_SETBUFFERINFO:
{
audinfo("AUDIOIOC_SETBUFFERINFO\n");
if (upper->periods == 0)
{
ret = lower->ops->ioctl(lower, AUDIOIOC_SETBUFFERINFO, arg);
}
}
break;
/* AUDIOIOC_GETBUFFERINFO - Get buffer information
*
* ioctl argument - pointer to get the buffer information
*/
case AUDIOIOC_GETBUFFERINFO:
{
audinfo("AUDIOIOC_GETBUFFERINFO\n");
ret = lower->ops->ioctl(lower, AUDIOIOC_GETBUFFERINFO, arg);
if (ret >= 0)
{
upper->nbuffers =
((FAR struct ap_buffer_info_s *)arg)->nbuffers;
}
}
break;
/* Any unrecognized IOCTL commands might be
* platform-specific ioctl commands
*/