Phil Burk | 5ed503c | 2017-02-01 09:38:15 -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 | |
| 17 | #define LOG_TAG "AAudioService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 21 | #include <sstream> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 22 | //#include <time.h> |
| 23 | //#include <pthread.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 24 | |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 25 | #include <aaudio/AAudio.h> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 26 | #include <mediautils/SchedulingPolicyService.h> |
| 27 | #include <utils/String16.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 28 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 29 | #include "binding/AAudioServiceMessage.h" |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 30 | #include "AAudioClientTracker.h" |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 31 | #include "AAudioEndpointManager.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 32 | #include "AAudioService.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 33 | #include "AAudioServiceStreamMMAP.h" |
| 34 | #include "AAudioServiceStreamShared.h" |
| 35 | #include "AAudioServiceStreamMMAP.h" |
| 36 | #include "binding/IAAudioService.h" |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 37 | #include "ServiceUtilities.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 38 | #include "utility/HandleTracker.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 39 | |
| 40 | using namespace android; |
| 41 | using namespace aaudio; |
| 42 | |
Phil Burk | 9169294 | 2017-06-30 12:23:05 -0700 | [diff] [blame^] | 43 | #define MAX_STREAMS_PER_PROCESS 8 |
| 44 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 45 | typedef enum |
| 46 | { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 47 | AAUDIO_HANDLE_TYPE_STREAM |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 48 | } aaudio_service_handle_type_t; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 49 | static_assert(AAUDIO_HANDLE_TYPE_STREAM < HANDLE_TRACKER_MAX_TYPES, "Too many handle types."); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 50 | |
| 51 | android::AAudioService::AAudioService() |
| 52 | : BnAAudioService() { |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 53 | mCachedProcessId = getpid(); |
| 54 | mCachedUserId = getuid(); // TODO consider using geteuid() |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 55 | AAudioClientTracker::getInstance().setAAudioService(this); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | AAudioService::~AAudioService() { |
| 59 | } |
| 60 | |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 61 | status_t AAudioService::dump(int fd, const Vector<String16>& args) { |
| 62 | std::string result; |
| 63 | |
| 64 | if (!dumpAllowed()) { |
| 65 | std::stringstream ss; |
| 66 | ss << "Permission denial: can't dump AAudioService from pid=" |
| 67 | << IPCThreadState::self()->getCallingPid() << ", uid=" |
| 68 | << IPCThreadState::self()->getCallingUid() << "\n"; |
| 69 | result = ss.str(); |
| 70 | ALOGW("%s", result.c_str()); |
| 71 | } else { |
| 72 | result = mHandleTracker.dump() + AAudioEndpointManager::getInstance().dump(); |
| 73 | } |
| 74 | (void)write(fd, result.c_str(), result.size()); |
| 75 | return NO_ERROR; |
| 76 | } |
| 77 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 78 | void AAudioService::registerClient(const sp<IAAudioClient>& client) { |
| 79 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 80 | AAudioClientTracker::getInstance().registerClient(pid, client); |
| 81 | } |
| 82 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 83 | aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &request, |
| 84 | aaudio::AAudioStreamConfiguration &configurationOutput) { |
| 85 | aaudio_result_t result = AAUDIO_OK; |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 86 | sp<AAudioServiceStreamBase> serviceStream; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 87 | const AAudioStreamConfiguration &configurationInput = request.getConstantConfiguration(); |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 88 | bool sharingModeMatchRequired = request.isSharingModeMatchRequired(); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 89 | aaudio_sharing_mode_t sharingMode = configurationInput.getSharingMode(); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 90 | |
Phil Burk | 9169294 | 2017-06-30 12:23:05 -0700 | [diff] [blame^] | 91 | // Enforce limit on client processes. |
| 92 | pid_t pid = request.getProcessId(); |
| 93 | if (pid != mCachedProcessId) { |
| 94 | int32_t count = AAudioClientTracker::getInstance().getStreamCount(pid); |
| 95 | if (count >= MAX_STREAMS_PER_PROCESS) { |
| 96 | ALOGE("AAudioService::openStream(): exceeded max streams per process %d >= %d", |
| 97 | count, MAX_STREAMS_PER_PROCESS); |
| 98 | return AAUDIO_ERROR_UNAVAILABLE; |
| 99 | } |
| 100 | } |
| 101 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 102 | if (sharingMode != AAUDIO_SHARING_MODE_EXCLUSIVE && sharingMode != AAUDIO_SHARING_MODE_SHARED) { |
| 103 | ALOGE("AAudioService::openStream(): unrecognized sharing mode = %d", sharingMode); |
| 104 | return AAUDIO_ERROR_ILLEGAL_ARGUMENT; |
| 105 | } |
| 106 | |
| 107 | if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 108 | serviceStream = new AAudioServiceStreamMMAP(); |
| 109 | result = serviceStream->open(request, configurationOutput); |
| 110 | if (result != AAUDIO_OK) { |
| 111 | // fall back to using a shared stream |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 112 | ALOGW("AAudioService::openStream(), could not open in EXCLUSIVE mode"); |
| 113 | serviceStream.clear(); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 114 | } else { |
| 115 | configurationOutput.setSharingMode(AAUDIO_SHARING_MODE_EXCLUSIVE); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // if SHARED requested or if EXCLUSIVE failed |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 120 | if (sharingMode == AAUDIO_SHARING_MODE_SHARED |
| 121 | || (serviceStream == nullptr && !sharingModeMatchRequired)) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 122 | serviceStream = new AAudioServiceStreamShared(*this); |
| 123 | result = serviceStream->open(request, configurationOutput); |
| 124 | configurationOutput.setSharingMode(AAUDIO_SHARING_MODE_SHARED); |
| 125 | } |
| 126 | |
| 127 | if (result != AAUDIO_OK) { |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 128 | serviceStream.clear(); |
| 129 | ALOGE("AAudioService::openStream(): failed, return %d = %s", |
| 130 | result, AAudio_convertResultToText(result)); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 131 | return result; |
| 132 | } else { |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 133 | const uid_t ownerUserId = request.getUserId(); // only set by service, not by client |
| 134 | serviceStream->setOwnerUserId(ownerUserId); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 135 | aaudio_handle_t handle = mHandleTracker.put(AAUDIO_HANDLE_TYPE_STREAM, serviceStream.get()); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 136 | if (handle < 0) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 137 | ALOGE("AAudioService::openStream(): handle table full"); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 138 | serviceStream.clear(); |
| 139 | } else { |
| 140 | ALOGD("AAudioService::openStream(): handle = 0x%08X", handle); |
| 141 | serviceStream->setHandle(handle); |
| 142 | pid_t pid = request.getProcessId(); |
Phil Burk | b63320a | 2017-06-30 10:28:20 -0700 | [diff] [blame] | 143 | serviceStream->setOwnerProcessId(pid); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 144 | AAudioClientTracker::getInstance().registerClientStream(pid, serviceStream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 145 | } |
| 146 | return handle; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) { |
Phil Burk | 9169294 | 2017-06-30 12:23:05 -0700 | [diff] [blame^] | 151 | // Check permission first. |
| 152 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
| 153 | if (serviceStream == nullptr) { |
| 154 | ALOGE("AAudioService::startStream(), illegal stream handle = 0x%0x", streamHandle); |
| 155 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 156 | } |
| 157 | |
| 158 | serviceStream = (AAudioServiceStreamBase *) |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 159 | mHandleTracker.remove(AAUDIO_HANDLE_TYPE_STREAM, |
| 160 | streamHandle); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 161 | ALOGD("AAudioService.closeStream(0x%08X)", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 162 | if (serviceStream != nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 163 | serviceStream->close(); |
Phil Burk | b63320a | 2017-06-30 10:28:20 -0700 | [diff] [blame] | 164 | pid_t pid = serviceStream->getOwnerProcessId(); |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 165 | AAudioClientTracker::getInstance().unregisterClientStream(pid, serviceStream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 166 | return AAUDIO_OK; |
| 167 | } |
| 168 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 169 | } |
| 170 | |
| 171 | AAudioServiceStreamBase *AAudioService::convertHandleToServiceStream( |
| 172 | aaudio_handle_t streamHandle) const { |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 173 | AAudioServiceStreamBase *serviceStream = (AAudioServiceStreamBase *) |
| 174 | mHandleTracker.get(AAUDIO_HANDLE_TYPE_STREAM, (aaudio_handle_t)streamHandle); |
| 175 | if (serviceStream != nullptr) { |
| 176 | // Only allow owner or the aaudio service to access the stream. |
| 177 | const uid_t callingUserId = IPCThreadState::self()->getCallingUid(); |
| 178 | const uid_t ownerUserId = serviceStream->getOwnerUserId(); |
| 179 | bool callerOwnsIt = callingUserId == ownerUserId; |
| 180 | bool serverCalling = callingUserId == mCachedUserId; |
| 181 | bool serverOwnsIt = ownerUserId == mCachedUserId; |
| 182 | bool allowed = callerOwnsIt || serverCalling || serverOwnsIt; |
| 183 | if (!allowed) { |
| 184 | ALOGE("AAudioService: calling uid %d cannot access stream 0x%08X owned by %d", |
| 185 | callingUserId, streamHandle, ownerUserId); |
| 186 | serviceStream = nullptr; |
| 187 | } |
| 188 | } |
| 189 | return serviceStream; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | aaudio_result_t AAudioService::getStreamDescription( |
| 193 | aaudio_handle_t streamHandle, |
| 194 | aaudio::AudioEndpointParcelable &parcelable) { |
| 195 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 196 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 197 | ALOGE("AAudioService::getStreamDescription(), illegal stream handle = 0x%0x", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 198 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 199 | } |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 200 | aaudio_result_t result = serviceStream->getDescription(parcelable); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 201 | // parcelable.dump(); |
| 202 | return result; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | aaudio_result_t AAudioService::startStream(aaudio_handle_t streamHandle) { |
| 206 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 207 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 208 | ALOGE("AAudioService::startStream(), illegal stream handle = 0x%0x", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 209 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 210 | } |
| 211 | aaudio_result_t result = serviceStream->start(); |
| 212 | return result; |
| 213 | } |
| 214 | |
| 215 | aaudio_result_t AAudioService::pauseStream(aaudio_handle_t streamHandle) { |
| 216 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 217 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 218 | ALOGE("AAudioService::pauseStream(), illegal stream handle = 0x%0x", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 219 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 220 | } |
| 221 | aaudio_result_t result = serviceStream->pause(); |
| 222 | return result; |
| 223 | } |
| 224 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 225 | aaudio_result_t AAudioService::stopStream(aaudio_handle_t streamHandle) { |
| 226 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
| 227 | if (serviceStream == nullptr) { |
| 228 | ALOGE("AAudioService::pauseStream(), illegal stream handle = 0x%0x", streamHandle); |
| 229 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 230 | } |
| 231 | aaudio_result_t result = serviceStream->stop(); |
| 232 | return result; |
| 233 | } |
| 234 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 235 | aaudio_result_t AAudioService::flushStream(aaudio_handle_t streamHandle) { |
| 236 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 237 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 238 | ALOGE("AAudioService::flushStream(), illegal stream handle = 0x%0x", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 239 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 240 | } |
| 241 | return serviceStream->flush(); |
| 242 | } |
| 243 | |
| 244 | aaudio_result_t AAudioService::registerAudioThread(aaudio_handle_t streamHandle, |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 245 | pid_t clientThreadId, |
| 246 | int64_t periodNanoseconds) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 247 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 248 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 249 | ALOGE("AAudioService::registerAudioThread(), illegal stream handle = 0x%0x", streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 250 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 251 | } |
| 252 | if (serviceStream->getRegisteredThread() != AAudioServiceStreamBase::ILLEGAL_THREAD_ID) { |
| 253 | ALOGE("AAudioService::registerAudioThread(), thread already registered"); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 254 | return AAUDIO_ERROR_INVALID_STATE; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 255 | } |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 256 | |
| 257 | const pid_t ownerPid = IPCThreadState::self()->getCallingPid(); // TODO review |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 258 | serviceStream->setRegisteredThread(clientThreadId); |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 259 | int err = android::requestPriority(ownerPid, clientThreadId, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 260 | DEFAULT_AUDIO_PRIORITY, true /* isForApp */); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 261 | if (err != 0){ |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 262 | ALOGE("AAudioService::registerAudioThread(%d) failed, errno = %d, priority = %d", |
| 263 | clientThreadId, errno, DEFAULT_AUDIO_PRIORITY); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 264 | return AAUDIO_ERROR_INTERNAL; |
| 265 | } else { |
| 266 | return AAUDIO_OK; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | aaudio_result_t AAudioService::unregisterAudioThread(aaudio_handle_t streamHandle, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 271 | pid_t clientThreadId) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 272 | AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 273 | if (serviceStream == nullptr) { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 274 | ALOGE("AAudioService::unregisterAudioThread(), illegal stream handle = 0x%0x", |
| 275 | streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 276 | return AAUDIO_ERROR_INVALID_HANDLE; |
| 277 | } |
| 278 | if (serviceStream->getRegisteredThread() != clientThreadId) { |
| 279 | ALOGE("AAudioService::unregisterAudioThread(), wrong thread"); |
| 280 | return AAUDIO_ERROR_ILLEGAL_ARGUMENT; |
| 281 | } |
| 282 | serviceStream->setRegisteredThread(0); |
| 283 | return AAUDIO_OK; |
| 284 | } |