Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 1 | /* |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 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 | |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 17 | #ifndef android_hardware_audio_Hidl_Utils_H_ |
| 18 | #define android_hardware_audio_Hidl_Utils_H_ |
| 19 | |
| 20 | #include PATH(android/hardware/audio/common/FILE_VERSION/types.h) |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 21 | |
| 22 | #include <memory> |
| 23 | |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 24 | #include <system/audio.h> |
| 25 | |
Kevin Rocard | 55b1061 | 2018-11-12 12:33:16 -0800 | [diff] [blame] | 26 | using ::android::hardware::hidl_vec; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
Kevin Rocard | 6891d7e | 2017-12-14 18:39:39 -0800 | [diff] [blame] | 29 | namespace hardware { |
| 30 | namespace audio { |
| 31 | namespace common { |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 32 | namespace CPP_VERSION { |
Mikhail Naganov | 543bf9c | 2018-12-11 16:36:53 -0800 | [diff] [blame] | 33 | namespace implementation { |
| 34 | |
| 35 | using namespace ::android::hardware::audio::common::CPP_VERSION; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 36 | |
Mikhail Naganov | 1b444a5 | 2020-10-29 13:08:05 -0700 | [diff] [blame] | 37 | struct HidlUtils { |
| 38 | #if MAJOR_VERSION < 7 |
Andy Hung | 7aab101 | 2020-02-14 15:39:55 -0800 | [diff] [blame] | 39 | static status_t audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config); |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 40 | static void audioGainConfigFromHal(const struct audio_gain_config& halConfig, |
| 41 | AudioGainConfig* config); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 42 | static void audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain); |
Mikhail Naganov | 1b444a5 | 2020-10-29 13:08:05 -0700 | [diff] [blame] | 43 | #else |
| 44 | static status_t audioConfigFromHal(const audio_config_t& halConfig, bool isInput, |
| 45 | AudioConfig* config); |
| 46 | static status_t audioGainConfigFromHal(const struct audio_gain_config& halConfig, bool isInput, |
| 47 | AudioGainConfig* config); |
| 48 | static status_t audioGainFromHal(const struct audio_gain& halGain, bool isInput, |
| 49 | AudioGain* gain); |
| 50 | #endif |
| 51 | static status_t audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig); |
| 52 | static status_t audioGainConfigToHal(const AudioGainConfig& config, |
| 53 | struct audio_gain_config* halConfig); |
| 54 | static status_t audioGainToHal(const AudioGain& gain, struct audio_gain* halGain); |
| 55 | static status_t audioUsageFromHal(audio_usage_t halUsage, AudioUsage* usage); |
| 56 | static status_t audioUsageToHal(const AudioUsage& usage, audio_usage_t* halUsage); |
Andy Hung | 7aab101 | 2020-02-14 15:39:55 -0800 | [diff] [blame] | 57 | static status_t audioOffloadInfoFromHal(const audio_offload_info_t& halOffload, |
| 58 | AudioOffloadInfo* offload); |
Mikhail Naganov | 1b444a5 | 2020-10-29 13:08:05 -0700 | [diff] [blame] | 59 | static status_t audioOffloadInfoToHal(const AudioOffloadInfo& offload, |
| 60 | audio_offload_info_t* halOffload); |
| 61 | static status_t audioPortConfigFromHal(const struct audio_port_config& halConfig, |
| 62 | AudioPortConfig* config); |
| 63 | static status_t audioPortConfigToHal(const AudioPortConfig& config, |
| 64 | struct audio_port_config* halConfig); |
| 65 | static status_t audioPortConfigsFromHal(unsigned int numHalConfigs, |
| 66 | const struct audio_port_config* halConfigs, |
| 67 | hidl_vec<AudioPortConfig>* configs) { |
| 68 | status_t result = NO_ERROR; |
| 69 | configs->resize(numHalConfigs); |
| 70 | for (unsigned int i = 0; i < numHalConfigs; ++i) { |
| 71 | if (status_t status = audioPortConfigFromHal(halConfigs[i], &(*configs)[i]); |
| 72 | status != NO_ERROR) { |
| 73 | result = status; |
| 74 | } |
| 75 | } |
| 76 | return result; |
| 77 | } |
| 78 | static status_t audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& configs, |
| 79 | std::unique_ptr<audio_port_config[]>* halConfigs) { |
| 80 | status_t result = NO_ERROR; |
| 81 | halConfigs->reset(new audio_port_config[configs.size()]); |
| 82 | for (size_t i = 0; i < configs.size(); ++i) { |
| 83 | if (status_t status = audioPortConfigToHal(configs[i], &(*halConfigs)[i]); |
| 84 | status != NO_ERROR) { |
| 85 | result = status; |
| 86 | } |
| 87 | } |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | // PLEASE DO NOT USE, will be removed in a couple of days |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 92 | static std::unique_ptr<audio_port_config[]> audioPortConfigsToHal( |
Mikhail Naganov | 1b444a5 | 2020-10-29 13:08:05 -0700 | [diff] [blame] | 93 | const hidl_vec<AudioPortConfig>& configs) { |
| 94 | std::unique_ptr<audio_port_config[]> halConfigs; |
| 95 | (void)audioPortConfigsToHal(configs, &halConfigs); |
| 96 | return halConfigs; |
| 97 | } |
| 98 | |
| 99 | static status_t audioPortFromHal(const struct audio_port& halPort, AudioPort* port); |
| 100 | static status_t audioPortToHal(const AudioPort& port, struct audio_port* halPort); |
| 101 | #if MAJOR_VERSION >= 7 |
| 102 | static status_t audioChannelMaskFromHal(audio_channel_mask_t halChannelMask, bool isInput, |
| 103 | AudioChannelMask* channelMask); |
| 104 | static status_t audioChannelMaskToHal(const AudioChannelMask& channelMask, |
| 105 | audio_channel_mask_t* halChannelMask); |
| 106 | static status_t audioConfigBaseFromHal(const audio_config_base_t& halConfigBase, bool isInput, |
| 107 | AudioConfigBase* configBase); |
| 108 | static status_t audioConfigBaseToHal(const AudioConfigBase& configBase, |
| 109 | audio_config_base_t* halConfigBase); |
| 110 | static status_t audioDeviceTypeFromHal(audio_devices_t halDevice, AudioDevice* device); |
| 111 | static status_t audioDeviceTypeToHal(const AudioDevice& device, audio_devices_t* halDevice); |
| 112 | static status_t audioFormatFromHal(audio_format_t halFormat, AudioFormat* format); |
| 113 | static status_t audioFormatToHal(const AudioFormat& format, audio_format_t* halFormat); |
| 114 | static status_t audioGainModeMaskFromHal(audio_gain_mode_t halGainModeMask, |
| 115 | hidl_vec<AudioGainMode>* gainModeMask); |
| 116 | static status_t audioGainModeMaskToHal(const hidl_vec<AudioGainMode>& gainModeMask, |
| 117 | audio_gain_mode_t* halGainModeMask); |
| 118 | static status_t audioPortFromHal(const struct audio_port_v7& halPort, AudioPort* port); |
| 119 | static status_t audioPortToHal(const AudioPort& port, struct audio_port_v7* halPort); |
| 120 | static status_t audioProfileFromHal(const struct audio_profile& halProfile, bool isInput, |
| 121 | AudioProfile* profile); |
| 122 | static status_t audioProfileToHal(const AudioProfile& profile, |
| 123 | struct audio_profile* halProfile); |
| 124 | static status_t audioSourceFromHal(audio_source_t halSource, AudioSource* source); |
| 125 | static status_t audioSourceToHal(const AudioSource& source, audio_source_t* halSource); |
| 126 | static status_t audioStreamTypeFromHal(audio_stream_type_t halStreamType, |
| 127 | AudioStreamType* streamType); |
| 128 | static status_t audioStreamTypeToHal(const AudioStreamType& streamType, |
| 129 | audio_stream_type_t* halStreamType); |
| 130 | static status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType, |
| 131 | char* halDeviceAddress); |
| 132 | static status_t deviceAddressFromHal(audio_devices_t halDeviceType, |
| 133 | const char* halDeviceAddress, DeviceAddress* device); |
| 134 | |
| 135 | private: |
| 136 | static status_t audioIndexChannelMaskFromHal(audio_channel_mask_t halChannelMask, |
| 137 | AudioChannelMask* channelMask); |
| 138 | static status_t audioInputChannelMaskFromHal(audio_channel_mask_t halChannelMask, |
| 139 | AudioChannelMask* channelMask); |
| 140 | static status_t audioOutputChannelMaskFromHal(audio_channel_mask_t halChannelMask, |
| 141 | AudioChannelMask* channelMask); |
| 142 | static status_t audioPortExtendedInfoFromHal( |
| 143 | audio_port_role_t role, audio_port_type_t type, |
| 144 | const struct audio_port_config_device_ext& device, |
| 145 | const struct audio_port_config_mix_ext& mix, |
| 146 | const struct audio_port_config_session_ext& session, AudioPortExtendedInfo* ext, |
| 147 | bool* isInput); |
| 148 | static status_t audioPortExtendedInfoToHal(const AudioPortExtendedInfo& ext, |
| 149 | audio_port_role_t* role, audio_port_type_t* type, |
| 150 | struct audio_port_config_device_ext* device, |
| 151 | struct audio_port_config_mix_ext* mix, |
| 152 | struct audio_port_config_session_ext* session); |
| 153 | #endif |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Mikhail Naganov | 543bf9c | 2018-12-11 16:36:53 -0800 | [diff] [blame] | 156 | } // namespace implementation |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 157 | } // namespace CPP_VERSION |
Kevin Rocard | 6891d7e | 2017-12-14 18:39:39 -0800 | [diff] [blame] | 158 | } // namespace common |
| 159 | } // namespace audio |
| 160 | } // namespace hardware |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 161 | } // namespace android |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 162 | |
| 163 | #endif // android_hardware_audio_Hidl_Utils_H_ |