Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2014, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #define LOG_TAG "AudioFlinger::PatchPanel" |
| 20 | //#define LOG_NDEBUG 0 |
| 21 | |
| 22 | #include "Configuration.h" |
| 23 | #include <utils/Log.h> |
| 24 | #include <audio_utils/primitives.h> |
| 25 | |
| 26 | #include "AudioFlinger.h" |
| 27 | #include "ServiceUtilities.h" |
| 28 | #include <media/AudioParameter.h> |
| 29 | |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame^] | 30 | #include <hardware/audio.h> // for AUDIO_DEVICE_API_VERSION_... |
| 31 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 32 | // ---------------------------------------------------------------------------- |
| 33 | |
| 34 | // Note: the following macro is used for extremely verbose logging message. In |
| 35 | // order to run with ALOG_ASSERT turned on, we need to have LOG_NDEBUG set to |
| 36 | // 0; but one side effect of this is to turn all LOGV's as well. Some messages |
| 37 | // are so verbose that we want to suppress them even when we have ALOG_ASSERT |
| 38 | // turned on. Do not uncomment the #def below unless you really know what you |
| 39 | // are doing and want to see all of the extremely verbose messages. |
| 40 | //#define VERY_VERY_VERBOSE_LOGGING |
| 41 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 42 | #define ALOGVV ALOGV |
| 43 | #else |
| 44 | #define ALOGVV(a...) do { } while(0) |
| 45 | #endif |
| 46 | |
| 47 | namespace android { |
| 48 | |
| 49 | /* List connected audio ports and their attributes */ |
| 50 | status_t AudioFlinger::listAudioPorts(unsigned int *num_ports, |
| 51 | struct audio_port *ports) |
| 52 | { |
| 53 | Mutex::Autolock _l(mLock); |
| 54 | if (mPatchPanel != 0) { |
| 55 | return mPatchPanel->listAudioPorts(num_ports, ports); |
| 56 | } |
| 57 | return NO_INIT; |
| 58 | } |
| 59 | |
| 60 | /* Get supported attributes for a given audio port */ |
| 61 | status_t AudioFlinger::getAudioPort(struct audio_port *port) |
| 62 | { |
| 63 | Mutex::Autolock _l(mLock); |
| 64 | if (mPatchPanel != 0) { |
| 65 | return mPatchPanel->getAudioPort(port); |
| 66 | } |
| 67 | return NO_INIT; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* Connect a patch between several source and sink ports */ |
| 72 | status_t AudioFlinger::createAudioPatch(const struct audio_patch *patch, |
| 73 | audio_patch_handle_t *handle) |
| 74 | { |
| 75 | Mutex::Autolock _l(mLock); |
| 76 | if (mPatchPanel != 0) { |
| 77 | return mPatchPanel->createAudioPatch(patch, handle); |
| 78 | } |
| 79 | return NO_INIT; |
| 80 | } |
| 81 | |
| 82 | /* Disconnect a patch */ |
| 83 | status_t AudioFlinger::releaseAudioPatch(audio_patch_handle_t handle) |
| 84 | { |
| 85 | Mutex::Autolock _l(mLock); |
| 86 | if (mPatchPanel != 0) { |
| 87 | return mPatchPanel->releaseAudioPatch(handle); |
| 88 | } |
| 89 | return NO_INIT; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* List connected audio ports and they attributes */ |
| 94 | status_t AudioFlinger::listAudioPatches(unsigned int *num_patches, |
| 95 | struct audio_patch *patches) |
| 96 | { |
| 97 | Mutex::Autolock _l(mLock); |
| 98 | if (mPatchPanel != 0) { |
| 99 | return mPatchPanel->listAudioPatches(num_patches, patches); |
| 100 | } |
| 101 | return NO_INIT; |
| 102 | } |
| 103 | |
| 104 | /* Set audio port configuration */ |
| 105 | status_t AudioFlinger::setAudioPortConfig(const struct audio_port_config *config) |
| 106 | { |
| 107 | Mutex::Autolock _l(mLock); |
| 108 | if (mPatchPanel != 0) { |
| 109 | return mPatchPanel->setAudioPortConfig(config); |
| 110 | } |
| 111 | return NO_INIT; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | AudioFlinger::PatchPanel::PatchPanel(const sp<AudioFlinger>& audioFlinger) |
| 116 | : mAudioFlinger(audioFlinger) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | AudioFlinger::PatchPanel::~PatchPanel() |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | /* List connected audio ports and their attributes */ |
| 125 | status_t AudioFlinger::PatchPanel::listAudioPorts(unsigned int *num_ports __unused, |
| 126 | struct audio_port *ports __unused) |
| 127 | { |
| 128 | ALOGV("listAudioPorts"); |
| 129 | return NO_ERROR; |
| 130 | } |
| 131 | |
| 132 | /* Get supported attributes for a given audio port */ |
| 133 | status_t AudioFlinger::PatchPanel::getAudioPort(struct audio_port *port __unused) |
| 134 | { |
| 135 | ALOGV("getAudioPort"); |
| 136 | return NO_ERROR; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /* Connect a patch between several source and sink ports */ |
| 141 | status_t AudioFlinger::PatchPanel::createAudioPatch(const struct audio_patch *patch, |
| 142 | audio_patch_handle_t *handle) |
| 143 | { |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 144 | status_t status = NO_ERROR; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 145 | audio_patch_handle_t halHandle = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 146 | sp<AudioFlinger> audioflinger = mAudioFlinger.promote(); |
Greg Kaiser | f27ce40 | 2016-03-14 13:43:14 -0700 | [diff] [blame] | 147 | if (handle == NULL || patch == NULL) { |
| 148 | return BAD_VALUE; |
| 149 | } |
| 150 | ALOGV("createAudioPatch() num_sources %d num_sinks %d handle %d", |
| 151 | patch->num_sources, patch->num_sinks, *handle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 152 | if (audioflinger == 0) { |
| 153 | return NO_INIT; |
| 154 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 155 | |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 156 | if (patch->num_sources == 0 || patch->num_sources > AUDIO_PATCH_PORTS_MAX || |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 157 | (patch->num_sinks == 0 && patch->num_sources != 2) || |
| 158 | patch->num_sinks > AUDIO_PATCH_PORTS_MAX) { |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 159 | return BAD_VALUE; |
| 160 | } |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 161 | // limit number of sources to 1 for now or 2 sources for special cross hw module case. |
| 162 | // only the audio policy manager can request a patch creation with 2 sources. |
| 163 | if (patch->num_sources > 2) { |
| 164 | return INVALID_OPERATION; |
| 165 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 166 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 167 | if (*handle != AUDIO_PATCH_HANDLE_NONE) { |
| 168 | for (size_t index = 0; *handle != 0 && index < mPatches.size(); index++) { |
| 169 | if (*handle == mPatches[index]->mHandle) { |
| 170 | ALOGV("createAudioPatch() removing patch handle %d", *handle); |
| 171 | halHandle = mPatches[index]->mHalHandle; |
soon1.choi | d8cd477 | 2015-01-05 14:27:42 +0900 | [diff] [blame] | 172 | Patch *removedPatch = mPatches[index]; |
Eric Laurent | b997d3a | 2016-06-07 18:23:45 -0700 | [diff] [blame] | 173 | // free resources owned by the removed patch if applicable |
| 174 | // 1) if a software patch is present, release the playback and capture threads and |
| 175 | // tracks created. This will also release the corresponding audio HAL patches |
Eric Laurent | 0666cc5 | 2015-12-15 10:14:06 -0800 | [diff] [blame] | 176 | if ((removedPatch->mRecordPatchHandle |
| 177 | != AUDIO_PATCH_HANDLE_NONE) || |
| 178 | (removedPatch->mPlaybackPatchHandle != |
| 179 | AUDIO_PATCH_HANDLE_NONE)) { |
| 180 | clearPatchConnections(removedPatch); |
| 181 | } |
Eric Laurent | b997d3a | 2016-06-07 18:23:45 -0700 | [diff] [blame] | 182 | // 2) if the new patch and old patch source or sink are devices from different |
| 183 | // hw modules, clear the audio HAL patches now because they will not be updated |
| 184 | // by call to create_audio_patch() below which will happen on a different HW module |
| 185 | if (halHandle != AUDIO_PATCH_HANDLE_NONE) { |
| 186 | audio_module_handle_t hwModule = AUDIO_MODULE_HANDLE_NONE; |
| 187 | if ((removedPatch->mAudioPatch.sources[0].type == AUDIO_PORT_TYPE_DEVICE) && |
| 188 | ((patch->sources[0].type != AUDIO_PORT_TYPE_DEVICE) || |
| 189 | (removedPatch->mAudioPatch.sources[0].ext.device.hw_module != |
| 190 | patch->sources[0].ext.device.hw_module))) { |
| 191 | hwModule = removedPatch->mAudioPatch.sources[0].ext.device.hw_module; |
| 192 | } else if ((patch->num_sinks == 0) || |
| 193 | ((removedPatch->mAudioPatch.sinks[0].type == AUDIO_PORT_TYPE_DEVICE) && |
| 194 | ((patch->sinks[0].type != AUDIO_PORT_TYPE_DEVICE) || |
| 195 | (removedPatch->mAudioPatch.sinks[0].ext.device.hw_module != |
| 196 | patch->sinks[0].ext.device.hw_module)))) { |
| 197 | // Note on (patch->num_sinks == 0): this situation should not happen as |
| 198 | // these special patches are only created by the policy manager but just |
| 199 | // in case, systematically clear the HAL patch. |
| 200 | // Note that removedPatch->mAudioPatch.num_sinks cannot be 0 here because |
| 201 | // halHandle would be AUDIO_PATCH_HANDLE_NONE in this case. |
| 202 | hwModule = removedPatch->mAudioPatch.sinks[0].ext.device.hw_module; |
| 203 | } |
| 204 | if (hwModule != AUDIO_MODULE_HANDLE_NONE) { |
| 205 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(hwModule); |
| 206 | if (index >= 0) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 207 | sp<DeviceHalInterface> hwDevice = |
Eric Laurent | b997d3a | 2016-06-07 18:23:45 -0700 | [diff] [blame] | 208 | audioflinger->mAudioHwDevs.valueAt(index)->hwDevice(); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 209 | hwDevice->releaseAudioPatch(halHandle); |
Eric Laurent | b997d3a | 2016-06-07 18:23:45 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 213 | mPatches.removeAt(index); |
soon1.choi | d8cd477 | 2015-01-05 14:27:42 +0900 | [diff] [blame] | 214 | delete removedPatch; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 215 | break; |
| 216 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 220 | Patch *newPatch = new Patch(patch); |
| 221 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 222 | switch (patch->sources[0].type) { |
| 223 | case AUDIO_PORT_TYPE_DEVICE: { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 224 | audio_module_handle_t srcModule = patch->sources[0].ext.device.hw_module; |
| 225 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 226 | if (index < 0) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 227 | ALOGW("createAudioPatch() bad src hw module %d", srcModule); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 228 | status = BAD_VALUE; |
| 229 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 230 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 231 | AudioHwDevice *audioHwDevice = audioflinger->mAudioHwDevs.valueAt(index); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 232 | for (unsigned int i = 0; i < patch->num_sinks; i++) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 233 | // support only one sink if connection to a mix or across HW modules |
| 234 | if ((patch->sinks[i].type == AUDIO_PORT_TYPE_MIX || |
| 235 | patch->sinks[i].ext.mix.hw_module != srcModule) && |
| 236 | patch->num_sinks > 1) { |
| 237 | status = INVALID_OPERATION; |
| 238 | goto exit; |
| 239 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 240 | // reject connection to different sink types |
| 241 | if (patch->sinks[i].type != patch->sinks[0].type) { |
| 242 | ALOGW("createAudioPatch() different sink types in same patch not supported"); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 243 | status = BAD_VALUE; |
| 244 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 245 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 248 | // manage patches requiring a software bridge |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 249 | // - special patch request with 2 sources (reuse one existing output mix) OR |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 250 | // - Device to device AND |
| 251 | // - source HW module != destination HW module OR |
| 252 | // - audio HAL version < 3.0 |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 253 | if ((patch->num_sources == 2) || |
| 254 | ((patch->sinks[0].type == AUDIO_PORT_TYPE_DEVICE) && |
| 255 | ((patch->sinks[0].ext.device.hw_module != srcModule) || |
| 256 | (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0)))) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 257 | if (patch->num_sources == 2) { |
| 258 | if (patch->sources[1].type != AUDIO_PORT_TYPE_MIX || |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 259 | (patch->num_sinks != 0 && patch->sinks[0].ext.device.hw_module != |
| 260 | patch->sources[1].ext.mix.hw_module)) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 261 | ALOGW("createAudioPatch() invalid source combination"); |
| 262 | status = INVALID_OPERATION; |
| 263 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 264 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 265 | |
| 266 | sp<ThreadBase> thread = |
| 267 | audioflinger->checkPlaybackThread_l(patch->sources[1].ext.mix.handle); |
| 268 | newPatch->mPlaybackThread = (MixerThread *)thread.get(); |
| 269 | if (thread == 0) { |
| 270 | ALOGW("createAudioPatch() cannot get playback thread"); |
| 271 | status = INVALID_OPERATION; |
| 272 | goto exit; |
| 273 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 274 | } else { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 275 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 276 | audio_devices_t device = patch->sinks[0].ext.device.type; |
| 277 | String8 address = String8(patch->sinks[0].ext.device.address); |
| 278 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 279 | newPatch->mPlaybackThread = audioflinger->openOutput_l( |
| 280 | patch->sinks[0].ext.device.hw_module, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 281 | &output, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 282 | &config, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 283 | device, |
| 284 | address, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 285 | AUDIO_OUTPUT_FLAG_NONE); |
| 286 | ALOGV("audioflinger->openOutput_l() returned %p", |
| 287 | newPatch->mPlaybackThread.get()); |
| 288 | if (newPatch->mPlaybackThread == 0) { |
| 289 | status = NO_MEMORY; |
| 290 | goto exit; |
| 291 | } |
| 292 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 293 | audio_devices_t device = patch->sources[0].ext.device.type; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 294 | String8 address = String8(patch->sources[0].ext.device.address); |
| 295 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
Eric Laurent | 8ae7312 | 2016-04-12 10:13:29 -0700 | [diff] [blame] | 296 | // open input stream with source device audio properties if provided or |
| 297 | // default to peer output stream properties otherwise. |
| 298 | if (patch->sources[0].config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE) { |
| 299 | config.sample_rate = patch->sources[0].sample_rate; |
| 300 | } else { |
| 301 | config.sample_rate = newPatch->mPlaybackThread->sampleRate(); |
| 302 | } |
| 303 | if (patch->sources[0].config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK) { |
| 304 | config.channel_mask = patch->sources[0].channel_mask; |
| 305 | } else { |
| 306 | config.channel_mask = |
| 307 | audio_channel_in_mask_from_count(newPatch->mPlaybackThread->channelCount()); |
| 308 | } |
| 309 | if (patch->sources[0].config_mask & AUDIO_PORT_CONFIG_FORMAT) { |
| 310 | config.format = patch->sources[0].format; |
| 311 | } else { |
| 312 | config.format = newPatch->mPlaybackThread->format(); |
| 313 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 314 | audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 315 | newPatch->mRecordThread = audioflinger->openInput_l(srcModule, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 316 | &input, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 317 | &config, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 318 | device, |
| 319 | address, |
| 320 | AUDIO_SOURCE_MIC, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 321 | AUDIO_INPUT_FLAG_NONE); |
| 322 | ALOGV("audioflinger->openInput_l() returned %p inChannelMask %08x", |
Eric Laurent | 8ae7312 | 2016-04-12 10:13:29 -0700 | [diff] [blame] | 323 | newPatch->mRecordThread.get(), config.channel_mask); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 324 | if (newPatch->mRecordThread == 0) { |
| 325 | status = NO_MEMORY; |
| 326 | goto exit; |
| 327 | } |
| 328 | status = createPatchConnections(newPatch, patch); |
| 329 | if (status != NO_ERROR) { |
| 330 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 331 | } |
| 332 | } else { |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 333 | if (patch->sinks[0].type == AUDIO_PORT_TYPE_MIX) { |
| 334 | sp<ThreadBase> thread = audioflinger->checkRecordThread_l( |
| 335 | patch->sinks[0].ext.mix.handle); |
| 336 | if (thread == 0) { |
| 337 | ALOGW("createAudioPatch() bad capture I/O handle %d", |
| 338 | patch->sinks[0].ext.mix.handle); |
| 339 | status = BAD_VALUE; |
| 340 | goto exit; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 341 | } |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 342 | status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 343 | } else { |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 344 | if (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0) { |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 345 | status = INVALID_OPERATION; |
| 346 | goto exit; |
| 347 | } |
| 348 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 349 | sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice(); |
| 350 | status = hwDevice->createAudioPatch(patch->num_sources, |
| 351 | patch->sources, |
| 352 | patch->num_sinks, |
| 353 | patch->sinks, |
| 354 | &halHandle); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 355 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 356 | } |
| 357 | } break; |
| 358 | case AUDIO_PORT_TYPE_MIX: { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 359 | audio_module_handle_t srcModule = patch->sources[0].ext.mix.hw_module; |
| 360 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 361 | if (index < 0) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 362 | ALOGW("createAudioPatch() bad src hw module %d", srcModule); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 363 | status = BAD_VALUE; |
| 364 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 365 | } |
| 366 | // limit to connections between devices and output streams |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 367 | audio_devices_t type = AUDIO_DEVICE_NONE; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 368 | for (unsigned int i = 0; i < patch->num_sinks; i++) { |
| 369 | if (patch->sinks[i].type != AUDIO_PORT_TYPE_DEVICE) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 370 | ALOGW("createAudioPatch() invalid sink type %d for mix source", |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 371 | patch->sinks[i].type); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 372 | status = BAD_VALUE; |
| 373 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 374 | } |
| 375 | // limit to connections between sinks and sources on same HW module |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 376 | if (patch->sinks[i].ext.device.hw_module != srcModule) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 377 | status = BAD_VALUE; |
| 378 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 379 | } |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 380 | type |= patch->sinks[i].ext.device.type; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 381 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 382 | sp<ThreadBase> thread = |
| 383 | audioflinger->checkPlaybackThread_l(patch->sources[0].ext.mix.handle); |
| 384 | if (thread == 0) { |
| 385 | ALOGW("createAudioPatch() bad playback I/O handle %d", |
| 386 | patch->sources[0].ext.mix.handle); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 387 | status = BAD_VALUE; |
| 388 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 389 | } |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 390 | if (thread == audioflinger->primaryPlaybackThread_l()) { |
| 391 | AudioParameter param = AudioParameter(); |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame^] | 392 | param.addInt(String8(AudioParameter::keyRouting), (int)type); |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 393 | |
| 394 | audioflinger->broacastParametersToRecordThreads_l(param.toString()); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 397 | status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 398 | } break; |
| 399 | default: |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 400 | status = BAD_VALUE; |
| 401 | goto exit; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 402 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 403 | exit: |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 404 | ALOGV("createAudioPatch() status %d", status); |
| 405 | if (status == NO_ERROR) { |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 406 | *handle = (audio_patch_handle_t) audioflinger->nextUniqueId(AUDIO_UNIQUE_ID_USE_PATCH); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 407 | newPatch->mHandle = *handle; |
| 408 | newPatch->mHalHandle = halHandle; |
| 409 | mPatches.add(newPatch); |
| 410 | ALOGV("createAudioPatch() added new patch handle %d halHandle %d", *handle, halHandle); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 411 | } else { |
| 412 | clearPatchConnections(newPatch); |
| 413 | delete newPatch; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 414 | } |
| 415 | return status; |
| 416 | } |
| 417 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 418 | status_t AudioFlinger::PatchPanel::createPatchConnections(Patch *patch, |
| 419 | const struct audio_patch *audioPatch) |
| 420 | { |
| 421 | // create patch from source device to record thread input |
| 422 | struct audio_patch subPatch; |
| 423 | subPatch.num_sources = 1; |
| 424 | subPatch.sources[0] = audioPatch->sources[0]; |
| 425 | subPatch.num_sinks = 1; |
| 426 | |
| 427 | patch->mRecordThread->getAudioPortConfig(&subPatch.sinks[0]); |
| 428 | subPatch.sinks[0].ext.mix.usecase.source = AUDIO_SOURCE_MIC; |
| 429 | |
| 430 | status_t status = createAudioPatch(&subPatch, &patch->mRecordPatchHandle); |
| 431 | if (status != NO_ERROR) { |
| 432 | patch->mRecordPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 433 | return status; |
| 434 | } |
| 435 | |
| 436 | // create patch from playback thread output to sink device |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 437 | if (audioPatch->num_sinks != 0) { |
| 438 | patch->mPlaybackThread->getAudioPortConfig(&subPatch.sources[0]); |
| 439 | subPatch.sinks[0] = audioPatch->sinks[0]; |
| 440 | status = createAudioPatch(&subPatch, &patch->mPlaybackPatchHandle); |
| 441 | if (status != NO_ERROR) { |
| 442 | patch->mPlaybackPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 443 | return status; |
| 444 | } |
| 445 | } else { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 446 | patch->mPlaybackPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // use a pseudo LCM between input and output framecount |
| 450 | size_t playbackFrameCount = patch->mPlaybackThread->frameCount(); |
| 451 | int playbackShift = __builtin_ctz(playbackFrameCount); |
| 452 | size_t recordFramecount = patch->mRecordThread->frameCount(); |
| 453 | int shift = __builtin_ctz(recordFramecount); |
| 454 | if (playbackShift < shift) { |
| 455 | shift = playbackShift; |
| 456 | } |
| 457 | size_t frameCount = (playbackFrameCount * recordFramecount) >> shift; |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 458 | ALOGV("createPatchConnections() playframeCount %zu recordFramecount %zu frameCount %zu", |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 459 | playbackFrameCount, recordFramecount, frameCount); |
| 460 | |
| 461 | // create a special record track to capture from record thread |
| 462 | uint32_t channelCount = patch->mPlaybackThread->channelCount(); |
| 463 | audio_channel_mask_t inChannelMask = audio_channel_in_mask_from_count(channelCount); |
| 464 | audio_channel_mask_t outChannelMask = patch->mPlaybackThread->channelMask(); |
| 465 | uint32_t sampleRate = patch->mPlaybackThread->sampleRate(); |
| 466 | audio_format_t format = patch->mPlaybackThread->format(); |
| 467 | |
| 468 | patch->mPatchRecord = new RecordThread::PatchRecord( |
| 469 | patch->mRecordThread.get(), |
| 470 | sampleRate, |
| 471 | inChannelMask, |
| 472 | format, |
| 473 | frameCount, |
| 474 | NULL, |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 475 | AUDIO_INPUT_FLAG_NONE); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 476 | if (patch->mPatchRecord == 0) { |
| 477 | return NO_MEMORY; |
| 478 | } |
| 479 | status = patch->mPatchRecord->initCheck(); |
| 480 | if (status != NO_ERROR) { |
| 481 | return status; |
| 482 | } |
| 483 | patch->mRecordThread->addPatchRecord(patch->mPatchRecord); |
| 484 | |
| 485 | // create a special playback track to render to playback thread. |
| 486 | // this track is given the same buffer as the PatchRecord buffer |
| 487 | patch->mPatchTrack = new PlaybackThread::PatchTrack( |
| 488 | patch->mPlaybackThread.get(), |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 489 | audioPatch->sources[1].ext.mix.usecase.stream, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 490 | sampleRate, |
| 491 | outChannelMask, |
| 492 | format, |
| 493 | frameCount, |
| 494 | patch->mPatchRecord->buffer(), |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 495 | AUDIO_OUTPUT_FLAG_NONE); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 496 | if (patch->mPatchTrack == 0) { |
| 497 | return NO_MEMORY; |
| 498 | } |
| 499 | status = patch->mPatchTrack->initCheck(); |
| 500 | if (status != NO_ERROR) { |
| 501 | return status; |
| 502 | } |
| 503 | patch->mPlaybackThread->addPatchTrack(patch->mPatchTrack); |
| 504 | |
| 505 | // tie playback and record tracks together |
| 506 | patch->mPatchRecord->setPeerProxy(patch->mPatchTrack.get()); |
| 507 | patch->mPatchTrack->setPeerProxy(patch->mPatchRecord.get()); |
| 508 | |
| 509 | // start capture and playback |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 510 | patch->mPatchRecord->start(AudioSystem::SYNC_EVENT_NONE, AUDIO_SESSION_NONE); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 511 | patch->mPatchTrack->start(); |
| 512 | |
| 513 | return status; |
| 514 | } |
| 515 | |
| 516 | void AudioFlinger::PatchPanel::clearPatchConnections(Patch *patch) |
| 517 | { |
| 518 | sp<AudioFlinger> audioflinger = mAudioFlinger.promote(); |
| 519 | if (audioflinger == 0) { |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | ALOGV("clearPatchConnections() patch->mRecordPatchHandle %d patch->mPlaybackPatchHandle %d", |
| 524 | patch->mRecordPatchHandle, patch->mPlaybackPatchHandle); |
| 525 | |
| 526 | if (patch->mPatchRecord != 0) { |
| 527 | patch->mPatchRecord->stop(); |
| 528 | } |
| 529 | if (patch->mPatchTrack != 0) { |
| 530 | patch->mPatchTrack->stop(); |
| 531 | } |
| 532 | if (patch->mRecordPatchHandle != AUDIO_PATCH_HANDLE_NONE) { |
| 533 | releaseAudioPatch(patch->mRecordPatchHandle); |
| 534 | patch->mRecordPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 535 | } |
| 536 | if (patch->mPlaybackPatchHandle != AUDIO_PATCH_HANDLE_NONE) { |
| 537 | releaseAudioPatch(patch->mPlaybackPatchHandle); |
| 538 | patch->mPlaybackPatchHandle = AUDIO_PATCH_HANDLE_NONE; |
| 539 | } |
| 540 | if (patch->mRecordThread != 0) { |
| 541 | if (patch->mPatchRecord != 0) { |
| 542 | patch->mRecordThread->deletePatchRecord(patch->mPatchRecord); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 543 | } |
| 544 | audioflinger->closeInputInternal_l(patch->mRecordThread); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 545 | } |
| 546 | if (patch->mPlaybackThread != 0) { |
| 547 | if (patch->mPatchTrack != 0) { |
| 548 | patch->mPlaybackThread->deletePatchTrack(patch->mPatchTrack); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 549 | } |
| 550 | // if num sources == 2 we are reusing an existing playback thread so we do not close it |
| 551 | if (patch->mAudioPatch.num_sources != 2) { |
| 552 | audioflinger->closeOutputInternal_l(patch->mPlaybackThread); |
| 553 | } |
Eric Laurent | a0169a0 | 2015-07-06 18:32:01 -0700 | [diff] [blame] | 554 | } |
| 555 | if (patch->mRecordThread != 0) { |
| 556 | if (patch->mPatchRecord != 0) { |
| 557 | patch->mPatchRecord.clear(); |
| 558 | } |
| 559 | patch->mRecordThread.clear(); |
| 560 | } |
| 561 | if (patch->mPlaybackThread != 0) { |
| 562 | if (patch->mPatchTrack != 0) { |
| 563 | patch->mPatchTrack.clear(); |
| 564 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 565 | patch->mPlaybackThread.clear(); |
| 566 | } |
Eric Laurent | a0169a0 | 2015-07-06 18:32:01 -0700 | [diff] [blame] | 567 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 570 | /* Disconnect a patch */ |
| 571 | status_t AudioFlinger::PatchPanel::releaseAudioPatch(audio_patch_handle_t handle) |
| 572 | { |
| 573 | ALOGV("releaseAudioPatch handle %d", handle); |
| 574 | status_t status = NO_ERROR; |
| 575 | size_t index; |
| 576 | |
| 577 | sp<AudioFlinger> audioflinger = mAudioFlinger.promote(); |
| 578 | if (audioflinger == 0) { |
| 579 | return NO_INIT; |
| 580 | } |
| 581 | |
| 582 | for (index = 0; index < mPatches.size(); index++) { |
| 583 | if (handle == mPatches[index]->mHandle) { |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | if (index == mPatches.size()) { |
| 588 | return BAD_VALUE; |
| 589 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 590 | Patch *removedPatch = mPatches[index]; |
| 591 | mPatches.removeAt(index); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 592 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 593 | struct audio_patch *patch = &removedPatch->mAudioPatch; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 594 | |
| 595 | switch (patch->sources[0].type) { |
| 596 | case AUDIO_PORT_TYPE_DEVICE: { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 597 | audio_module_handle_t srcModule = patch->sources[0].ext.device.hw_module; |
| 598 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 599 | if (index < 0) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 600 | ALOGW("releaseAudioPatch() bad src hw module %d", srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 601 | status = BAD_VALUE; |
| 602 | break; |
| 603 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 604 | |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 605 | if (removedPatch->mRecordPatchHandle != AUDIO_PATCH_HANDLE_NONE || |
| 606 | removedPatch->mPlaybackPatchHandle != AUDIO_PATCH_HANDLE_NONE) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 607 | clearPatchConnections(removedPatch); |
| 608 | break; |
| 609 | } |
| 610 | |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 611 | if (patch->sinks[0].type == AUDIO_PORT_TYPE_MIX) { |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 612 | sp<ThreadBase> thread = audioflinger->checkRecordThread_l( |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 613 | patch->sinks[0].ext.mix.handle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 614 | if (thread == 0) { |
| 615 | ALOGW("releaseAudioPatch() bad capture I/O handle %d", |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 616 | patch->sinks[0].ext.mix.handle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 617 | status = BAD_VALUE; |
| 618 | break; |
| 619 | } |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 620 | status = thread->sendReleaseAudioPatchConfigEvent(removedPatch->mHalHandle); |
| 621 | } else { |
| 622 | AudioHwDevice *audioHwDevice = audioflinger->mAudioHwDevs.valueAt(index); |
| 623 | if (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0) { |
| 624 | status = INVALID_OPERATION; |
| 625 | break; |
| 626 | } |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 627 | sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice(); |
| 628 | status = hwDevice->releaseAudioPatch(removedPatch->mHalHandle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 629 | } |
| 630 | } break; |
| 631 | case AUDIO_PORT_TYPE_MIX: { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 632 | audio_module_handle_t srcModule = patch->sources[0].ext.mix.hw_module; |
| 633 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 634 | if (index < 0) { |
Eric Laurent | 874c4287 | 2014-08-08 15:13:39 -0700 | [diff] [blame] | 635 | ALOGW("releaseAudioPatch() bad src hw module %d", srcModule); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 636 | status = BAD_VALUE; |
| 637 | break; |
| 638 | } |
| 639 | sp<ThreadBase> thread = |
| 640 | audioflinger->checkPlaybackThread_l(patch->sources[0].ext.mix.handle); |
| 641 | if (thread == 0) { |
| 642 | ALOGW("releaseAudioPatch() bad playback I/O handle %d", |
| 643 | patch->sources[0].ext.mix.handle); |
| 644 | status = BAD_VALUE; |
| 645 | break; |
| 646 | } |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 647 | status = thread->sendReleaseAudioPatchConfigEvent(removedPatch->mHalHandle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 648 | } break; |
| 649 | default: |
| 650 | status = BAD_VALUE; |
| 651 | break; |
| 652 | } |
| 653 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 654 | delete removedPatch; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 655 | return status; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | /* List connected audio ports and they attributes */ |
| 660 | status_t AudioFlinger::PatchPanel::listAudioPatches(unsigned int *num_patches __unused, |
| 661 | struct audio_patch *patches __unused) |
| 662 | { |
| 663 | ALOGV("listAudioPatches"); |
| 664 | return NO_ERROR; |
| 665 | } |
| 666 | |
| 667 | /* Set audio port configuration */ |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 668 | status_t AudioFlinger::PatchPanel::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 669 | { |
| 670 | ALOGV("setAudioPortConfig"); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 671 | |
| 672 | sp<AudioFlinger> audioflinger = mAudioFlinger.promote(); |
| 673 | if (audioflinger == 0) { |
| 674 | return NO_INIT; |
| 675 | } |
| 676 | |
| 677 | audio_module_handle_t module; |
| 678 | if (config->type == AUDIO_PORT_TYPE_DEVICE) { |
| 679 | module = config->ext.device.hw_module; |
| 680 | } else { |
| 681 | module = config->ext.mix.hw_module; |
| 682 | } |
| 683 | |
| 684 | ssize_t index = audioflinger->mAudioHwDevs.indexOfKey(module); |
| 685 | if (index < 0) { |
| 686 | ALOGW("setAudioPortConfig() bad hw module %d", module); |
| 687 | return BAD_VALUE; |
| 688 | } |
| 689 | |
| 690 | AudioHwDevice *audioHwDevice = audioflinger->mAudioHwDevs.valueAt(index); |
| 691 | if (audioHwDevice->version() >= AUDIO_DEVICE_API_VERSION_3_0) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 692 | sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice(); |
| 693 | return hwDevice->setAudioPortConfig(config); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 694 | } else { |
| 695 | return INVALID_OPERATION; |
| 696 | } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 697 | return NO_ERROR; |
| 698 | } |
| 699 | |
Glenn Kasten | 63238ef | 2015-03-02 15:50:29 -0800 | [diff] [blame] | 700 | } // namespace android |