blob: 53ee14513eea08169035794620382343fa88d0da [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -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
17#define LOG_TAG "AAudioService"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burk523b3042017-09-13 13:03:08 -070021#include <iomanip>
22#include <iostream>
Andy Hung47c5e532017-06-26 18:28:00 -070023#include <sstream>
Phil Burk5ed503c2017-02-01 09:38:15 -080024
Phil Burka4eb0d82017-04-12 15:44:06 -070025#include <aaudio/AAudio.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080026#include <mediautils/SchedulingPolicyService.h>
Andy Hungab7ef302018-05-15 19:35:29 -070027#include <mediautils/ServiceUtilities.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080028#include <utils/String16.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080029
Phil Burkc0c70e32017-02-09 13:18:38 -080030#include "binding/AAudioServiceMessage.h"
Phil Burk11e8d332017-05-24 09:59:02 -070031#include "AAudioClientTracker.h"
Andy Hung47c5e532017-06-26 18:28:00 -070032#include "AAudioEndpointManager.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080033#include "AAudioService.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080034#include "AAudioServiceStreamMMAP.h"
35#include "AAudioServiceStreamShared.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080036#include "binding/IAAudioService.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080037
38using namespace android;
39using namespace aaudio;
40
Phil Burk91692942017-06-30 12:23:05 -070041#define MAX_STREAMS_PER_PROCESS 8
42
Phil Burk523b3042017-09-13 13:03:08 -070043using android::AAudioService;
Phil Burk5ed503c2017-02-01 09:38:15 -080044
45android::AAudioService::AAudioService()
46 : BnAAudioService() {
Eric Laurenta54f1282017-07-01 19:39:32 -070047 mAudioClient.clientUid = getuid(); // TODO consider using geteuid()
48 mAudioClient.clientPid = getpid();
49 mAudioClient.packageName = String16("");
Phil Burk11e8d332017-05-24 09:59:02 -070050 AAudioClientTracker::getInstance().setAAudioService(this);
Phil Burk5ed503c2017-02-01 09:38:15 -080051}
52
53AAudioService::~AAudioService() {
54}
55
Andy Hung47c5e532017-06-26 18:28:00 -070056status_t AAudioService::dump(int fd, const Vector<String16>& args) {
57 std::string result;
58
59 if (!dumpAllowed()) {
60 std::stringstream ss;
61 ss << "Permission denial: can't dump AAudioService from pid="
62 << IPCThreadState::self()->getCallingPid() << ", uid="
63 << IPCThreadState::self()->getCallingUid() << "\n";
64 result = ss.str();
65 ALOGW("%s", result.c_str());
66 } else {
Phil Burk523b3042017-09-13 13:03:08 -070067 result = "------------ AAudio Service ------------\n"
68 + mStreamTracker.dump()
Phil Burk4501b352017-06-29 18:12:36 -070069 + AAudioClientTracker::getInstance().dump()
70 + AAudioEndpointManager::getInstance().dump();
Andy Hung47c5e532017-06-26 18:28:00 -070071 }
72 (void)write(fd, result.c_str(), result.size());
73 return NO_ERROR;
74}
75
Phil Burk11e8d332017-05-24 09:59:02 -070076void AAudioService::registerClient(const sp<IAAudioClient>& client) {
77 pid_t pid = IPCThreadState::self()->getCallingPid();
78 AAudioClientTracker::getInstance().registerClient(pid, client);
79}
80
Phil Burkc0c70e32017-02-09 13:18:38 -080081aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &request,
82 aaudio::AAudioStreamConfiguration &configurationOutput) {
83 aaudio_result_t result = AAUDIO_OK;
Phil Burk11e8d332017-05-24 09:59:02 -070084 sp<AAudioServiceStreamBase> serviceStream;
Phil Burkc0c70e32017-02-09 13:18:38 -080085 const AAudioStreamConfiguration &configurationInput = request.getConstantConfiguration();
Phil Burk71f35bb2017-04-13 16:05:07 -070086 bool sharingModeMatchRequired = request.isSharingModeMatchRequired();
Phil Burkc0c70e32017-02-09 13:18:38 -080087 aaudio_sharing_mode_t sharingMode = configurationInput.getSharingMode();
Phil Burkc0c70e32017-02-09 13:18:38 -080088
Phil Burk91692942017-06-30 12:23:05 -070089 // Enforce limit on client processes.
90 pid_t pid = request.getProcessId();
Eric Laurenta54f1282017-07-01 19:39:32 -070091 if (pid != mAudioClient.clientPid) {
Phil Burk91692942017-06-30 12:23:05 -070092 int32_t count = AAudioClientTracker::getInstance().getStreamCount(pid);
93 if (count >= MAX_STREAMS_PER_PROCESS) {
Phil Burkfbf031e2017-10-12 15:58:31 -070094 ALOGE("openStream(): exceeded max streams per process %d >= %d",
Phil Burk91692942017-06-30 12:23:05 -070095 count, MAX_STREAMS_PER_PROCESS);
96 return AAUDIO_ERROR_UNAVAILABLE;
97 }
98 }
99
Phil Burkc0c70e32017-02-09 13:18:38 -0800100 if (sharingMode != AAUDIO_SHARING_MODE_EXCLUSIVE && sharingMode != AAUDIO_SHARING_MODE_SHARED) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700101 ALOGE("openStream(): unrecognized sharing mode = %d", sharingMode);
Phil Burkc0c70e32017-02-09 13:18:38 -0800102 return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
103 }
104
105 if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) {
Eric Laurenta54f1282017-07-01 19:39:32 -0700106 // only trust audioserver for in service indication
107 bool inService = false;
108 if (mAudioClient.clientPid == IPCThreadState::self()->getCallingPid() &&
109 mAudioClient.clientUid == IPCThreadState::self()->getCallingUid()) {
110 inService = request.isInService();
111 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700112 serviceStream = new AAudioServiceStreamMMAP(*this, inService);
113 result = serviceStream->open(request);
Phil Burkc0c70e32017-02-09 13:18:38 -0800114 if (result != AAUDIO_OK) {
Phil Burk39f02dd2017-08-04 09:13:31 -0700115 // Clear it so we can possibly fall back to using a shared stream.
Phil Burkfbf031e2017-10-12 15:58:31 -0700116 ALOGW("openStream(), could not open in EXCLUSIVE mode");
Phil Burk11e8d332017-05-24 09:59:02 -0700117 serviceStream.clear();
Phil Burkc0c70e32017-02-09 13:18:38 -0800118 }
119 }
120
Phil Burk15f97c92018-09-04 14:06:27 -0700121 // If SHARED requested or if EXCLUSIVE failed.
122 if (sharingMode == AAUDIO_SHARING_MODE_SHARED) {
Phil Burkc0c70e32017-02-09 13:18:38 -0800123 serviceStream = new AAudioServiceStreamShared(*this);
Phil Burk39f02dd2017-08-04 09:13:31 -0700124 result = serviceStream->open(request);
Phil Burk15f97c92018-09-04 14:06:27 -0700125 } else if (serviceStream.get() == nullptr && !sharingModeMatchRequired) {
126 aaudio::AAudioStreamRequest modifiedRequest = request;
127 // Overwrite the original EXCLUSIVE mode with SHARED.
128 modifiedRequest.getConfiguration().setSharingMode(AAUDIO_SHARING_MODE_SHARED);
129 serviceStream = new AAudioServiceStreamShared(*this);
130 result = serviceStream->open(modifiedRequest);
Phil Burkc0c70e32017-02-09 13:18:38 -0800131 }
132
133 if (result != AAUDIO_OK) {
Phil Burk11e8d332017-05-24 09:59:02 -0700134 serviceStream.clear();
Phil Burkfbf031e2017-10-12 15:58:31 -0700135 ALOGE("openStream(): failed, return %d = %s",
Phil Burk11e8d332017-05-24 09:59:02 -0700136 result, AAudio_convertResultToText(result));
Phil Burk5ed503c2017-02-01 09:38:15 -0800137 return result;
138 } else {
Phil Burk523b3042017-09-13 13:03:08 -0700139 aaudio_handle_t handle = mStreamTracker.addStreamForHandle(serviceStream.get());
Phil Burkfbf031e2017-10-12 15:58:31 -0700140 ALOGD("openStream(): handle = 0x%08X", handle);
Phil Burk523b3042017-09-13 13:03:08 -0700141 serviceStream->setHandle(handle);
142 pid_t pid = request.getProcessId();
143 AAudioClientTracker::getInstance().registerClientStream(pid, serviceStream);
144 configurationOutput.copyFrom(*serviceStream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800145 return handle;
146 }
147}
148
Phil Burk94862522017-09-13 21:31:36 -0700149// If a close request is pending then close the stream
150bool AAudioService::releaseStream(const sp<AAudioServiceStreamBase> &serviceStream) {
151 bool closed = false;
Phil Burk2fe718b2018-05-14 12:28:32 -0700152 // decrementAndRemoveStreamByHandle() uses a lock so that if there are two simultaneous closes
153 // then only one will get the pointer and do the close.
154 sp<AAudioServiceStreamBase> foundStream = mStreamTracker.decrementAndRemoveStreamByHandle(
155 serviceStream->getHandle());
156 if (foundStream.get() != nullptr) {
157 foundStream->close();
158 pid_t pid = foundStream->getOwnerProcessId();
159 AAudioClientTracker::getInstance().unregisterClientStream(pid, foundStream);
Phil Burk94862522017-09-13 21:31:36 -0700160 closed = true;
161 }
162 return closed;
163}
164
165aaudio_result_t AAudioService::checkForPendingClose(
166 const sp<AAudioServiceStreamBase> &serviceStream,
167 aaudio_result_t defaultResult) {
168 return releaseStream(serviceStream) ? AAUDIO_ERROR_INVALID_STATE : defaultResult;
169}
170
Phil Burk5ed503c2017-02-01 09:38:15 -0800171aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) {
Phil Burk98d6d922017-07-06 11:52:45 -0700172 // Check permission and ownership first.
173 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
Phil Burk523b3042017-09-13 13:03:08 -0700174 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700175 ALOGE("closeStream(0x%0x), illegal stream handle", streamHandle);
Phil Burk91692942017-06-30 12:23:05 -0700176 return AAUDIO_ERROR_INVALID_HANDLE;
177 }
178
Phil Burk94862522017-09-13 21:31:36 -0700179 pid_t pid = serviceStream->getOwnerProcessId();
180 AAudioClientTracker::getInstance().unregisterClientStream(pid, serviceStream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800181
Phil Burk2fe718b2018-05-14 12:28:32 -0700182 serviceStream->markCloseNeeded();
Phil Burk94862522017-09-13 21:31:36 -0700183 (void) releaseStream(serviceStream);
184 return AAUDIO_OK;
185}
Phil Burk523b3042017-09-13 13:03:08 -0700186
187sp<AAudioServiceStreamBase> AAudioService::convertHandleToServiceStream(
188 aaudio_handle_t streamHandle) {
Phil Burk2fe718b2018-05-14 12:28:32 -0700189 sp<AAudioServiceStreamBase> serviceStream = mStreamTracker.getStreamByHandleAndIncrement(
190 streamHandle);
Phil Burk523b3042017-09-13 13:03:08 -0700191 if (serviceStream.get() != nullptr) {
Phil Burk2ac035f2017-06-23 14:51:14 -0700192 // Only allow owner or the aaudio service to access the stream.
193 const uid_t callingUserId = IPCThreadState::self()->getCallingUid();
194 const uid_t ownerUserId = serviceStream->getOwnerUserId();
195 bool callerOwnsIt = callingUserId == ownerUserId;
Eric Laurenta54f1282017-07-01 19:39:32 -0700196 bool serverCalling = callingUserId == mAudioClient.clientUid;
197 bool serverOwnsIt = ownerUserId == mAudioClient.clientUid;
Phil Burk2ac035f2017-06-23 14:51:14 -0700198 bool allowed = callerOwnsIt || serverCalling || serverOwnsIt;
199 if (!allowed) {
200 ALOGE("AAudioService: calling uid %d cannot access stream 0x%08X owned by %d",
201 callingUserId, streamHandle, ownerUserId);
Phil Burk2fe718b2018-05-14 12:28:32 -0700202 // We incremented the reference count so we must check if it needs to be closed.
203 checkForPendingClose(serviceStream, AAUDIO_OK);
Phil Burk94862522017-09-13 21:31:36 -0700204 serviceStream.clear();
Phil Burk2ac035f2017-06-23 14:51:14 -0700205 }
206 }
207 return serviceStream;
Phil Burk5ed503c2017-02-01 09:38:15 -0800208}
209
210aaudio_result_t AAudioService::getStreamDescription(
211 aaudio_handle_t streamHandle,
212 aaudio::AudioEndpointParcelable &parcelable) {
Phil Burk523b3042017-09-13 13:03:08 -0700213 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
214 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700215 ALOGE("getStreamDescription(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800216 return AAUDIO_ERROR_INVALID_HANDLE;
217 }
Phil Burk523b3042017-09-13 13:03:08 -0700218
Phil Burkc0c70e32017-02-09 13:18:38 -0800219 aaudio_result_t result = serviceStream->getDescription(parcelable);
Phil Burkc0c70e32017-02-09 13:18:38 -0800220 // parcelable.dump();
Phil Burk94862522017-09-13 21:31:36 -0700221 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800222}
223
224aaudio_result_t AAudioService::startStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700225 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
226 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700227 ALOGE("startStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800228 return AAUDIO_ERROR_INVALID_HANDLE;
229 }
Eric Laurenta54f1282017-07-01 19:39:32 -0700230
Phil Burk94862522017-09-13 21:31:36 -0700231 aaudio_result_t result = serviceStream->start();
232 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800233}
234
235aaudio_result_t AAudioService::pauseStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700236 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
237 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700238 ALOGE("pauseStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800239 return AAUDIO_ERROR_INVALID_HANDLE;
240 }
241 aaudio_result_t result = serviceStream->pause();
Phil Burk94862522017-09-13 21:31:36 -0700242 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800243}
244
Phil Burk71f35bb2017-04-13 16:05:07 -0700245aaudio_result_t AAudioService::stopStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700246 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
247 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700248 ALOGE("stopStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk71f35bb2017-04-13 16:05:07 -0700249 return AAUDIO_ERROR_INVALID_HANDLE;
250 }
251 aaudio_result_t result = serviceStream->stop();
Phil Burk94862522017-09-13 21:31:36 -0700252 return checkForPendingClose(serviceStream, result);
Phil Burk71f35bb2017-04-13 16:05:07 -0700253}
254
Phil Burk5ed503c2017-02-01 09:38:15 -0800255aaudio_result_t AAudioService::flushStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700256 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
257 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700258 ALOGE("flushStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800259 return AAUDIO_ERROR_INVALID_HANDLE;
260 }
Phil Burk94862522017-09-13 21:31:36 -0700261 aaudio_result_t result = serviceStream->flush();
262 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800263}
264
265aaudio_result_t AAudioService::registerAudioThread(aaudio_handle_t streamHandle,
Phil Burk11e8d332017-05-24 09:59:02 -0700266 pid_t clientThreadId,
267 int64_t periodNanoseconds) {
Phil Burk94862522017-09-13 21:31:36 -0700268 aaudio_result_t result = AAUDIO_OK;
Phil Burk523b3042017-09-13 13:03:08 -0700269 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
270 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700271 ALOGE("registerAudioThread(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800272 return AAUDIO_ERROR_INVALID_HANDLE;
273 }
274 if (serviceStream->getRegisteredThread() != AAudioServiceStreamBase::ILLEGAL_THREAD_ID) {
Phil Burk94862522017-09-13 21:31:36 -0700275 ALOGE("AAudioService::registerAudioThread(), thread already registered");
276 result = AAUDIO_ERROR_INVALID_STATE;
Phil Burk5ed503c2017-02-01 09:38:15 -0800277 } else {
Phil Burk94862522017-09-13 21:31:36 -0700278 const pid_t ownerPid = IPCThreadState::self()->getCallingPid(); // TODO review
279 serviceStream->setRegisteredThread(clientThreadId);
280 int err = android::requestPriority(ownerPid, clientThreadId,
281 DEFAULT_AUDIO_PRIORITY, true /* isForApp */);
282 if (err != 0) {
283 ALOGE("AAudioService::registerAudioThread(%d) failed, errno = %d, priority = %d",
284 clientThreadId, errno, DEFAULT_AUDIO_PRIORITY);
285 result = AAUDIO_ERROR_INTERNAL;
286 }
Phil Burk5ed503c2017-02-01 09:38:15 -0800287 }
Phil Burk94862522017-09-13 21:31:36 -0700288 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800289}
290
291aaudio_result_t AAudioService::unregisterAudioThread(aaudio_handle_t streamHandle,
Phil Burkc0c70e32017-02-09 13:18:38 -0800292 pid_t clientThreadId) {
Phil Burk94862522017-09-13 21:31:36 -0700293 aaudio_result_t result = AAUDIO_OK;
Phil Burk523b3042017-09-13 13:03:08 -0700294 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
295 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700296 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800297 return AAUDIO_ERROR_INVALID_HANDLE;
298 }
299 if (serviceStream->getRegisteredThread() != clientThreadId) {
Phil Burkbbd52862018-04-13 11:37:42 -0700300 ALOGE("%s(), wrong thread", __func__);
Phil Burk94862522017-09-13 21:31:36 -0700301 result = AAUDIO_ERROR_ILLEGAL_ARGUMENT;
302 } else {
303 serviceStream->setRegisteredThread(0);
Phil Burk5ed503c2017-02-01 09:38:15 -0800304 }
Phil Burk94862522017-09-13 21:31:36 -0700305 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800306}
Eric Laurenta54f1282017-07-01 19:39:32 -0700307
308aaudio_result_t AAudioService::startClient(aaudio_handle_t streamHandle,
309 const android::AudioClient& client,
310 audio_port_handle_t *clientHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700311 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
312 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700313 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Eric Laurenta54f1282017-07-01 19:39:32 -0700314 return AAUDIO_ERROR_INVALID_HANDLE;
315 }
Phil Burk94862522017-09-13 21:31:36 -0700316 aaudio_result_t result = serviceStream->startClient(client, clientHandle);
317 return checkForPendingClose(serviceStream, result);
Eric Laurenta54f1282017-07-01 19:39:32 -0700318}
319
320aaudio_result_t AAudioService::stopClient(aaudio_handle_t streamHandle,
Phil Burkbbd52862018-04-13 11:37:42 -0700321 audio_port_handle_t portHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700322 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
323 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700324 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Eric Laurenta54f1282017-07-01 19:39:32 -0700325 return AAUDIO_ERROR_INVALID_HANDLE;
326 }
Phil Burkbbd52862018-04-13 11:37:42 -0700327 aaudio_result_t result = serviceStream->stopClient(portHandle);
328 return checkForPendingClose(serviceStream, result);
329}
330
331// This is only called internally when AudioFlinger wants to tear down a stream.
332// So we do not have to check permissions.
333aaudio_result_t AAudioService::disconnectStreamByPortHandle(audio_port_handle_t portHandle) {
334 ALOGD("%s(%d) called", __func__, portHandle);
335 sp<AAudioServiceStreamBase> serviceStream =
Phil Burk2fe718b2018-05-14 12:28:32 -0700336 mStreamTracker.findStreamByPortHandleAndIncrement(portHandle);
Phil Burkbbd52862018-04-13 11:37:42 -0700337 if (serviceStream.get() == nullptr) {
338 ALOGE("%s(), could not find stream with portHandle = %d", __func__, portHandle);
339 return AAUDIO_ERROR_INVALID_HANDLE;
340 }
Phil Burkbbd52862018-04-13 11:37:42 -0700341 aaudio_result_t result = serviceStream->stop();
342 serviceStream->disconnect();
Phil Burk94862522017-09-13 21:31:36 -0700343 return checkForPendingClose(serviceStream, result);
Eric Laurenta54f1282017-07-01 19:39:32 -0700344}