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 | #include "HidlUtils.h" |
Kevin Rocard | 6891d7e | 2017-12-14 18:39:39 -0800 | [diff] [blame] | 18 | |
Kevin Rocard | b3f36c0 | 2018-02-26 18:45:07 -0800 | [diff] [blame] | 19 | #include <common/all-versions/VersionUtils.h> |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 20 | #include <string.h> |
| 21 | |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 22 | using ::android::hardware::audio::common::utils::EnumBitfield; |
Kevin Rocard | b3f36c0 | 2018-02-26 18:45:07 -0800 | [diff] [blame] | 23 | |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 24 | namespace android { |
Kevin Rocard | 6891d7e | 2017-12-14 18:39:39 -0800 | [diff] [blame] | 25 | namespace hardware { |
| 26 | namespace audio { |
| 27 | namespace common { |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 28 | namespace CPP_VERSION { |
Mikhail Naganov | 543bf9c | 2018-12-11 16:36:53 -0800 | [diff] [blame^] | 29 | namespace implementation { |
| 30 | |
| 31 | using namespace ::android::hardware::audio::common::CPP_VERSION; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 32 | |
| 33 | void HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) { |
| 34 | config->sampleRateHz = halConfig.sample_rate; |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 35 | config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 36 | config->format = AudioFormat(halConfig.format); |
| 37 | audioOffloadInfoFromHal(halConfig.offload_info, &config->offloadInfo); |
| 38 | config->frameCount = halConfig.frame_count; |
| 39 | } |
| 40 | |
| 41 | void HidlUtils::audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig) { |
| 42 | memset(halConfig, 0, sizeof(audio_config_t)); |
| 43 | halConfig->sample_rate = config.sampleRateHz; |
| 44 | halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask); |
| 45 | halConfig->format = static_cast<audio_format_t>(config.format); |
| 46 | audioOffloadInfoToHal(config.offloadInfo, &halConfig->offload_info); |
| 47 | halConfig->frame_count = config.frameCount; |
| 48 | } |
| 49 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 50 | void HidlUtils::audioGainConfigFromHal(const struct audio_gain_config& halConfig, |
| 51 | AudioGainConfig* config) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 52 | config->index = halConfig.index; |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 53 | config->mode = EnumBitfield<AudioGainMode>(halConfig.mode); |
| 54 | config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 55 | for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) { |
| 56 | config->values[i] = halConfig.values[i]; |
| 57 | } |
| 58 | config->rampDurationMs = halConfig.ramp_duration_ms; |
| 59 | } |
| 60 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 61 | void HidlUtils::audioGainConfigToHal(const AudioGainConfig& config, |
| 62 | struct audio_gain_config* halConfig) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 63 | halConfig->index = config.index; |
| 64 | halConfig->mode = static_cast<audio_gain_mode_t>(config.mode); |
| 65 | halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask); |
| 66 | memset(halConfig->values, 0, sizeof(halConfig->values)); |
| 67 | for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) { |
| 68 | halConfig->values[i] = config.values[i]; |
| 69 | } |
| 70 | halConfig->ramp_duration_ms = config.rampDurationMs; |
| 71 | } |
| 72 | |
| 73 | void HidlUtils::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) { |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 74 | gain->mode = EnumBitfield<AudioGainMode>(halGain.mode); |
| 75 | gain->channelMask = EnumBitfield<AudioChannelMask>(halGain.channel_mask); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 76 | gain->minValue = halGain.min_value; |
| 77 | gain->maxValue = halGain.max_value; |
| 78 | gain->defaultValue = halGain.default_value; |
| 79 | gain->stepValue = halGain.step_value; |
| 80 | gain->minRampMs = halGain.min_ramp_ms; |
| 81 | gain->maxRampMs = halGain.max_ramp_ms; |
| 82 | } |
| 83 | |
| 84 | void HidlUtils::audioGainToHal(const AudioGain& gain, struct audio_gain* halGain) { |
| 85 | halGain->mode = static_cast<audio_gain_mode_t>(gain.mode); |
| 86 | halGain->channel_mask = static_cast<audio_channel_mask_t>(gain.channelMask); |
| 87 | halGain->min_value = gain.minValue; |
| 88 | halGain->max_value = gain.maxValue; |
| 89 | halGain->default_value = gain.defaultValue; |
| 90 | halGain->step_value = gain.stepValue; |
| 91 | halGain->min_ramp_ms = gain.minRampMs; |
| 92 | halGain->max_ramp_ms = gain.maxRampMs; |
| 93 | } |
| 94 | |
Kevin Rocard | 9733136 | 2018-02-23 18:43:39 -0800 | [diff] [blame] | 95 | AudioUsage HidlUtils::audioUsageFromHal(const audio_usage_t halUsage) { |
| 96 | switch (halUsage) { |
| 97 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 98 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 99 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 100 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 101 | return AudioUsage::NOTIFICATION; |
| 102 | default: |
| 103 | return static_cast<AudioUsage>(halUsage); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | audio_usage_t HidlUtils::audioUsageToHal(const AudioUsage usage) { |
| 108 | return static_cast<audio_usage_t>(usage); |
| 109 | } |
| 110 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 111 | void HidlUtils::audioOffloadInfoFromHal(const audio_offload_info_t& halOffload, |
| 112 | AudioOffloadInfo* offload) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 113 | offload->sampleRateHz = halOffload.sample_rate; |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 114 | offload->channelMask = EnumBitfield<AudioChannelMask>(halOffload.channel_mask); |
Mikhail Naganov | 685f0e3 | 2016-12-16 17:18:08 -0800 | [diff] [blame] | 115 | offload->format = AudioFormat(halOffload.format); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 116 | offload->streamType = AudioStreamType(halOffload.stream_type); |
| 117 | offload->bitRatePerSecond = halOffload.bit_rate; |
| 118 | offload->durationMicroseconds = halOffload.duration_us; |
| 119 | offload->hasVideo = halOffload.has_video; |
| 120 | offload->isStreaming = halOffload.is_streaming; |
vivek mehta | 9236036 | 2017-04-06 18:27:34 -0700 | [diff] [blame] | 121 | offload->bitWidth = halOffload.bit_width; |
| 122 | offload->bufferSize = halOffload.offload_buffer_size; |
Kevin Rocard | 9733136 | 2018-02-23 18:43:39 -0800 | [diff] [blame] | 123 | offload->usage = audioUsageFromHal(halOffload.usage); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 126 | void HidlUtils::audioOffloadInfoToHal(const AudioOffloadInfo& offload, |
| 127 | audio_offload_info_t* halOffload) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 128 | *halOffload = AUDIO_INFO_INITIALIZER; |
| 129 | halOffload->sample_rate = offload.sampleRateHz; |
| 130 | halOffload->channel_mask = static_cast<audio_channel_mask_t>(offload.channelMask); |
Mikhail Naganov | 685f0e3 | 2016-12-16 17:18:08 -0800 | [diff] [blame] | 131 | halOffload->format = static_cast<audio_format_t>(offload.format); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 132 | halOffload->stream_type = static_cast<audio_stream_type_t>(offload.streamType); |
| 133 | halOffload->bit_rate = offload.bitRatePerSecond; |
| 134 | halOffload->duration_us = offload.durationMicroseconds; |
| 135 | halOffload->has_video = offload.hasVideo; |
| 136 | halOffload->is_streaming = offload.isStreaming; |
Mikhail Naganov | c292056 | 2016-11-21 18:33:52 -0800 | [diff] [blame] | 137 | halOffload->bit_width = offload.bitWidth; |
| 138 | halOffload->offload_buffer_size = offload.bufferSize; |
Kevin Rocard | 9733136 | 2018-02-23 18:43:39 -0800 | [diff] [blame] | 139 | halOffload->usage = audioUsageToHal(offload.usage); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 142 | void HidlUtils::audioPortConfigFromHal(const struct audio_port_config& halConfig, |
| 143 | AudioPortConfig* config) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 144 | config->id = halConfig.id; |
| 145 | config->role = AudioPortRole(halConfig.role); |
| 146 | config->type = AudioPortType(halConfig.type); |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 147 | config->configMask = EnumBitfield<AudioPortConfigMask>(halConfig.config_mask); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 148 | config->sampleRateHz = halConfig.sample_rate; |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 149 | config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 150 | config->format = AudioFormat(halConfig.format); |
| 151 | audioGainConfigFromHal(halConfig.gain, &config->gain); |
| 152 | switch (halConfig.type) { |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 153 | case AUDIO_PORT_TYPE_NONE: |
| 154 | break; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 155 | case AUDIO_PORT_TYPE_DEVICE: { |
| 156 | config->ext.device.hwModule = halConfig.ext.device.hw_module; |
| 157 | config->ext.device.type = AudioDevice(halConfig.ext.device.type); |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 158 | memcpy(config->ext.device.address.data(), halConfig.ext.device.address, |
| 159 | AUDIO_DEVICE_MAX_ADDRESS_LEN); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | case AUDIO_PORT_TYPE_MIX: { |
| 163 | config->ext.mix.hwModule = halConfig.ext.mix.hw_module; |
| 164 | config->ext.mix.ioHandle = halConfig.ext.mix.handle; |
| 165 | if (halConfig.role == AUDIO_PORT_ROLE_SOURCE) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 166 | config->ext.mix.useCase.stream = AudioStreamType(halConfig.ext.mix.usecase.stream); |
Mikhail Naganov | 93b5778 | 2018-07-09 14:28:57 -0700 | [diff] [blame] | 167 | } else if (halConfig.role == AUDIO_PORT_ROLE_SINK) { |
| 168 | config->ext.mix.useCase.source = AudioSource(halConfig.ext.mix.usecase.source); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 169 | } |
| 170 | break; |
| 171 | } |
| 172 | case AUDIO_PORT_TYPE_SESSION: { |
| 173 | config->ext.session.session = halConfig.ext.session.session; |
| 174 | break; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 179 | void HidlUtils::audioPortConfigToHal(const AudioPortConfig& config, |
| 180 | struct audio_port_config* halConfig) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 181 | memset(halConfig, 0, sizeof(audio_port_config)); |
| 182 | halConfig->id = config.id; |
| 183 | halConfig->role = static_cast<audio_port_role_t>(config.role); |
| 184 | halConfig->type = static_cast<audio_port_type_t>(config.type); |
| 185 | halConfig->config_mask = static_cast<unsigned int>(config.configMask); |
| 186 | halConfig->sample_rate = config.sampleRateHz; |
| 187 | halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask); |
| 188 | halConfig->format = static_cast<audio_format_t>(config.format); |
| 189 | audioGainConfigToHal(config.gain, &halConfig->gain); |
| 190 | switch (config.type) { |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 191 | case AudioPortType::NONE: |
| 192 | break; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 193 | case AudioPortType::DEVICE: { |
| 194 | halConfig->ext.device.hw_module = config.ext.device.hwModule; |
| 195 | halConfig->ext.device.type = static_cast<audio_devices_t>(config.ext.device.type); |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 196 | memcpy(halConfig->ext.device.address, config.ext.device.address.data(), |
| 197 | AUDIO_DEVICE_MAX_ADDRESS_LEN); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | case AudioPortType::MIX: { |
| 201 | halConfig->ext.mix.hw_module = config.ext.mix.hwModule; |
| 202 | halConfig->ext.mix.handle = config.ext.mix.ioHandle; |
| 203 | if (config.role == AudioPortRole::SOURCE) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 204 | halConfig->ext.mix.usecase.stream = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 205 | static_cast<audio_stream_type_t>(config.ext.mix.useCase.stream); |
Mikhail Naganov | 93b5778 | 2018-07-09 14:28:57 -0700 | [diff] [blame] | 206 | } else if (config.role == AudioPortRole::SINK) { |
| 207 | halConfig->ext.mix.usecase.source = |
| 208 | static_cast<audio_source_t>(config.ext.mix.useCase.source); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 209 | } |
| 210 | break; |
| 211 | } |
| 212 | case AudioPortType::SESSION: { |
| 213 | halConfig->ext.session.session = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 214 | static_cast<audio_session_t>(config.ext.session.session); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 220 | void HidlUtils::audioPortConfigsFromHal(unsigned int numHalConfigs, |
| 221 | const struct audio_port_config* halConfigs, |
| 222 | hidl_vec<AudioPortConfig>* configs) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 223 | configs->resize(numHalConfigs); |
| 224 | for (unsigned int i = 0; i < numHalConfigs; ++i) { |
| 225 | audioPortConfigFromHal(halConfigs[i], &(*configs)[i]); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | std::unique_ptr<audio_port_config[]> HidlUtils::audioPortConfigsToHal( |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 230 | const hidl_vec<AudioPortConfig>& configs) { |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 231 | std::unique_ptr<audio_port_config[]> halConfigs(new audio_port_config[configs.size()]); |
| 232 | for (size_t i = 0; i < configs.size(); ++i) { |
| 233 | audioPortConfigToHal(configs[i], &halConfigs[i]); |
| 234 | } |
| 235 | return halConfigs; |
| 236 | } |
| 237 | |
| 238 | void HidlUtils::audioPortFromHal(const struct audio_port& halPort, AudioPort* port) { |
| 239 | port->id = halPort.id; |
| 240 | port->role = AudioPortRole(halPort.role); |
| 241 | port->type = AudioPortType(halPort.type); |
| 242 | port->name.setToExternal(halPort.name, strlen(halPort.name)); |
| 243 | port->sampleRates.resize(halPort.num_sample_rates); |
| 244 | for (size_t i = 0; i < halPort.num_sample_rates; ++i) { |
| 245 | port->sampleRates[i] = halPort.sample_rates[i]; |
| 246 | } |
| 247 | port->channelMasks.resize(halPort.num_channel_masks); |
| 248 | for (size_t i = 0; i < halPort.num_channel_masks; ++i) { |
Kevin Rocard | f5305b3 | 2018-11-13 10:41:53 -0800 | [diff] [blame] | 249 | port->channelMasks[i] = EnumBitfield<AudioChannelMask>(halPort.channel_masks[i]); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 250 | } |
| 251 | port->formats.resize(halPort.num_formats); |
| 252 | for (size_t i = 0; i < halPort.num_formats; ++i) { |
| 253 | port->formats[i] = AudioFormat(halPort.formats[i]); |
| 254 | } |
| 255 | port->gains.resize(halPort.num_gains); |
| 256 | for (size_t i = 0; i < halPort.num_gains; ++i) { |
| 257 | audioGainFromHal(halPort.gains[i], &port->gains[i]); |
| 258 | } |
| 259 | audioPortConfigFromHal(halPort.active_config, &port->activeConfig); |
| 260 | switch (halPort.type) { |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 261 | case AUDIO_PORT_TYPE_NONE: |
| 262 | break; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 263 | case AUDIO_PORT_TYPE_DEVICE: { |
| 264 | port->ext.device.hwModule = halPort.ext.device.hw_module; |
| 265 | port->ext.device.type = AudioDevice(halPort.ext.device.type); |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 266 | memcpy(port->ext.device.address.data(), halPort.ext.device.address, |
| 267 | AUDIO_DEVICE_MAX_ADDRESS_LEN); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 268 | break; |
| 269 | } |
| 270 | case AUDIO_PORT_TYPE_MIX: { |
| 271 | port->ext.mix.hwModule = halPort.ext.mix.hw_module; |
| 272 | port->ext.mix.ioHandle = halPort.ext.mix.handle; |
| 273 | port->ext.mix.latencyClass = AudioMixLatencyClass(halPort.ext.mix.latency_class); |
| 274 | break; |
| 275 | } |
| 276 | case AUDIO_PORT_TYPE_SESSION: { |
| 277 | port->ext.session.session = halPort.ext.session.session; |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | void HidlUtils::audioPortToHal(const AudioPort& port, struct audio_port* halPort) { |
| 284 | memset(halPort, 0, sizeof(audio_port)); |
| 285 | halPort->id = port.id; |
| 286 | halPort->role = static_cast<audio_port_role_t>(port.role); |
| 287 | halPort->type = static_cast<audio_port_type_t>(port.type); |
Kevin Rocard | 7ee6fee | 2018-02-27 10:56:32 -0800 | [diff] [blame] | 288 | strncpy(halPort->name, port.name.c_str(), AUDIO_PORT_MAX_NAME_LEN); |
| 289 | halPort->name[AUDIO_PORT_MAX_NAME_LEN - 1] = '\0'; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 290 | halPort->num_sample_rates = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 291 | std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES)); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 292 | for (size_t i = 0; i < halPort->num_sample_rates; ++i) { |
| 293 | halPort->sample_rates[i] = port.sampleRates[i]; |
| 294 | } |
| 295 | halPort->num_channel_masks = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 296 | std::min(port.channelMasks.size(), static_cast<size_t>(AUDIO_PORT_MAX_CHANNEL_MASKS)); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 297 | for (size_t i = 0; i < halPort->num_channel_masks; ++i) { |
| 298 | halPort->channel_masks[i] = static_cast<audio_channel_mask_t>(port.channelMasks[i]); |
| 299 | } |
| 300 | halPort->num_formats = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 301 | std::min(port.formats.size(), static_cast<size_t>(AUDIO_PORT_MAX_FORMATS)); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 302 | for (size_t i = 0; i < halPort->num_formats; ++i) { |
| 303 | halPort->formats[i] = static_cast<audio_format_t>(port.formats[i]); |
| 304 | } |
| 305 | halPort->num_gains = std::min(port.gains.size(), static_cast<size_t>(AUDIO_PORT_MAX_GAINS)); |
| 306 | for (size_t i = 0; i < halPort->num_gains; ++i) { |
| 307 | audioGainToHal(port.gains[i], &halPort->gains[i]); |
| 308 | } |
| 309 | audioPortConfigToHal(port.activeConfig, &halPort->active_config); |
| 310 | switch (port.type) { |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 311 | case AudioPortType::NONE: |
| 312 | break; |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 313 | case AudioPortType::DEVICE: { |
| 314 | halPort->ext.device.hw_module = port.ext.device.hwModule; |
| 315 | halPort->ext.device.type = static_cast<audio_devices_t>(port.ext.device.type); |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 316 | memcpy(halPort->ext.device.address, port.ext.device.address.data(), |
| 317 | AUDIO_DEVICE_MAX_ADDRESS_LEN); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 318 | break; |
| 319 | } |
| 320 | case AudioPortType::MIX: { |
| 321 | halPort->ext.mix.hw_module = port.ext.mix.hwModule; |
| 322 | halPort->ext.mix.handle = port.ext.mix.ioHandle; |
| 323 | halPort->ext.mix.latency_class = |
Kevin Rocard | dc874e0 | 2017-12-14 18:50:12 -0800 | [diff] [blame] | 324 | static_cast<audio_mix_latency_class_t>(port.ext.mix.latencyClass); |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 325 | break; |
| 326 | } |
| 327 | case AudioPortType::SESSION: { |
| 328 | halPort->ext.session.session = static_cast<audio_session_t>(port.ext.session.session); |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void HidlUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) { |
| 335 | uuid->timeLow = halUuid.timeLow; |
| 336 | uuid->timeMid = halUuid.timeMid; |
| 337 | uuid->versionAndTimeHigh = halUuid.timeHiAndVersion; |
| 338 | uuid->variantAndClockSeqHigh = halUuid.clockSeq; |
| 339 | memcpy(uuid->node.data(), halUuid.node, uuid->node.size()); |
| 340 | } |
| 341 | |
| 342 | void HidlUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) { |
| 343 | halUuid->timeLow = uuid.timeLow; |
| 344 | halUuid->timeMid = uuid.timeMid; |
| 345 | halUuid->timeHiAndVersion = uuid.versionAndTimeHigh; |
| 346 | halUuid->clockSeq = uuid.variantAndClockSeqHigh; |
| 347 | memcpy(halUuid->node, uuid.node.data(), uuid.node.size()); |
| 348 | } |
| 349 | |
Mikhail Naganov | 543bf9c | 2018-12-11 16:36:53 -0800 | [diff] [blame^] | 350 | } // namespace implementation |
Kevin Rocard | 96d2cd9 | 2018-11-14 16:22:07 -0800 | [diff] [blame] | 351 | } // namespace CPP_VERSION |
Kevin Rocard | 6891d7e | 2017-12-14 18:39:39 -0800 | [diff] [blame] | 352 | } // namespace common |
| 353 | } // namespace audio |
| 354 | } // namespace hardware |
Mikhail Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 355 | } // namespace android |