blob: 635b45cd9dc984c3de1a858fb9bd85137425a37e [file] [log] [blame]
Phil Burk2355edb2016-12-26 13:54:02 -08001/*
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 Laurentcb4dae22017-07-01 19:39:32 -070017#define LOG_TAG "AAudioServiceStreamBase"
Phil Burk2355edb2016-12-26 13:54:02 -080018//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burka5222e22017-07-28 13:31:14 -070021#include <iomanip>
22#include <iostream>
Phil Burkc0c70e32017-02-09 13:18:38 -080023#include <mutex>
Phil Burk2355edb2016-12-26 13:54:02 -080024
Phil Burkc0c70e32017-02-09 13:18:38 -080025#include "binding/IAAudioService.h"
26#include "binding/AAudioServiceMessage.h"
27#include "utility/AudioClock.h"
28
Phil Burk39f02dd2017-08-04 09:13:31 -070029#include "AAudioEndpointManager.h"
30#include "AAudioService.h"
31#include "AAudioServiceEndpoint.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080032#include "AAudioServiceStreamBase.h"
33#include "TimestampScheduler.h"
34
35using namespace android; // TODO just import names needed
36using namespace aaudio; // TODO just import names needed
Phil Burk2355edb2016-12-26 13:54:02 -080037
38/**
Phil Burkc0c70e32017-02-09 13:18:38 -080039 * Base class for streams in the service.
40 * @return
Phil Burk2355edb2016-12-26 13:54:02 -080041 */
42
Phil Burk39f02dd2017-08-04 09:13:31 -070043AAudioServiceStreamBase::AAudioServiceStreamBase(AAudioService &audioService)
Phil Burk2355edb2016-12-26 13:54:02 -080044 : mUpMessageQueue(nullptr)
Phil Burkbcc36742017-08-31 17:24:51 -070045 , mTimestampThread()
Phil Burk39f02dd2017-08-04 09:13:31 -070046 , mAtomicTimestamp()
47 , mAudioService(audioService) {
Eric Laurentcb4dae22017-07-01 19:39:32 -070048 mMmapClient.clientUid = -1;
49 mMmapClient.clientPid = -1;
50 mMmapClient.packageName = String16("");
Phil Burk2355edb2016-12-26 13:54:02 -080051}
52
Phil Burk5ed503c2017-02-01 09:38:15 -080053AAudioServiceStreamBase::~AAudioServiceStreamBase() {
Phil Burkfbf031e2017-10-12 15:58:31 -070054 ALOGD("~AAudioServiceStreamBase() destroying %p", this);
Phil Burk5a26e662017-07-07 12:44:48 -070055 // If the stream is deleted when OPEN or in use then audio resources will leak.
56 // This would indicate an internal error. So we want to find this ASAP.
Phil Burkbcc36742017-08-31 17:24:51 -070057 LOG_ALWAYS_FATAL_IF(!(getState() == AAUDIO_STREAM_STATE_CLOSED
58 || getState() == AAUDIO_STREAM_STATE_UNINITIALIZED
59 || getState() == AAUDIO_STREAM_STATE_DISCONNECTED),
60 "service stream still open, state = %d", getState());
Phil Burk2355edb2016-12-26 13:54:02 -080061}
62
Phil Burka5222e22017-07-28 13:31:14 -070063std::string AAudioServiceStreamBase::dumpHeader() {
64 return std::string(" T Handle UId Run State Format Burst Chan Capacity");
65}
66
Phil Burk4501b352017-06-29 18:12:36 -070067std::string AAudioServiceStreamBase::dump() const {
68 std::stringstream result;
69
Phil Burka5222e22017-07-28 13:31:14 -070070 result << " 0x" << std::setfill('0') << std::setw(8) << std::hex << mHandle
71 << std::dec << std::setfill(' ') ;
72 result << std::setw(6) << mMmapClient.clientUid;
73 result << std::setw(4) << (isRunning() ? "yes" : " no");
Phil Burkbcc36742017-08-31 17:24:51 -070074 result << std::setw(6) << getState();
Phil Burk39f02dd2017-08-04 09:13:31 -070075 result << std::setw(7) << getFormat();
Phil Burka5222e22017-07-28 13:31:14 -070076 result << std::setw(6) << mFramesPerBurst;
Phil Burk39f02dd2017-08-04 09:13:31 -070077 result << std::setw(5) << getSamplesPerFrame();
78 result << std::setw(9) << getBufferCapacity();
Phil Burk4501b352017-06-29 18:12:36 -070079
80 return result.str();
81}
82
Phil Burkc0c70e32017-02-09 13:18:38 -080083aaudio_result_t AAudioServiceStreamBase::open(const aaudio::AAudioStreamRequest &request,
Phil Burk39f02dd2017-08-04 09:13:31 -070084 aaudio_sharing_mode_t sharingMode) {
85 AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance();
86 aaudio_result_t result = AAUDIO_OK;
Eric Laurentcb4dae22017-07-01 19:39:32 -070087
88 mMmapClient.clientUid = request.getUserId();
89 mMmapClient.clientPid = request.getProcessId();
Phil Burk39f02dd2017-08-04 09:13:31 -070090 mMmapClient.packageName.setTo(String16("")); // TODO What should we do here?
Eric Laurentcb4dae22017-07-01 19:39:32 -070091
Phil Burk39f02dd2017-08-04 09:13:31 -070092 // Limit scope of lock to avoid recursive lock in close().
93 {
94 std::lock_guard<std::mutex> lock(mUpMessageQueueLock);
95 if (mUpMessageQueue != nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -070096 ALOGE("open() called twice");
Phil Burk39f02dd2017-08-04 09:13:31 -070097 return AAUDIO_ERROR_INVALID_STATE;
98 }
99
Phil Burkc0c70e32017-02-09 13:18:38 -0800100 mUpMessageQueue = new SharedRingBuffer();
Phil Burk39f02dd2017-08-04 09:13:31 -0700101 result = mUpMessageQueue->allocate(sizeof(AAudioServiceMessage),
102 QUEUE_UP_CAPACITY_COMMANDS);
103 if (result != AAUDIO_OK) {
104 goto error;
105 }
106
107 mServiceEndpoint = mEndpointManager.openEndpoint(mAudioService,
108 request,
109 sharingMode);
110 if (mServiceEndpoint == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700111 ALOGE("open() openEndpoint() failed");
Phil Burk39f02dd2017-08-04 09:13:31 -0700112 result = AAUDIO_ERROR_UNAVAILABLE;
113 goto error;
114 }
115 mFramesPerBurst = mServiceEndpoint->getFramesPerBurst();
116 copyFrom(*mServiceEndpoint);
Phil Burkc0c70e32017-02-09 13:18:38 -0800117 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700118 return result;
119
120error:
121 close();
122 return result;
Phil Burkc0c70e32017-02-09 13:18:38 -0800123}
Phil Burkdec33ab2017-01-17 14:48:16 -0800124
Phil Burkc0c70e32017-02-09 13:18:38 -0800125aaudio_result_t AAudioServiceStreamBase::close() {
Phil Burk39f02dd2017-08-04 09:13:31 -0700126 aaudio_result_t result = AAUDIO_OK;
Phil Burkbcc36742017-08-31 17:24:51 -0700127 if (getState() == AAUDIO_STREAM_STATE_CLOSED) {
Phil Burk39f02dd2017-08-04 09:13:31 -0700128 return AAUDIO_OK;
129 }
130
131 stop();
132
133 if (mServiceEndpoint == nullptr) {
134 result = AAUDIO_ERROR_INVALID_STATE;
135 } else {
136 mServiceEndpoint->unregisterStream(this);
137 AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance();
138 mEndpointManager.closeEndpoint(mServiceEndpoint);
139 mServiceEndpoint.clear();
140 }
141
142 {
143 std::lock_guard<std::mutex> lock(mUpMessageQueueLock);
Phil Burk98d6d922017-07-06 11:52:45 -0700144 stopTimestampThread();
Phil Burk98d6d922017-07-06 11:52:45 -0700145 delete mUpMessageQueue;
146 mUpMessageQueue = nullptr;
Phil Burk98d6d922017-07-06 11:52:45 -0700147 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700148
Phil Burkbcc36742017-08-31 17:24:51 -0700149 setState(AAUDIO_STREAM_STATE_CLOSED);
Phil Burk39f02dd2017-08-04 09:13:31 -0700150 return result;
Phil Burkc0c70e32017-02-09 13:18:38 -0800151}
152
Phil Burkbcc36742017-08-31 17:24:51 -0700153aaudio_result_t AAudioServiceStreamBase::startDevice() {
154 mClientHandle = AUDIO_PORT_HANDLE_NONE;
155 return mServiceEndpoint->startStream(this, &mClientHandle);
156}
157
Phil Burk39f02dd2017-08-04 09:13:31 -0700158/**
159 * Start the flow of audio data.
160 *
161 * An AAUDIO_SERVICE_EVENT_STARTED will be sent to the client when complete.
162 */
Phil Burkc0c70e32017-02-09 13:18:38 -0800163aaudio_result_t AAudioServiceStreamBase::start() {
Phil Burkbcc36742017-08-31 17:24:51 -0700164 aaudio_result_t result = AAUDIO_OK;
Eric Laurentcb4dae22017-07-01 19:39:32 -0700165 if (isRunning()) {
166 return AAUDIO_OK;
167 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700168
169 if (mServiceEndpoint == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700170 ALOGE("start() missing endpoint");
Phil Burkbcc36742017-08-31 17:24:51 -0700171 result = AAUDIO_ERROR_INVALID_STATE;
172 goto error;
Phil Burk39f02dd2017-08-04 09:13:31 -0700173 }
Phil Burkbcc36742017-08-31 17:24:51 -0700174
Phil Burk23296382017-11-20 15:45:11 -0800175 setFlowing(false);
176
Phil Burkbcc36742017-08-31 17:24:51 -0700177 // Start with fresh presentation timestamps.
178 mAtomicTimestamp.clear();
179
Phil Burk39f02dd2017-08-04 09:13:31 -0700180 mClientHandle = AUDIO_PORT_HANDLE_NONE;
Phil Burkbcc36742017-08-31 17:24:51 -0700181 result = startDevice();
182 if (result != AAUDIO_OK) goto error;
183
184 // This should happen at the end of the start.
185 sendServiceEvent(AAUDIO_SERVICE_EVENT_STARTED);
186 setState(AAUDIO_STREAM_STATE_STARTED);
187 mThreadEnabled.store(true);
188 result = mTimestampThread.start(this);
189 if (result != AAUDIO_OK) goto error;
190
191 return result;
192
193error:
194 disconnect();
Phil Burk39f02dd2017-08-04 09:13:31 -0700195 return result;
Phil Burkc0c70e32017-02-09 13:18:38 -0800196}
197
198aaudio_result_t AAudioServiceStreamBase::pause() {
Phil Burk11e8d332017-05-24 09:59:02 -0700199 aaudio_result_t result = AAUDIO_OK;
Eric Laurentcb4dae22017-07-01 19:39:32 -0700200 if (!isRunning()) {
201 return result;
Phil Burkc0c70e32017-02-09 13:18:38 -0800202 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700203 if (mServiceEndpoint == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700204 ALOGE("pause() missing endpoint");
Phil Burk39f02dd2017-08-04 09:13:31 -0700205 return AAUDIO_ERROR_INVALID_STATE;
206 }
Phil Burk73af62a2017-10-26 12:11:47 -0700207
208 // Send it now because the timestamp gets rounded up when stopStream() is called below.
209 // Also we don't need the timestamps while we are shutting down.
210 sendCurrentTimestamp();
211
212 result = stopTimestampThread();
213 if (result != AAUDIO_OK) {
214 disconnect();
215 return result;
216 }
217
Phil Burk39f02dd2017-08-04 09:13:31 -0700218 result = mServiceEndpoint->stopStream(this, mClientHandle);
219 if (result != AAUDIO_OK) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700220 ALOGE("pause() mServiceEndpoint returned %d", result);
Phil Burk39f02dd2017-08-04 09:13:31 -0700221 disconnect(); // TODO should we return or pause Base first?
222 }
223
Eric Laurentcb4dae22017-07-01 19:39:32 -0700224 sendServiceEvent(AAUDIO_SERVICE_EVENT_PAUSED);
Phil Burkbcc36742017-08-31 17:24:51 -0700225 setState(AAUDIO_STREAM_STATE_PAUSED);
Phil Burkc0c70e32017-02-09 13:18:38 -0800226 return result;
227}
228
Phil Burk71f35bb2017-04-13 16:05:07 -0700229aaudio_result_t AAudioServiceStreamBase::stop() {
Phil Burk11e8d332017-05-24 09:59:02 -0700230 aaudio_result_t result = AAUDIO_OK;
Eric Laurentcb4dae22017-07-01 19:39:32 -0700231 if (!isRunning()) {
232 return result;
Phil Burk71f35bb2017-04-13 16:05:07 -0700233 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700234
235 if (mServiceEndpoint == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700236 ALOGE("stop() missing endpoint");
Phil Burk39f02dd2017-08-04 09:13:31 -0700237 return AAUDIO_ERROR_INVALID_STATE;
238 }
239
Phil Burk83fb8442017-10-05 16:55:17 -0700240 setState(AAUDIO_STREAM_STATE_STOPPING);
241
Phil Burk73af62a2017-10-26 12:11:47 -0700242 // Send it now because the timestamp gets rounded up when stopStream() is called below.
243 // Also we don't need the timestamps while we are shutting down.
Eric Laurentcb4dae22017-07-01 19:39:32 -0700244 sendCurrentTimestamp(); // warning - this calls a virtual function
245 result = stopTimestampThread();
246 if (result != AAUDIO_OK) {
247 disconnect();
248 return result;
249 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700250
251 // TODO wait for data to be played out
252 result = mServiceEndpoint->stopStream(this, mClientHandle);
253 if (result != AAUDIO_OK) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700254 ALOGE("stop() mServiceEndpoint returned %d", result);
Phil Burk39f02dd2017-08-04 09:13:31 -0700255 disconnect();
256 // TODO what to do with result here?
257 }
258
Eric Laurentcb4dae22017-07-01 19:39:32 -0700259 sendServiceEvent(AAUDIO_SERVICE_EVENT_STOPPED);
Phil Burkbcc36742017-08-31 17:24:51 -0700260 setState(AAUDIO_STREAM_STATE_STOPPED);
Phil Burk71f35bb2017-04-13 16:05:07 -0700261 return result;
262}
263
Phil Burk98d6d922017-07-06 11:52:45 -0700264aaudio_result_t AAudioServiceStreamBase::stopTimestampThread() {
265 aaudio_result_t result = AAUDIO_OK;
266 // clear flag that tells thread to loop
267 if (mThreadEnabled.exchange(false)) {
Phil Burkbcc36742017-08-31 17:24:51 -0700268 result = mTimestampThread.stop();
Phil Burk98d6d922017-07-06 11:52:45 -0700269 }
270 return result;
271}
272
Phil Burk71f35bb2017-04-13 16:05:07 -0700273aaudio_result_t AAudioServiceStreamBase::flush() {
Phil Burkbcc36742017-08-31 17:24:51 -0700274 if (getState() != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700275 ALOGE("flush() stream not paused, state = %s",
Phil Burk39f02dd2017-08-04 09:13:31 -0700276 AAudio_convertStreamStateToText(mState));
277 return AAUDIO_ERROR_INVALID_STATE;
278 }
279 // Data will get flushed when the client receives the FLUSHED event.
Phil Burk71f35bb2017-04-13 16:05:07 -0700280 sendServiceEvent(AAUDIO_SERVICE_EVENT_FLUSHED);
Phil Burkbcc36742017-08-31 17:24:51 -0700281 setState(AAUDIO_STREAM_STATE_FLUSHED);
Phil Burk71f35bb2017-04-13 16:05:07 -0700282 return AAUDIO_OK;
283}
284
Phil Burkcf5f6d22017-05-26 12:35:07 -0700285// implement Runnable, periodically send timestamps to client
Phil Burkc0c70e32017-02-09 13:18:38 -0800286void AAudioServiceStreamBase::run() {
Phil Burkfbf031e2017-10-12 15:58:31 -0700287 ALOGD("run() entering ----------------");
Phil Burkc0c70e32017-02-09 13:18:38 -0800288 TimestampScheduler timestampScheduler;
Phil Burk39f02dd2017-08-04 09:13:31 -0700289 timestampScheduler.setBurstPeriod(mFramesPerBurst, getSampleRate());
Phil Burkc0c70e32017-02-09 13:18:38 -0800290 timestampScheduler.start(AudioClock::getNanoseconds());
291 int64_t nextTime = timestampScheduler.nextAbsoluteTime();
292 while(mThreadEnabled.load()) {
293 if (AudioClock::getNanoseconds() >= nextTime) {
294 aaudio_result_t result = sendCurrentTimestamp();
295 if (result != AAUDIO_OK) {
296 break;
297 }
298 nextTime = timestampScheduler.nextAbsoluteTime();
299 } else {
300 // Sleep until it is time to send the next timestamp.
Phil Burk98d6d922017-07-06 11:52:45 -0700301 // TODO Wait for a signal with a timeout so that we can stop more quickly.
Phil Burkc0c70e32017-02-09 13:18:38 -0800302 AudioClock::sleepUntilNanoTime(nextTime);
303 }
304 }
Phil Burkfbf031e2017-10-12 15:58:31 -0700305 ALOGD("run() exiting ----------------");
Phil Burkc0c70e32017-02-09 13:18:38 -0800306}
307
Phil Burk5ef003b2017-06-30 11:43:37 -0700308void AAudioServiceStreamBase::disconnect() {
Phil Burkbcc36742017-08-31 17:24:51 -0700309 if (getState() != AAUDIO_STREAM_STATE_DISCONNECTED) {
Phil Burk5ef003b2017-06-30 11:43:37 -0700310 sendServiceEvent(AAUDIO_SERVICE_EVENT_DISCONNECTED);
Phil Burkbcc36742017-08-31 17:24:51 -0700311 setState(AAUDIO_STREAM_STATE_DISCONNECTED);
Phil Burk5ef003b2017-06-30 11:43:37 -0700312 }
Phil Burkc0c70e32017-02-09 13:18:38 -0800313}
314
315aaudio_result_t AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event,
Phil Burk23296382017-11-20 15:45:11 -0800316 double dataDouble) {
Phil Burk5ed503c2017-02-01 09:38:15 -0800317 AAudioServiceMessage command;
318 command.what = AAudioServiceMessage::code::EVENT;
Phil Burk2355edb2016-12-26 13:54:02 -0800319 command.event.event = event;
Phil Burkc0c70e32017-02-09 13:18:38 -0800320 command.event.dataDouble = dataDouble;
Phil Burk23296382017-11-20 15:45:11 -0800321 return writeUpMessageQueue(&command);
322}
323
324aaudio_result_t AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event,
325 int64_t dataLong) {
326 AAudioServiceMessage command;
327 command.what = AAudioServiceMessage::code::EVENT;
328 command.event.event = event;
Phil Burkc0c70e32017-02-09 13:18:38 -0800329 command.event.dataLong = dataLong;
330 return writeUpMessageQueue(&command);
331}
332
333aaudio_result_t AAudioServiceStreamBase::writeUpMessageQueue(AAudioServiceMessage *command) {
Phil Burk39f02dd2017-08-04 09:13:31 -0700334 std::lock_guard<std::mutex> lock(mUpMessageQueueLock);
Phil Burk71f35bb2017-04-13 16:05:07 -0700335 if (mUpMessageQueue == nullptr) {
336 ALOGE("writeUpMessageQueue(): mUpMessageQueue null! - stream not open");
337 return AAUDIO_ERROR_NULL;
338 }
Phil Burkc0c70e32017-02-09 13:18:38 -0800339 int32_t count = mUpMessageQueue->getFifoBuffer()->write(command, 1);
340 if (count != 1) {
341 ALOGE("writeUpMessageQueue(): Queue full. Did client die?");
342 return AAUDIO_ERROR_WOULD_BLOCK;
343 } else {
344 return AAUDIO_OK;
345 }
346}
347
Phil Burk23296382017-11-20 15:45:11 -0800348aaudio_result_t AAudioServiceStreamBase::sendXRunCount(int32_t xRunCount) {
349 return sendServiceEvent(AAUDIO_SERVICE_EVENT_XRUN, (int64_t) xRunCount);
350}
351
Phil Burkc0c70e32017-02-09 13:18:38 -0800352aaudio_result_t AAudioServiceStreamBase::sendCurrentTimestamp() {
353 AAudioServiceMessage command;
Phil Burk97350f92017-07-21 15:59:44 -0700354 // Send a timestamp for the clock model.
Phil Burkc0c70e32017-02-09 13:18:38 -0800355 aaudio_result_t result = getFreeRunningPosition(&command.timestamp.position,
356 &command.timestamp.timestamp);
357 if (result == AAUDIO_OK) {
Phil Burkbcc36742017-08-31 17:24:51 -0700358 ALOGV("sendCurrentTimestamp() SERVICE %8lld at %lld",
359 (long long) command.timestamp.position,
360 (long long) command.timestamp.timestamp);
Phil Burk97350f92017-07-21 15:59:44 -0700361 command.what = AAudioServiceMessage::code::TIMESTAMP_SERVICE;
Phil Burkc0c70e32017-02-09 13:18:38 -0800362 result = writeUpMessageQueue(&command);
Phil Burk97350f92017-07-21 15:59:44 -0700363
364 if (result == AAUDIO_OK) {
365 // Send a hardware timestamp for presentation time.
366 result = getHardwareTimestamp(&command.timestamp.position,
367 &command.timestamp.timestamp);
368 if (result == AAUDIO_OK) {
Phil Burkbcc36742017-08-31 17:24:51 -0700369 ALOGV("sendCurrentTimestamp() HARDWARE %8lld at %lld",
370 (long long) command.timestamp.position,
371 (long long) command.timestamp.timestamp);
Phil Burk97350f92017-07-21 15:59:44 -0700372 command.what = AAudioServiceMessage::code::TIMESTAMP_HARDWARE;
373 result = writeUpMessageQueue(&command);
374 }
375 }
376 }
377
Phil Burkbcc36742017-08-31 17:24:51 -0700378 if (result == AAUDIO_ERROR_UNAVAILABLE) { // TODO review best error code
Phil Burk940083c2017-07-17 17:00:02 -0700379 result = AAUDIO_OK; // just not available yet, try again later
Phil Burkc0c70e32017-02-09 13:18:38 -0800380 }
381 return result;
Phil Burk2355edb2016-12-26 13:54:02 -0800382}
383
Phil Burkc0c70e32017-02-09 13:18:38 -0800384/**
385 * Get an immutable description of the in-memory queues
386 * used to communicate with the underlying HAL or Service.
387 */
388aaudio_result_t AAudioServiceStreamBase::getDescription(AudioEndpointParcelable &parcelable) {
Phil Burk523b3042017-09-13 13:03:08 -0700389 {
390 std::lock_guard<std::mutex> lock(mUpMessageQueueLock);
391 if (mUpMessageQueue == nullptr) {
392 ALOGE("getDescription(): mUpMessageQueue null! - stream not open");
393 return AAUDIO_ERROR_NULL;
394 }
395 // Gather information on the message queue.
396 mUpMessageQueue->fillParcelable(parcelable,
397 parcelable.mUpMessageQueueParcelable);
398 }
399 return getAudioDataDescription(parcelable);
Phil Burk11e8d332017-05-24 09:59:02 -0700400}
Phil Burk39f02dd2017-08-04 09:13:31 -0700401
402void AAudioServiceStreamBase::onVolumeChanged(float volume) {
403 sendServiceEvent(AAUDIO_SERVICE_EVENT_VOLUME, volume);
404}