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 21 #include <aidl/android/hardware/audio/core/SurroundSoundConfig.h> 22 #include <aidl/android/media/audio/common/AudioHalEngineConfig.h> 23 #include <android_audio_policy_configuration.h> 24 #include <android_audio_policy_configuration_enums.h> 25 26 #include "core-impl/XmlConverter.h" 27 28 namespace aidl::android::hardware::audio::core::internal { 29 30 class AudioPolicyConfigXmlConverter { 31 public: AudioPolicyConfigXmlConverter(const std::string & configFilePath)32 explicit AudioPolicyConfigXmlConverter(const std::string& configFilePath) 33 : mConverter(configFilePath, &::android::audio::policy::configuration::read) {} 34 getError()35 std::string getError() const { return mConverter.getError(); } getStatus()36 ::android::status_t getStatus() const { return mConverter.getStatus(); } 37 38 const ::aidl::android::media::audio::common::AudioHalEngineConfig& getAidlEngineConfig(); 39 const SurroundSoundConfig& getSurroundSoundConfig(); 40 41 // Public for testing purposes. 42 static const SurroundSoundConfig& getDefaultSurroundSoundConfig(); 43 44 private: 45 const std::optional<::android::audio::policy::configuration::AudioPolicyConfiguration>& getXsdcConfig()46 getXsdcConfig() const { 47 return mConverter.getXsdcConfig(); 48 } 49 void addVolumeGroupstoEngineConfig(); 50 void mapStreamToVolumeCurve( 51 const ::android::audio::policy::configuration::Volume& xsdcVolumeCurve); 52 void mapStreamsToVolumeCurves(); 53 void parseVolumes(); 54 ::aidl::android::media::audio::common::AudioHalVolumeCurve::CurvePoint convertCurvePointToAidl( 55 const std::string& xsdcCurvePoint); 56 ::aidl::android::media::audio::common::AudioHalVolumeCurve convertVolumeCurveToAidl( 57 const ::android::audio::policy::configuration::Volume& xsdcVolumeCurve); 58 59 ::aidl::android::media::audio::common::AudioHalEngineConfig mAidlEngineConfig; 60 XmlConverter<::android::audio::policy::configuration::AudioPolicyConfiguration> mConverter; 61 std::unordered_map<std::string, ::android::audio::policy::configuration::Reference> 62 mVolumesReferenceMap; 63 std::unordered_map<::android::audio::policy::configuration::AudioStreamType, 64 std::vector<::aidl::android::media::audio::common::AudioHalVolumeCurve>> 65 mStreamToVolumeCurvesMap; 66 }; 67 68 } // namespace aidl::android::hardware::audio::core::internal 69