You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/08/02 10:27:18 UTC

[nuttx] branch master updated: alsa/sim_alsa.c:fix ioctl AUDIOIOC_GETBUFFERINFO error

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 238eba14ad alsa/sim_alsa.c:fix ioctl AUDIOIOC_GETBUFFERINFO error
238eba14ad is described below

commit 238eba14ad1d5aada26fa447b651a9a3954b830e
Author: shipei <sh...@xiaomi.com>
AuthorDate: Tue Aug 1 20:28:25 2023 +0800

    alsa/sim_alsa.c:fix ioctl AUDIOIOC_GETBUFFERINFO error
    
    when executing ioctl AUDIOIOC_GETBUFFERINFO,the priv->pcm is still NULL,
    so it will return -ENXIO,we can remove this check at the start of ioctl
    and add in the case where it is used.
    
    Signed-off-by: shipei <sh...@xiaomi.com>
---
 arch/sim/src/sim/posix/sim_alsa.c | 78 ++++++++++++++++++++++++---------------
 1 file changed, 48 insertions(+), 30 deletions(-)

diff --git a/arch/sim/src/sim/posix/sim_alsa.c b/arch/sim/src/sim/posix/sim_alsa.c
index 185d1d0377..0ffef89d67 100644
--- a/arch/sim/src/sim/posix/sim_alsa.c
+++ b/arch/sim/src/sim/posix/sim_alsa.c
@@ -564,6 +564,11 @@ static int sim_audio_flush(struct audio_lowerhalf_s *dev)
   struct sim_audio_s *priv = (struct sim_audio_s *)dev;
   int ret;
 
+  if (!priv->pcm)
+    {
+      return 0;
+    }
+
   ret = nxmutex_lock(&priv->pendlock);
   if (ret < 0)
     {
@@ -587,6 +592,48 @@ static int sim_audio_flush(struct audio_lowerhalf_s *dev)
   return 0;
 }
 
+static int sim_alsa_get_latency(struct audio_lowerhalf_s *dev,
+                                unsigned long arg)
+{
+  struct sim_audio_s *priv = (struct sim_audio_s *)dev;
+  long *latency = (long *)arg;
+  struct ap_buffer_s *apb;
+  dq_entry_t *cur;
+  long remain = 0;
+  int ret;
+
+  if (!priv->pcm)
+    {
+      return -ENXIO;
+    }
+
+  ret = snd_pcm_delay(priv->pcm, latency);
+  if (ret < 0)
+    {
+      return ret;
+    }
+  else
+    {
+      remain = priv->aux->nbytes - priv->aux->curbyte;
+      ret = nxmutex_lock(&priv->pendlock);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      for (cur = dq_peek(&priv->pendq); cur; cur = dq_next(cur))
+        {
+          apb = (struct ap_buffer_s *)cur;
+          remain += apb->nbytes - apb->curbyte;
+        }
+
+      nxmutex_unlock(&priv->pendlock);
+      *latency += remain / priv->frame_size;
+    }
+
+  return ret;
+}
+
 static int sim_audio_enqueuebuffer(struct audio_lowerhalf_s *dev,
                                    struct ap_buffer_s *apb)
 {
@@ -613,11 +660,6 @@ static int sim_audio_ioctl(struct audio_lowerhalf_s *dev, int cmd,
   struct sim_audio_s *priv = (struct sim_audio_s *)dev;
   int ret = 0;
 
-  if (!priv->pcm)
-    {
-      return -ENXIO;
-    }
-
   switch (cmd)
     {
       case AUDIOIOC_SETBUFFERINFO:
@@ -655,35 +697,11 @@ static int sim_audio_ioctl(struct audio_lowerhalf_s *dev, int cmd,
 
         case AUDIOIOC_GETLATENCY:
           {
-            long *latency = (long *)arg;
-            long remain = 0;
-            dq_entry_t *cur;
-
-            ret = snd_pcm_delay(priv->pcm, latency);
+            ret = sim_alsa_get_latency(dev, arg);
             if (ret < 0)
               {
                 return ret;
               }
-            else
-              {
-                remain = priv->aux->nbytes - priv->aux->curbyte;
-
-                ret = nxmutex_lock(&priv->pendlock);
-                if (ret < 0)
-                  {
-                    return ret;
-                  }
-
-                for (cur = dq_peek(&priv->pendq); cur; cur = dq_next(cur))
-                  {
-                    struct ap_buffer_s *apb = (struct ap_buffer_s *)cur;
-                    remain += apb->nbytes - apb->curbyte;
-                  }
-
-                nxmutex_unlock(&priv->pendlock);
-
-                *latency += remain / priv->frame_size;
-              }
           }
           break;