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

Commit bcfd6df4 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge changes Ie37a2d9d,I3ed8c7d7,I6ed11be0,Idc2e1ccd

* changes:
  audiopolicy: common: add several helper function on DeviceDesc
  audiopolicy: update type convertion library
  audiopolicy: apm: connectAudioSource: use Sw brigding according to hal support
  audiopolicy: Fix sofware bridge creation for AudioHAL supporting routing APIs
parents 762365c3 aca677cf
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -285,6 +285,7 @@ const GainModeConverter::Table GainModeConverter::mTable[] = {

template <>
const StreamTypeConverter::Table StreamTypeConverter::mTable[] = {
    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_DEFAULT),
    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_VOICE_CALL),
    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_SYSTEM),
    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_RING),
@@ -361,6 +362,22 @@ const SourceTypeConverter::Table SourceTypeConverter::mTable[] = {
    TERMINATOR
};

template <>
const AudioFlagConverter::Table AudioFlagConverter::mTable[] = {
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_NONE),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_AUDIBILITY_ENFORCED),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_SECURE),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_SCO),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BEACON),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_HW_AV_SYNC),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_HW_HOTWORD),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BYPASS_MUTE),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_LOW_LATENCY),
    MAKE_STRING_FROM_ENUM(AUDIO_FLAG_DEEP_BUFFER),
    TERMINATOR
};

template class TypeConverter<OutputDeviceTraits>;
template class TypeConverter<InputDeviceTraits>;
template class TypeConverter<OutputFlagTraits>;
@@ -374,6 +391,7 @@ template class TypeConverter<StreamTraits>;
template class TypeConverter<AudioModeTraits>;
template class TypeConverter<UsageTraits>;
template class TypeConverter<SourceTraits>;
template class TypeConverter<AudioFlagTraits>;

bool deviceFromString(const std::string& literalDevice, audio_devices_t& device) {
    return InputDeviceConverter::fromString(literalDevice, device) ||
+106 −62
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <string>
#include <string.h>

#include <vector>
#include <system/audio.h>
#include <utils/Log.h>
#include <utils/Vector.h>
@@ -30,77 +31,55 @@

namespace android {

struct SampleRateTraits
{
    typedef uint32_t Type;
    typedef SortedVector<Type> Collection;
};
struct DeviceTraits
template <typename T>
struct DefaultTraits
{
    typedef audio_devices_t Type;
    typedef Vector<Type> Collection;
};
struct OutputDeviceTraits : public DeviceTraits {};
struct InputDeviceTraits : public DeviceTraits {};
struct OutputFlagTraits
    typedef T Type;
    typedef std::vector<Type> Collection;
    static void add(Collection &collection, Type value)
    {
    typedef audio_output_flags_t Type;
    typedef Vector<Type> Collection;
        collection.push_back(value);
    }
};
struct InputFlagTraits
template <typename T>
struct VectorTraits
{
    typedef audio_input_flags_t Type;
    typedef T Type;
    typedef Vector<Type> Collection;
};
struct FormatTraits
    static void add(Collection &collection, Type value)
    {
    typedef audio_format_t Type;
    typedef Vector<Type> Collection;
        collection.add(value);
    }
};
struct ChannelTraits
template <typename T>
struct SortedVectorTraits
{
    typedef audio_channel_mask_t Type;
    typedef T Type;
    typedef SortedVector<Type> Collection;
    static void add(Collection &collection, Type value)
    {
        collection.add(value);
    }
};

using SampleRateTraits = SortedVectorTraits<uint32_t>;
using DeviceTraits = DefaultTraits<audio_devices_t>;
struct OutputDeviceTraits : public DeviceTraits {};
struct InputDeviceTraits : public DeviceTraits {};
using ChannelTraits = SortedVectorTraits<audio_channel_mask_t>;
struct OutputChannelTraits : public ChannelTraits {};
struct InputChannelTraits : public ChannelTraits {};
struct ChannelIndexTraits : public ChannelTraits {};
struct GainModeTraits
{
    typedef audio_gain_mode_t Type;
    typedef Vector<Type> Collection;
};
struct StreamTraits
{
    typedef audio_stream_type_t Type;
    typedef Vector<Type> Collection;
};
struct AudioModeTraits
{
    typedef audio_mode_t Type;
    typedef Vector<Type> Collection;
};
struct AudioContentTraits
{
    typedef audio_content_type_t Type;
    typedef Vector<Type> Collection;
};
struct UsageTraits
{
    typedef audio_usage_t Type;
    typedef Vector<Type> Collection;
};
struct SourceTraits
{
    typedef audio_source_t Type;
    typedef Vector<Type> Collection;
};
template <typename T>
struct DefaultTraits
{
    typedef T Type;
    typedef Vector<Type> Collection;
};
using InputFlagTraits = DefaultTraits<audio_input_flags_t>;
using OutputFlagTraits = DefaultTraits<audio_output_flags_t>;
using FormatTraits = VectorTraits<audio_format_t>;
using GainModeTraits = DefaultTraits<audio_gain_mode_t>;
using StreamTraits = DefaultTraits<audio_stream_type_t>;
using AudioModeTraits = DefaultTraits<audio_mode_t>;
using AudioContentTraits = DefaultTraits<audio_content_type_t>;
using UsageTraits = DefaultTraits<audio_usage_t>;
using SourceTraits = DefaultTraits<audio_source_t>;
struct AudioFlagTraits : public DefaultTraits<audio_flags_mask_t> {};

template <class Traits>
static void collectionFromString(const std::string &str, typename Traits::Collection &collection,
@@ -110,7 +89,7 @@ static void collectionFromString(const std::string &str, typename Traits::Collec
    for (const char *cstr = strtok(literal, del); cstr != NULL; cstr = strtok(NULL, del)) {
        typename Traits::Type value;
        if (utilities::convertTo<std::string, typename Traits::Type >(cstr, value)) {
            collection.add(value);
            Traits::add(collection, value);
        }
    }
    free(literal);
@@ -181,7 +160,7 @@ inline void TypeConverter<Traits>::collectionFromString(const std::string &str,
    for (const char *cstr = strtok(literal, del); cstr != NULL; cstr = strtok(NULL, del)) {
        typename Traits::Type value;
        if (fromString(cstr, value)) {
            collection.add(value);
            Traits::add(collection, value);
        }
    }
    free(literal);
@@ -234,6 +213,7 @@ typedef TypeConverter<AudioModeTraits> AudioModeConverter;
typedef TypeConverter<AudioContentTraits> AudioContentTypeConverter;
typedef TypeConverter<UsageTraits> UsageTypeConverter;
typedef TypeConverter<SourceTraits> SourceTypeConverter;
typedef TypeConverter<AudioFlagTraits> AudioFlagConverter;

template<> const OutputDeviceConverter::Table OutputDeviceConverter::mTable[];
template<> const InputDeviceConverter::Table InputDeviceConverter::mTable[];
@@ -249,6 +229,7 @@ template<> const AudioModeConverter::Table AudioModeConverter::mTable[];
template<> const AudioContentTypeConverter::Table AudioContentTypeConverter::mTable[];
template<> const UsageTypeConverter::Table UsageTypeConverter::mTable[];
template<> const SourceTypeConverter::Table SourceTypeConverter::mTable[];
template<> const AudioFlagConverter::Table AudioFlagConverter::mTable[];

bool deviceFromString(const std::string& literalDevice, audio_devices_t& device);

@@ -274,6 +255,69 @@ InputChannelTraits::Collection inputChannelMasksFromString(
OutputChannelTraits::Collection outputChannelMasksFromString(
        const std::string &outChannels, const char *del = AudioParameter::valueListSeparator);

static inline std::string toString(audio_usage_t usage)
{
    std::string usageLiteral;
    if (!android::UsageTypeConverter::toString(usage, usageLiteral)) {
        ALOGV("failed to convert usage: %d", usage);
        return "AUDIO_USAGE_UNKNOWN";
    }
    return usageLiteral;
}

static inline std::string toString(audio_content_type_t content)
{
    std::string contentLiteral;
    if (!android::AudioContentTypeConverter::toString(content, contentLiteral)) {
        ALOGV("failed to convert content type: %d", content);
        return "AUDIO_CONTENT_TYPE_UNKNOWN";
    }
    return contentLiteral;
}

static inline std::string toString(audio_stream_type_t stream)
{
    std::string streamLiteral;
    if (!android::StreamTypeConverter::toString(stream, streamLiteral)) {
        ALOGV("failed to convert stream: %d", stream);
        return "AUDIO_STREAM_DEFAULT";
    }
    return streamLiteral;
}

static inline std::string toString(audio_source_t source)
{
    std::string sourceLiteral;
    if (!android::SourceTypeConverter::toString(source, sourceLiteral)) {
        ALOGV("failed to convert source: %d", source);
        return "AUDIO_SOURCE_DEFAULT";
    }
    return sourceLiteral;
}

static inline std::string toString(const audio_attributes_t &attributes)
{
    std::ostringstream result;
    result << "{ Content type: " << toString(attributes.content_type)
           << " Usage: " << toString(attributes.usage)
           << " Source: " << toString(attributes.source)
           << " Flags: " << attributes.flags
           << " Tags: " << attributes.tags
           << " }";

    return result.str();
}

static inline std::string toString(audio_mode_t mode)
{
    std::string modeLiteral;
    if (!android::AudioModeConverter::toString(mode, modeLiteral)) {
        ALOGV("failed to convert mode: %d", mode);
        return "AUDIO_MODE_INVALID";
    }
    return modeLiteral;
}

}; // namespace android

#endif  /*ANDROID_TYPE_CONVERTER_H_*/
+2 −1
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public:
    audio_module_handle_t getModuleHandle() const;
    uint32_t getModuleVersionMajor() const;
    const char *getModuleName() const;
    sp<HwModule> getModule() const { return mModule; }

    bool useInputChannelMask() const
    {
@@ -137,12 +138,12 @@ public:
    void log(const char* indent) const;

    AudioGainCollection mGains; // gain controllers
    sp<HwModule> mModule;                 // audio HW module exposing this I/O stream

private:
    void pickChannelMask(audio_channel_mask_t &channelMask, const ChannelsVector &channelMasks) const;
    void pickSamplingRate(uint32_t &rate,const SampleRateVector &samplingRates) const;

    sp<HwModule> mModule;                 // audio HW module exposing this I/O stream
    String8  mName;
    audio_port_type_t mType;
    audio_port_role_t mRole;
+13 −0
Original line number Diff line number Diff line
@@ -46,6 +46,19 @@ public:

    audio_route_type_t getType() const { return mType; }

    /**
     * @brief supportsPatch checks if an audio patch is supported by a Route declared in
     * the audio_policy_configuration.xml file.
     * If the patch is supported natively by an AudioHAL (which supports of course Routing API 3.0),
     * audiopolicy will not request AudioFlinger to use a software bridge to realize a patch
     * between 2 ports.
     * @param srcPort (aka the source) to be considered
     * @param dstPort (aka the sink) to be considered
     * @return true if the audio route supports the connection between the sink and the source,
     * false otherwise
     */
    bool supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const;

    void dump(String8 *dst, int spaces) const;

private:
+82 −6
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public:
    virtual const String8 getTagName() const { return mTagName; }

    audio_devices_t type() const { return mDeviceType; }
    String8 address() const { return mAddress; }
    void setAddress(const String8 &address) { mAddress = address; }

    const FormatVector& encodedFormats() const { return mEncodedFormats; }

@@ -57,39 +59,113 @@ public:
    audio_port_handle_t getId() const;
    void dump(String8 *dst, int spaces, int index, bool verbose = true) const;
    void log() const;

    String8 mAddress;
    std::string toString() const;

private:
    String8 mAddress{""};
    String8 mTagName; // Unique human readable identifier for a device port found in conf file.
    audio_devices_t     mDeviceType;
    FormatVector        mEncodedFormats;
    audio_port_handle_t mId;

friend class DeviceVector;
    audio_port_handle_t mId = AUDIO_PORT_HANDLE_NONE;
};

class DeviceVector : public SortedVector<sp<DeviceDescriptor> >
{
public:
    DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {}
    explicit DeviceVector(const sp<DeviceDescriptor>& item) : DeviceVector()
    {
        add(item);
    }

    ssize_t add(const sp<DeviceDescriptor>& item);
    void add(const DeviceVector &devices);
    ssize_t remove(const sp<DeviceDescriptor>& item);
    void remove(const DeviceVector &devices);
    ssize_t indexOf(const sp<DeviceDescriptor>& item) const;

    audio_devices_t types() const { return mDeviceTypes; }

    // If 'address' is empty, a device with a non-empty address may be returned
    // if there is no device with the specified 'type' and empty address.
    sp<DeviceDescriptor> getDevice(audio_devices_t type, const String8 &address) const;
    sp<DeviceDescriptor> getDevice(audio_devices_t type, const String8 &address = {}) const;
    DeviceVector getDevicesFromTypeMask(audio_devices_t types) const;

    /**
     * @brief getDeviceFromId
     * @param id of the DeviceDescriptor to seach (aka Port handle).
     * @return DeviceDescriptor associated to port id if found, nullptr otherwise. If the id is
     * equal to AUDIO_PORT_HANDLE_NONE, it also returns a nullptr.
     */
    sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
    sp<DeviceDescriptor> getDeviceFromTagName(const String8 &tagName) const;
    DeviceVector getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
    audio_devices_t getDeviceTypesFromHwModule(audio_module_handle_t moduleHandle) const;

    bool contains(const sp<DeviceDescriptor>& item) const { return indexOf(item) >= 0; }

    /**
     * @brief containsAtLeastOne
     * @param devices vector of devices to check against.
     * @return true if the DeviceVector contains at list one of the devices from the given vector.
     */
    bool containsAtLeastOne(const DeviceVector &devices) const;

    /**
     * @brief containsAllDevices
     * @param devices vector of devices to check against.
     * @return true if the DeviceVector contains all the devices from the given vector
     */
    bool containsAllDevices(const DeviceVector &devices) const;

    /**
     * @brief filter the devices supported by this collection against another collection
     * @param devices to filter against
     * @return
     */
    DeviceVector filter(const DeviceVector &devices) const;

    /**
     * @brief merge two vectors. As SortedVector Implementation is buggy (it does not check the size
     * of the destination vector, only of the source, it provides a safe implementation
     * @param devices source device vector to merge with
     * @return size of the merged vector.
     */
    ssize_t merge(const DeviceVector &devices)
    {
        if (isEmpty()) {
            add(devices);
            return size();
        }
        return SortedVector::merge(devices);
    }

    /**
     * @brief operator == DeviceVector are equals if all the DeviceDescriptor can be found (aka
     * DeviceDescriptor with same type and address) and the vector has same size.
     * @param right DeviceVector to compare to.
     * @return true if right contains the same device and has the same size.
     */
    bool operator==(const DeviceVector &right) const
    {
        if (size() != right.size()) {
            return false;
        }
        for (const auto &device : *this) {
            if (right.indexOf(device) < 0) {
                return false;
            }
        }
        return true;
    }

    bool operator!=(const DeviceVector &right) const
    {
        return !operator==(right);
    }

    std::string toString() const;

    void dump(String8 *dst, const String8 &tag, int spaces = 0, bool verbose = true) const;

private:
Loading