diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-03-16 14:33:55 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-03-16 14:33:55 +0000 |
commit | 046cec3aa7fd58a9519cad8d693b47a2400e1742 (patch) | |
tree | cb0ba0773a3e8b3cef5d7690e2822f03d1425ddb /firmware/target/hosted/android/pcm-android.c | |
parent | efa9f13500d1672d0b631520e92e08f3ff61e45c (diff) |
Android: Partly revert r29569 and only call the new getJavaEnvironment() when needed.
The environment is fine to share in general, just not across OS threads, so it's only needed
for functions which are possibly called from multiple OS threads (only 1 currently).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29601 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android/pcm-android.c')
-rw-r--r-- | firmware/target/hosted/android/pcm-android.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index 24881bd3df..edb3503262 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c @@ -21,10 +21,13 @@ #include <jni.h> #include <stdbool.h> +#define _SYSTEM_WITH_JNI /* for getJavaEnvironment */ #include <system.h> #include "debug.h" #include "pcm.h" +extern JNIEnv *env_ptr; + /* infos about our pcm chunks */ static size_t pcm_data_size; static char *pcm_data_start; @@ -115,17 +118,17 @@ void pcm_play_dma_start(const void *addr, size_t size) void pcm_play_dma_stop(void) { - JNIEnv *env_ptr = getJavaEnvironment(); - - (*env_ptr)->CallVoidMethod(env_ptr, - RockboxPCM_instance, - stop_method); + /* NOTE: due to how pcm_play_get_more_callback() works, this is + * possibly called from pcmSamplesToByteArray(), i.e. another thread. + * => We need to discover the env_ptr */ + JNIEnv* env = getJavaEnvironment(); + (*env)->CallVoidMethod(env, + RockboxPCM_instance, + stop_method); } void pcm_play_dma_pause(bool pause) { - JNIEnv *env_ptr = getJavaEnvironment(); - (*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, play_pause_method, @@ -154,7 +157,6 @@ void pcm_play_dma_init(void) * Luckily we only reference the PCM object from here, so it's safe (and * clean) to allocate it here **/ - JNIEnv *env_ptr = getJavaEnvironment(); JNIEnv e = *env_ptr; /* get the class and its constructor */ jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); @@ -175,8 +177,6 @@ void pcm_postinit(void) void pcm_set_mixer_volume(int volume) { - JNIEnv *env_ptr = getJavaEnvironment(); - (*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, set_volume_method, volume); } |