Audio V4: Split HAL wrapper for versioning

Both core and effect Hal now have one single point of entry.
This point of entry is their respective factories:
 - DevicesFactoryHalInterface::create
 - EffectsFactoryHalInterface::create

Each entry point looks for their respective services supported
version, starting from the highest (currently only 2.0) and
returning the subclass wrapping this version to the most recent audio.h
framework api.

Note that EffectBufferHalInterface were previously created from static
methods (mirror and allocate) which broke the single point of entry
requirement.
As a result, buffers have now to be created from the factory like the
other classes.

Note that the death handler also need to be its own library as it is
used by versioned code and is version independent.

Bug: 38184704
Test: compile
Change-Id: Iac9b1fda561bb486193d5b9e025a870f50cda530
Signed-off-by: Kevin Rocard <krocard@google.com>
gugelfrei
Kevin Rocard 7 years ago
parent 51ac542df4
commit 7588ff418a

@ -1,5 +1,5 @@
cc_library_shared {
name: "libaudiohal",
name: "libaudiohal@2.0",
srcs: [
"DeviceHalLocal.cpp",
@ -8,7 +8,6 @@ cc_library_shared {
"StreamHalLocal.cpp",
"ConversionHelperHidl.cpp",
"HalDeathHandlerHidl.cpp",
"DeviceHalHidl.cpp",
"DevicesFactoryHalHidl.cpp",
"EffectBufferHalHidl.cpp",
@ -17,12 +16,14 @@ cc_library_shared {
"StreamHalHidl.cpp",
],
export_include_dirs: ["."],
cflags: [
"-Wall",
"-Werror",
],
shared_libs: [
"libaudiohal_deathhandler",
"libaudioutils",
"libcutils",
"liblog",
@ -46,4 +47,8 @@ cc_library_shared {
header_libs: [
"libaudiohal_headers"
],
export_shared_lib_headers: [
"libfmq",
],
}

@ -23,11 +23,6 @@
namespace android {
// static
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
return new DevicesFactoryHalHybrid();
}
DevicesFactoryHalHybrid::DevicesFactoryHalHybrid()
: mLocalFactory(new DevicesFactoryHalLocal()),
mHidlFactory(new DevicesFactoryHalHidl()) {

@ -37,14 +37,12 @@ uint64_t EffectBufferHalHidl::makeUniqueId() {
return counter++;
}
// static
status_t EffectBufferHalInterface::allocate(
status_t EffectBufferHalHidl::allocate(
size_t size, sp<EffectBufferHalInterface>* buffer) {
return mirror(nullptr, size, buffer);
}
// static
status_t EffectBufferHalInterface::mirror(
status_t EffectBufferHalHidl::mirror(
void* external, size_t size, sp<EffectBufferHalInterface>* buffer) {
sp<EffectBufferHalInterface> tempBuffer = new EffectBufferHalHidl(size);
status_t result = static_cast<EffectBufferHalHidl*>(tempBuffer.get())->init();

@ -32,6 +32,9 @@ namespace android {
class EffectBufferHalHidl : public EffectBufferHalInterface
{
public:
static status_t allocate(size_t size, sp<EffectBufferHalInterface>* buffer);
static status_t mirror(void* external, size_t size, sp<EffectBufferHalInterface>* buffer);
virtual audio_buffer_t* audioBuffer();
virtual void* externalData() const;

@ -20,6 +20,7 @@
#include <cutils/native_handle.h>
#include "ConversionHelperHidl.h"
#include "EffectBufferHalHidl.h"
#include "EffectHalHidl.h"
#include "EffectsFactoryHalHidl.h"
#include "HidlUtils.h"
@ -32,16 +33,6 @@ using ::android::hardware::Return;
namespace android {
// static
sp<EffectsFactoryHalInterface> EffectsFactoryHalInterface::create() {
return new EffectsFactoryHalHidl();
}
// static
bool EffectsFactoryHalInterface::isNullUuid(const effect_uuid_t *pEffectUuid) {
return memcmp(pEffectUuid, EFFECT_UUID_NULL, sizeof(effect_uuid_t)) == 0;
}
EffectsFactoryHalHidl::EffectsFactoryHalHidl() : ConversionHelperHidl("EffectsFactory") {
mEffectsFactory = IEffectsFactory::getService();
if (mEffectsFactory == 0) {
@ -146,4 +137,14 @@ status_t EffectsFactoryHalHidl::dumpEffects(int fd) {
return processReturn(__FUNCTION__, ret);
}
status_t EffectsFactoryHalHidl::allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) {
return EffectBufferHalHidl::allocate(size, buffer);
}
status_t EffectsFactoryHalHidl::mirrorBuffer(void* external, size_t size,
sp<EffectBufferHalInterface>* buffer) {
return EffectBufferHalHidl::mirror(external, size, buffer);
}
} // namespace android

@ -21,6 +21,8 @@
#include <android/hardware/audio/effect/2.0/types.h>
#include <media/audiohal/EffectsFactoryHalInterface.h>
#include "ConversionHelperHidl.h"
namespace android {
using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
@ -49,6 +51,10 @@ class EffectsFactoryHalHidl : public EffectsFactoryHalInterface, public Conversi
virtual status_t dumpEffects(int fd);
status_t allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override;
status_t mirrorBuffer(void* external, size_t size,
sp<EffectBufferHalInterface>* buffer) override;
private:
friend class EffectsFactoryHalInterface;

@ -1,3 +1,51 @@
cc_library_shared {
name: "libaudiohal",
srcs: [
"DevicesFactoryHalInterface.cpp",
"EffectsFactoryHalInterface.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
shared_libs: [
"android.hardware.audio@2.0",
"android.hardware.audio.effect@2.0",
"libaudiohal@2.0",
"libutils",
],
header_libs: [
"libaudiohal_headers"
]
}
cc_library_shared {
name: "libaudiohal_deathhandler",
srcs: [
"HalDeathHandlerHidl.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
shared_libs: [
"libhidlbase",
"libutils",
"liblog",
],
header_libs: [
"libaudiohal_headers"
]
}
cc_library_headers {
name: "libaudiohal_headers",

@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 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 "DevicesFactoryHalHybrid.h"
#include <android/hardware/audio/2.0/IDevicesFactory.h>
using namespace ::android::hardware::audio;
namespace android {
// static
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
if (V2_0::IDevicesFactory::getService() != nullptr) {
return new DevicesFactoryHalHybrid();
}
return nullptr;
}
} // namespace android

@ -0,0 +1,42 @@
/*
* Copyright (C) 2016 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 "EffectsFactoryHalHidl"
//#define LOG_NDEBUG 0
#include "EffectHalHidl.h"
#include "EffectsFactoryHalHidl.h"
using ::android::hardware::Return;
using namespace ::android::hardware::audio::effect;
namespace android {
// static
sp<EffectsFactoryHalInterface> EffectsFactoryHalInterface::create() {
if (V2_0::IEffectsFactory::getService() != nullptr) {
return new EffectsFactoryHalHidl();
}
return nullptr;
}
// static
bool EffectsFactoryHalInterface::isNullUuid(const effect_uuid_t *pEffectUuid) {
return memcmp(pEffectUuid, EFFECT_UUID_NULL, sizeof(effect_uuid_t)) == 0;
}
} // namespace android

@ -26,6 +26,7 @@ namespace android {
// Abstraction for an audio buffer. It may be a "mirror" for
// a buffer that the effect chain doesn't own, or a buffer owned by
// the effect chain.
// Buffers are created from EffectsFactoryHalInterface
class EffectBufferHalInterface : public RefBase
{
public:
@ -49,9 +50,6 @@ class EffectBufferHalInterface : public RefBase
virtual void update(size_t size) = 0; // copies partial data from external buffer
virtual void commit(size_t size) = 0; // copies partial data to external buffer
static status_t allocate(size_t size, sp<EffectBufferHalInterface>* buffer);
static status_t mirror(void* external, size_t size, sp<EffectBufferHalInterface>* buffer);
protected:
// Subclasses can not be constructed directly by clients.
EffectBufferHalInterface() {}

@ -48,6 +48,10 @@ class EffectsFactoryHalInterface : public RefBase
static sp<EffectsFactoryHalInterface> create();
virtual status_t allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) = 0;
virtual status_t mirrorBuffer(void* external, size_t size,
sp<EffectBufferHalInterface>* buffer) = 0;
// Helper function to compare effect uuid to EFFECT_UUID_NULL.
static bool isNullUuid(const effect_uuid_t *pEffectUuid);

@ -183,7 +183,7 @@ DownmixerBufferProvider::DownmixerBufferProvider(
mOutFrameSize =
audio_bytes_per_sample(format) * audio_channel_count_from_out_mask(outputChannelMask);
status_t status;
status = EffectBufferHalInterface::mirror(
status = mEffectsFactory->mirrorBuffer(
nullptr, mInFrameSize * bufferFrameCount, &mInBuffer);
if (status != 0) {
ALOGE("DownmixerBufferProvider() error %d while creating input buffer", status);
@ -191,7 +191,7 @@ DownmixerBufferProvider::DownmixerBufferProvider(
mEffectsFactory.clear();
return;
}
status = EffectBufferHalInterface::mirror(
status = mEffectsFactory->mirrorBuffer(
nullptr, mOutFrameSize * bufferFrameCount, &mOutBuffer);
if (status != 0) {
ALOGE("DownmixerBufferProvider() error %d while creating output buffer", status);

@ -1027,7 +1027,9 @@ void AudioFlinger::EffectModule::setInBuffer(const sp<EffectBufferHalInterface>&
|| size > mInConversionBuffer->getSize())) {
mInConversionBuffer.clear();
ALOGV("%s: allocating mInConversionBuffer %zu", __func__, size);
(void)EffectBufferHalInterface::allocate(size, &mInConversionBuffer);
sp<AudioFlinger> audioFlinger = mAudioFlinger.promote();
LOG_ALWAYS_FATAL_IF(audioFlinger == nullptr, "EM could not retrieved audioFlinger");
(void)audioFlinger->mEffectsFactoryHal->allocateBuffer(size, &mInConversionBuffer);
}
if (mInConversionBuffer.get() != nullptr) {
mInConversionBuffer->setFrameCount(inFrameCount);
@ -1071,7 +1073,9 @@ void AudioFlinger::EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>
|| size > mOutConversionBuffer->getSize())) {
mOutConversionBuffer.clear();
ALOGV("%s: allocating mOutConversionBuffer %zu", __func__, size);
(void)EffectBufferHalInterface::allocate(size, &mOutConversionBuffer);
sp<AudioFlinger> audioFlinger = mAudioFlinger.promote();
LOG_ALWAYS_FATAL_IF(audioFlinger == nullptr, "EM could not retrieved audioFlinger");
(void)audioFlinger->mEffectsFactoryHal->allocateBuffer(size, &mOutConversionBuffer);
}
if (mOutConversionBuffer.get() != nullptr) {
mOutConversionBuffer->setFrameCount(outFrameCount);
@ -2020,10 +2024,10 @@ status_t AudioFlinger::EffectChain::addEffect_ll(const sp<EffectModule>& effect)
size_t numSamples = thread->frameCount();
sp<EffectBufferHalInterface> halBuffer;
#ifdef FLOAT_EFFECT_CHAIN
status_t result = EffectBufferHalInterface::allocate(
status_t result = thread->mAudioFlinger->mEffectsFactoryHal->allocateBuffer(
numSamples * sizeof(float), &halBuffer);
#else
status_t result = EffectBufferHalInterface::allocate(
status_t result = thread->mAudioFlinger->mEffectsFactoryHal->allocateBuffer(
numSamples * sizeof(int32_t), &halBuffer);
#endif
if (result != OK) return result;

@ -56,6 +56,8 @@
#include <powermanager/PowerManager.h>
#include <media/audiohal/EffectsFactoryHalInterface.h>
#include "AudioFlinger.h"
#include "FastMixer.h"
#include "FastCapture.h"
@ -2882,7 +2884,7 @@ status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp<EffectChain>& c
{
audio_session_t session = chain->sessionId();
sp<EffectBufferHalInterface> halInBuffer, halOutBuffer;
status_t result = EffectBufferHalInterface::mirror(
status_t result = mAudioFlinger->mEffectsFactoryHal->mirrorBuffer(
mEffectBufferEnabled ? mEffectBuffer : mSinkBuffer,
mEffectBufferEnabled ? mEffectBufferSize : mSinkBufferSize,
&halInBuffer);
@ -2895,7 +2897,7 @@ status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp<EffectChain>& c
// the sink buffer as input
if (mType != DIRECT) {
size_t numSamples = mNormalFrameCount * mChannelCount;
status_t result = EffectBufferHalInterface::allocate(
status_t result = mAudioFlinger->mEffectsFactoryHal->allocateBuffer(
numSamples * sizeof(effect_buffer_t),
&halInBuffer);
if (result != OK) return result;

@ -53,6 +53,7 @@ LOCAL_SHARED_LIBRARIES += \
libhidltransport \
libbase \
libaudiohal \
libaudiohal_deathhandler \
android.hardware.soundtrigger@2.0 \
android.hardware.soundtrigger@2.1 \
android.hardware.audio.common@2.0 \

Loading…
Cancel
Save