1 /* 2 * Copyright (C) 2023 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 "AHAL_AidlXsdc" 18 #include <android-base/logging.h> 19 #include <error/expected_utils.h> 20 #include <media/AidlConversionCppNdk.h> 21 #include <media/TypeConverter.h> 22 23 #include "core-impl/AidlConversionXsdc.h" 24 25 using aidl::android::media::audio::common::AudioFormatDescription; 26 27 namespace xsd = android::audio::policy::configuration; 28 29 namespace aidl::android::hardware::audio::core::internal { 30 xsdc2aidl_AudioFormatDescription(const std::string & xsdc)31ConversionResult<AudioFormatDescription> xsdc2aidl_AudioFormatDescription(const std::string& xsdc) { 32 return legacy2aidl_audio_format_t_AudioFormatDescription(::android::formatFromString(xsdc)); 33 } 34 xsdc2aidl_SurroundFormatFamily(const::xsd::SurroundFormats::Format & xsdc)35ConversionResult<SurroundSoundConfig::SurroundFormatFamily> xsdc2aidl_SurroundFormatFamily( 36 const ::xsd::SurroundFormats::Format& xsdc) { 37 SurroundSoundConfig::SurroundFormatFamily aidl; 38 aidl.primaryFormat = VALUE_OR_RETURN(xsdc2aidl_AudioFormatDescription(xsdc.getName())); 39 if (xsdc.hasSubformats()) { 40 aidl.subFormats = VALUE_OR_RETURN(convertContainer<std::vector<AudioFormatDescription>>( 41 xsdc.getSubformats(), xsdc2aidl_AudioFormatDescription)); 42 } 43 return aidl; 44 } 45 xsdc2aidl_SurroundSoundConfig(const::xsd::SurroundSound & xsdc)46ConversionResult<SurroundSoundConfig> xsdc2aidl_SurroundSoundConfig( 47 const ::xsd::SurroundSound& xsdc) { 48 SurroundSoundConfig aidl; 49 if (!xsdc.hasFormats() || !xsdc.getFirstFormats()->hasFormat()) return aidl; 50 aidl.formatFamilies = VALUE_OR_RETURN( 51 convertContainer<std::vector<SurroundSoundConfig::SurroundFormatFamily>>( 52 xsdc.getFirstFormats()->getFormat(), xsdc2aidl_SurroundFormatFamily)); 53 return aidl; 54 } 55 56 } // namespace aidl::android::hardware::audio::core::internal 57