Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a7484bd authored by Kevin Rocard's avatar Kevin Rocard
Browse files

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
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent 2390b5d6
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
cc_library_shared {
    name: "libaudiohal@4.0",

    srcs: [
        "DeviceHalLocal.cpp",
        "DevicesFactoryHalHybrid.cpp",
        "DevicesFactoryHalLocal.cpp",
        "StreamHalLocal.cpp",

        "ConversionHelperHidl.cpp",
        "DeviceHalHidl.cpp",
        "DevicesFactoryHalHidl.cpp",
        "EffectBufferHalHidl.cpp",
        "EffectHalHidl.cpp",
        "EffectsFactoryHalHidl.cpp",
        "StreamHalHidl.cpp",
    ],

    export_include_dirs: ["include"],

    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
    ],
    shared_libs: [
        "libaudiohal_deathhandler",
        "libaudioutils",
        "libcutils",
        "liblog",
        "libutils",
        "libhardware",
        "libbase",
        "libfmq",
        "libhwbinder",
        "libhidlbase",
        "libhidlmemory",
        "libhidltransport",
        "android.hardware.audio@4.0",
        "android.hardware.audio.common-util",
        "android.hardware.audio.common@4.0",
        "android.hardware.audio.common@4.0-util",
        "android.hardware.audio.effect@4.0",
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "libmedia_helper",
        "libmediautils",
    ],
    header_libs: [
        "android.hardware.audio.common.util@all-versions",
        "libaudiohal_headers"
    ],

    export_shared_lib_headers: [
        "libfmq",
    ],
}
+18 −6
Original line number Diff line number Diff line
@@ -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::AudioPortConfig;
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 @@ status_t DeviceHalHidl::setParameters(const String8& kvPairs) {
    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 DeviceHalHidl::getParameters(const String8& keys, String8 *values) {
    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 @@ status_t DeviceHalHidl::openOutputStream(
            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 @@ status_t DeviceHalHidl::openInputStream(
    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 @@ status_t DeviceHalHidl::dump(int fd) {
    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);
}
+1 −26
Original line number Diff line number Diff line
@@ -52,36 +52,11 @@ DevicesFactoryHalHidl::DevicesFactoryHalHidl() {
DevicesFactoryHalHidl::~DevicesFactoryHalHidl() {
}

// static
status_t DevicesFactoryHalHidl::nameFromHal(const char *name, IDevicesFactory::Device *device) {
    if (strcmp(name, AUDIO_HARDWARE_MODULE_ID_PRIMARY) == 0) {
        *device = IDevicesFactory::Device::PRIMARY;
        return OK;
    } else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_A2DP) == 0) {
        *device = IDevicesFactory::Device::A2DP;
        return OK;
    } else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_USB) == 0) {
        *device = IDevicesFactory::Device::USB;
        return OK;
    } else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX) == 0) {
        *device = IDevicesFactory::Device::R_SUBMIX;
        return OK;
    } else if(strcmp(name, AUDIO_HARDWARE_MODULE_ID_STUB) == 0) {
        *device = IDevicesFactory::Device::STUB;
        return OK;
    }
    ALOGE("Invalid device name %s", name);
    return BAD_VALUE;
}

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 (status != OK) return status;
    Result retval = Result::NOT_INITIALIZED;
    Return<void> ret = mDevicesFactory->openDevice(
            hidlDevice,
            name,
            [&](Result r, const sp<IDevice>& result) {
                retval = r;
                if (retval == Result::OK) {
+0 −2
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
    sp<IDevicesFactory> mDevicesFactory;
    sp<IDevicesFactory> mDevicesFactoryMsd;

    static status_t nameFromHal(const char *name, IDevicesFactory::Device *device);

    // Can not be constructed directly by clients.
    DevicesFactoryHalHidl();

+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#define LOG_TAG "DevicesFactoryHalHybrid"
//#define LOG_NDEBUG 0

#include "DevicesFactoryHalHybrid.h"
#include <libaudiohal/4.0/DevicesFactoryHalHybrid.h>
#include "DevicesFactoryHalLocal.h"
#include "DevicesFactoryHalHidl.h"

Loading