diff --git a/audio/README.md b/audio/README.md index 83ae6b26e8..b77b9ba42d 100644 --- a/audio/README.md +++ b/audio/README.md @@ -18,6 +18,10 @@ based on an existing one. - `2.0` -- version 2.0 of the common types HIDL API. - `4.0` -- version 4.0. - ... + - `7.0` -- version 7.0. + - `example` -- example implementation of the core and effect + V7.0 API. It represents a "fake" audio HAL that doesn't + actually communicate with hardware. - `all-versions` -- code common to all version of both core and effect API. - `default` -- shared code of the default implementation. - `service` -- vendor HAL service for hosting the default diff --git a/audio/common/7.0/example/Android.bp b/audio/common/7.0/example/Android.bp new file mode 100644 index 0000000000..03c1cd89cd --- /dev/null +++ b/audio/common/7.0/example/Android.bp @@ -0,0 +1,45 @@ +// +// Copyright (C) 2020 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. + +cc_binary { + name: "android.hardware.audio@7.0-service.example", + vendor: true, + relative_install_path: "hw", + init_rc: ["android.hardware.audio@7.0-service.example.rc"], + vintf_fragments: ["android.hardware.audio@7.0-service.example.xml"], + srcs: [ + "DevicesFactory.cpp", + "Effect.cpp", + "EffectsFactory.cpp", + "EqualizerEffect.cpp", + "LoudnessEnhancerEffect.cpp", + "service.cpp", + ], + cflags: [ + "-Wall", + "-Werror", + ], + shared_libs: [ + "libcutils", + "libhidlbase", + "liblog", + "libxml2", + "libutils", + "android.hardware.audio@7.0", + "android.hardware.audio.common@7.0", + "android.hardware.audio.common@7.0-enums", + "android.hardware.audio.effect@7.0", + ], +} diff --git a/audio/common/7.0/example/DevicesFactory.cpp b/audio/common/7.0/example/DevicesFactory.cpp new file mode 100644 index 0000000000..ddd5fef8f7 --- /dev/null +++ b/audio/common/7.0/example/DevicesFactory.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 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 "DevicesFactory7.0" +#include + +#include "DevicesFactory.h" + +using ::android::hardware::hidl_string; +using ::android::hardware::Return; +using ::android::hardware::Void; + +namespace android::hardware::audio::V7_0::implementation { + +Return DevicesFactory::openDevice(const hidl_string& device, openDevice_cb _hidl_cb) { + (void)device; + _hidl_cb(Result::INVALID_ARGUMENTS, nullptr); + return Void(); +} + +Return DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) { + _hidl_cb(Result::INVALID_ARGUMENTS, nullptr); + return Void(); +} + +} // namespace android::hardware::audio::V7_0::implementation diff --git a/audio/common/7.0/example/DevicesFactory.h b/audio/common/7.0/example/DevicesFactory.h new file mode 100644 index 0000000000..00f665c17e --- /dev/null +++ b/audio/common/7.0/example/DevicesFactory.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 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 android::hardware::audio::V7_0::implementation { + +class DevicesFactory : public IDevicesFactory { + public: + DevicesFactory() = default; + + ::android::hardware::Return openDevice(const ::android::hardware::hidl_string& device, + openDevice_cb _hidl_cb) override; + + ::android::hardware::Return openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override; +}; + +} // namespace android::hardware::audio::V7_0::implementation diff --git a/audio/common/7.0/example/Effect.cpp b/audio/common/7.0/example/Effect.cpp new file mode 100644 index 0000000000..423754d593 --- /dev/null +++ b/audio/common/7.0/example/Effect.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2020 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 "EffectsFactory7.0" +#include + +#include + +#include "Effect.h" + +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using namespace ::android::hardware::audio::common::V7_0; +// Make an alias for enumerations generated from the APM config XSD. +namespace xsd { +using namespace ::audio::policy::configuration::V7_0; +} + +namespace android::hardware::audio::effect::V7_0::implementation { + +Return Effect::init() { + return Result::OK; +} + +Return Effect::setConfig( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) { + (void)config; + (void)inputBufferProvider; + (void)outputBufferProvider; + return Result::OK; +} + +Return Effect::reset() { + return Result::OK; +} + +Return Effect::enable() { + if (!mEnabled) { + mEnabled = true; + return Result::OK; + } else { + return Result::NOT_SUPPORTED; + } +} + +Return Effect::disable() { + if (mEnabled) { + mEnabled = false; + return Result::OK; + } else { + return Result::NOT_SUPPORTED; + } +} + +Return Effect::setDevice(const DeviceAddress& device) { + (void)device; + return Result::OK; +} + +Return Effect::setAndGetVolume(const hidl_vec& volumes, + setAndGetVolume_cb _hidl_cb) { + (void)volumes; + _hidl_cb(Result::OK, hidl_vec{}); + return Void(); +} + +Return Effect::volumeChangeNotification(const hidl_vec& volumes) { + (void)volumes; + return Result::OK; +} + +Return Effect::setAudioMode(AudioMode mode) { + (void)mode; + return Result::OK; +} + +Return Effect::setConfigReverse( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) { + (void)config; + (void)inputBufferProvider; + (void)outputBufferProvider; + return Result::OK; +} + +Return Effect::setInputDevice(const DeviceAddress& device) { + (void)device; + return Result::OK; +} + +Return Effect::getConfig(getConfig_cb _hidl_cb) { + const EffectConfig config = {{} /* inputCfg */, + // outputCfg + {{} /* buffer */, + 48000 /* samplingRateHz */, + toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO), + toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT), + EffectBufferAccess::ACCESS_ACCUMULATE, + 0 /* mask */}}; + _hidl_cb(Result::OK, config); + return Void(); +} + +Return Effect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + _hidl_cb(Result::OK, EffectConfig{}); + return Void(); +} + +Return Effect::getSupportedAuxChannelsConfigs(uint32_t maxConfigs, + getSupportedAuxChannelsConfigs_cb _hidl_cb) { + (void)maxConfigs; + _hidl_cb(Result::OK, hidl_vec{}); + return Void(); +} + +Return Effect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + _hidl_cb(Result::OK, EffectAuxChannelsConfig{}); + return Void(); +} + +Return Effect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) { + (void)config; + return Result::OK; +} + +Return Effect::setAudioSource(const hidl_string& source) { + (void)source; + return Result::OK; +} + +Return Effect::offload(const EffectOffloadParameter& param) { + (void)param; + return Result::OK; +} + +Return Effect::getDescriptor(getDescriptor_cb _hidl_cb) { + _hidl_cb(Result::OK, mDescriptor); + return Void(); +} + +Return Effect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) { + _hidl_cb(Result::OK, MQDescriptor{}); + return Void(); +} + +Return Effect::setProcessBuffers(const AudioBuffer& inBuffer, + const AudioBuffer& outBuffer) { + (void)inBuffer; + (void)outBuffer; + return Result::OK; +} + +Return Effect::command(uint32_t commandId, const hidl_vec& data, + uint32_t resultMaxSize, command_cb _hidl_cb) { + (void)commandId; + (void)data; + (void)resultMaxSize; + _hidl_cb(-EINVAL, hidl_vec{}); + return Void(); +} + +Return Effect::setParameter(const hidl_vec& parameter, + const hidl_vec& value) { + (void)parameter; + (void)value; + return Result::OK; +} + +Return Effect::getParameter(const hidl_vec& parameter, uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + (void)parameter; + (void)valueMaxSize; + _hidl_cb(Result::OK, hidl_vec{}); + return Void(); +} + +Return Effect::getSupportedConfigsForFeature(uint32_t featureId, uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + (void)featureId; + (void)maxConfigs; + (void)configSize; + _hidl_cb(Result::OK, 0, hidl_vec{}); + return Void(); +} + +Return Effect::getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + (void)featureId; + (void)configSize; + _hidl_cb(Result::OK, hidl_vec{}); + return Void(); +} + +Return Effect::setCurrentConfigForFeature(uint32_t featureId, + const hidl_vec& configData) { + (void)featureId; + (void)configData; + return Result::OK; +} + +Return Effect::close() { + return Result::OK; +} + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/Effect.h b/audio/common/7.0/example/Effect.h new file mode 100644 index 0000000000..fa7f41bda6 --- /dev/null +++ b/audio/common/7.0/example/Effect.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2020 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 android::hardware::audio::effect::V7_0::implementation { + +class Effect : public IEffect { + public: + explicit Effect(const EffectDescriptor& descriptor) : mDescriptor(descriptor) {} + + ::android::hardware::Return init() override; + ::android::hardware::Return setConfig( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override; + ::android::hardware::Return reset() override; + ::android::hardware::Return enable() override; + ::android::hardware::Return disable() override; + ::android::hardware::Return setDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override; + ::android::hardware::Return setAndGetVolume( + const ::android::hardware::hidl_vec& volumes, + setAndGetVolume_cb _hidl_cb) override; + ::android::hardware::Return volumeChangeNotification( + const ::android::hardware::hidl_vec& volumes) override; + ::android::hardware::Return setAudioMode( + ::android::hardware::audio::common::V7_0::AudioMode mode) override; + ::android::hardware::Return setConfigReverse( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override; + ::android::hardware::Return setInputDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override; + ::android::hardware::Return getConfig(getConfig_cb _hidl_cb) override; + ::android::hardware::Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + ::android::hardware::Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + ::android::hardware::Return getAuxChannelsConfig( + getAuxChannelsConfig_cb _hidl_cb) override; + ::android::hardware::Return setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) override; + ::android::hardware::Return setAudioSource( + const ::android::hardware::hidl_string& source) override; + ::android::hardware::Return offload(const EffectOffloadParameter& param) override; + ::android::hardware::Return getDescriptor(getDescriptor_cb _hidl_cb) override; + ::android::hardware::Return prepareForProcessing( + prepareForProcessing_cb _hidl_cb) override; + ::android::hardware::Return setProcessBuffers(const AudioBuffer& inBuffer, + const AudioBuffer& outBuffer) override; + ::android::hardware::Return command(uint32_t commandId, + const ::android::hardware::hidl_vec& data, + uint32_t resultMaxSize, command_cb _hidl_cb) override; + ::android::hardware::Return setParameter( + const ::android::hardware::hidl_vec& parameter, + const ::android::hardware::hidl_vec& value) override; + ::android::hardware::Return getParameter( + const ::android::hardware::hidl_vec& parameter, uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + ::android::hardware::Return getSupportedConfigsForFeature( + uint32_t featureId, uint32_t maxConfigs, uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + ::android::hardware::Return getCurrentConfigForFeature( + uint32_t featureId, uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + ::android::hardware::Return setCurrentConfigForFeature( + uint32_t featureId, const ::android::hardware::hidl_vec& configData) override; + ::android::hardware::Return close() override; + + private: + const EffectDescriptor mDescriptor; + bool mEnabled = false; +}; + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/EffectsFactory.cpp b/audio/common/7.0/example/EffectsFactory.cpp new file mode 100644 index 0000000000..7d333ae040 --- /dev/null +++ b/audio/common/7.0/example/EffectsFactory.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020 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 "EffectsFactory7.0" +#include + +#include "EffectsFactory.h" +#include "EqualizerEffect.h" +#include "LoudnessEnhancerEffect.h" + +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using namespace ::android::hardware::audio::common::V7_0; + +namespace android::hardware::audio::effect::V7_0::implementation { + +Return EffectsFactory::getAllDescriptors(getAllDescriptors_cb _hidl_cb) { + hidl_vec descriptors; + descriptors.resize(2); + descriptors[0] = EqualizerEffect::getDescriptor(); + descriptors[1] = LoudnessEnhancerEffect::getDescriptor(); + _hidl_cb(Result::OK, descriptors); + return Void(); +} + +Return EffectsFactory::getDescriptor(const Uuid& uuid, getDescriptor_cb _hidl_cb) { + if (auto desc = EqualizerEffect::getDescriptor(); uuid == desc.type || uuid == desc.uuid) { + _hidl_cb(Result::OK, desc); + } else if (auto desc = LoudnessEnhancerEffect::getDescriptor(); + uuid == desc.type || uuid == desc.uuid) { + _hidl_cb(Result::OK, desc); + } else { + _hidl_cb(Result::INVALID_ARGUMENTS, EffectDescriptor{}); + } + return Void(); +} + +Return EffectsFactory::createEffect(const Uuid& uuid, int32_t session, int32_t ioHandle, + int32_t device, createEffect_cb _hidl_cb) { + (void)session; + (void)ioHandle; + (void)device; + if (auto desc = EqualizerEffect::getDescriptor(); uuid == desc.type || uuid == desc.uuid) { + _hidl_cb(Result::OK, new EqualizerEffect(), 0); + } else if (auto desc = LoudnessEnhancerEffect::getDescriptor(); + uuid == desc.type || uuid == desc.uuid) { + _hidl_cb(Result::OK, new LoudnessEnhancerEffect(), 0); + } else { + _hidl_cb(Result::INVALID_ARGUMENTS, nullptr, 0); + } + return Void(); +} + +Return EffectsFactory::debug(const hidl_handle& fd, const hidl_vec& options) { + (void)fd; + (void)options; + return Void(); +} + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/EffectsFactory.h b/audio/common/7.0/example/EffectsFactory.h new file mode 100644 index 0000000000..8fec70cb35 --- /dev/null +++ b/audio/common/7.0/example/EffectsFactory.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 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 android::hardware::audio::effect::V7_0::implementation { + +class EffectsFactory : public IEffectsFactory { + public: + EffectsFactory() = default; + + ::android::hardware::Return getAllDescriptors(getAllDescriptors_cb _hidl_cb) override; + ::android::hardware::Return getDescriptor( + const ::android::hardware::audio::common::V7_0::Uuid& uuid, + getDescriptor_cb _hidl_cb) override; + ::android::hardware::Return createEffect( + const ::android::hardware::audio::common::V7_0::Uuid& uuid, int32_t session, + int32_t ioHandle, int32_t device, createEffect_cb _hidl_cb) override; + ::android::hardware::Return + debug(const ::android::hardware::hidl_handle& fd, + const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& options) override; +}; + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/EqualizerEffect.cpp b/audio/common/7.0/example/EqualizerEffect.cpp new file mode 100644 index 0000000000..c93c5a90fb --- /dev/null +++ b/audio/common/7.0/example/EqualizerEffect.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2020 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 + +#define LOG_TAG "EffectsFactory7.0" +#include + +#include "EqualizerEffect.h" + +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using namespace ::android::hardware::audio::common::V7_0; + +namespace android::hardware::audio::effect::V7_0::implementation { + +const EffectDescriptor& EqualizerEffect::getDescriptor() { + // Note: for VTS tests only 'type' and 'uuid' fields are required. + // The actual implementation must provide meaningful values + // for all fields of the descriptor. + static const EffectDescriptor descriptor = { + .type = + {// Same UUID as AudioEffect.EFFECT_TYPE_EQUALIZER in Java. + 0x0bed4300, 0xddd6, 0x11db, 0x8f34, + std::array{{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}}, + .uuid = {0, 0, 0, 1, std::array{{0, 0, 0, 0, 0, 0}}}}; + return descriptor; +} + +EqualizerEffect::EqualizerEffect() : mEffect(new Effect(getDescriptor())) { + mProperties.bandLevels.resize(kNumBands); +} + +Return EqualizerEffect::getNumBands(getNumBands_cb _hidl_cb) { + _hidl_cb(Result::OK, kNumBands); + return Void(); +} + +Return EqualizerEffect::getLevelRange(getLevelRange_cb _hidl_cb) { + _hidl_cb(Result::OK, std::numeric_limits::min(), std::numeric_limits::max()); + return Void(); +} + +Return EqualizerEffect::setBandLevel(uint16_t band, int16_t level) { + if (band < kNumBands) { + mProperties.bandLevels[band] = level; + return Result::OK; + } else { + return Result::INVALID_ARGUMENTS; + } +} + +Return EqualizerEffect::getBandLevel(uint16_t band, getBandLevel_cb _hidl_cb) { + if (band < kNumBands) { + _hidl_cb(Result::OK, mProperties.bandLevels[band]); + } else { + _hidl_cb(Result::INVALID_ARGUMENTS, 0); + } + return Void(); +} + +Return EqualizerEffect::getBandCenterFrequency(uint16_t band, + getBandCenterFrequency_cb _hidl_cb) { + (void)band; + _hidl_cb(Result::OK, 0); + return Void(); +} + +Return EqualizerEffect::getBandFrequencyRange(uint16_t band, + getBandFrequencyRange_cb _hidl_cb) { + (void)band; + _hidl_cb(Result::OK, 0, 1); + return Void(); +} + +Return EqualizerEffect::getBandForFrequency(uint32_t freq, getBandForFrequency_cb _hidl_cb) { + (void)freq; + _hidl_cb(Result::OK, 0); + return Void(); +} + +Return EqualizerEffect::getPresetNames(getPresetNames_cb _hidl_cb) { + hidl_vec presetNames; + presetNames.resize(kNumPresets); + presetNames[0] = "default"; + _hidl_cb(Result::OK, presetNames); + return Void(); +} + +Return EqualizerEffect::setCurrentPreset(uint16_t preset) { + if (preset < kNumPresets) { + mProperties.curPreset = preset; + return Result::OK; + } else { + return Result::INVALID_ARGUMENTS; + } +} + +Return EqualizerEffect::getCurrentPreset(getCurrentPreset_cb _hidl_cb) { + _hidl_cb(Result::OK, mProperties.curPreset); + return Void(); +} + +Return EqualizerEffect::setAllProperties( + const IEqualizerEffect::AllProperties& properties) { + mProperties = properties; + return Result::OK; +} + +Return EqualizerEffect::getAllProperties(getAllProperties_cb _hidl_cb) { + _hidl_cb(Result::OK, mProperties); + return Void(); +} + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/EqualizerEffect.h b/audio/common/7.0/example/EqualizerEffect.h new file mode 100644 index 0000000000..11853c3392 --- /dev/null +++ b/audio/common/7.0/example/EqualizerEffect.h @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2020 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 "Effect.h" + +namespace android::hardware::audio::effect::V7_0::implementation { + +class EqualizerEffect : public IEqualizerEffect { + public: + static const EffectDescriptor& getDescriptor(); + + EqualizerEffect(); + + // Methods from IEffect interface. + ::android::hardware::Return init() override { return mEffect->init(); } + ::android::hardware::Return setConfig( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); + } + ::android::hardware::Return reset() override { return mEffect->reset(); } + ::android::hardware::Return enable() override { return mEffect->enable(); } + ::android::hardware::Return disable() override { return mEffect->disable(); } + ::android::hardware::Return setDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override { + return mEffect->setDevice(device); + } + ::android::hardware::Return setAndGetVolume( + const ::android::hardware::hidl_vec& volumes, + setAndGetVolume_cb _hidl_cb) override { + return mEffect->setAndGetVolume(volumes, _hidl_cb); + } + ::android::hardware::Return volumeChangeNotification( + const ::android::hardware::hidl_vec& volumes) override { + return mEffect->volumeChangeNotification(volumes); + } + ::android::hardware::Return setAudioMode( + ::android::hardware::audio::common::V7_0::AudioMode mode) override { + return mEffect->setAudioMode(mode); + } + ::android::hardware::Return setConfigReverse( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); + } + ::android::hardware::Return setInputDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override { + return mEffect->setInputDevice(device); + } + ::android::hardware::Return getConfig(getConfig_cb _hidl_cb) override { + return mEffect->getConfig(_hidl_cb); + } + ::android::hardware::Return getConfigReverse(getConfigReverse_cb _hidl_cb) override { + return mEffect->getConfigReverse(_hidl_cb); + } + ::android::hardware::Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); + } + ::android::hardware::Return getAuxChannelsConfig( + getAuxChannelsConfig_cb _hidl_cb) override { + return mEffect->getAuxChannelsConfig(_hidl_cb); + } + ::android::hardware::Return setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) override { + return mEffect->setAuxChannelsConfig(config); + } + ::android::hardware::Return setAudioSource( + const ::android::hardware::hidl_string& source) override { + return mEffect->setAudioSource(source); + } + ::android::hardware::Return offload(const EffectOffloadParameter& param) override { + return mEffect->offload(param); + } + ::android::hardware::Return getDescriptor(getDescriptor_cb _hidl_cb) override { + return mEffect->getDescriptor(_hidl_cb); + } + ::android::hardware::Return prepareForProcessing( + prepareForProcessing_cb _hidl_cb) override { + return mEffect->prepareForProcessing(_hidl_cb); + } + ::android::hardware::Return setProcessBuffers(const AudioBuffer& inBuffer, + const AudioBuffer& outBuffer) override { + return mEffect->setProcessBuffers(inBuffer, outBuffer); + } + ::android::hardware::Return command(uint32_t commandId, + const ::android::hardware::hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); + } + ::android::hardware::Return setParameter( + const ::android::hardware::hidl_vec& parameter, + const ::android::hardware::hidl_vec& value) override { + return mEffect->setParameter(parameter, value); + } + ::android::hardware::Return getParameter( + const ::android::hardware::hidl_vec& parameter, uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); + } + ::android::hardware::Return getSupportedConfigsForFeature( + uint32_t featureId, uint32_t maxConfigs, uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); + } + ::android::hardware::Return getCurrentConfigForFeature( + uint32_t featureId, uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); + } + ::android::hardware::Return setCurrentConfigForFeature( + uint32_t featureId, const ::android::hardware::hidl_vec& configData) override { + return mEffect->setCurrentConfigForFeature(featureId, configData); + } + ::android::hardware::Return close() override { return mEffect->close(); } + + // Methods from IEqualizerEffect interface. + ::android::hardware::Return getNumBands(getNumBands_cb _hidl_cb) override; + ::android::hardware::Return getLevelRange(getLevelRange_cb _hidl_cb) override; + ::android::hardware::Return setBandLevel(uint16_t band, int16_t level) override; + ::android::hardware::Return getBandLevel(uint16_t band, + getBandLevel_cb _hidl_cb) override; + ::android::hardware::Return getBandCenterFrequency( + uint16_t band, getBandCenterFrequency_cb _hidl_cb) override; + ::android::hardware::Return getBandFrequencyRange( + uint16_t band, getBandFrequencyRange_cb _hidl_cb) override; + ::android::hardware::Return getBandForFrequency(uint32_t freq, + getBandForFrequency_cb _hidl_cb) override; + ::android::hardware::Return getPresetNames(getPresetNames_cb _hidl_cb) override; + ::android::hardware::Return setCurrentPreset(uint16_t preset) override; + ::android::hardware::Return getCurrentPreset(getCurrentPreset_cb _hidl_cb) override; + ::android::hardware::Return setAllProperties( + const IEqualizerEffect::AllProperties& properties) override; + ::android::hardware::Return getAllProperties(getAllProperties_cb _hidl_cb) override; + + private: + static constexpr size_t kNumBands = 1; + static constexpr size_t kNumPresets = 1; + sp mEffect; + IEqualizerEffect::AllProperties mProperties{}; +}; + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/LoudnessEnhancerEffect.cpp b/audio/common/7.0/example/LoudnessEnhancerEffect.cpp new file mode 100644 index 0000000000..38269b3308 --- /dev/null +++ b/audio/common/7.0/example/LoudnessEnhancerEffect.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 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 "EffectsFactory7.0" +#include + +#include "LoudnessEnhancerEffect.h" + +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using namespace ::android::hardware::audio::common::V7_0; + +namespace android::hardware::audio::effect::V7_0::implementation { + +const EffectDescriptor& LoudnessEnhancerEffect::getDescriptor() { + // Note: for VTS tests only 'type' and 'uuid' fields are required. + // The actual implementation must provide meaningful values + // for all fields of the descriptor. + static const EffectDescriptor descriptor = { + .type = + {// Same UUID as AudioEffect.EFFECT_TYPE_LOUDNESS_ENHANCER in Java. + 0xfe3199be, 0xaed0, 0x413f, 0x87bb, + std::array{{0x11, 0x26, 0x0e, 0xb6, 0x3c, 0xf1}}}, + .uuid = {0, 0, 0, 2, std::array{{0, 0, 0, 0, 0, 0}}}}; + return descriptor; +} // namespace android::hardware::audio::effect::V7_0::implementation + +LoudnessEnhancerEffect::LoudnessEnhancerEffect() : mEffect(new Effect(getDescriptor())) {} + +Return LoudnessEnhancerEffect::setTargetGain(int32_t targetGainMb) { + mTargetGainMb = targetGainMb; + return Result::OK; +} + +Return LoudnessEnhancerEffect::getTargetGain(getTargetGain_cb _hidl_cb) { + _hidl_cb(Result::OK, mTargetGainMb); + return Void(); +} + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/LoudnessEnhancerEffect.h b/audio/common/7.0/example/LoudnessEnhancerEffect.h new file mode 100644 index 0000000000..1af0d9f852 --- /dev/null +++ b/audio/common/7.0/example/LoudnessEnhancerEffect.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2020 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 "Effect.h" + +namespace android::hardware::audio::effect::V7_0::implementation { + +class LoudnessEnhancerEffect : public ILoudnessEnhancerEffect { + public: + static const EffectDescriptor& getDescriptor(); + + LoudnessEnhancerEffect(); + + // Methods from IEffect interface. + ::android::hardware::Return init() override { return mEffect->init(); } + ::android::hardware::Return setConfig( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); + } + ::android::hardware::Return reset() override { return mEffect->reset(); } + ::android::hardware::Return enable() override { return mEffect->enable(); } + ::android::hardware::Return disable() override { return mEffect->disable(); } + ::android::hardware::Return setDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override { + return mEffect->setDevice(device); + } + ::android::hardware::Return setAndGetVolume( + const ::android::hardware::hidl_vec& volumes, + setAndGetVolume_cb _hidl_cb) override { + return mEffect->setAndGetVolume(volumes, _hidl_cb); + } + ::android::hardware::Return volumeChangeNotification( + const ::android::hardware::hidl_vec& volumes) override { + return mEffect->volumeChangeNotification(volumes); + } + ::android::hardware::Return setAudioMode( + ::android::hardware::audio::common::V7_0::AudioMode mode) override { + return mEffect->setAudioMode(mode); + } + ::android::hardware::Return setConfigReverse( + const EffectConfig& config, + const ::android::sp& inputBufferProvider, + const ::android::sp& outputBufferProvider) override { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); + } + ::android::hardware::Return setInputDevice( + const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override { + return mEffect->setInputDevice(device); + } + ::android::hardware::Return getConfig(getConfig_cb _hidl_cb) override { + return mEffect->getConfig(_hidl_cb); + } + ::android::hardware::Return getConfigReverse(getConfigReverse_cb _hidl_cb) override { + return mEffect->getConfigReverse(_hidl_cb); + } + ::android::hardware::Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); + } + ::android::hardware::Return getAuxChannelsConfig( + getAuxChannelsConfig_cb _hidl_cb) override { + return mEffect->getAuxChannelsConfig(_hidl_cb); + } + ::android::hardware::Return setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) override { + return mEffect->setAuxChannelsConfig(config); + } + ::android::hardware::Return setAudioSource( + const ::android::hardware::hidl_string& source) override { + return mEffect->setAudioSource(source); + } + ::android::hardware::Return offload(const EffectOffloadParameter& param) override { + return mEffect->offload(param); + } + ::android::hardware::Return getDescriptor(getDescriptor_cb _hidl_cb) override { + return mEffect->getDescriptor(_hidl_cb); + } + ::android::hardware::Return prepareForProcessing( + prepareForProcessing_cb _hidl_cb) override { + return mEffect->prepareForProcessing(_hidl_cb); + } + ::android::hardware::Return setProcessBuffers(const AudioBuffer& inBuffer, + const AudioBuffer& outBuffer) override { + return mEffect->setProcessBuffers(inBuffer, outBuffer); + } + ::android::hardware::Return command(uint32_t commandId, + const ::android::hardware::hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); + } + ::android::hardware::Return setParameter( + const ::android::hardware::hidl_vec& parameter, + const ::android::hardware::hidl_vec& value) override { + return mEffect->setParameter(parameter, value); + } + ::android::hardware::Return getParameter( + const ::android::hardware::hidl_vec& parameter, uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); + } + ::android::hardware::Return getSupportedConfigsForFeature( + uint32_t featureId, uint32_t maxConfigs, uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); + } + ::android::hardware::Return getCurrentConfigForFeature( + uint32_t featureId, uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); + } + ::android::hardware::Return setCurrentConfigForFeature( + uint32_t featureId, const ::android::hardware::hidl_vec& configData) override { + return mEffect->setCurrentConfigForFeature(featureId, configData); + } + ::android::hardware::Return close() override { return mEffect->close(); } + + // Methods from ILoudnessEnhancerEffect interface. + ::android::hardware::Return setTargetGain(int32_t targetGainMb) override; + ::android::hardware::Return getTargetGain(getTargetGain_cb _hidl_cb) override; + + private: + sp mEffect; + int32_t mTargetGainMb = 0; +}; + +} // namespace android::hardware::audio::effect::V7_0::implementation diff --git a/audio/common/7.0/example/PREUPLOAD.cfg b/audio/common/7.0/example/PREUPLOAD.cfg new file mode 100644 index 0000000000..6b7fd7137c --- /dev/null +++ b/audio/common/7.0/example/PREUPLOAD.cfg @@ -0,0 +1,2 @@ +[Builtin Hooks] +clang_format = true diff --git a/audio/common/7.0/example/android.hardware.audio@7.0-service.example.rc b/audio/common/7.0/example/android.hardware.audio@7.0-service.example.rc new file mode 100644 index 0000000000..cf8b51f07b --- /dev/null +++ b/audio/common/7.0/example/android.hardware.audio@7.0-service.example.rc @@ -0,0 +1,7 @@ +service vendor.audio-hal-7-0 /vendor/bin/hw/android.hardware.audio@7.0-service.example + class hal + user audioserver + group audio + capabilities BLOCK_SUSPEND + ioprio rt 4 + task_profiles ProcessCapacityHigh HighPerformance diff --git a/audio/common/7.0/example/android.hardware.audio@7.0-service.example.xml b/audio/common/7.0/example/android.hardware.audio@7.0-service.example.xml new file mode 100644 index 0000000000..b91b0612ce --- /dev/null +++ b/audio/common/7.0/example/android.hardware.audio@7.0-service.example.xml @@ -0,0 +1,20 @@ + + + android.hardware.audio + hwbinder + 7.0 + + IDevicesFactory + example + + + + android.hardware.audio.effect + hwbinder + 7.0 + + IEffectsFactory + example + + + diff --git a/audio/common/7.0/example/service.cpp b/audio/common/7.0/example/service.cpp new file mode 100644 index 0000000000..641e2c90ae --- /dev/null +++ b/audio/common/7.0/example/service.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2020 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 "android.hardware.audio@7.0-service.example" +#include +#include + +#include "DevicesFactory.h" +#include "EffectsFactory.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using namespace android; + +status_t registerDevicesFactoryService() { + sp<::android::hardware::audio::V7_0::IDevicesFactory> devicesFactory = + new ::android::hardware::audio::V7_0::implementation::DevicesFactory(); + status_t status = devicesFactory->registerAsService("example"); + ALOGE_IF(status != OK, "Error registering devices factory as service: %d", status); + return status; +} + +status_t registerEffectsFactoryService() { + sp<::android::hardware::audio::effect::V7_0::IEffectsFactory> devicesFactory = + new ::android::hardware::audio::effect::V7_0::implementation::EffectsFactory(); + status_t status = devicesFactory->registerAsService("example"); + ALOGE_IF(status != OK, "Error registering effects factory as service: %d", status); + return status; +} + +int main() { + configureRpcThreadpool(1, true); + status_t status = registerDevicesFactoryService(); + if (status != OK) { + return status; + } + status = registerEffectsFactoryService(); + if (status != OK) { + return status; + } + joinRpcThreadpool(); + + return 1; +}