libaudiohal: Add support for audio@7.1
Added libauiohal@7.1 to support audio@7.1, core interfaces only,
no effects (these are still @7.0). Removed version-bound
namespace from the implementation to simplify code reuse. The
implementation classes are not exported from the libaudiohal
.so, thus no name conflicts could occur.
libaudiohal now tries audio@7.1 first and loads libaudiohal@7.1
client library. The library code has been updated to handle
opening of the primary device in the way appropriate for V7.1.
Note that as the effect HAL is 7.0, libaudiohal ends up loading
@7.1 client for the core HAL and @7.0 client for the effect
HAL. This can increase memory consumption.
Bug: 214426419
Test: check audio functionality on cuttlefish
and redfin (temporarily updated to @7.1)
Change-Id: I62f72dc86dee472d6b358a9861882b9b7f6c6177
diff --git a/media/libaudiohal/impl/DevicesFactoryHalHidl.cpp b/media/libaudiohal/impl/DevicesFactoryHalHidl.cpp
index 1c0eacb..f475729 100644
--- a/media/libaudiohal/impl/DevicesFactoryHalHidl.cpp
+++ b/media/libaudiohal/impl/DevicesFactoryHalHidl.cpp
@@ -31,14 +31,13 @@
#include "DevicesFactoryHalHidl.h"
using ::android::hardware::audio::CPP_VERSION::IDevice;
-using ::android::hardware::audio::CPP_VERSION::Result;
+using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::Result;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hidl::manager::V1_0::IServiceManager;
using ::android::hidl::manager::V1_0::IServiceNotification;
namespace android {
-namespace CPP_VERSION {
class ServiceNotificationListener : public IServiceNotification {
public:
@@ -115,14 +114,37 @@
if (status != OK) return status;
Result retval = Result::NOT_INITIALIZED;
for (const auto& factory : factories) {
- Return<void> ret = factory->openDevice(
- hidlId,
- [&](Result r, const sp<IDevice>& result) {
- retval = r;
- if (retval == Result::OK) {
- *device = new DeviceHalHidl(result);
- }
- });
+ Return<void> ret;
+ if (strcmp(name, AUDIO_HARDWARE_MODULE_ID_PRIMARY) == 0) {
+ // In V7.1 it's not possible to cast IDevice back to IPrimaryDevice,
+ // thus openPrimaryDevice must be used.
+#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
+ ret = factory->openPrimaryDevice_7_1(
+#else
+ ret = factory->openPrimaryDevice(
+#endif
+ [&](Result r,
+ const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& result) {
+ retval = r;
+ if (retval == Result::OK) {
+ *device = new DeviceHalHidl(result);
+ }
+ });
+ } else {
+#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
+ ret = factory->openDevice_7_1(
+#else
+ ret = factory->openDevice(
+#endif
+ hidlId,
+ [&](Result r,
+ const sp<::android::hardware::audio::CPP_VERSION::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.
@@ -178,7 +200,8 @@
return NO_ERROR;
}
-void DevicesFactoryHalHidl::addDeviceFactory(sp<IDevicesFactory> factory, bool needToNotify) {
+void DevicesFactoryHalHidl::addDeviceFactory(
+ sp<::android::hardware::audio::CPP_VERSION::IDevicesFactory> factory, bool needToNotify) {
// It is assumed that the DevicesFactoryHalInterface instance is owned
// by AudioFlinger and thus have the same lifespan.
factory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/);
@@ -198,10 +221,10 @@
}
}
-std::vector<sp<IDevicesFactory>> DevicesFactoryHalHidl::copyDeviceFactories() {
+std::vector<sp<::android::hardware::audio::CPP_VERSION::IDevicesFactory>>
+ DevicesFactoryHalHidl::copyDeviceFactories() {
std::lock_guard<std::mutex> lock(mLock);
return mDeviceFactories;
}
-} // namespace CPP_VERSION
} // namespace android