Commit 5f65a79f authored by Sébastien Toque's avatar Sébastien Toque
Browse files

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"
parent 431fc2d0
......@@ -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");
......
......@@ -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
......@@ -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);
}
......
......@@ -68,4 +68,7 @@ public class Aout {
mAudioTrack.play();
}
public void pause() {
mAudioTrack.pause();
}
}
......@@ -239,6 +239,15 @@ public class LibVLC {
mAout.playBuffer(audioData, bufferSize);
}
/**
* 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment