android_media_AudioEffect.cpp revision 0f7f4ece1b6b73caf608d533d833a8cdc11c8131
1948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent/* 2948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Copyright (C) 2010 The Android Open Source Project 3948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 4948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 5948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * you may not use this file except in compliance with the License. 6948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * You may obtain a copy of the License at 7948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 8948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * http://www.apache.org/licenses/LICENSE-2.0 9948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * 10948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * Unless required by applicable law or agreed to in writing, software 11948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 12948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * See the License for the specific language governing permissions and 14948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent * limitations under the License. 15948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent */ 16948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 17948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include <stdio.h> 18948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 19948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent//#define LOG_NDEBUG 0 20948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define LOG_TAG "AudioEffects-JNI" 21948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 22948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include <utils/Log.h> 23948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include <nativehelper/jni.h> 24948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include <nativehelper/JNIHelp.h> 25948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include <android_runtime/AndroidRuntime.h> 26948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#include "media/AudioEffect.h" 27948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 28948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentusing namespace android; 29948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 30948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_SUCCESS 0 31948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR -1 32948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_ALREADY_EXISTS -2 33948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_NO_INIT -3 34948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_BAD_VALUE -4 35948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_INVALID_OPERATION -5 36948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_NO_MEMORY -6 37948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent#define AUDIOEFFECT_ERROR_DEAD_OBJECT -7 38948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 39948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 401a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurentstatic const char* const kClassPathName = "android/media/audiofx/AudioEffect"; 41948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 42948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstruct fields_t { 43948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // these fields provide access from C++ to the... 44948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jclass clazzEffect; // AudioEffect class 45948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jmethodID midPostNativeEvent; // event post callback method 46948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jfieldID fidNativeAudioEffect; // stores in Java the native AudioEffect object 47948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jfieldID fidJniData; // stores in Java additional resources used by the native AudioEffect 48948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jclass clazzDesc; // AudioEffect.Descriptor class 49948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jmethodID midDescCstor; // AudioEffect.Descriptor class constructor 50948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent}; 51948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic fields_t fields; 52948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 53948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstruct effect_callback_cookie { 54948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jclass audioEffect_class; // AudioEffect class 55948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject audioEffect_ref; // AudioEffect object instance 56948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent }; 57948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 58948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 59948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentclass AudioEffectJniStorage { 60948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent public: 61948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_callback_cookie mCallbackData; 62948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 63948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffectJniStorage() { 64948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 65948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 66948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent ~AudioEffectJniStorage() { 67948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 68948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 69948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent}; 70948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 71948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 72948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint translateError(int code) { 73948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent switch(code) { 74948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NO_ERROR: 75948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_SUCCESS; 76948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case ALREADY_EXISTS: 77948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_ALREADY_EXISTS; 78948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NO_INIT: 79948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 80948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case BAD_VALUE: 81948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 82948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case INVALID_OPERATION: 83948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_INVALID_OPERATION; 84948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case NO_MEMORY: 85948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_MEMORY; 86948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case DEAD_OBJECT: 87948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_DEAD_OBJECT; 88948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent default: 89948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR; 90948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 91948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 92948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 93948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 94948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 95948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void effectCallback(int event, void* user, void *info) { 96948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 97948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_param_t *p; 98948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int arg1 = 0; 99948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int arg2 = 0; 100948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject obj = NULL; 101948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyteArray array = NULL; 102948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte *bytes; 103948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent bool param; 104948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent size_t size; 105948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 106948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_callback_cookie *callbackInfo = (effect_callback_cookie *)user; 107948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent JNIEnv *env = AndroidRuntime::getJNIEnv(); 108948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 109948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("effectCallback: callbackInfo %p, audioEffect_ref %p audioEffect_class %p", 110948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent callbackInfo, 111948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent callbackInfo->audioEffect_ref, 112948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent callbackInfo->audioEffect_class); 113948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 114948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (!user || !env) { 115948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGW("effectCallback error user %p, env %p", user, env); 116948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 117948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 118948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 119948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent switch (event) { 120948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_CONTROL_STATUS_CHANGED: 121948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (info == 0) { 122948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGW("EVENT_CONTROL_STATUS_CHANGED info == NULL"); 123948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 124948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 125948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent param = *(bool *)info; 126948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent arg1 = (int)param; 127948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("EVENT_CONTROL_STATUS_CHANGED"); 128948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 129948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_ENABLE_STATUS_CHANGED: 130948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (info == 0) { 131948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGW("EVENT_ENABLE_STATUS_CHANGED info == NULL"); 132948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 133948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 134948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent param = *(bool *)info; 135948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent arg1 = (int)param; 136948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("EVENT_ENABLE_STATUS_CHANGED"); 137948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 138948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_PARAMETER_CHANGED: 139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (info == 0) { 140948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGW("EVENT_PARAMETER_CHANGED info == NULL"); 141948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 142948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 143948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = (effect_param_t *)info; 144948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (p->psize == 0 || p->vsize == 0) { 145948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 146948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 147948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // arg1 contains offset of parameter value from start of byte array 148948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent arg1 = sizeof(effect_param_t) + ((p->psize - 1) / sizeof(int) + 1) * sizeof(int); 149948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent size = arg1 + p->vsize; 150948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent array = env->NewByteArray(size); 151948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (array == NULL) { 152948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("effectCallback: Couldn't allocate byte array for parameter data"); 153948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 154948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 155948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent bytes = env->GetByteArrayElements(array, NULL); 156948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(bytes, p, size); 157948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseByteArrayElements(array, bytes, 0); 158948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent obj = array; 159948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("EVENT_PARAMETER_CHANGED"); 160948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 161948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_ERROR: 162948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGW("EVENT_ERROR"); 163948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 164948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 165948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 166948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->CallStaticVoidMethod( 167948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent callbackInfo->audioEffect_class, 168948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midPostNativeEvent, 169948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent callbackInfo->audioEffect_ref, event, arg1, arg2, obj); 170948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 171948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurenteffectCallback_Exit: 172948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (array) { 173948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(array); 174948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 175948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 176948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (env->ExceptionCheck()) { 177948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ExceptionDescribe(); 178948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ExceptionClear(); 179948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 180948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 181948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 182948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 183948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// This function gets some field IDs, which in turn causes class initialization. 184948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// It is called from a static block in AudioEffect, which won't run until the 185948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// first time an instance of this class is used. 186948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void 187948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_init(JNIEnv *env) 188948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 189948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 190948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("android_media_AudioEffect_native_init"); 191948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 192948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect = NULL; 193948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzDesc = NULL; 194948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 195948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Get the AudioEffect class 196948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jclass clazz = env->FindClass(kClassPathName); 197948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (clazz == NULL) { 198948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("Can't find %s", kClassPathName); 199948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 200948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 201948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 202948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect = (jclass)env->NewGlobalRef(clazz); 203948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 204948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Get the postEvent method 205948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midPostNativeEvent = env->GetStaticMethodID( 206948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect, 207948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V"); 208948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.midPostNativeEvent == NULL) { 209948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("Can't find AudioEffect.%s", "postEventFromNative"); 210948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 211948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 212948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 213948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // Get the variables fields 214948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // nativeTrackInJavaObj 215948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect = env->GetFieldID( 216948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect, 217948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "mNativeAudioEffect", "I"); 218948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.fidNativeAudioEffect == NULL) { 219948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("Can't find AudioEffect.%s", "mNativeAudioEffect"); 220948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 221948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 222948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // fidJniData; 223948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidJniData = env->GetFieldID( 224948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect, 225948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "mJniData", "I"); 226948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.fidJniData == NULL) { 227948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("Can't find AudioEffect.%s", "mJniData"); 228948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 229948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 230948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 2311a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent clazz = env->FindClass("android/media/audiofx/AudioEffect$Descriptor"); 232948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (clazz == NULL) { 2331a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent LOGE("Can't find android/media/audiofx/AudioEffect$Descriptor class"); 234948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 235948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 236948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzDesc = (jclass)env->NewGlobalRef(clazz); 237948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 238948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midDescCstor 239948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent = env->GetMethodID( 240948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzDesc, 241948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "<init>", 242948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); 243948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.midDescCstor == NULL) { 2441a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent LOGE("Can't find android/media/audiofx/AudioEffect$Descriptor class constructor"); 245948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 246948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 247948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 248948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 249948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 250948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint 251948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_this, 252948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId, jobjectArray javadesc) 253948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 254948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("android_media_AudioEffect_native_setup"); 255948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffectJniStorage* lpJniStorage = NULL; 256948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int lStatus = AUDIOEFFECT_ERROR_NO_MEMORY; 257948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = NULL; 258948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint* nId = NULL; 259948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent const char *typeStr = NULL; 260948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent const char *uuidStr = NULL; 261948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_descriptor_t desc; 262948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject jdesc; 263948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent char str[EFFECT_STRING_LEN_MAX]; 264948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescType; 265948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescUuid; 266948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescConnect; 267948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescName; 268948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescImplementor; 269948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 270948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (type != NULL) { 271948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent typeStr = env->GetStringUTFChars(type, NULL); 272948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (typeStr == NULL) { // Out of memory 273948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); 274948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 275948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 276948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 277948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 278948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (uuid != NULL) { 279948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uuidStr = env->GetStringUTFChars(uuid, NULL); 280948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (uuidStr == NULL) { // Out of memory 281948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); 282948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 283948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 284948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 285948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 286948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (typeStr == NULL && uuidStr == NULL) { 287948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 288948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 289948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 290948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 291948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage = new AudioEffectJniStorage(); 292948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpJniStorage == NULL) { 293948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setup: Error creating JNI Storage"); 294948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 295948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 296948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 297948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage->mCallbackData.audioEffect_class = (jclass)env->NewGlobalRef(fields.clazzEffect); 298948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // we use a weak reference so the AudioEffect object can be garbage collected. 299948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage->mCallbackData.audioEffect_ref = env->NewGlobalRef(weak_this); 300948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 301948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("setup: lpJniStorage: %p audioEffect_ref %p audioEffect_class %p, &mCallbackData %p", 302948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage, 303948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage->mCallbackData.audioEffect_ref, 304948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpJniStorage->mCallbackData.audioEffect_class, 305948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent &lpJniStorage->mCallbackData); 306948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 3072fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent if (jId == NULL) { 308948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setup: NULL java array for id pointer"); 309948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 310948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 311948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 312948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 313948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // create the native AudioEffect object 314948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpAudioEffect = new AudioEffect(typeStr, 315948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uuidStr, 316948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent priority, 317948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effectCallback, 318948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent &lpJniStorage->mCallbackData, 3194cb15cf15dfc9d9c6c8dc34911a4ed6bf53e8e4cJean-Michel Trivi sessionId, 3204cb15cf15dfc9d9c6c8dc34911a4ed6bf53e8e4cJean-Michel Trivi 0); 321948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 322948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("Error creating AudioEffect"); 323948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 324948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 325948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 326948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = translateError(lpAudioEffect->initCheck()); 327948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus != AUDIOEFFECT_SUCCESS && lStatus != AUDIOEFFECT_ERROR_ALREADY_EXISTS) { 328948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("AudioEffect initCheck failed %d", lStatus); 329948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 330948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 331948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 3322fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent nId = (jint *) env->GetPrimitiveArrayCritical(jId, NULL); 3332fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent if (nId == NULL) { 3342fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent LOGE("setup: Error retrieving id pointer"); 3352fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 3362fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent goto setup_failure; 3372fb43ef8c0b922c1bd0d7cb6867e30d702d4bdb8Eric Laurent } 338948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent nId[0] = lpAudioEffect->id(); 339948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jId, nId, 0); 340948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent nId = NULL; 341948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 342948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (typeStr) { 343948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(type, typeStr); 344948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent typeStr = NULL; 345948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 346948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 347948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (uuidStr) { 348948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(uuid, uuidStr); 349948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uuidStr = NULL; 350948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 351948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 352948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the effect descriptor 353948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent desc = lpAudioEffect->descriptor(); 354948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 355948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.type, str, EFFECT_STRING_LEN_MAX); 356948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType = env->NewStringUTF(str); 357948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 358948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.uuid, str, EFFECT_STRING_LEN_MAX); 359948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid = env->NewStringUTF(str); 360948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 361948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 362948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect = env->NewStringUTF("Auxiliary"); 363948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 364948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect = env->NewStringUTF("Insert"); 365948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 366948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 367948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName = env->NewStringUTF(desc.name); 368948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor = env->NewStringUTF(desc.implementor); 369948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 370948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 371948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midDescCstor, 372948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType, 373948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid, 374948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect, 375948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName, 376948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor); 377948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescType); 378948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescUuid); 379948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescConnect); 380948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescName); 381948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescImplementor); 382948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (jdesc == NULL) { 383948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 384948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 385948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 386948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 387948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetObjectArrayElement(javadesc, 0, jdesc); 388948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 389948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidNativeAudioEffect, (int)lpAudioEffect); 390948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 391948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidJniData, (int)lpJniStorage); 392948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 393948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_SUCCESS; 394948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 395948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // failures: 396948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentsetup_failure: 397948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 398948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (nId != NULL) { 399948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jId, nId, 0); 400948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 401948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 402948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect) { 403948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpAudioEffect; 404948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 405948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidNativeAudioEffect, 0); 406948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 407948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpJniStorage) { 408948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpJniStorage; 409948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 410948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidJniData, 0); 411948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 412948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (uuidStr != NULL) { 413948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(uuid, uuidStr); 414948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 415948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 416948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (typeStr != NULL) { 417948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(type, typeStr); 418948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 419948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 420948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return lStatus; 421948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 422948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 423948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 424948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 425948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void android_media_AudioEffect_native_finalize(JNIEnv *env, jobject thiz) { 426948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("android_media_AudioEffect_native_finalize jobject: %x\n", (int)thiz); 427948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 428948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // delete the AudioEffect object 429948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( 430948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 431948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect) { 432948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("deleting AudioEffect: %x\n", (int)lpAudioEffect); 433948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpAudioEffect; 434948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 435948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 436948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // delete the JNI data 437948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffectJniStorage* lpJniStorage = (AudioEffectJniStorage *)env->GetIntField( 438948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidJniData); 439948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpJniStorage) { 440948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("deleting pJniStorage: %x\n", (int)lpJniStorage); 441948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpJniStorage; 442948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 443948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 444948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 445948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 446948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void android_media_AudioEffect_native_release(JNIEnv *env, jobject thiz) { 447948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 448948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // do everything a call to finalize would 449948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent android_media_AudioEffect_native_finalize(env, thiz); 450948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // + reset the native resources in the Java object so any attempt to access 451948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // them after a call to release fails. 452948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidNativeAudioEffect, 0); 453948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetIntField(thiz, fields.fidJniData, 0); 454948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 455948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 456948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint 457df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentandroid_media_AudioEffect_native_setEnabled(JNIEnv *env, jobject thiz, jboolean enabled) 458948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 459948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 460948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( 461948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 462948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 463948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 464948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 465948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for enable()"); 466948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 467948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 468948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 469df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return translateError(lpAudioEffect->setEnabled(enabled)); 470948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 471948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 472948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jboolean 473df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentandroid_media_AudioEffect_native_getEnabled(JNIEnv *env, jobject thiz) 474948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 475948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 476948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( 477948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 478948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 479948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 480948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 481948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for getEnabled()"); 482948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return false; 483948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 484948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 485df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent return (jboolean)lpAudioEffect->getEnabled(); 486948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 487948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 488948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 489948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jboolean 490948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_hasControl(JNIEnv *env, jobject thiz) 491948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 492948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 493948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( 494948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 495948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 496948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 497948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 498df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Unable to retrieve AudioEffect pointer for hasControl()"); 499948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return false; 500948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 501948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 502948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect->initCheck() == NO_ERROR) { 503948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return true; 504948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 505948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return false; 506948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 507948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 508948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 509948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint android_media_AudioEffect_native_setParameter(JNIEnv *env, 510948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject thiz, int psize, jbyteArray pJavaParam, int vsize, 511948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyteArray pJavaValue) { 512948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 513948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpValue = NULL; 514948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpParam = NULL; 515948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 516948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_param_t *p; 517948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int voffset; 518948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 519948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz, 520948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 521948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 522948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 523948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 524948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for setParameter()"); 525948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 526948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 527948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 528948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (psize == 0 || vsize == 0 || pJavaParam == NULL || pJavaValue == NULL) { 529948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 530948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 531948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 532948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the param from the java array 533948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpParam = (jbyte *) env->GetPrimitiveArrayCritical(pJavaParam, NULL); 534948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam == NULL) { 535948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setParameter: Error retrieving param pointer"); 536948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setParameter_Exit; 537948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 538948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 539948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the value from the java array 540948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpValue = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValue, NULL); 541948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue == NULL) { 542948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setParameter: Error retrieving value pointer"); 543948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setParameter_Exit; 544948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 545948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 546948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent voffset = ((psize - 1) / sizeof(int) + 1) * sizeof(int); 547948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = (effect_param_t *) malloc(sizeof(effect_param_t) + voffset + vsize); 548948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(p->data, lpParam, psize); 549948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->psize = psize; 550ca57d1cc89d65dfbd59c749c5736574cd08c7bd3Eric Laurent memcpy(p->data + voffset, lpValue, vsize); 551948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->vsize = vsize; 552948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 553948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = lpAudioEffect->setParameter(p); 554948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 555948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = p->status; 556948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 557948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 558948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent free(p); 559948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 560948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentsetParameter_Exit: 561948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 562948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam != NULL) { 563948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaParam, lpParam, 0); 564948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 565948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue != NULL) { 566948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0); 567948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 568948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return translateError(lStatus); 569948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 570948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 571948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint 572948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_getParameter(JNIEnv *env, 573602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jobject thiz, jint psize, jbyteArray pJavaParam, 574602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jint vsize, jbyteArray pJavaValue) { 575948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 576948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpParam = NULL; 577948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpValue = NULL; 578948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 579948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_param_t *p; 580948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int voffset; 581948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 582948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz, 583948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 584948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 585948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 586948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 587948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for getParameter()"); 588948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 589948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 590948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 591602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (psize == 0 || vsize == 0 || pJavaParam == NULL || pJavaValue == NULL) { 592948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 593948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 594948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 595948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the param from the java array 596948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpParam = (jbyte *) env->GetPrimitiveArrayCritical(pJavaParam, NULL); 597948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam == NULL) { 598948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("getParameter: Error retrieving param pointer"); 599948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto getParameter_Exit; 600948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 601948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 602948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the value from the java array 603948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpValue = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValue, NULL); 604948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue == NULL) { 605948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("getParameter: Error retrieving value pointer"); 606948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto getParameter_Exit; 607948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 608948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 609948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent voffset = ((psize - 1) / sizeof(int) + 1) * sizeof(int); 610602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent p = (effect_param_t *) malloc(sizeof(effect_param_t) + voffset + vsize); 611948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(p->data, lpParam, psize); 612948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->psize = psize; 613602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent p->vsize = vsize; 614948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 615948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = lpAudioEffect->getParameter(p); 616948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 617948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = p->status; 618948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 619948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(lpValue, p->data + voffset, p->vsize); 620602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent vsize = p->vsize; 621948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 622948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 623948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 624948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent free(p); 625948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 626948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentgetParameter_Exit: 627948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 628948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam != NULL) { 629948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaParam, lpParam, 0); 630948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 631948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue != NULL) { 632948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0); 633948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 634948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 635602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (lStatus == NO_ERROR) { 636602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return vsize; 637602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 638948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return translateError(lStatus); 639948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 640948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 641948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint android_media_AudioEffect_native_command(JNIEnv *env, jobject thiz, 642602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jint cmdCode, jint cmdSize, jbyteArray jCmdData, jint replySize, 643948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyteArray jReplyData) { 644948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* pCmdData = NULL; 645948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* pReplyData = NULL; 646948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 647948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 648948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 649948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz, 650948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 651948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 652948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 653948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 654948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for setParameter()"); 655948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 656948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 657948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 658602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if ((cmdSize != 0 && jCmdData == NULL) || (replySize != 0 && jReplyData == NULL)) { 659948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 660948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 661948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 662948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the command from the java array 663948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (cmdSize != 0) { 664948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent pCmdData = (jbyte *) env->GetPrimitiveArrayCritical(jCmdData, NULL); 665948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pCmdData == NULL) { 666948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setParameter: Error retrieving command pointer"); 667948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto command_Exit; 668948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 669948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 670948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 671948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the reply from the java array 672602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (replySize != 0 && jReplyData != NULL) { 673948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent pReplyData = (jbyte *) env->GetPrimitiveArrayCritical(jReplyData, NULL); 674948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pReplyData == NULL) { 675948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("setParameter: Error retrieving reply pointer"); 676948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto command_Exit; 677948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 678948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 679948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 680a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent lStatus = translateError(lpAudioEffect->command((uint32_t)cmdCode, 681a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent (uint32_t)cmdSize, 682a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent pCmdData, 683602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent (uint32_t *)&replySize, 684a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent pReplyData)); 685948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 686948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentcommand_Exit: 687948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 688948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pCmdData != NULL) { 689948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jCmdData, pCmdData, 0); 690948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 691948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pReplyData != NULL) { 692948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jReplyData, pReplyData, 0); 693948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 694948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 695602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (lStatus == NO_ERROR) { 696602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return replySize; 697602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 698948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return lStatus; 699948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 700948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 701948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jobjectArray 702948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_queryEffects(JNIEnv *env, jclass clazz) 703948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 704948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_descriptor_t desc; 705948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent char str[EFFECT_STRING_LEN_MAX]; 706948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uint32_t numEffects; 707948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uint32_t i = 0; 708948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescType; 709948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescUuid; 710948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescConnect; 711948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescName; 712948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescImplementor; 713948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject jdesc; 714948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 715948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::queryNumberEffects(&numEffects); 716948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobjectArray ret = env->NewObjectArray(numEffects, fields.clazzDesc, NULL); 717948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (ret == NULL) { 718948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return ret; 719948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 720948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 721948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGV("queryEffects() numEffects: %d", numEffects); 722948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 723948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent for (i = 0; i < numEffects; i++) { 72453334cdb81bab4a4dfd0a41d2ef50709015a36c8Eric Laurent if (AudioEffect::queryEffect(i, &desc) != NO_ERROR) { 725948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto queryEffects_failure; 726948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 727948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7280f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 7290f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Auxiliary"); 7300f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT) { 7310f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Insert"); 7320f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC) { 7330f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Pre Processing"); 7340f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else { 7350f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent continue; 7360f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 7370f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 738948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.type, str, EFFECT_STRING_LEN_MAX); 739948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType = env->NewStringUTF(str); 740948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 741948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.uuid, str, EFFECT_STRING_LEN_MAX); 742948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid = env->NewStringUTF(str); 743948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 744948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName = env->NewStringUTF(desc.name); 745948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor = env->NewStringUTF(desc.implementor); 746948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 747948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 748948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midDescCstor, 749948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType, 750948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid, 751948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect, 752948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName, 753948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor); 754948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescType); 755948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescUuid); 756948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescConnect); 757948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescName); 758948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescImplementor); 759948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (jdesc == NULL) { 760948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 761948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto queryEffects_failure; 762948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 763948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 764948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetObjectArrayElement(ret, i, jdesc); 765948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 766948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 767948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return ret; 768948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 769948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentqueryEffects_failure: 770948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 771948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (ret != NULL) { 772948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(ret); 773948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 774948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return NULL; 775948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 776948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 777948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7780f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 7790f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 7800f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurentstatic jobjectArray 7810f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurentandroid_media_AudioEffect_native_queryPreProcessings(JNIEnv *env, jclass clazz, jint audioSession) 7820f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent{ 7830f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent // kDefaultNumEffects is a "reasonable" value ensuring that only one query will be enough on 7840f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent // most devices to get all active audio pre processing on a given session. 7850f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent static const uint32_t kDefaultNumEffects = 5; 7860f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 7870f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent effect_descriptor_t *descriptors = new effect_descriptor_t[kDefaultNumEffects]; 7880f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent uint32_t numEffects = kDefaultNumEffects; 7890f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 7900f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent status_t status = AudioEffect::queryDefaultPreProcessing(audioSession, 7910f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent descriptors, 7920f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent &numEffects); 7930f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if ((status != NO_ERROR && status != NO_MEMORY) || 7940f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent numEffects == 0) { 7950f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete[] descriptors; 7960f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return NULL; 7970f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 7980f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (status == NO_MEMORY) { 7990f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete [] descriptors; 8000f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent descriptors = new effect_descriptor_t[numEffects]; 8010f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent status = AudioEffect::queryDefaultPreProcessing(audioSession, 8020f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent descriptors, 8030f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent &numEffects); 8040f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8050f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (status != NO_ERROR || numEffects == 0) { 8060f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete[] descriptors; 8070f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return NULL; 8080f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8090f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent LOGV("queryDefaultPreProcessing() got %d effects", numEffects); 8100f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8110f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jobjectArray ret = env->NewObjectArray(numEffects, fields.clazzDesc, NULL); 8120f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (ret == NULL) { 8130f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete[] descriptors; 8140f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return ret; 8150f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8160f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8170f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent char str[EFFECT_STRING_LEN_MAX]; 8180f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescType; 8190f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescUuid; 8200f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescConnect; 8210f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescName; 8220f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescImplementor; 8230f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jobject jdesc; 8240f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8250f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent for (uint32_t i = 0; i < numEffects; i++) { 8260f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8270f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent AudioEffect::guidToString(&descriptors[i].type, str, EFFECT_STRING_LEN_MAX); 8280f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescType = env->NewStringUTF(str); 8290f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent AudioEffect::guidToString(&descriptors[i].uuid, str, EFFECT_STRING_LEN_MAX); 8300f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescUuid = env->NewStringUTF(str); 8310f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Pre Processing"); 8320f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescName = env->NewStringUTF(descriptors[i].name); 8330f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescImplementor = env->NewStringUTF(descriptors[i].implementor); 8340f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8350f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 8360f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent fields.midDescCstor, 8370f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescType, 8380f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescUuid, 8390f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect, 8400f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescName, 8410f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescImplementor); 8420f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescType); 8430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescUuid); 8440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescConnect); 8450f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescName); 8460f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescImplementor); 8470f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (jdesc == NULL) { 8480f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent LOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 8490f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(ret); 8500f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return NULL;; 8510f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8520f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8530f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->SetObjectArrayElement(ret, i, jdesc); 8540f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8550f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8560f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return ret; 8570f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent} 8580f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 859948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 860948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 861948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// Dalvik VM type signatures 862948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic JNINativeMethod gMethods[] = { 863948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_init", "()V", (void *)android_media_AudioEffect_native_init}, 864948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;)I", 865948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent (void *)android_media_AudioEffect_native_setup}, 866948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_finalize", "()V", (void *)android_media_AudioEffect_native_finalize}, 867948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_release", "()V", (void *)android_media_AudioEffect_native_release}, 868df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent {"native_setEnabled", "(Z)I", (void *)android_media_AudioEffect_native_setEnabled}, 869df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent {"native_getEnabled", "()Z", (void *)android_media_AudioEffect_native_getEnabled}, 870948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_hasControl", "()Z", (void *)android_media_AudioEffect_native_hasControl}, 871948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_setParameter", "(I[BI[B)I", (void *)android_media_AudioEffect_native_setParameter}, 872602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent {"native_getParameter", "(I[BI[B)I", (void *)android_media_AudioEffect_native_getParameter}, 873602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent {"native_command", "(II[BI[B)I", (void *)android_media_AudioEffect_native_command}, 874948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_query_effects", "()[Ljava/lang/Object;", (void *)android_media_AudioEffect_native_queryEffects}, 8750f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent {"native_query_pre_processing", "(I)[Ljava/lang/Object;", 8760f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent (void *)android_media_AudioEffect_native_queryPreProcessings}, 877948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent}; 878948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 879948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 880948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 881948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 882df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentextern int register_android_media_visualizer(JNIEnv *env); 883df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 884948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentint register_android_media_AudioEffect(JNIEnv *env) 885948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 886948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); 887948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 888948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 889948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentjint JNI_OnLoad(JavaVM* vm, void* reserved) 890948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 891948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 892948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent JNIEnv* env = NULL; 893948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint result = -1; 894948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 895948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 896948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("ERROR: GetEnv failed\n"); 897948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto bail; 898948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 899948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent assert(env != NULL); 900948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 901948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (register_android_media_AudioEffect(env) < 0) { 902948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent LOGE("ERROR: AudioEffect native registration failed\n"); 903948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto bail; 904948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 905948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 906df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent if (register_android_media_visualizer(env) < 0) { 907df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent LOGE("ERROR: Visualizer native registration failed\n"); 908df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent goto bail; 909df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 910df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 911948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /* success -- return valid version number */ 912948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent result = JNI_VERSION_1_4; 913948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 914948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentbail: 915948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return result; 916948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 917948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 918