Skip to content

Commit b13defe

Browse files
fangyiboacassis
authored andcommitted
nuttx/audio: ALLOCATE_BUFFER & BUFFERINFO support multiple calling
support multiple applications simultaneously calling ALLOCATE_BUFFER Signed-off-by: fangyibo <fangyibo@xiaomi.com>
1 parent 904f391 commit b13defe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

audio/audio.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct audio_upperhalf_s
8888
{
8989
struct audio_info_s info; /* Record the last playing audio format */
9090
mutex_t lock; /* Supports mutual exclusion */
91+
uint8_t nbuffers; /* Max ap buffers number */
9192
spinlock_t spinlock; /* Supports spin lock */
9293
uint8_t periods; /* Ap buffers number */
9394
FAR struct ap_buffer_s **apbs; /* Ap buffers list */
@@ -767,6 +768,11 @@ static int audio_allocbuffer(FAR struct audio_upperhalf_s *upper,
767768
FAR void *newaddr;
768769
int ret;
769770

771+
if (upper->periods >= upper->nbuffers)
772+
{
773+
return 0;
774+
}
775+
770776
if (bufdesc->u.pbuffer == NULL)
771777
{
772778
bufdesc->u.pbuffer = &apb;
@@ -1180,6 +1186,40 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
11801186
}
11811187
break;
11821188

1189+
/* AUDIOIOC_SETBUFFERINFO - Set buffer information
1190+
*
1191+
* ioctl argument - pointer to set the buffer information
1192+
*/
1193+
1194+
case AUDIOIOC_SETBUFFERINFO:
1195+
{
1196+
audinfo("AUDIOIOC_SETBUFFERINFO\n");
1197+
1198+
if (upper->periods == 0)
1199+
{
1200+
ret = lower->ops->ioctl(lower, AUDIOIOC_SETBUFFERINFO, arg);
1201+
}
1202+
}
1203+
break;
1204+
1205+
/* AUDIOIOC_GETBUFFERINFO - Get buffer information
1206+
*
1207+
* ioctl argument - pointer to get the buffer information
1208+
*/
1209+
1210+
case AUDIOIOC_GETBUFFERINFO:
1211+
{
1212+
audinfo("AUDIOIOC_GETBUFFERINFO\n");
1213+
1214+
ret = lower->ops->ioctl(lower, AUDIOIOC_GETBUFFERINFO, arg);
1215+
if (ret >= 0)
1216+
{
1217+
upper->nbuffers =
1218+
((FAR struct ap_buffer_info_s *)arg)->nbuffers;
1219+
}
1220+
}
1221+
break;
1222+
11831223
/* Any unrecognized IOCTL commands might be
11841224
* platform-specific ioctl commands
11851225
*/

0 commit comments

Comments
 (0)