blob: 811730c8eb96d1e1e4f367e39b6c1c335a042136 [file] [log] [blame]
* Copyright (C) 2017 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.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
/** @file Parses audio effects configuration file to C and C++ structure.
* @see audio_effects_conf_V2_0.xsd for documentation on each structure
#include <system/audio_effect.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace android {
namespace effectsConfig {
/** Default path of effect configuration file. */
constexpr char DEFAULT_PATH[] = "/vendor/etc/audio_effects.xml";
/** Directories where the effect libraries will be search for. */
constexpr const char* LD_EFFECT_LIBRARY_PATH[] =
#ifdef __LP64__
{"/odm/lib64/soundfx", "/vendor/lib64/soundfx", "/system/lib64/soundfx"};
{"/odm/lib/soundfx", "/vendor/lib/soundfx", "/system/lib/soundfx"};
struct Library {
std::string name;
std::string path;
using Libraries = std::vector<Library>;
struct EffectImpl {
Library* library; //< Only valid as long as the associated library vector is unmodified
effect_uuid_t uuid;
struct Effect : public EffectImpl {
std::string name;
bool isProxy;
EffectImpl libSw; //< Only valid if isProxy
EffectImpl libHw; //< Only valid if isProxy
using Effects = std::vector<Effect>;
template <class Type>
struct Stream {
Type type;
std::vector<std::reference_wrapper<Effect>> effects;
using OutputStream = Stream<audio_stream_type_t>;
using InputStream = Stream<audio_source_t>;
/** Parsed configuration.
* Intended to be a transient structure only used for deserialization.
* Note: Everything is copied in the configuration from the xml dom.
* If copies needed to be avoided due to performance issue,
* consider keeping a private handle on the xml dom and replace all strings by dom pointers.
* Or even better, use SAX parsing to avoid the allocations all together.
struct Config {
float version;
Libraries libraries;
Effects effects;
std::vector<OutputStream> postprocess;
std::vector<InputStream> preprocess;
/** Result of `parse(const char*)` */
struct ParsingResult {
/** Parsed config, nullptr if the xml lib could not load the file */
std::unique_ptr<Config> parsedConfig;
size_t nbSkippedElement; //< Number of skipped invalid library, effect or processing chain
/** Parses the provided effect configuration.
* Parsing do not stop of first invalid element, but continues to the next.
* @see ParsingResult::nbSkippedElement
ParsingResult parse(const char* path = DEFAULT_PATH);
} // namespace effectsConfig
} // namespace android