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