blob: b57baa550106843e25d521af2aa61a79fb0aa945 [file] [log] [blame]
hkuang26587cb2020-01-16 10:36:08 -08001/*
2 * Copyright (C) 2020 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_NDEBUG 0
18#define LOG_TAG "TranscodingClientManager"
19
Chong Zhang8e062632020-03-31 10:56:37 -070020#include <aidl/android/media/BnTranscodingClient.h>
Chong Zhang15c192a2020-05-05 16:24:00 -070021#include <aidl/android/media/IMediaTranscodingService.h>
Chong Zhang8e062632020-03-31 10:56:37 -070022#include <android/binder_ibinder.h>
hkuang9c04b8d2020-01-22 10:03:21 -080023#include <inttypes.h>
hkuang26587cb2020-01-16 10:36:08 -080024#include <media/TranscodingClientManager.h>
Chong Zhang6d58e4b2020-03-31 09:41:10 -070025#include <media/TranscodingRequest.h>
Chong Zhangc37bdfe2020-10-06 13:54:09 -070026#include <media/TranscodingUidPolicy.h>
Chong Zhang3f23e982020-09-24 14:03:41 -070027#include <private/android_filesystem_config.h>
hkuang26587cb2020-01-16 10:36:08 -080028#include <utils/Log.h>
Chong Zhangc37bdfe2020-10-06 13:54:09 -070029#include <utils/String16.h>
hkuang26587cb2020-01-16 10:36:08 -080030namespace android {
31
Chong Zhang15c192a2020-05-05 16:24:00 -070032static_assert(sizeof(ClientIdType) == sizeof(void*), "ClientIdType should be pointer-sized");
33
Chong Zhangc37bdfe2020-10-06 13:54:09 -070034static constexpr const char* MEDIA_PROVIDER_PKG_NAME = "com.google.android.providers.media.module";
35
Chong Zhang8e062632020-03-31 10:56:37 -070036using ::aidl::android::media::BnTranscodingClient;
Chong Zhang15c192a2020-05-05 16:24:00 -070037using ::aidl::android::media::IMediaTranscodingService; // For service error codes
Chong Zhang8e062632020-03-31 10:56:37 -070038using ::aidl::android::media::TranscodingRequestParcel;
Chong Zhangbc062482020-10-14 16:43:53 -070039using ::aidl::android::media::TranscodingSessionParcel;
hkuang26587cb2020-01-16 10:36:08 -080040using Status = ::ndk::ScopedAStatus;
Chong Zhang8e062632020-03-31 10:56:37 -070041using ::ndk::SpAIBinder;
42
Chong Zhang3fa408f2020-04-30 11:04:28 -070043//static
44std::atomic<ClientIdType> TranscodingClientManager::sCookieCounter = 0;
45//static
46std::mutex TranscodingClientManager::sCookie2ClientLock;
47//static
48std::map<ClientIdType, std::shared_ptr<TranscodingClientManager::ClientImpl>>
49 TranscodingClientManager::sCookie2Client;
Chong Zhang8e062632020-03-31 10:56:37 -070050///////////////////////////////////////////////////////////////////////////////
51
Chong Zhang3f23e982020-09-24 14:03:41 -070052// Convenience methods for constructing binder::Status objects for error returns
53#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
54 Status::fromServiceSpecificErrorWithMessage( \
55 errorCode, \
56 String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, ##__VA_ARGS__))
57
Chong Zhang8e062632020-03-31 10:56:37 -070058/**
59 * ClientImpl implements a single client and contains all its information.
60 */
61struct TranscodingClientManager::ClientImpl : public BnTranscodingClient {
Chong Zhang6d58e4b2020-03-31 09:41:10 -070062 /* The remote client callback that this ClientInfo is associated with.
Chong Zhang8e062632020-03-31 10:56:37 -070063 * Once the ClientInfo is created, we hold an SpAIBinder so that the binder
64 * object doesn't get created again, otherwise the binder object pointer
65 * may not be unique.
66 */
Chong Zhangacb33502020-04-20 11:04:48 -070067 SpAIBinder mClientBinder;
68 std::shared_ptr<ITranscodingClientCallback> mClientCallback;
Chong Zhang8e062632020-03-31 10:56:37 -070069 /* A unique id assigned to the client by the service. This number is used
70 * by the service for indexing. Here we use the binder object's pointer
71 * (casted to int64t_t) as the client id.
72 */
73 ClientIdType mClientId;
Chong Zhang8e062632020-03-31 10:56:37 -070074 std::string mClientName;
75 std::string mClientOpPackageName;
Chong Zhang6d58e4b2020-03-31 09:41:10 -070076
Chong Zhangbc062482020-10-14 16:43:53 -070077 // Next sessionId to assign.
78 std::atomic<int32_t> mNextSessionId;
Chong Zhang15c192a2020-05-05 16:24:00 -070079 // Whether this client has been unregistered already.
80 std::atomic<bool> mAbandoned;
81 // Weak pointer to the client manager for this client.
82 std::weak_ptr<TranscodingClientManager> mOwner;
Chong Zhang8e062632020-03-31 10:56:37 -070083
Chong Zhang3f23e982020-09-24 14:03:41 -070084 ClientImpl(const std::shared_ptr<ITranscodingClientCallback>& callback,
hkuang08b38d02020-04-17 14:29:33 -070085 const std::string& clientName, const std::string& opPackageName,
Chong Zhang15c192a2020-05-05 16:24:00 -070086 const std::weak_ptr<TranscodingClientManager>& owner);
Chong Zhang8e062632020-03-31 10:56:37 -070087
88 Status submitRequest(const TranscodingRequestParcel& /*in_request*/,
Chong Zhangbc062482020-10-14 16:43:53 -070089 TranscodingSessionParcel* /*out_session*/,
90 bool* /*_aidl_return*/) override;
Chong Zhang8e062632020-03-31 10:56:37 -070091
Chong Zhangbc062482020-10-14 16:43:53 -070092 Status cancelSession(int32_t /*in_sessionId*/, bool* /*_aidl_return*/) override;
Chong Zhang8e062632020-03-31 10:56:37 -070093
Chong Zhangbc062482020-10-14 16:43:53 -070094 Status getSessionWithId(int32_t /*in_sessionId*/, TranscodingSessionParcel* /*out_session*/,
95 bool* /*_aidl_return*/) override;
Chong Zhang8e062632020-03-31 10:56:37 -070096
97 Status unregister() override;
98};
99
100TranscodingClientManager::ClientImpl::ClientImpl(
Chong Zhang3f23e982020-09-24 14:03:41 -0700101 const std::shared_ptr<ITranscodingClientCallback>& callback, const std::string& clientName,
102 const std::string& opPackageName, const std::weak_ptr<TranscodingClientManager>& owner)
Chong Zhangacb33502020-04-20 11:04:48 -0700103 : mClientBinder((callback != nullptr) ? callback->asBinder() : nullptr),
104 mClientCallback(callback),
Chong Zhang3fa408f2020-04-30 11:04:28 -0700105 mClientId(sCookieCounter.fetch_add(1, std::memory_order_relaxed)),
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700106 mClientName(clientName),
107 mClientOpPackageName(opPackageName),
Chong Zhangbc062482020-10-14 16:43:53 -0700108 mNextSessionId(0),
Chong Zhang15c192a2020-05-05 16:24:00 -0700109 mAbandoned(false),
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700110 mOwner(owner) {}
Chong Zhang8e062632020-03-31 10:56:37 -0700111
112Status TranscodingClientManager::ClientImpl::submitRequest(
Chong Zhangbc062482020-10-14 16:43:53 -0700113 const TranscodingRequestParcel& in_request, TranscodingSessionParcel* out_session,
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700114 bool* _aidl_return) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700115 *_aidl_return = false;
116
117 std::shared_ptr<TranscodingClientManager> owner;
118 if (mAbandoned || (owner = mOwner.lock()) == nullptr) {
119 return Status::fromServiceSpecificError(IMediaTranscodingService::ERROR_DISCONNECTED);
120 }
121
hkuang72d105f2020-05-21 10:48:55 -0700122 if (in_request.sourceFilePath.empty() || in_request.destinationFilePath.empty()) {
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700123 return Status::ok();
124 }
125
Chong Zhang3f23e982020-09-24 14:03:41 -0700126 int32_t callingPid = AIBinder_getCallingPid();
127 int32_t callingUid = AIBinder_getCallingUid();
128 int32_t in_clientUid = in_request.clientUid;
129 int32_t in_clientPid = in_request.clientPid;
130
131 // Check if we can trust clientUid. Only privilege caller could forward the
132 // uid on app client's behalf.
133 if (in_clientUid == IMediaTranscodingService::USE_CALLING_UID) {
134 in_clientUid = callingUid;
135 } else if (in_clientUid < 0) {
136 return Status::ok();
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700137 } else if (in_clientUid != callingUid && !owner->isTrustedCallingUid(callingUid)) {
Chong Zhang3f23e982020-09-24 14:03:41 -0700138 ALOGE("MediaTranscodingService::registerClient rejected (clientPid %d, clientUid %d) "
139 "(don't trust callingUid %d)",
140 in_clientPid, in_clientUid, callingUid);
141 return STATUS_ERROR_FMT(
142 IMediaTranscodingService::ERROR_PERMISSION_DENIED,
143 "MediaTranscodingService::registerClient rejected (clientPid %d, clientUid %d) "
144 "(don't trust callingUid %d)",
145 in_clientPid, in_clientUid, callingUid);
146 }
147
148 // Check if we can trust clientPid. Only privilege caller could forward the
149 // pid on app client's behalf.
150 if (in_clientPid == IMediaTranscodingService::USE_CALLING_PID) {
151 in_clientPid = callingPid;
152 } else if (in_clientPid < 0) {
153 return Status::ok();
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700154 } else if (in_clientPid != callingPid && !owner->isTrustedCallingUid(callingUid)) {
Chong Zhang3f23e982020-09-24 14:03:41 -0700155 ALOGE("MediaTranscodingService::registerClient rejected (clientPid %d, clientUid %d) "
156 "(don't trust callingUid %d)",
157 in_clientPid, in_clientUid, callingUid);
158 return STATUS_ERROR_FMT(
159 IMediaTranscodingService::ERROR_PERMISSION_DENIED,
160 "MediaTranscodingService::registerClient rejected (clientPid %d, clientUid %d) "
161 "(don't trust callingUid %d)",
162 in_clientPid, in_clientUid, callingUid);
163 }
164
Chong Zhangbc062482020-10-14 16:43:53 -0700165 int32_t sessionId = mNextSessionId.fetch_add(1);
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700166
Chong Zhangbc062482020-10-14 16:43:53 -0700167 *_aidl_return = owner->mSessionController->submit(mClientId, sessionId, in_clientUid,
168 in_request, mClientCallback);
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700169
170 if (*_aidl_return) {
Chong Zhangbc062482020-10-14 16:43:53 -0700171 out_session->sessionId = sessionId;
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700172
Chong Zhangbc062482020-10-14 16:43:53 -0700173 // TODO(chz): is some of this coming from SessionController?
174 *(TranscodingRequest*)&out_session->request = in_request;
175 out_session->awaitNumberOfSessions = 0;
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700176 }
Chong Zhang15c192a2020-05-05 16:24:00 -0700177
Chong Zhang8e062632020-03-31 10:56:37 -0700178 return Status::ok();
179}
180
Chong Zhangbc062482020-10-14 16:43:53 -0700181Status TranscodingClientManager::ClientImpl::cancelSession(int32_t in_sessionId,
182 bool* _aidl_return) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700183 *_aidl_return = false;
184
185 std::shared_ptr<TranscodingClientManager> owner;
186 if (mAbandoned || (owner = mOwner.lock()) == nullptr) {
187 return Status::fromServiceSpecificError(IMediaTranscodingService::ERROR_DISCONNECTED);
188 }
189
Chong Zhangbc062482020-10-14 16:43:53 -0700190 if (in_sessionId < 0) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700191 return Status::ok();
192 }
193
Chong Zhangbc062482020-10-14 16:43:53 -0700194 *_aidl_return = owner->mSessionController->cancel(mClientId, in_sessionId);
Chong Zhang8e062632020-03-31 10:56:37 -0700195 return Status::ok();
196}
197
Chong Zhangbc062482020-10-14 16:43:53 -0700198Status TranscodingClientManager::ClientImpl::getSessionWithId(int32_t in_sessionId,
199 TranscodingSessionParcel* out_session,
200 bool* _aidl_return) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700201 *_aidl_return = false;
202
203 std::shared_ptr<TranscodingClientManager> owner;
204 if (mAbandoned || (owner = mOwner.lock()) == nullptr) {
205 return Status::fromServiceSpecificError(IMediaTranscodingService::ERROR_DISCONNECTED);
206 }
207
Chong Zhangbc062482020-10-14 16:43:53 -0700208 if (in_sessionId < 0) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700209 return Status::ok();
210 }
211
Chong Zhangbc062482020-10-14 16:43:53 -0700212 *_aidl_return =
213 owner->mSessionController->getSession(mClientId, in_sessionId, &out_session->request);
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700214
215 if (*_aidl_return) {
Chong Zhangbc062482020-10-14 16:43:53 -0700216 out_session->sessionId = in_sessionId;
217 out_session->awaitNumberOfSessions = 0;
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700218 }
Chong Zhang8e062632020-03-31 10:56:37 -0700219 return Status::ok();
220}
221
222Status TranscodingClientManager::ClientImpl::unregister() {
Chong Zhang15c192a2020-05-05 16:24:00 -0700223 bool abandoned = mAbandoned.exchange(true);
224
225 std::shared_ptr<TranscodingClientManager> owner;
226 if (abandoned || (owner = mOwner.lock()) == nullptr) {
227 return Status::fromServiceSpecificError(IMediaTranscodingService::ERROR_DISCONNECTED);
228 }
229
Chong Zhangbc062482020-10-14 16:43:53 -0700230 // Use sessionId == -1 to cancel all realtime sessions for this client with the controller.
231 owner->mSessionController->cancel(mClientId, -1);
Chong Zhang15c192a2020-05-05 16:24:00 -0700232 owner->removeClient(mClientId);
233
Chong Zhang8e062632020-03-31 10:56:37 -0700234 return Status::ok();
235}
236
237///////////////////////////////////////////////////////////////////////////////
hkuang26587cb2020-01-16 10:36:08 -0800238
239// static
hkuang9c04b8d2020-01-22 10:03:21 -0800240void TranscodingClientManager::BinderDiedCallback(void* cookie) {
Chong Zhang3fa408f2020-04-30 11:04:28 -0700241 ClientIdType clientId = reinterpret_cast<ClientIdType>(cookie);
242
243 ALOGD("Client %lld is dead", (long long)clientId);
244
245 std::shared_ptr<ClientImpl> client;
246
247 {
248 std::scoped_lock lock{sCookie2ClientLock};
249
250 auto it = sCookie2Client.find(clientId);
251 if (it != sCookie2Client.end()) {
252 client = it->second;
253 }
254 }
255
256 if (client != nullptr) {
257 client->unregister();
258 }
hkuang9c04b8d2020-01-22 10:03:21 -0800259}
260
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700261TranscodingClientManager::TranscodingClientManager(
Chong Zhangbc062482020-10-14 16:43:53 -0700262 const std::shared_ptr<ControllerClientInterface>& controller)
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700263 : mDeathRecipient(AIBinder_DeathRecipient_new(BinderDiedCallback)),
Chong Zhangbc062482020-10-14 16:43:53 -0700264 mSessionController(controller),
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700265 mMediaProviderUid(-1) {
hkuang26587cb2020-01-16 10:36:08 -0800266 ALOGD("TranscodingClientManager started");
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700267 uid_t mpuid;
268 if (TranscodingUidPolicy::getUidForPackage(String16(MEDIA_PROVIDER_PKG_NAME), mpuid) ==
269 NO_ERROR) {
270 ALOGI("Found MediaProvider uid: %d", mpuid);
271 mMediaProviderUid = mpuid;
272 } else {
273 ALOGW("Couldn't get uid for MediaProvider.");
274 }
hkuang26587cb2020-01-16 10:36:08 -0800275}
276
277TranscodingClientManager::~TranscodingClientManager() {
278 ALOGD("TranscodingClientManager exited");
279}
280
hkuang26587cb2020-01-16 10:36:08 -0800281void TranscodingClientManager::dumpAllClients(int fd, const Vector<String16>& args __unused) {
282 String8 result;
283
284 const size_t SIZE = 256;
285 char buffer[SIZE];
hkuang08b38d02020-04-17 14:29:33 -0700286 std::scoped_lock lock{mLock};
hkuang26587cb2020-01-16 10:36:08 -0800287
Chong Zhang8e062632020-03-31 10:56:37 -0700288 if (mClientIdToClientMap.size() > 0) {
Chong Zhang0579c6f2020-10-05 12:03:34 -0700289 snprintf(buffer, SIZE, "\n========== Dumping all clients =========\n");
hkuang26587cb2020-01-16 10:36:08 -0800290 result.append(buffer);
291 }
292
Chong Zhang0579c6f2020-10-05 12:03:34 -0700293 snprintf(buffer, SIZE, " Total num of Clients: %zu\n", mClientIdToClientMap.size());
294 result.append(buffer);
295
Chong Zhang8e062632020-03-31 10:56:37 -0700296 for (const auto& iter : mClientIdToClientMap) {
Chong Zhang0579c6f2020-10-05 12:03:34 -0700297 snprintf(buffer, SIZE, " Client %lld: pkg: %s\n", (long long)iter.first,
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700298 iter.second->mClientName.c_str());
hkuang26587cb2020-01-16 10:36:08 -0800299 result.append(buffer);
300 }
301
302 write(fd, result.string(), result.size());
303}
304
Chong Zhangc37bdfe2020-10-06 13:54:09 -0700305bool TranscodingClientManager::isTrustedCallingUid(uid_t uid) {
306 if (uid > 0 && uid == mMediaProviderUid) {
307 return true;
308 }
309
310 switch (uid) {
311 case AID_ROOT: // root user
312 case AID_SYSTEM:
313 case AID_SHELL:
314 case AID_MEDIA: // mediaserver
315 return true;
316 default:
317 return false;
318 }
319}
320
Chong Zhang8e062632020-03-31 10:56:37 -0700321status_t TranscodingClientManager::addClient(
Chong Zhang3f23e982020-09-24 14:03:41 -0700322 const std::shared_ptr<ITranscodingClientCallback>& callback, const std::string& clientName,
323 const std::string& opPackageName, std::shared_ptr<ITranscodingClient>* outClient) {
hkuang26587cb2020-01-16 10:36:08 -0800324 // Validate the client.
Chong Zhang3f23e982020-09-24 14:03:41 -0700325 if (callback == nullptr || clientName.empty() || opPackageName.empty()) {
hkuang26587cb2020-01-16 10:36:08 -0800326 ALOGE("Invalid client");
Chong Zhang15c192a2020-05-05 16:24:00 -0700327 return IMediaTranscodingService::ERROR_ILLEGAL_ARGUMENT;
hkuang26587cb2020-01-16 10:36:08 -0800328 }
329
Chong Zhang3fa408f2020-04-30 11:04:28 -0700330 SpAIBinder binder = callback->asBinder();
Chong Zhang8e062632020-03-31 10:56:37 -0700331
hkuang26587cb2020-01-16 10:36:08 -0800332 std::scoped_lock lock{mLock};
333
Chong Zhang8e062632020-03-31 10:56:37 -0700334 // Checks if the client already registers.
Chong Zhang3fa408f2020-04-30 11:04:28 -0700335 if (mRegisteredCallbacks.count((uintptr_t)binder.get()) > 0) {
Chong Zhang15c192a2020-05-05 16:24:00 -0700336 return IMediaTranscodingService::ERROR_ALREADY_EXISTS;
hkuang26587cb2020-01-16 10:36:08 -0800337 }
338
Chong Zhang3f23e982020-09-24 14:03:41 -0700339 // Creates the client (with the id assigned by ClientImpl).
Chong Zhang3fa408f2020-04-30 11:04:28 -0700340 std::shared_ptr<ClientImpl> client = ::ndk::SharedRefBase::make<ClientImpl>(
Chong Zhang3f23e982020-09-24 14:03:41 -0700341 callback, clientName, opPackageName, shared_from_this());
Chong Zhang3fa408f2020-04-30 11:04:28 -0700342
Chong Zhang3f23e982020-09-24 14:03:41 -0700343 ALOGD("Adding client id %lld, name %s, package %s", (long long)client->mClientId,
Chong Zhang6d58e4b2020-03-31 09:41:10 -0700344 client->mClientName.c_str(), client->mClientOpPackageName.c_str());
hkuang9c04b8d2020-01-22 10:03:21 -0800345
Chong Zhang3fa408f2020-04-30 11:04:28 -0700346 {
347 std::scoped_lock lock{sCookie2ClientLock};
348 sCookie2Client.emplace(std::make_pair(client->mClientId, client));
349 }
350
351 AIBinder_linkToDeath(binder.get(), mDeathRecipient.get(),
352 reinterpret_cast<void*>(client->mClientId));
hkuang26587cb2020-01-16 10:36:08 -0800353
354 // Adds the new client to the map.
Chong Zhang3fa408f2020-04-30 11:04:28 -0700355 mRegisteredCallbacks.insert((uintptr_t)binder.get());
Chong Zhang8e062632020-03-31 10:56:37 -0700356 mClientIdToClientMap[client->mClientId] = client;
357
358 *outClient = client;
hkuang26587cb2020-01-16 10:36:08 -0800359
360 return OK;
361}
362
Chong Zhang8e062632020-03-31 10:56:37 -0700363status_t TranscodingClientManager::removeClient(ClientIdType clientId) {
364 ALOGD("Removing client id %lld", (long long)clientId);
hkuang26587cb2020-01-16 10:36:08 -0800365 std::scoped_lock lock{mLock};
366
367 // Checks if the client is valid.
Chong Zhang8e062632020-03-31 10:56:37 -0700368 auto it = mClientIdToClientMap.find(clientId);
369 if (it == mClientIdToClientMap.end()) {
370 ALOGE("Client id %lld does not exist", (long long)clientId);
Chong Zhang15c192a2020-05-05 16:24:00 -0700371 return IMediaTranscodingService::ERROR_INVALID_OPERATION;
hkuang26587cb2020-01-16 10:36:08 -0800372 }
373
Chong Zhang3fa408f2020-04-30 11:04:28 -0700374 SpAIBinder binder = it->second->mClientBinder;
hkuang26587cb2020-01-16 10:36:08 -0800375
376 // Check if the client still live. If alive, unlink the death.
Chong Zhang3fa408f2020-04-30 11:04:28 -0700377 if (binder.get() != nullptr) {
378 AIBinder_unlinkToDeath(binder.get(), mDeathRecipient.get(),
379 reinterpret_cast<void*>(it->second->mClientId));
380 }
381
382 {
383 std::scoped_lock lock{sCookie2ClientLock};
384 sCookie2Client.erase(it->second->mClientId);
hkuang26587cb2020-01-16 10:36:08 -0800385 }
386
387 // Erase the entry.
Chong Zhang8e062632020-03-31 10:56:37 -0700388 mClientIdToClientMap.erase(it);
Chong Zhang3fa408f2020-04-30 11:04:28 -0700389 mRegisteredCallbacks.erase((uintptr_t)binder.get());
hkuang26587cb2020-01-16 10:36:08 -0800390
391 return OK;
392}
393
394size_t TranscodingClientManager::getNumOfClients() const {
395 std::scoped_lock lock{mLock};
Chong Zhang8e062632020-03-31 10:56:37 -0700396 return mClientIdToClientMap.size();
hkuang26587cb2020-01-16 10:36:08 -0800397}
398
hkuang26587cb2020-01-16 10:36:08 -0800399} // namespace android