diff --git a/audio/aidl/default/Android.bp b/audio/aidl/default/Android.bp index 03f8c64a6a..5354b8e329 100644 --- a/audio/aidl/default/Android.bp +++ b/audio/aidl/default/Android.bp @@ -51,3 +51,45 @@ cc_binary { ], srcs: ["main.cpp"], } + +cc_library_static { + name: "libaudioeffectserviceexampleimpl", + vendor: true, + shared_libs: [ + "libbase", + "libbinder_ndk", + "android.media.audio.common.types-V1-ndk", + "android.hardware.audio.effect-V1-ndk", + ], + export_include_dirs: ["include"], + srcs: [ + "EffectFactory.cpp", + ], + visibility: [ + ":__subpackages__", + ], +} + +cc_binary { + name: "android.hardware.audio.effect.service-aidl.example", + relative_install_path: "hw", + init_rc: ["android.hardware.audio.effect.service-aidl.example.rc"], + vintf_fragments: ["android.hardware.audio.effect.service-aidl.xml"], + vendor: true, + shared_libs: [ + "libbase", + "libbinder_ndk", + "android.media.audio.common.types-V1-ndk", + "android.hardware.audio.effect-V1-ndk", + ], + static_libs: [ + "libaudioeffectserviceexampleimpl", + ], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + "-Wthread-safety", + ], + srcs: ["EffectMain.cpp"], +} diff --git a/audio/aidl/default/EffectFactory.cpp b/audio/aidl/default/EffectFactory.cpp new file mode 100644 index 0000000000..a31e23f8db --- /dev/null +++ b/audio/aidl/default/EffectFactory.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 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_EffectFactory" +#include + +#include "effectFactory-impl/EffectFactory.h" +#include "equalizer-impl/Equalizer.h" +#include "visualizer-impl/Visualizer.h" + +using aidl::android::media::audio::common::AudioUuid; + +namespace aidl::android::hardware::audio::effect { + +Factory::Factory() { + // TODO: implement this with xml parser on audio_effect.xml, and filter with optional + // parameters. + Descriptor::Identity id; + id.type = {static_cast(0x0bed4300), + 0xddd6, + 0x11db, + 0x8f34, + {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}; + id.uuid = EqualizerUUID; + mIdentityList.push_back(id); + id.type = {static_cast(0xd3467faa), + 0xacc7, + 0x4d34, + 0xacaf, + {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}; + id.uuid = VisualizerUUID; + mIdentityList.push_back(id); +} + +ndk::ScopedAStatus Factory::queryEffects(const std::optional& in_type, + const std::optional& in_instance, + std::vector* _aidl_return) { + std::copy_if(mIdentityList.begin(), mIdentityList.end(), std::back_inserter(*_aidl_return), + [&](auto& desc) { + return (!in_type.has_value() || in_type.value() == desc.type) && + (!in_instance.has_value() || in_instance.value() == desc.uuid); + }); + return ndk::ScopedAStatus::ok(); +} + +} // namespace aidl::android::hardware::audio::effect diff --git a/audio/aidl/default/EffectMain.cpp b/audio/aidl/default/EffectMain.cpp new file mode 100644 index 0000000000..3b3c39b7aa --- /dev/null +++ b/audio/aidl/default/EffectMain.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "effectFactory-impl/EffectFactory.h" + +#include +#include +#include + +int main() { + // This is a debug implementation, always enable debug logging. + android::base::SetMinimumLogSeverity(::android::base::DEBUG); + ABinderProcess_setThreadPoolMaxThreadCount(16); + + auto effectFactory = + ndk::SharedRefBase::make(); + std::string serviceName = std::string() + effectFactory->descriptor + "/default"; + binder_status_t status = + AServiceManager_addService(effectFactory->asBinder().get(), serviceName.c_str()); + CHECK_EQ(STATUS_OK, status); + LOG(DEBUG) << __func__ << ": effectFactoryName:" << serviceName; + + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach +} diff --git a/audio/aidl/default/android.hardware.audio.effect.service-aidl.example.rc b/audio/aidl/default/android.hardware.audio.effect.service-aidl.example.rc new file mode 100644 index 0000000000..01c0e6e6e6 --- /dev/null +++ b/audio/aidl/default/android.hardware.audio.effect.service-aidl.example.rc @@ -0,0 +1,9 @@ +service vendor.audio-effect-hal-aidl /vendor/bin/hw/android.hardware.audio.effect.service-aidl.example + class hal + user audioserver + # media gid needed for /dev/fm (radio) and for /data/misc/media (tee) + group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct wakelock context_hub + capabilities BLOCK_SUSPEND + ioprio rt 4 + task_profiles ProcessCapacityHigh HighPerformance + onrestart restart audioserver diff --git a/audio/aidl/default/android.hardware.audio.effect.service-aidl.xml b/audio/aidl/default/android.hardware.audio.effect.service-aidl.xml new file mode 100644 index 0000000000..fdc53a339c --- /dev/null +++ b/audio/aidl/default/android.hardware.audio.effect.service-aidl.xml @@ -0,0 +1,7 @@ + + + android.hardware.audio.effect + 1 + IFactory/default + + diff --git a/audio/aidl/default/include/effectFactory-impl/EffectFactory.h b/audio/aidl/default/include/effectFactory-impl/EffectFactory.h new file mode 100644 index 0000000000..7670250834 --- /dev/null +++ b/audio/aidl/default/include/effectFactory-impl/EffectFactory.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 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 +#include + +#include + +namespace aidl::android::hardware::audio::effect { + +class Factory : public BnFactory { + public: + Factory(); + /** + * @brief Get identity of all effects supported by the device, with the optional filter by type + * and/or by instance UUID. + * + * @param in_type Type UUID. + * @param in_instance Instance UUID. + * @param out_descriptor List of identities . + * @return ndk::ScopedAStatus + */ + ndk::ScopedAStatus queryEffects( + const std::optional<::aidl::android::media::audio::common::AudioUuid>& in_type, + const std::optional<::aidl::android::media::audio::common::AudioUuid>& in_instance, + std::vector* out_descriptor) override; + + private: + // List of effect descriptors supported by the devices. + std::vector mIdentityList; +}; +} // namespace aidl::android::hardware::audio::effect diff --git a/audio/aidl/default/include/equalizer-impl/Equalizer.h b/audio/aidl/default/include/equalizer-impl/Equalizer.h new file mode 100644 index 0000000000..86f8c3ad2e --- /dev/null +++ b/audio/aidl/default/include/equalizer-impl/Equalizer.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 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 + +namespace aidl::android::hardware::audio::effect { + +// Equalizer implementation UUID. +static const ::aidl::android::media::audio::common::AudioUuid EqualizerUUID = { + static_cast(0xce772f20), + 0x847d, + 0x11df, + 0xbb17, + {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}; + +} // namespace aidl::android::hardware::audio::effect \ No newline at end of file diff --git a/audio/aidl/default/include/visualizer-impl/Visualizer.h b/audio/aidl/default/include/visualizer-impl/Visualizer.h new file mode 100644 index 0000000000..4b82dd0911 --- /dev/null +++ b/audio/aidl/default/include/visualizer-impl/Visualizer.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 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 + +namespace aidl::android::hardware::audio::effect { + +// Visualizer implementation UUID. +static const ::aidl::android::media::audio::common::AudioUuid VisualizerUUID = { + static_cast(0x1d4033c0), + 0x8557, + 0x11df, + 0x9f2d, + {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}; + +} // namespace aidl::android::hardware::audio::effect \ No newline at end of file diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 7d775038f6..4e2a4edc13 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -37,6 +37,14 @@ default + + android.hardware.audio.effect + 1 + + IFactory + default + + android.hardware.authsecret 1