• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include <android_audio_policy_engine_configuration.h>
23 #include <android_audio_policy_engine_configuration_enums.h>
24 #include <media/AidlConversionUtil.h>
25 
26 #include "core-impl/XmlConverter.h"
27 
28 namespace aidl::android::hardware::audio::core::internal {
29 
30 class EngineConfigXmlConverter {
31   public:
EngineConfigXmlConverter(const std::string & configFilePath)32     explicit EngineConfigXmlConverter(const std::string& configFilePath)
33         : mConverter(configFilePath, &::android::audio::policy::engine::configuration::read) {
34         if (mConverter.getXsdcConfig()) {
35             init();
36         }
37     }
38 
getError()39     std::string getError() const { return mConverter.getError(); }
getStatus()40     ::android::status_t getStatus() const { return mConverter.getStatus(); }
41 
42     ::aidl::android::media::audio::common::AudioHalEngineConfig& getAidlEngineConfig();
43 
44   private:
45     const std::optional<::android::audio::policy::engine::configuration::Configuration>&
getXsdcConfig()46     getXsdcConfig() {
47         return mConverter.getXsdcConfig();
48     }
49     void init();
50     void initProductStrategyMap();
51     ConversionResult<::aidl::android::media::audio::common::AudioAttributes>
52     convertAudioAttributesToAidl(
53             const ::android::audio::policy::engine::configuration::AttributesType&
54                     xsdcAudioAttributes);
55     ConversionResult<::aidl::android::media::audio::common::AudioHalAttributesGroup>
56     convertAttributesGroupToAidl(
57             const ::android::audio::policy::engine::configuration::AttributesGroup&
58                     xsdcAttributesGroup);
59     ConversionResult<::aidl::android::media::audio::common::AudioHalProductStrategy>
60     convertProductStrategyToAidl(const ::android::audio::policy::engine::configuration::
61                                          ProductStrategies::ProductStrategy& xsdcProductStrategy);
62     ConversionResult<int> convertProductStrategyNameToAidl(
63             const std::string& xsdcProductStrategyName);
64     ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeCurve>
65     convertVolumeCurveToAidl(
66             const ::android::audio::policy::engine::configuration::Volume& xsdcVolumeCurve);
67     ConversionResult<::aidl::android::media::audio::common::AudioHalVolumeGroup>
68     convertVolumeGroupToAidl(
69             const ::android::audio::policy::engine::configuration::VolumeGroupsType::VolumeGroup&
70                     xsdcVolumeGroup);
71 
72     ::aidl::android::media::audio::common::AudioHalEngineConfig mAidlEngineConfig;
73     XmlConverter<::android::audio::policy::engine::configuration::Configuration> mConverter;
74     std::unordered_map<std::string,
75                        ::android::audio::policy::engine::configuration::AttributesRefType>
76             mAttributesReferenceMap;
77     std::unordered_map<std::string, ::android::audio::policy::engine::configuration::VolumeRef>
78             mVolumesReferenceMap;
79     std::unordered_map<std::string, int> mProductStrategyMap;
80     int mNextVendorStrategy = ::aidl::android::media::audio::common::AudioHalProductStrategy::
81             VENDOR_STRATEGY_ID_START;
82     std::optional<int> mDefaultProductStrategyId;
83 };
84 
85 }  // namespace aidl::android::hardware::audio::core::internal
86