|
|
|
@ -318,6 +318,74 @@ status_t AudioPolicyEffects::releaseOutputSessionEffects(audio_io_handle_t outpu
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t AudioPolicyEffects::addSourceDefaultEffect(const effect_uuid_t *type,
|
|
|
|
|
const String16& opPackageName,
|
|
|
|
|
const effect_uuid_t *uuid,
|
|
|
|
|
int32_t priority,
|
|
|
|
|
audio_source_t source,
|
|
|
|
|
audio_unique_id_t* id)
|
|
|
|
|
{
|
|
|
|
|
if (uuid == NULL || type == NULL) {
|
|
|
|
|
ALOGE("addSourceDefaultEffect(): Null uuid or type uuid pointer");
|
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HOTWORD and FM_TUNER are two special case sources > MAX.
|
|
|
|
|
if (source < AUDIO_SOURCE_DEFAULT ||
|
|
|
|
|
(source > AUDIO_SOURCE_MAX &&
|
|
|
|
|
source != AUDIO_SOURCE_HOTWORD &&
|
|
|
|
|
source != AUDIO_SOURCE_FM_TUNER)) {
|
|
|
|
|
ALOGE("addSourceDefaultEffect(): Unsupported source type %d", source);
|
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that |uuid| or |type| corresponds to an effect on the system.
|
|
|
|
|
effect_descriptor_t descriptor = {};
|
|
|
|
|
status_t res = AudioEffect::getEffectDescriptor(
|
|
|
|
|
uuid, type, EFFECT_FLAG_TYPE_PRE_PROC, &descriptor);
|
|
|
|
|
if (res != OK) {
|
|
|
|
|
ALOGE("addSourceDefaultEffect(): Failed to find effect descriptor matching uuid/type.");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only pre-processing effects can be added dynamically as source defaults.
|
|
|
|
|
if ((descriptor.flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_PRE_PROC) {
|
|
|
|
|
ALOGE("addSourceDefaultEffect(): Desired effect cannot be attached "
|
|
|
|
|
"as a source default effect.");
|
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
|
|
|
|
|
|
// Find the EffectDescVector for the given source type, or create a new one if necessary.
|
|
|
|
|
ssize_t index = mInputSources.indexOfKey(source);
|
|
|
|
|
EffectDescVector *desc = NULL;
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
// No effects for this source type yet.
|
|
|
|
|
desc = new EffectDescVector();
|
|
|
|
|
mInputSources.add(source, desc);
|
|
|
|
|
} else {
|
|
|
|
|
desc = mInputSources.valueAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a new effect and add it to the vector.
|
|
|
|
|
res = AudioEffect::newEffectUniqueId(id);
|
|
|
|
|
if (res != OK) {
|
|
|
|
|
ALOGE("addSourceDefaultEffect(): failed to get new unique id.");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
EffectDesc *effect = new EffectDesc(
|
|
|
|
|
descriptor.name, *type, opPackageName, *uuid, priority, *id);
|
|
|
|
|
desc->mEffects.add(effect);
|
|
|
|
|
// TODO(b/71813697): Support setting params as well.
|
|
|
|
|
|
|
|
|
|
// TODO(b/71814300): Retroactively attach to any existing sources of the given type.
|
|
|
|
|
// This requires tracking the source type of each session id in addition to what is
|
|
|
|
|
// already being tracked.
|
|
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t AudioPolicyEffects::addStreamDefaultEffect(const effect_uuid_t *type,
|
|
|
|
|
const String16& opPackageName,
|
|
|
|
|
const effect_uuid_t *uuid,
|
|
|
|
@ -384,6 +452,37 @@ status_t AudioPolicyEffects::addStreamDefaultEffect(const effect_uuid_t *type,
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t AudioPolicyEffects::removeSourceDefaultEffect(audio_unique_id_t id)
|
|
|
|
|
{
|
|
|
|
|
if (id == AUDIO_UNIQUE_ID_ALLOCATE) {
|
|
|
|
|
// ALLOCATE is not a unique identifier, but rather a reserved value indicating
|
|
|
|
|
// a real id has not been assigned. For default effects, this value is only used
|
|
|
|
|
// by system-owned defaults from the loaded config, which cannot be removed.
|
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
|
|
|
|
|
|
// Check each source type.
|
|
|
|
|
size_t numSources = mInputSources.size();
|
|
|
|
|
for (size_t i = 0; i < numSources; ++i) {
|
|
|
|
|
// Check each effect for each source.
|
|
|
|
|
EffectDescVector* descVector = mInputSources[i];
|
|
|
|
|
for (auto desc = descVector->mEffects.begin(); desc != descVector->mEffects.end(); ++desc) {
|
|
|
|
|
if ((*desc)->mId == id) {
|
|
|
|
|
// Found it!
|
|
|
|
|
// TODO(b/71814300): Remove from any sources the effect was attached to.
|
|
|
|
|
descVector->mEffects.erase(desc);
|
|
|
|
|
// Handles are unique; there can only be one match, so return early.
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Effect wasn't found, so it's been trivially removed successfully.
|
|
|
|
|
return NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status_t AudioPolicyEffects::removeStreamDefaultEffect(audio_unique_id_t id)
|
|
|
|
|
{
|
|
|
|
|
if (id == AUDIO_UNIQUE_ID_ALLOCATE) {
|
|
|
|
|