blob: 34964d41465501710117b22741430d9aeab9d39b [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>
Austin Borger1c1bee02023-06-01 16:51:35 -070031#include <camera/StringUtils.h>
Shuzhen Wang316781a2020-08-18 18:11:01 -070032
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070033#include "common/Camera2ClientBase.h"
Igor Murashkine7ee7632013-06-11 18:10:18 -070034
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include "api2/CameraDeviceClient.h"
36
Eino-Ville Talvalad309fb92015-11-25 12:12:45 -080037#include "device3/Camera3Device.h"
Jayant Chowdhary35642f22022-01-08 00:39:39 +000038#include "device3/aidl/AidlCamera3Device.h"
Jayant Chowdhary22441f32021-12-26 18:35:41 -080039#include "device3/hidl/HidlCamera3Device.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,
Austin Borger249e6592024-03-10 22:28:11 -070052 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070053 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080054 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070055 const std::optional<std::string>& clientFeatureId,
56 const std::string& cameraId,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080057 int api1CameraId,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080058 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070059 int sensorOrientation,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080060 int clientPid,
61 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070062 int servicePid,
Emilian Peev5104fe92021-10-21 14:27:09 -070063 bool overrideForPerfClass,
Austin Borger18b30a72022-10-27 12:20:29 -070064 bool overrideToPortrait,
Emilian Peev5104fe92021-10-21 14:27:09 -070065 bool legacyClient):
Austin Borger249e6592024-03-10 22:28:11 -070066 TClientBase(cameraService, remoteCallback, attributionAndPermissionUtils, clientPackageName,
67 systemNativeClient, clientFeatureId, cameraId, api1CameraId, cameraFacing,
68 sensorOrientation, clientPid, clientUid, servicePid, overrideToPortrait),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070069 mSharedCameraCallbacks(remoteCallback),
Austin Borger74fca042022-05-23 12:41:21 -070070 mCameraServiceProxyWrapper(cameraServiceProxyWrapper),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080071 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080072{
Austin Borger1c1bee02023-06-01 16:51:35 -070073 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.c_str(),
74 clientPackageName.c_str(), clientPid, clientUid);
Igor Murashkin98e24722013-06-19 19:51:04 -070075
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -070076 mInitialClientPid = clientPid;
Jayant Chowdhary22441f32021-12-26 18:35:41 -080077 mOverrideForPerfClass = overrideForPerfClass;
78 mLegacyClient = legacyClient;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080079}
80
81template <typename TClientBase>
82status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation)
83 const {
84
Austin Borger22c5c852024-03-08 13:31:36 -080085 int callingPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080086 if (callingPid == TClientBase::mClientPid) return NO_ERROR;
87
88 ALOGE("%s: attempt to use a locked camera from a different process"
89 " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid);
90 return PERMISSION_DENIED;
91}
92
93template <typename TClientBase>
Emilian Peevbd8c5032018-02-14 23:05:40 +000094status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -070095 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +000096 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080097}
98
99template <typename TClientBase>
100template <typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +0000101status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr,
Austin Borger1c1bee02023-06-01 16:51:35 -0700102 const std::string& monitorTags) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800103 ATRACE_CALL();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800104 ALOGV("%s: Initializing client for camera %s", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700105 TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800106 status_t res;
107
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800108 IPCTransport providerTransport = IPCTransport::INVALID;
Austin Borger1c1bee02023-06-01 16:51:35 -0700109 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800110 &providerTransport);
111 if (res != OK) {
112 return res;
113 }
114 switch (providerTransport) {
115 case IPCTransport::HIDL:
116 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700117 new HidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger22c5c852024-03-08 13:31:36 -0800118 TClientBase::mAttributionAndPermissionUtils,
Austin Borger18b30a72022-10-27 12:20:29 -0700119 TClientBase::mCameraIdStr, mOverrideForPerfClass,
120 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800121 break;
122 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000123 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700124 new AidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger22c5c852024-03-08 13:31:36 -0800125 TClientBase::mAttributionAndPermissionUtils,
Austin Borger18b30a72022-10-27 12:20:29 -0700126 TClientBase::mCameraIdStr, mOverrideForPerfClass,
127 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000128 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800129 default:
130 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700131 TClientBase::mCameraIdStr.c_str());
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800132 return NO_INIT;
133 }
Igor Murashkine6800ce2013-03-04 17:25:57 -0800134 if (mDevice == NULL) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800135 ALOGE("%s: Camera %s: No device connected",
Austin Borger1c1bee02023-06-01 16:51:35 -0700136 __FUNCTION__, TClientBase::mCameraIdStr.c_str());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800137 return NO_INIT;
138 }
139
Emilian Peevbd8c5032018-02-14 23:05:40 +0000140 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800141 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800142 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700143 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Zhijun He66281c32013-09-13 17:59:59 -0700144 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800145 }
146
Emilian Peevfa17f092022-07-29 13:28:55 -0700147 // Verify ops permissions
148 res = TClientBase::startCameraOps();
149 if (res != OK) {
150 TClientBase::finishCameraOps();
Emilian Peevfa17f092022-07-29 13:28:55 -0700151 return res;
152 }
153
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800154 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700155 res = mDevice->setNotifyCallback(weakThis);
Austin Borger7b129542022-06-09 13:23:06 -0700156 if (res != OK) {
157 ALOGE("%s: Camera %s: Unable to set notify callback: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700158 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Austin Borger7b129542022-06-09 13:23:06 -0700159 return res;
160 }
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800161
162 return OK;
163}
164
165template <typename TClientBase>
166Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
167 ATRACE_CALL();
168
169 TClientBase::mDestructionStarted = true;
170
171 disconnect();
172
Jayant Chowdhary3ab499d2022-06-15 15:43:33 -0700173 ALOGI("%s: Client object's dtor for Camera Id %s completed. Client was: %s (PID %d, UID %u)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700174 __FUNCTION__, TClientBase::mCameraIdStr.c_str(),
175 TClientBase::mClientPackageName.c_str(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700176 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800177}
178
179template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800180status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800181 const Vector<String16>& args) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700182 std::string result;
183 result += fmt::sprintf("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
184 TClientBase::mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800185 (TClientBase::getRemoteCallback() != NULL ?
Austin Borger1c1bee02023-06-01 16:51:35 -0700186 (void *)IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800187 TClientBase::mClientPid);
Austin Borger1c1bee02023-06-01 16:51:35 -0700188 result += " State: ";
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800189
Austin Borger1c1bee02023-06-01 16:51:35 -0700190 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800191 // TODO: print dynamic/request section from most recent requests
192
193 return dumpDevice(fd, args);
194}
195
196template <typename TClientBase>
Austin Borger1c1bee02023-06-01 16:51:35 -0700197status_t Camera2ClientBase<TClientBase>::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700198 sp<CameraDeviceBase> device = mDevice;
199 if (!device) {
200 dprintf(out, " Device is detached");
201 return OK;
202 }
203
204 return device->startWatchingTags(tags);
205}
206
207template <typename TClientBase>
208status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
209 sp<CameraDeviceBase> device = mDevice;
210 if (!device) {
211 dprintf(out, " Device is detached");
212 return OK;
213 }
214
215 return device->stopWatchingTags();
216}
217
218template <typename TClientBase>
219status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
220 sp<CameraDeviceBase> device = mDevice;
221 if (!device) {
222 // Nothing to dump if the device is detached
223 return OK;
224 }
225 return device->dumpWatchedEventsToVector(out);
226}
227
228template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800229status_t Camera2ClientBase<TClientBase>::dumpDevice(
230 int fd,
231 const Vector<String16>& args) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700232 std::string result;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800233
234 result = " Device dump:\n";
Austin Borger1c1bee02023-06-01 16:51:35 -0700235 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800236
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800237 sp<CameraDeviceBase> device = mDevice;
238 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800239 result = " *** Device is detached\n";
Austin Borger1c1bee02023-06-01 16:51:35 -0700240 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800241 return NO_ERROR;
242 }
243
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800244 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800245 if (res != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700246 result = fmt::sprintf(" Error dumping device: %s (%d)",
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800247 strerror(-res), res);
Austin Borger1c1bee02023-06-01 16:51:35 -0700248 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800249 }
250
251 return NO_ERROR;
252}
253
254// ICameraClient2BaseUser interface
255
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800256template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800257binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjalbaa324b2023-10-11 01:19:18 +0000258
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000259 return disconnectImpl();
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000260}
261
262template <typename TClientBase>
263binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800264 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700265 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800266 Mutex::Autolock icl(mBinderSerializationLock);
267
Austin Borger1c1bee02023-06-01 16:51:35 -0700268 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800269 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800270 // Allow both client and the media server to disconnect at all times
Austin Borger22c5c852024-03-08 13:31:36 -0800271 int callingPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800272 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800273 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800274
Austin Borger1c1bee02023-06-01 16:51:35 -0700275 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800276
Rucha Katakwardf223072021-06-15 10:21:00 -0700277 // Before detaching the device, cache the info from current open session.
278 // The disconnected check avoids duplication of info and also prevents
279 // deadlock while acquiring service lock in cacheDump.
280 if (!TClientBase::mDisconnected) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700281 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
Rucha Katakwardf223072021-06-15 10:21:00 -0700282 Camera2ClientBase::getCameraService()->cacheDump();
283 }
284
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800285 detachDevice();
286
Igor Murashkine6800ce2013-03-04 17:25:57 -0800287 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800288
Austin Borger1c1bee02023-06-01 16:51:35 -0700289 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800290
291 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800292}
293
294template <typename TClientBase>
295void Camera2ClientBase<TClientBase>::detachDevice() {
296 if (mDevice == 0) return;
297 mDevice->disconnect();
298
Austin Borger1c1bee02023-06-01 16:51:35 -0700299 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800300}
301
302template <typename TClientBase>
303status_t Camera2ClientBase<TClientBase>::connect(
304 const sp<TCamCallbacks>& client) {
305 ATRACE_CALL();
306 ALOGV("%s: E", __FUNCTION__);
307 Mutex::Autolock icl(mBinderSerializationLock);
308
309 if (TClientBase::mClientPid != 0 &&
Austin Borger22c5c852024-03-08 13:31:36 -0800310 TClientBase::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800311
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800312 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800313 "current locked to pid %d",
314 __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700315 TClientBase::mCameraIdStr.c_str(),
Austin Borger22c5c852024-03-08 13:31:36 -0800316 TClientBase::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800317 TClientBase::mClientPid);
318 return BAD_VALUE;
319 }
320
Austin Borger22c5c852024-03-08 13:31:36 -0800321 TClientBase::mClientPid = TClientBase::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800322
323 TClientBase::mRemoteCallback = client;
324 mSharedCameraCallbacks = client;
325
326 return OK;
327}
328
329/** Device-related methods */
330
331template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700332void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800333 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700334 const CaptureResultExtras& resultExtras) {
335 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
336 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800337}
338
339template <typename TClientBase>
Austin Borgerc8099762023-01-12 17:08:46 -0800340void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
341 // We're only interested in this notification if overrideToPortrait is turned on.
342 if (!TClientBase::mOverrideToPortrait) {
343 return;
344 }
345
Austin Borger1c1bee02023-06-01 16:51:35 -0700346 auto physicalCameraMetadata = mDevice->infoPhysical(physicalId);
Austin Borgerc8099762023-01-12 17:08:46 -0800347 auto orientationEntry = physicalCameraMetadata.find(ANDROID_SENSOR_ORIENTATION);
348
349 if (orientationEntry.count == 1) {
350 int orientation = orientationEntry.data.i32[0];
351 int rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
352
353 if (orientation == 0 || orientation == 180) {
354 rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_90;
355 }
356
Jayant Chowdhary44d5f622023-09-20 03:11:41 +0000357 static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode,
358 /*fromHal*/ true);
Austin Borgerc8099762023-01-12 17:08:46 -0800359 }
360}
361
362template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000363status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700364 if (!mDeviceActive) {
365 status_t res = TClientBase::startCameraStreamingOps();
366 if (res != OK) {
367 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700368 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700369 return res;
370 }
Austin Borger74fca042022-05-23 12:41:21 -0700371 mCameraServiceProxyWrapper->logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700372 }
373 mDeviceActive = true;
374
375 ALOGV("Camera device is now active");
376 return OK;
377}
378
379template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800380void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700381 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800382 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000383 const std::string& userTag, int videoStabilizationMode, bool usedUltraWide,
384 bool usedZoomOverride) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700385 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700386 status_t res = TClientBase::finishCameraStreamingOps();
387 if (res != OK) {
388 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700389 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700390 }
Austin Borger74fca042022-05-23 12:41:21 -0700391 mCameraServiceProxyWrapper->logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700392 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000393 usedUltraWide, usedZoomOverride, streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700394 }
395 mDeviceActive = false;
396
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700397 ALOGV("Camera device is now idle");
398}
399
400template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800401void Camera2ClientBase<TClientBase>::notifyShutter(
402 [[maybe_unused]] const CaptureResultExtras& resultExtras,
403 [[maybe_unused]] nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700404 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
405 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800406}
407
408template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800409void Camera2ClientBase<TClientBase>::notifyAutoFocus([[maybe_unused]] uint8_t newState,
410 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800411 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>
Jing Mikec7f9b132023-03-12 11:12:04 +0800417void Camera2ClientBase<TClientBase>::notifyAutoExposure([[maybe_unused]] uint8_t newState,
418 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800419 ALOGV("%s: Autoexposure state now %d, last trigger %d",
420 __FUNCTION__, newState, triggerId);
421}
422
423template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800424void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(
425 [[maybe_unused]] uint8_t newState,
426 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800427 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
428 __FUNCTION__, newState, triggerId);
429}
430
431template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800432void Camera2ClientBase<TClientBase>::notifyPrepared([[maybe_unused]] int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700433 ALOGV("%s: Stream %d now prepared",
434 __FUNCTION__, streamId);
435}
436
437template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700438void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
439
440 ALOGV("%s: Request queue now empty", __FUNCTION__);
441}
442
443template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800444void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(
445 [[maybe_unused]] long lastFrameNumber) {
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700446 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
447 __FUNCTION__, lastFrameNumber);
448}
449
450template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800451int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800452 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800453}
454
455template <typename TClientBase>
456const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
457 return mDevice;
458}
459
460template <typename TClientBase>
461const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800462 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800463}
464
465template <typename TClientBase>
466Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
467 SharedCameraCallbacks &client) :
468
469 mRemoteCallback(client.mRemoteCallback),
470 mSharedClient(client) {
471
472 mSharedClient.mRemoteCallbackLock.lock();
473}
474
475template <typename TClientBase>
476Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
477 mSharedClient.mRemoteCallbackLock.unlock();
478}
479
480template <typename TClientBase>
481Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
482 const sp<TCamCallbacks>&client) :
483
484 mRemoteCallback(client) {
485}
486
487template <typename TClientBase>
488typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
489Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
490 const sp<TCamCallbacks>&client) {
491
492 Mutex::Autolock l(mRemoteCallbackLock);
493 mRemoteCallback = client;
494 return *this;
495}
496
497template <typename TClientBase>
498void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
499 Mutex::Autolock l(mRemoteCallbackLock);
500 mRemoteCallback.clear();
501}
502
Cliff Wud3a05312021-04-26 23:07:31 +0800503template <typename TClientBase>
Austin Borger1c1bee02023-06-01 16:51:35 -0700504status_t Camera2ClientBase<TClientBase>::injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800505 sp<CameraProviderManager> manager) {
506 return mDevice->injectCamera(injectedCamId, manager);
507}
508
509template <typename TClientBase>
510status_t Camera2ClientBase<TClientBase>::stopInjection() {
511 return mDevice->stopInjection();
512}
513
malikakash22af94c2023-12-04 18:13:14 +0000514template <typename TClientBase>
515status_t Camera2ClientBase<TClientBase>::injectSessionParams(
516 const CameraMetadata& sessionParams) {
517 return mDevice->injectSessionParams(sessionParams);
518}
519
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800520template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700521template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800522
523} // namespace android