Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "AudioStreamLegacy" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 22 | |
| 23 | #include <aaudio/AAudio.h> |
| 24 | #include <audio_utils/primitives.h> |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 25 | #include <media/AudioTrack.h> |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 26 | #include <media/AudioTimestamp.h> |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 27 | #include <utils/String16.h> |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 28 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 29 | #include "core/AudioGlobal.h" |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 30 | #include "core/AudioStream.h" |
| 31 | #include "legacy/AudioStreamLegacy.h" |
| 32 | |
| 33 | using namespace android; |
| 34 | using namespace aaudio; |
| 35 | |
| 36 | AudioStreamLegacy::AudioStreamLegacy() |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 37 | : AudioStream() { |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 40 | |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 41 | aaudio_data_callback_result_t AudioStreamLegacy::callDataCallbackFrames(uint8_t *buffer, |
| 42 | int32_t numFrames) { |
| 43 | void *finalAudioData = buffer; |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 44 | if (getDirection() == AAUDIO_DIRECTION_INPUT) { |
| 45 | // Increment before because we already got the data from the device. |
| 46 | incrementFramesRead(numFrames); |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 47 | finalAudioData = (void *) maybeConvertDeviceData(buffer, numFrames); |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 50 | // Call using the AAudio callback interface. |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 51 | aaudio_data_callback_result_t callbackResult = maybeCallDataCallback(finalAudioData, numFrames); |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 52 | |
| 53 | if (callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE |
| 54 | && getDirection() == AAUDIO_DIRECTION_OUTPUT) { |
| 55 | // Increment after because we are going to write the data to the device. |
| 56 | incrementFramesWritten(numFrames); |
| 57 | } |
| 58 | return callbackResult; |
| 59 | } |
| 60 | |
| 61 | // Implement FixedBlockProcessor |
| 62 | int32_t AudioStreamLegacy::onProcessFixedBlock(uint8_t *buffer, int32_t numBytes) { |
Phil Burk | 4b86749 | 2020-02-12 10:58:05 -0800 | [diff] [blame] | 63 | int32_t numFrames = numBytes / mBlockAdapterBytesPerFrame; |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 64 | return (int32_t) callDataCallbackFrames(buffer, numFrames); |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 67 | |
| 68 | void AudioStreamLegacy::onNewIAudioTrack() { |
| 69 | ALOGD("%s stream disconnected", __func__); |
| 70 | forceDisconnect(); |
| 71 | mCallbackEnabled.store(false); |
| 72 | } |
| 73 | |
| 74 | size_t AudioStreamLegacy::onMoreData(const android::AudioTrack::Buffer& buffer) { |
Phil Burk | 1e83bee | 2018-12-17 14:15:20 -0800 | [diff] [blame] | 75 | // This illegal size can be used to tell AudioRecord or AudioTrack to stop calling us. |
| 76 | // This takes advantage of them killing the stream when they see a size out of range. |
| 77 | // That is an undocumented behavior. |
Phil Burk | 3d786cb | 2018-04-09 11:58:09 -0700 | [diff] [blame] | 78 | // TODO add to API in AudioRecord and AudioTrack |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 79 | // TODO(b/216175830) cleanup size re-computation |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 80 | const size_t SIZE_STOP_CALLBACKS = SIZE_MAX; |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 81 | aaudio_data_callback_result_t callbackResult; |
| 82 | (void) checkForDisconnectRequest(true); |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 83 | |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 84 | // Note that this code assumes an AudioTrack::Buffer is the same as |
| 85 | // AudioRecord::Buffer |
| 86 | // TODO define our own AudioBuffer and pass it from the subclasses. |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 87 | size_t written = buffer.size(); |
jiabin | cb212cd | 2022-08-24 16:50:44 -0700 | [diff] [blame] | 88 | if (isDisconnected()) { |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 89 | ALOGW("%s() data, stream disconnected", __func__); |
| 90 | // This will kill the stream and prevent it from being restarted. |
| 91 | // That is OK because the stream is disconnected. |
| 92 | written = SIZE_STOP_CALLBACKS; |
| 93 | } else if (!mCallbackEnabled.load()) { |
| 94 | ALOGW("%s() no data because callback disabled, set size=0", __func__); |
| 95 | // Do NOT use SIZE_STOP_CALLBACKS here because that will kill the stream and |
| 96 | // prevent it from being restarted. This can occur because of a race condition |
| 97 | // caused by Legacy callbacks running after the track is "stopped". |
| 98 | written = 0; |
| 99 | } else { |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 100 | if (buffer.getFrameCount() == 0) { |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 101 | ALOGW("%s() data, frameCount is zero", __func__); |
| 102 | return written; |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 103 | } |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 104 | |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 105 | // If the caller specified an exact size then use a block size adapter. |
| 106 | if (mBlockAdapter != nullptr) { |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 107 | int32_t byteCount = buffer.getFrameCount() * getBytesPerDeviceFrame(); |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 108 | callbackResult = mBlockAdapter->processVariableBlock( |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 109 | buffer.data(), byteCount); |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 110 | } else { |
| 111 | // Call using the AAudio callback interface. |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 112 | callbackResult = callDataCallbackFrames(buffer.data(), |
| 113 | buffer.getFrameCount()); |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 114 | } |
| 115 | if (callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE) { |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 116 | written = buffer.getFrameCount() * getBytesPerDeviceFrame(); |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 117 | } else { |
| 118 | if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) { |
| 119 | ALOGD("%s() callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__); |
| 120 | } else { |
| 121 | ALOGW("%s() callback returned invalid result = %d", |
| 122 | __func__, callbackResult); |
| 123 | } |
| 124 | written = 0; |
| 125 | systemStopInternal(); |
| 126 | // Disable the callback just in case the system keeps trying to call us. |
| 127 | mCallbackEnabled.store(false); |
| 128 | } |
| 129 | |
Robert Wu | 3da128d | 2022-03-04 23:17:25 +0000 | [diff] [blame] | 130 | if (processCommands() != AAUDIO_OK) { |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 131 | forceDisconnect(); |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 132 | mCallbackEnabled.store(false); |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 133 | } |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 134 | } |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 135 | return written; |
Phil Burk | e4d7bb4 | 2017-03-28 11:32:39 -0700 | [diff] [blame] | 136 | } |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 137 | |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 138 | // TODO (b/216175830) this method is duplicated in order to ease refactoring which will |
| 139 | // reconsolidate. |
| 140 | size_t AudioStreamLegacy::onMoreData(const android::AudioRecord::Buffer& buffer) { |
| 141 | // This illegal size can be used to tell AudioRecord or AudioTrack to stop calling us. |
| 142 | // This takes advantage of them killing the stream when they see a size out of range. |
| 143 | // That is an undocumented behavior. |
| 144 | // TODO add to API in AudioRecord and AudioTrack |
| 145 | const size_t SIZE_STOP_CALLBACKS = SIZE_MAX; |
| 146 | aaudio_data_callback_result_t callbackResult; |
| 147 | (void) checkForDisconnectRequest(true); |
| 148 | |
| 149 | // Note that this code assumes an AudioTrack::Buffer is the same as |
| 150 | // AudioRecord::Buffer |
| 151 | // TODO define our own AudioBuffer and pass it from the subclasses. |
| 152 | size_t written = buffer.size(); |
jiabin | cb212cd | 2022-08-24 16:50:44 -0700 | [diff] [blame] | 153 | if (isDisconnected()) { |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 154 | ALOGW("%s() data, stream disconnected", __func__); |
| 155 | // This will kill the stream and prevent it from being restarted. |
| 156 | // That is OK because the stream is disconnected. |
| 157 | written = SIZE_STOP_CALLBACKS; |
| 158 | } else if (!mCallbackEnabled.load()) { |
| 159 | ALOGW("%s() no data because callback disabled, set size=0", __func__); |
| 160 | // Do NOT use SIZE_STOP_CALLBACKS here because that will kill the stream and |
| 161 | // prevent it from being restarted. This can occur because of a race condition |
| 162 | // caused by Legacy callbacks running after the track is "stopped". |
| 163 | written = 0; |
| 164 | } else { |
| 165 | if (buffer.getFrameCount() == 0) { |
| 166 | ALOGW("%s() data, frameCount is zero", __func__); |
| 167 | return written; |
| 168 | } |
| 169 | |
| 170 | // If the caller specified an exact size then use a block size adapter. |
| 171 | if (mBlockAdapter != nullptr) { |
| 172 | int32_t byteCount = buffer.getFrameCount() * getBytesPerDeviceFrame(); |
| 173 | callbackResult = mBlockAdapter->processVariableBlock( |
| 174 | buffer.data(), byteCount); |
| 175 | } else { |
| 176 | // Call using the AAudio callback interface. |
| 177 | callbackResult = callDataCallbackFrames(buffer.data(), |
| 178 | buffer.getFrameCount()); |
| 179 | } |
| 180 | if (callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE) { |
| 181 | written = buffer.getFrameCount() * getBytesPerDeviceFrame(); |
| 182 | } else { |
| 183 | if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) { |
| 184 | ALOGD("%s() callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__); |
| 185 | } else { |
| 186 | ALOGW("%s() callback returned invalid result = %d", |
| 187 | __func__, callbackResult); |
| 188 | } |
| 189 | written = 0; |
| 190 | systemStopInternal(); |
| 191 | // Disable the callback just in case the system keeps trying to call us. |
| 192 | mCallbackEnabled.store(false); |
| 193 | } |
| 194 | |
Robert Wu | 3da128d | 2022-03-04 23:17:25 +0000 | [diff] [blame] | 195 | if (processCommands() != AAUDIO_OK) { |
Atneya Nair | 0307927 | 2022-01-18 17:03:14 -0500 | [diff] [blame] | 196 | forceDisconnect(); |
| 197 | mCallbackEnabled.store(false); |
| 198 | } |
| 199 | } |
| 200 | return written; |
| 201 | } |
Atneya Nair | 7daa4f9 | 2021-11-19 14:00:24 -0500 | [diff] [blame] | 202 | |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 203 | aaudio_result_t AudioStreamLegacy::checkForDisconnectRequest(bool errorCallbackEnabled) { |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 204 | if (mRequestDisconnect.isRequested()) { |
| 205 | ALOGD("checkForDisconnectRequest() mRequestDisconnect acknowledged"); |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 206 | forceDisconnect(errorCallbackEnabled); |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 207 | mRequestDisconnect.acknowledge(); |
| 208 | mCallbackEnabled.store(false); |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 209 | return AAUDIO_ERROR_DISCONNECTED; |
| 210 | } else { |
| 211 | return AAUDIO_OK; |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 215 | void AudioStreamLegacy::forceDisconnect(bool errorCallbackEnabled) { |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 216 | // There is no need to disconnect if already in these states. |
jiabin | cb212cd | 2022-08-24 16:50:44 -0700 | [diff] [blame] | 217 | if (!isDisconnected() |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 218 | && getState() != AAUDIO_STREAM_STATE_CLOSING |
| 219 | && getState() != AAUDIO_STREAM_STATE_CLOSED |
| 220 | ) { |
jiabin | cb212cd | 2022-08-24 16:50:44 -0700 | [diff] [blame] | 221 | setDisconnected(); |
Phil Burk | 134f197 | 2017-12-08 13:06:11 -0800 | [diff] [blame] | 222 | if (errorCallbackEnabled) { |
| 223 | maybeCallErrorCallback(AAUDIO_ERROR_DISCONNECTED); |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 228 | aaudio_result_t AudioStreamLegacy::getBestTimestamp(clockid_t clockId, |
| 229 | int64_t *framePosition, |
| 230 | int64_t *timeNanoseconds, |
| 231 | ExtendedTimestamp *extendedTimestamp) { |
| 232 | int timebase; |
| 233 | switch (clockId) { |
| 234 | case CLOCK_BOOTTIME: |
| 235 | timebase = ExtendedTimestamp::TIMEBASE_BOOTTIME; |
| 236 | break; |
| 237 | case CLOCK_MONOTONIC: |
| 238 | timebase = ExtendedTimestamp::TIMEBASE_MONOTONIC; |
| 239 | break; |
| 240 | default: |
| 241 | ALOGE("getTimestamp() - Unrecognized clock type %d", (int) clockId); |
Phil Burk | 17fff38 | 2017-05-16 14:06:45 -0700 | [diff] [blame] | 242 | return AAUDIO_ERROR_ILLEGAL_ARGUMENT; |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 243 | break; |
| 244 | } |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 245 | ExtendedTimestamp::Location location = ExtendedTimestamp::Location::LOCATION_INVALID; |
| 246 | int64_t localPosition; |
| 247 | status_t status = extendedTimestamp->getBestTimestamp(&localPosition, timeNanoseconds, |
| 248 | timebase, &location); |
Phil Burk | c095964 | 2018-04-05 18:11:01 -0700 | [diff] [blame] | 249 | if (status == OK) { |
| 250 | // use MonotonicCounter to prevent retrograde motion. |
| 251 | mTimestampPosition.update32((int32_t) localPosition); |
| 252 | *framePosition = mTimestampPosition.get(); |
| 253 | } |
Phil Burk | 7328a80 | 2017-08-30 09:29:48 -0700 | [diff] [blame] | 254 | |
| 255 | // ALOGD("getBestTimestamp() fposition: server = %6lld, kernel = %6lld, location = %d", |
| 256 | // (long long) extendedTimestamp->mPosition[ExtendedTimestamp::Location::LOCATION_SERVER], |
| 257 | // (long long) extendedTimestamp->mPosition[ExtendedTimestamp::Location::LOCATION_KERNEL], |
| 258 | // (int)location); |
Phil Burk | c095964 | 2018-04-05 18:11:01 -0700 | [diff] [blame] | 259 | return AAudioConvert_androidToAAudioResult(status); |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 260 | } |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 261 | |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 262 | void AudioStreamLegacy::onAudioDeviceUpdate(audio_io_handle_t /* audioIo */, |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 263 | const android::DeviceIdVector& deviceIds) { |
| 264 | // Check for empty deviceIds. Callbacks for duplicating threads returns empty devices. |
| 265 | if (deviceIds.empty()) { |
| 266 | ALOGW("%s(empty deviceIds", __func__); |
Phil Burk | 1cd9ce6 | 2024-06-12 19:13:53 +0000 | [diff] [blame] | 267 | return; |
| 268 | } |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 269 | android::DeviceIdVector oldDeviceIds = getDeviceIds(); |
Phil Burk | 7ba4655 | 2019-04-15 08:58:08 -0700 | [diff] [blame] | 270 | // Device routing is a common source of errors and DISCONNECTS. |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 271 | // Please leave this log in place. If there is a bug then this might |
| 272 | // get called after the stream has been deleted so log before we |
| 273 | // touch the stream object. |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 274 | ALOGD("%s() devices %s => %s", |
| 275 | __func__, android::toString(oldDeviceIds).c_str(), |
| 276 | android::toString(deviceIds).c_str()); |
| 277 | if (!oldDeviceIds.empty() |
| 278 | && !android::areDeviceIdsEqual(oldDeviceIds, deviceIds) |
jiabin | cb212cd | 2022-08-24 16:50:44 -0700 | [diff] [blame] | 279 | && !isDisconnected() |
Phil Burk | 58f5ce1 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 280 | ) { |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 281 | // Note that isDataCallbackActive() is affected by state so call it before DISCONNECTING. |
| 282 | // If we have a data callback and the stream is active, then ask the data callback |
| 283 | // to DISCONNECT and call the error callback. |
| 284 | if (isDataCallbackActive()) { |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 285 | ALOGD("%s() request DISCONNECT in data callback, devices %s => %s", |
| 286 | __func__, android::toString(oldDeviceIds).c_str(), |
| 287 | android::toString(deviceIds).c_str()); |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 288 | // If the stream is stopped before the data callback has a chance to handle the |
Phil Burk | dd58292 | 2020-10-15 20:29:51 +0000 | [diff] [blame] | 289 | // request then the requestStop_l() and requestPause() methods will handle it after |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 290 | // the callback has stopped. |
| 291 | mRequestDisconnect.request(); |
| 292 | } else { |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 293 | ALOGD("%s() DISCONNECT the stream now, devices %s => %s", |
| 294 | __func__, android::toString(oldDeviceIds).c_str(), |
| 295 | android::toString(deviceIds).c_str()); |
Phil Burk | 2d5ba53 | 2017-09-06 14:36:11 -0700 | [diff] [blame] | 296 | forceDisconnect(); |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
Robert Wu | b7f8edc | 2024-11-04 19:54:38 +0000 | [diff] [blame^] | 299 | setDeviceIds(deviceIds); |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 300 | } |