[Android] [PATCH] aout: reset sample rate default to 4kHz~48kHz

Zhang Rui bbcallen at gmail.com
Tue Oct 22 07:07:43 CEST 2013


---
 vlc-android/jni/aout.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/vlc-android/jni/aout.c b/vlc-android/jni/aout.c
index 859509b..85d1cff 100644
--- a/vlc-android/jni/aout.c
+++ b/vlc-android/jni/aout.c
@@ -79,10 +79,31 @@ int aout_open(void **opaque, char *format, unsigned *rate, unsigned *nb_channels
     LOGV ("Number of channels forced to 2, number of samples to %d", FRAME_SIZE);
     *nb_channels = 2;
 
-    (*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdInitAout,
-                              *rate, *nb_channels, FRAME_SIZE);
-    if ((*p_env)->ExceptionCheck (p_env))
+    int aout_rate = *rate;
+    assert(aout_rate > 0);
+    while (1)
     {
+        (*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdInitAout,
+                                  aout_rate, *nb_channels, FRAME_SIZE);
+        if ((*p_env)->ExceptionCheck (p_env) == 0)
+            break;
+
+        if (aout_rate < 4000)
+        {
+            while (aout_rate < 4000)
+                aout_rate *= 2;
+            LOGE ("failed initAout, try new sample rate %dHz", aout_rate);
+            (*p_env)->ExceptionClear (p_env);
+            continue;
+        }
+        else if (aout_rate > 48000)
+        {
+            aout_rate /= 2;
+            LOGE ("failed initAout, try new sample rate %dHz", aout_rate);
+            (*p_env)->ExceptionClear (p_env);
+            continue;
+        }
+
         LOGE ("Unable to create audio player!");
 #ifndef NDEBUG
         (*p_env)->ExceptionDescribe (p_env);
-- 
1.8.3.4



More information about the Android mailing list