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