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

Commit 9c8c665a authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "AOSP AIDL USB audio HAL implementation." am: 9275a964 am: 4fd112fa am: 19eced66

parents e906fca8 19eced66
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -104,6 +104,30 @@ constexpr bool isTelephonyDeviceType(
           device == ::aidl::android::media::audio::common::AudioDeviceType::OUT_TELEPHONY_TX;
}

constexpr bool isUsbInputDeviceType(::aidl::android::media::audio::common::AudioDeviceType type) {
    switch (type) {
        case ::aidl::android::media::audio::common::AudioDeviceType::IN_DOCK:
        case ::aidl::android::media::audio::common::AudioDeviceType::IN_ACCESSORY:
        case ::aidl::android::media::audio::common::AudioDeviceType::IN_DEVICE:
        case ::aidl::android::media::audio::common::AudioDeviceType::IN_HEADSET:
            return true;
        default:
            return false;
    }
}

constexpr bool isUsbOutputtDeviceType(::aidl::android::media::audio::common::AudioDeviceType type) {
    switch (type) {
        case ::aidl::android::media::audio::common::AudioDeviceType::OUT_DOCK:
        case ::aidl::android::media::audio::common::AudioDeviceType::OUT_ACCESSORY:
        case ::aidl::android::media::audio::common::AudioDeviceType::OUT_DEVICE:
        case ::aidl::android::media::audio::common::AudioDeviceType::OUT_HEADSET:
            return true;
        default:
            return false;
    }
}

constexpr bool isValidAudioMode(::aidl::android::media::audio::common::AudioMode mode) {
    return std::find(kValidAudioModes.begin(), kValidAudioModes.end(), mode) !=
           kValidAudioModes.end();
+5 −0
Original line number Diff line number Diff line
@@ -11,12 +11,14 @@ cc_defaults {
    name: "aidlaudioservice_defaults",
    vendor: true,
    shared_libs: [
        "libalsautilsv2",
        "libaudioaidlcommon",
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "libfmq",
        "libstagefright_foundation",
        "libtinyalsav2",
        "libutils",
        "libxml2",
        "android.hardware.common-V2-ndk",
@@ -71,6 +73,9 @@ cc_library_static {
        "Stream.cpp",
        "StreamStub.cpp",
        "Telephony.cpp",
        "usb/ModuleUsb.cpp",
        "usb/StreamUsb.cpp",
        "usb/UsbAlsaUtils.cpp",
    ],
    generated_sources: [
        "audio_policy_configuration_aidl_default",
+64 −8
Original line number Diff line number Diff line
@@ -27,8 +27,10 @@

#include "core-impl/Bluetooth.h"
#include "core-impl/Module.h"
#include "core-impl/ModuleUsb.h"
#include "core-impl/SoundDose.h"
#include "core-impl/StreamStub.h"
#include "core-impl/StreamUsb.h"
#include "core-impl/Telephony.h"
#include "core-impl/utils.h"

@@ -104,6 +106,42 @@ bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& forma

}  // namespace

// static
std::shared_ptr<Module> Module::createInstance(Type type) {
    switch (type) {
        case Module::Type::USB:
            return ndk::SharedRefBase::make<ModuleUsb>(type);
        case Type::DEFAULT:
        case Type::R_SUBMIX:
        default:
            return ndk::SharedRefBase::make<Module>(type);
    }
}

// static
StreamIn::CreateInstance Module::getStreamInCreator(Type type) {
    switch (type) {
        case Type::USB:
            return StreamInUsb::createInstance;
        case Type::DEFAULT:
        case Type::R_SUBMIX:
        default:
            return StreamInStub::createInstance;
    }
}

// static
StreamOut::CreateInstance Module::getStreamOutCreator(Type type) {
    switch (type) {
        case Type::USB:
            return StreamOutUsb::createInstance;
        case Type::DEFAULT:
        case Type::R_SUBMIX:
        default:
            return StreamOutStub::createInstance;
    }
}

void Module::cleanUpPatch(int32_t patchId) {
    erase_all_values(mPatches, std::set<int32_t>{patchId});
}
@@ -153,6 +191,7 @@ ndk::ScopedAStatus Module::createStreamContext(
                std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
                std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
                portConfigIt->format.value(), portConfigIt->channelMask.value(),
                portConfigIt->sampleRate.value().value,
                std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
                asyncCallback, outEventCallback, params);
        if (temp.isValid()) {
@@ -261,6 +300,7 @@ internal::Configuration& Module::getConfig() {
                break;
            case Type::USB:
                mConfig = std::move(internal::getUsbConfiguration());
                break;
        }
    }
    return *mConfig;
@@ -401,6 +441,8 @@ ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdA
    if (!mDebug.simulateDeviceConnections) {
        // In a real HAL here we would attempt querying the profiles from the device.
        LOG(ERROR) << __func__ << ": failed to query supported device profiles";
        // TODO: Check the return value when it is ready for actual devices.
        populateConnectedDevicePort(&connectedPort);
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
    }

@@ -560,10 +602,9 @@ ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_ar
    }
    context.fillDescriptor(&_aidl_return->desc);
    std::shared_ptr<StreamIn> stream;
    // TODO: Add a mapping from module instance names to a corresponding 'createInstance'.
    if (auto status = StreamInStub::createInstance(in_args.sinkMetadata, std::move(context),
    ndk::ScopedAStatus status = getStreamInCreator(mType)(in_args.sinkMetadata, std::move(context),
                                                          mConfig->microphones, &stream);
        !status.isOk()) {
    if (!status.isOk()) {
        return status;
    }
    StreamWrapper streamWrapper(stream);
@@ -615,10 +656,9 @@ ndk::ScopedAStatus Module::openOutputStream(const OpenOutputStreamArguments& in_
    }
    context.fillDescriptor(&_aidl_return->desc);
    std::shared_ptr<StreamOut> stream;
    // TODO: Add a mapping from module instance names to a corresponding 'createInstance'.
    if (auto status = StreamOutStub::createInstance(in_args.sourceMetadata, std::move(context),
                                                    in_args.offloadInfo, &stream);
        !status.isOk()) {
    ndk::ScopedAStatus status = getStreamOutCreator(mType)(
            in_args.sourceMetadata, std::move(context), in_args.offloadInfo, &stream);
    if (!status.isOk()) {
        return status;
    }
    StreamWrapper streamWrapper(stream);
@@ -696,6 +736,10 @@ ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPa
        }
    }

    if (auto status = checkAudioPatchEndpointsMatch(sources, sinks); !status.isOk()) {
        return status;
    }

    auto& patches = getConfig().patches;
    auto existing = patches.end();
    std::optional<decltype(mPatches)> patchesBackup;
@@ -1190,4 +1234,16 @@ bool Module::isMmapSupported() {
    return mIsMmapSupported.value();
}

ndk::ScopedAStatus Module::populateConnectedDevicePort(AudioPort* audioPort __unused) {
    LOG(DEBUG) << __func__ << ": do nothing and return ok";
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus Module::checkAudioPatchEndpointsMatch(
        const std::vector<AudioPortConfig*>& sources __unused,
        const std::vector<AudioPortConfig*>& sinks __unused) {
    LOG(DEBUG) << __func__ << ": do nothing and return ok";
    return ndk::ScopedAStatus::ok();
}

}  // namespace aidl::android::hardware::audio::core
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

using aidl::android::hardware::audio::common::SinkMetadata;
using aidl::android::hardware::audio::common::SourceMetadata;
using aidl::android::media::audio::common::AudioDevice;
using aidl::android::media::audio::common::AudioOffloadInfo;

namespace aidl::android::hardware::audio::core {
@@ -68,6 +69,11 @@ DriverStub::DriverStub(const StreamContext& context, bool isInput)
    return ::android::OK;
}

::android::status_t DriverStub::setConnectedDevices(
        const std::vector<AudioDevice>& connectedDevices __unused) {
    return ::android::OK;
}

// static
ndk::ScopedAStatus StreamInStub::createInstance(const SinkMetadata& sinkMetadata,
                                                StreamContext&& context,
+15 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ class Module : public BnModule {

    explicit Module(Type type) : mType(type) {}

    static std::shared_ptr<Module> createInstance(Type type);
    static StreamIn::CreateInstance getStreamInCreator(Type type);
    static StreamOut::CreateInstance getStreamOutCreator(Type type);

  private:
    struct VendorDebug {
        static const std::string kForceTransientBurstName;
@@ -163,6 +167,17 @@ class Module : public BnModule {
    std::shared_ptr<sounddose::ISoundDose> mSoundDose;
    ndk::SpAIBinder mSoundDoseBinder;
    std::optional<bool> mIsMmapSupported;

  protected:
    // If the module is unable to populate the connected device port correctly, the returned error
    // code must correspond to the errors of `IModule.connectedExternalDevice` method.
    virtual ndk::ScopedAStatus populateConnectedDevicePort(
            ::aidl::android::media::audio::common::AudioPort* audioPort);
    // If the module finds that the patch endpoints configurations are not matched, the returned
    // error code must correspond to the errors of `IModule.setAudioPatch` method.
    virtual ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
            const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
            const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks);
};

}  // namespace aidl::android::hardware::audio::core
Loading