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

Commit 3e277cc0 authored by jiabin's avatar jiabin
Browse files

Leave AudioProfileVector only in libaudiofoundation.

Make AudioProfileVector only in libaudiofoundation. In policy part,
instead of having policy specific AudioProfileVector deriving from
AudioProfileVector in libaudiofoundation, make all the functions as
global functions. In that case, AudioPortBase does not need to be a
template class. That helps make the structure clearer.

Test: audio smoke test
Test: CTS for AudioTrack, AudioRecord, AudioManager
Test: audiopolicy_tests, AudioHostTest
Bug: 135621476
Change-Id: I36b12123cf52c3f82cef09a965403791dff74093
parent 861df4b5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -22,13 +22,13 @@

namespace android {

void AudioPortFoundation::toAudioPort(struct audio_port *port) const {
void AudioPortBase::toAudioPort(struct audio_port *port) const {
    // TODO: update this function once audio_port structure reflects the new profile definition.
    // For compatibility reason: flatening the AudioProfile into audio_port structure.
    FormatSet flatenedFormats;
    SampleRateSet flatenedRates;
    ChannelMaskSet flatenedChannels;
    for (const auto& profile : *getAudioProfileVectorBase()) {
    for (const auto& profile : mProfiles) {
        if (profile->isValid()) {
            audio_format_t formatToExport = profile->getFormat();
            const SampleRateSet &ratesToExport = profile->getSampleRates();
@@ -64,13 +64,13 @@ void AudioPortFoundation::toAudioPort(struct audio_port *port) const {
    }
}

void AudioPortFoundation::dump(std::string *dst, int spaces, bool verbose) const {
void AudioPortBase::dump(std::string *dst, int spaces, bool verbose) const {
    if (!mName.empty()) {
        dst->append(base::StringPrintf("%*s- name: %s\n", spaces, "", mName.c_str()));
    }
    if (verbose) {
        std::string profilesStr;
        getAudioProfileVectorBase()->dump(&profilesStr, spaces);
        mProfiles.dump(&profilesStr, spaces);
        dst->append(profilesStr);

        if (mGains.size() != 0) {
+11 −11
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Copyright (C) 2019 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.
@@ -118,14 +118,14 @@ void AudioProfile::dump(std::string *dst, int spaces) const
    }
}

ssize_t AudioProfileVectorBase::add(const sp<AudioProfile> &profile)
ssize_t AudioProfileVector::add(const sp<AudioProfile> &profile)
{
    ssize_t index = size();
    push_back(profile);
    return index;
}

void AudioProfileVectorBase::clearProfiles()
void AudioProfileVector::clearProfiles()
{
    for (auto it = begin(); it != end();) {
        if ((*it)->isDynamicFormat() && (*it)->hasValidFormat()) {
@@ -137,7 +137,7 @@ void AudioProfileVectorBase::clearProfiles()
    }
}

sp<AudioProfile> AudioProfileVectorBase::getFirstValidProfile() const
sp<AudioProfile> AudioProfileVector::getFirstValidProfile() const
{
    for (const auto &profile : *this) {
        if (profile->isValid()) {
@@ -147,7 +147,7 @@ sp<AudioProfile> AudioProfileVectorBase::getFirstValidProfile() const
    return nullptr;
}

sp<AudioProfile> AudioProfileVectorBase::getFirstValidProfileFor(audio_format_t format) const
sp<AudioProfile> AudioProfileVector::getFirstValidProfileFor(audio_format_t format) const
{
    for (const auto &profile : *this) {
        if (profile->isValid() && profile->getFormat() == format) {
@@ -157,7 +157,7 @@ sp<AudioProfile> AudioProfileVectorBase::getFirstValidProfileFor(audio_format_t
    return nullptr;
}

FormatVector AudioProfileVectorBase::getSupportedFormats() const
FormatVector AudioProfileVector::getSupportedFormats() const
{
    FormatVector supportedFormats;
    for (const auto &profile : *this) {
@@ -168,7 +168,7 @@ FormatVector AudioProfileVectorBase::getSupportedFormats() const
    return supportedFormats;
}

bool AudioProfileVectorBase::hasDynamicChannelsFor(audio_format_t format) const
bool AudioProfileVector::hasDynamicChannelsFor(audio_format_t format) const
{
    for (const auto &profile : *this) {
        if (profile->getFormat() == format && profile->isDynamicChannels()) {
@@ -178,7 +178,7 @@ bool AudioProfileVectorBase::hasDynamicChannelsFor(audio_format_t format) const
    return false;
}

bool AudioProfileVectorBase::hasDynamicFormat() const
bool AudioProfileVector::hasDynamicFormat() const
{
    for (const auto &profile : *this) {
        if (profile->isDynamicFormat()) {
@@ -188,7 +188,7 @@ bool AudioProfileVectorBase::hasDynamicFormat() const
    return false;
}

bool AudioProfileVectorBase::hasDynamicProfile() const
bool AudioProfileVector::hasDynamicProfile() const
{
    for (const auto &profile : *this) {
        if (profile->isDynamic()) {
@@ -198,7 +198,7 @@ bool AudioProfileVectorBase::hasDynamicProfile() const
    return false;
}

bool AudioProfileVectorBase::hasDynamicRateFor(audio_format_t format) const
bool AudioProfileVector::hasDynamicRateFor(audio_format_t format) const
{
    for (const auto &profile : *this) {
        if (profile->getFormat() == format && profile->isDynamicRate()) {
@@ -208,7 +208,7 @@ bool AudioProfileVectorBase::hasDynamicRateFor(audio_format_t format) const
    return false;
}

void AudioProfileVectorBase::dump(std::string *dst, int spaces) const
void AudioProfileVector::dump(std::string *dst, int spaces) const
{
    dst->append(base::StringPrintf("%*s- Profiles:\n", spaces, ""));
    for (size_t i = 0; i < size(); i++) {
+10 −32
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@

namespace android {

class AudioPortFoundation : public virtual RefBase
class AudioPortBase : public virtual RefBase
{
public:
    AudioPortFoundation(const std::string& name, audio_port_type_t type,  audio_port_role_t role) :
    AudioPortBase(const std::string& name, audio_port_type_t type,  audio_port_role_t role) :
            mName(name), mType(type), mRole(role) {}

    virtual ~AudioPortFoundation() = default;
    virtual ~AudioPortBase() = default;

    void setName(const std::string &name) { mName = name; }
    const std::string &getName() const { return mName; }
@@ -48,15 +48,17 @@ public:

    virtual void toAudioPort(struct audio_port *port) const;

    virtual AudioProfileVectorBase* getAudioProfileVectorBase() const = 0;
    virtual void addAudioProfile(const sp<AudioProfile> &profile) {
        getAudioProfileVectorBase()->add(profile);
        mProfiles.add(profile);
    }
    virtual void clearAudioProfiles() {
        getAudioProfileVectorBase()->clearProfiles();
        mProfiles.clearProfiles();
    }

    bool hasValidAudioProfile() const { return getAudioProfileVectorBase()->hasValidProfile(); }
    bool hasValidAudioProfile() const { return mProfiles.hasValidProfile(); }

    void setAudioProfiles(const AudioProfileVector &profiles) { mProfiles = profiles; }
    AudioProfileVector &getAudioProfiles() { return mProfiles; }

    status_t checkGain(const struct audio_gain_config *gainConfig, int index) const {
        if (index < 0 || (size_t)index >= mGains.size()) {
@@ -78,31 +80,7 @@ protected:
    std::string  mName;
    audio_port_type_t mType;
    audio_port_role_t mRole;
};

template <typename ProfileVector,
          typename = typename std::enable_if<std::is_base_of<
                  AudioProfileVectorBase, ProfileVector>::value>::type>
class AudioPortBase : public AudioPortFoundation
{
public:
    AudioPortBase(const std::string& name, audio_port_type_t type,  audio_port_role_t role) :
            AudioPortFoundation(name, type, role) {}

    virtual ~AudioPortBase() {}

    AudioProfileVectorBase* getAudioProfileVectorBase() const override {
        return static_cast<AudioProfileVectorBase*>(const_cast<ProfileVector*>(&mProfiles));
    }

    void addAudioProfile(const sp<AudioProfile> &profile) override { mProfiles.add(profile); }
    void clearAudioProfiles() override { return mProfiles.clearProfiles(); }

    void setAudioProfiles(const ProfileVector &profiles) { mProfiles = profiles; }
    ProfileVector &getAudioProfiles() { return mProfiles; }

protected:
    ProfileVector mProfiles; // AudioProfiles supported by this port (format, Rates, Channels)
    AudioProfileVector mProfiles; // AudioProfiles supported by this port (format, Rates, Channels)
};


+2 −2
Original line number Diff line number Diff line
@@ -77,10 +77,10 @@ private:
    bool mIsDynamicRate = false;
};

class AudioProfileVectorBase : public std::vector<sp<AudioProfile> >
class AudioProfileVector : public std::vector<sp<AudioProfile>>
{
public:
    virtual ~AudioProfileVectorBase() = default;
    virtual ~AudioProfileVector() = default;

    virtual ssize_t add(const sp<AudioProfile> &profile);

+8 −4
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ namespace android {
class HwModule;
class AudioRoute;

class AudioPort : public virtual RefBase, public AudioPortBase<AudioProfileVector>,
                  private HandleGenerator<audio_port_handle_t>
class AudioPort : public AudioPortBase, private HandleGenerator<audio_port_handle_t>
{
public:
    AudioPort(const std::string& name, audio_port_type_t type,  audio_port_role_t role) :
@@ -42,6 +41,10 @@ public:

    virtual ~AudioPort() {}

    void addAudioProfile(const sp<AudioProfile> &profile) {
        addAudioProfileAndSort(mProfiles, profile);
    }

    virtual void setFlags(uint32_t flags)
    {
        //force direct flag if offload flag is set: offloading implies a direct output stream
@@ -63,7 +66,7 @@ public:

    virtual void importAudioPort(const sp<AudioPort>& port, bool force = false);

    bool hasDynamicAudioProfile() const { return getAudioProfileVectorBase()->hasDynamicProfile(); }
    bool hasDynamicAudioProfile() const { return mProfiles.hasDynamicProfile(); }

    // searches for an exact match
    virtual status_t checkExactAudioProfile(const struct audio_port_config *config) const;
@@ -74,7 +77,8 @@ public:
                                         audio_channel_mask_t &channelMask,
                                         audio_format_t &format) const
    {
        return mProfiles.checkCompatibleProfile(samplingRate, channelMask, format, mType, mRole);
        return checkCompatibleProfile(
                mProfiles, samplingRate, channelMask, format, mType, mRole);
    }

    void pickAudioProfile(uint32_t &samplingRate,
Loading