audio: Add example HAL implementation

This is partial implementation of the example V7.0 audio HAL
which passes VTS tests. Note that the 'core' part
of the HAL (IDevice/IStream) isn't implemented yet.
It passes VTS because it doesn't provide any devices
(modules) and the audio HAL isn't the 'default' instance.

Bug: 142480271
Test: atest VtsHalAudioV7_0TargetTest
      atest VtsHalAudioEffectV7_0TargetTest
Change-Id: Ie3dd62c5db1cdb5534df4dd7f326c4c8776bf3c4
This commit is contained in:
Mikhail Naganov
2020-08-11 23:23:16 +00:00
parent 108e702dc7
commit c9e1607de4
16 changed files with 1129 additions and 0 deletions

View File

@@ -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

View File

@@ -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",
],
}

View File

@@ -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 <log/log.h>
#include "DevicesFactory.h"
using ::android::hardware::hidl_string;
using ::android::hardware::Return;
using ::android::hardware::Void;
namespace android::hardware::audio::V7_0::implementation {
Return<void> DevicesFactory::openDevice(const hidl_string& device, openDevice_cb _hidl_cb) {
(void)device;
_hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
return Void();
}
Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) {
_hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
return Void();
}
} // namespace android::hardware::audio::V7_0::implementation

View File

@@ -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 <android/hardware/audio/7.0/IDevicesFactory.h>
namespace android::hardware::audio::V7_0::implementation {
class DevicesFactory : public IDevicesFactory {
public:
DevicesFactory() = default;
::android::hardware::Return<void> openDevice(const ::android::hardware::hidl_string& device,
openDevice_cb _hidl_cb) override;
::android::hardware::Return<void> openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override;
};
} // namespace android::hardware::audio::V7_0::implementation

View File

@@ -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 <log/log.h>
#include <audio_policy_configuration_V7_0.h>
#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<Result> Effect::init() {
return Result::OK;
}
Return<Result> Effect::setConfig(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) {
(void)config;
(void)inputBufferProvider;
(void)outputBufferProvider;
return Result::OK;
}
Return<Result> Effect::reset() {
return Result::OK;
}
Return<Result> Effect::enable() {
if (!mEnabled) {
mEnabled = true;
return Result::OK;
} else {
return Result::NOT_SUPPORTED;
}
}
Return<Result> Effect::disable() {
if (mEnabled) {
mEnabled = false;
return Result::OK;
} else {
return Result::NOT_SUPPORTED;
}
}
Return<Result> Effect::setDevice(const DeviceAddress& device) {
(void)device;
return Result::OK;
}
Return<void> Effect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) {
(void)volumes;
_hidl_cb(Result::OK, hidl_vec<uint32_t>{});
return Void();
}
Return<Result> Effect::volumeChangeNotification(const hidl_vec<uint32_t>& volumes) {
(void)volumes;
return Result::OK;
}
Return<Result> Effect::setAudioMode(AudioMode mode) {
(void)mode;
return Result::OK;
}
Return<Result> Effect::setConfigReverse(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) {
(void)config;
(void)inputBufferProvider;
(void)outputBufferProvider;
return Result::OK;
}
Return<Result> Effect::setInputDevice(const DeviceAddress& device) {
(void)device;
return Result::OK;
}
Return<void> 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<void> Effect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
_hidl_cb(Result::OK, EffectConfig{});
return Void();
}
Return<void> Effect::getSupportedAuxChannelsConfigs(uint32_t maxConfigs,
getSupportedAuxChannelsConfigs_cb _hidl_cb) {
(void)maxConfigs;
_hidl_cb(Result::OK, hidl_vec<EffectAuxChannelsConfig>{});
return Void();
}
Return<void> Effect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
_hidl_cb(Result::OK, EffectAuxChannelsConfig{});
return Void();
}
Return<Result> Effect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) {
(void)config;
return Result::OK;
}
Return<Result> Effect::setAudioSource(const hidl_string& source) {
(void)source;
return Result::OK;
}
Return<Result> Effect::offload(const EffectOffloadParameter& param) {
(void)param;
return Result::OK;
}
Return<void> Effect::getDescriptor(getDescriptor_cb _hidl_cb) {
_hidl_cb(Result::OK, mDescriptor);
return Void();
}
Return<void> Effect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
_hidl_cb(Result::OK, MQDescriptor<Result, kSynchronizedReadWrite>{});
return Void();
}
Return<Result> Effect::setProcessBuffers(const AudioBuffer& inBuffer,
const AudioBuffer& outBuffer) {
(void)inBuffer;
(void)outBuffer;
return Result::OK;
}
Return<void> Effect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
uint32_t resultMaxSize, command_cb _hidl_cb) {
(void)commandId;
(void)data;
(void)resultMaxSize;
_hidl_cb(-EINVAL, hidl_vec<uint8_t>{});
return Void();
}
Return<Result> Effect::setParameter(const hidl_vec<uint8_t>& parameter,
const hidl_vec<uint8_t>& value) {
(void)parameter;
(void)value;
return Result::OK;
}
Return<void> Effect::getParameter(const hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
getParameter_cb _hidl_cb) {
(void)parameter;
(void)valueMaxSize;
_hidl_cb(Result::OK, hidl_vec<uint8_t>{});
return Void();
}
Return<void> 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<uint8_t>{});
return Void();
}
Return<void> Effect::getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize,
getCurrentConfigForFeature_cb _hidl_cb) {
(void)featureId;
(void)configSize;
_hidl_cb(Result::OK, hidl_vec<uint8_t>{});
return Void();
}
Return<Result> Effect::setCurrentConfigForFeature(uint32_t featureId,
const hidl_vec<uint8_t>& configData) {
(void)featureId;
(void)configData;
return Result::OK;
}
Return<Result> Effect::close() {
return Result::OK;
}
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <android/hardware/audio/effect/7.0/IEffect.h>
namespace android::hardware::audio::effect::V7_0::implementation {
class Effect : public IEffect {
public:
explicit Effect(const EffectDescriptor& descriptor) : mDescriptor(descriptor) {}
::android::hardware::Return<Result> init() override;
::android::hardware::Return<Result> setConfig(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
::android::hardware::Return<Result> reset() override;
::android::hardware::Return<Result> enable() override;
::android::hardware::Return<Result> disable() override;
::android::hardware::Return<Result> setDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override;
::android::hardware::Return<void> setAndGetVolume(
const ::android::hardware::hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override;
::android::hardware::Return<Result> volumeChangeNotification(
const ::android::hardware::hidl_vec<uint32_t>& volumes) override;
::android::hardware::Return<Result> setAudioMode(
::android::hardware::audio::common::V7_0::AudioMode mode) override;
::android::hardware::Return<Result> setConfigReverse(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
::android::hardware::Return<Result> setInputDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override;
::android::hardware::Return<void> getConfig(getConfig_cb _hidl_cb) override;
::android::hardware::Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
::android::hardware::Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
::android::hardware::Return<void> getAuxChannelsConfig(
getAuxChannelsConfig_cb _hidl_cb) override;
::android::hardware::Return<Result> setAuxChannelsConfig(
const EffectAuxChannelsConfig& config) override;
::android::hardware::Return<Result> setAudioSource(
const ::android::hardware::hidl_string& source) override;
::android::hardware::Return<Result> offload(const EffectOffloadParameter& param) override;
::android::hardware::Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
::android::hardware::Return<void> prepareForProcessing(
prepareForProcessing_cb _hidl_cb) override;
::android::hardware::Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
const AudioBuffer& outBuffer) override;
::android::hardware::Return<void> command(uint32_t commandId,
const ::android::hardware::hidl_vec<uint8_t>& data,
uint32_t resultMaxSize, command_cb _hidl_cb) override;
::android::hardware::Return<Result> setParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter,
const ::android::hardware::hidl_vec<uint8_t>& value) override;
::android::hardware::Return<void> getParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
getParameter_cb _hidl_cb) override;
::android::hardware::Return<void> getSupportedConfigsForFeature(
uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
getSupportedConfigsForFeature_cb _hidl_cb) override;
::android::hardware::Return<void> getCurrentConfigForFeature(
uint32_t featureId, uint32_t configSize,
getCurrentConfigForFeature_cb _hidl_cb) override;
::android::hardware::Return<Result> setCurrentConfigForFeature(
uint32_t featureId, const ::android::hardware::hidl_vec<uint8_t>& configData) override;
::android::hardware::Return<Result> close() override;
private:
const EffectDescriptor mDescriptor;
bool mEnabled = false;
};
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <log/log.h>
#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<void> EffectsFactory::getAllDescriptors(getAllDescriptors_cb _hidl_cb) {
hidl_vec<EffectDescriptor> descriptors;
descriptors.resize(2);
descriptors[0] = EqualizerEffect::getDescriptor();
descriptors[1] = LoudnessEnhancerEffect::getDescriptor();
_hidl_cb(Result::OK, descriptors);
return Void();
}
Return<void> 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<void> 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<void> EffectsFactory::debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) {
(void)fd;
(void)options;
return Void();
}
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <android/hardware/audio/effect/7.0/IEffectsFactory.h>
namespace android::hardware::audio::effect::V7_0::implementation {
class EffectsFactory : public IEffectsFactory {
public:
EffectsFactory() = default;
::android::hardware::Return<void> getAllDescriptors(getAllDescriptors_cb _hidl_cb) override;
::android::hardware::Return<void> getDescriptor(
const ::android::hardware::audio::common::V7_0::Uuid& uuid,
getDescriptor_cb _hidl_cb) override;
::android::hardware::Return<void> 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<void>
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

View File

@@ -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 <limits>
#define LOG_TAG "EffectsFactory7.0"
#include <log/log.h>
#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<uint8_t, 6>{{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}},
.uuid = {0, 0, 0, 1, std::array<uint8_t, 6>{{0, 0, 0, 0, 0, 0}}}};
return descriptor;
}
EqualizerEffect::EqualizerEffect() : mEffect(new Effect(getDescriptor())) {
mProperties.bandLevels.resize(kNumBands);
}
Return<void> EqualizerEffect::getNumBands(getNumBands_cb _hidl_cb) {
_hidl_cb(Result::OK, kNumBands);
return Void();
}
Return<void> EqualizerEffect::getLevelRange(getLevelRange_cb _hidl_cb) {
_hidl_cb(Result::OK, std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max());
return Void();
}
Return<Result> EqualizerEffect::setBandLevel(uint16_t band, int16_t level) {
if (band < kNumBands) {
mProperties.bandLevels[band] = level;
return Result::OK;
} else {
return Result::INVALID_ARGUMENTS;
}
}
Return<void> 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<void> EqualizerEffect::getBandCenterFrequency(uint16_t band,
getBandCenterFrequency_cb _hidl_cb) {
(void)band;
_hidl_cb(Result::OK, 0);
return Void();
}
Return<void> EqualizerEffect::getBandFrequencyRange(uint16_t band,
getBandFrequencyRange_cb _hidl_cb) {
(void)band;
_hidl_cb(Result::OK, 0, 1);
return Void();
}
Return<void> EqualizerEffect::getBandForFrequency(uint32_t freq, getBandForFrequency_cb _hidl_cb) {
(void)freq;
_hidl_cb(Result::OK, 0);
return Void();
}
Return<void> EqualizerEffect::getPresetNames(getPresetNames_cb _hidl_cb) {
hidl_vec<hidl_string> presetNames;
presetNames.resize(kNumPresets);
presetNames[0] = "default";
_hidl_cb(Result::OK, presetNames);
return Void();
}
Return<Result> EqualizerEffect::setCurrentPreset(uint16_t preset) {
if (preset < kNumPresets) {
mProperties.curPreset = preset;
return Result::OK;
} else {
return Result::INVALID_ARGUMENTS;
}
}
Return<void> EqualizerEffect::getCurrentPreset(getCurrentPreset_cb _hidl_cb) {
_hidl_cb(Result::OK, mProperties.curPreset);
return Void();
}
Return<Result> EqualizerEffect::setAllProperties(
const IEqualizerEffect::AllProperties& properties) {
mProperties = properties;
return Result::OK;
}
Return<void> EqualizerEffect::getAllProperties(getAllProperties_cb _hidl_cb) {
_hidl_cb(Result::OK, mProperties);
return Void();
}
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <android/hardware/audio/effect/7.0/IEqualizerEffect.h>
#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<Result> init() override { return mEffect->init(); }
::android::hardware::Return<Result> setConfig(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override {
return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
}
::android::hardware::Return<Result> reset() override { return mEffect->reset(); }
::android::hardware::Return<Result> enable() override { return mEffect->enable(); }
::android::hardware::Return<Result> disable() override { return mEffect->disable(); }
::android::hardware::Return<Result> setDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override {
return mEffect->setDevice(device);
}
::android::hardware::Return<void> setAndGetVolume(
const ::android::hardware::hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
}
::android::hardware::Return<Result> volumeChangeNotification(
const ::android::hardware::hidl_vec<uint32_t>& volumes) override {
return mEffect->volumeChangeNotification(volumes);
}
::android::hardware::Return<Result> setAudioMode(
::android::hardware::audio::common::V7_0::AudioMode mode) override {
return mEffect->setAudioMode(mode);
}
::android::hardware::Return<Result> setConfigReverse(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override {
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
::android::hardware::Return<Result> setInputDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override {
return mEffect->setInputDevice(device);
}
::android::hardware::Return<void> getConfig(getConfig_cb _hidl_cb) override {
return mEffect->getConfig(_hidl_cb);
}
::android::hardware::Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override {
return mEffect->getConfigReverse(_hidl_cb);
}
::android::hardware::Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override {
return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
}
::android::hardware::Return<void> getAuxChannelsConfig(
getAuxChannelsConfig_cb _hidl_cb) override {
return mEffect->getAuxChannelsConfig(_hidl_cb);
}
::android::hardware::Return<Result> setAuxChannelsConfig(
const EffectAuxChannelsConfig& config) override {
return mEffect->setAuxChannelsConfig(config);
}
::android::hardware::Return<Result> setAudioSource(
const ::android::hardware::hidl_string& source) override {
return mEffect->setAudioSource(source);
}
::android::hardware::Return<Result> offload(const EffectOffloadParameter& param) override {
return mEffect->offload(param);
}
::android::hardware::Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override {
return mEffect->getDescriptor(_hidl_cb);
}
::android::hardware::Return<void> prepareForProcessing(
prepareForProcessing_cb _hidl_cb) override {
return mEffect->prepareForProcessing(_hidl_cb);
}
::android::hardware::Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
const AudioBuffer& outBuffer) override {
return mEffect->setProcessBuffers(inBuffer, outBuffer);
}
::android::hardware::Return<void> command(uint32_t commandId,
const ::android::hardware::hidl_vec<uint8_t>& data,
uint32_t resultMaxSize,
command_cb _hidl_cb) override {
return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
}
::android::hardware::Return<Result> setParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter,
const ::android::hardware::hidl_vec<uint8_t>& value) override {
return mEffect->setParameter(parameter, value);
}
::android::hardware::Return<void> getParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
getParameter_cb _hidl_cb) override {
return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
}
::android::hardware::Return<void> 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<void> getCurrentConfigForFeature(
uint32_t featureId, uint32_t configSize,
getCurrentConfigForFeature_cb _hidl_cb) override {
return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
}
::android::hardware::Return<Result> setCurrentConfigForFeature(
uint32_t featureId, const ::android::hardware::hidl_vec<uint8_t>& configData) override {
return mEffect->setCurrentConfigForFeature(featureId, configData);
}
::android::hardware::Return<Result> close() override { return mEffect->close(); }
// Methods from IEqualizerEffect interface.
::android::hardware::Return<void> getNumBands(getNumBands_cb _hidl_cb) override;
::android::hardware::Return<void> getLevelRange(getLevelRange_cb _hidl_cb) override;
::android::hardware::Return<Result> setBandLevel(uint16_t band, int16_t level) override;
::android::hardware::Return<void> getBandLevel(uint16_t band,
getBandLevel_cb _hidl_cb) override;
::android::hardware::Return<void> getBandCenterFrequency(
uint16_t band, getBandCenterFrequency_cb _hidl_cb) override;
::android::hardware::Return<void> getBandFrequencyRange(
uint16_t band, getBandFrequencyRange_cb _hidl_cb) override;
::android::hardware::Return<void> getBandForFrequency(uint32_t freq,
getBandForFrequency_cb _hidl_cb) override;
::android::hardware::Return<void> getPresetNames(getPresetNames_cb _hidl_cb) override;
::android::hardware::Return<Result> setCurrentPreset(uint16_t preset) override;
::android::hardware::Return<void> getCurrentPreset(getCurrentPreset_cb _hidl_cb) override;
::android::hardware::Return<Result> setAllProperties(
const IEqualizerEffect::AllProperties& properties) override;
::android::hardware::Return<void> getAllProperties(getAllProperties_cb _hidl_cb) override;
private:
static constexpr size_t kNumBands = 1;
static constexpr size_t kNumPresets = 1;
sp<Effect> mEffect;
IEqualizerEffect::AllProperties mProperties{};
};
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <log/log.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 {
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<uint8_t, 6>{{0x11, 0x26, 0x0e, 0xb6, 0x3c, 0xf1}}},
.uuid = {0, 0, 0, 2, std::array<uint8_t, 6>{{0, 0, 0, 0, 0, 0}}}};
return descriptor;
} // namespace android::hardware::audio::effect::V7_0::implementation
LoudnessEnhancerEffect::LoudnessEnhancerEffect() : mEffect(new Effect(getDescriptor())) {}
Return<Result> LoudnessEnhancerEffect::setTargetGain(int32_t targetGainMb) {
mTargetGainMb = targetGainMb;
return Result::OK;
}
Return<void> LoudnessEnhancerEffect::getTargetGain(getTargetGain_cb _hidl_cb) {
_hidl_cb(Result::OK, mTargetGainMb);
return Void();
}
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -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 <android/hardware/audio/effect/7.0/ILoudnessEnhancerEffect.h>
#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<Result> init() override { return mEffect->init(); }
::android::hardware::Return<Result> setConfig(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override {
return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
}
::android::hardware::Return<Result> reset() override { return mEffect->reset(); }
::android::hardware::Return<Result> enable() override { return mEffect->enable(); }
::android::hardware::Return<Result> disable() override { return mEffect->disable(); }
::android::hardware::Return<Result> setDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override {
return mEffect->setDevice(device);
}
::android::hardware::Return<void> setAndGetVolume(
const ::android::hardware::hidl_vec<uint32_t>& volumes,
setAndGetVolume_cb _hidl_cb) override {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
}
::android::hardware::Return<Result> volumeChangeNotification(
const ::android::hardware::hidl_vec<uint32_t>& volumes) override {
return mEffect->volumeChangeNotification(volumes);
}
::android::hardware::Return<Result> setAudioMode(
::android::hardware::audio::common::V7_0::AudioMode mode) override {
return mEffect->setAudioMode(mode);
}
::android::hardware::Return<Result> setConfigReverse(
const EffectConfig& config,
const ::android::sp<IEffectBufferProviderCallback>& inputBufferProvider,
const ::android::sp<IEffectBufferProviderCallback>& outputBufferProvider) override {
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
::android::hardware::Return<Result> setInputDevice(
const ::android::hardware::audio::common::V7_0::DeviceAddress& device) override {
return mEffect->setInputDevice(device);
}
::android::hardware::Return<void> getConfig(getConfig_cb _hidl_cb) override {
return mEffect->getConfig(_hidl_cb);
}
::android::hardware::Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override {
return mEffect->getConfigReverse(_hidl_cb);
}
::android::hardware::Return<void> getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override {
return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
}
::android::hardware::Return<void> getAuxChannelsConfig(
getAuxChannelsConfig_cb _hidl_cb) override {
return mEffect->getAuxChannelsConfig(_hidl_cb);
}
::android::hardware::Return<Result> setAuxChannelsConfig(
const EffectAuxChannelsConfig& config) override {
return mEffect->setAuxChannelsConfig(config);
}
::android::hardware::Return<Result> setAudioSource(
const ::android::hardware::hidl_string& source) override {
return mEffect->setAudioSource(source);
}
::android::hardware::Return<Result> offload(const EffectOffloadParameter& param) override {
return mEffect->offload(param);
}
::android::hardware::Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override {
return mEffect->getDescriptor(_hidl_cb);
}
::android::hardware::Return<void> prepareForProcessing(
prepareForProcessing_cb _hidl_cb) override {
return mEffect->prepareForProcessing(_hidl_cb);
}
::android::hardware::Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
const AudioBuffer& outBuffer) override {
return mEffect->setProcessBuffers(inBuffer, outBuffer);
}
::android::hardware::Return<void> command(uint32_t commandId,
const ::android::hardware::hidl_vec<uint8_t>& data,
uint32_t resultMaxSize,
command_cb _hidl_cb) override {
return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
}
::android::hardware::Return<Result> setParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter,
const ::android::hardware::hidl_vec<uint8_t>& value) override {
return mEffect->setParameter(parameter, value);
}
::android::hardware::Return<void> getParameter(
const ::android::hardware::hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
getParameter_cb _hidl_cb) override {
return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
}
::android::hardware::Return<void> 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<void> getCurrentConfigForFeature(
uint32_t featureId, uint32_t configSize,
getCurrentConfigForFeature_cb _hidl_cb) override {
return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
}
::android::hardware::Return<Result> setCurrentConfigForFeature(
uint32_t featureId, const ::android::hardware::hidl_vec<uint8_t>& configData) override {
return mEffect->setCurrentConfigForFeature(featureId, configData);
}
::android::hardware::Return<Result> close() override { return mEffect->close(); }
// Methods from ILoudnessEnhancerEffect interface.
::android::hardware::Return<Result> setTargetGain(int32_t targetGainMb) override;
::android::hardware::Return<void> getTargetGain(getTargetGain_cb _hidl_cb) override;
private:
sp<Effect> mEffect;
int32_t mTargetGainMb = 0;
};
} // namespace android::hardware::audio::effect::V7_0::implementation

View File

@@ -0,0 +1,2 @@
[Builtin Hooks]
clang_format = true

View File

@@ -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

View File

@@ -0,0 +1,20 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.audio</name>
<transport>hwbinder</transport>
<version>7.0</version>
<interface>
<name>IDevicesFactory</name>
<instance>example</instance>
</interface>
</hal>
<hal format="hidl">
<name>android.hardware.audio.effect</name>
<transport>hwbinder</transport>
<version>7.0</version>
<interface>
<name>IEffectsFactory</name>
<instance>example</instance>
</interface>
</hal>
</manifest>

View File

@@ -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 <hidl/HidlTransportSupport.h>
#include <log/log.h>
#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;
}