blob: 0ac047a33d34b8212220352c3953b647862efa3c [file] [log] [blame]
Igor Murashkin44cfcf02013-03-01 16:22:28 -08001/*
2 * Copyright (C) 2013 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 "Camera2ClientBase"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
19//#define LOG_NDEBUG 0
20
Colin Crosse5729fa2014-03-21 15:04:25 -070021#include <inttypes.h>
22
Igor Murashkin44cfcf02013-03-01 16:22:28 -080023#include <utils/Log.h>
24#include <utils/Trace.h>
25
26#include <cutils/properties.h>
27#include <gui/Surface.h>
28#include <gui/Surface.h>
Igor Murashkin44cfcf02013-03-01 16:22:28 -080029
Shuzhen Wang316781a2020-08-18 18:11:01 -070030#include <camera/CameraSessionStats.h>
31
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070032#include "common/Camera2ClientBase.h"
Igor Murashkine7ee7632013-06-11 18:10:18 -070033
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070034#include "api2/CameraDeviceClient.h"
35
Eino-Ville Talvalad309fb92015-11-25 12:12:45 -080036#include "device3/Camera3Device.h"
Jayant Chowdhary35642f22022-01-08 00:39:39 +000037#include "device3/aidl/AidlCamera3Device.h"
Jayant Chowdhary22441f32021-12-26 18:35:41 -080038#include "device3/hidl/HidlCamera3Device.h"
Jayant Chowdhary12361932018-08-27 14:46:13 -070039#include "utils/CameraThreadState.h"
Shuzhen Wang316781a2020-08-18 18:11:01 -070040#include "utils/CameraServiceProxyWrapper.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080041
42namespace android {
43using namespace camera2;
44
Igor Murashkin44cfcf02013-03-01 16:22:28 -080045// Interface used by CameraService
46
47template <typename TClientBase>
48Camera2ClientBase<TClientBase>::Camera2ClientBase(
49 const sp<CameraService>& cameraService,
50 const sp<TCamCallbacks>& remoteCallback,
51 const String16& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080052 bool systemNativeClient,
Jooyung Han3f9a3b42020-01-23 12:27:18 +090053 const std::optional<String16>& clientFeatureId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080054 const String8& cameraId,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080055 int api1CameraId,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080056 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070057 int sensorOrientation,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080058 int clientPid,
59 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070060 int servicePid,
Emilian Peev5104fe92021-10-21 14:27:09 -070061 bool overrideForPerfClass,
62 bool legacyClient):
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080063 TClientBase(cameraService, remoteCallback, clientPackageName, systemNativeClient,
64 clientFeatureId, cameraId, api1CameraId, cameraFacing, sensorOrientation, clientPid,
65 clientUid, servicePid),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070066 mSharedCameraCallbacks(remoteCallback),
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080067 mDeviceVersion(cameraService->getDeviceVersion(TClientBase::mCameraIdStr)),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080068 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080069{
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080070 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070071 String8(clientPackageName).string(), clientPid, clientUid);
Igor Murashkin98e24722013-06-19 19:51:04 -070072
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070073 mInitialClientPid = clientPid;
Jayant Chowdhary22441f32021-12-26 18:35:41 -080074 mOverrideForPerfClass = overrideForPerfClass;
75 mLegacyClient = legacyClient;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080076}
77
78template <typename TClientBase>
79status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation)
80 const {
81
Jayant Chowdhary12361932018-08-27 14:46:13 -070082 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080083 if (callingPid == TClientBase::mClientPid) return NO_ERROR;
84
85 ALOGE("%s: attempt to use a locked camera from a different process"
86 " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid);
87 return PERMISSION_DENIED;
88}
89
90template <typename TClientBase>
Emilian Peevbd8c5032018-02-14 23:05:40 +000091status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager,
92 const String8& monitorTags) {
93 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080094}
95
96template <typename TClientBase>
97template <typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +000098status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr,
99 const String8& monitorTags) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800100 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800101 ALOGV("%s: Initializing client for camera %s", __FUNCTION__,
102 TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800103 status_t res;
104
Igor Murashkine6800ce2013-03-04 17:25:57 -0800105 // Verify ops permissions
106 res = TClientBase::startCameraOps();
107 if (res != OK) {
108 return res;
109 }
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800110 IPCTransport providerTransport = IPCTransport::INVALID;
111 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr.string(),
112 &providerTransport);
113 if (res != OK) {
114 return res;
115 }
116 switch (providerTransport) {
117 case IPCTransport::HIDL:
118 mDevice =
119 new HidlCamera3Device(TClientBase::mCameraIdStr, mOverrideForPerfClass,
120 mLegacyClient);
121 break;
122 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000123 mDevice =
124 new AidlCamera3Device(TClientBase::mCameraIdStr, mOverrideForPerfClass,
125 mLegacyClient);
126 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800127 default:
128 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
129 TClientBase::mCameraIdStr.string());
130 return NO_INIT;
131 }
Igor Murashkine6800ce2013-03-04 17:25:57 -0800132 if (mDevice == NULL) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800133 ALOGE("%s: Camera %s: No device connected",
134 __FUNCTION__, TClientBase::mCameraIdStr.string());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800135 return NO_INIT;
136 }
137
Emilian Peevbd8c5032018-02-14 23:05:40 +0000138 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800139 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800140 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
141 __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res);
Zhijun He66281c32013-09-13 17:59:59 -0700142 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800143 }
144
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800145 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700146 res = mDevice->setNotifyCallback(weakThis);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800147
148 return OK;
149}
150
151template <typename TClientBase>
152Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
153 ATRACE_CALL();
154
155 TClientBase::mDestructionStarted = true;
156
157 disconnect();
158
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800159 ALOGI("Closed Camera %s. Client was: %s (PID %d, UID %u)",
160 TClientBase::mCameraIdStr.string(),
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000161 String8(TClientBase::mClientPackageName).string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700162 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800163}
164
165template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800166status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800167 const Vector<String16>& args) {
168 String8 result;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800169 result.appendFormat("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
170 TClientBase::mCameraIdStr.string(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800171 (TClientBase::getRemoteCallback() != NULL ?
Marco Nelissen06b46062014-11-14 07:58:25 -0800172 IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800173 TClientBase::mClientPid);
174 result.append(" State: ");
175
176 write(fd, result.string(), result.size());
177 // TODO: print dynamic/request section from most recent requests
178
179 return dumpDevice(fd, args);
180}
181
182template <typename TClientBase>
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700183status_t Camera2ClientBase<TClientBase>::startWatchingTags(const String8 &tags, int out) {
184 sp<CameraDeviceBase> device = mDevice;
185 if (!device) {
186 dprintf(out, " Device is detached");
187 return OK;
188 }
189
190 return device->startWatchingTags(tags);
191}
192
193template <typename TClientBase>
194status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
195 sp<CameraDeviceBase> device = mDevice;
196 if (!device) {
197 dprintf(out, " Device is detached");
198 return OK;
199 }
200
201 return device->stopWatchingTags();
202}
203
204template <typename TClientBase>
205status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
206 sp<CameraDeviceBase> device = mDevice;
207 if (!device) {
208 // Nothing to dump if the device is detached
209 return OK;
210 }
211 return device->dumpWatchedEventsToVector(out);
212}
213
214template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800215status_t Camera2ClientBase<TClientBase>::dumpDevice(
216 int fd,
217 const Vector<String16>& args) {
218 String8 result;
219
220 result = " Device dump:\n";
221 write(fd, result.string(), result.size());
222
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800223 sp<CameraDeviceBase> device = mDevice;
224 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800225 result = " *** Device is detached\n";
226 write(fd, result.string(), result.size());
227 return NO_ERROR;
228 }
229
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800230 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800231 if (res != OK) {
232 result = String8::format(" Error dumping device: %s (%d)",
233 strerror(-res), res);
234 write(fd, result.string(), result.size());
235 }
236
237 return NO_ERROR;
238}
239
240// ICameraClient2BaseUser interface
241
242
243template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800244binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800245 ATRACE_CALL();
246 Mutex::Autolock icl(mBinderSerializationLock);
247
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800248 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800249 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700250 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800251 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800252 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800253
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800254 ALOGV("Camera %s: Shutting down", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800255
Rucha Katakwardf223072021-06-15 10:21:00 -0700256 // Before detaching the device, cache the info from current open session.
257 // The disconnected check avoids duplication of info and also prevents
258 // deadlock while acquiring service lock in cacheDump.
259 if (!TClientBase::mDisconnected) {
260 Camera2ClientBase::getCameraService()->cacheDump();
261 }
262
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800263 detachDevice();
264
Igor Murashkine6800ce2013-03-04 17:25:57 -0800265 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800266
Shuzhen Wang316781a2020-08-18 18:11:01 -0700267 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800268
269 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800270}
271
272template <typename TClientBase>
273void Camera2ClientBase<TClientBase>::detachDevice() {
274 if (mDevice == 0) return;
275 mDevice->disconnect();
276
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800277 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800278}
279
280template <typename TClientBase>
281status_t Camera2ClientBase<TClientBase>::connect(
282 const sp<TCamCallbacks>& client) {
283 ATRACE_CALL();
284 ALOGV("%s: E", __FUNCTION__);
285 Mutex::Autolock icl(mBinderSerializationLock);
286
287 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700288 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800289
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800290 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800291 "current locked to pid %d",
292 __FUNCTION__,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800293 TClientBase::mCameraIdStr.string(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700294 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800295 TClientBase::mClientPid);
296 return BAD_VALUE;
297 }
298
Jayant Chowdhary12361932018-08-27 14:46:13 -0700299 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800300
301 TClientBase::mRemoteCallback = client;
302 mSharedCameraCallbacks = client;
303
304 return OK;
305}
306
307/** Device-related methods */
308
309template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700310void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800311 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700312 const CaptureResultExtras& resultExtras) {
313 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
314 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800315}
316
317template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000318status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700319 if (!mDeviceActive) {
320 status_t res = TClientBase::startCameraStreamingOps();
321 if (res != OK) {
322 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
323 TClientBase::mCameraIdStr.string(), res);
324 return res;
325 }
Austin Borger4a870a32022-02-25 01:48:41 +0000326 CameraServiceProxyWrapper::logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700327 }
328 mDeviceActive = true;
329
330 ALOGV("Camera device is now active");
331 return OK;
332}
333
334template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800335void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700336 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800337 const std::vector<hardware::CameraStreamStats>& streamStats,
338 const std::string& userTag) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700339 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700340 status_t res = TClientBase::finishCameraStreamingOps();
341 if (res != OK) {
342 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
343 TClientBase::mCameraIdStr.string(), res);
344 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700345 CameraServiceProxyWrapper::logIdle(TClientBase::mCameraIdStr,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800346 requestCount, resultErrorCount, deviceError, userTag, streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700347 }
348 mDeviceActive = false;
349
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700350 ALOGV("Camera device is now idle");
351}
352
353template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700354void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800355 nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700356 (void)resultExtras;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800357 (void)timestamp;
358
Jianing Weicb0652e2014-03-12 18:29:36 -0700359 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
360 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800361}
362
363template <typename TClientBase>
364void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState,
365 int triggerId) {
366 (void)newState;
367 (void)triggerId;
368
369 ALOGV("%s: Autofocus state now %d, last trigger %d",
370 __FUNCTION__, newState, triggerId);
371
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800372}
373
374template <typename TClientBase>
375void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState,
376 int triggerId) {
377 (void)newState;
378 (void)triggerId;
379
380 ALOGV("%s: Autoexposure state now %d, last trigger %d",
381 __FUNCTION__, newState, triggerId);
382}
383
384template <typename TClientBase>
385void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState,
386 int triggerId) {
387 (void)newState;
388 (void)triggerId;
389
390 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
391 __FUNCTION__, newState, triggerId);
392}
393
394template <typename TClientBase>
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700395void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) {
396 (void)streamId;
397
398 ALOGV("%s: Stream %d now prepared",
399 __FUNCTION__, streamId);
400}
401
402template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700403void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
404
405 ALOGV("%s: Request queue now empty", __FUNCTION__);
406}
407
408template <typename TClientBase>
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700409void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) {
410 (void)lastFrameNumber;
411
412 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
413 __FUNCTION__, lastFrameNumber);
414}
415
416template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800417int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800418 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800419}
420
421template <typename TClientBase>
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -0700422int Camera2ClientBase<TClientBase>::getCameraDeviceVersion() const {
423 return mDeviceVersion;
424}
425
426template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800427const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
428 return mDevice;
429}
430
431template <typename TClientBase>
432const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800433 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800434}
435
436template <typename TClientBase>
437Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
438 SharedCameraCallbacks &client) :
439
440 mRemoteCallback(client.mRemoteCallback),
441 mSharedClient(client) {
442
443 mSharedClient.mRemoteCallbackLock.lock();
444}
445
446template <typename TClientBase>
447Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
448 mSharedClient.mRemoteCallbackLock.unlock();
449}
450
451template <typename TClientBase>
452Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
453 const sp<TCamCallbacks>&client) :
454
455 mRemoteCallback(client) {
456}
457
458template <typename TClientBase>
459typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
460Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
461 const sp<TCamCallbacks>&client) {
462
463 Mutex::Autolock l(mRemoteCallbackLock);
464 mRemoteCallback = client;
465 return *this;
466}
467
468template <typename TClientBase>
469void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
470 Mutex::Autolock l(mRemoteCallbackLock);
471 mRemoteCallback.clear();
472}
473
Cliff Wud3a05312021-04-26 23:07:31 +0800474template <typename TClientBase>
475status_t Camera2ClientBase<TClientBase>::injectCamera(const String8& injectedCamId,
476 sp<CameraProviderManager> manager) {
477 return mDevice->injectCamera(injectedCamId, manager);
478}
479
480template <typename TClientBase>
481status_t Camera2ClientBase<TClientBase>::stopInjection() {
482 return mDevice->stopInjection();
483}
484
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800485template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700486template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800487
488} // namespace android