static jboolean android_media_SoundPool_SoundPoolImpl_unload(JNIEnv *env, jobject thiz, jint sampleID) { ALOGV("android_media_SoundPool_SoundPoolImpl_unload\n"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return JNI_FALSE; return ap->unload(sampleID) ? JNI_TRUE : JNI_FALSE; }
static bool android_media_SoundPool_unload(JNIEnv *env, jobject thiz, jint sampleID) { ALOGV("android_media_SoundPool_unload\n"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return 0; return ap->unload(sampleID); }
static void android_media_SoundPool_resume(JNIEnv *env, jobject thiz, jint channelID) { ALOGV("android_media_SoundPool_resume"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->resume(channelID); }
static void android_media_SoundPool_autoResume(JNIEnv *env, jobject thiz) { ALOGV("android_media_SoundPool_autoResume"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->autoResume(); }
static void android_media_SoundPool_setRate(JNIEnv *env, jobject thiz, jint channelID, float rate) { ALOGV("android_media_SoundPool_setRate"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->setRate(channelID, rate); }
static void android_media_SoundPool_setLoop(JNIEnv *env, jobject thiz, jint channelID, int loop) { ALOGV("android_media_SoundPool_setLoop"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->setLoop(channelID, loop); }
static void android_media_SoundPool_setPriority(JNIEnv *env, jobject thiz, jint channelID, int priority) { ALOGV("android_media_SoundPool_setPriority"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->setPriority(channelID, priority); }
static void android_media_SoundPool_setVolume(JNIEnv *env, jobject thiz, jint channelID, float leftVolume, float rightVolume) { ALOGV("android_media_SoundPool_setVolume"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return; ap->setVolume(channelID, leftVolume, rightVolume); }
static int android_media_SoundPool_play(JNIEnv *env, jobject thiz, jint sampleID, jfloat leftVolume, jfloat rightVolume, jint priority, jint loop, jfloat rate) { ALOGV("android_media_SoundPool_play\n"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return 0; return ap->play(sampleID, leftVolume, rightVolume, priority, loop, rate); }
static int android_media_SoundPool_load_FD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length, jint priority) { ALOGV("android_media_SoundPool_load_FD"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap == NULL) return 0; return ap->load(jniGetFDFromFileDescriptor(env, fileDescriptor), int64_t(offset), int64_t(length), int(priority)); }
// ---------------------------------------------------------------------------- static int android_media_SoundPool_load_URL(JNIEnv *env, jobject thiz, jstring path, jint priority) { ALOGV("android_media_SoundPool_load_URL"); SoundPool *ap = MusterSoundPool(env, thiz); if (path == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return 0; } const char* s = env->GetStringUTFChars(path, NULL); int id = ap->load(s, priority); env->ReleaseStringUTFChars(path, s); return id; }
static jint android_media_SoundPool_native_setup(JNIEnv *env, jobject thiz, jobject weakRef, jint maxChannels, jint streamType, jint srcQuality) { ALOGV("android_media_SoundPool_native_setup"); SoundPool *ap = new SoundPool(maxChannels, (audio_stream_type_t) streamType, srcQuality); if (ap == NULL) { return -1; } // save pointer to SoundPool C++ object in opaque field in Java object env->SetIntField(thiz, fields.mNativeContext, (int)ap); // set callback with weak reference jobject globalWeakRef = env->NewGlobalRef(weakRef); ap->setCallback(android_media_callback, globalWeakRef); return 0; }
static void android_media_SoundPool_release(JNIEnv *env, jobject thiz) { ALOGV("android_media_SoundPool_release"); SoundPool *ap = MusterSoundPool(env, thiz); if (ap != NULL) { // release weak reference jobject weakRef = (jobject) ap->getUserData(); if (weakRef != NULL) { env->DeleteGlobalRef(weakRef); } // clear callback and native context ap->setCallback(NULL, NULL); env->SetIntField(thiz, fields.mNativeContext, 0); delete ap; } }
static jint android_media_SoundPool_SoundPoolImpl_native_setup(JNIEnv *env, jobject thiz, jobject weakRef, jint maxChannels, jobject jaa) { if (jaa == 0) { ALOGE("Error creating SoundPool: invalid audio attributes"); return -1; } audio_attributes_t *paa = NULL; // read the AudioAttributes values paa = (audio_attributes_t *) calloc(1, sizeof(audio_attributes_t)); const jstring jtags = (jstring) env->GetObjectField(jaa, javaAudioAttrFields.fieldFormattedTags); const char* tags = env->GetStringUTFChars(jtags, NULL); // copying array size -1, char array for tags was calloc'd, no need to NULL-terminate it strncpy(paa->tags, tags, AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); env->ReleaseStringUTFChars(jtags, tags); paa->usage = (audio_usage_t) env->GetIntField(jaa, javaAudioAttrFields.fieldUsage); paa->content_type = (audio_content_type_t) env->GetIntField(jaa, javaAudioAttrFields.fieldContentType); paa->flags = env->GetIntField(jaa, javaAudioAttrFields.fieldFlags); ALOGV("android_media_SoundPool_SoundPoolImpl_native_setup"); SoundPool *ap = new SoundPool(maxChannels, paa); if (ap == NULL) { return -1; } // save pointer to SoundPool C++ object in opaque field in Java object env->SetLongField(thiz, fields.mNativeContext, (jlong) ap); // set callback with weak reference jobject globalWeakRef = env->NewGlobalRef(weakRef); ap->setCallback(android_media_callback, globalWeakRef); // audio attributes were copied in SoundPool creation free(paa); return 0; }
int SoundPool::beginThread(void* arg) { SoundPool* p = (SoundPool*)arg; return p->run(); }