[Android] pause AudioTrack (java aout) when needed.
Sébastien Toque
git at videolan.org
Tue Nov 6 22:56:33 CET 2012
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Tue Nov 6 22:52:38 2012 +0100| [5f65a79f3e403ade22b042493735fe1698771d22] | committer: Sébastien Toque
pause AudioTrack (java aout) when needed.
This prevent the AudioTrack from waiting for buffers and spamming the logs with this :
"W/AudioTrack(6696): obtainBuffer() track 0x13173b0 disabled, restarting"
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5f65a79f3e403ade22b042493735fe1698771d22
---
vlc-android/jni/aout.c | 27 ++++++++++++++++++++++++++
vlc-android/jni/aout.h | 1 +
vlc-android/jni/libvlcjni.c | 2 +-
vlc-android/src/org/videolan/vlc/Aout.java | 3 +++
vlc-android/src/org/videolan/vlc/LibVLC.java | 9 +++++++++
5 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/vlc-android/jni/aout.c b/vlc-android/jni/aout.c
index 45d095f..a823bf6 100644
--- a/vlc-android/jni/aout.c
+++ b/vlc-android/jni/aout.c
@@ -162,6 +162,33 @@ void aout_play(void *opaque, const void *samples, unsigned count, int64_t pts)
(*myVm)->DetachCurrentThread (myVm);
}
+void aout_pause(void *opaque, int64_t pts)
+{
+ LOGI ("Pausing audio output");
+ aout_sys_t *p_sys = opaque;
+ assert(p_sys);
+
+ JNIEnv *p_env;
+ (*myVm)->AttachCurrentThread (myVm, &p_env, NULL);
+
+ // Call the pause function.
+ jclass cls = (*p_env)->GetObjectClass (p_env, p_sys->j_libVlc);
+ jmethodID methodIdPauseAout = (*p_env)->GetMethodID (p_env, cls, "pauseAout", "()V");
+ if (!methodIdPauseAout)
+ LOGE ("Method pauseAout() could not be found!");
+ (*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdPauseAout);
+ if ((*p_env)->ExceptionCheck (p_env))
+ {
+ LOGE ("Unable to pause audio player!");
+#ifndef NDEBUG
+ (*p_env)->ExceptionDescribe (p_env);
+#endif
+ (*p_env)->ExceptionClear (p_env);
+ }
+
+ (*myVm)->DetachCurrentThread (myVm);
+}
+
void aout_close(void *opaque)
{
LOGI ("Closing audio output");
diff --git a/vlc-android/jni/aout.h b/vlc-android/jni/aout.h
index 878d492..09db1bc 100644
--- a/vlc-android/jni/aout.h
+++ b/vlc-android/jni/aout.h
@@ -25,6 +25,7 @@
int aout_open(void **opaque, char *format, unsigned *rate, unsigned *nb_channels);
void aout_play(void *opaque, const void *samples, unsigned count, int64_t pts);
+void aout_pause(void *opaque, int64_t pts);
void aout_close(void *opaque);
#endif // LIBVLCJNI_VOUT_H
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index ff98043..31668eb 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -583,7 +583,7 @@ static void create_player_and_play(JNIEnv* env, jobject thiz,
jmethodID methodId = (*env)->GetMethodID(env, cls, "getAout", "()I");
if ( (*env)->CallIntMethod(env, thiz, methodId) == AOUT_AUDIOTRACK_JAVA )
{
- libvlc_audio_set_callbacks(mp, aout_play, NULL, NULL, NULL, NULL,
+ libvlc_audio_set_callbacks(mp, aout_play, aout_pause, NULL, NULL, NULL,
(void*) myJavaLibVLC);
libvlc_audio_set_format_callbacks(mp, aout_open, aout_close);
}
diff --git a/vlc-android/src/org/videolan/vlc/Aout.java b/vlc-android/src/org/videolan/vlc/Aout.java
index 976861e..ba51df6 100644
--- a/vlc-android/src/org/videolan/vlc/Aout.java
+++ b/vlc-android/src/org/videolan/vlc/Aout.java
@@ -68,4 +68,7 @@ public class Aout {
mAudioTrack.play();
}
+ public void pause() {
+ mAudioTrack.pause();
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index e2e43bd..8ad1a49 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -240,6 +240,15 @@ public class LibVLC {
}
/**
+ * Pause the Java audio output
+ * This function is called by the native code
+ */
+ public void pauseAout() {
+ Log.d(TAG, "Pausing the java audio output");
+ mAout.pause();
+ }
+
+ /**
* Close the Java audio output
* This function is called by the native code
*/
More information about the Android
mailing list