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

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

[audioeffect] add support of device effect in config parser



Bug: 136294538
Test: build

Change-Id: I2c75b4bf6a4346362044696feabb35822c860efa
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 160863fd
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -13,6 +13,8 @@ cc_library {
    shared_libs: [
    shared_libs: [
        "liblog",
        "liblog",
        "libtinyxml2",
        "libtinyxml2",
        "libutils",
        "libmedia_helper",
    ],
    ],


    header_libs: ["libaudio_system_headers"],
    header_libs: ["libaudio_system_headers"],
+5 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,10 @@ struct Stream {
using OutputStream = Stream<audio_stream_type_t>;
using OutputStream = Stream<audio_stream_type_t>;
using InputStream = Stream<audio_source_t>;
using InputStream = Stream<audio_source_t>;


struct DeviceEffects : Stream<audio_devices_t> {
    std::string address;
};

/** Parsed configuration.
/** Parsed configuration.
 * Intended to be a transient structure only used for deserialization.
 * Intended to be a transient structure only used for deserialization.
 * Note: Everything is copied in the configuration from the xml dom.
 * Note: Everything is copied in the configuration from the xml dom.
@@ -89,6 +93,7 @@ struct Config {
    Effects effects;
    Effects effects;
    std::vector<OutputStream> postprocess;
    std::vector<OutputStream> postprocess;
    std::vector<InputStream> preprocess;
    std::vector<InputStream> preprocess;
    std::vector<DeviceEffects> deviceprocess;
};
};


/** Result of `parse(const char*)` */
/** Result of `parse(const char*)` */
+32 −3
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include <log/log.h>
#include <log/log.h>


#include <media/EffectsConfig.h>
#include <media/EffectsConfig.h>
#include <media/TypeConverter.h>


using namespace tinyxml2;
using namespace tinyxml2;


@@ -134,6 +135,11 @@ bool stringToStreamType(const char *streamName, Type* type)
    return false;
    return false;
}
}


template <>
bool stringToStreamType(const char *streamName, audio_devices_t* type) {
    return deviceFromString(streamName, *type);
}

/** Parse a library xml note and push the result in libraries or return false on failure. */
/** Parse a library xml note and push the result in libraries or return false on failure. */
bool parseLibrary(const XMLElement& xmlLibrary, Libraries* libraries) {
bool parseLibrary(const XMLElement& xmlLibrary, Libraries* libraries) {
    const char* name = xmlLibrary.Attribute("name");
    const char* name = xmlLibrary.Attribute("name");
@@ -221,7 +227,7 @@ bool parseEffect(const XMLElement& xmlEffect, Libraries& libraries, Effects* eff
    return true;
    return true;
}
}


/** Parse an stream from an xml element describing it.
/** Parse an <Output|Input>stream or a device from an xml element describing it.
 * @return true and pushes the stream in streams on success,
 * @return true and pushes the stream in streams on success,
 *         false on failure. */
 *         false on failure. */
template <class Stream>
template <class Stream>
@@ -233,14 +239,14 @@ bool parseStream(const XMLElement& xmlStream, Effects& effects, std::vector<Stre
    }
    }
    Stream stream;
    Stream stream;
    if (!stringToStreamType(streamType, &stream.type)) {
    if (!stringToStreamType(streamType, &stream.type)) {
        ALOGE("Invalid stream type %s: %s", streamType, dump(xmlStream));
        ALOGE("Invalid <stream|device> type %s: %s", streamType, dump(xmlStream));
        return false;
        return false;
    }
    }


    for (auto& xmlApply : getChildren(xmlStream, "apply")) {
    for (auto& xmlApply : getChildren(xmlStream, "apply")) {
        const char* effectName = xmlApply.get().Attribute("effect");
        const char* effectName = xmlApply.get().Attribute("effect");
        if (effectName == nullptr) {
        if (effectName == nullptr) {
            ALOGE("stream/apply must have reference an effect: %s", dump(xmlApply));
            ALOGE("<stream|device>/apply must have reference an effect: %s", dump(xmlApply));
            return false;
            return false;
        }
        }
        auto* effect = findByName(effectName, effects);
        auto* effect = findByName(effectName, effects);
@@ -254,6 +260,21 @@ bool parseStream(const XMLElement& xmlStream, Effects& effects, std::vector<Stre
    return true;
    return true;
}
}


bool parseDeviceEffects(
        const XMLElement& xmlDevice, Effects& effects, std::vector<DeviceEffects>* deviceEffects) {

    const char* address = xmlDevice.Attribute("address");
    if (address == nullptr) {
        ALOGE("device must have an address: %s", dump(xmlDevice));
        return false;
    }
    if (!parseStream(xmlDevice, effects, deviceEffects)) {
        return false;
    }
    deviceEffects->back().address = address;
    return true;
}

/** Internal version of the public parse(const char* path) where path always exist. */
/** Internal version of the public parse(const char* path) where path always exist. */
ParsingResult parseWithPath(std::string&& path) {
ParsingResult parseWithPath(std::string&& path) {
    XMLDocument doc;
    XMLDocument doc;
@@ -298,6 +319,14 @@ ParsingResult parseWithPath(std::string&& path) {
                registerFailure(parseStream(xmlStream, config->effects, &config->postprocess));
                registerFailure(parseStream(xmlStream, config->effects, &config->postprocess));
            }
            }
        }
        }

        // Parse device effect chains
        for (auto& xmlDeviceEffects : getChildren(xmlConfig, "deviceEffects")) {
            for (auto& xmlDevice : getChildren(xmlDeviceEffects, "devicePort")) {
                registerFailure(
                            parseDeviceEffects(xmlDevice, config->effects, &config->deviceprocess));
            }
        }
    }
    }
    return {std::move(config), nbSkippedElements, std::move(path)};
    return {std::move(config), nbSkippedElements, std::move(path)};
}
}
+27 −0
Original line number Original line Diff line number Diff line
@@ -99,4 +99,31 @@
        </postprocess>
        </postprocess>
    -->
    -->


     <!-- Device pre/post processor configurations.
          The device pre/post processor configuration is described in a deviceEffects element and
          consists in a list of elements each describing pre/post proecessor settings for a given
          device or "devicePort".
          Each devicePort element has a "type" attribute corresponding to the device type (e.g.
          speaker, bus), an "address" attribute corresponding to the device address and contains a
          list of "apply" elements indicating one effect to apply.
          If the device is a source, only pre processing effects are expected, if the
          device is a sink, only post processing effects are expected.
          The effect to apply is designated by its name in the "effects" elements.
          The effect will be enabled by default and the audio framework will automatically add
          and activate the effect if the given port is involved in an audio patch.
          If the patch is "HW", the effect must be HW accelerated.

        <deviceEffects>
            <devicePort type="AUDIO_DEVICE_OUT_BUS" address="BUS00_USAGE_MAIN">
                <apply effect="equalizer"/>
            </devicePort>
            <devicePort type="AUDIO_DEVICE_OUT_BUS" address="BUS04_USAGE_VOICE">
                <apply effect="volume"/>
            </devicePort>
            <devicePort type="AUDIO_DEVICE_IN_BUILTIN_MIC" address="bottom">
                <apply effect="agc"/>
            </devicePort>
        </deviceEffects>
    -->

</audio_effects_conf>
</audio_effects_conf>