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

commit c755218295b24df3a659638b229cfb7d77377dcb
Author: Tiago Medicci <[email protected]>
AuthorDate: Mon Jul 29 17:01:44 2024 -0300

    drivers/audio/es8311: Fix setting sample rate and bits per sample
    
    When setting the sample rate (`es8311_setsamplerate`) and the bits
    per sample (`es8311_setbitspersample`), check their return value in
    `es8311_configure`. Also, this commit ensures that these functions
    are called after `es8311_reset` to avoid these values to be set to
    the default values.
---
 drivers/audio/es8311.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/audio/es8311.c b/drivers/audio/es8311.c
index 296c75cb58..8d497f05a2 100644
--- a/drivers/audio/es8311.c
+++ b/drivers/audio/es8311.c
@@ -1033,19 +1033,25 @@ static int es8311_configure(FAR struct 
audio_lowerhalf_s *dev,
             break;
           }
 
+        es8311_audio_output(priv);
+        es8311_reset(priv);
+
         /* Save the current stream configuration */
 
         priv->samprate  = caps->ac_controls.hw[0];
         priv->bpsamp    = caps->ac_controls.b[2];
 
-        es8311_audio_output(priv);
-        es8311_reset(priv);
-        es8311_setsamplerate(priv);
-        es8311_setbitspersample(priv);
+        ret = es8311_setsamplerate(priv) == -ENOTTY ? OK : ret;
+        if (ret < 0)
+          {
+            break;
+          }
+
+        ret = es8311_setbitspersample(priv) == -ENOTTY ? OK : ret;
       }
       break;
 
-        case AUDIO_TYPE_INPUT:
+    case AUDIO_TYPE_INPUT:
       {
         audinfo("  AUDIO_TYPE_INPUT:\n");
         audinfo("    Number of channels: %u\n", caps->ac_channels);
@@ -1074,15 +1080,21 @@ static int es8311_configure(FAR struct 
audio_lowerhalf_s *dev,
             break;
           }
 
+        es8311_audio_input(priv);
+        es8311_reset(priv);
+
         /* Save the current stream configuration */
 
         priv->samprate  = caps->ac_controls.hw[0];
         priv->bpsamp    = caps->ac_controls.b[2];
 
-        es8311_audio_input(priv);
-        es8311_reset(priv);
-        es8311_setsamplerate(priv);
-        es8311_setbitspersample(priv);
+        ret = es8311_setsamplerate(priv) == -ENOTTY ? OK : ret;
+        if (ret != OK)
+          {
+            break;
+          }
+
+        ret = es8311_setbitspersample(priv) == -ENOTTY ? OK : ret;
       }
       break;
 

Reply via email to