alps/frameworks/base/media/java/android/media/audiofx/LoudnessEnhancer.java
public LoudnessEnhancer(int audioSession){
//默认只使用type,uuid等于null
super(EFFECT_TYPE_LOUDNESS_ENHANCER, EFFECT_TYPE_NULL, 0, audioSession);
}
alps/frameworks/base/media/java/android/media/audiofx/AudioEffect.java
/**
* UUID for Loudness Enhancer
*/
public static final UUID EFFECT_TYPE_LOUDNESS_ENHANCER = UUID
.fromString(“fe3199be-aed0-413f-87bb-11260eb63cf1”);
public static final UUID EFFECT_TYPE_NULL = UUID
.fromString(“ec7178ec-e5e1-4432-a3f4-4657e6795210”);
public AudioEffect(UUID type, UUID uuid, int priority, int audioSession){
int[] id = new int[1];
Descriptor[] desc = new Descriptor[1];
// native initialization
int initResult = native_setup(new WeakReference(this),
type.toString(), uuid.toString(), priority, audioSession, id,
desc, ActivityThread.currentOpPackageName());
mId = id[0];
mDescriptor = desc[0];
synchronized (mStateLock) {
mState = STATE_INITIALIZED;
}
}
alps/frameworks/base/media/jni/audioeffect/android_media_AudioEffect.cpp
android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId,
jobjectArray javadesc, jstring opPackageName)
{
typeStr = env->GetStringUTFChars(type, NULL);
uuidStr = env->GetStringUTFChars(uuid, NULL);
lpAudioEffect = new AudioEffect(typeStr,
String16(opPackageNameStr.c_str()),
uuidStr,
priority,
effectCallback,
&lpJniStorage->mCallbackData,
(audio_session_t) sessionId,
AUDIO_IO_HANDLE_NONE);
}
alps/frameworks/av/media/libaudioclient/AudioEffect.cpp
AudioEffect::AudioEffect(const char *typeStr,
const String16& opPackageName,
const char uuidStr,
int32_t priority,
effect_callback_t cbf,
void user,
audio_session_t sessionId,
audio_io_handle_t io
)
: mStatus(NO_INIT), mOpPackageName(opPackageName)
{
mStatus = set(pType, pUuid, priority, cbf, user, sessionId, io);
}
status_t AudioEffect::set(const effect_uuid_t *type,
const effect_uuid_t uuid,
int32_t priority,
effect_callback_t cbf,
void user,
audio_session_t sessionId,
audio_io_handle_t io)
{
mDescriptor.type = *(type != NULL ? type : EFFECT_UUID_NULL);
mDescriptor.uuid = *(uuid != NULL ? uuid : EFFECT_UUID_NULL);
iEffect = audioFlinger->createEffect((effect_descriptor_t *)&mDescriptor,
mIEffectClient, priority, io, mSessionId, mOpPackageName, mClientPid,
&mStatus, &mId, &enabled);
}
sp AudioFlinger::createEffect(
effect_descriptor_t *pDesc,
const sp& effectClient,
int32_t priority,
audio_io_handle_t io,
audio_session_t sessionId,
const String16& opPackageName,
pid_t pid,
status_t *status,
int *id,
int *enabled)
{
{
if (!EffectsFactoryHalInterface::isNullUuid(&pDesc->uuid)) {
// if uuid is specified, request effect descriptor
lStatus = mEffectsFactoryHal->getDescriptor(&pDesc->uuid, &desc);
} else {
EffectsFactoryHalInterface::isNullUuid(&pDesc->type);
uint32_t numEffects = 0;
effect_descriptor_t d;
d.flags = 0; // prevent compiler warning
bool found = false;
//遍历所有的音效库,上层只提供了type,这里会将uuid读取出来
lStatus = mEffectsFactoryHal->queryNumberEffects(&numEffects);
for (uint32_t i = 0; i < numEffects; i++) {
lStatus = mEffectsFactoryHal->getDescriptor(i, &desc);
if (memcmp(&desc.type, &pDesc->type, sizeof(effect_uuid_t)) == 0) {
found = true;
d = desc;
}
}
if (sessionId == AUDIO_SESSION_OUTPUT_MIX &&
(d.flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_AUXILIARY) {
desc = d;
}
}
}
handle = thread->createEffect_l(client, effectClient, priority, sessionId,
&desc, enabled, &lStatus, pinned);
}
alps/frameworks/av/services/audioflinger/Effects.cpp
AudioFlinger::EffectModule::EffectModule(ThreadBase *thread,
const wpAudioFlinger::EffectChain& chain,
effect_descriptor_t *desc,
int id,
audio_session_t sessionId,
bool pinned){
sp audioFlinger = mAudioFlinger.promote();
if (audioFlinger != 0) {
sp effectsFactory = audioFlinger->getEffectsFactory();
if (effectsFactory != 0) {
mStatus = effectsFactory->createEffect(
&desc->uuid, sessionId, thread->id(), &mEffectInterface);
}
}
}
alps/hardware/interfaces/audio/effect/all-versions/default/include/effect/all-versions/default/EffectsFactory.impl.h
Return EffectsFactory::createEffect(const Uuid& uid, int32_t session, int32_t ioHandle,
createEffect_cb _hidl_cb) {
effect_uuid_t halUuid;
HidlUtils::uuidToHal(uid, &halUuid);
effect_handle_t handle;
Result retval(Result::OK);
status_t status = EffectCreate(&halUuid, session, ioHandle, &handle);
sp effect;
uint64_t effectId = EffectMap::INVALID_ID;
if (status == OK) {
effect_descriptor_t halDescriptor;
memset(&halDescriptor, 0, sizeof(effect_descriptor_t));
status = (*handle)->get_descriptor(handle, &halDescriptor);
if (status == OK) {
effect = dispatchEffectInstanceCreation(halDescriptor, handle);
effectId = EffectMap::getInstance().add(handle);
} else {
EffectRelease(handle);
}
}
_hidl_cb(retval, effect, effectId);
return Void();
}
alps/frameworks/av/media/libeffects/factory/EffectsFactory.c
int EffectCreate(const effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_handle_t *pHandle)
{
list_elem_t *e = gLibraryList;
lib_entry_t *l = NULL;
effect_descriptor_t *d = NULL;
effect_handle_t itfe;
effect_entry_t *fx;
int ret;
if (uuid == NULL || pHandle == NULL) {
return -EINVAL;
}
ret = init();
ret = findEffect(NULL, uuid, &l, &d);
// create effect in library
ret = l->desc->create_effect(uuid, sessionId, ioId, &itfe);
// add entry to effect list
fx = (effect_entry_t *)malloc(sizeof(effect_entry_t));
fx->subItfe = itfe;
if ((*itfe)->process_reverse != NULL) {
fx->itfe = (struct effect_interface_s *)&gInterfaceWithReverse;
} else {
fx->itfe = (struct effect_interface_s *)&gInterface;
}
fx->lib = l;
e = (list_elem_t *)malloc(sizeof(list_elem_t));
e->object = fx;
e->next = gEffectList;
gEffectList = e;
*pHandle = (effect_handle_t)fx;
exit:
pthread_mutex_unlock(&gLibLock);
return ret;
}
alps/frameworks/av/media/libeffects/factory/EffectsFactoryState.c
int findEffect(const effect_uuid_t *type,
const effect_uuid_t *uuid,
lib_entry_t **lib,
effect_descriptor_t **desc)
{
list_elem_t *e = gLibraryList;
lib_entry_t *l = NULL;
effect_descriptor_t *d = NULL;
int found = 0;
int ret = 0;
//通过uuid找到对应的音效库
while (e && !found) {
l = (lib_entry_t *)e->object;
list_elem_t *efx = l->effects;
while (efx) {
d = (effect_descriptor_t *)efx->object;
if (type != NULL && memcmp(&d->type, type, sizeof(effect_uuid_t)) == 0) {
found = 1;
break;
}
if (uuid != NULL && memcmp(&d->uuid, uuid, sizeof(effect_uuid_t)) == 0) {
found = 1;
break;
}
efx = efx->next;
}
e = e->next;
}
if (!found) {
ret = -ENOENT;
} else {
*lib = l;
if (desc) {
*desc = d;
}
}
return ret;
}
alps/frameworks/av/media/libeffects/data/audio_effects.xml
alps/frameworks/av/media/libeffects/loudness/EffectLoudnessEnhancer.cpp
// AOSP Loudness Enhancer UUID: fa415329-2034-4bea-b5dc-5b381c8d1e2c
const effect_descriptor_t gLEDescriptor = {
{0xfe3199be, 0xaed0, 0x413f, 0x87bb, {0x11, 0x26, 0x0e, 0xb6, 0x3c, 0xf1}}, // type
{0xfa415329, 0x2034, 0x4bea, 0xb5dc, {0x5b, 0x38, 0x1c, 0x8d, 0x1e, 0x2c}}, // uuid
EFFECT_CONTROL_API_VERSION,
(EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST),
0, // TODO
1,
“Loudness Enhancer”,
“The Android Open Source Project”,
};