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

Commit 6b111f32 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audiohal: Always load A2DP module locally

This makes legitimate unix socket interaction between A2DP
module and the Bluetooth stack.

Implemented by allowing both "local" and "hidl" interface
wrappers to co-exist for devices and streams. A "hybrid" device
factory is introduced to create an appropriate implementation
of a device depending on the requested module name.

Bug: 37640821
Test: Play Music over BT headset
Change-Id: I5592961dd5b56840418fb122680979d11a261b6c
parent 6f85f653
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -5,28 +5,35 @@ include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := \
    libcutils   \
    liblog      \
    libutils
    libutils    \
    libhardware

LOCAL_SRC_FILES := \
    DeviceHalLocal.cpp          \
    DevicesFactoryHalHybrid.cpp \
    DevicesFactoryHalLocal.cpp  \
    StreamHalLocal.cpp

LOCAL_CFLAGS := -Wall -Werror

ifeq ($(USE_LEGACY_LOCAL_AUDIO_HAL), true)

# Use audiohal directly w/o hwbinder middleware.
# This is for performance comparison and debugging only.

LOCAL_SRC_FILES := \
    DeviceHalLocal.cpp          \
    DevicesFactoryHalLocal.cpp  \
LOCAL_SRC_FILES += \
    EffectBufferHalLocal.cpp    \
    EffectHalLocal.cpp          \
    EffectsFactoryHalLocal.cpp  \
    StreamHalLocal.cpp
    EffectHalLocal.cpp

LOCAL_SHARED_LIBRARIES += \
    libeffects  \
    libhardware
    libeffects

LOCAL_CFLAGS += -DUSE_LEGACY_LOCAL_AUDIO_HAL

else  # if !USE_LEGACY_LOCAL_AUDIO_HAL

LOCAL_SRC_FILES := \
LOCAL_SRC_FILES += \
    ConversionHelperHidl.cpp   \
    HalDeathHandlerHidl.cpp    \
    DeviceHalHidl.cpp          \
@@ -60,6 +67,4 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include

LOCAL_MODULE := libaudiohal

LOCAL_CFLAGS := -Wall -Werror

include $(BUILD_SHARED_LIBRARY)
+0 −5
Original line number Diff line number Diff line
@@ -33,11 +33,6 @@ using ::android::hardware::Return;

namespace android {

// static
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
    return new DevicesFactoryHalHidl();
}

DevicesFactoryHalHidl::DevicesFactoryHalHidl() {
    mDevicesFactory = IDevicesFactory::getService();
    if (mDevicesFactory != 0) {
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class DevicesFactoryHalHidl : public DevicesFactoryHalInterface
    virtual status_t openDevice(const char *name, sp<DeviceHalInterface> *device);

  private:
    friend class DevicesFactoryHalInterface;
    friend class DevicesFactoryHalHybrid;

    sp<IDevicesFactory> mDevicesFactory;

+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#define LOG_TAG "DevicesFactoryHalHybrid"
//#define LOG_NDEBUG 0

#include "DevicesFactoryHalHybrid.h"
#include "DevicesFactoryHalLocal.h"
#ifndef USE_LEGACY_LOCAL_AUDIO_HAL
#include "DevicesFactoryHalHidl.h"
#endif

namespace android {

// static
sp<DevicesFactoryHalInterface> DevicesFactoryHalInterface::create() {
    return new DevicesFactoryHalHybrid();
}

DevicesFactoryHalHybrid::DevicesFactoryHalHybrid()
        : mLocalFactory(new DevicesFactoryHalLocal()),
          mHidlFactory(
#ifdef USE_LEGACY_LOCAL_AUDIO_HAL
                  nullptr
#else
                  new DevicesFactoryHalHidl()
#endif
                       ) {
}

DevicesFactoryHalHybrid::~DevicesFactoryHalHybrid() {
}

status_t DevicesFactoryHalHybrid::openDevice(const char *name, sp<DeviceHalInterface> *device) {
    if (mHidlFactory != 0 && strcmp(AUDIO_HARDWARE_MODULE_ID_A2DP, name) != 0) {
        return mHidlFactory->openDevice(name, device);
    }
    return mLocalFactory->openDevice(name, device);
}

} // namespace android
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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_DEVICES_FACTORY_HAL_HYBRID_H
#define ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HYBRID_H

#include <media/audiohal/DevicesFactoryHalInterface.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>

namespace android {

class DevicesFactoryHalHybrid : public DevicesFactoryHalInterface
{
  public:
    // 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;
};

} // namespace android

#endif // ANDROID_HARDWARE_DEVICES_FACTORY_HAL_HYBRID_H
Loading