blob: 0a2819c06864b0dda2064d3f5b890337ce38a679 [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,
Austin Borger18b30a72022-10-27 12:20:29 -070063 bool overrideToPortrait,
Emilian Peev5104fe92021-10-21 14:27:09 -070064 bool legacyClient):
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080065 TClientBase(cameraService, remoteCallback, clientPackageName, systemNativeClient,
66 clientFeatureId, cameraId, api1CameraId, cameraFacing, sensorOrientation, clientPid,
Austin Borger18b30a72022-10-27 12:20:29 -070067 clientUid, servicePid, overrideToPortrait),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070068 mSharedCameraCallbacks(remoteCallback),
Austin Borger74fca042022-05-23 12:41:21 -070069 mCameraServiceProxyWrapper(cameraServiceProxyWrapper),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080070 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080071{
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080072 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070073 String8(clientPackageName).string(), clientPid, clientUid);
Igor Murashkin98e24722013-06-19 19:51:04 -070074
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070075 mInitialClientPid = clientPid;
Jayant Chowdhary22441f32021-12-26 18:35:41 -080076 mOverrideForPerfClass = overrideForPerfClass;
77 mLegacyClient = legacyClient;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080078}
79
80template <typename TClientBase>
81status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation)
82 const {
83
Jayant Chowdhary12361932018-08-27 14:46:13 -070084 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080085 if (callingPid == TClientBase::mClientPid) return NO_ERROR;
86
87 ALOGE("%s: attempt to use a locked camera from a different process"
88 " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid);
89 return PERMISSION_DENIED;
90}
91
92template <typename TClientBase>
Emilian Peevbd8c5032018-02-14 23:05:40 +000093status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager,
94 const String8& monitorTags) {
95 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080096}
97
98template <typename TClientBase>
99template <typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +0000100status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr,
101 const String8& monitorTags) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800102 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800103 ALOGV("%s: Initializing client for camera %s", __FUNCTION__,
104 TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800105 status_t res;
106
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800107 IPCTransport providerTransport = IPCTransport::INVALID;
108 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr.string(),
109 &providerTransport);
110 if (res != OK) {
111 return res;
112 }
113 switch (providerTransport) {
114 case IPCTransport::HIDL:
115 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700116 new HidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger18b30a72022-10-27 12:20:29 -0700117 TClientBase::mCameraIdStr, mOverrideForPerfClass,
118 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800119 break;
120 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000121 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700122 new AidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger18b30a72022-10-27 12:20:29 -0700123 TClientBase::mCameraIdStr, mOverrideForPerfClass,
124 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000125 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800126 default:
127 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
128 TClientBase::mCameraIdStr.string());
129 return NO_INIT;
130 }
Igor Murashkine6800ce2013-03-04 17:25:57 -0800131 if (mDevice == NULL) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800132 ALOGE("%s: Camera %s: No device connected",
133 __FUNCTION__, TClientBase::mCameraIdStr.string());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800134 return NO_INIT;
135 }
136
Emilian Peevbd8c5032018-02-14 23:05:40 +0000137 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800138 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800139 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
140 __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res);
Zhijun He66281c32013-09-13 17:59:59 -0700141 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800142 }
143
Emilian Peevfa17f092022-07-29 13:28:55 -0700144 // Verify ops permissions
145 res = TClientBase::startCameraOps();
146 if (res != OK) {
147 TClientBase::finishCameraOps();
148 mDevice.clear();
149 return res;
150 }
151
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800152 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700153 res = mDevice->setNotifyCallback(weakThis);
Austin Borger7b129542022-06-09 13:23:06 -0700154 if (res != OK) {
155 ALOGE("%s: Camera %s: Unable to set notify callback: %s (%d)",
156 __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res);
157 return res;
158 }
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800159
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000160 /** Start watchdog thread */
Shuzhen Wang03fe6232023-02-05 12:41:15 -0800161 mCameraServiceWatchdog = new CameraServiceWatchdog(TClientBase::mCameraIdStr,
162 mCameraServiceProxyWrapper);
Austin Borger7b129542022-06-09 13:23:06 -0700163 res = mCameraServiceWatchdog->run("Camera2ClientBaseWatchdog");
164 if (res != OK) {
165 ALOGE("%s: Unable to start camera service watchdog thread: %s (%d)",
166 __FUNCTION__, strerror(-res), res);
167 return res;
168 }
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000169
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800170 return OK;
171}
172
173template <typename TClientBase>
174Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
175 ATRACE_CALL();
176
177 TClientBase::mDestructionStarted = true;
178
179 disconnect();
180
Ravneetc83d7c42022-06-03 20:51:58 +0000181 if (mCameraServiceWatchdog != NULL) {
182 mCameraServiceWatchdog->requestExit();
183 mCameraServiceWatchdog.clear();
184 }
185
Jayant Chowdhary3ab499d2022-06-15 15:43:33 -0700186 ALOGI("%s: Client object's dtor for Camera Id %s completed. Client was: %s (PID %d, UID %u)",
187 __FUNCTION__, TClientBase::mCameraIdStr.string(),
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000188 String8(TClientBase::mClientPackageName).string(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700189 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800190}
191
192template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800193status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800194 const Vector<String16>& args) {
195 String8 result;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800196 result.appendFormat("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
197 TClientBase::mCameraIdStr.string(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800198 (TClientBase::getRemoteCallback() != NULL ?
Marco Nelissen06b46062014-11-14 07:58:25 -0800199 IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800200 TClientBase::mClientPid);
201 result.append(" State: ");
202
203 write(fd, result.string(), result.size());
204 // TODO: print dynamic/request section from most recent requests
205
206 return dumpDevice(fd, args);
207}
208
209template <typename TClientBase>
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700210status_t Camera2ClientBase<TClientBase>::startWatchingTags(const String8 &tags, int out) {
211 sp<CameraDeviceBase> device = mDevice;
212 if (!device) {
213 dprintf(out, " Device is detached");
214 return OK;
215 }
216
217 return device->startWatchingTags(tags);
218}
219
220template <typename TClientBase>
221status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
222 sp<CameraDeviceBase> device = mDevice;
223 if (!device) {
224 dprintf(out, " Device is detached");
225 return OK;
226 }
227
228 return device->stopWatchingTags();
229}
230
231template <typename TClientBase>
232status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
233 sp<CameraDeviceBase> device = mDevice;
234 if (!device) {
235 // Nothing to dump if the device is detached
236 return OK;
237 }
238 return device->dumpWatchedEventsToVector(out);
239}
240
241template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800242status_t Camera2ClientBase<TClientBase>::dumpDevice(
243 int fd,
244 const Vector<String16>& args) {
245 String8 result;
246
247 result = " Device dump:\n";
248 write(fd, result.string(), result.size());
249
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800250 sp<CameraDeviceBase> device = mDevice;
251 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800252 result = " *** Device is detached\n";
253 write(fd, result.string(), result.size());
254 return NO_ERROR;
255 }
256
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800257 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800258 if (res != OK) {
259 result = String8::format(" Error dumping device: %s (%d)",
260 strerror(-res), res);
261 write(fd, result.string(), result.size());
262 }
263
264 return NO_ERROR;
265}
266
267// ICameraClient2BaseUser interface
268
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800269template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800270binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000271 if (mCameraServiceWatchdog != nullptr && mDevice != nullptr) {
272 // Timer for the disconnect call should be greater than getExpectedInFlightDuration
273 // since this duration is used to error handle methods in the disconnect sequence
274 // thus allowing existing error handling methods to execute first
275 uint64_t maxExpectedDuration =
276 ns2ms(mDevice->getExpectedInFlightDuration() + kBufferTimeDisconnectNs);
277
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000278 // Initialization from hal succeeded, time disconnect.
279 return mCameraServiceWatchdog->WATCH_CUSTOM_TIMER(disconnectImpl(),
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000280 maxExpectedDuration / kCycleLengthMs, kCycleLengthMs);
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000281 }
282 return disconnectImpl();
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000283}
284
285template <typename TClientBase>
286binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800287 ATRACE_CALL();
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700288 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800289 Mutex::Autolock icl(mBinderSerializationLock);
290
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700291 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800292 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800293 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700294 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800295 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800296 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800297
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700298 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800299
Rucha Katakwardf223072021-06-15 10:21:00 -0700300 // Before detaching the device, cache the info from current open session.
301 // The disconnected check avoids duplication of info and also prevents
302 // deadlock while acquiring service lock in cacheDump.
303 if (!TClientBase::mDisconnected) {
Shuzhen Wang046f4a82022-05-05 17:15:24 -0700304 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.string());
Rucha Katakwardf223072021-06-15 10:21:00 -0700305 Camera2ClientBase::getCameraService()->cacheDump();
306 }
307
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800308 detachDevice();
309
Igor Murashkine6800ce2013-03-04 17:25:57 -0800310 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800311
Shuzhen Wang316781a2020-08-18 18:11:01 -0700312 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800313
314 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800315}
316
317template <typename TClientBase>
318void Camera2ClientBase<TClientBase>::detachDevice() {
319 if (mDevice == 0) return;
320 mDevice->disconnect();
321
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800322 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800323}
324
325template <typename TClientBase>
326status_t Camera2ClientBase<TClientBase>::connect(
327 const sp<TCamCallbacks>& client) {
328 ATRACE_CALL();
329 ALOGV("%s: E", __FUNCTION__);
330 Mutex::Autolock icl(mBinderSerializationLock);
331
332 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700333 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800334
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800335 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800336 "current locked to pid %d",
337 __FUNCTION__,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800338 TClientBase::mCameraIdStr.string(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700339 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800340 TClientBase::mClientPid);
341 return BAD_VALUE;
342 }
343
Jayant Chowdhary12361932018-08-27 14:46:13 -0700344 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800345
346 TClientBase::mRemoteCallback = client;
347 mSharedCameraCallbacks = client;
348
349 return OK;
350}
351
352/** Device-related methods */
353
354template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700355void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800356 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700357 const CaptureResultExtras& resultExtras) {
358 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
359 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800360}
361
362template <typename TClientBase>
Austin Borgerc8099762023-01-12 17:08:46 -0800363void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
364 // We're only interested in this notification if overrideToPortrait is turned on.
365 if (!TClientBase::mOverrideToPortrait) {
366 return;
367 }
368
369 String8 physicalId8(physicalId.c_str());
370 auto physicalCameraMetadata = mDevice->infoPhysical(physicalId8);
371 auto orientationEntry = physicalCameraMetadata.find(ANDROID_SENSOR_ORIENTATION);
372
373 if (orientationEntry.count == 1) {
374 int orientation = orientationEntry.data.i32[0];
375 int rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
376
377 if (orientation == 0 || orientation == 180) {
378 rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_90;
379 }
380
381 static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode);
382 }
383}
384
385template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000386status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700387 if (!mDeviceActive) {
388 status_t res = TClientBase::startCameraStreamingOps();
389 if (res != OK) {
390 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
391 TClientBase::mCameraIdStr.string(), res);
392 return res;
393 }
Austin Borger74fca042022-05-23 12:41:21 -0700394 mCameraServiceProxyWrapper->logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700395 }
396 mDeviceActive = true;
397
398 ALOGV("Camera device is now active");
399 return OK;
400}
401
402template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800403void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700404 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800405 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700406 const std::string& userTag, int videoStabilizationMode) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700407 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700408 status_t res = TClientBase::finishCameraStreamingOps();
409 if (res != OK) {
410 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
411 TClientBase::mCameraIdStr.string(), res);
412 }
Austin Borger74fca042022-05-23 12:41:21 -0700413 mCameraServiceProxyWrapper->logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700414 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
415 streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700416 }
417 mDeviceActive = false;
418
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700419 ALOGV("Camera device is now idle");
420}
421
422template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700423void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800424 nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700425 (void)resultExtras;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800426 (void)timestamp;
427
Jianing Weicb0652e2014-03-12 18:29:36 -0700428 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
429 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800430}
431
432template <typename TClientBase>
433void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState,
434 int triggerId) {
435 (void)newState;
436 (void)triggerId;
437
438 ALOGV("%s: Autofocus state now %d, last trigger %d",
439 __FUNCTION__, newState, triggerId);
440
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800441}
442
443template <typename TClientBase>
444void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState,
445 int triggerId) {
446 (void)newState;
447 (void)triggerId;
448
449 ALOGV("%s: Autoexposure state now %d, last trigger %d",
450 __FUNCTION__, newState, triggerId);
451}
452
453template <typename TClientBase>
454void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState,
455 int triggerId) {
456 (void)newState;
457 (void)triggerId;
458
459 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
460 __FUNCTION__, newState, triggerId);
461}
462
463template <typename TClientBase>
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700464void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) {
465 (void)streamId;
466
467 ALOGV("%s: Stream %d now prepared",
468 __FUNCTION__, streamId);
469}
470
471template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700472void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
473
474 ALOGV("%s: Request queue now empty", __FUNCTION__);
475}
476
477template <typename TClientBase>
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700478void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) {
479 (void)lastFrameNumber;
480
481 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
482 __FUNCTION__, lastFrameNumber);
483}
484
485template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800486int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800487 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800488}
489
490template <typename TClientBase>
491const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
492 return mDevice;
493}
494
495template <typename TClientBase>
496const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800497 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800498}
499
500template <typename TClientBase>
501Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
502 SharedCameraCallbacks &client) :
503
504 mRemoteCallback(client.mRemoteCallback),
505 mSharedClient(client) {
506
507 mSharedClient.mRemoteCallbackLock.lock();
508}
509
510template <typename TClientBase>
511Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
512 mSharedClient.mRemoteCallbackLock.unlock();
513}
514
515template <typename TClientBase>
516Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
517 const sp<TCamCallbacks>&client) :
518
519 mRemoteCallback(client) {
520}
521
522template <typename TClientBase>
523typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
524Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
525 const sp<TCamCallbacks>&client) {
526
527 Mutex::Autolock l(mRemoteCallbackLock);
528 mRemoteCallback = client;
529 return *this;
530}
531
532template <typename TClientBase>
533void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
534 Mutex::Autolock l(mRemoteCallbackLock);
535 mRemoteCallback.clear();
536}
537
Cliff Wud3a05312021-04-26 23:07:31 +0800538template <typename TClientBase>
539status_t Camera2ClientBase<TClientBase>::injectCamera(const String8& injectedCamId,
540 sp<CameraProviderManager> manager) {
541 return mDevice->injectCamera(injectedCamId, manager);
542}
543
544template <typename TClientBase>
545status_t Camera2ClientBase<TClientBase>::stopInjection() {
546 return mDevice->stopInjection();
547}
548
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800549template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700550template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800551
552} // namespace android