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 10971f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("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) { 1158564c8da817a845353d213acd8636b76f567b234Steve Block ALOGW("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) { 1228564c8da817a845353d213acd8636b76f567b234Steve Block ALOGW("EVENT_CONTROL_STATUS_CHANGED info == NULL"); 123948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 124948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 125948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent param = *(bool *)info; 126948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent arg1 = (int)param; 12771f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("EVENT_CONTROL_STATUS_CHANGED"); 128948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 129948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_ENABLE_STATUS_CHANGED: 130948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (info == 0) { 1318564c8da817a845353d213acd8636b76f567b234Steve Block ALOGW("EVENT_ENABLE_STATUS_CHANGED info == NULL"); 132948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto effectCallback_Exit; 133948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 134948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent param = *(bool *)info; 135948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent arg1 = (int)param; 13671f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("EVENT_ENABLE_STATUS_CHANGED"); 137948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 138948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_PARAMETER_CHANGED: 139948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (info == 0) { 1408564c8da817a845353d213acd8636b76f567b234Steve Block ALOGW("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) { 1523762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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; 15971f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("EVENT_PARAMETER_CHANGED"); 160948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent break; 161948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent case AudioEffect::EVENT_ERROR: 1628564c8da817a845353d213acd8636b76f567b234Steve Block ALOGW("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 19071f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("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) { 1983762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 2093762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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, 217ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat "mNativeAudioEffect", "J"); 218948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.fidNativeAudioEffect == NULL) { 2193762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find AudioEffect.%s", "mNativeAudioEffect"); 220948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return; 221948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 222948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // fidJniData; 223948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidJniData = env->GetFieldID( 224948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.clazzEffect, 225ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat "mJniData", "J"); 226948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (fields.fidJniData == NULL) { 2273762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 2333762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 2443762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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{ 25471f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("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) { 2933762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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 30171f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("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) { 3083762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 3223762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 3283762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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) { 3343762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("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"); 36309f1735fadf985f321abef5fe696d0b80c6b46c7Eric Laurent } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC) { 36409f1735fadf985f321abef5fe696d0b80c6b46c7Eric Laurent jdescConnect = env->NewStringUTF("Pre Processing"); 365948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 366948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect = env->NewStringUTF("Insert"); 367948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 368948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 369948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName = env->NewStringUTF(desc.name); 370948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor = env->NewStringUTF(desc.implementor); 371948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 372948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 373948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midDescCstor, 374948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType, 375948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid, 376948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect, 377948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName, 378948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor); 379948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescType); 380948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescUuid); 381948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescConnect); 382948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescName); 383948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescImplementor); 384948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (jdesc == NULL) { 3853762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 386948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setup_failure; 387948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 388948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 389948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->SetObjectArrayElement(javadesc, 0, jdesc); 390948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 391ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidNativeAudioEffect, (jlong)lpAudioEffect); 392948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 393ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidJniData, (jlong)lpJniStorage); 394948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 395ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return (jint) AUDIOEFFECT_SUCCESS; 396948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 397948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // failures: 398948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentsetup_failure: 399948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 400948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (nId != NULL) { 401948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jId, nId, 0); 402948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 403948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 404948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect) { 405948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpAudioEffect; 406948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 407ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidNativeAudioEffect, 0); 408948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 409948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpJniStorage) { 410948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpJniStorage; 411948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 412ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidJniData, 0); 413948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 414948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (uuidStr != NULL) { 415948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(uuid, uuidStr); 416948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 417948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 418948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (typeStr != NULL) { 419948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleaseStringUTFChars(type, typeStr); 420948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 421948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 422ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return (jint)lStatus; 423948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 424948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 425948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 426948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 427948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void android_media_AudioEffect_native_finalize(JNIEnv *env, jobject thiz) { 428ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat ALOGV("android_media_AudioEffect_native_finalize jobject: %p\n", thiz); 429948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 430948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // delete the AudioEffect object 431ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField( 432948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 433948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect) { 434ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat ALOGV("deleting AudioEffect: %p\n", lpAudioEffect); 435948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpAudioEffect; 436948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 437948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 438948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // delete the JNI data 439ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffectJniStorage* lpJniStorage = (AudioEffectJniStorage *)env->GetLongField( 440948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidJniData); 441948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpJniStorage) { 442ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat ALOGV("deleting pJniStorage: %p\n", lpJniStorage); 443948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent delete lpJniStorage; 444948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 445948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 446948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 447948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 448948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic void android_media_AudioEffect_native_release(JNIEnv *env, jobject thiz) { 449948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 450948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // do everything a call to finalize would 451948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent android_media_AudioEffect_native_finalize(env, thiz); 452948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // + reset the native resources in the Java object so any attempt to access 453948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // them after a call to release fails. 454ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidNativeAudioEffect, 0); 455ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat env->SetLongField(thiz, fields.fidJniData, 0); 456948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 457948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 458948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint 459df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentandroid_media_AudioEffect_native_setEnabled(JNIEnv *env, jobject thiz, jboolean enabled) 460948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 461948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 462ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField( 463948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 464948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 465948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 466948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 467948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for enable()"); 468948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 469948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 470948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 471ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return (jint) translateError(lpAudioEffect->setEnabled(enabled)); 472948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 473948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 474948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jboolean 475df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentandroid_media_AudioEffect_native_getEnabled(JNIEnv *env, jobject thiz) 476948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 477948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 478ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField( 479948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 480948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 481948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 482948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 483948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for getEnabled()"); 484ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_FALSE; 485948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 486948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 487ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat if (lpAudioEffect->getEnabled()) { 488ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_TRUE; 489ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat } else { 490ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_FALSE; 491ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat } 492948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 493948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 494948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 495948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jboolean 496948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_hasControl(JNIEnv *env, jobject thiz) 497948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 498948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 499ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField( 500948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent thiz, fields.fidNativeAudioEffect); 501948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 502948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 503948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 504df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent "Unable to retrieve AudioEffect pointer for hasControl()"); 505ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_FALSE; 506948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 507948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 508948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect->initCheck() == NO_ERROR) { 509ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_TRUE; 510948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } else { 511ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return JNI_FALSE; 512948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 513948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 514948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 515948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint android_media_AudioEffect_native_setParameter(JNIEnv *env, 516ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat jobject thiz, jint psize, jbyteArray pJavaParam, jint vsize, 517948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyteArray pJavaValue) { 518948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 519948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpValue = NULL; 520948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpParam = NULL; 521948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 522948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_param_t *p; 523948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int voffset; 524948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 525ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz, 526948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 527948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 528948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 529948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 530948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for setParameter()"); 531948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 532948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 533948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 534948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (psize == 0 || vsize == 0 || pJavaParam == NULL || pJavaValue == NULL) { 535948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 536948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 537948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 538948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the param from the java array 539948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpParam = (jbyte *) env->GetPrimitiveArrayCritical(pJavaParam, NULL); 540948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam == NULL) { 5413762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("setParameter: Error retrieving param pointer"); 542948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setParameter_Exit; 543948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 544948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 545948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the value from the java array 546948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpValue = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValue, NULL); 547948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue == NULL) { 5483762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("setParameter: Error retrieving value pointer"); 549948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto setParameter_Exit; 550948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 551948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 552948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent voffset = ((psize - 1) / sizeof(int) + 1) * sizeof(int); 553948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p = (effect_param_t *) malloc(sizeof(effect_param_t) + voffset + vsize); 554948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(p->data, lpParam, psize); 555948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->psize = psize; 556ca57d1cc89d65dfbd59c749c5736574cd08c7bd3Eric Laurent memcpy(p->data + voffset, lpValue, vsize); 557948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->vsize = vsize; 558948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 559948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = lpAudioEffect->setParameter(p); 560948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 561948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = p->status; 562948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 563948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 564948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent free(p); 565948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 566948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentsetParameter_Exit: 567948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 568948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam != NULL) { 569948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaParam, lpParam, 0); 570948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 571948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue != NULL) { 572948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0); 573948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 574ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return (jint) translateError(lStatus); 575948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 576948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 577948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint 578948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentandroid_media_AudioEffect_native_getParameter(JNIEnv *env, 579602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jobject thiz, jint psize, jbyteArray pJavaParam, 580602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jint vsize, jbyteArray pJavaValue) { 581948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 582948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpParam = NULL; 583948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* lpValue = NULL; 584948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 585948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_param_t *p; 586948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent int voffset; 587948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 588ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz, 589948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 590948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 591948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 592948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 593948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for getParameter()"); 594948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 595948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 596948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 597602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (psize == 0 || vsize == 0 || pJavaParam == NULL || pJavaValue == NULL) { 598948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 599948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 600948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 601948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the param from the java array 602948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpParam = (jbyte *) env->GetPrimitiveArrayCritical(pJavaParam, NULL); 603948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam == NULL) { 6043762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("getParameter: Error retrieving param pointer"); 605948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto getParameter_Exit; 606948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 607948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 608948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the value from the java array 609948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lpValue = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValue, NULL); 610948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue == NULL) { 6113762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("getParameter: Error retrieving value pointer"); 612948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto getParameter_Exit; 613948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 614948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 615948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent voffset = ((psize - 1) / sizeof(int) + 1) * sizeof(int); 616602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent p = (effect_param_t *) malloc(sizeof(effect_param_t) + voffset + vsize); 617948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(p->data, lpParam, psize); 618948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent p->psize = psize; 619602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent p->vsize = vsize; 620948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 621948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = lpAudioEffect->getParameter(p); 622948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 623948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent lStatus = p->status; 624948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lStatus == NO_ERROR) { 625948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent memcpy(lpValue, p->data + voffset, p->vsize); 626602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent vsize = p->vsize; 627948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 628948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 629948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 630948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent free(p); 631948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 632948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentgetParameter_Exit: 633948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 634948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpParam != NULL) { 635948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaParam, lpParam, 0); 636948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 637948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpValue != NULL) { 638948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0); 639948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 640948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 641602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (lStatus == NO_ERROR) { 642602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return vsize; 643602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 644ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat return (jint) translateError(lStatus); 645948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 646948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 647948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jint android_media_AudioEffect_native_command(JNIEnv *env, jobject thiz, 648602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent jint cmdCode, jint cmdSize, jbyteArray jCmdData, jint replySize, 649948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyteArray jReplyData) { 650948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* pCmdData = NULL; 651948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jbyte* pReplyData = NULL; 652948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; 653948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 654948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // retrieve the AudioEffect object 655ea7861c918567d17d40a762b38f97c053d88b839Ashok Bhat AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz, 656948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.fidNativeAudioEffect); 657948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 658948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (lpAudioEffect == NULL) { 659948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jniThrowException(env, "java/lang/IllegalStateException", 660948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent "Unable to retrieve AudioEffect pointer for setParameter()"); 661948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_NO_INIT; 662948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 663948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 664602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if ((cmdSize != 0 && jCmdData == NULL) || (replySize != 0 && jReplyData == NULL)) { 665948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AUDIOEFFECT_ERROR_BAD_VALUE; 666948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 667948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 668948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the command from the java array 669948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (cmdSize != 0) { 670948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent pCmdData = (jbyte *) env->GetPrimitiveArrayCritical(jCmdData, NULL); 671948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pCmdData == NULL) { 6723762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("setParameter: Error retrieving command pointer"); 673948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto command_Exit; 674948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 675948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 676948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 677948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent // get the pointer for the reply from the java array 678602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (replySize != 0 && jReplyData != NULL) { 679948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent pReplyData = (jbyte *) env->GetPrimitiveArrayCritical(jReplyData, NULL); 680948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pReplyData == NULL) { 6813762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("setParameter: Error retrieving reply pointer"); 682948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto command_Exit; 683948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 684948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 685948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 686a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent lStatus = translateError(lpAudioEffect->command((uint32_t)cmdCode, 687a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent (uint32_t)cmdSize, 688a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent pCmdData, 689602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent (uint32_t *)&replySize, 690a4c72acfbc6c06588dd26cf41e67a834fc0a54f9Eric Laurent pReplyData)); 691948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 692948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentcommand_Exit: 693948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 694948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pCmdData != NULL) { 695948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jCmdData, pCmdData, 0); 696948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 697948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (pReplyData != NULL) { 698948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->ReleasePrimitiveArrayCritical(jReplyData, pReplyData, 0); 699948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 700948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 701602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent if (lStatus == NO_ERROR) { 702602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent return replySize; 703602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent } 704948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return lStatus; 705948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 706948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 707948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic jobjectArray 7084fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurentandroid_media_AudioEffect_native_queryEffects(JNIEnv *env, jclass clazz __unused) 709948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 710948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent effect_descriptor_t desc; 711948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent char str[EFFECT_STRING_LEN_MAX]; 7124fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent uint32_t totalEffectsCount = 0; 7134fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent uint32_t returnedEffectsCount = 0; 714948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent uint32_t i = 0; 715948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescType; 716948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescUuid; 717948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescConnect; 718948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescName; 719948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jstring jdescImplementor; 720948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jobject jdesc; 7214fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent jobjectArray ret; 722948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7234fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent if (AudioEffect::queryNumberEffects(&totalEffectsCount) != NO_ERROR) { 7244526f0de0a5698832719f16158bed57ad209d4f2Peter Karlsson return NULL; 7254526f0de0a5698832719f16158bed57ad209d4f2Peter Karlsson } 7264526f0de0a5698832719f16158bed57ad209d4f2Peter Karlsson 7274fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent jobjectArray temp = env->NewObjectArray(totalEffectsCount, fields.clazzDesc, NULL); 7284fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent if (temp == NULL) { 7294fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent return temp; 730948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 731948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7324fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent ALOGV("queryEffects() totalEffectsCount: %d", totalEffectsCount); 733948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7344fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent for (i = 0; i < totalEffectsCount; i++) { 73553334cdb81bab4a4dfd0a41d2ef50709015a36c8Eric Laurent if (AudioEffect::queryEffect(i, &desc) != NO_ERROR) { 736948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto queryEffects_failure; 737948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 738948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7390f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 7400f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Auxiliary"); 7410f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT) { 7420f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Insert"); 7430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC) { 7440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Pre Processing"); 7450f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } else { 7460f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent continue; 7470f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 7480f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 749948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.type, str, EFFECT_STRING_LEN_MAX); 750948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType = env->NewStringUTF(str); 751948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 752948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent AudioEffect::guidToString(&desc.uuid, str, EFFECT_STRING_LEN_MAX); 753948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid = env->NewStringUTF(str); 754948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 755948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName = env->NewStringUTF(desc.name); 756948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor = env->NewStringUTF(desc.implementor); 757948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 758948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 759948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent fields.midDescCstor, 760948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescType, 761948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescUuid, 762948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescConnect, 763948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescName, 764948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jdescImplementor); 765948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescType); 766948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescUuid); 767948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescConnect); 768948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescName); 769948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent env->DeleteLocalRef(jdescImplementor); 770948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (jdesc == NULL) { 7713762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 772948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto queryEffects_failure; 773948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 774948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7754fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent env->SetObjectArrayElement(temp, returnedEffectsCount++, jdesc); 776948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 777948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7784fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent if (returnedEffectsCount == 0) { 7794fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent goto queryEffects_failure; 7804fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent } 7814fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent ret = env->NewObjectArray(returnedEffectsCount, fields.clazzDesc, NULL); 7824fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent if (ret == NULL) { 7834fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent goto queryEffects_failure; 7844fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent } 7854fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent for (i = 0; i < returnedEffectsCount; i++) { 7864fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent env->SetObjectArrayElement(ret, i, env->GetObjectArrayElement(temp, i)); 7874fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent } 7884fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent env->DeleteLocalRef(temp); 789948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return ret; 790948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 791948235c06ed0d49190b2f49d9299b473c4dd61a9Eric LaurentqueryEffects_failure: 792948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 7934fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent if (temp != NULL) { 7944fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent env->DeleteLocalRef(temp); 795948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 796948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return NULL; 797948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 798948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 799948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 8000f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8010f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8020f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurentstatic jobjectArray 8034fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurentandroid_media_AudioEffect_native_queryPreProcessings(JNIEnv *env, jclass clazz __unused, 8044fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurent jint audioSession) 8050f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent{ 806b27a8a5bcc40054f6d775d070bc2de6eb996d1c2Eric Laurent effect_descriptor_t *descriptors = new effect_descriptor_t[AudioEffect::kMaxPreProcessing]; 807b27a8a5bcc40054f6d775d070bc2de6eb996d1c2Eric Laurent uint32_t numEffects = AudioEffect::kMaxPreProcessing; 8080f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8090f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent status_t status = AudioEffect::queryDefaultPreProcessing(audioSession, 8100f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent descriptors, 8110f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent &numEffects); 8120f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (status != NO_ERROR || numEffects == 0) { 8130f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete[] descriptors; 8140f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return NULL; 8150f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 81671f2cf116aab893e224056c38ab146bd1538dd3eSteve Block ALOGV("queryDefaultPreProcessing() got %d effects", numEffects); 8170f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8180f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jobjectArray ret = env->NewObjectArray(numEffects, fields.clazzDesc, NULL); 8190f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (ret == NULL) { 8200f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent delete[] descriptors; 8210f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return ret; 8220f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8230f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8240f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent char str[EFFECT_STRING_LEN_MAX]; 8250f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescType; 8260f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescUuid; 8270f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescConnect; 8280f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescName; 8290f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jstring jdescImplementor; 8300f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jobject jdesc; 8310f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8320f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent for (uint32_t i = 0; i < numEffects; i++) { 8330f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8340f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent AudioEffect::guidToString(&descriptors[i].type, str, EFFECT_STRING_LEN_MAX); 8350f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescType = env->NewStringUTF(str); 8360f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent AudioEffect::guidToString(&descriptors[i].uuid, str, EFFECT_STRING_LEN_MAX); 8370f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescUuid = env->NewStringUTF(str); 8380f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect = env->NewStringUTF("Pre Processing"); 8390f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescName = env->NewStringUTF(descriptors[i].name); 8400f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescImplementor = env->NewStringUTF(descriptors[i].implementor); 8410f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8420f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdesc = env->NewObject(fields.clazzDesc, 8430f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent fields.midDescCstor, 8440f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescType, 8450f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescUuid, 8460f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescConnect, 8470f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescName, 8480f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent jdescImplementor); 8490f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescType); 8500f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescUuid); 8510f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescConnect); 8520f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescName); 8530f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(jdescImplementor); 8540f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent if (jdesc == NULL) { 8553762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); 8560f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->DeleteLocalRef(ret); 8570f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return NULL;; 8580f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8590f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8600f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent env->SetObjectArrayElement(ret, i, jdesc); 8610f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent } 8620f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 8630f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent return ret; 8640f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent} 8650f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent 866948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 867948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 868948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// Dalvik VM type signatures 869948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentstatic JNINativeMethod gMethods[] = { 870948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_init", "()V", (void *)android_media_AudioEffect_native_init}, 871948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;)I", 872948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent (void *)android_media_AudioEffect_native_setup}, 873948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_finalize", "()V", (void *)android_media_AudioEffect_native_finalize}, 874948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_release", "()V", (void *)android_media_AudioEffect_native_release}, 875df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent {"native_setEnabled", "(Z)I", (void *)android_media_AudioEffect_native_setEnabled}, 876df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent {"native_getEnabled", "()Z", (void *)android_media_AudioEffect_native_getEnabled}, 877948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_hasControl", "()Z", (void *)android_media_AudioEffect_native_hasControl}, 878948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_setParameter", "(I[BI[B)I", (void *)android_media_AudioEffect_native_setParameter}, 879602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent {"native_getParameter", "(I[BI[B)I", (void *)android_media_AudioEffect_native_getParameter}, 880602b3286ffe7da6e70bf2d9e4861a5d74ff7c473Eric Laurent {"native_command", "(II[BI[B)I", (void *)android_media_AudioEffect_native_command}, 881948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent {"native_query_effects", "()[Ljava/lang/Object;", (void *)android_media_AudioEffect_native_queryEffects}, 8820f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent {"native_query_pre_processing", "(I)[Ljava/lang/Object;", 8830f7f4ece1b6b73caf608d533d833a8cdc11c8131Eric Laurent (void *)android_media_AudioEffect_native_queryPreProcessings}, 884948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent}; 885948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 886948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 887948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent// ---------------------------------------------------------------------------- 888948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 889df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurentextern int register_android_media_visualizer(JNIEnv *env); 890df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 891948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentint register_android_media_AudioEffect(JNIEnv *env) 892948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 893948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); 894948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 895948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 8964fc28d78cb925c2780abf02c6826e77f8f8a230aEric Laurentjint JNI_OnLoad(JavaVM* vm, void* reserved __unused) 897948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent{ 898948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 899948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent JNIEnv* env = NULL; 900948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent jint result = -1; 901948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 902948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 9033762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("ERROR: GetEnv failed\n"); 904948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto bail; 905948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 906948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent assert(env != NULL); 907948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 908948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent if (register_android_media_AudioEffect(env) < 0) { 9093762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("ERROR: AudioEffect native registration failed\n"); 910948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent goto bail; 911948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent } 912948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 913df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent if (register_android_media_visualizer(env) < 0) { 9143762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("ERROR: Visualizer native registration failed\n"); 915df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent goto bail; 916df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent } 917df9b81ced437b11f8a3fcf4ba3ea6af703d121e2Eric Laurent 918948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent /* success -- return valid version number */ 919948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent result = JNI_VERSION_1_4; 920948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 921948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurentbail: 922948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent return result; 923948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent} 924948235c06ed0d49190b2f49d9299b473c4dd61a9Eric Laurent 925