[vlc-commits] opensles: Only try the actual sampling rate if it is lower or equal to the native sampling rate

Martin Storsjö git at videolan.org
Sat Feb 1 14:10:46 CET 2014


vlc | branch: master | Martin Storsjö <martin at martin.st> | Fri Jan 31 10:53:27 2014 +0200| [8033756b40cf80e436cc37f844f99d7af826cafc] | committer: Rafaël Carré

opensles: Only try the actual sampling rate if it is lower or equal to the native sampling rate

If resampling from a higher sampling rate to a lower, one will
end up with noises in the audio due to an android bug.

Signed-off-by: Rafaël Carré <funman at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8033756b40cf80e436cc37f844f99d7af826cafc
---

 modules/audio_output/opensles_android.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/opensles_android.c b/modules/audio_output/opensles_android.c
index eb18ebd..434d78d 100644
--- a/modules/audio_output/opensles_android.c
+++ b/modules/audio_output/opensles_android.c
@@ -41,6 +41,8 @@
 #include <SLES/OpenSLES.h>
 #include <SLES/OpenSLES_Android.h>
 
+int aout_get_native_sample_rate(void);
+
 #define OPENSLES_BUFFERS 255 /* maximum number of buffers */
 #define OPENSLES_BUFLEN  10   /* ms */
 /*
@@ -385,9 +387,20 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     //create audio player
     const SLInterfaceID ids2[] = { sys->SL_IID_ANDROIDSIMPLEBUFFERQUEUE, sys->SL_IID_VOLUME };
     static const SLboolean req2[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
-    result = CreateAudioPlayer(sys->engineEngine, &sys->playerObject, &audioSrc,
+
+    if (aout_get_native_sample_rate() >= fmt->i_rate) {
+        result = CreateAudioPlayer(sys->engineEngine, &sys->playerObject, &audioSrc,
                                     &audioSnk, sizeof(ids2) / sizeof(*ids2),
                                     ids2, req2);
+    } else {
+        // Don't try to play back a sample rate higher than the native one,
+        // since OpenSL ES will try to use the fast path, which AudioFlinger
+        // will reject (fast path can't do resampling), and will end up with
+        // too small buffers for the resampling. See http://b.android.com/59453
+        // for details. This bug is still present in 4.4. If it is fixed later
+        // this workaround could be made conditional.
+        result = SL_RESULT_UNKNOWN_ERROR;
+    }
     if (unlikely(result != SL_RESULT_SUCCESS)) {
         /* Try again with a more sensible samplerate */
         fmt->i_rate = 44100;



More information about the vlc-commits mailing list