blob: a7097fb5d93d5f2c61dace3f44f3aaaff147f942 [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();
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700246 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800247 Mutex::Autolock icl(mBinderSerializationLock);
248
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700249 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800250 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800251 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700252 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800253 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800254 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800255
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700256 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800257
Rucha Katakwardf223072021-06-15 10:21:00 -0700258 // Before detaching the device, cache the info from current open session.
259 // The disconnected check avoids duplication of info and also prevents
260 // deadlock while acquiring service lock in cacheDump.
261 if (!TClientBase::mDisconnected) {
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700262 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.string());
Rucha Katakwardf223072021-06-15 10:21:00 -0700263 Camera2ClientBase::getCameraService()->cacheDump();
264 }
265
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800266 detachDevice();
267
Igor Murashkine6800ce2013-03-04 17:25:57 -0800268 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800269
Shuzhen Wang316781a2020-08-18 18:11:01 -0700270 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800271
272 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800273}
274
275template <typename TClientBase>
276void Camera2ClientBase<TClientBase>::detachDevice() {
277 if (mDevice == 0) return;
278 mDevice->disconnect();
279
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800280 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800281}
282
283template <typename TClientBase>
284status_t Camera2ClientBase<TClientBase>::connect(
285 const sp<TCamCallbacks>& client) {
286 ATRACE_CALL();
287 ALOGV("%s: E", __FUNCTION__);
288 Mutex::Autolock icl(mBinderSerializationLock);
289
290 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700291 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800292
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800293 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800294 "current locked to pid %d",
295 __FUNCTION__,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800296 TClientBase::mCameraIdStr.string(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700297 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800298 TClientBase::mClientPid);
299 return BAD_VALUE;
300 }
301
Jayant Chowdhary12361932018-08-27 14:46:13 -0700302 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800303
304 TClientBase::mRemoteCallback = client;
305 mSharedCameraCallbacks = client;
306
307 return OK;
308}
309
310/** Device-related methods */
311
312template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700313void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800314 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700315 const CaptureResultExtras& resultExtras) {
316 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
317 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800318}
319
320template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000321status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700322 if (!mDeviceActive) {
323 status_t res = TClientBase::startCameraStreamingOps();
324 if (res != OK) {
325 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
326 TClientBase::mCameraIdStr.string(), res);
327 return res;
328 }
Austin Borger4a870a32022-02-25 01:48:41 +0000329 CameraServiceProxyWrapper::logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700330 }
331 mDeviceActive = true;
332
333 ALOGV("Camera device is now active");
334 return OK;
335}
336
337template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800338void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700339 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800340 const std::vector<hardware::CameraStreamStats>& streamStats,
341 const std::string& userTag) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700342 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700343 status_t res = TClientBase::finishCameraStreamingOps();
344 if (res != OK) {
345 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
346 TClientBase::mCameraIdStr.string(), res);
347 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700348 CameraServiceProxyWrapper::logIdle(TClientBase::mCameraIdStr,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800349 requestCount, resultErrorCount, deviceError, userTag, streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700350 }
351 mDeviceActive = false;
352
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700353 ALOGV("Camera device is now idle");
354}
355
356template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700357void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800358 nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700359 (void)resultExtras;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800360 (void)timestamp;
361
Jianing Weicb0652e2014-03-12 18:29:36 -0700362 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
363 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800364}
365
366template <typename TClientBase>
367void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState,
368 int triggerId) {
369 (void)newState;
370 (void)triggerId;
371
372 ALOGV("%s: Autofocus state now %d, last trigger %d",
373 __FUNCTION__, newState, triggerId);
374
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800375}
376
377template <typename TClientBase>
378void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState,
379 int triggerId) {
380 (void)newState;
381 (void)triggerId;
382
383 ALOGV("%s: Autoexposure state now %d, last trigger %d",
384 __FUNCTION__, newState, triggerId);
385}
386
387template <typename TClientBase>
388void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState,
389 int triggerId) {
390 (void)newState;
391 (void)triggerId;
392
393 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
394 __FUNCTION__, newState, triggerId);
395}
396
397template <typename TClientBase>
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700398void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) {
399 (void)streamId;
400
401 ALOGV("%s: Stream %d now prepared",
402 __FUNCTION__, streamId);
403}
404
405template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700406void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
407
408 ALOGV("%s: Request queue now empty", __FUNCTION__);
409}
410
411template <typename TClientBase>
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700412void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) {
413 (void)lastFrameNumber;
414
415 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
416 __FUNCTION__, lastFrameNumber);
417}
418
419template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800420int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800421 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800422}
423
424template <typename TClientBase>
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -0700425int Camera2ClientBase<TClientBase>::getCameraDeviceVersion() const {
426 return mDeviceVersion;
427}
428
429template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800430const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
431 return mDevice;
432}
433
434template <typename TClientBase>
435const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800436 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800437}
438
439template <typename TClientBase>
440Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
441 SharedCameraCallbacks &client) :
442
443 mRemoteCallback(client.mRemoteCallback),
444 mSharedClient(client) {
445
446 mSharedClient.mRemoteCallbackLock.lock();
447}
448
449template <typename TClientBase>
450Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
451 mSharedClient.mRemoteCallbackLock.unlock();
452}
453
454template <typename TClientBase>
455Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
456 const sp<TCamCallbacks>&client) :
457
458 mRemoteCallback(client) {
459}
460
461template <typename TClientBase>
462typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
463Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
464 const sp<TCamCallbacks>&client) {
465
466 Mutex::Autolock l(mRemoteCallbackLock);
467 mRemoteCallback = client;
468 return *this;
469}
470
471template <typename TClientBase>
472void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
473 Mutex::Autolock l(mRemoteCallbackLock);
474 mRemoteCallback.clear();
475}
476
Cliff Wud3a05312021-04-26 23:07:31 +0800477template <typename TClientBase>
478status_t Camera2ClientBase<TClientBase>::injectCamera(const String8& injectedCamId,
479 sp<CameraProviderManager> manager) {
480 return mDevice->injectCamera(injectedCamId, manager);
481}
482
483template <typename TClientBase>
484status_t Camera2ClientBase<TClientBase>::stopInjection() {
485 return mDevice->stopInjection();
486}
487
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800488template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700489template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800490
491} // namespace android