blob: 95b40508f53900a044213b75692807a4e92cbeb2 [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"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080040
41namespace android {
Jayant Chowdhary620763f2022-05-27 05:37:14 +000042
Igor Murashkin44cfcf02013-03-01 16:22:28 -080043using 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,
Austin Borger74fca042022-05-23 12:41:21 -070051 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080052 const String16& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080053 bool systemNativeClient,
Jooyung Han3f9a3b42020-01-23 12:27:18 +090054 const std::optional<String16>& clientFeatureId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080055 const String8& cameraId,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080056 int api1CameraId,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080057 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070058 int sensorOrientation,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080059 int clientPid,
60 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070061 int servicePid,
Emilian Peev5104fe92021-10-21 14:27:09 -070062 bool overrideForPerfClass,
63 bool legacyClient):
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080064 TClientBase(cameraService, remoteCallback, clientPackageName, systemNativeClient,
65 clientFeatureId, cameraId, api1CameraId, cameraFacing, sensorOrientation, clientPid,
66 clientUid, servicePid),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070067 mSharedCameraCallbacks(remoteCallback),
Austin Borger74fca042022-05-23 12:41:21 -070068 mCameraServiceProxyWrapper(cameraServiceProxyWrapper),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080069 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080070{
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080071 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070072 String8(clientPackageName).string(), clientPid, clientUid);
Igor Murashkin98e24722013-06-19 19:51:04 -070073
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070074 mInitialClientPid = clientPid;
Jayant Chowdhary22441f32021-12-26 18:35:41 -080075 mOverrideForPerfClass = overrideForPerfClass;
76 mLegacyClient = legacyClient;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080077}
78
79template <typename TClientBase>
80status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation)
81 const {
82
Jayant Chowdhary12361932018-08-27 14:46:13 -070083 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080084 if (callingPid == TClientBase::mClientPid) return NO_ERROR;
85
86 ALOGE("%s: attempt to use a locked camera from a different process"
87 " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid);
88 return PERMISSION_DENIED;
89}
90
91template <typename TClientBase>
Emilian Peevbd8c5032018-02-14 23:05:40 +000092status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager,
93 const String8& monitorTags) {
94 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080095}
96
97template <typename TClientBase>
98template <typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +000099status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr,
100 const String8& monitorTags) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800101 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800102 ALOGV("%s: Initializing client for camera %s", __FUNCTION__,
103 TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800104 status_t res;
105
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800106 IPCTransport providerTransport = IPCTransport::INVALID;
107 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr.string(),
108 &providerTransport);
109 if (res != OK) {
110 return res;
111 }
112 switch (providerTransport) {
113 case IPCTransport::HIDL:
114 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700115 new HidlCamera3Device(mCameraServiceProxyWrapper,
116 TClientBase::mCameraIdStr, mOverrideForPerfClass, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800117 break;
118 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000119 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700120 new AidlCamera3Device(mCameraServiceProxyWrapper,
121 TClientBase::mCameraIdStr, mOverrideForPerfClass, mLegacyClient);
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000122 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800123 default:
124 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
125 TClientBase::mCameraIdStr.string());
126 return NO_INIT;
127 }
Igor Murashkine6800ce2013-03-04 17:25:57 -0800128 if (mDevice == NULL) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800129 ALOGE("%s: Camera %s: No device connected",
130 __FUNCTION__, TClientBase::mCameraIdStr.string());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800131 return NO_INIT;
132 }
133
Emilian Peevbd8c5032018-02-14 23:05:40 +0000134 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800135 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800136 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
137 __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res);
Zhijun He66281c32013-09-13 17:59:59 -0700138 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800139 }
140
Emilian Peevfa17f092022-07-29 13:28:55 -0700141 // Verify ops permissions
142 res = TClientBase::startCameraOps();
143 if (res != OK) {
144 TClientBase::finishCameraOps();
145 mDevice.clear();
146 return res;
147 }
148
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800149 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700150 res = mDevice->setNotifyCallback(weakThis);
Austin Borger7b129542022-06-09 13:23:06 -0700151 if (res != OK) {
152 ALOGE("%s: Camera %s: Unable to set notify callback: %s (%d)",
153 __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res);
154 return res;
155 }
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800156
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000157 /** Start watchdog thread */
158 mCameraServiceWatchdog = new CameraServiceWatchdog();
Austin Borger7b129542022-06-09 13:23:06 -0700159 res = mCameraServiceWatchdog->run("Camera2ClientBaseWatchdog");
160 if (res != OK) {
161 ALOGE("%s: Unable to start camera service watchdog thread: %s (%d)",
162 __FUNCTION__, strerror(-res), res);
163 return res;
164 }
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000165
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800166 return OK;
167}
168
169template <typename TClientBase>
170Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
171 ATRACE_CALL();
172
173 TClientBase::mDestructionStarted = true;
174
175 disconnect();
176
Ravneetc83d7c42022-06-03 20:51:58 +0000177 if (mCameraServiceWatchdog != NULL) {
178 mCameraServiceWatchdog->requestExit();
179 mCameraServiceWatchdog.clear();
180 }
181
Jayant Chowdhary3ab499d2022-06-15 15:43:33 -0700182 ALOGI("%s: Client object's dtor for Camera Id %s completed. Client was: %s (PID %d, UID %u)",
183 __FUNCTION__, TClientBase::mCameraIdStr.string(),
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000184 String8(TClientBase::mClientPackageName).string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700185 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800186}
187
188template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800189status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800190 const Vector<String16>& args) {
191 String8 result;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800192 result.appendFormat("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
193 TClientBase::mCameraIdStr.string(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800194 (TClientBase::getRemoteCallback() != NULL ?
Marco Nelissen06b46062014-11-14 07:58:25 -0800195 IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800196 TClientBase::mClientPid);
197 result.append(" State: ");
198
199 write(fd, result.string(), result.size());
200 // TODO: print dynamic/request section from most recent requests
201
202 return dumpDevice(fd, args);
203}
204
205template <typename TClientBase>
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700206status_t Camera2ClientBase<TClientBase>::startWatchingTags(const String8 &tags, int out) {
207 sp<CameraDeviceBase> device = mDevice;
208 if (!device) {
209 dprintf(out, " Device is detached");
210 return OK;
211 }
212
213 return device->startWatchingTags(tags);
214}
215
216template <typename TClientBase>
217status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
218 sp<CameraDeviceBase> device = mDevice;
219 if (!device) {
220 dprintf(out, " Device is detached");
221 return OK;
222 }
223
224 return device->stopWatchingTags();
225}
226
227template <typename TClientBase>
228status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
229 sp<CameraDeviceBase> device = mDevice;
230 if (!device) {
231 // Nothing to dump if the device is detached
232 return OK;
233 }
234 return device->dumpWatchedEventsToVector(out);
235}
236
237template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800238status_t Camera2ClientBase<TClientBase>::dumpDevice(
239 int fd,
240 const Vector<String16>& args) {
241 String8 result;
242
243 result = " Device dump:\n";
244 write(fd, result.string(), result.size());
245
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800246 sp<CameraDeviceBase> device = mDevice;
247 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800248 result = " *** Device is detached\n";
249 write(fd, result.string(), result.size());
250 return NO_ERROR;
251 }
252
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800253 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800254 if (res != OK) {
255 result = String8::format(" Error dumping device: %s (%d)",
256 strerror(-res), res);
257 write(fd, result.string(), result.size());
258 }
259
260 return NO_ERROR;
261}
262
263// ICameraClient2BaseUser interface
264
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800265template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800266binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000267 if (mCameraServiceWatchdog != nullptr && mDevice != nullptr) {
268 // Timer for the disconnect call should be greater than getExpectedInFlightDuration
269 // since this duration is used to error handle methods in the disconnect sequence
270 // thus allowing existing error handling methods to execute first
271 uint64_t maxExpectedDuration =
272 ns2ms(mDevice->getExpectedInFlightDuration() + kBufferTimeDisconnectNs);
273
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000274 // Initialization from hal succeeded, time disconnect.
275 return mCameraServiceWatchdog->WATCH_CUSTOM_TIMER(disconnectImpl(),
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000276 maxExpectedDuration / kCycleLengthMs, kCycleLengthMs);
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000277 }
278 return disconnectImpl();
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000279}
280
281template <typename TClientBase>
282binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800283 ATRACE_CALL();
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700284 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800285 Mutex::Autolock icl(mBinderSerializationLock);
286
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700287 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800288 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800289 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700290 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800291 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800292 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800293
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700294 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800295
Rucha Katakwardf223072021-06-15 10:21:00 -0700296 // Before detaching the device, cache the info from current open session.
297 // The disconnected check avoids duplication of info and also prevents
298 // deadlock while acquiring service lock in cacheDump.
299 if (!TClientBase::mDisconnected) {
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700300 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.string());
Rucha Katakwardf223072021-06-15 10:21:00 -0700301 Camera2ClientBase::getCameraService()->cacheDump();
302 }
303
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800304 detachDevice();
305
Igor Murashkine6800ce2013-03-04 17:25:57 -0800306 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800307
Shuzhen Wang316781a2020-08-18 18:11:01 -0700308 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800309
310 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800311}
312
313template <typename TClientBase>
314void Camera2ClientBase<TClientBase>::detachDevice() {
315 if (mDevice == 0) return;
316 mDevice->disconnect();
317
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800318 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800319}
320
321template <typename TClientBase>
322status_t Camera2ClientBase<TClientBase>::connect(
323 const sp<TCamCallbacks>& client) {
324 ATRACE_CALL();
325 ALOGV("%s: E", __FUNCTION__);
326 Mutex::Autolock icl(mBinderSerializationLock);
327
328 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700329 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800330
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800331 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800332 "current locked to pid %d",
333 __FUNCTION__,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800334 TClientBase::mCameraIdStr.string(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700335 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800336 TClientBase::mClientPid);
337 return BAD_VALUE;
338 }
339
Jayant Chowdhary12361932018-08-27 14:46:13 -0700340 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800341
342 TClientBase::mRemoteCallback = client;
343 mSharedCameraCallbacks = client;
344
345 return OK;
346}
347
348/** Device-related methods */
349
350template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700351void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800352 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700353 const CaptureResultExtras& resultExtras) {
354 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
355 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800356}
357
358template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000359status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700360 if (!mDeviceActive) {
361 status_t res = TClientBase::startCameraStreamingOps();
362 if (res != OK) {
363 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
364 TClientBase::mCameraIdStr.string(), res);
365 return res;
366 }
Austin Borger74fca042022-05-23 12:41:21 -0700367 mCameraServiceProxyWrapper->logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700368 }
369 mDeviceActive = true;
370
371 ALOGV("Camera device is now active");
372 return OK;
373}
374
375template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800376void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700377 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800378 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700379 const std::string& userTag, int videoStabilizationMode) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700380 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700381 status_t res = TClientBase::finishCameraStreamingOps();
382 if (res != OK) {
383 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
384 TClientBase::mCameraIdStr.string(), res);
385 }
Austin Borger74fca042022-05-23 12:41:21 -0700386 mCameraServiceProxyWrapper->logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700387 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
388 streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700389 }
390 mDeviceActive = false;
391
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700392 ALOGV("Camera device is now idle");
393}
394
395template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700396void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800397 nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700398 (void)resultExtras;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800399 (void)timestamp;
400
Jianing Weicb0652e2014-03-12 18:29:36 -0700401 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
402 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800403}
404
405template <typename TClientBase>
406void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState,
407 int triggerId) {
408 (void)newState;
409 (void)triggerId;
410
411 ALOGV("%s: Autofocus state now %d, last trigger %d",
412 __FUNCTION__, newState, triggerId);
413
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800414}
415
416template <typename TClientBase>
417void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState,
418 int triggerId) {
419 (void)newState;
420 (void)triggerId;
421
422 ALOGV("%s: Autoexposure state now %d, last trigger %d",
423 __FUNCTION__, newState, triggerId);
424}
425
426template <typename TClientBase>
427void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState,
428 int triggerId) {
429 (void)newState;
430 (void)triggerId;
431
432 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
433 __FUNCTION__, newState, triggerId);
434}
435
436template <typename TClientBase>
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700437void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) {
438 (void)streamId;
439
440 ALOGV("%s: Stream %d now prepared",
441 __FUNCTION__, streamId);
442}
443
444template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700445void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
446
447 ALOGV("%s: Request queue now empty", __FUNCTION__);
448}
449
450template <typename TClientBase>
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700451void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) {
452 (void)lastFrameNumber;
453
454 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
455 __FUNCTION__, lastFrameNumber);
456}
457
458template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800459int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800460 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800461}
462
463template <typename TClientBase>
464const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
465 return mDevice;
466}
467
468template <typename TClientBase>
469const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800470 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800471}
472
473template <typename TClientBase>
474Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
475 SharedCameraCallbacks &client) :
476
477 mRemoteCallback(client.mRemoteCallback),
478 mSharedClient(client) {
479
480 mSharedClient.mRemoteCallbackLock.lock();
481}
482
483template <typename TClientBase>
484Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
485 mSharedClient.mRemoteCallbackLock.unlock();
486}
487
488template <typename TClientBase>
489Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
490 const sp<TCamCallbacks>&client) :
491
492 mRemoteCallback(client) {
493}
494
495template <typename TClientBase>
496typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
497Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
498 const sp<TCamCallbacks>&client) {
499
500 Mutex::Autolock l(mRemoteCallbackLock);
501 mRemoteCallback = client;
502 return *this;
503}
504
505template <typename TClientBase>
506void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
507 Mutex::Autolock l(mRemoteCallbackLock);
508 mRemoteCallback.clear();
509}
510
Cliff Wud3a05312021-04-26 23:07:31 +0800511template <typename TClientBase>
512status_t Camera2ClientBase<TClientBase>::injectCamera(const String8& injectedCamId,
513 sp<CameraProviderManager> manager) {
514 return mDevice->injectCamera(injectedCamId, manager);
515}
516
517template <typename TClientBase>
518status_t Camera2ClientBase<TClientBase>::stopInjection() {
519 return mDevice->stopInjection();
520}
521
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800522template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700523template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800524
525} // namespace android