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

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

commit 20f4c953d0a73aaa8f3090b846b5de837e98377f
Author: ViezeVingertjes <[email protected]>
AuthorDate: Wed Nov 25 20:02:14 2026 +0100

    audio/pcm_decode: Complete the stream on every first-buffer failure.
    
    When the first buffer of a stream cannot be accepted, the client must be
    told the stream is over with AUDIO_CALLBACK_COMPLETE (nxplayer waits for
    AUDIO_MSG_COMPLETE after a failed enqueue).  pcm_enqueuebuffer() only
    did so when the lower half rejected the buffer; if the data had no valid
    WAV header or the lower half could not be configured, it just returned
    an error and the client waited forever.
    
    Route all first-buffer failures through the same completion path and
    return the actual error code instead of always -EINVAL, also in the
    completion callback.
    
    Tested on Waveshare ESP32-S3-Touch-AMOLED-2.16 with ES8311 behind the
    PCM decoder: "tone" (raw PCM, no WAV header) in nxplayer used to hang
    the player on exit; it now fails and nxplayer exits normally.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: ViezeVingertjes <[email protected]>
---
 audio/pcm_decode.c | 59 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

diff --git a/audio/pcm_decode.c b/audio/pcm_decode.c
index 71f4a5b37c5..5f5bf7d223a 100644
--- a/audio/pcm_decode.c
+++ b/audio/pcm_decode.c
@@ -1115,7 +1115,7 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s 
*dev,
       if (ret < 0)
         {
           auderr("ERROR: Failed to set PCM configuration: %d\n", ret);
-          return ret;
+          goto errout;
         }
 
       /* Bump up the data offset */
@@ -1149,36 +1149,47 @@ static int pcm_enqueuebuffer(FAR struct 
audio_lowerhalf_s *dev,
           return OK;
         }
 
-      /* The normal protocol for streaming errors is as follows:
-       *
-       * (1) Fail the enqueueing by returned a negated error value.  The
-       *     upper level then knows that this buffer was not queue.
-       * (2) Return all queued buffers to the caller using the
-       *     AUDIO_CALLBACK_DEQUEUE callback
-       * (3) Terminate playing using the AUDIO_CALLBACK_COMPLETE
-       *     callback.
-       *
-       * In this case we fail on the very first buffer and we need only
-       * do (1) and (3).
-       */
-
-#ifdef CONFIG_AUDIO_MULTI_SESSION
-      priv->export.upper(priv->export.priv, AUDIO_CALLBACK_COMPLETE,
-                         NULL, OK, NULL);
-#else
-      priv->export.upper(priv->export.priv, AUDIO_CALLBACK_COMPLETE,
-                         NULL, OK);
-#endif
+      if (ret < 0)
+        {
+          auderr("ERROR: Lower half enqueuebuffer failed: %d\n", ret);
+        }
 
 #ifndef CONFIG_AUDIO_FORMAT_RAW
     }
+  else
+    {
+      /* This is not a WAV file! */
+
+      auderr("ERROR: Invalid PCM WAV file\n");
+      ret = -EINVAL;
+    }
 
-  /* This is not a WAV file! */
+errout:
+#endif
+
+  /* The normal protocol for streaming errors is as follows:
+   *
+   * (1) Fail the enqueueing by returned a negated error value.  The
+   *     upper level then knows that this buffer was not queue.
+   * (2) Return all queued buffers to the caller using the
+   *     AUDIO_CALLBACK_DEQUEUE callback
+   * (3) Terminate playing using the AUDIO_CALLBACK_COMPLETE
+   *     callback.
+   *
+   * In this case we fail on the very first buffer and we need only
+   * do (1) and (3).  Without (3) the client (e.g. nxplayer) waits
+   * forever for the completion of the stream.
+   */
 
-  auderr("ERROR: Invalid PCM WAV file\n");
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+  priv->export.upper(priv->export.priv, AUDIO_CALLBACK_COMPLETE,
+                     NULL, ret, NULL);
+#else
+  priv->export.upper(priv->export.priv, AUDIO_CALLBACK_COMPLETE,
+                     NULL, ret);
 #endif
 
-  return -EINVAL;
+  return ret;
 }
 
 /****************************************************************************

Reply via email to