summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/pcm-android.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/android/pcm-android.c')
-rw-r--r--firmware/target/hosted/android/pcm-android.c20
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);
}