Merge "Add audio eraser effect AIDL and placeholder implementation" into main

This commit is contained in:
Treehugger Robot
2024-10-25 16:15:38 +00:00
committed by Android (Google) Code Review
12 changed files with 453 additions and 0 deletions

View File

@@ -303,6 +303,7 @@ aidl_interface {
"android.hardware.audio_defaults",
"latest_android_hardware_audio_common_import_interface",
"latest_android_media_audio_common_types_import_interface",
"latest_android_media_audio_eraser_types_import_interface",
],
srcs: [
"android/hardware/audio/effect/AcousticEchoCanceler.aidl",
@@ -317,6 +318,7 @@ aidl_interface {
"android/hardware/audio/effect/DynamicsProcessing.aidl",
"android/hardware/audio/effect/EnvironmentalReverb.aidl",
"android/hardware/audio/effect/Equalizer.aidl",
"android/hardware/audio/effect/Eraser.aidl",
"android/hardware/audio/effect/Flags.aidl",
"android/hardware/audio/effect/HapticGenerator.aidl",
"android/hardware/audio/effect/IEffect.aidl",

View File

@@ -44,6 +44,7 @@ parcelable Descriptor {
const String EFFECT_TYPE_UUID_DYNAMICS_PROCESSING = "7261676f-6d75-7369-6364-28e2fd3ac39e";
const String EFFECT_TYPE_UUID_ENV_REVERB = "c2e5d5f0-94bd-4763-9cac-4e234d06839e";
const String EFFECT_TYPE_UUID_EQUALIZER = "0bed4300-ddd6-11db-8f34-0002a5d5c51b";
const String EFFECT_TYPE_UUID_ERASER = "fa81a9ac-588b-11ed-9b6a-0242ac120002";
const String EFFECT_TYPE_UUID_HAPTIC_GENERATOR = "1411e6d6-aecd-4021-a1cf-a6aceb0d71e5";
const String EFFECT_TYPE_UUID_LOUDNESS_ENHANCER = "fe3199be-aed0-413f-87bb-11260eb63cf1";
const String EFFECT_TYPE_UUID_NS = "58b4b260-8e06-11e0-aa8e-0002a5d5c51b";

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 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.
*/
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
// the interface (from the latest frozen version), the build system will
// prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.audio.effect;
@VintfStability
union Eraser {
android.hardware.audio.effect.VendorExtension vendor;
android.media.audio.eraser.Capability capability;
android.media.audio.eraser.Configuration configuration;
@VintfStability
union Id {
android.hardware.audio.effect.VendorExtension vendorExtensionTag;
android.hardware.audio.effect.Eraser.Tag commonTag;
}
}

View File

@@ -63,6 +63,7 @@ union Parameter {
android.hardware.audio.effect.Volume.Id volumeTag;
android.hardware.audio.effect.Parameter.Tag commonTag;
android.hardware.audio.effect.Spatializer.Id spatializerTag;
android.hardware.audio.effect.Eraser.Id eraserTag;
}
@VintfStability
parcelable Common {
@@ -95,5 +96,6 @@ union Parameter {
android.hardware.audio.effect.Visualizer visualizer;
android.hardware.audio.effect.Volume volume;
android.hardware.audio.effect.Spatializer spatializer;
android.hardware.audio.effect.Eraser eraser;
}
}

View File

@@ -69,6 +69,10 @@ parcelable Descriptor {
* UUID for equalizer effect type.
*/
const String EFFECT_TYPE_UUID_EQUALIZER = "0bed4300-ddd6-11db-8f34-0002a5d5c51b";
/**
* UUID for Audio eraser effect type.
*/
const String EFFECT_TYPE_UUID_ERASER = "fa81a9ac-588b-11ed-9b6a-0242ac120002";
/**
* UUID for Haptic Generator type.
*/

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2024 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.
*/
package android.hardware.audio.effect;
import android.hardware.audio.effect.VendorExtension;
import android.media.audio.eraser.Capability;
import android.media.audio.eraser.Configuration;
import android.media.audio.eraser.Mode;
/**
* The Audio Eraser Effect is an audio effect that combines multiple capabilities to manipulate and
* enhance audio streams.
*
* The Audio Eraser Effect integrates three primary components:
*
* Sound Separator: Detects and splits the input audio into multiple sound sources.
* Sound Classifier: Classifies each separated sound source into predefined categories based on the
* AudioSet ontology.
* Remixer: Adjusts the gain factor (volume) of each classified sound source according to specified
* configurations, then recombines them into a single output audio stream.
*
* The Audio Eraser Effect operates in different modes, each leveraging a subset of these
* components to achieve specific functionalities as defined in `android.media.audio.eraser.Mode`.
*
* Flow Diagrams for each operation mode as below.
*
* ERASER:
* +-----------------+
* +-->| Sound Classifier|---+
* | +-----------------+ |
* | |
*+----------------+ +----------------+ | +-----------------+ | +----------------+
*| Input Audio |------>| Sound Separator|---+-->| Sound Classifier|---+-->| Remixer |
*+----------------+ +----------------+ | +-----------------+ | +--------+-------+
* | | |
* | +-----------------+ | |
* +-->| Sound Classifier|---+ |
* +-----------------+ |
* | v
* v +----------------+
* {Classification Metadata} | Output Audio |
* +----------------+
*
* CLASSIFIER:
*+----------------+ +-----------------+ +-----------------+
*| Input Audio |------>| Sound Classifier|------>| Original Audio |
*+----------------+ +-----------------+ +-----------------+
* |
* v
* {Classification Metadata}
*
*/
@VintfStability
union Eraser {
/**
* Parameter Id with union tag to identify the parameters for getParameter().
*/
@VintfStability
union Id {
VendorExtension vendorExtensionTag;
Eraser.Tag commonTag;
}
/**
* Vendor extension parameters which can be customized.
*/
VendorExtension vendor;
/**
* Eraser capability, defines supported input/output data formats, available work modes, and
* the specific capabilities of the sound classifier and separator
*/
Capability capability;
/**
* Eraser configuration, contains the list of configurations for the eraser effect.
*/
Configuration configuration;
}

View File

@@ -26,6 +26,7 @@ import android.hardware.audio.effect.Downmix;
import android.hardware.audio.effect.DynamicsProcessing;
import android.hardware.audio.effect.EnvironmentalReverb;
import android.hardware.audio.effect.Equalizer;
import android.hardware.audio.effect.Eraser;
import android.hardware.audio.effect.HapticGenerator;
import android.hardware.audio.effect.LoudnessEnhancer;
import android.hardware.audio.effect.NoiseSuppression;
@@ -111,6 +112,10 @@ union Parameter {
* Parameter tag defined for Spatializer parameters.
*/
Spatializer.Id spatializerTag;
/**
* Parameter tag defined for eraser parameters.
*/
Eraser.Id eraserTag;
}
/**
@@ -198,6 +203,8 @@ union Parameter {
Visualizer visualizer;
Volume volume;
Spatializer spatializer;
// Eraser added at android.hardware.audio.effect.V3
Eraser eraser;
}
Specific specific;

View File

@@ -36,6 +36,7 @@
<library name="downmix" path="libdownmixaidl.so"/>
<library name="dynamics_processing" path="libdynamicsprocessingaidl.so"/>
<library name="equalizersw" path="libequalizersw.so"/>
<library name="erasersw" path="liberasersw.so"/>
<library name="haptic_generator" path="libhapticgeneratoraidl.so"/>
<library name="loudness_enhancer" path="libloudnessenhanceraidl.so"/>
<library name="nssw" path="libnssw.so"/>

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 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.
*/
package {
default_team: "trendy_team_android_media_audio_framework",
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "hardware_interfaces_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["hardware_interfaces_license"],
}
cc_library_shared {
name: "liberasersw",
defaults: [
"aidlaudioeffectservice_defaults",
],
srcs: [
"Eraser.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default:__subpackages__",
],
}

View File

@@ -0,0 +1,187 @@
/*
* Copyright (C) 2024 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_TAG "AHAL_Eraser"
#include "Eraser.h"
#include <android-base/logging.h>
#include <system/audio_effects/effect_uuid.h>
#include <optional>
using aidl::android::hardware::audio::common::getChannelCount;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::EraserSw;
using aidl::android::hardware::audio::effect::getEffectImplUuidEraserSw;
using aidl::android::hardware::audio::effect::getEffectTypeUuidEraser;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::State;
using aidl::android::media::audio::common::AudioChannelLayout;
using aidl::android::media::audio::common::AudioUuid;
extern "C" binder_exception_t createEffect(const AudioUuid* in_impl_uuid,
std::shared_ptr<IEffect>* instanceSpp) {
if (!in_impl_uuid || *in_impl_uuid != getEffectImplUuidEraserSw()) {
LOG(ERROR) << __func__ << "uuid not supported";
return EX_ILLEGAL_ARGUMENT;
}
if (!instanceSpp) {
LOG(ERROR) << __func__ << " invalid input parameter!";
return EX_ILLEGAL_ARGUMENT;
}
*instanceSpp = ndk::SharedRefBase::make<EraserSw>();
LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
}
extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descriptor* _aidl_return) {
if (!in_impl_uuid || *in_impl_uuid != getEffectImplUuidEraserSw()) {
LOG(ERROR) << __func__ << "uuid not supported";
return EX_ILLEGAL_ARGUMENT;
}
*_aidl_return = EraserSw::kDescriptor;
return EX_NONE;
}
namespace aidl::android::hardware::audio::effect {
const std::string EraserSw::kEffectName = "EraserSw";
const Descriptor EraserSw::kDescriptor = {
.common = {.id = {.type = getEffectTypeUuidEraser(), .uuid = getEffectImplUuidEraserSw()},
.flags = {.type = Flags::Type::INSERT,
.insert = Flags::Insert::FIRST,
.hwAcceleratorMode = Flags::HardwareAccelerator::NONE},
.name = EraserSw::kEffectName,
.implementor = "The Android Open Source Project"}};
ndk::ScopedAStatus EraserSw::getDescriptor(Descriptor* _aidl_return) {
LOG(DEBUG) << __func__ << kDescriptor.toString();
*_aidl_return = kDescriptor;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus EraserSw::setParameterSpecific(const Parameter::Specific& specific) {
RETURN_IF(Parameter::Specific::eraser != specific.getTag(), EX_ILLEGAL_ARGUMENT,
"EffectNotSupported");
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
auto& param = specific.get<Parameter::Specific::eraser>();
return mContext->setParam(param.getTag(), param);
}
ndk::ScopedAStatus EraserSw::getParameterSpecific(const Parameter::Id& id,
Parameter::Specific* specific) {
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
auto tag = id.getTag();
RETURN_IF(Parameter::Id::eraserTag != tag, EX_ILLEGAL_ARGUMENT, "wrongIdTag");
auto eraserId = id.get<Parameter::Id::eraserTag>();
auto eraserTag = eraserId.getTag();
switch (eraserTag) {
case Eraser::Id::commonTag: {
auto specificTag = eraserId.get<Eraser::Id::commonTag>();
std::optional<Eraser> param = mContext->getParam(specificTag);
if (!param.has_value()) {
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
"EraserTagNotSupported");
}
specific->set<Parameter::Specific::eraser>(param.value());
break;
}
default: {
LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
"EraserTagNotSupported");
}
}
return ndk::ScopedAStatus::ok();
}
std::shared_ptr<EffectContext> EraserSw::createContext(const Parameter::Common& common) {
if (mContext) {
LOG(DEBUG) << __func__ << " context already exist";
} else {
mContext = std::make_shared<EraserSwContext>(1 /* statusFmqDepth */, common);
}
return mContext;
}
RetCode EraserSw::releaseContext() {
if (mContext) {
mContext.reset();
}
return RetCode::SUCCESS;
}
EraserSw::~EraserSw() {
cleanUp();
LOG(DEBUG) << __func__;
}
// Processing method running in EffectWorker thread.
IEffect::Status EraserSw::effectProcessImpl(float* in, float* out, int samples) {
RETURN_VALUE_IF(!mContext, (IEffect::Status{EX_NULL_POINTER, 0, 0}), "nullContext");
return mContext->process(in, out, samples);
}
EraserSwContext::EraserSwContext(int statusDepth, const Parameter::Common& common)
: EffectContext(statusDepth, common) {
LOG(DEBUG) << __func__;
}
EraserSwContext::~EraserSwContext() {
LOG(DEBUG) << __func__;
}
template <typename TAG>
std::optional<Eraser> EraserSwContext::getParam(TAG tag) {
if (mParamsMap.find(tag) != mParamsMap.end()) {
return mParamsMap.at(tag);
}
return std::nullopt;
}
template <typename TAG>
ndk::ScopedAStatus EraserSwContext::setParam(TAG tag, Eraser eraser) {
mParamsMap[tag] = eraser;
return ndk::ScopedAStatus::ok();
}
IEffect::Status EraserSwContext::process(float* in, float* out, int samples) {
LOG(DEBUG) << __func__ << " in " << in << " out " << out << " samples " << samples;
IEffect::Status status = {EX_ILLEGAL_ARGUMENT, 0, 0};
const auto inputChannelCount = getChannelCount(mCommon.input.base.channelMask);
const auto outputChannelCount = getChannelCount(mCommon.output.base.channelMask);
if (inputChannelCount < outputChannelCount) {
LOG(ERROR) << __func__ << " invalid channel count, in: " << inputChannelCount
<< " out: " << outputChannelCount;
return status;
}
int iFrames = samples / inputChannelCount;
for (int i = 0; i < iFrames; i++) {
std::memcpy(out, in, outputChannelCount);
in += inputChannelCount;
out += outputChannelCount;
}
return {STATUS_OK, static_cast<int32_t>(iFrames * inputChannelCount),
static_cast<int32_t>(iFrames * outputChannelCount)};
}
} // namespace aidl::android::hardware::audio::effect

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2024 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.
*/
#pragma once
#include "effect-impl/EffectContext.h"
#include "effect-impl/EffectImpl.h"
#include <fmq/AidlMessageQueue.h>
#include <unordered_map>
#include <vector>
namespace aidl::android::hardware::audio::effect {
class EraserSwContext final : public EffectContext {
public:
EraserSwContext(int statusDepth, const Parameter::Common& common);
~EraserSwContext() final;
template <typename TAG>
std::optional<Eraser> getParam(TAG tag);
template <typename TAG>
ndk::ScopedAStatus setParam(TAG tag, Eraser eraser);
IEffect::Status process(float* in, float* out, int samples);
private:
std::unordered_map<Eraser::Tag, Eraser> mParamsMap;
};
class EraserSw final : public EffectImpl {
public:
static const std::string kEffectName;
static const Capability kCapability;
static const Descriptor kDescriptor;
~EraserSw() final;
ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) final;
ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
REQUIRES(mImplMutex) final;
ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
REQUIRES(mImplMutex) final;
std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
REQUIRES(mImplMutex) final;
RetCode releaseContext() REQUIRES(mImplMutex) final;
std::string getEffectName() final { return kEffectName; };
IEffect::Status effectProcessImpl(float* in, float* out, int samples)
REQUIRES(mImplMutex) final;
private:
static const std::vector<Range::SpatializerRange> kRanges;
std::shared_ptr<EraserSwContext> mContext GUARDED_BY(mImplMutex);
};
} // namespace aidl::android::hardware::audio::effect

View File

@@ -14,6 +14,7 @@ cc_defaults {
"latest_android_hardware_audio_common_ndk_static",
"latest_android_hardware_audio_effect_ndk_static",
"latest_android_media_audio_common_types_ndk_static",
"latest_android_media_audio_eraser_types_ndk_static",
"use_libaidlvintf_gtest_helper_static",
"VtsHalTargetTestDefaults",
],