Audio V4: Introduce 4.0 shim to HIDL
The difference between the 2.0 and the 4.0 is very small
by design and most of the modification have been made in a
retro compatible way
The intent is to be able to merge the two implementation
but it could not be done in this patch due to time constrains.
Bug: 38184704
Test: compile
Change-Id: I4738928313b7fd1f6332c0f22bb802d4fba41d82
Merged-In: I4738928313b7fd1f6332c0f22bb802d4fba41d82
Cherry-picked from master
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/media/libaudiohal/4.0/DeviceHalHidl.cpp b/media/libaudiohal/4.0/DeviceHalHidl.cpp
index 24f2eeb..8da1051 100644
--- a/media/libaudiohal/4.0/DeviceHalHidl.cpp
+++ b/media/libaudiohal/4.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::V4_0::AudioConfig;
using ::android::hardware::audio::common::V4_0::AudioDevice;
@@ -38,10 +41,12 @@
using ::android::hardware::audio::common::V4_0::AudioMode;
using ::android::hardware::audio::common::V4_0::AudioSource;
using ::android::hardware::audio::common::V4_0::HidlUtils;
+using ::android::hardware::audio::common::utils::mkEnumConverter;
using ::android::hardware::audio::V4_0::DeviceAddress;
using ::android::hardware::audio::V4_0::IPrimaryDevice;
using ::android::hardware::audio::V4_0::ParameterValue;
using ::android::hardware::audio::V4_0::Result;
+using ::android::hardware::audio::V4_0::SinkMetadata;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
@@ -194,7 +199,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) {
@@ -204,7 +211,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;
@@ -250,7 +258,8 @@
handle,
hidlDevice,
hidlConfig,
- AudioOutputFlag(flags),
+ mkEnumConverter<AudioOutputFlag>(flags),
+ {} /* metadata */,
[&](Result r, const sp<IStreamOut>& result, const AudioConfig& suggestedConfig) {
retval = r;
if (retval == Result::OK) {
@@ -276,12 +285,15 @@
AudioConfig hidlConfig;
HidlUtils::audioConfigFromHal(*config, &hidlConfig);
Result retval = Result::NOT_INITIALIZED;
+ // TODO: correctly propagate the tracks sources and volume
+ // for now, only send the main source at 1dbfs
+ SinkMetadata metadata = {{{AudioSource(source), 1}}};
Return<void> ret = mDevice->openInputStream(
handle,
hidlDevice,
hidlConfig,
- AudioInputFlag(flags),
- AudioSource(source),
+ flags,
+ metadata,
[&](Result r, const sp<IStreamIn>& result, const AudioConfig& suggestedConfig) {
retval = r;
if (retval == Result::OK) {
@@ -351,7 +363,7 @@
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);
}