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/StreamHalHidl.cpp b/media/libaudiohal/4.0/StreamHalHidl.cpp
index 9ba3b694..de16e98 100644
--- a/media/libaudiohal/4.0/StreamHalHidl.cpp
+++ b/media/libaudiohal/4.0/StreamHalHidl.cpp
@@ -25,6 +25,7 @@
 #include "DeviceHalHidl.h"
 #include "EffectHalHidl.h"
 #include "StreamHalHidl.h"
+#include "VersionUtils.h"
 
 using ::android::hardware::audio::common::V4_0::AudioChannelMask;
 using ::android::hardware::audio::common::V4_0::AudioFormat;
@@ -56,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));
@@ -96,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);
@@ -109,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) {
@@ -119,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;
@@ -151,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);