blob: 4a8d7a3c22696d8ca82d79bedf598788dc69fa21 [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 Borgered99f642023-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"
Jayant Chowdhary12361932018-08-27 14:46:13 -070040#include "utils/CameraThreadState.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080041
42namespace android {
Jayant Chowdhary620763f2022-05-27 05:37:14 +000043
Igor Murashkin44cfcf02013-03-01 16:22:28 -080044using namespace camera2;
45
Igor Murashkin44cfcf02013-03-01 16:22:28 -080046// Interface used by CameraService
47
48template <typename TClientBase>
49Camera2ClientBase<TClientBase>::Camera2ClientBase(
50 const sp<CameraService>& cameraService,
51 const sp<TCamCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070052 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borgered99f642023-06-01 16:51:35 -070053 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080054 bool systemNativeClient,
Austin Borgered99f642023-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):
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080066 TClientBase(cameraService, remoteCallback, clientPackageName, systemNativeClient,
67 clientFeatureId, cameraId, api1CameraId, cameraFacing, sensorOrientation, clientPid,
Austin Borger18b30a72022-10-27 12:20:29 -070068 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 Borgered99f642023-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
Jayant Chowdhary12361932018-08-27 14:46:13 -070085 int callingPid = CameraThreadState::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 Borgered99f642023-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 Borgered99f642023-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 Borgered99f642023-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 Borgered99f642023-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 Borger18b30a72022-10-27 12:20:29 -0700118 TClientBase::mCameraIdStr, mOverrideForPerfClass,
119 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800120 break;
121 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000122 mDevice =
Austin Borger74fca042022-05-23 12:41:21 -0700123 new AidlCamera3Device(mCameraServiceProxyWrapper,
Austin Borger18b30a72022-10-27 12:20:29 -0700124 TClientBase::mCameraIdStr, mOverrideForPerfClass,
125 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000126 break;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800127 default:
128 ALOGE("%s Invalid transport for camera id %s", __FUNCTION__,
Austin Borgered99f642023-06-01 16:51:35 -0700129 TClientBase::mCameraIdStr.c_str());
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800130 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",
Austin Borgered99f642023-06-01 16:51:35 -0700134 __FUNCTION__, TClientBase::mCameraIdStr.c_str());
Igor Murashkine6800ce2013-03-04 17:25:57 -0800135 return NO_INIT;
136 }
137
Emilian Peev510546a2024-03-07 01:21:28 +0000138 // Verify ops permissions
139 res = TClientBase::startCameraOps();
140 if (res != OK) {
141 TClientBase::finishCameraOps();
142 return res;
143 }
144
Emilian Peevbd8c5032018-02-14 23:05:40 +0000145 res = mDevice->initialize(providerPtr, monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800146 if (res != OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800147 ALOGE("%s: Camera %s: unable to initialize device: %s (%d)",
Austin Borgered99f642023-06-01 16:51:35 -0700148 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Emilian Peevfa17f092022-07-29 13:28:55 -0700149 TClientBase::finishCameraOps();
Emilian Peevfa17f092022-07-29 13:28:55 -0700150 return res;
151 }
152
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800153 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700154 res = mDevice->setNotifyCallback(weakThis);
Austin Borger7b129542022-06-09 13:23:06 -0700155 if (res != OK) {
156 ALOGE("%s: Camera %s: Unable to set notify callback: %s (%d)",
Austin Borgered99f642023-06-01 16:51:35 -0700157 __FUNCTION__, TClientBase::mCameraIdStr.c_str(), strerror(-res), res);
Austin Borger7b129542022-06-09 13:23:06 -0700158 return res;
159 }
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800160
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000161 /** Start watchdog thread */
Shuzhen Wang03fe6232023-02-05 12:41:15 -0800162 mCameraServiceWatchdog = new CameraServiceWatchdog(TClientBase::mCameraIdStr,
163 mCameraServiceProxyWrapper);
Austin Borger7b129542022-06-09 13:23:06 -0700164 res = mCameraServiceWatchdog->run("Camera2ClientBaseWatchdog");
165 if (res != OK) {
166 ALOGE("%s: Unable to start camera service watchdog thread: %s (%d)",
167 __FUNCTION__, strerror(-res), res);
168 return res;
169 }
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000170
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800171 return OK;
172}
173
174template <typename TClientBase>
175Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
176 ATRACE_CALL();
177
178 TClientBase::mDestructionStarted = true;
179
180 disconnect();
181
Ravneetc83d7c42022-06-03 20:51:58 +0000182 if (mCameraServiceWatchdog != NULL) {
183 mCameraServiceWatchdog->requestExit();
184 mCameraServiceWatchdog.clear();
185 }
186
Jayant Chowdhary3ab499d2022-06-15 15:43:33 -0700187 ALOGI("%s: Client object's dtor for Camera Id %s completed. Client was: %s (PID %d, UID %u)",
Austin Borgered99f642023-06-01 16:51:35 -0700188 __FUNCTION__, TClientBase::mCameraIdStr.c_str(),
189 TClientBase::mClientPackageName.c_str(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700190 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800191}
192
193template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800194status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800195 const Vector<String16>& args) {
Austin Borgered99f642023-06-01 16:51:35 -0700196 std::string result;
197 result += fmt::sprintf("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
198 TClientBase::mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800199 (TClientBase::getRemoteCallback() != NULL ?
Austin Borgered99f642023-06-01 16:51:35 -0700200 (void *)IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800201 TClientBase::mClientPid);
Austin Borgered99f642023-06-01 16:51:35 -0700202 result += " State: ";
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800203
Austin Borgered99f642023-06-01 16:51:35 -0700204 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800205 // TODO: print dynamic/request section from most recent requests
206
207 return dumpDevice(fd, args);
208}
209
210template <typename TClientBase>
Austin Borgered99f642023-06-01 16:51:35 -0700211status_t Camera2ClientBase<TClientBase>::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700212 sp<CameraDeviceBase> device = mDevice;
213 if (!device) {
214 dprintf(out, " Device is detached");
215 return OK;
216 }
217
218 return device->startWatchingTags(tags);
219}
220
221template <typename TClientBase>
222status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
223 sp<CameraDeviceBase> device = mDevice;
224 if (!device) {
225 dprintf(out, " Device is detached");
226 return OK;
227 }
228
229 return device->stopWatchingTags();
230}
231
232template <typename TClientBase>
233status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
234 sp<CameraDeviceBase> device = mDevice;
235 if (!device) {
236 // Nothing to dump if the device is detached
237 return OK;
238 }
239 return device->dumpWatchedEventsToVector(out);
240}
241
242template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800243status_t Camera2ClientBase<TClientBase>::dumpDevice(
244 int fd,
245 const Vector<String16>& args) {
Austin Borgered99f642023-06-01 16:51:35 -0700246 std::string result;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800247
248 result = " Device dump:\n";
Austin Borgered99f642023-06-01 16:51:35 -0700249 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800250
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800251 sp<CameraDeviceBase> device = mDevice;
252 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800253 result = " *** Device is detached\n";
Austin Borgered99f642023-06-01 16:51:35 -0700254 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800255 return NO_ERROR;
256 }
257
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800258 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800259 if (res != OK) {
Austin Borgered99f642023-06-01 16:51:35 -0700260 result = fmt::sprintf(" Error dumping device: %s (%d)",
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800261 strerror(-res), res);
Austin Borgered99f642023-06-01 16:51:35 -0700262 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800263 }
264
265 return NO_ERROR;
266}
267
268// ICameraClient2BaseUser interface
269
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800270template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800271binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000272 if (mCameraServiceWatchdog != nullptr && mDevice != nullptr) {
273 // Timer for the disconnect call should be greater than getExpectedInFlightDuration
274 // since this duration is used to error handle methods in the disconnect sequence
275 // thus allowing existing error handling methods to execute first
276 uint64_t maxExpectedDuration =
277 ns2ms(mDevice->getExpectedInFlightDuration() + kBufferTimeDisconnectNs);
278
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000279 // Initialization from hal succeeded, time disconnect.
280 return mCameraServiceWatchdog->WATCH_CUSTOM_TIMER(disconnectImpl(),
Ravneet Dhanjal7d412d22022-06-29 01:34:01 +0000281 maxExpectedDuration / kCycleLengthMs, kCycleLengthMs);
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000282 }
283 return disconnectImpl();
Jayant Chowdhary620763f2022-05-27 05:37:14 +0000284}
285
286template <typename TClientBase>
287binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800288 ATRACE_CALL();
Austin Borgered99f642023-06-01 16:51:35 -0700289 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800290 Mutex::Autolock icl(mBinderSerializationLock);
291
Austin Borgered99f642023-06-01 16:51:35 -0700292 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800293 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800294 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700295 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800296 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800297 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800298
Austin Borgered99f642023-06-01 16:51:35 -0700299 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800300
Rucha Katakwardf223072021-06-15 10:21:00 -0700301 // Before detaching the device, cache the info from current open session.
302 // The disconnected check avoids duplication of info and also prevents
303 // deadlock while acquiring service lock in cacheDump.
304 if (!TClientBase::mDisconnected) {
Austin Borgered99f642023-06-01 16:51:35 -0700305 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
Rucha Katakwardf223072021-06-15 10:21:00 -0700306 Camera2ClientBase::getCameraService()->cacheDump();
307 }
308
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800309 detachDevice();
310
Igor Murashkine6800ce2013-03-04 17:25:57 -0800311 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800312
Austin Borgered99f642023-06-01 16:51:35 -0700313 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800314
315 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800316}
317
318template <typename TClientBase>
319void Camera2ClientBase<TClientBase>::detachDevice() {
320 if (mDevice == 0) return;
321 mDevice->disconnect();
322
Austin Borgered99f642023-06-01 16:51:35 -0700323 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800324}
325
326template <typename TClientBase>
327status_t Camera2ClientBase<TClientBase>::connect(
328 const sp<TCamCallbacks>& client) {
329 ATRACE_CALL();
330 ALOGV("%s: E", __FUNCTION__);
331 Mutex::Autolock icl(mBinderSerializationLock);
332
333 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700334 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800335
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800336 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800337 "current locked to pid %d",
338 __FUNCTION__,
Austin Borgered99f642023-06-01 16:51:35 -0700339 TClientBase::mCameraIdStr.c_str(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700340 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800341 TClientBase::mClientPid);
342 return BAD_VALUE;
343 }
344
Jayant Chowdhary12361932018-08-27 14:46:13 -0700345 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800346
347 TClientBase::mRemoteCallback = client;
348 mSharedCameraCallbacks = client;
349
350 return OK;
351}
352
353/** Device-related methods */
354
355template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700356void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800357 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700358 const CaptureResultExtras& resultExtras) {
359 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
360 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800361}
362
363template <typename TClientBase>
Austin Borgerc8099762023-01-12 17:08:46 -0800364void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
365 // We're only interested in this notification if overrideToPortrait is turned on.
366 if (!TClientBase::mOverrideToPortrait) {
367 return;
368 }
369
Austin Borgered99f642023-06-01 16:51:35 -0700370 auto physicalCameraMetadata = mDevice->infoPhysical(physicalId);
Austin Borgerc8099762023-01-12 17:08:46 -0800371 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
Jayant Chowdhary44d5f622023-09-20 03:11:41 +0000381 static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode,
382 /*fromHal*/ true);
Austin Borgerc8099762023-01-12 17:08:46 -0800383 }
384}
385
386template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000387status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700388 if (!mDeviceActive) {
389 status_t res = TClientBase::startCameraStreamingOps();
390 if (res != OK) {
391 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
Austin Borgered99f642023-06-01 16:51:35 -0700392 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700393 return res;
394 }
Austin Borger74fca042022-05-23 12:41:21 -0700395 mCameraServiceProxyWrapper->logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700396 }
397 mDeviceActive = true;
398
399 ALOGV("Camera device is now active");
400 return OK;
401}
402
403template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800404void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700405 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800406 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700407 const std::string& userTag, int videoStabilizationMode) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700408 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700409 status_t res = TClientBase::finishCameraStreamingOps();
410 if (res != OK) {
411 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
Austin Borgered99f642023-06-01 16:51:35 -0700412 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700413 }
Austin Borger74fca042022-05-23 12:41:21 -0700414 mCameraServiceProxyWrapper->logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700415 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
416 streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700417 }
418 mDeviceActive = false;
419
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700420 ALOGV("Camera device is now idle");
421}
422
423template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800424void Camera2ClientBase<TClientBase>::notifyShutter(
425 [[maybe_unused]] const CaptureResultExtras& resultExtras,
426 [[maybe_unused]] nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700427 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
428 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800429}
430
431template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800432void Camera2ClientBase<TClientBase>::notifyAutoFocus([[maybe_unused]] uint8_t newState,
433 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800434 ALOGV("%s: Autofocus state now %d, last trigger %d",
435 __FUNCTION__, newState, triggerId);
436
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800437}
438
439template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800440void Camera2ClientBase<TClientBase>::notifyAutoExposure([[maybe_unused]] uint8_t newState,
441 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800442 ALOGV("%s: Autoexposure state now %d, last trigger %d",
443 __FUNCTION__, newState, triggerId);
444}
445
446template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800447void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(
448 [[maybe_unused]] uint8_t newState,
449 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800450 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
451 __FUNCTION__, newState, triggerId);
452}
453
454template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800455void Camera2ClientBase<TClientBase>::notifyPrepared([[maybe_unused]] int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700456 ALOGV("%s: Stream %d now prepared",
457 __FUNCTION__, streamId);
458}
459
460template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700461void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
462
463 ALOGV("%s: Request queue now empty", __FUNCTION__);
464}
465
466template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800467void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(
468 [[maybe_unused]] long lastFrameNumber) {
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700469 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
470 __FUNCTION__, lastFrameNumber);
471}
472
473template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800474int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800475 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800476}
477
478template <typename TClientBase>
479const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
480 return mDevice;
481}
482
483template <typename TClientBase>
484const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800485 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800486}
487
488template <typename TClientBase>
489Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
490 SharedCameraCallbacks &client) :
491
492 mRemoteCallback(client.mRemoteCallback),
493 mSharedClient(client) {
494
495 mSharedClient.mRemoteCallbackLock.lock();
496}
497
498template <typename TClientBase>
499Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
500 mSharedClient.mRemoteCallbackLock.unlock();
501}
502
503template <typename TClientBase>
504Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
505 const sp<TCamCallbacks>&client) :
506
507 mRemoteCallback(client) {
508}
509
510template <typename TClientBase>
511typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
512Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
513 const sp<TCamCallbacks>&client) {
514
515 Mutex::Autolock l(mRemoteCallbackLock);
516 mRemoteCallback = client;
517 return *this;
518}
519
520template <typename TClientBase>
521void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
522 Mutex::Autolock l(mRemoteCallbackLock);
523 mRemoteCallback.clear();
524}
525
Cliff Wud3a05312021-04-26 23:07:31 +0800526template <typename TClientBase>
Austin Borgered99f642023-06-01 16:51:35 -0700527status_t Camera2ClientBase<TClientBase>::injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800528 sp<CameraProviderManager> manager) {
529 return mDevice->injectCamera(injectedCamId, manager);
530}
531
532template <typename TClientBase>
533status_t Camera2ClientBase<TClientBase>::stopInjection() {
534 return mDevice->stopInjection();
535}
536
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800537template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700538template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800539
540} // namespace android