This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b13defe9e4edbb39331b8bc5637e86e314a4300d
Author: fangyibo <[email protected]>
AuthorDate: Thu Nov 20 17:04:29 2025 +0800

    nuttx/audio: ALLOCATE_BUFFER & BUFFERINFO support multiple calling
    
    support multiple applications simultaneously calling ALLOCATE_BUFFER
    
    Signed-off-by: fangyibo <[email protected]>
---
 audio/audio.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/audio/audio.c b/audio/audio.c
index ba31a29f5c0..28bf839f899 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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
        */

Reply via email to