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

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

audiopolicy: moves Stream Volume Curves to Engine



This CL moves the volume curves to the engine.
The configuration files of volume are now owned by the engine,
that is intended to become vendor specific.

Test: build, dumpsys media.audio_policy and checks the volume curves.
Bug: 124767636

Change-Id: I9e3b256d2eb89c8eac6b282db0e59ec3af47d76d
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 7a2f8152
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ cc_library_static {
        "src/Serializer.cpp",
        "src/SoundTriggerSession.cpp",
        "src/TypeConverter.cpp",
        "src/VolumeCurve.cpp",
    ],
    shared_libs: [
        "libcutils",
+1 −12
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
#include <unordered_set>

#include <AudioGain.h>
#include <VolumeCurve.h>
#include <AudioPort.h>
#include <AudioPatch.h>
#include <DeviceDescriptor.h>
@@ -40,13 +39,11 @@ public:
    AudioPolicyConfig(HwModuleCollection &hwModules,
                      DeviceVector &availableOutputDevices,
                      DeviceVector &availableInputDevices,
                      sp<DeviceDescriptor> &defaultOutputDevice,
                      VolumeCurvesCollection *volumes = nullptr)
                      sp<DeviceDescriptor> &defaultOutputDevice)
        : mHwModules(hwModules),
          mAvailableOutputDevices(availableOutputDevices),
          mAvailableInputDevices(availableInputDevices),
          mDefaultOutputDevice(defaultOutputDevice),
          mVolumeCurves(volumes),
          mIsSpeakerDrcEnabled(false)
    {}

@@ -58,13 +55,6 @@ public:
        mSource = file;
    }

    void setVolumes(const VolumeCurvesCollection &volumes)
    {
        if (mVolumeCurves != nullptr) {
            *mVolumeCurves = volumes;
        }
    }

    void setHwModules(const HwModuleCollection &hwModules)
    {
        mHwModules = hwModules;
@@ -182,7 +172,6 @@ private:
    DeviceVector &mAvailableOutputDevices;
    DeviceVector &mAvailableInputDevices;
    sp<DeviceDescriptor> &mDefaultOutputDevice;
    VolumeCurvesCollection *mVolumeCurves;
    // TODO: remove when legacy conf file is removed. true on devices that use DRC on the
    // DEVICE_CATEGORY_SPEAKER path to boost soft sounds, used to adjust volume curves accordingly.
    // Note: remove also speaker_drc_enabled from global configuration of XML config file.
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Copyright (C) 2018 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.
@@ -20,35 +20,25 @@
#include <Volume.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <vector>

namespace android {

class IVolumeCurvesCollection
class IVolumeCurves
{
public:
    virtual ~IVolumeCurvesCollection() = default;

    virtual void clearCurrentVolumeIndex(audio_stream_type_t stream) = 0;
    virtual void addCurrentVolumeIndex(audio_stream_type_t stream, audio_devices_t device,
                                       int index) = 0;
    virtual bool canBeMuted(audio_stream_type_t stream) = 0;
    virtual int getVolumeIndexMin(audio_stream_type_t stream) const = 0;
    virtual int getVolumeIndex(audio_stream_type_t stream, audio_devices_t device) = 0;
    virtual int getVolumeIndexMax(audio_stream_type_t stream) const = 0;
    virtual float volIndexToDb(audio_stream_type_t stream, device_category device,
                               int indexInUi) const = 0;
    virtual status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax) = 0;

    virtual void initializeVolumeCurves(bool /*isSpeakerDrcEnabled*/) {}
    virtual void switchVolumeCurve(audio_stream_type_t src, audio_stream_type_t dst) = 0;
    virtual void restoreOriginVolumeCurve(audio_stream_type_t stream)
    {
        switchVolumeCurve(stream, stream);
    }
    virtual bool hasVolumeIndexForDevice(audio_stream_type_t stream,
                                         audio_devices_t device) const = 0;

    virtual void dump(String8 *dst) const = 0;
    virtual ~IVolumeCurves() = default;

    virtual void clearCurrentVolumeIndex() = 0;
    virtual void addCurrentVolumeIndex(audio_devices_t device, int index) = 0;
    virtual bool canBeMuted() const = 0;
    virtual int getVolumeIndexMin() const = 0;
    virtual int getVolumeIndex(audio_devices_t device) const = 0;
    virtual int getVolumeIndexMax() const = 0;
    virtual float volIndexToDb(device_category device, int indexInUi) const = 0;
    virtual bool hasVolumeIndexForDevice(audio_devices_t device) const = 0;
    virtual status_t initVolume(int indexMin, int indexMax) = 0;
    virtual void dump(String8 *dst, int spaces = 0, bool curvePoints = false) const = 0;
};

} // namespace android
+0 −88
Original line number Diff line number Diff line
@@ -201,25 +201,6 @@ struct GlobalConfigTraits
    static status_t deserialize(const xmlNode *root, AudioPolicyConfig *config);
};

struct VolumeTraits : public AndroidCollectionTraits<VolumeCurve, VolumeCurvesCollection>
{
    static constexpr const char *tag = "volume";
    static constexpr const char *collectionTag = "volumes";
    static constexpr const char *volumePointTag = "point";
    static constexpr const char *referenceTag = "reference";

    struct Attributes
    {
        static constexpr const char *stream = "stream";
        static constexpr const char *deviceCategory = "deviceCategory";
        static constexpr const char *reference = "ref";
        static constexpr const char *referenceName = "name";
    };

    static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext);
    // No Children
};

struct SurroundSoundTraits
{
    static constexpr const char *tag = "surroundSound";
@@ -703,67 +684,6 @@ status_t GlobalConfigTraits::deserialize(const xmlNode *root, AudioPolicyConfig
    return NO_ERROR;
}

Return<VolumeTraits::Element> VolumeTraits::deserialize(const xmlNode *cur,
        PtrSerializingCtx /*serializingContext*/)
{
    std::string streamTypeLiteral = getXmlAttribute(cur, Attributes::stream);
    if (streamTypeLiteral.empty()) {
        ALOGE("%s: No %s found", __func__, Attributes::stream);
        return Status::fromStatusT(BAD_VALUE);
    }
    audio_stream_type_t streamType;
    if (!StreamTypeConverter::fromString(streamTypeLiteral, streamType)) {
        ALOGE("%s: Invalid %s", __func__, Attributes::stream);
        return Status::fromStatusT(BAD_VALUE);
    }
    std::string deviceCategoryLiteral = getXmlAttribute(cur, Attributes::deviceCategory);
    if (deviceCategoryLiteral.empty()) {
        ALOGE("%s: No %s found", __func__, Attributes::deviceCategory);
        return Status::fromStatusT(BAD_VALUE);
    }
    device_category deviceCategory;
    if (!DeviceCategoryConverter::fromString(deviceCategoryLiteral, deviceCategory)) {
        ALOGE("%s: Invalid %s=%s", __func__, Attributes::deviceCategory,
              deviceCategoryLiteral.c_str());
        return Status::fromStatusT(BAD_VALUE);
    }

    std::string referenceName = getXmlAttribute(cur, Attributes::reference);
    const xmlNode *ref = NULL;
    if (!referenceName.empty()) {
        ref = getReference<VolumeTraits>(cur->parent, referenceName);
        if (ref == NULL) {
            ALOGE("%s: No reference Ptr found for %s", __func__, referenceName.c_str());
            return Status::fromStatusT(BAD_VALUE);
        }
    }

    Element volCurve = new VolumeCurve(deviceCategory, streamType);

    for (const xmlNode *child = referenceName.empty() ? cur->xmlChildrenNode : ref->xmlChildrenNode;
         child != NULL; child = child->next) {
        if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>(volumePointTag))) {
            auto pointDefinition = make_xmlUnique(xmlNodeListGetString(
                            child->doc, child->xmlChildrenNode, 1));
            if (pointDefinition == nullptr) {
                return Status::fromStatusT(BAD_VALUE);
            }
            ALOGV("%s: %s=%s",
                    __func__, tag, reinterpret_cast<const char*>(pointDefinition.get()));
            std::vector<int32_t> point;
            collectionFromString<DefaultTraits<int32_t>>(
                    reinterpret_cast<const char*>(pointDefinition.get()), point, ",");
            if (point.size() != 2) {
                ALOGE("%s: Invalid %s: %s", __func__, volumePointTag,
                        reinterpret_cast<const char*>(pointDefinition.get()));
                return Status::fromStatusT(BAD_VALUE);
            }
            volCurve->add(CurvePoint(point[0], point[1]));
        }
    }
    return volCurve;
}

status_t SurroundSoundTraits::deserialize(const xmlNode *root, AudioPolicyConfig *config)
{
    config->setDefaultSurroundFormats();
@@ -851,14 +771,6 @@ status_t PolicySerializer::deserialize(const char *configFile, AudioPolicyConfig
    }
    config->setHwModules(modules);

    // deserialize volume section
    VolumeTraits::Collection volumes;
    status = deserializeCollection<VolumeTraits>(root, &volumes, config);
    if (status != NO_ERROR) {
        return status;
    }
    config->setVolumes(volumes);

    // Global Configuration
    GlobalConfigTraits::deserialize(root, config);

+5 −1
Original line number Diff line number Diff line
@@ -191,7 +191,11 @@
    </modules>
    <!-- End of Modules section -->

    <!-- Volume section -->
    <!-- Volume section:
        IMPORTANT NOTE: Volume tables have been moved to engine configuration.
                        Keep it here for legacy.
                        Engine will fallback on these files if none are provided by engine.
     -->

    <xi:include href="audio_policy_volumes.xml"/>
    <xi:include href="default_volume_tables.xml"/>
Loading