1 /* 2 * Copyright (C) 2021 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 // clang-format off 20 #include PATH(android/hardware/audio/FILE_VERSION/types.h) 21 // clang-format off 22 23 #include <vector> 24 25 #include <system/audio.h> 26 27 #include <common/all-versions/VersionUtils.h> 28 #include <VersionUtils.h> 29 30 namespace android { 31 namespace hardware { 32 namespace audio { 33 namespace CPP_VERSION { 34 namespace implementation { 35 36 using ::android::hardware::audio::common::utils::EnumBitfield; 37 using ::android::hardware::hidl_vec; 38 using namespace ::android::hardware::audio::common::CPP_VERSION; 39 using namespace ::android::hardware::audio::CPP_VERSION; 40 41 struct CoreUtils { 42 // Note: the converters for DeviceAddress have to be in CoreUtils for HAL V4 43 // because DeviceAddress used to be defined in the core HAL. For V5 and above 44 // these functions simply delegate to HidlUtils. 45 static status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType, 46 char* halDeviceAddress); 47 static status_t deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress, 48 DeviceAddress* device); 49 #if MAJOR_VERSION >= 4 50 static status_t microphoneInfoFromHal(const struct audio_microphone_characteristic_t& halMicInfo, 51 MicrophoneInfo* micInfo); 52 static status_t microphoneInfoToHal(const MicrophoneInfo& micInfo, audio_microphone_characteristic_t* halMicInfo); 53 // Note: {Sink|Source}Metadata types are defined in 'common' (since V5), so they can be used 54 // by the BT HAL. However, the converters are defined here, not in HidlUtils to avoid adding 55 // conditionals to handle V4. The converters are only used by 'core' HAL anyways. 56 static status_t sinkMetadataFromHal(const std::vector<record_track_metadata_t>& halTracks, 57 SinkMetadata* sinkMetadata); 58 static status_t sinkMetadataFromHalV7(const std::vector<record_track_metadata_v7_t>& halTracks, 59 bool ignoreNonVendorTags, SinkMetadata* sinkMetadata); 60 static status_t sinkMetadataToHal(const SinkMetadata& sinkMetadata, 61 std::vector<record_track_metadata_t>* halTracks); 62 static status_t sinkMetadataToHalV7(const SinkMetadata& sinkMetadata, bool ignoreNonVendorTags, 63 std::vector<record_track_metadata_v7_t>* halTracks); 64 static status_t sourceMetadataFromHal(const std::vector<playback_track_metadata_t>& halTracks, 65 SourceMetadata* sourceMetadata); 66 static status_t sourceMetadataFromHalV7(const std::vector<playback_track_metadata_v7_t>& halTracks, 67 bool ignoreNonVendorTags, SourceMetadata* sourceMetadata); 68 static status_t sourceMetadataToHal(const SourceMetadata& sourceMetadata, 69 std::vector<playback_track_metadata_t>* halTracks); 70 static status_t sourceMetadataToHalV7(const SourceMetadata& sourceMetadata, bool ignoreNonVendorTags, 71 std::vector<playback_track_metadata_v7_t>* halTracks); 72 #endif 73 74 #if MAJOR_VERSION <= 6 75 using AudioInputFlags = 76 ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield; 77 using AudioOutputFlags = 78 ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield; audioInputFlagsFromHalCoreUtils79 static inline status_t audioInputFlagsFromHal(audio_input_flags_t halFlagMask, AudioInputFlags* flags) { 80 *flags = EnumBitfield<AudioInputFlag>(halFlagMask); 81 return NO_ERROR; 82 } audioInputFlagsToHalCoreUtils83 static inline status_t audioInputFlagsToHal(AudioInputFlags flags, audio_input_flags_t* halFlagMask) { 84 *halFlagMask = static_cast<audio_input_flags_t>(flags); 85 return NO_ERROR; 86 } audioOutputFlagsFromHalCoreUtils87 static inline status_t audioOutputFlagsFromHal(audio_output_flags_t halFlagMask, AudioOutputFlags* flags) { 88 *flags = EnumBitfield<AudioOutputFlag>(halFlagMask); 89 return NO_ERROR; 90 } audioOutputFlagsToHalCoreUtils91 static inline status_t audioOutputFlagsToHal(AudioOutputFlags flags, audio_output_flags_t* halFlagMask) { 92 *halFlagMask = static_cast<audio_output_flags_t>(flags); 93 return NO_ERROR; 94 } 95 #else 96 using AudioInputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>; 97 using AudioOutputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>; 98 static status_t audioInputFlagsFromHal(audio_input_flags_t halFlagMask, AudioInputFlags* flags); 99 static status_t audioInputFlagsToHal(const AudioInputFlags& flags, audio_input_flags_t* halFlagMask); 100 static status_t audioOutputFlagsFromHal(audio_output_flags_t halFlagMask, AudioOutputFlags* flags); 101 static status_t audioOutputFlagsToHal(const AudioOutputFlags& flags, audio_output_flags_t* halFlagMask); 102 #endif 103 104 }; 105 106 } // namespace implementation 107 } // namespace CPP_VERSION 108 } // namespace audio 109 } // namespace hardware 110 } // namespace android 111