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

Commit 2b167173 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: update type convertion library



Test: Audio smoke tests.
Test: CTS tests for AudioRecord, AudioTrack and AudioEffect

Change-Id: I3ed8c7d7ee8a97f0bd41a5ae9f28d673994d7f07
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 83d789d6
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_*/
+4 −20
Original line number Diff line number Diff line
@@ -23,26 +23,10 @@

namespace android {

struct DeviceCategoryTraits
{
    typedef device_category Type;
    typedef Vector<Type> Collection;
};
struct MixTypeTraits
{
    typedef int32_t Type;
    typedef Vector<Type> Collection;
};
struct RouteFlagTraits
{
    typedef uint32_t Type;
    typedef Vector<Type> Collection;
};
struct RuleTraits
{
    typedef uint32_t Type;
    typedef Vector<Type> Collection;
};
struct RuleTraits : public DefaultTraits<uint32_t> {};
using DeviceCategoryTraits = DefaultTraits<device_category>;
struct MixTypeTraits : public DefaultTraits<int32_t> {};
struct RouteFlagTraits : public DefaultTraits<uint32_t> {};

typedef TypeConverter<DeviceCategoryTraits> DeviceCategoryConverter;
typedef TypeConverter<MixTypeTraits> MixTypeConverter;
+1 −1
Original line number Diff line number Diff line
@@ -742,7 +742,7 @@ Return<VolumeTraits::Element> VolumeTraits::deserialize(const xmlNode *cur,
            }
            ALOGV("%s: %s=%s",
                    __func__, tag, reinterpret_cast<const char*>(pointDefinition.get()));
            Vector<int32_t> point;
            std::vector<int32_t> point;
            collectionFromString<DefaultTraits<int32_t>>(
                    reinterpret_cast<const char*>(pointDefinition.get()), point, ",");
            if (point.size() != 2) {