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