Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "AAudioServiceStreamBase" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 21 | #include <iomanip> |
| 22 | #include <iostream> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 23 | #include <mutex> |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 24 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 25 | #include <media/MediaMetricsItem.h> |
| 26 | #include <media/TypeConverter.h> |
| 27 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 28 | #include "binding/IAAudioService.h" |
| 29 | #include "binding/AAudioServiceMessage.h" |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 30 | #include "core/AudioGlobal.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 31 | #include "utility/AudioClock.h" |
| 32 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 33 | #include "AAudioEndpointManager.h" |
| 34 | #include "AAudioService.h" |
| 35 | #include "AAudioServiceEndpoint.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 36 | #include "AAudioServiceStreamBase.h" |
| 37 | #include "TimestampScheduler.h" |
| 38 | |
| 39 | using namespace android; // TODO just import names needed |
| 40 | using namespace aaudio; // TODO just import names needed |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 43 | * Base class for streams in the service. |
| 44 | * @return |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 45 | */ |
| 46 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 47 | AAudioServiceStreamBase::AAudioServiceStreamBase(AAudioService &audioService) |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 48 | : mUpMessageQueue(nullptr) |
Phil Burk | 5597889 | 2018-01-11 14:56:09 -0800 | [diff] [blame] | 49 | , mTimestampThread("AATime") |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 50 | , mAtomicStreamTimestamp() |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 51 | , mAudioService(audioService) { |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 52 | mMmapClient.clientUid = -1; |
| 53 | mMmapClient.clientPid = -1; |
| 54 | mMmapClient.packageName = String16(""); |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 57 | AAudioServiceStreamBase::~AAudioServiceStreamBase() { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 58 | // May not be set if open failed. |
| 59 | if (mMetricsId.size() > 0) { |
| 60 | mediametrics::LogItem(mMetricsId) |
| 61 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_DTOR) |
| 62 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 63 | .record(); |
| 64 | } |
| 65 | |
Phil Burk | 5a26e66 | 2017-07-07 12:44:48 -0700 | [diff] [blame] | 66 | // If the stream is deleted when OPEN or in use then audio resources will leak. |
| 67 | // This would indicate an internal error. So we want to find this ASAP. |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 68 | LOG_ALWAYS_FATAL_IF(!(getState() == AAUDIO_STREAM_STATE_CLOSED |
| 69 | || getState() == AAUDIO_STREAM_STATE_UNINITIALIZED |
| 70 | || getState() == AAUDIO_STREAM_STATE_DISCONNECTED), |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 71 | "service stream %p still open, state = %d", |
| 72 | this, getState()); |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 75 | std::string AAudioServiceStreamBase::dumpHeader() { |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 76 | return std::string(" T Handle UId Port Run State Format Burst Chan Capacity"); |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Phil Burk | 4501b35 | 2017-06-29 18:12:36 -0700 | [diff] [blame] | 79 | std::string AAudioServiceStreamBase::dump() const { |
| 80 | std::stringstream result; |
| 81 | |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 82 | result << " 0x" << std::setfill('0') << std::setw(8) << std::hex << mHandle |
| 83 | << std::dec << std::setfill(' ') ; |
| 84 | result << std::setw(6) << mMmapClient.clientUid; |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 85 | result << std::setw(7) << mClientHandle; |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 86 | result << std::setw(4) << (isRunning() ? "yes" : " no"); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 87 | result << std::setw(6) << getState(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 88 | result << std::setw(7) << getFormat(); |
Phil Burk | a5222e2 | 2017-07-28 13:31:14 -0700 | [diff] [blame] | 89 | result << std::setw(6) << mFramesPerBurst; |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 90 | result << std::setw(5) << getSamplesPerFrame(); |
| 91 | result << std::setw(9) << getBufferCapacity(); |
Phil Burk | 4501b35 | 2017-06-29 18:12:36 -0700 | [diff] [blame] | 92 | |
| 93 | return result.str(); |
| 94 | } |
| 95 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 96 | void AAudioServiceStreamBase::logOpen(aaudio_handle_t streamHandle) { |
| 97 | // This is the first log sent from the AAudio Service for a stream. |
| 98 | mMetricsId = std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_STREAM) |
| 99 | + std::to_string(streamHandle); |
| 100 | |
| 101 | audio_attributes_t attributes = AAudioServiceEndpoint::getAudioAttributesFrom(this); |
| 102 | |
| 103 | // Once this item is logged by the server, the client with the same PID, UID |
| 104 | // can also log properties. |
| 105 | mediametrics::LogItem(mMetricsId) |
| 106 | .setPid(getOwnerProcessId()) |
| 107 | .setUid(getOwnerUserId()) |
Andy Hung | d203eb6 | 2020-04-27 09:12:46 -0700 | [diff] [blame] | 108 | .set(AMEDIAMETRICS_PROP_ALLOWUID, (int32_t)getOwnerUserId()) |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 109 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_OPEN) |
| 110 | // the following are immutable |
| 111 | .set(AMEDIAMETRICS_PROP_BUFFERCAPACITYFRAMES, (int32_t)getBufferCapacity()) |
| 112 | .set(AMEDIAMETRICS_PROP_BURSTFRAMES, (int32_t)getFramesPerBurst()) |
| 113 | .set(AMEDIAMETRICS_PROP_CHANNELCOUNT, (int32_t)getSamplesPerFrame()) |
| 114 | .set(AMEDIAMETRICS_PROP_CONTENTTYPE, toString(attributes.content_type).c_str()) |
| 115 | .set(AMEDIAMETRICS_PROP_DIRECTION, |
| 116 | AudioGlobal_convertDirectionToText(getDirection())) |
| 117 | .set(AMEDIAMETRICS_PROP_ENCODING, toString(getFormat()).c_str()) |
| 118 | .set(AMEDIAMETRICS_PROP_ROUTEDDEVICEID, (int32_t)getDeviceId()) |
| 119 | .set(AMEDIAMETRICS_PROP_SAMPLERATE, (int32_t)getSampleRate()) |
| 120 | .set(AMEDIAMETRICS_PROP_SESSIONID, (int32_t)getSessionId()) |
| 121 | .set(AMEDIAMETRICS_PROP_SOURCE, toString(attributes.source).c_str()) |
| 122 | .set(AMEDIAMETRICS_PROP_USAGE, toString(attributes.usage).c_str()) |
| 123 | .record(); |
| 124 | } |
| 125 | |
Phil Burk | 15f97c9 | 2018-09-04 14:06:27 -0700 | [diff] [blame] | 126 | aaudio_result_t AAudioServiceStreamBase::open(const aaudio::AAudioStreamRequest &request) { |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 127 | AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance(); |
| 128 | aaudio_result_t result = AAUDIO_OK; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 129 | |
| 130 | mMmapClient.clientUid = request.getUserId(); |
| 131 | mMmapClient.clientPid = request.getProcessId(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 132 | mMmapClient.packageName.setTo(String16("")); // TODO What should we do here? |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 133 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 134 | // Limit scope of lock to avoid recursive lock in close(). |
| 135 | { |
| 136 | std::lock_guard<std::mutex> lock(mUpMessageQueueLock); |
| 137 | if (mUpMessageQueue != nullptr) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 138 | ALOGE("%s() called twice", __func__); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 139 | return AAUDIO_ERROR_INVALID_STATE; |
| 140 | } |
| 141 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 142 | mUpMessageQueue = new SharedRingBuffer(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 143 | result = mUpMessageQueue->allocate(sizeof(AAudioServiceMessage), |
| 144 | QUEUE_UP_CAPACITY_COMMANDS); |
| 145 | if (result != AAUDIO_OK) { |
| 146 | goto error; |
| 147 | } |
| 148 | |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 149 | // This is not protected by a lock because the stream cannot be |
| 150 | // referenced until the service returns a handle to the client. |
| 151 | // So only one thread can open a stream. |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 152 | mServiceEndpoint = mEndpointManager.openEndpoint(mAudioService, |
Phil Burk | 15f97c9 | 2018-09-04 14:06:27 -0700 | [diff] [blame] | 153 | request); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 154 | if (mServiceEndpoint == nullptr) { |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 155 | result = AAUDIO_ERROR_UNAVAILABLE; |
| 156 | goto error; |
| 157 | } |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 158 | // Save a weak pointer that we will use to access the endpoint. |
| 159 | mServiceEndpointWeak = mServiceEndpoint; |
| 160 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 161 | mFramesPerBurst = mServiceEndpoint->getFramesPerBurst(); |
| 162 | copyFrom(*mServiceEndpoint); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 163 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 164 | return result; |
| 165 | |
| 166 | error: |
| 167 | close(); |
| 168 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 169 | } |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 170 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 171 | aaudio_result_t AAudioServiceStreamBase::close() { |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 172 | if (getState() == AAUDIO_STREAM_STATE_CLOSED) { |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 173 | return AAUDIO_OK; |
| 174 | } |
| 175 | |
| 176 | stop(); |
| 177 | |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 178 | aaudio_result_t result = AAUDIO_OK; |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 179 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 180 | if (endpoint == nullptr) { |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 181 | result = AAUDIO_ERROR_INVALID_STATE; |
| 182 | } else { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 183 | endpoint->unregisterStream(this); |
| 184 | AAudioEndpointManager &endpointManager = AAudioEndpointManager::getInstance(); |
| 185 | endpointManager.closeEndpoint(endpoint); |
| 186 | |
| 187 | // AAudioService::closeStream() prevents two threads from closing at the same time. |
| 188 | mServiceEndpoint.clear(); // endpoint will hold the pointer until this method returns. |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | { |
| 192 | std::lock_guard<std::mutex> lock(mUpMessageQueueLock); |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 193 | stopTimestampThread(); |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 194 | delete mUpMessageQueue; |
| 195 | mUpMessageQueue = nullptr; |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 196 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 197 | |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 198 | setState(AAUDIO_STREAM_STATE_CLOSED); |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 199 | |
| 200 | mediametrics::LogItem(mMetricsId) |
| 201 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_CLOSE) |
| 202 | .record(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 203 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 206 | aaudio_result_t AAudioServiceStreamBase::startDevice() { |
| 207 | mClientHandle = AUDIO_PORT_HANDLE_NONE; |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 208 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 209 | if (endpoint == nullptr) { |
| 210 | ALOGE("%s() has no endpoint", __func__); |
| 211 | return AAUDIO_ERROR_INVALID_STATE; |
| 212 | } |
| 213 | return endpoint->startStream(this, &mClientHandle); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 216 | /** |
| 217 | * Start the flow of audio data. |
| 218 | * |
| 219 | * An AAUDIO_SERVICE_EVENT_STARTED will be sent to the client when complete. |
| 220 | */ |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 221 | aaudio_result_t AAudioServiceStreamBase::start() { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 222 | const int64_t beginNs = AudioClock::getNanoseconds(); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 223 | aaudio_result_t result = AAUDIO_OK; |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 224 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 225 | mediametrics::Defer defer([&] { |
| 226 | mediametrics::LogItem(mMetricsId) |
| 227 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_START) |
| 228 | .set(AMEDIAMETRICS_PROP_DURATIONNS, (int64_t)(AudioClock::getNanoseconds() - beginNs)) |
| 229 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 230 | .set(AMEDIAMETRICS_PROP_STATUS, (int32_t)result) |
| 231 | .record(); }); |
| 232 | |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 233 | if (isRunning()) { |
| 234 | return AAUDIO_OK; |
| 235 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 236 | |
Phil Burk | 2329638 | 2017-11-20 15:45:11 -0800 | [diff] [blame] | 237 | setFlowing(false); |
Phil Burk | 762365c | 2018-12-10 16:02:16 -0800 | [diff] [blame] | 238 | setSuspended(false); |
Phil Burk | 2329638 | 2017-11-20 15:45:11 -0800 | [diff] [blame] | 239 | |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 240 | // Start with fresh presentation timestamps. |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 241 | mAtomicStreamTimestamp.clear(); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 242 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 243 | mClientHandle = AUDIO_PORT_HANDLE_NONE; |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 244 | result = startDevice(); |
| 245 | if (result != AAUDIO_OK) goto error; |
| 246 | |
| 247 | // This should happen at the end of the start. |
| 248 | sendServiceEvent(AAUDIO_SERVICE_EVENT_STARTED); |
| 249 | setState(AAUDIO_STREAM_STATE_STARTED); |
| 250 | mThreadEnabled.store(true); |
| 251 | result = mTimestampThread.start(this); |
| 252 | if (result != AAUDIO_OK) goto error; |
| 253 | |
| 254 | return result; |
| 255 | |
| 256 | error: |
| 257 | disconnect(); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 258 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | aaudio_result_t AAudioServiceStreamBase::pause() { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 262 | const int64_t beginNs = AudioClock::getNanoseconds(); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 263 | aaudio_result_t result = AAUDIO_OK; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 264 | if (!isRunning()) { |
| 265 | return result; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 266 | } |
Phil Burk | 73af62a | 2017-10-26 12:11:47 -0700 | [diff] [blame] | 267 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 268 | mediametrics::Defer defer([&] { |
| 269 | mediametrics::LogItem(mMetricsId) |
| 270 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_PAUSE) |
| 271 | .set(AMEDIAMETRICS_PROP_DURATIONNS, (int64_t)(AudioClock::getNanoseconds() - beginNs)) |
| 272 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 273 | .set(AMEDIAMETRICS_PROP_STATUS, (int32_t)result) |
| 274 | .record(); }); |
| 275 | |
Phil Burk | 73af62a | 2017-10-26 12:11:47 -0700 | [diff] [blame] | 276 | // Send it now because the timestamp gets rounded up when stopStream() is called below. |
| 277 | // Also we don't need the timestamps while we are shutting down. |
| 278 | sendCurrentTimestamp(); |
| 279 | |
| 280 | result = stopTimestampThread(); |
| 281 | if (result != AAUDIO_OK) { |
| 282 | disconnect(); |
| 283 | return result; |
| 284 | } |
| 285 | |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 286 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 287 | if (endpoint == nullptr) { |
| 288 | ALOGE("%s() has no endpoint", __func__); |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 289 | result = AAUDIO_ERROR_INVALID_STATE; // for MediaMetric tracking |
| 290 | return result; |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 291 | } |
| 292 | result = endpoint->stopStream(this, mClientHandle); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 293 | if (result != AAUDIO_OK) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 294 | ALOGE("%s() mServiceEndpoint returned %d, %s", __func__, result, getTypeText()); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 295 | disconnect(); // TODO should we return or pause Base first? |
| 296 | } |
| 297 | |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 298 | sendServiceEvent(AAUDIO_SERVICE_EVENT_PAUSED); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 299 | setState(AAUDIO_STREAM_STATE_PAUSED); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 300 | return result; |
| 301 | } |
| 302 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 303 | aaudio_result_t AAudioServiceStreamBase::stop() { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 304 | const int64_t beginNs = AudioClock::getNanoseconds(); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 305 | aaudio_result_t result = AAUDIO_OK; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 306 | if (!isRunning()) { |
| 307 | return result; |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 308 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 309 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 310 | mediametrics::Defer defer([&] { |
| 311 | mediametrics::LogItem(mMetricsId) |
| 312 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_STOP) |
| 313 | .set(AMEDIAMETRICS_PROP_DURATIONNS, (int64_t)(AudioClock::getNanoseconds() - beginNs)) |
| 314 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 315 | .set(AMEDIAMETRICS_PROP_STATUS, (int32_t)result) |
| 316 | .record(); }); |
| 317 | |
Phil Burk | 83fb844 | 2017-10-05 16:55:17 -0700 | [diff] [blame] | 318 | setState(AAUDIO_STREAM_STATE_STOPPING); |
| 319 | |
Phil Burk | 73af62a | 2017-10-26 12:11:47 -0700 | [diff] [blame] | 320 | // Send it now because the timestamp gets rounded up when stopStream() is called below. |
| 321 | // Also we don't need the timestamps while we are shutting down. |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 322 | sendCurrentTimestamp(); // warning - this calls a virtual function |
| 323 | result = stopTimestampThread(); |
| 324 | if (result != AAUDIO_OK) { |
| 325 | disconnect(); |
| 326 | return result; |
| 327 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 328 | |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 329 | sp<AAudioServiceEndpoint> endpoint = mServiceEndpointWeak.promote(); |
| 330 | if (endpoint == nullptr) { |
| 331 | ALOGE("%s() has no endpoint", __func__); |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 332 | result = AAUDIO_ERROR_INVALID_STATE; // for MediaMetric tracking |
| 333 | return result; |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 334 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 335 | // TODO wait for data to be played out |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 336 | result = endpoint->stopStream(this, mClientHandle); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 337 | if (result != AAUDIO_OK) { |
Phil Burk | 6e2770e | 2018-05-01 13:03:52 -0700 | [diff] [blame] | 338 | ALOGE("%s() stopStream returned %d, %s", __func__, result, getTypeText()); |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 339 | disconnect(); |
| 340 | // TODO what to do with result here? |
| 341 | } |
| 342 | |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 343 | sendServiceEvent(AAUDIO_SERVICE_EVENT_STOPPED); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 344 | setState(AAUDIO_STREAM_STATE_STOPPED); |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 345 | return result; |
| 346 | } |
| 347 | |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 348 | aaudio_result_t AAudioServiceStreamBase::stopTimestampThread() { |
| 349 | aaudio_result_t result = AAUDIO_OK; |
| 350 | // clear flag that tells thread to loop |
| 351 | if (mThreadEnabled.exchange(false)) { |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 352 | result = mTimestampThread.stop(); |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 353 | } |
| 354 | return result; |
| 355 | } |
| 356 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 357 | aaudio_result_t AAudioServiceStreamBase::flush() { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 358 | const int64_t beginNs = AudioClock::getNanoseconds(); |
Phil Burk | 5cc83c3 | 2017-11-28 15:43:18 -0800 | [diff] [blame] | 359 | aaudio_result_t result = AAudio_isFlushAllowed(getState()); |
| 360 | if (result != AAUDIO_OK) { |
| 361 | return result; |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 362 | } |
Phil Burk | 5cc83c3 | 2017-11-28 15:43:18 -0800 | [diff] [blame] | 363 | |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 364 | mediametrics::Defer defer([&] { |
| 365 | mediametrics::LogItem(mMetricsId) |
| 366 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_FLUSH) |
| 367 | .set(AMEDIAMETRICS_PROP_DURATIONNS, (int64_t)(AudioClock::getNanoseconds() - beginNs)) |
| 368 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 369 | .set(AMEDIAMETRICS_PROP_STATUS, (int32_t)result) |
| 370 | .record(); }); |
| 371 | |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 372 | // Data will get flushed when the client receives the FLUSHED event. |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 373 | sendServiceEvent(AAUDIO_SERVICE_EVENT_FLUSHED); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 374 | setState(AAUDIO_STREAM_STATE_FLUSHED); |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 375 | return AAUDIO_OK; |
| 376 | } |
| 377 | |
Phil Burk | cf5f6d2 | 2017-05-26 12:35:07 -0700 | [diff] [blame] | 378 | // implement Runnable, periodically send timestamps to client |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 379 | __attribute__((no_sanitize("integer"))) |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 380 | void AAudioServiceStreamBase::run() { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 381 | ALOGD("%s() %s entering >>>>>>>>>>>>>> TIMESTAMPS", __func__, getTypeText()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 382 | TimestampScheduler timestampScheduler; |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 383 | timestampScheduler.setBurstPeriod(mFramesPerBurst, getSampleRate()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 384 | timestampScheduler.start(AudioClock::getNanoseconds()); |
| 385 | int64_t nextTime = timestampScheduler.nextAbsoluteTime(); |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 386 | int32_t loopCount = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 387 | while(mThreadEnabled.load()) { |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 388 | loopCount++; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 389 | if (AudioClock::getNanoseconds() >= nextTime) { |
| 390 | aaudio_result_t result = sendCurrentTimestamp(); |
| 391 | if (result != AAUDIO_OK) { |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 392 | ALOGE("%s() timestamp thread got result = %d", __func__, result); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 393 | break; |
| 394 | } |
| 395 | nextTime = timestampScheduler.nextAbsoluteTime(); |
| 396 | } else { |
| 397 | // Sleep until it is time to send the next timestamp. |
Phil Burk | 98d6d92 | 2017-07-06 11:52:45 -0700 | [diff] [blame] | 398 | // TODO Wait for a signal with a timeout so that we can stop more quickly. |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 399 | AudioClock::sleepUntilNanoTime(nextTime); |
| 400 | } |
| 401 | } |
Phil Burk | a53ffa6 | 2018-10-10 16:21:37 -0700 | [diff] [blame] | 402 | ALOGD("%s() %s exiting after %d loops <<<<<<<<<<<<<< TIMESTAMPS", |
| 403 | __func__, getTypeText(), loopCount); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Phil Burk | 5ef003b | 2017-06-30 11:43:37 -0700 | [diff] [blame] | 406 | void AAudioServiceStreamBase::disconnect() { |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 407 | if (getState() != AAUDIO_STREAM_STATE_DISCONNECTED) { |
Phil Burk | a987670 | 2020-04-20 18:16:15 -0700 | [diff] [blame] | 408 | mediametrics::LogItem(mMetricsId) |
| 409 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_DISCONNECT) |
| 410 | .set(AMEDIAMETRICS_PROP_STATE, AudioGlobal_convertStreamStateToText(getState())) |
| 411 | .record(); |
Phil Burk | 5ef003b | 2017-06-30 11:43:37 -0700 | [diff] [blame] | 412 | sendServiceEvent(AAUDIO_SERVICE_EVENT_DISCONNECTED); |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 413 | setState(AAUDIO_STREAM_STATE_DISCONNECTED); |
Phil Burk | 5ef003b | 2017-06-30 11:43:37 -0700 | [diff] [blame] | 414 | } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | aaudio_result_t AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event, |
Phil Burk | 2329638 | 2017-11-20 15:45:11 -0800 | [diff] [blame] | 418 | double dataDouble) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 419 | AAudioServiceMessage command; |
| 420 | command.what = AAudioServiceMessage::code::EVENT; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 421 | command.event.event = event; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 422 | command.event.dataDouble = dataDouble; |
Phil Burk | 2329638 | 2017-11-20 15:45:11 -0800 | [diff] [blame] | 423 | return writeUpMessageQueue(&command); |
| 424 | } |
| 425 | |
| 426 | aaudio_result_t AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event, |
| 427 | int64_t dataLong) { |
| 428 | AAudioServiceMessage command; |
| 429 | command.what = AAudioServiceMessage::code::EVENT; |
| 430 | command.event.event = event; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 431 | command.event.dataLong = dataLong; |
| 432 | return writeUpMessageQueue(&command); |
| 433 | } |
| 434 | |
Phil Burk | f878a8d | 2019-03-29 17:23:00 -0700 | [diff] [blame] | 435 | bool AAudioServiceStreamBase::isUpMessageQueueBusy() { |
| 436 | std::lock_guard<std::mutex> lock(mUpMessageQueueLock); |
| 437 | if (mUpMessageQueue == nullptr) { |
| 438 | ALOGE("%s(): mUpMessageQueue null! - stream not open", __func__); |
| 439 | return true; |
| 440 | } |
| 441 | int32_t framesAvailable = mUpMessageQueue->getFifoBuffer() |
| 442 | ->getFullFramesAvailable(); |
| 443 | int32_t capacity = mUpMessageQueue->getFifoBuffer() |
| 444 | ->getBufferCapacityInFrames(); |
| 445 | // Is it half full or more |
| 446 | return framesAvailable >= (capacity / 2); |
| 447 | } |
| 448 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 449 | aaudio_result_t AAudioServiceStreamBase::writeUpMessageQueue(AAudioServiceMessage *command) { |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 450 | std::lock_guard<std::mutex> lock(mUpMessageQueueLock); |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 451 | if (mUpMessageQueue == nullptr) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 452 | ALOGE("%s(): mUpMessageQueue null! - stream not open", __func__); |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 453 | return AAUDIO_ERROR_NULL; |
| 454 | } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 455 | int32_t count = mUpMessageQueue->getFifoBuffer()->write(command, 1); |
| 456 | if (count != 1) { |
Phil Burk | 762365c | 2018-12-10 16:02:16 -0800 | [diff] [blame] | 457 | ALOGW("%s(): Queue full. Did client stop? Suspending stream. what = %u, %s", |
| 458 | __func__, command->what, getTypeText()); |
| 459 | setSuspended(true); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 460 | return AAUDIO_ERROR_WOULD_BLOCK; |
| 461 | } else { |
| 462 | return AAUDIO_OK; |
| 463 | } |
| 464 | } |
| 465 | |
Phil Burk | 2329638 | 2017-11-20 15:45:11 -0800 | [diff] [blame] | 466 | aaudio_result_t AAudioServiceStreamBase::sendXRunCount(int32_t xRunCount) { |
| 467 | return sendServiceEvent(AAUDIO_SERVICE_EVENT_XRUN, (int64_t) xRunCount); |
| 468 | } |
| 469 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 470 | aaudio_result_t AAudioServiceStreamBase::sendCurrentTimestamp() { |
| 471 | AAudioServiceMessage command; |
Phil Burk | f878a8d | 2019-03-29 17:23:00 -0700 | [diff] [blame] | 472 | // It is not worth filling up the queue with timestamps. |
| 473 | // That can cause the stream to get suspended. |
| 474 | // So just drop the timestamp if the queue is getting full. |
| 475 | if (isUpMessageQueueBusy()) { |
| 476 | return AAUDIO_OK; |
| 477 | } |
| 478 | |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 479 | // Send a timestamp for the clock model. |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 480 | aaudio_result_t result = getFreeRunningPosition(&command.timestamp.position, |
| 481 | &command.timestamp.timestamp); |
| 482 | if (result == AAUDIO_OK) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 483 | ALOGV("%s() SERVICE %8lld at %lld", __func__, |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 484 | (long long) command.timestamp.position, |
| 485 | (long long) command.timestamp.timestamp); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 486 | command.what = AAudioServiceMessage::code::TIMESTAMP_SERVICE; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 487 | result = writeUpMessageQueue(&command); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 488 | |
| 489 | if (result == AAUDIO_OK) { |
| 490 | // Send a hardware timestamp for presentation time. |
| 491 | result = getHardwareTimestamp(&command.timestamp.position, |
| 492 | &command.timestamp.timestamp); |
| 493 | if (result == AAUDIO_OK) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 494 | ALOGV("%s() HARDWARE %8lld at %lld", __func__, |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 495 | (long long) command.timestamp.position, |
| 496 | (long long) command.timestamp.timestamp); |
Phil Burk | 97350f9 | 2017-07-21 15:59:44 -0700 | [diff] [blame] | 497 | command.what = AAudioServiceMessage::code::TIMESTAMP_HARDWARE; |
| 498 | result = writeUpMessageQueue(&command); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 503 | if (result == AAUDIO_ERROR_UNAVAILABLE) { // TODO review best error code |
Phil Burk | 940083c | 2017-07-17 17:00:02 -0700 | [diff] [blame] | 504 | result = AAUDIO_OK; // just not available yet, try again later |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 505 | } |
| 506 | return result; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 509 | /** |
| 510 | * Get an immutable description of the in-memory queues |
| 511 | * used to communicate with the underlying HAL or Service. |
| 512 | */ |
| 513 | aaudio_result_t AAudioServiceStreamBase::getDescription(AudioEndpointParcelable &parcelable) { |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 514 | { |
| 515 | std::lock_guard<std::mutex> lock(mUpMessageQueueLock); |
| 516 | if (mUpMessageQueue == nullptr) { |
Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 517 | ALOGE("%s(): mUpMessageQueue null! - stream not open", __func__); |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 518 | return AAUDIO_ERROR_NULL; |
| 519 | } |
| 520 | // Gather information on the message queue. |
| 521 | mUpMessageQueue->fillParcelable(parcelable, |
| 522 | parcelable.mUpMessageQueueParcelable); |
| 523 | } |
| 524 | return getAudioDataDescription(parcelable); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 525 | } |
Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 526 | |
| 527 | void AAudioServiceStreamBase::onVolumeChanged(float volume) { |
| 528 | sendServiceEvent(AAUDIO_SERVICE_EVENT_VOLUME, volume); |
| 529 | } |
Phil Burk | 9486252 | 2017-09-13 21:31:36 -0700 | [diff] [blame] | 530 | |
Phil Burk | 2fe718b | 2018-05-14 12:28:32 -0700 | [diff] [blame] | 531 | int32_t AAudioServiceStreamBase::incrementServiceReferenceCount_l() { |
Phil Burk | 9486252 | 2017-09-13 21:31:36 -0700 | [diff] [blame] | 532 | return ++mCallingCount; |
| 533 | } |
| 534 | |
Phil Burk | 2fe718b | 2018-05-14 12:28:32 -0700 | [diff] [blame] | 535 | int32_t AAudioServiceStreamBase::decrementServiceReferenceCount_l() { |
| 536 | int32_t count = --mCallingCount; |
| 537 | // Each call to increment should be balanced with one call to decrement. |
| 538 | assert(count >= 0); |
| 539 | return count; |
Phil Burk | 9486252 | 2017-09-13 21:31:36 -0700 | [diff] [blame] | 540 | } |