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

Zhang Rui git at videolan.org
Wed Oct 23 17:21:04 CEST 2013


vlc-ports/android | branch: master | Zhang Rui <bbcallen at gmail.com> | Wed Oct 23 22:59:02 2013 +0800| [707c5f1474509f07ee24daaa574b7511143b6f3a] | committer: Rafaël Carré

aout: reset sample rate default to 4kHz~48kHz

If that fails too, try 44.1kHz

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

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=707c5f1474509f07ee24daaa574b7511143b6f3a
---

 vlc-android/jni/aout.c |   33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/vlc-android/jni/aout.c b/vlc-android/jni/aout.c
index 859509b..02eae0f 100644
--- a/vlc-android/jni/aout.c
+++ b/vlc-android/jni/aout.c
@@ -79,10 +79,35 @@ 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;
+    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) {
+            *rate = aout_rate;
+            break;
+        }
+
+        if (aout_rate <= 0) {
+            LOGE ("initAout failed, invalid sample rate %dHz", aout_rate);
+        } else if (aout_rate != 44100) {
+            if (aout_rate < 4000) {
+                do {
+                    aout_rate *= 2;
+                } while (aout_rate < 4000);
+            } else if (aout_rate > 48000) {
+                do {
+                    aout_rate /= 2;
+                } while (aout_rate > 48000);
+            } else {
+                aout_rate = 44100;
+            }
+
+            LOGE ("initAout failed, try next sample rate %dHz", aout_rate);
+            (*p_env)->ExceptionClear (p_env);
+            continue;
+        }
+
         LOGE ("Unable to create audio player!");
 #ifndef NDEBUG
         (*p_env)->ExceptionDescribe (p_env);



More information about the Android mailing list