Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AAudioServiceStreamMMAP" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <atomic> |
Phil Burk | f95ed73 | 2020-09-30 18:48:17 +0000 | [diff] [blame] | 22 | #include <inttypes.h> |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 23 | #include <iomanip> |
| 24 | #include <iostream> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 25 | #include <stdint.h> |
| 26 | |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 27 | #include <com_android_media_aaudio.h> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 28 | #include <utils/String16.h> |
| 29 | #include <media/nbaio/AudioStreamOutSink.h> |
| 30 | #include <media/MmapStreamInterface.h> |
| 31 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 32 | #include "binding/AudioEndpointParcelable.h" |
| 33 | #include "utility/AAudioUtilities.h" |
| 34 | |
| 35 | #include "AAudioServiceEndpointMMAP.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 36 | #include "AAudioServiceStreamBase.h" |
| 37 | #include "AAudioServiceStreamMMAP.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 38 | #include "SharedMemoryProxy.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 39 | |
Phil Burk | e72481c | 2017-08-08 13:20:45 -0700 | [diff] [blame] | 40 | using android::base::unique_fd; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 41 | using namespace android; |
| 42 | using namespace aaudio; |
| 43 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 44 | /** |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 45 | * Service Stream that uses an MMAP buffer. |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 46 | */ |
| 47 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 48 | AAudioServiceStreamMMAP::AAudioServiceStreamMMAP(android::AAudioService &aAudioService, |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 49 | bool inService) |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 50 | : AAudioServiceStreamBase(aAudioService) |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 51 | , mInService(inService) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 54 | // Open stream on HAL and pass information about the shared memory buffer back to the client. |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 55 | aaudio_result_t AAudioServiceStreamMMAP::open(const aaudio::AAudioStreamRequest &request) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 56 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 57 | sp<AAudioServiceStreamMMAP> keep(this); |
| 58 | |
Phil Burk | 15f97c9 | 2018-09-04 14:06:27 -0700 | [diff] [blame] | 59 | if (request.getConstantConfiguration().getSharingMode() != AAUDIO_SHARING_MODE_EXCLUSIVE) { |
| 60 | ALOGE("%s() sharingMode mismatch %d", __func__, |
| 61 | request.getConstantConfiguration().getSharingMode()); |
| 62 | return AAUDIO_ERROR_INTERNAL; |
| 63 | } |
| 64 | |
| 65 | aaudio_result_t result = AAudioServiceStreamBase::open(request); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 66 | if (result != AAUDIO_OK) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 67 | return result; |
| 68 | } |
| 69 | |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 70 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 71 | if (endpoint == nullptr) { |
| 72 | ALOGE("%s() has no endpoint", __func__); |
| 73 | return AAUDIO_ERROR_INVALID_STATE; |
| 74 | } |
| 75 | |
| 76 | result = endpoint->registerStream(keep); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 77 | if (result != AAUDIO_OK) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 78 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 79 | } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 80 | |
Phil Burk | 5a26e66 | 2017-07-07 12:44:48 -0700 | [diff] [blame] | 81 | setState(AAUDIO_STREAM_STATE_OPEN); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 82 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 83 | return AAUDIO_OK; |
| 84 | } |
| 85 | |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 86 | // Start the flow of data. |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 87 | aaudio_result_t AAudioServiceStreamMMAP::startDevice_l() { |
| 88 | aaudio_result_t result = AAudioServiceStreamBase::startDevice_l(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 89 | if (!mInService && result == AAUDIO_OK) { |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 90 | // Note that this can sometimes take 200 to 300 msec for a cold start! |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 91 | result = startClient_l( |
| 92 | mMmapClient, nullptr /*const audio_attributes_t* */, &mClientHandle); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 93 | } |
| 94 | return result; |
| 95 | } |
| 96 | |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 97 | // Stop the flow of data such that start() can resume with loss of data. |
Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 98 | aaudio_result_t AAudioServiceStreamMMAP::pause_l() { |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 99 | if (!isRunning()) { |
| 100 | return AAUDIO_OK; |
| 101 | } |
Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 102 | aaudio_result_t result = AAudioServiceStreamBase::pause_l(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 103 | // TODO put before base::pause()? |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 104 | if (!mInService) { |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 105 | (void) stopClient_l(mClientHandle); |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 106 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 107 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 110 | aaudio_result_t AAudioServiceStreamMMAP::stop_l() { |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 111 | if (!isRunning()) { |
| 112 | return AAUDIO_OK; |
| 113 | } |
Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 114 | aaudio_result_t result = AAudioServiceStreamBase::stop_l(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 115 | // TODO put before base::stop()? |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 116 | if (!mInService) { |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 117 | (void) stopClient_l(mClientHandle); |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 118 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 119 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 120 | } |
| 121 | |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 122 | aaudio_result_t AAudioServiceStreamMMAP::standby_l() { |
| 123 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 124 | if (endpoint == nullptr) { |
| 125 | ALOGE("%s() has no endpoint", __func__); |
| 126 | return AAUDIO_ERROR_INVALID_STATE; |
| 127 | } |
| 128 | aaudio_result_t result = endpoint->standby(); |
| 129 | if (result == AAUDIO_OK) { |
| 130 | setStandby_l(true); |
| 131 | } |
| 132 | return result; |
| 133 | } |
| 134 | |
| 135 | aaudio_result_t AAudioServiceStreamMMAP::exitStandby_l(AudioEndpointParcelable* parcelable) { |
| 136 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 137 | if (endpoint == nullptr) { |
| 138 | ALOGE("%s() has no endpoint", __func__); |
| 139 | return AAUDIO_ERROR_INVALID_STATE; |
| 140 | } |
| 141 | aaudio_result_t result = endpoint->exitStandby(parcelable); |
| 142 | if (result == AAUDIO_OK) { |
| 143 | setStandby_l(false); |
| 144 | } else { |
| 145 | ALOGE("%s failed, result %d, disconnecting stream.", __func__, result); |
| 146 | disconnect_l(); |
| 147 | } |
| 148 | return result; |
| 149 | } |
| 150 | |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 151 | aaudio_result_t AAudioServiceStreamMMAP::startClient(const android::AudioClient& client, |
jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 152 | const audio_attributes_t *attr, |
Phil Burk | cffd50f | 2024-06-03 23:52:19 +0000 | [diff] [blame] | 153 | audio_port_handle_t *portHandlePtr) { |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 154 | if (com::android::media::aaudio::start_stop_client_from_command_thread()) { |
Phil Burk | cffd50f | 2024-06-03 23:52:19 +0000 | [diff] [blame] | 155 | return sendStartClientCommand(client, attr, portHandlePtr); |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 156 | } else { |
| 157 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 158 | if (endpoint == nullptr) { |
| 159 | ALOGE("%s() has no endpoint", __func__); |
| 160 | return AAUDIO_ERROR_INVALID_STATE; |
| 161 | } |
| 162 | // Start the client on behalf of the application. Generate a new porthandle. |
Phil Burk | cffd50f | 2024-06-03 23:52:19 +0000 | [diff] [blame] | 163 | aaudio_result_t result = endpoint->startClient(client, attr, portHandlePtr); |
| 164 | ALOGD("%s() flag off, got port %d", __func__, |
| 165 | ((portHandlePtr == nullptr) ? -1 : *portHandlePtr)); |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 166 | return result; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | aaudio_result_t AAudioServiceStreamMMAP::stopClient(audio_port_handle_t clientHandle) { |
| 171 | if (com::android::media::aaudio::start_stop_client_from_command_thread()) { |
| 172 | return sendStopClientCommand(clientHandle); |
| 173 | } else { |
| 174 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 175 | if (endpoint == nullptr) { |
| 176 | ALOGE("%s() has no endpoint", __func__); |
| 177 | return AAUDIO_ERROR_INVALID_STATE; |
| 178 | } |
| 179 | aaudio_result_t result = endpoint->stopClient(clientHandle); |
| 180 | return result; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | aaudio_result_t AAudioServiceStreamMMAP::startClient_l(const android::AudioClient& client, |
| 185 | const audio_attributes_t *attr, |
| 186 | audio_port_handle_t *clientHandle) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 187 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 188 | if (endpoint == nullptr) { |
| 189 | ALOGE("%s() has no endpoint", __func__); |
| 190 | return AAUDIO_ERROR_INVALID_STATE; |
| 191 | } |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 192 | // Start the client on behalf of the application. Generate a new porthandle. |
jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 193 | aaudio_result_t result = endpoint->startClient(client, attr, clientHandle); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 194 | return result; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 195 | } |
| 196 | |
jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 197 | aaudio_result_t AAudioServiceStreamMMAP::stopClient_l(audio_port_handle_t clientHandle) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 198 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 199 | if (endpoint == nullptr) { |
| 200 | ALOGE("%s() has no endpoint", __func__); |
| 201 | return AAUDIO_ERROR_INVALID_STATE; |
| 202 | } |
| 203 | aaudio_result_t result = endpoint->stopClient(clientHandle); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 204 | return result; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 207 | // Get free-running DSP or DMA hardware position from the HAL. |
jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 208 | aaudio_result_t AAudioServiceStreamMMAP::getFreeRunningPosition_l(int64_t *positionFrames, |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 209 | int64_t *timeNanos) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 210 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 211 | if (endpoint == nullptr) { |
| 212 | ALOGE("%s() has no endpoint", __func__); |
| 213 | return AAUDIO_ERROR_INVALID_STATE; |
| 214 | } |
| 215 | sp<AAudioServiceEndpointMMAP> serviceEndpointMMAP = |
| 216 | static_cast<AAudioServiceEndpointMMAP *>(endpoint.get()); |
| 217 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 218 | aaudio_result_t result = serviceEndpointMMAP->getFreeRunningPosition(positionFrames, timeNanos); |
| 219 | if (result == AAUDIO_OK) { |
| 220 | Timestamp timestamp(*positionFrames, *timeNanos); |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 221 | mAtomicStreamTimestamp.write(timestamp); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 222 | *positionFrames = timestamp.getPosition(); |
| 223 | *timeNanos = timestamp.getNanoseconds(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 224 | } else if (result != AAUDIO_ERROR_UNAVAILABLE) { |
jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 225 | disconnect_l(); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 226 | } |
Phil Burk | 940083c | 2017-07-17 17:00:02 -0700 | [diff] [blame] | 227 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 228 | } |
| 229 | |
jiabin | b7d8c5a | 2020-08-26 17:24:52 -0700 | [diff] [blame] | 230 | // Get timestamp from presentation position. |
Phil Burk | f95ed73 | 2020-09-30 18:48:17 +0000 | [diff] [blame] | 231 | // If it fails, get timestamp that was written by getFreeRunningPosition() |
jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 232 | aaudio_result_t AAudioServiceStreamMMAP::getHardwareTimestamp_l(int64_t *positionFrames, |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 233 | int64_t *timeNanos) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 234 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 235 | if (endpoint == nullptr) { |
| 236 | ALOGE("%s() has no endpoint", __func__); |
| 237 | return AAUDIO_ERROR_INVALID_STATE; |
| 238 | } |
| 239 | sp<AAudioServiceEndpointMMAP> serviceEndpointMMAP = |
| 240 | static_cast<AAudioServiceEndpointMMAP *>(endpoint.get()); |
| 241 | |
jiabin | b7d8c5a | 2020-08-26 17:24:52 -0700 | [diff] [blame] | 242 | uint64_t position; |
jiabin | a5df87b | 2020-12-29 10:45:19 -0800 | [diff] [blame] | 243 | aaudio_result_t result = serviceEndpointMMAP->getExternalPosition(&position, timeNanos); |
| 244 | if (result == AAUDIO_OK) { |
| 245 | ALOGV("%s() getExternalPosition() says pos = %" PRIi64 ", time = %" PRIi64, |
Phil Burk | f95ed73 | 2020-09-30 18:48:17 +0000 | [diff] [blame] | 246 | __func__, position, *timeNanos); |
jiabin | b7d8c5a | 2020-08-26 17:24:52 -0700 | [diff] [blame] | 247 | *positionFrames = (int64_t) position; |
| 248 | return AAUDIO_OK; |
jiabin | a5df87b | 2020-12-29 10:45:19 -0800 | [diff] [blame] | 249 | } else { |
| 250 | ALOGV("%s() getExternalPosition() returns error %d", __func__, result); |
| 251 | } |
| 252 | |
Phil Burk | f95ed73 | 2020-09-30 18:48:17 +0000 | [diff] [blame] | 253 | if (mAtomicStreamTimestamp.isValid()) { |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 254 | Timestamp timestamp = mAtomicStreamTimestamp.read(); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 255 | *positionFrames = timestamp.getPosition(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 256 | *timeNanos = timestamp.getNanoseconds() + serviceEndpointMMAP->getHardwareTimeOffsetNanos(); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 257 | return AAUDIO_OK; |
| 258 | } else { |
| 259 | return AAUDIO_ERROR_UNAVAILABLE; |
| 260 | } |
| 261 | } |
| 262 | |
Phil Burk | fbf031e | 2017-10-12 15:58:31 -0700 | [diff] [blame] | 263 | // Get an immutable description of the data queue from the HAL. |
jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 264 | aaudio_result_t AAudioServiceStreamMMAP::getAudioDataDescription_l( |
| 265 | AudioEndpointParcelable* parcelable) |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 266 | { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 267 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 268 | if (endpoint == nullptr) { |
| 269 | ALOGE("%s() has no endpoint", __func__); |
| 270 | return AAUDIO_ERROR_INVALID_STATE; |
| 271 | } |
| 272 | sp<AAudioServiceEndpointMMAP> serviceEndpointMMAP = |
| 273 | static_cast<AAudioServiceEndpointMMAP *>(endpoint.get()); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 274 | return serviceEndpointMMAP->getDownDataDescription(parcelable); |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 275 | } |
jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame] | 276 | |
| 277 | int64_t AAudioServiceStreamMMAP::nextDataReportTime_l() { |
| 278 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 279 | if (endpoint == nullptr) { |
| 280 | ALOGE("%s() has no endpoint", __func__); |
| 281 | return std::numeric_limits<int64_t>::max(); |
| 282 | } |
| 283 | sp<AAudioServiceEndpointMMAP> serviceEndpointMMAP = |
| 284 | static_cast<AAudioServiceEndpointMMAP *>(endpoint.get()); |
| 285 | return serviceEndpointMMAP->nextDataReportTime(); |
| 286 | } |
| 287 | |
| 288 | void AAudioServiceStreamMMAP::reportData_l() { |
| 289 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 290 | if (endpoint == nullptr) { |
| 291 | ALOGE("%s() has no endpoint", __func__); |
| 292 | return; |
| 293 | } |
| 294 | sp<AAudioServiceEndpointMMAP> serviceEndpointMMAP = |
| 295 | static_cast<AAudioServiceEndpointMMAP *>(endpoint.get()); |
| 296 | return serviceEndpointMMAP->reportData(); |
| 297 | } |