| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "APM::Serializer" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 20 | #include <memory> |
| 21 | #include <string> |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 22 | #include <utility> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 23 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 24 | #include <hidl/Status.h> |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 25 | #include <libxml/parser.h> |
| 26 | #include <libxml/xinclude.h> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 27 | #include <media/convert.h> |
| 28 | #include <utils/Log.h> |
| 29 | #include <utils/StrongPointer.h> |
| 30 | #include <utils/Errors.h> |
| 31 | #include <utils/RefBase.h> |
| 32 | #include "Serializer.h" |
| 33 | #include "TypeConverter.h" |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 37 | namespace { |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 38 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 39 | // TODO(mnaganov): Consider finding an alternative for using HIDL code. |
| 40 | using hardware::Return; |
| 41 | using hardware::Status; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 42 | using utilities::convertTo; |
| 43 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 44 | template<typename E, typename C> |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 45 | struct AndroidCollectionTraits { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 46 | typedef sp<E> Element; |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 47 | typedef C Collection; |
| 48 | typedef void* PtrSerializingCtx; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 49 | |
| 50 | static status_t addElementToCollection(const Element &element, Collection *collection) { |
| 51 | return collection->add(element) >= 0 ? NO_ERROR : BAD_VALUE; |
| 52 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 53 | }; |
| François Gaffie | c9d7c4e | 2016-01-22 13:54:30 +0100 | [diff] [blame] | 54 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 55 | template<typename C> |
| 56 | struct StdCollectionTraits { |
| 57 | typedef C Collection; |
| 58 | typedef typename C::value_type Element; |
| 59 | typedef void* PtrSerializingCtx; |
| 60 | |
| 61 | static status_t addElementToCollection(const Element &element, Collection *collection) { |
| 62 | auto pair = collection->insert(element); |
| 63 | return pair.second ? NO_ERROR : BAD_VALUE; |
| 64 | } |
| 65 | }; |
| 66 | |
| François Gaffie | 43c7344 | 2018-11-08 08:21:55 +0100 | [diff] [blame] | 67 | struct AudioGainTraits : public AndroidCollectionTraits<AudioGain, AudioGains> |
| François Gaffie | c9d7c4e | 2016-01-22 13:54:30 +0100 | [diff] [blame] | 68 | { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 69 | static constexpr const char *tag = "gain"; |
| 70 | static constexpr const char *collectionTag = "gains"; |
| 71 | |
| 72 | struct Attributes |
| 73 | { |
| 74 | /** gain modes supported, e.g. AUDIO_GAIN_MODE_CHANNELS. */ |
| 75 | static constexpr const char *mode = "mode"; |
| 76 | /** controlled channels, needed if mode AUDIO_GAIN_MODE_CHANNELS. */ |
| 77 | static constexpr const char *channelMask = "channel_mask"; |
| 78 | static constexpr const char *minValueMB = "minValueMB"; /**< min value in millibel. */ |
| 79 | static constexpr const char *maxValueMB = "maxValueMB"; /**< max value in millibel. */ |
| 80 | /** default value in millibel. */ |
| 81 | static constexpr const char *defaultValueMB = "defaultValueMB"; |
| 82 | static constexpr const char *stepValueMB = "stepValueMB"; /**< step value in millibel. */ |
| 83 | /** needed if mode AUDIO_GAIN_MODE_RAMP. */ |
| 84 | static constexpr const char *minRampMs = "minRampMs"; |
| 85 | /** needed if mode AUDIO_GAIN_MODE_RAMP. */ |
| 86 | static constexpr const char *maxRampMs = "maxRampMs"; |
| François Gaffie | 43c7344 | 2018-11-08 08:21:55 +0100 | [diff] [blame] | 87 | /** needed to allow use setPortGain instead of setStreamVolume. */ |
| 88 | static constexpr const char *useForVolume = "useForVolume"; |
| 89 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 92 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 93 | // No children |
| 94 | }; |
| 95 | |
| 96 | // A profile section contains a name, one audio format and the list of supported sampling rates |
| 97 | // and channel masks for this format |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 98 | struct AudioProfileTraits : public AndroidCollectionTraits<AudioProfile, AudioProfileVector> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 99 | { |
| 100 | static constexpr const char *tag = "profile"; |
| 101 | static constexpr const char *collectionTag = "profiles"; |
| 102 | |
| 103 | struct Attributes |
| 104 | { |
| 105 | static constexpr const char *samplingRates = "samplingRates"; |
| 106 | static constexpr const char *format = "format"; |
| 107 | static constexpr const char *channelMasks = "channelMasks"; |
| 108 | }; |
| 109 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 110 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 113 | struct MixPortTraits : public AndroidCollectionTraits<IOProfile, IOProfileCollection> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 114 | { |
| 115 | static constexpr const char *tag = "mixPort"; |
| 116 | static constexpr const char *collectionTag = "mixPorts"; |
| 117 | |
| 118 | struct Attributes |
| 119 | { |
| 120 | static constexpr const char *name = "name"; |
| 121 | static constexpr const char *role = "role"; |
| 122 | static constexpr const char *roleSource = "source"; /**< <attribute role source value>. */ |
| 123 | static constexpr const char *flags = "flags"; |
| 124 | static constexpr const char *maxOpenCount = "maxOpenCount"; |
| 125 | static constexpr const char *maxActiveCount = "maxActiveCount"; |
| 126 | }; |
| 127 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 128 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 129 | // Children: GainTraits |
| 130 | }; |
| 131 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 132 | struct DevicePortTraits : public AndroidCollectionTraits<DeviceDescriptor, DeviceVector> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 133 | { |
| 134 | static constexpr const char *tag = "devicePort"; |
| 135 | static constexpr const char *collectionTag = "devicePorts"; |
| 136 | |
| 137 | struct Attributes |
| 138 | { |
| 139 | /** <device tag name>: any string without space. */ |
| 140 | static constexpr const char *tagName = "tagName"; |
| 141 | static constexpr const char *type = "type"; /**< <device type>. */ |
| 142 | static constexpr const char *role = "role"; /**< <device role: sink or source>. */ |
| 143 | static constexpr const char *roleSource = "source"; /**< <attribute role source value>. */ |
| 144 | /** optional: device address, char string less than 64. */ |
| 145 | static constexpr const char *address = "address"; |
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 146 | /** optional: the list of encoded audio formats that are known to be supported. */ |
| 147 | static constexpr const char *encodedFormats = "encodedFormats"; |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 150 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 151 | // Children: GainTraits (optional) |
| 152 | }; |
| 153 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 154 | struct RouteTraits : public AndroidCollectionTraits<AudioRoute, AudioRouteVector> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 155 | { |
| 156 | static constexpr const char *tag = "route"; |
| 157 | static constexpr const char *collectionTag = "routes"; |
| 158 | |
| 159 | struct Attributes |
| 160 | { |
| 161 | static constexpr const char *type = "type"; /**< <route type>: mix or mux. */ |
| 162 | static constexpr const char *typeMix = "mix"; /**< type attribute mix value. */ |
| 163 | static constexpr const char *sink = "sink"; /**< <sink: involved in this route>. */ |
| 164 | /** sources: all source that can be involved in this route. */ |
| 165 | static constexpr const char *sources = "sources"; |
| 166 | }; |
| 167 | |
| 168 | typedef HwModule *PtrSerializingCtx; |
| 169 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 170 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 173 | struct ModuleTraits : public AndroidCollectionTraits<HwModule, HwModuleCollection> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 174 | { |
| 175 | static constexpr const char *tag = "module"; |
| 176 | static constexpr const char *collectionTag = "modules"; |
| 177 | |
| 178 | static constexpr const char *childAttachedDevicesTag = "attachedDevices"; |
| 179 | static constexpr const char *childAttachedDeviceTag = "item"; |
| 180 | static constexpr const char *childDefaultOutputDeviceTag = "defaultOutputDevice"; |
| 181 | |
| 182 | struct Attributes |
| 183 | { |
| 184 | static constexpr const char *name = "name"; |
| 185 | static constexpr const char *version = "halVersion"; |
| 186 | }; |
| 187 | |
| 188 | typedef AudioPolicyConfig *PtrSerializingCtx; |
| 189 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 190 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 191 | // Children: mixPortTraits, devicePortTraits, and routeTraits |
| 192 | // Need to call deserialize on each child |
| 193 | }; |
| 194 | |
| 195 | struct GlobalConfigTraits |
| 196 | { |
| 197 | static constexpr const char *tag = "globalConfiguration"; |
| 198 | |
| 199 | struct Attributes |
| 200 | { |
| 201 | static constexpr const char *speakerDrcEnabled = "speaker_drc_enabled"; |
| 202 | }; |
| 203 | |
| 204 | static status_t deserialize(const xmlNode *root, AudioPolicyConfig *config); |
| 205 | }; |
| 206 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 207 | struct SurroundSoundTraits |
| 208 | { |
| 209 | static constexpr const char *tag = "surroundSound"; |
| 210 | |
| 211 | static status_t deserialize(const xmlNode *root, AudioPolicyConfig *config); |
| 212 | // Children: SurroundSoundFormatTraits |
| 213 | }; |
| 214 | |
| 215 | struct SurroundSoundFormatTraits : public StdCollectionTraits<AudioPolicyConfig::SurroundFormats> |
| 216 | { |
| 217 | static constexpr const char *tag = "format"; |
| 218 | static constexpr const char *collectionTag = "formats"; |
| 219 | |
| 220 | struct Attributes |
| 221 | { |
| 222 | static constexpr const char *name = "name"; |
| 223 | static constexpr const char *subformats = "subformats"; |
| 224 | }; |
| 225 | |
| 226 | static Return<Element> deserialize(const xmlNode *cur, PtrSerializingCtx serializingContext); |
| 227 | }; |
| 228 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 229 | class PolicySerializer |
| 230 | { |
| 231 | public: |
| 232 | PolicySerializer() : mVersion{std::to_string(gMajor) + "." + std::to_string(gMinor)} |
| 233 | { |
| 234 | ALOGV("%s: Version=%s Root=%s", __func__, mVersion.c_str(), rootName); |
| François Gaffie | c9d7c4e | 2016-01-22 13:54:30 +0100 | [diff] [blame] | 235 | } |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 236 | status_t deserialize(const char *configFile, AudioPolicyConfig *config); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 237 | |
| 238 | private: |
| 239 | static constexpr const char *rootName = "audioPolicyConfiguration"; |
| 240 | static constexpr const char *versionAttribute = "version"; |
| 241 | static constexpr uint32_t gMajor = 1; /**< the major number of the policy xml format version. */ |
| 242 | static constexpr uint32_t gMinor = 0; /**< the minor number of the policy xml format version. */ |
| 243 | |
| 244 | typedef AudioPolicyConfig Element; |
| 245 | |
| 246 | const std::string mVersion; |
| 247 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 248 | // Children: ModulesTraits, VolumeTraits, SurroundSoundTraits (optional) |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | template <class T> |
| 252 | constexpr void (*xmlDeleter)(T* t); |
| 253 | template <> |
| 254 | constexpr auto xmlDeleter<xmlDoc> = xmlFreeDoc; |
| Stephen Hines | e754a45 | 2018-09-20 17:08:23 -0700 | [diff] [blame] | 255 | // http://b/111067277 - Add back constexpr when we switch to C++17. |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 256 | template <> |
| Stephen Hines | e754a45 | 2018-09-20 17:08:23 -0700 | [diff] [blame] | 257 | auto xmlDeleter<xmlChar> = [](xmlChar *s) { xmlFree(s); }; |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 258 | |
| 259 | /** @return a unique_ptr with the correct deleter for the libxml2 object. */ |
| 260 | template <class T> |
| 261 | constexpr auto make_xmlUnique(T *t) { |
| 262 | // Wrap deleter in lambda to enable empty base optimization |
| 263 | auto deleter = [](T *t) { xmlDeleter<T>(t); }; |
| 264 | return std::unique_ptr<T, decltype(deleter)>{t, deleter}; |
| 265 | } |
| 266 | |
| 267 | std::string getXmlAttribute(const xmlNode *cur, const char *attribute) |
| 268 | { |
| 269 | auto xmlValue = make_xmlUnique(xmlGetProp(cur, reinterpret_cast<const xmlChar*>(attribute))); |
| 270 | if (xmlValue == nullptr) { |
| 271 | return ""; |
| 272 | } |
| 273 | std::string value(reinterpret_cast<const char*>(xmlValue.get())); |
| 274 | return value; |
| François Gaffie | c9d7c4e | 2016-01-22 13:54:30 +0100 | [diff] [blame] | 275 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 276 | |
| 277 | template <class Trait> |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 278 | const xmlNode* getReference(const xmlNode *cur, const std::string &refName) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 279 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 280 | for (; cur != NULL; cur = cur->next) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 281 | if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(Trait::collectionTag))) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 282 | for (const xmlNode *child = cur->children; child != NULL; child = child->next) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 283 | if ((!xmlStrcmp(child->name, |
| 284 | reinterpret_cast<const xmlChar*>(Trait::referenceTag)))) { |
| 285 | std::string name = getXmlAttribute(child, Trait::Attributes::referenceName); |
| 286 | if (refName == name) { |
| 287 | return child; |
| 288 | } |
| 289 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 292 | } |
| 293 | return NULL; |
| 294 | } |
| 295 | |
| 296 | template <class Trait> |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 297 | status_t deserializeCollection(const xmlNode *cur, |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 298 | typename Trait::Collection *collection, |
| 299 | typename Trait::PtrSerializingCtx serializingContext) |
| 300 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 301 | for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) { |
| 302 | const xmlNode *child = NULL; |
| 303 | if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(Trait::collectionTag))) { |
| 304 | child = cur->xmlChildrenNode; |
| 305 | } else if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(Trait::tag))) { |
| 306 | child = cur; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 307 | } |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 308 | for (; child != NULL; child = child->next) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 309 | if (!xmlStrcmp(child->name, reinterpret_cast<const xmlChar*>(Trait::tag))) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 310 | auto element = Trait::deserialize(child, serializingContext); |
| 311 | if (element.isOk()) { |
| 312 | status_t status = Trait::addElementToCollection(element, collection); |
| 313 | if (status != NO_ERROR) { |
| 314 | ALOGE("%s: could not add element to %s collection", __func__, |
| 315 | Trait::collectionTag); |
| 316 | return status; |
| 317 | } |
| 318 | } else { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 319 | return BAD_VALUE; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 320 | } |
| 321 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 322 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 323 | if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(Trait::tag))) { |
| François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 324 | return NO_ERROR; |
| 325 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 326 | } |
| François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 327 | return NO_ERROR; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 328 | } |
| 329 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 330 | Return<AudioGainTraits::Element> AudioGainTraits::deserialize(const xmlNode *cur, |
| 331 | PtrSerializingCtx /*serializingContext*/) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 332 | { |
| 333 | static uint32_t index = 0; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 334 | Element gain = new AudioGain(index++, true); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 335 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 336 | std::string mode = getXmlAttribute(cur, Attributes::mode); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 337 | if (!mode.empty()) { |
| 338 | gain->setMode(GainModeConverter::maskFromString(mode)); |
| 339 | } |
| 340 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 341 | std::string channelsLiteral = getXmlAttribute(cur, Attributes::channelMask); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 342 | if (!channelsLiteral.empty()) { |
| 343 | gain->setChannelMask(channelMaskFromString(channelsLiteral)); |
| 344 | } |
| 345 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 346 | std::string minValueMBLiteral = getXmlAttribute(cur, Attributes::minValueMB); |
| Kevin Rocard | 575bb3a | 2017-10-27 16:49:20 -0700 | [diff] [blame] | 347 | int32_t minValueMB; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 348 | if (!minValueMBLiteral.empty() && convertTo(minValueMBLiteral, minValueMB)) { |
| 349 | gain->setMinValueInMb(minValueMB); |
| 350 | } |
| 351 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 352 | std::string maxValueMBLiteral = getXmlAttribute(cur, Attributes::maxValueMB); |
| Kevin Rocard | 575bb3a | 2017-10-27 16:49:20 -0700 | [diff] [blame] | 353 | int32_t maxValueMB; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 354 | if (!maxValueMBLiteral.empty() && convertTo(maxValueMBLiteral, maxValueMB)) { |
| 355 | gain->setMaxValueInMb(maxValueMB); |
| 356 | } |
| 357 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 358 | std::string defaultValueMBLiteral = getXmlAttribute(cur, Attributes::defaultValueMB); |
| Kevin Rocard | 575bb3a | 2017-10-27 16:49:20 -0700 | [diff] [blame] | 359 | int32_t defaultValueMB; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 360 | if (!defaultValueMBLiteral.empty() && convertTo(defaultValueMBLiteral, defaultValueMB)) { |
| 361 | gain->setDefaultValueInMb(defaultValueMB); |
| 362 | } |
| 363 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 364 | std::string stepValueMBLiteral = getXmlAttribute(cur, Attributes::stepValueMB); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 365 | uint32_t stepValueMB; |
| 366 | if (!stepValueMBLiteral.empty() && convertTo(stepValueMBLiteral, stepValueMB)) { |
| 367 | gain->setStepValueInMb(stepValueMB); |
| 368 | } |
| 369 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 370 | std::string minRampMsLiteral = getXmlAttribute(cur, Attributes::minRampMs); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 371 | uint32_t minRampMs; |
| 372 | if (!minRampMsLiteral.empty() && convertTo(minRampMsLiteral, minRampMs)) { |
| 373 | gain->setMinRampInMs(minRampMs); |
| 374 | } |
| 375 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 376 | std::string maxRampMsLiteral = getXmlAttribute(cur, Attributes::maxRampMs); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 377 | uint32_t maxRampMs; |
| 378 | if (!maxRampMsLiteral.empty() && convertTo(maxRampMsLiteral, maxRampMs)) { |
| 379 | gain->setMaxRampInMs(maxRampMs); |
| 380 | } |
| François Gaffie | 43c7344 | 2018-11-08 08:21:55 +0100 | [diff] [blame] | 381 | std::string useForVolumeLiteral = getXmlAttribute(cur, Attributes::useForVolume); |
| 382 | bool useForVolume = false; |
| 383 | if (!useForVolumeLiteral.empty() && convertTo(useForVolumeLiteral, useForVolume)) { |
| 384 | gain->setUseForVolume(useForVolume); |
| 385 | } |
| 386 | ALOGV("%s: adding new gain mode %08x channel mask %08x min mB %d max mB %d UseForVolume: %d", |
| 387 | __func__, gain->getMode(), gain->getChannelMask(), gain->getMinValueInMb(), |
| 388 | gain->getMaxValueInMb(), useForVolume); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 389 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 390 | if (gain->getMode() != 0) { |
| 391 | return gain; |
| 392 | } else { |
| 393 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 394 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 397 | Return<AudioProfileTraits::Element> AudioProfileTraits::deserialize(const xmlNode *cur, |
| 398 | PtrSerializingCtx /*serializingContext*/) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 399 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 400 | std::string samplingRates = getXmlAttribute(cur, Attributes::samplingRates); |
| 401 | std::string format = getXmlAttribute(cur, Attributes::format); |
| 402 | std::string channels = getXmlAttribute(cur, Attributes::channelMasks); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 403 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 404 | Element profile = new AudioProfile(formatFromString(format, gDynamicFormat), |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 405 | channelMasksFromString(channels, ","), |
| 406 | samplingRatesFromString(samplingRates, ",")); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 407 | |
| 408 | profile->setDynamicFormat(profile->getFormat() == gDynamicFormat); |
| jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 409 | profile->setDynamicChannels(profile->getChannels().empty()); |
| 410 | profile->setDynamicRate(profile->getSampleRates().empty()); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 411 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 412 | return profile; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 415 | Return<MixPortTraits::Element> MixPortTraits::deserialize(const xmlNode *child, |
| 416 | PtrSerializingCtx /*serializingContext*/) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 417 | { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 418 | std::string name = getXmlAttribute(child, Attributes::name); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 419 | if (name.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 420 | ALOGE("%s: No %s found", __func__, Attributes::name); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 421 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 422 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 423 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::name, name.c_str()); |
| 424 | std::string role = getXmlAttribute(child, Attributes::role); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 425 | if (role.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 426 | ALOGE("%s: No %s found", __func__, Attributes::role); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 427 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 428 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 429 | ALOGV("%s: Role=%s", __func__, role.c_str()); |
| 430 | audio_port_role_t portRole = (role == Attributes::roleSource) ? |
| 431 | AUDIO_PORT_ROLE_SOURCE : AUDIO_PORT_ROLE_SINK; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 432 | |
| jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 433 | Element mixPort = new IOProfile(name, portRole); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 434 | |
| 435 | AudioProfileTraits::Collection profiles; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 436 | status_t status = deserializeCollection<AudioProfileTraits>(child, &profiles, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 437 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 438 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 439 | } |
| jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 440 | if (profiles.empty()) { |
| jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 441 | profiles.add(AudioProfile::createFullDynamic(gDynamicFormat)); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 442 | } |
| jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 443 | // The audio profiles are in order of listed in audio policy configuration file. |
| 444 | // Sort audio profiles accroding to the format. |
| 445 | sortAudioProfiles(profiles); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 446 | mixPort->setAudioProfiles(profiles); |
| 447 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 448 | std::string flags = getXmlAttribute(child, Attributes::flags); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 449 | if (!flags.empty()) { |
| 450 | // Source role |
| 451 | if (portRole == AUDIO_PORT_ROLE_SOURCE) { |
| 452 | mixPort->setFlags(OutputFlagConverter::maskFromString(flags)); |
| 453 | } else { |
| 454 | // Sink role |
| 455 | mixPort->setFlags(InputFlagConverter::maskFromString(flags)); |
| 456 | } |
| 457 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 458 | std::string maxOpenCount = getXmlAttribute(child, Attributes::maxOpenCount); |
| Eric Laurent | ae60317 | 2017-12-07 17:59:01 -0800 | [diff] [blame] | 459 | if (!maxOpenCount.empty()) { |
| 460 | convertTo(maxOpenCount, mixPort->maxOpenCount); |
| 461 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 462 | std::string maxActiveCount = getXmlAttribute(child, Attributes::maxActiveCount); |
| Eric Laurent | ae60317 | 2017-12-07 17:59:01 -0800 | [diff] [blame] | 463 | if (!maxActiveCount.empty()) { |
| 464 | convertTo(maxActiveCount, mixPort->maxActiveCount); |
| 465 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 466 | // Deserialize children |
| 467 | AudioGainTraits::Collection gains; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 468 | status = deserializeCollection<AudioGainTraits>(child, &gains, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 469 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 470 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 471 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 472 | mixPort->setGains(gains); |
| 473 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 474 | return mixPort; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 475 | } |
| 476 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 477 | Return<DevicePortTraits::Element> DevicePortTraits::deserialize(const xmlNode *cur, |
| 478 | PtrSerializingCtx /*serializingContext*/) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 479 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 480 | std::string name = getXmlAttribute(cur, Attributes::tagName); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 481 | if (name.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 482 | ALOGE("%s: No %s found", __func__, Attributes::tagName); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 483 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 484 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 485 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::tagName, name.c_str()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 486 | std::string typeName = getXmlAttribute(cur, Attributes::type); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 487 | if (typeName.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 488 | ALOGE("%s: no type for %s", __func__, name.c_str()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 489 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 490 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 491 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::type, typeName.c_str()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 492 | std::string role = getXmlAttribute(cur, Attributes::role); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 493 | if (role.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 494 | ALOGE("%s: No %s found", __func__, Attributes::role); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 495 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 496 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 497 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::role, role.c_str()); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 498 | audio_port_role_t portRole = (role == Attributes::roleSource) ? |
| 499 | AUDIO_PORT_ROLE_SOURCE : AUDIO_PORT_ROLE_SINK; |
| 500 | |
| 501 | audio_devices_t type = AUDIO_DEVICE_NONE; |
| Mikhail Naganov | 913d06c | 2016-11-01 12:49:22 -0700 | [diff] [blame] | 502 | if (!deviceFromString(typeName, type) || |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 503 | (!audio_is_input_device(type) && portRole == AUDIO_PORT_ROLE_SOURCE) || |
| 504 | (!audio_is_output_devices(type) && portRole == AUDIO_PORT_ROLE_SINK)) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 505 | ALOGW("%s: bad type %08x", __func__, type); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 506 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 507 | } |
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 508 | std::string encodedFormatsLiteral = getXmlAttribute(cur, Attributes::encodedFormats); |
| 509 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::encodedFormats, encodedFormatsLiteral.c_str()); |
| 510 | FormatVector encodedFormats; |
| 511 | if (!encodedFormatsLiteral.empty()) { |
| 512 | encodedFormats = formatsFromString(encodedFormatsLiteral, " "); |
| 513 | } |
| jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 514 | Element deviceDesc = new DeviceDescriptor(type, encodedFormats, name); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 515 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 516 | std::string address = getXmlAttribute(cur, Attributes::address); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 517 | if (!address.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 518 | ALOGV("%s: address=%s for %s", __func__, address.c_str(), name.c_str()); |
| François Gaffie | aca677c | 2018-05-03 10:47:50 +0200 | [diff] [blame] | 519 | deviceDesc->setAddress(String8(address.c_str())); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | AudioProfileTraits::Collection profiles; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 523 | status_t status = deserializeCollection<AudioProfileTraits>(cur, &profiles, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 524 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 525 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 526 | } |
| jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 527 | if (profiles.empty()) { |
| jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 528 | profiles.add(AudioProfile::createFullDynamic(gDynamicFormat)); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 529 | } |
| jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 530 | // The audio profiles are in order of listed in audio policy configuration file. |
| 531 | // Sort audio profiles accroding to the format. |
| 532 | sortAudioProfiles(profiles); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 533 | deviceDesc->setAudioProfiles(profiles); |
| 534 | |
| 535 | // Deserialize AudioGain children |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 536 | status = deserializeCollection<AudioGainTraits>(cur, &deviceDesc->mGains, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 537 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 538 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 539 | } |
| 540 | ALOGV("%s: adding device tag %s type %08x address %s", __func__, |
| jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 541 | deviceDesc->getName().c_str(), type, deviceDesc->address().string()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 542 | return deviceDesc; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 545 | Return<RouteTraits::Element> RouteTraits::deserialize(const xmlNode *cur, PtrSerializingCtx ctx) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 546 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 547 | std::string type = getXmlAttribute(cur, Attributes::type); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 548 | if (type.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 549 | ALOGE("%s: No %s found", __func__, Attributes::type); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 550 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 551 | } |
| 552 | audio_route_type_t routeType = (type == Attributes::typeMix) ? |
| 553 | AUDIO_ROUTE_MIX : AUDIO_ROUTE_MUX; |
| 554 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 555 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::type, type.c_str()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 556 | Element route = new AudioRoute(routeType); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 557 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 558 | std::string sinkAttr = getXmlAttribute(cur, Attributes::sink); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 559 | if (sinkAttr.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 560 | ALOGE("%s: No %s found", __func__, Attributes::sink); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 561 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 562 | } |
| 563 | // Convert Sink name to port pointer |
| jiabin | 4ef9345 | 2019-09-10 14:29:54 -0700 | [diff] [blame^] | 564 | sp<PolicyAudioPort> sink = ctx->findPortByTagName(sinkAttr); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 565 | if (sink == NULL) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 566 | ALOGE("%s: no sink found with name=%s", __func__, sinkAttr.c_str()); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 567 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 568 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 569 | route->setSink(sink); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 570 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 571 | std::string sourcesAttr = getXmlAttribute(cur, Attributes::sources); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 572 | if (sourcesAttr.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 573 | ALOGE("%s: No %s found", __func__, Attributes::sources); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 574 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 575 | } |
| 576 | // Tokenize and Convert Sources name to port pointer |
| jiabin | 4ef9345 | 2019-09-10 14:29:54 -0700 | [diff] [blame^] | 577 | PolicyAudioPortVector sources; |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 578 | std::unique_ptr<char[]> sourcesLiteral{strndup( |
| 579 | sourcesAttr.c_str(), strlen(sourcesAttr.c_str()))}; |
| 580 | char *devTag = strtok(sourcesLiteral.get(), ","); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 581 | while (devTag != NULL) { |
| 582 | if (strlen(devTag) != 0) { |
| jiabin | 4ef9345 | 2019-09-10 14:29:54 -0700 | [diff] [blame^] | 583 | sp<PolicyAudioPort> source = ctx->findPortByTagName(devTag); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 584 | if (source == NULL) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 585 | ALOGE("%s: no source found with name=%s", __func__, devTag); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 586 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 587 | } |
| 588 | sources.add(source); |
| 589 | } |
| 590 | devTag = strtok(NULL, ","); |
| 591 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 592 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 593 | sink->addRoute(route); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 594 | for (size_t i = 0; i < sources.size(); i++) { |
| jiabin | 4ef9345 | 2019-09-10 14:29:54 -0700 | [diff] [blame^] | 595 | sp<PolicyAudioPort> source = sources.itemAt(i); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 596 | source->addRoute(route); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 597 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 598 | route->setSources(sources); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 599 | return route; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 602 | Return<ModuleTraits::Element> ModuleTraits::deserialize(const xmlNode *cur, PtrSerializingCtx ctx) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 603 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 604 | std::string name = getXmlAttribute(cur, Attributes::name); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 605 | if (name.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 606 | ALOGE("%s: No %s found", __func__, Attributes::name); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 607 | return Status::fromStatusT(BAD_VALUE); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 608 | } |
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame] | 609 | uint32_t versionMajor = 0, versionMinor = 0; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 610 | std::string versionLiteral = getXmlAttribute(cur, Attributes::version); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 611 | if (!versionLiteral.empty()) { |
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame] | 612 | sscanf(versionLiteral.c_str(), "%u.%u", &versionMajor, &versionMinor); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 613 | ALOGV("%s: mHalVersion = major %u minor %u", __func__, |
| Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame] | 614 | versionMajor, versionMajor); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 615 | } |
| 616 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 617 | ALOGV("%s: %s %s=%s", __func__, tag, Attributes::name, name.c_str()); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 618 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 619 | Element module = new HwModule(name.c_str(), versionMajor, versionMinor); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 620 | |
| 621 | // Deserialize childrens: Audio Mix Port, Audio Device Ports (Source/Sink), Audio Routes |
| 622 | MixPortTraits::Collection mixPorts; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 623 | status_t status = deserializeCollection<MixPortTraits>(cur, &mixPorts, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 624 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 625 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 626 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 627 | module->setProfiles(mixPorts); |
| 628 | |
| 629 | DevicePortTraits::Collection devicePorts; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 630 | status = deserializeCollection<DevicePortTraits>(cur, &devicePorts, NULL); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 631 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 632 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 633 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 634 | module->setDeclaredDevices(devicePorts); |
| 635 | |
| 636 | RouteTraits::Collection routes; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 637 | status = deserializeCollection<RouteTraits>(cur, &routes, module.get()); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 638 | if (status != NO_ERROR) { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 639 | return Status::fromStatusT(status); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 640 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 641 | module->setRoutes(routes); |
| 642 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 643 | for (const xmlNode *children = cur->xmlChildrenNode; children != NULL; |
| 644 | children = children->next) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 645 | if (!xmlStrcmp(children->name, reinterpret_cast<const xmlChar*>(childAttachedDevicesTag))) { |
| 646 | ALOGV("%s: %s %s found", __func__, tag, childAttachedDevicesTag); |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 647 | for (const xmlNode *child = children->xmlChildrenNode; child != NULL; |
| 648 | child = child->next) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 649 | if (!xmlStrcmp(child->name, |
| 650 | reinterpret_cast<const xmlChar*>(childAttachedDeviceTag))) { |
| 651 | auto attachedDevice = make_xmlUnique(xmlNodeListGetString( |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 652 | child->doc, child->xmlChildrenNode, 1)); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 653 | if (attachedDevice != nullptr) { |
| 654 | ALOGV("%s: %s %s=%s", __func__, tag, childAttachedDeviceTag, |
| 655 | reinterpret_cast<const char*>(attachedDevice.get())); |
| 656 | sp<DeviceDescriptor> device = module->getDeclaredDevices(). |
| jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 657 | getDeviceFromTagName(std::string(reinterpret_cast<const char*>( |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 658 | attachedDevice.get()))); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 659 | ctx->addAvailableDevice(device); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 660 | } |
| 661 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 662 | } |
| 663 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 664 | if (!xmlStrcmp(children->name, |
| 665 | reinterpret_cast<const xmlChar*>(childDefaultOutputDeviceTag))) { |
| 666 | auto defaultOutputDevice = make_xmlUnique(xmlNodeListGetString( |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 667 | children->doc, children->xmlChildrenNode, 1)); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 668 | if (defaultOutputDevice != nullptr) { |
| 669 | ALOGV("%s: %s %s=%s", __func__, tag, childDefaultOutputDeviceTag, |
| 670 | reinterpret_cast<const char*>(defaultOutputDevice.get())); |
| 671 | sp<DeviceDescriptor> device = module->getDeclaredDevices().getDeviceFromTagName( |
| jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 672 | std::string(reinterpret_cast<const char*>(defaultOutputDevice.get()))); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 673 | if (device != 0 && ctx->getDefaultOutputDevice() == 0) { |
| 674 | ctx->setDefaultOutputDevice(device); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 675 | ALOGV("%s: default is %08x", |
| 676 | __func__, ctx->getDefaultOutputDevice()->type()); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 677 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 678 | } |
| 679 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 680 | } |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 681 | return module; |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 682 | } |
| 683 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 684 | status_t GlobalConfigTraits::deserialize(const xmlNode *root, AudioPolicyConfig *config) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 685 | { |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 686 | for (const xmlNode *cur = root->xmlChildrenNode; cur != NULL; cur = cur->next) { |
| 687 | if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(tag))) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 688 | std::string speakerDrcEnabled = |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 689 | getXmlAttribute(cur, Attributes::speakerDrcEnabled); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 690 | bool isSpeakerDrcEnabled; |
| 691 | if (!speakerDrcEnabled.empty() && |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 692 | convertTo<std::string, bool>(speakerDrcEnabled, isSpeakerDrcEnabled)) { |
| 693 | config->setSpeakerDrcEnabled(isSpeakerDrcEnabled); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 694 | } |
| 695 | return NO_ERROR; |
| 696 | } |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 697 | } |
| 698 | return NO_ERROR; |
| 699 | } |
| 700 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 701 | status_t SurroundSoundTraits::deserialize(const xmlNode *root, AudioPolicyConfig *config) |
| 702 | { |
| 703 | config->setDefaultSurroundFormats(); |
| 704 | |
| 705 | for (const xmlNode *cur = root->xmlChildrenNode; cur != NULL; cur = cur->next) { |
| 706 | if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(tag))) { |
| 707 | AudioPolicyConfig::SurroundFormats formats; |
| 708 | status_t status = deserializeCollection<SurroundSoundFormatTraits>( |
| 709 | cur, &formats, nullptr); |
| 710 | if (status == NO_ERROR) { |
| 711 | config->setSurroundFormats(formats); |
| 712 | } |
| 713 | return NO_ERROR; |
| 714 | } |
| 715 | } |
| 716 | return NO_ERROR; |
| 717 | } |
| 718 | |
| 719 | Return<SurroundSoundFormatTraits::Element> SurroundSoundFormatTraits::deserialize( |
| 720 | const xmlNode *cur, PtrSerializingCtx /*serializingContext*/) |
| 721 | { |
| 722 | std::string formatLiteral = getXmlAttribute(cur, Attributes::name); |
| 723 | if (formatLiteral.empty()) { |
| 724 | ALOGE("%s: No %s found for a surround format", __func__, Attributes::name); |
| 725 | return Status::fromStatusT(BAD_VALUE); |
| 726 | } |
| 727 | audio_format_t format = formatFromString(formatLiteral); |
| 728 | if (format == AUDIO_FORMAT_DEFAULT) { |
| 729 | ALOGE("%s: Unrecognized format %s", __func__, formatLiteral.c_str()); |
| 730 | return Status::fromStatusT(BAD_VALUE); |
| 731 | } |
| 732 | Element pair = std::make_pair(format, Collection::mapped_type{}); |
| 733 | |
| 734 | std::string subformatsLiteral = getXmlAttribute(cur, Attributes::subformats); |
| 735 | if (subformatsLiteral.empty()) return pair; |
| 736 | FormatVector subformats = formatsFromString(subformatsLiteral, " "); |
| 737 | for (const auto& subformat : subformats) { |
| 738 | auto result = pair.second.insert(subformat); |
| 739 | if (!result.second) { |
| 740 | ALOGE("%s: could not add subformat %x to collection", __func__, subformat); |
| 741 | return Status::fromStatusT(BAD_VALUE); |
| 742 | } |
| 743 | } |
| 744 | return pair; |
| 745 | } |
| 746 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 747 | status_t PolicySerializer::deserialize(const char *configFile, AudioPolicyConfig *config) |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 748 | { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 749 | auto doc = make_xmlUnique(xmlParseFile(configFile)); |
| 750 | if (doc == nullptr) { |
| 751 | ALOGE("%s: Could not parse %s document.", __func__, configFile); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 752 | return BAD_VALUE; |
| 753 | } |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 754 | xmlNodePtr root = xmlDocGetRootElement(doc.get()); |
| 755 | if (root == NULL) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 756 | ALOGE("%s: Could not parse %s document: empty.", __func__, configFile); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 757 | return BAD_VALUE; |
| 758 | } |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 759 | if (xmlXIncludeProcess(doc.get()) < 0) { |
| 760 | ALOGE("%s: libxml failed to resolve XIncludes on %s document.", __func__, configFile); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 761 | } |
| 762 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 763 | if (xmlStrcmp(root->name, reinterpret_cast<const xmlChar*>(rootName))) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 764 | ALOGE("%s: No %s root element found in xml data %s.", __func__, rootName, |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 765 | reinterpret_cast<const char*>(root->name)); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 766 | return BAD_VALUE; |
| 767 | } |
| 768 | |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 769 | std::string version = getXmlAttribute(root, versionAttribute); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 770 | if (version.empty()) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 771 | ALOGE("%s: No version found in root node %s", __func__, rootName); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 772 | return BAD_VALUE; |
| 773 | } |
| 774 | if (version != mVersion) { |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 775 | ALOGE("%s: Version does not match; expect %s got %s", __func__, mVersion.c_str(), |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 776 | version.c_str()); |
| 777 | return BAD_VALUE; |
| 778 | } |
| 779 | // Lets deserialize children |
| 780 | // Modules |
| 781 | ModuleTraits::Collection modules; |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 782 | status_t status = deserializeCollection<ModuleTraits>(root, &modules, config); |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 783 | if (status != NO_ERROR) { |
| 784 | return status; |
| 785 | } |
| 786 | config->setHwModules(modules); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 787 | |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 788 | // Global Configuration |
| Mikhail Naganov | 43c386c | 2018-09-19 12:38:29 -0700 | [diff] [blame] | 789 | GlobalConfigTraits::deserialize(root, config); |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 790 | |
| Mikhail Naganov | 778bc1f | 2018-09-14 16:28:52 -0700 | [diff] [blame] | 791 | // Surround configuration |
| 792 | SurroundSoundTraits::deserialize(root, config); |
| 793 | |
| François Gaffie | f4ad6e5 | 2015-11-19 16:59:57 +0100 | [diff] [blame] | 794 | return android::OK; |
| 795 | } |
| 796 | |
| Mikhail Naganov | a289aea | 2018-09-17 15:26:23 -0700 | [diff] [blame] | 797 | } // namespace |
| 798 | |
| 799 | status_t deserializeAudioPolicyFile(const char *fileName, AudioPolicyConfig *config) |
| 800 | { |
| 801 | PolicySerializer serializer; |
| 802 | return serializer.deserialize(fileName, config); |
| 803 | } |
| 804 | |
| Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 805 | } // namespace android |