Align LibAudioHal V2 and V4 for factorisation
In order to merge the two version, they must first align as much
as possible.
Test: playback music, assistant
Change-Id: If517cc3f4646a224af3e9b3d42b68a75f1801b39
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/media/libaudiohal/2.0/Android.bp b/media/libaudiohal/2.0/Android.bp
index 574b435..29a32af 100644
--- a/media/libaudiohal/2.0/Android.bp
+++ b/media/libaudiohal/2.0/Android.bp
@@ -1,5 +1,5 @@
-cc_library_shared {
- name: "libaudiohal@2.0",
+cc_defaults {
+ name: "libaudiohal@2.0_default",
srcs: [
"DeviceHalLocal.cpp",
@@ -16,15 +16,17 @@
"StreamHalHidl.cpp",
],
- export_include_dirs: ["."],
+ export_include_dirs: ["include"],
cflags: [
"-Wall",
+ "-Wextra",
"-Werror",
],
shared_libs: [
"libaudiohal_deathhandler",
"libaudioutils",
+ "libbinder",
"libcutils",
"liblog",
"libutils",
@@ -35,16 +37,14 @@
"libhidlbase",
"libhidlmemory",
"libhidltransport",
- "android.hardware.audio@2.0",
- "android.hardware.audio.common@2.0",
- "android.hardware.audio.common@2.0-util",
- "android.hardware.audio.effect@2.0",
+ "android.hardware.audio.common-util",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"libmedia_helper",
"libmediautils",
],
header_libs: [
+ "android.hardware.audio.common.util@all-versions",
"libaudiohal_headers"
],
@@ -52,3 +52,14 @@
"libfmq",
],
}
+
+cc_library_shared {
+ name: "libaudiohal@2.0",
+ defaults: ["libaudiohal@2.0_default"],
+ shared_libs: [
+ "android.hardware.audio@2.0",
+ "android.hardware.audio.common@2.0",
+ "android.hardware.audio.common@2.0-util",
+ "android.hardware.audio.effect@2.0",
+ ],
+}
diff --git a/media/libaudiohal/2.0/ConversionHelperHidl.cpp b/media/libaudiohal/2.0/ConversionHelperHidl.cpp
index f60bf8b..b7209e0 100644
--- a/media/libaudiohal/2.0/ConversionHelperHidl.cpp
+++ b/media/libaudiohal/2.0/ConversionHelperHidl.cpp
@@ -25,6 +25,7 @@
using ::android::hardware::audio::V2_0::Result;
namespace android {
+namespace V2_0 {
// static
status_t ConversionHelperHidl::keysFromHal(const String8& keys, hidl_vec<hidl_string> *hidlKeys) {
@@ -100,4 +101,5 @@
ALOGE("%s %p %s: %s (from rpc)", mClassName, this, funcName, description);
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/ConversionHelperHidl.h b/media/libaudiohal/2.0/ConversionHelperHidl.h
index c356f37..593afb1 100644
--- a/media/libaudiohal/2.0/ConversionHelperHidl.h
+++ b/media/libaudiohal/2.0/ConversionHelperHidl.h
@@ -19,14 +19,17 @@
#include <android/hardware/audio/2.0/types.h>
#include <hidl/HidlSupport.h>
+#include <system/audio.h>
#include <utils/String8.h>
using ::android::hardware::audio::V2_0::ParameterValue;
+using CoreResult = ::android::hardware::audio::V2_0::Result;
using ::android::hardware::Return;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
namespace android {
+namespace V2_0 {
class ConversionHelperHidl {
protected:
@@ -54,7 +57,7 @@
return ret.isOk() ? OK : FAILED_TRANSACTION;
}
- status_t processReturn(const char* funcName, const Return<hardware::audio::V2_0::Result>& ret) {
+ status_t processReturn(const char* funcName, const Return<CoreResult>& ret) {
if (!ret.isOk()) {
emitError(funcName, ret.description().c_str());
}
@@ -63,7 +66,7 @@
template<typename T>
status_t processReturn(
- const char* funcName, const Return<T>& ret, hardware::audio::V2_0::Result retval) {
+ const char* funcName, const Return<T>& ret, CoreResult retval) {
if (!ret.isOk()) {
emitError(funcName, ret.description().c_str());
}
@@ -73,11 +76,12 @@
private:
const char* mClassName;
- static status_t analyzeResult(const hardware::audio::V2_0::Result& result);
+ static status_t analyzeResult(const CoreResult& result);
void emitError(const char* funcName, const char* description);
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_CONVERSION_HELPER_HIDL_H
diff --git a/media/libaudiohal/2.0/DeviceHalHidl.cpp b/media/libaudiohal/2.0/DeviceHalHidl.cpp
index 5b99d70..a79cedd 100644
--- a/media/libaudiohal/2.0/DeviceHalHidl.cpp
+++ b/media/libaudiohal/2.0/DeviceHalHidl.cpp
@@ -24,9 +24,12 @@
#include <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
+#include <common/all-versions/VersionUtils.h>
+
#include "DeviceHalHidl.h"
#include "HidlUtils.h"
#include "StreamHalHidl.h"
+#include "VersionUtils.h"
using ::android::hardware::audio::common::V2_0::AudioConfig;
using ::android::hardware::audio::common::V2_0::AudioDevice;
@@ -38,6 +41,7 @@
using ::android::hardware::audio::common::V2_0::AudioMode;
using ::android::hardware::audio::common::V2_0::AudioSource;
using ::android::hardware::audio::common::V2_0::HidlUtils;
+using ::android::hardware::audio::common::utils::mkEnumConverter;
using ::android::hardware::audio::V2_0::DeviceAddress;
using ::android::hardware::audio::V2_0::IPrimaryDevice;
using ::android::hardware::audio::V2_0::ParameterValue;
@@ -46,6 +50,7 @@
using ::android::hardware::hidl_vec;
namespace android {
+namespace V2_0 {
namespace {
@@ -193,7 +198,9 @@
hidl_vec<ParameterValue> hidlParams;
status_t status = parametersFromHal(kvPairs, &hidlParams);
if (status != OK) return status;
- return processReturn("setParameters", mDevice->setParameters(hidlParams));
+ // TODO: change the API so that context and kvPairs are separated
+ return processReturn("setParameters",
+ utils::setParameters(mDevice, {} /* context */, hidlParams));
}
status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) {
@@ -203,7 +210,8 @@
status_t status = keysFromHal(keys, &hidlKeys);
if (status != OK) return status;
Result retval;
- Return<void> ret = mDevice->getParameters(
+ Return<void> ret = utils::getParameters(mDevice,
+ {} /* context */,
hidlKeys,
[&](Result r, const hidl_vec<ParameterValue>& parameters) {
retval = r;
@@ -249,7 +257,7 @@
handle,
hidlDevice,
hidlConfig,
- AudioOutputFlag(flags),
+ mkEnumConverter<AudioOutputFlag>(flags),
[&](Result r, const sp<IStreamOut>& result, const AudioConfig& suggestedConfig) {
retval = r;
if (retval == Result::OK) {
@@ -275,12 +283,13 @@
AudioConfig hidlConfig;
HidlUtils::audioConfigFromHal(*config, &hidlConfig);
Result retval = Result::NOT_INITIALIZED;
+ auto sourceMetadata = AudioSource(source);
Return<void> ret = mDevice->openInputStream(
handle,
hidlDevice,
hidlConfig,
- AudioInputFlag(flags),
- AudioSource(source),
+ mkEnumConverter<AudioInputFlag>(flags),
+ sourceMetadata,
[&](Result r, const sp<IStreamIn>& result, const AudioConfig& suggestedConfig) {
retval = r;
if (retval == Result::OK) {
@@ -356,9 +365,10 @@
if (mDevice == 0) return NO_INIT;
native_handle_t* hidlHandle = native_handle_create(1, 0);
hidlHandle->data[0] = fd;
- Return<void> ret = mDevice->debugDump(hidlHandle);
+ Return<void> ret = mDevice->debug(hidlHandle, {} /* options */);
native_handle_delete(hidlHandle);
return processReturn("dump", ret);
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/DeviceHalHidl.h b/media/libaudiohal/2.0/DeviceHalHidl.h
index 3c1cb59..d6b0ab0 100644
--- a/media/libaudiohal/2.0/DeviceHalHidl.h
+++ b/media/libaudiohal/2.0/DeviceHalHidl.h
@@ -28,6 +28,7 @@
using ::android::hardware::Return;
namespace android {
+namespace V2_0 {
class DeviceHalHidl : public DeviceHalInterface, public ConversionHelperHidl
{
@@ -124,6 +125,7 @@
virtual ~DeviceHalHidl();
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/DeviceHalLocal.cpp b/media/libaudiohal/2.0/DeviceHalLocal.cpp
index ec3bf78..4164659 100644
--- a/media/libaudiohal/2.0/DeviceHalLocal.cpp
+++ b/media/libaudiohal/2.0/DeviceHalLocal.cpp
@@ -23,6 +23,7 @@
#include "StreamHalLocal.h"
namespace android {
+namespace V2_0 {
DeviceHalLocal::DeviceHalLocal(audio_hw_device_t *dev)
: mDev(dev) {
@@ -201,4 +202,5 @@
mDev->close_input_stream(mDev, stream_in);
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/DeviceHalLocal.h b/media/libaudiohal/2.0/DeviceHalLocal.h
index aec201a..11e063a 100644
--- a/media/libaudiohal/2.0/DeviceHalLocal.h
+++ b/media/libaudiohal/2.0/DeviceHalLocal.h
@@ -21,6 +21,7 @@
#include <media/audiohal/DeviceHalInterface.h>
namespace android {
+namespace V2_0 {
class DeviceHalLocal : public DeviceHalInterface
{
@@ -122,6 +123,7 @@
uint32_t version() const { return mDev->common.version; }
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_DEVICE_HAL_LOCAL_H
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalHidl.cpp b/media/libaudiohal/2.0/DevicesFactoryHalHidl.cpp
index 31da263..ac65fcc 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalHidl.cpp
+++ b/media/libaudiohal/2.0/DevicesFactoryHalHidl.cpp
@@ -15,6 +15,7 @@
*/
#include <string.h>
+#include <vector>
#define LOG_TAG "DevicesFactoryHalHidl"
//#define LOG_NDEBUG 0
@@ -32,64 +33,69 @@
using ::android::hardware::Return;
namespace android {
+namespace V2_0 {
DevicesFactoryHalHidl::DevicesFactoryHalHidl() {
- mDevicesFactory = IDevicesFactory::getService();
- if (mDevicesFactory != 0) {
- // It is assumed that DevicesFactory is owned by AudioFlinger
- // and thus have the same lifespan.
- mDevicesFactory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/);
- } else {
- ALOGE("Failed to obtain IDevicesFactory service, terminating process.");
+ sp<IDevicesFactory> defaultFactory{IDevicesFactory::getService()};
+ if (!defaultFactory) {
+ ALOGE("Failed to obtain IDevicesFactory/default service, terminating process.");
exit(1);
}
+ mDeviceFactories.push_back(defaultFactory);
+ for (const auto& factory : mDeviceFactories) {
+ // It is assumed that the DevicesFactoryHalInterface instance is owned
+ // by AudioFlinger and thus have the same lifespan.
+ factory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/);
+ }
}
-DevicesFactoryHalHidl::~DevicesFactoryHalHidl() {
-}
-// static
-status_t DevicesFactoryHalHidl::nameFromHal(const char *name, IDevicesFactory::Device *device) {
+static IDevicesFactory::Device idFromHal(const char *name, status_t* status) {
+ *status = OK;
if (strcmp(name, AUDIO_HARDWARE_MODULE_ID_PRIMARY) == 0) {
- *device = IDevicesFactory::Device::PRIMARY;
- return OK;
+ return IDevicesFactory::Device::PRIMARY;
} else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_A2DP) == 0) {
- *device = IDevicesFactory::Device::A2DP;
- return OK;
+ return IDevicesFactory::Device::A2DP;
} else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_USB) == 0) {
- *device = IDevicesFactory::Device::USB;
- return OK;
+ return IDevicesFactory::Device::USB;
} else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX) == 0) {
- *device = IDevicesFactory::Device::R_SUBMIX;
- return OK;
+ return IDevicesFactory::Device::R_SUBMIX;
} else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_STUB) == 0) {
- *device = IDevicesFactory::Device::STUB;
- return OK;
+ return IDevicesFactory::Device::STUB;
}
ALOGE("Invalid device name %s", name);
- return BAD_VALUE;
+ *status = BAD_VALUE;
+ return {};
}
status_t DevicesFactoryHalHidl::openDevice(const char *name, sp<DeviceHalInterface> *device) {
- if (mDevicesFactory == 0) return NO_INIT;
- IDevicesFactory::Device hidlDevice;
- status_t status = nameFromHal(name, &hidlDevice);
+ if (mDeviceFactories.empty()) return NO_INIT;
+ status_t status;
+ auto hidlId = idFromHal(name, &status);
if (status != OK) return status;
Result retval = Result::NOT_INITIALIZED;
- Return<void> ret = mDevicesFactory->openDevice(
- hidlDevice,
- [&](Result r, const sp<IDevice>& result) {
- retval = r;
- if (retval == Result::OK) {
- *device = new DeviceHalHidl(result);
- }
- });
- if (ret.isOk()) {
- if (retval == Result::OK) return OK;
- else if (retval == Result::INVALID_ARGUMENTS) return BAD_VALUE;
- else return NO_INIT;
+ for (const auto& factory : mDeviceFactories) {
+ Return<void> ret = factory->openDevice(
+ hidlId,
+ [&](Result r, const sp<IDevice>& result) {
+ retval = r;
+ if (retval == Result::OK) {
+ *device = new DeviceHalHidl(result);
+ }
+ });
+ if (!ret.isOk()) return FAILED_TRANSACTION;
+ switch (retval) {
+ // Device was found and was initialized successfully.
+ case Result::OK: return OK;
+ // Device was found but failed to initalize.
+ case Result::NOT_INITIALIZED: return NO_INIT;
+ // Otherwise continue iterating.
+ default: ;
+ }
}
- return FAILED_TRANSACTION;
+ ALOGW("The specified device name is not recognized: \"%s\"", name);
+ return BAD_VALUE;
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalHidl.h b/media/libaudiohal/2.0/DevicesFactoryHalHidl.h
index e2f1ad1..45419f4 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalHidl.h
+++ b/media/libaudiohal/2.0/DevicesFactoryHalHidl.h
@@ -27,6 +27,7 @@
using ::android::hardware::audio::V2_0::IDevicesFactory;
namespace android {
+namespace V2_0 {
class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
{
@@ -38,16 +39,15 @@
private:
friend class DevicesFactoryHalHybrid;
- sp<IDevicesFactory> mDevicesFactory;
-
- static status_t nameFromHal(const char *name, IDevicesFactory::Device *device);
+ std::vector<sp<IDevicesFactory>> mDeviceFactories;
// Can not be constructed directly by clients.
DevicesFactoryHalHidl();
- virtual ~DevicesFactoryHalHidl();
+ virtual ~DevicesFactoryHalHidl() = default;
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalHybrid.cpp b/media/libaudiohal/2.0/DevicesFactoryHalHybrid.cpp
index 1c4be74..7d9c15c 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalHybrid.cpp
+++ b/media/libaudiohal/2.0/DevicesFactoryHalHybrid.cpp
@@ -22,15 +22,13 @@
#include "DevicesFactoryHalHidl.h"
namespace android {
+namespace V2_0 {
DevicesFactoryHalHybrid::DevicesFactoryHalHybrid()
: mLocalFactory(new DevicesFactoryHalLocal()),
mHidlFactory(new DevicesFactoryHalHidl()) {
}
-DevicesFactoryHalHybrid::~DevicesFactoryHalHybrid() {
-}
-
status_t DevicesFactoryHalHybrid::openDevice(const char *name, sp<DeviceHalInterface> *device) {
if (mHidlFactory != 0 && strcmp(AUDIO_HARDWARE_MODULE_ID_A2DP, name) != 0 &&
strcmp(AUDIO_HARDWARE_MODULE_ID_HEARING_AID, name) != 0) {
@@ -39,4 +37,5 @@
return mLocalFactory->openDevice(name, device);
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalHybrid.h b/media/libaudiohal/2.0/DevicesFactoryHalHybrid.h
index abd57d6..ba8c6f2 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalHybrid.h
+++ b/media/libaudiohal/2.0/DevicesFactoryHalHybrid.h
@@ -22,26 +22,27 @@
#include <utils/RefBase.h>
namespace android {
+namespace V2_0 {
class DevicesFactoryHalHybrid : public DevicesFactoryHalInterface
{
public:
+ DevicesFactoryHalHybrid();
+
// Opens a device with the specified name. To close the device, it is
// necessary to release references to the returned object.
virtual status_t openDevice(const char *name, sp<DeviceHalInterface> *device);
private:
- friend class DevicesFactoryHalInterface;
-
- // Can not be constructed directly by clients.
- DevicesFactoryHalHybrid();
-
- virtual ~DevicesFactoryHalHybrid();
-
sp<DevicesFactoryHalInterface> mLocalFactory;
sp<DevicesFactoryHalInterface> mHidlFactory;
};
+sp<DevicesFactoryHalInterface> createDevicesFactoryHal() {
+ return new DevicesFactoryHalHybrid();
+}
+
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HYBRID_H
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalLocal.cpp b/media/libaudiohal/2.0/DevicesFactoryHalLocal.cpp
index 13a9acd..6f60775 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalLocal.cpp
+++ b/media/libaudiohal/2.0/DevicesFactoryHalLocal.cpp
@@ -26,6 +26,7 @@
#include "DevicesFactoryHalLocal.h"
namespace android {
+namespace V2_0 {
static status_t load_audio_interface(const char *if_name, audio_hw_device_t **dev)
{
@@ -66,4 +67,5 @@
return rc;
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/DevicesFactoryHalLocal.h b/media/libaudiohal/2.0/DevicesFactoryHalLocal.h
index b9d18ab..41330b4 100644
--- a/media/libaudiohal/2.0/DevicesFactoryHalLocal.h
+++ b/media/libaudiohal/2.0/DevicesFactoryHalLocal.h
@@ -24,6 +24,7 @@
#include "DeviceHalLocal.h"
namespace android {
+namespace V2_0 {
class DevicesFactoryHalLocal : public DevicesFactoryHalInterface
{
@@ -41,6 +42,7 @@
virtual ~DevicesFactoryHalLocal() {}
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_LOCAL_H
diff --git a/media/libaudiohal/2.0/EffectBufferHalHidl.cpp b/media/libaudiohal/2.0/EffectBufferHalHidl.cpp
index 226a500..5f91042 100644
--- a/media/libaudiohal/2.0/EffectBufferHalHidl.cpp
+++ b/media/libaudiohal/2.0/EffectBufferHalHidl.cpp
@@ -30,6 +30,7 @@
using ::android::hidl::allocator::V1_0::IAllocator;
namespace android {
+namespace V2_0 {
// static
uint64_t EffectBufferHalHidl::makeUniqueId() {
@@ -141,4 +142,5 @@
memcpy(mExternalData, mAudioBuffer.raw, size);
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/EffectBufferHalHidl.h b/media/libaudiohal/2.0/EffectBufferHalHidl.h
index 31e0087..5c70743 100644
--- a/media/libaudiohal/2.0/EffectBufferHalHidl.h
+++ b/media/libaudiohal/2.0/EffectBufferHalHidl.h
@@ -28,6 +28,7 @@
using android::hidl::memory::V1_0::IMemory;
namespace android {
+namespace V2_0 {
class EffectBufferHalHidl : public EffectBufferHalInterface
{
@@ -71,6 +72,7 @@
status_t init();
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_EFFECT_BUFFER_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/EffectHalHidl.cpp b/media/libaudiohal/2.0/EffectHalHidl.cpp
index 4fb032c..dcd2dc2 100644
--- a/media/libaudiohal/2.0/EffectHalHidl.cpp
+++ b/media/libaudiohal/2.0/EffectHalHidl.cpp
@@ -17,11 +17,11 @@
#define LOG_TAG "EffectHalHidl"
//#define LOG_NDEBUG 0
+#include <common/all-versions/VersionUtils.h>
#include <hwbinder/IPCThreadState.h>
#include <media/EffectsFactoryApi.h>
#include <utils/Log.h>
-#include "ConversionHelperHidl.h"
#include "EffectBufferHalHidl.h"
#include "EffectHalHidl.h"
#include "HidlUtils.h"
@@ -34,11 +34,13 @@
using ::android::hardware::audio::common::V2_0::HidlUtils;
using ::android::hardware::audio::common::V2_0::AudioChannelMask;
using ::android::hardware::audio::common::V2_0::AudioFormat;
+using ::android::hardware::audio::common::utils::mkEnumConverter;
using ::android::hardware::hidl_vec;
using ::android::hardware::MQDescriptorSync;
using ::android::hardware::Return;
namespace android {
+namespace V2_0 {
EffectHalHidl::EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId)
: mEffect(effect), mEffectId(effectId), mBuffersChanged(true), mEfGroup(nullptr) {
@@ -75,10 +77,10 @@
void EffectHalHidl::effectBufferConfigFromHal(
const buffer_config_t& halConfig, EffectBufferConfig* config) {
config->samplingRateHz = halConfig.samplingRate;
- config->channels = AudioChannelMask(halConfig.channels);
+ config->channels = mkEnumConverter<AudioChannelMask>(halConfig.channels);
config->format = AudioFormat(halConfig.format);
config->accessMode = EffectBufferAccess(halConfig.accessMode);
- config->mask = EffectConfigParameters(halConfig.mask);
+ config->mask = mkEnumConverter<EffectConfigParameters>(halConfig.mask);
}
// static
@@ -335,4 +337,5 @@
return result;
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/EffectHalHidl.h b/media/libaudiohal/2.0/EffectHalHidl.h
index 6ffdaf1..6fd405e 100644
--- a/media/libaudiohal/2.0/EffectHalHidl.h
+++ b/media/libaudiohal/2.0/EffectHalHidl.h
@@ -27,10 +27,12 @@
using ::android::hardware::audio::effect::V2_0::EffectConfig;
using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
using ::android::hardware::audio::effect::V2_0::IEffect;
+using EffectResult = ::android::hardware::audio::effect::V2_0::Result;
using ::android::hardware::EventFlag;
using ::android::hardware::MessageQueue;
namespace android {
+namespace V2_0 {
class EffectHalHidl : public EffectHalInterface
{
@@ -68,8 +70,7 @@
private:
friend class EffectsFactoryHalHidl;
- typedef MessageQueue<
- hardware::audio::effect::V2_0::Result, hardware::kSynchronizedReadWrite> StatusMQ;
+ typedef MessageQueue<EffectResult, hardware::kSynchronizedReadWrite> StatusMQ;
sp<IEffect> mEffect;
const uint64_t mEffectId;
@@ -79,7 +80,7 @@
std::unique_ptr<StatusMQ> mStatusMQ;
EventFlag* mEfGroup;
- static status_t analyzeResult(const hardware::audio::effect::V2_0::Result& result);
+ static status_t analyzeResult(const EffectResult& result);
static void effectBufferConfigFromHal(
const buffer_config_t& halConfig, EffectBufferConfig* config);
static void effectBufferConfigToHal(
@@ -103,6 +104,7 @@
status_t setProcessBuffers();
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/EffectsFactoryHalHidl.cpp b/media/libaudiohal/2.0/EffectsFactoryHalHidl.cpp
index 0d40e6d..ade2574 100644
--- a/media/libaudiohal/2.0/EffectsFactoryHalHidl.cpp
+++ b/media/libaudiohal/2.0/EffectsFactoryHalHidl.cpp
@@ -19,10 +19,10 @@
#include <cutils/native_handle.h>
+#include "EffectsFactoryHalHidl.h"
#include "ConversionHelperHidl.h"
#include "EffectBufferHalHidl.h"
#include "EffectHalHidl.h"
-#include "EffectsFactoryHalHidl.h"
#include "HidlUtils.h"
using ::android::hardware::audio::common::V2_0::HidlUtils;
@@ -32,6 +32,7 @@
using ::android::hardware::Return;
namespace android {
+namespace V2_0 {
EffectsFactoryHalHidl::EffectsFactoryHalHidl() : ConversionHelperHidl("EffectsFactory") {
mEffectsFactory = IEffectsFactory::getService();
@@ -41,9 +42,6 @@
}
}
-EffectsFactoryHalHidl::~EffectsFactoryHalHidl() {
-}
-
status_t EffectsFactoryHalHidl::queryAllDescriptors() {
if (mEffectsFactory == 0) return NO_INIT;
Result retval = Result::NOT_INITIALIZED;
@@ -132,7 +130,7 @@
if (mEffectsFactory == 0) return NO_INIT;
native_handle_t* hidlHandle = native_handle_create(1, 0);
hidlHandle->data[0] = fd;
- Return<void> ret = mEffectsFactory->debugDump(hidlHandle);
+ Return<void> ret = mEffectsFactory->debug(hidlHandle, {} /* options */);
native_handle_delete(hidlHandle);
return processReturn(__FUNCTION__, ret);
}
@@ -147,4 +145,5 @@
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/EffectsFactoryHalHidl.h b/media/libaudiohal/2.0/EffectsFactoryHalHidl.h
index 82b5481..c7c37c2 100644
--- a/media/libaudiohal/2.0/EffectsFactoryHalHidl.h
+++ b/media/libaudiohal/2.0/EffectsFactoryHalHidl.h
@@ -24,6 +24,7 @@
#include "ConversionHelperHidl.h"
namespace android {
+namespace V2_0 {
using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
using ::android::hardware::audio::effect::V2_0::IEffectsFactory;
@@ -32,6 +33,8 @@
class EffectsFactoryHalHidl : public EffectsFactoryHalInterface, public ConversionHelperHidl
{
public:
+ EffectsFactoryHalHidl();
+
// Returns the number of different effects in all loaded libraries.
virtual status_t queryNumberEffects(uint32_t *pNumEffects);
@@ -56,18 +59,17 @@
sp<EffectBufferHalInterface>* buffer) override;
private:
- friend class EffectsFactoryHalInterface;
-
sp<IEffectsFactory> mEffectsFactory;
hidl_vec<EffectDescriptor> mLastDescriptors;
- // Can not be constructed directly by clients.
- EffectsFactoryHalHidl();
- virtual ~EffectsFactoryHalHidl();
-
status_t queryAllDescriptors();
};
+sp<EffectsFactoryHalInterface> createEffectsFactoryHal() {
+ return new EffectsFactoryHalHidl();
+}
+
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_EFFECTS_FACTORY_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/StreamHalHidl.cpp b/media/libaudiohal/2.0/StreamHalHidl.cpp
index 9869cd2..b6e8365 100644
--- a/media/libaudiohal/2.0/StreamHalHidl.cpp
+++ b/media/libaudiohal/2.0/StreamHalHidl.cpp
@@ -25,6 +25,7 @@
#include "DeviceHalHidl.h"
#include "EffectHalHidl.h"
#include "StreamHalHidl.h"
+#include "VersionUtils.h"
using ::android::hardware::audio::common::V2_0::AudioChannelMask;
using ::android::hardware::audio::common::V2_0::AudioFormat;
@@ -43,6 +44,7 @@
using ReadCommand = ::android::hardware::audio::V2_0::IStreamIn::ReadCommand;
namespace android {
+namespace V2_0 {
StreamHalHidl::StreamHalHidl(IStream *stream)
: ConversionHelperHidl("Stream"),
@@ -55,7 +57,7 @@
if (mStream != nullptr && mStreamPowerLog.isUserDebugOrEngBuild()) {
// Obtain audio properties (see StreamHalHidl::getAudioProperties() below).
Return<void> ret = mStream->getAudioProperties(
- [&](uint32_t sr, AudioChannelMask m, AudioFormat f) {
+ [&](auto sr, auto m, auto f) {
mStreamPowerLog.init(sr,
static_cast<audio_channel_mask_t>(m),
static_cast<audio_format_t>(f));
@@ -95,7 +97,7 @@
uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) {
if (!mStream) return NO_INIT;
Return<void> ret = mStream->getAudioProperties(
- [&](uint32_t sr, AudioChannelMask m, AudioFormat f) {
+ [&](uint32_t sr, auto m, auto f) {
*sampleRate = sr;
*mask = static_cast<audio_channel_mask_t>(m);
*format = static_cast<audio_format_t>(f);
@@ -108,7 +110,8 @@
hidl_vec<ParameterValue> hidlParams;
status_t status = parametersFromHal(kvPairs, &hidlParams);
if (status != OK) return status;
- return processReturn("setParameters", mStream->setParameters(hidlParams));
+ return processReturn("setParameters",
+ utils::setParameters(mStream, hidlParams, {} /* options */));
}
status_t StreamHalHidl::getParameters(const String8& keys, String8 *values) {
@@ -118,7 +121,9 @@
status_t status = keysFromHal(keys, &hidlKeys);
if (status != OK) return status;
Result retval;
- Return<void> ret = mStream->getParameters(
+ Return<void> ret = utils::getParameters(
+ mStream,
+ {} /* context */,
hidlKeys,
[&](Result r, const hidl_vec<ParameterValue>& parameters) {
retval = r;
@@ -150,7 +155,7 @@
if (!mStream) return NO_INIT;
native_handle_t* hidlHandle = native_handle_create(1, 0);
hidlHandle->data[0] = fd;
- Return<void> ret = mStream->debugDump(hidlHandle);
+ Return<void> ret = mStream->debug(hidlHandle, {} /* options */);
native_handle_delete(hidlHandle);
mStreamPowerLog.dump(fd);
return processReturn("dump", ret);
@@ -765,4 +770,5 @@
return INVALID_OPERATION;
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/StreamHalHidl.h b/media/libaudiohal/2.0/StreamHalHidl.h
index ebad8ae..8727620 100644
--- a/media/libaudiohal/2.0/StreamHalHidl.h
+++ b/media/libaudiohal/2.0/StreamHalHidl.h
@@ -41,6 +41,7 @@
using WriteStatus = ::android::hardware::audio::V2_0::IStreamOut::WriteStatus;
namespace android {
+namespace V2_0 {
class DeviceHalHidl;
@@ -243,6 +244,7 @@
status_t prepareForReading(size_t bufferSize);
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_STREAM_HAL_HIDL_H
diff --git a/media/libaudiohal/2.0/StreamHalLocal.cpp b/media/libaudiohal/2.0/StreamHalLocal.cpp
index 98107e5..7951f79 100644
--- a/media/libaudiohal/2.0/StreamHalLocal.cpp
+++ b/media/libaudiohal/2.0/StreamHalLocal.cpp
@@ -22,8 +22,10 @@
#include "DeviceHalLocal.h"
#include "StreamHalLocal.h"
+#include "VersionUtils.h"
namespace android {
+namespace V2_0 {
StreamHalLocal::StreamHalLocal(audio_stream_t *stream, sp<DeviceHalLocal> device)
: mDevice(device),
@@ -344,4 +346,5 @@
return INVALID_OPERATION;
}
+} // namespace V2_0
} // namespace android
diff --git a/media/libaudiohal/2.0/StreamHalLocal.h b/media/libaudiohal/2.0/StreamHalLocal.h
index cda8d0c..a4a71e1 100644
--- a/media/libaudiohal/2.0/StreamHalLocal.h
+++ b/media/libaudiohal/2.0/StreamHalLocal.h
@@ -21,6 +21,7 @@
#include "StreamPowerLog.h"
namespace android {
+namespace V2_0 {
class DeviceHalLocal;
@@ -214,6 +215,7 @@
virtual ~StreamInHalLocal();
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_STREAM_HAL_LOCAL_H
diff --git a/media/libaudiohal/2.0/StreamPowerLog.h b/media/libaudiohal/2.0/StreamPowerLog.h
index a78b1aa..db2f068 100644
--- a/media/libaudiohal/2.0/StreamPowerLog.h
+++ b/media/libaudiohal/2.0/StreamPowerLog.h
@@ -23,6 +23,7 @@
#include <system/audio.h>
namespace android {
+namespace V2_0 {
class StreamPowerLog {
public:
@@ -97,6 +98,7 @@
size_t mFrameSize;
};
+} // namespace V2_0
} // namespace android
#endif // ANDROID_HARDWARE_STREAM_POWER_LOG_H
diff --git a/media/libaudiohal/2.0/VersionUtils.h b/media/libaudiohal/2.0/VersionUtils.h
new file mode 100644
index 0000000..54e5ae0
--- /dev/null
+++ b/media/libaudiohal/2.0/VersionUtils.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#ifndef ANDROID_HARDWARE_VERSION_UTILS_H
+#define ANDROID_HARDWARE_VERSION_UTILS_H
+
+#include <android/hardware/audio/2.0/types.h>
+#include <hidl/HidlSupport.h>
+
+using ::android::hardware::audio::V2_0::ParameterValue;
+using ::android::hardware::audio::V2_0::Result;
+using ::android::hardware::Return;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+
+namespace android {
+namespace V2_0 {
+namespace utils {
+
+template <class T, class Callback>
+Return<void> getParameters(T& object, hidl_vec<ParameterValue> /*context*/,
+ hidl_vec<hidl_string> keys, Callback callback) {
+ return object->getParameters(keys, callback);
+}
+
+template <class T>
+Return<Result> setParameters(T& object, hidl_vec<ParameterValue> /*context*/,
+ hidl_vec<ParameterValue> keys) {
+ return object->setParameters(keys);
+}
+
+} // namespace utils
+} // namespace V2_0
+} // namespace android
+
+#endif // ANDROID_HARDWARE_VERSION_UTILS_H
diff --git a/media/libaudiohal/2.0/include/libaudiohal/2.0/FactoryHalHidl.h b/media/libaudiohal/2.0/include/libaudiohal/2.0/FactoryHalHidl.h
new file mode 100644
index 0000000..95335c0
--- /dev/null
+++ b/media/libaudiohal/2.0/include/libaudiohal/2.0/FactoryHalHidl.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#ifndef ANDROID_HARDWARE_FACTORY_HAL_HIDL_V2_0_H
+#define ANDROID_HARDWARE_FACTORY_HAL_HIDL_V2_0_H
+
+/** @file Library entry points to create the HAL factories. */
+
+#include <media/audiohal/DevicesFactoryHalInterface.h>
+#include <media/audiohal/EffectsFactoryHalInterface.h>
+#include <utils/StrongPointer.h>
+
+namespace android {
+namespace V2_0 {
+
+sp<EffectsFactoryHalInterface> createEffectsFactoryHal();
+
+sp<DevicesFactoryHalInterface> createDevicesFactoryHal();
+
+} // namespace V2_0
+} // namespace android
+
+#endif // ANDROID_HARDWARE_FACTORY_HAL_HIDL_V2_0_H