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

Commit fe96319b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move handling of flags of audio ports to libaudiofoundation"

parents b72b358d 99809024
Loading
Loading
Loading
Loading
+18 −34
Original line number Diff line number Diff line
@@ -1589,44 +1589,29 @@ ConversionResult<int32_t> legacy2aidl_audio_output_flags_t_int32_t_mask(
}

ConversionResult<audio_io_flags> aidl2legacy_AudioIoFlags_audio_io_flags(
        const AudioIoFlags& aidl, media::AudioPortRole role, media::AudioPortType type) {
        const AudioIoFlags& aidl, bool isInput) {
    audio_io_flags legacy;
    Direction dir = VALUE_OR_RETURN(direction(role, type));
    switch (dir) {
        case Direction::INPUT: {
    if (isInput) {
        legacy.input = VALUE_OR_RETURN(
                aidl2legacy_int32_t_audio_input_flags_t_mask(
                        VALUE_OR_RETURN(UNION_GET(aidl, input))));
        }
            break;

        case Direction::OUTPUT: {
    } else {
        legacy.output = VALUE_OR_RETURN(
                aidl2legacy_int32_t_audio_output_flags_t_mask(
                        VALUE_OR_RETURN(UNION_GET(aidl, output))));
    }
            break;
    }

    return legacy;
}

ConversionResult<AudioIoFlags> legacy2aidl_audio_io_flags_AudioIoFlags(
        const audio_io_flags& legacy, audio_port_role_t role, audio_port_type_t type) {
        const audio_io_flags& legacy, bool isInput) {
    AudioIoFlags aidl;

    Direction dir = VALUE_OR_RETURN(direction(role, type));
    switch (dir) {
        case Direction::INPUT:
    if (isInput) {
        UNION_SET(aidl, input,
                      VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(
                              legacy.input)));
            break;
        case Direction::OUTPUT:
                VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(legacy.input)));
    } else {
        UNION_SET(aidl, output,
                      VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(
                              legacy.output)));
            break;
                VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(legacy.output)));
    }
    return aidl;
}
@@ -2000,8 +1985,7 @@ ConversionResult<audio_port_config> aidl2legacy_AudioPortConfig_audio_port_confi
    }
    if (aidl.hal.flags.has_value()) {
        legacy.flags = VALUE_OR_RETURN(
                aidl2legacy_AudioIoFlags_audio_io_flags(
                        aidl.hal.flags.value(), aidl.sys.role, aidl.sys.type));
                aidl2legacy_AudioIoFlags_audio_io_flags(aidl.hal.flags.value(), isInput));
        legacy.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
    }
    legacy.ext = VALUE_OR_RETURN(
@@ -2037,7 +2021,7 @@ ConversionResult<media::AudioPortConfig> legacy2aidl_audio_port_config_AudioPort
    }
    if (legacy.config_mask & AUDIO_PORT_CONFIG_FLAGS) {
        aidl.hal.flags = VALUE_OR_RETURN(
                legacy2aidl_audio_io_flags_AudioIoFlags(legacy.flags, legacy.role, legacy.type));
                legacy2aidl_audio_io_flags_AudioIoFlags(legacy.flags, isInput));
    }
    RETURN_IF_ERROR(legacy2aidl_AudioPortExt(legacy.ext, legacy.type, legacy.role,
                    &aidl.hal.ext, &aidl.sys.ext));
+2 −3
Original line number Diff line number Diff line
@@ -194,10 +194,9 @@ ConversionResult<int32_t> legacy2aidl_audio_output_flags_t_int32_t_mask(
        audio_output_flags_t legacy);

ConversionResult<audio_io_flags> aidl2legacy_AudioIoFlags_audio_io_flags(
        const media::audio::common::AudioIoFlags& aidl,
        media::AudioPortRole role, media::AudioPortType type);
        const media::audio::common::AudioIoFlags& aidl, bool isInput);
ConversionResult<media::audio::common::AudioIoFlags> legacy2aidl_audio_io_flags_AudioIoFlags(
        const audio_io_flags& legacy, audio_port_role_t role, audio_port_type_t type);
        const audio_io_flags& legacy, bool isInput);

ConversionResult<audio_port_config_device_ext>
aidl2legacy_AudioPortDeviceExt_audio_port_config_device_ext(
+36 −14
Original line number Diff line number Diff line
@@ -24,6 +24,22 @@

namespace android {

void AudioPort::setFlags(uint32_t flags)
{
    // force direct flag if offload flag is set: offloading implies a direct output stream
    // and all common behaviors are driven by checking only the direct flag
    // this should normally be set appropriately in the policy configuration file
    if (mRole == AUDIO_PORT_ROLE_SOURCE &&
            (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
        flags |= AUDIO_OUTPUT_FLAG_DIRECT;
    }
    if (useInputChannelMask()) {
        mFlags.input = static_cast<audio_input_flags_t>(flags);
    } else {
        mFlags.output = static_cast<audio_output_flags_t>(flags);
    }
}

void AudioPort::importAudioPort(const sp<AudioPort>& port, bool force __unused)
{
    for (const auto& profileToImport : port->mProfiles) {
@@ -195,16 +211,10 @@ bool AudioPort::equals(const sp<AudioPort> &other) const
           mType == other->getType() &&
           mRole == other->getRole() &&
           mProfiles.equals(other->getAudioProfiles()) &&
           getFlags() == other->getFlags() &&
           mExtraAudioDescriptors == other->getExtraAudioDescriptors();
}

status_t AudioPort::writeToParcel(Parcel *parcel) const
{
    media::AudioPort parcelable;
    return writeToParcelable(&parcelable)
        ?: parcelable.writeToParcel(parcel);
}

status_t AudioPort::writeToParcelable(media::AudioPort* parcelable) const {
    parcelable->hal.name = mName;
    parcelable->sys.type = VALUE_OR_RETURN_STATUS(
@@ -215,6 +225,8 @@ status_t AudioPort::writeToParcelable(media::AudioPort* parcelable) const {
            legacy2aidl_AudioProfileVector(mProfiles, useInputChannelMask()));
    parcelable->hal.profiles = aidlProfiles.first;
    parcelable->sys.profiles = aidlProfiles.second;
    parcelable->hal.flags = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_io_flags_AudioIoFlags(mFlags, useInputChannelMask()));
    parcelable->hal.extraAudioDescriptors = mExtraAudioDescriptors;
    auto aidlGains = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioGains(mGains));
    parcelable->hal.gains = aidlGains.first;
@@ -230,12 +242,6 @@ status_t AudioPort::writeToParcelable(media::AudioPort* parcelable) const {
    return OK;
}

status_t AudioPort::readFromParcel(const Parcel *parcel) {
    media::AudioPort parcelable;
    return parcelable.readFromParcel(parcel)
        ?: readFromParcelable(parcelable);
}

status_t AudioPort::readFromParcelable(const media::AudioPort& parcelable) {
    mName = parcelable.hal.name;
    mType = VALUE_OR_RETURN_STATUS(
@@ -246,6 +252,8 @@ status_t AudioPort::readFromParcelable(const media::AudioPort& parcelable) {
            aidl2legacy_AudioProfileVector(
                    std::make_pair(parcelable.hal.profiles, parcelable.sys.profiles),
                    useInputChannelMask()));
    mFlags = VALUE_OR_RETURN_STATUS(
            aidl2legacy_AudioIoFlags_audio_io_flags(parcelable.hal.flags, useInputChannelMask()));
    mExtraAudioDescriptors = parcelable.hal.extraAudioDescriptors;
    mGains = VALUE_OR_RETURN_STATUS(
            aidl2legacy_AudioGains(std::make_pair(parcelable.hal.gains, parcelable.sys.gains)));
@@ -277,6 +285,9 @@ status_t AudioPortConfig::applyAudioPortConfig(
    if (config->config_mask & AUDIO_PORT_CONFIG_GAIN) {
        mGain = config->gain;
    }
    if (config->config_mask & AUDIO_PORT_CONFIG_FLAGS) {
        mFlags = config->flags;
    }

    return NO_ERROR;
}
@@ -330,6 +341,9 @@ void AudioPortConfig::toAudioPortConfig(
    } else {
        dstConfig->config_mask &= ~AUDIO_PORT_CONFIG_GAIN;
    }

    updateField(mFlags, &audio_port_config::flags,
            dstConfig, srcConfig, AUDIO_PORT_CONFIG_FLAGS, { AUDIO_INPUT_FLAG_NONE });
}

bool AudioPortConfig::hasGainController(bool canUseForVolume) const
@@ -342,12 +356,14 @@ bool AudioPortConfig::hasGainController(bool canUseForVolume) const
                           : audioport->getGains().size() > 0;
}

bool AudioPortConfig::equals(const sp<AudioPortConfig> &other) const
bool AudioPortConfig::equals(const sp<AudioPortConfig> &other, bool isInput) const
{
    return other != nullptr &&
           mSamplingRate == other->getSamplingRate() &&
           mFormat == other->getFormat() &&
           mChannelMask == other->getChannelMask() &&
           (isInput ? mFlags.input == other->getFlags().input :
                   mFlags.output == other->getFlags().output )&&
           // Compare audio gain config
           mGain.index == other->mGain.index &&
           mGain.mode == other->mGain.mode &&
@@ -370,6 +386,8 @@ status_t AudioPortConfig::writeToParcelable(
    media::audio::common::AudioGainConfig aidl_gain = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_gain_config_AudioGainConfig(mGain, isInput));
    parcelable->gain = aidl_gain;
    parcelable->flags = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_io_flags_AudioIoFlags(mFlags, isInput));
    return OK;
}

@@ -393,6 +411,10 @@ status_t AudioPortConfig::readFromParcelable(
        mGain = VALUE_OR_RETURN_STATUS(
                aidl2legacy_AudioGainConfig_audio_gain_config(parcelable.gain.value(), isInput));
    }
    if (parcelable.flags.has_value()) {
        mFlags = VALUE_OR_RETURN_STATUS(
                aidl2legacy_AudioIoFlags_audio_io_flags(parcelable.flags.value(), isInput));
    }
    return OK;
}

+1 −15
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ bool DeviceDescriptorBase::equals(const sp<DeviceDescriptorBase> &other) const
{
    return other != nullptr &&
           static_cast<const AudioPort*>(this)->equals(other) &&
           static_cast<const AudioPortConfig*>(this)->equals(other) &&
           static_cast<const AudioPortConfig*>(this)->equals(other, useInputChannelMask()) &&
           mDeviceTypeAddr.equals(other->mDeviceTypeAddr) &&
           checkEqual(mEncodedFormats, other->mEncodedFormats);
}
@@ -183,14 +183,6 @@ bool DeviceDescriptorBase::supportsFormat(audio_format_t format)
    return false;
}


status_t DeviceDescriptorBase::writeToParcel(Parcel *parcel) const
{
    media::AudioPort parcelable;
    return writeToParcelable(&parcelable)
        ?: parcelable.writeToParcel(parcel);
}

status_t DeviceDescriptorBase::writeToParcelable(media::AudioPort* parcelable) const {
    AudioPort::writeToParcelable(parcelable);
    AudioPortConfig::writeToParcelable(&parcelable->hal.activeConfig, useInputChannelMask());
@@ -212,12 +204,6 @@ status_t DeviceDescriptorBase::writeToParcelable(media::AudioPort* parcelable) c
    return OK;
}

status_t DeviceDescriptorBase::readFromParcel(const Parcel *parcel) {
    media::AudioPort parcelable;
    return parcelable.readFromParcel(parcel)
        ?: readFromParcelable(parcelable);
}

status_t DeviceDescriptorBase::readFromParcelable(const media::AudioPort& parcelable) {
    if (parcelable.sys.type != media::AudioPortType::DEVICE) {
        return BAD_VALUE;
+23 −5
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@

namespace android {

class AudioPort : public virtual RefBase, public virtual Parcelable
class AudioPort : public virtual RefBase
{
public:
    AudioPort(const std::string& name, audio_port_type_t type,  audio_port_role_t role) :
@@ -47,6 +47,9 @@ public:
    audio_port_type_t getType() const { return mType; }
    audio_port_role_t getRole() const { return mRole; }

    virtual void setFlags(uint32_t flags);
    uint32_t getFlags() const { return useInputChannelMask() ? mFlags.input : mFlags.output; }

    void setGains(const AudioGains &gains) { mGains = gains; }
    const AudioGains &getGains() const { return mGains; }

@@ -93,15 +96,27 @@ public:
                ((mType == AUDIO_PORT_TYPE_MIX) && (mRole == AUDIO_PORT_ROLE_SINK));
    }

    bool isDirectOutput() const
    {
        return (mType == AUDIO_PORT_TYPE_MIX) && (mRole == AUDIO_PORT_ROLE_SOURCE) &&
                ((mFlags.output & AUDIO_OUTPUT_FLAG_DIRECT) != 0);
    }

    bool isMmap() const
    {
        return (mType == AUDIO_PORT_TYPE_MIX)
                && (((mRole == AUDIO_PORT_ROLE_SOURCE) &&
                        ((mFlags.output & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) != 0))
                    || ((mRole == AUDIO_PORT_ROLE_SINK) &&
                        ((mFlags.input & AUDIO_INPUT_FLAG_MMAP_NOIRQ) != 0)));
    }

    void dump(std::string *dst, int spaces, bool verbose = true) const;

    void log(const char* indent) const;

    bool equals(const sp<AudioPort>& other) const;

    status_t writeToParcel(Parcel* parcel) const override;
    status_t readFromParcel(const Parcel* parcel) override;

    status_t writeToParcelable(media::AudioPort* parcelable) const;
    status_t readFromParcelable(const media::AudioPort& parcelable);

@@ -130,6 +145,7 @@ protected:
    // Audio capabilities that are defined by hardware descriptors when the format is unrecognized
    // by the platform, e.g. short audio descriptor in EDID for HDMI.
    std::vector<media::audio::common::ExtraAudioDescriptor> mExtraAudioDescriptors;
    union audio_io_flags mFlags = { .output = AUDIO_OUTPUT_FLAG_NONE };
private:
    template <typename T, std::enable_if_t<std::is_same<T, struct audio_port>::value
                                        || std::is_same<T, struct audio_port_v7>::value, int> = 0>
@@ -162,10 +178,11 @@ public:
    audio_format_t getFormat() const { return mFormat; }
    audio_channel_mask_t getChannelMask() const { return mChannelMask; }
    audio_port_handle_t getId() const { return mId; }
    audio_io_flags getFlags() const { return mFlags; }

    bool hasGainController(bool canUseForVolume = false) const;

    bool equals(const sp<AudioPortConfig>& other) const;
    bool equals(const sp<AudioPortConfig>& other, bool isInput) const;

    status_t writeToParcelable(
            media::audio::common::AudioPortConfig* parcelable, bool isInput) const;
@@ -178,6 +195,7 @@ protected:
    audio_channel_mask_t mChannelMask = AUDIO_CHANNEL_NONE;
    audio_port_handle_t mId = AUDIO_PORT_HANDLE_NONE;
    struct audio_gain_config mGain = { .index = -1 };
    union audio_io_flags mFlags = { AUDIO_INPUT_FLAG_NONE };
};

} // namespace android
Loading