1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "StreamDefaultEffect-JNI"
#include <utils/Errors.h>
#include <utils/Log.h>
#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
#include "media/AudioEffect.h"
#include <nativehelper/ScopedUtfChars.h>
#include "android_media_AudioEffect.h"
using namespace android;
static const char* const kClassPathName = "android/media/audiofx/StreamDefaultEffect";
static jint android_media_StreamDefaultEffect_native_setup(JNIEnv *env,
jobject /*thiz*/,
jstring type,
jstring uuid,
jint priority,
jint streamUsage,
jstring opPackageName,
jintArray jId)
{
ALOGV("android_media_StreamDefaultEffect_native_setup");
status_t lStatus = NO_ERROR;
jint* nId = NULL;
const char *typeStr = NULL;
const char *uuidStr = NULL;
ScopedUtfChars opPackageNameStr(env, opPackageName);
if (type != NULL) {
typeStr = env->GetStringUTFChars(type, NULL);
if (typeStr == NULL) { // Out of memory
lStatus = NO_MEMORY;
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
goto setup_exit;
}
}
if (uuid != NULL) {
uuidStr = env->GetStringUTFChars(uuid, NULL);
if (uuidStr == NULL) { // Out of memory
lStatus = NO_MEMORY;
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
goto setup_exit;
}
}
if (typeStr == NULL && uuidStr == NULL) {
lStatus = BAD_VALUE;
goto setup_exit;
}
nId = reinterpret_cast<jint *>(env->GetPrimitiveArrayCritical(jId, NULL));
if (nId == NULL) {
ALOGE("setup: Error retrieving id pointer");
lStatus = BAD_VALUE;
goto setup_exit;
}
// create the native StreamDefaultEffect.
audio_unique_id_t id;
lStatus = AudioEffect::addStreamDefaultEffect(typeStr,
String16(opPackageNameStr.c_str()),
uuidStr,
priority,
static_cast<audio_usage_t>(streamUsage),
&id);
if (lStatus != NO_ERROR) {
ALOGE("setup: Error adding StreamDefaultEffect");
goto setup_exit;
}
nId[0] = static_cast<jint>(id);
setup_exit:
// Final cleanup and return.
if (nId != NULL) {
env->ReleasePrimitiveArrayCritical(jId, nId, 0);
nId = NULL;
}
if (uuidStr != NULL) {
env->ReleaseStringUTFChars(uuid, uuidStr);
uuidStr = NULL;
}
if (typeStr != NULL) {
env->ReleaseStringUTFChars(type, typeStr);
typeStr = NULL;
}
return AudioEffectJni::translateNativeErrorToJava(lStatus);
}
static void android_media_StreamDefaultEffect_native_release(JNIEnv */*env*/,
jobject /*thiz*/,
jint id) {
status_t lStatus = AudioEffect::removeStreamDefaultEffect(id);
if (lStatus != NO_ERROR) {
ALOGW("Error releasing StreamDefaultEffect: %d", lStatus);
}
}
// ----------------------------------------------------------------------------
// Dalvik VM type signatures
static const JNINativeMethod gMethods[] = {
{"native_setup", "(Ljava/lang/String;Ljava/lang/String;IILjava/lang/String;[I)I",
(void *)android_media_StreamDefaultEffect_native_setup},
{"native_release", "(I)V", (void *)android_media_StreamDefaultEffect_native_release},
};
// ----------------------------------------------------------------------------
int register_android_media_StreamDefaultEffect(JNIEnv *env)
{
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}
|