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