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

Commit 5a7913b4 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Add utility functions to AudioProfile

Added AudioProfileVector::getFirstValidProfileFor for retrieving
first valid profile supporting the given format.

Added ChannelsVector::as{In|Out}Mask for reversing direction on all
contained channel masks.

Bug: 63901775
Test: make
Change-Id: Ib4a816abd9a3904a552f670ee75266e7dd890011
parent fa4fd528
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
namespace android {

typedef SortedVector<uint32_t> SampleRateVector;
typedef SortedVector<audio_channel_mask_t> ChannelsVector;
typedef Vector<audio_format_t> FormatVector;

template <typename T>
@@ -50,6 +49,21 @@ bool operator!= (const SortedVector<T> &left, const SortedVector<T> &right)
    return !(left == right);
}

class ChannelsVector : public SortedVector<audio_channel_mask_t>
{
public:
    ChannelsVector() = default;
    ChannelsVector(const ChannelsVector&) = default;
    ChannelsVector(const SortedVector<audio_channel_mask_t>& sv) :
            SortedVector<audio_channel_mask_t>(sv) {}
    ChannelsVector& operator=(const ChannelsVector&) = default;

    // Applies audio_channel_mask_out_to_in to all elements and returns the result.
    ChannelsVector asInMask() const;
    // Applies audio_channel_mask_in_to_out to all elements and returns the result.
    ChannelsVector asOutMask() const;
};

class AudioProfile : public virtual RefBase
{
public:
@@ -211,6 +225,16 @@ public:
        return 0;
    }

    sp<AudioProfile> getFirstValidProfileFor(audio_format_t format) const
    {
        for (size_t i = 0; i < size(); i++) {
            if (itemAt(i)->isValid() && itemAt(i)->getFormat() == format) {
                return itemAt(i);
            }
        }
        return 0;
    }

    bool hasValidProfile() const { return getFirstValidProfile() != 0; }

    status_t checkExactProfile(uint32_t samplingRate, audio_channel_mask_t channelMask,
+22 −0
Original line number Diff line number Diff line
@@ -28,6 +28,28 @@

namespace android {

ChannelsVector ChannelsVector::asInMask() const
{
    ChannelsVector inMaskVector;
    for (const auto& channel : *this) {
        if (audio_channel_mask_out_to_in(channel) != AUDIO_CHANNEL_INVALID) {
            inMaskVector.add(audio_channel_mask_out_to_in(channel));
        }
    }
    return inMaskVector;
}

ChannelsVector ChannelsVector::asOutMask() const
{
    ChannelsVector outMaskVector;
    for (const auto& channel : *this) {
        if (audio_channel_mask_in_to_out(channel) != AUDIO_CHANNEL_INVALID) {
            outMaskVector.add(audio_channel_mask_in_to_out(channel));
        }
    }
    return outMaskVector;
}

static AudioProfile* createFullDynamicImpl()
{
    AudioProfile* dynamicProfile = new AudioProfile(gDynamicFormat,