blob: 0fe15a8b2e4464ba1f55f36477683340b224bcbb [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 Borger0fb3ad92023-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"
Shuzhen Wang316781a2020-08-18 18:11:01 -070041#include "utils/CameraServiceProxyWrapper.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080042
43namespace android {
Jayant Chowdhary48162a72022-05-27 05:37:14 +000044
Igor Murashkin44cfcf02013-03-01 16:22:28 -080045using namespace camera2;
46
Igor Murashkin44cfcf02013-03-01 16:22:28 -080047// Interface used by CameraService
48
49template <typename TClientBase>
50Camera2ClientBase<TClientBase>::Camera2ClientBase(
51 const sp<CameraService>& cameraService,
52 const sp<TCamCallbacks>& remoteCallback,
Austin Borger0fb3ad92023-06-01 16:51:35 -070053 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080054 bool systemNativeClient,
Austin Borger0fb3ad92023-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 Borger3560b7e2022-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 Borger3560b7e2022-10-27 12:20:29 -070068 clientUid, servicePid, overrideToPortrait),
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070069 mSharedCameraCallbacks(remoteCallback),
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080070 mDeviceActive(false), mApi1CameraId(api1CameraId)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080071{
Austin Borger0fb3ad92023-06-01 16:51:35 -070072 ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.c_str(),
73 clientPackageName.c_str(), 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,
Austin Borger0fb3ad92023-06-01 16:51:35 -070094 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +000095 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,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700101 const std::string& 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__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700104 TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800105 status_t res;
106
Igor Murashkine6800ce2013-03-04 17:25:57 -0800107 // Verify ops permissions
108 res = TClientBase::startCameraOps();
109 if (res != OK) {
110 return res;
111 }
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800112 IPCTransport providerTransport = IPCTransport::INVALID;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700113 res = providerPtr->getCameraIdIPCTransport(TClientBase::mCameraIdStr,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800114 &providerTransport);
115 if (res != OK) {
116 return res;
117 }
118 switch (providerTransport) {
119 case IPCTransport::HIDL:
120 mDevice =
121 new HidlCamera3Device(TClientBase::mCameraIdStr, mOverrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700122 TClientBase::mOverrideToPortrait, mLegacyClient);
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800123 break;
124 case IPCTransport::AIDL:
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000125 mDevice =
126 new AidlCamera3Device(TClientBase::mCameraIdStr, mOverrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700127 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 Borger0fb3ad92023-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 Borger0fb3ad92023-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 Borger0fb3ad92023-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
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800147 wp<NotificationListener> weakThis(this);
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700148 res = mDevice->setNotifyCallback(weakThis);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800149
Jayant Chowdhary48162a72022-05-27 05:37:14 +0000150 /** Start watchdog thread */
151 mCameraServiceWatchdog = new CameraServiceWatchdog();
152 mCameraServiceWatchdog->run("Camera2ClientBaseWatchdog");
153
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800154 return OK;
155}
156
157template <typename TClientBase>
158Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
159 ATRACE_CALL();
160
161 TClientBase::mDestructionStarted = true;
162
163 disconnect();
164
Ravneetc83d7c42022-06-03 20:51:58 +0000165 if (mCameraServiceWatchdog != NULL) {
166 mCameraServiceWatchdog->requestExit();
167 mCameraServiceWatchdog.clear();
168 }
169
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800170 ALOGI("Closed Camera %s. Client was: %s (PID %d, UID %u)",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700171 TClientBase::mCameraIdStr.c_str(),
172 TClientBase::mClientPackageName.c_str(),
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700173 mInitialClientPid, TClientBase::mClientUid);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800174}
175
176template <typename TClientBase>
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800177status_t Camera2ClientBase<TClientBase>::dumpClient(int fd,
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800178 const Vector<String16>& args) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700179 std::string result;
180 result += fmt::sprintf("Camera2ClientBase[%s] (%p) PID: %d, dump:\n",
181 TClientBase::mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -0800182 (TClientBase::getRemoteCallback() != NULL ?
Austin Borger0fb3ad92023-06-01 16:51:35 -0700183 (void *)IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800184 TClientBase::mClientPid);
Austin Borger0fb3ad92023-06-01 16:51:35 -0700185 result += " State: ";
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800186
Austin Borger0fb3ad92023-06-01 16:51:35 -0700187 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800188 // TODO: print dynamic/request section from most recent requests
189
190 return dumpDevice(fd, args);
191}
192
193template <typename TClientBase>
Austin Borger0fb3ad92023-06-01 16:51:35 -0700194status_t Camera2ClientBase<TClientBase>::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700195 sp<CameraDeviceBase> device = mDevice;
196 if (!device) {
197 dprintf(out, " Device is detached");
198 return OK;
199 }
200
201 return device->startWatchingTags(tags);
202}
203
204template <typename TClientBase>
205status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) {
206 sp<CameraDeviceBase> device = mDevice;
207 if (!device) {
208 dprintf(out, " Device is detached");
209 return OK;
210 }
211
212 return device->stopWatchingTags();
213}
214
215template <typename TClientBase>
216status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) {
217 sp<CameraDeviceBase> device = mDevice;
218 if (!device) {
219 // Nothing to dump if the device is detached
220 return OK;
221 }
222 return device->dumpWatchedEventsToVector(out);
223}
224
225template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800226status_t Camera2ClientBase<TClientBase>::dumpDevice(
227 int fd,
228 const Vector<String16>& args) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700229 std::string result;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800230
231 result = " Device dump:\n";
Austin Borger0fb3ad92023-06-01 16:51:35 -0700232 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800233
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800234 sp<CameraDeviceBase> device = mDevice;
235 if (!device.get()) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800236 result = " *** Device is detached\n";
Austin Borger0fb3ad92023-06-01 16:51:35 -0700237 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800238 return NO_ERROR;
239 }
240
Yin-Chia Yehe5138f12017-11-10 14:10:05 -0800241 status_t res = device->dump(fd, args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800242 if (res != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700243 result = fmt::sprintf(" Error dumping device: %s (%d)",
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800244 strerror(-res), res);
Austin Borger0fb3ad92023-06-01 16:51:35 -0700245 write(fd, result.c_str(), result.size());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800246 }
247
248 return NO_ERROR;
249}
250
251// ICameraClient2BaseUser interface
252
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800253template <typename TClientBase>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800254binder::Status Camera2ClientBase<TClientBase>::disconnect() {
Ravneet Dhanjal72c96652022-06-29 01:34:01 +0000255 if (mCameraServiceWatchdog != nullptr && mDevice != nullptr) {
256 // Timer for the disconnect call should be greater than getExpectedInFlightDuration
257 // since this duration is used to error handle methods in the disconnect sequence
258 // thus allowing existing error handling methods to execute first
259 uint64_t maxExpectedDuration =
260 ns2ms(mDevice->getExpectedInFlightDuration() + kBufferTimeDisconnectNs);
261
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000262 // Initialization from hal succeeded, time disconnect.
263 return mCameraServiceWatchdog->WATCH_CUSTOM_TIMER(disconnectImpl(),
Ravneet Dhanjal72c96652022-06-29 01:34:01 +0000264 maxExpectedDuration / kCycleLengthMs, kCycleLengthMs);
Jayant Chowdhary3f20d192022-05-31 17:24:39 +0000265 }
266 return disconnectImpl();
Jayant Chowdhary48162a72022-05-27 05:37:14 +0000267}
268
269template <typename TClientBase>
270binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800271 ATRACE_CALL();
Austin Borger0fb3ad92023-06-01 16:51:35 -0700272 ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800273 Mutex::Autolock icl(mBinderSerializationLock);
274
Austin Borger0fb3ad92023-06-01 16:51:35 -0700275 ALOGD("Camera %s: serializationLock acquired", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800276 binder::Status res = binder::Status::ok();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800277 // Allow both client and the media server to disconnect at all times
Jayant Chowdhary12361932018-08-27 14:46:13 -0700278 int callingPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800279 if (callingPid != TClientBase::mClientPid &&
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800280 callingPid != TClientBase::mServicePid) return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800281
Austin Borger0fb3ad92023-06-01 16:51:35 -0700282 ALOGD("Camera %s: Shutting down", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800283
Rucha Katakwardf223072021-06-15 10:21:00 -0700284 // Before detaching the device, cache the info from current open session.
285 // The disconnected check avoids duplication of info and also prevents
286 // deadlock while acquiring service lock in cacheDump.
287 if (!TClientBase::mDisconnected) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700288 ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
Rucha Katakwardf223072021-06-15 10:21:00 -0700289 Camera2ClientBase::getCameraService()->cacheDump();
290 }
291
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800292 detachDevice();
293
Igor Murashkine6800ce2013-03-04 17:25:57 -0800294 CameraService::BasicClient::disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800295
Austin Borger0fb3ad92023-06-01 16:51:35 -0700296 ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800297
298 return res;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800299}
300
301template <typename TClientBase>
302void Camera2ClientBase<TClientBase>::detachDevice() {
303 if (mDevice == 0) return;
304 mDevice->disconnect();
305
Austin Borger0fb3ad92023-06-01 16:51:35 -0700306 ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.c_str());
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800307}
308
309template <typename TClientBase>
310status_t Camera2ClientBase<TClientBase>::connect(
311 const sp<TCamCallbacks>& client) {
312 ATRACE_CALL();
313 ALOGV("%s: E", __FUNCTION__);
314 Mutex::Autolock icl(mBinderSerializationLock);
315
316 if (TClientBase::mClientPid != 0 &&
Jayant Chowdhary12361932018-08-27 14:46:13 -0700317 CameraThreadState::getCallingPid() != TClientBase::mClientPid) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800318
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800319 ALOGE("%s: Camera %s: Connection attempt from pid %d; "
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800320 "current locked to pid %d",
321 __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700322 TClientBase::mCameraIdStr.c_str(),
Jayant Chowdhary12361932018-08-27 14:46:13 -0700323 CameraThreadState::getCallingPid(),
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800324 TClientBase::mClientPid);
325 return BAD_VALUE;
326 }
327
Jayant Chowdhary12361932018-08-27 14:46:13 -0700328 TClientBase::mClientPid = CameraThreadState::getCallingPid();
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800329
330 TClientBase::mRemoteCallback = client;
331 mSharedCameraCallbacks = client;
332
333 return OK;
334}
335
336/** Device-related methods */
337
338template <typename TClientBase>
Jianing Weicb0652e2014-03-12 18:29:36 -0700339void Camera2ClientBase<TClientBase>::notifyError(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800340 int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -0700341 const CaptureResultExtras& resultExtras) {
342 ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
343 resultExtras.requestId);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800344}
345
346template <typename TClientBase>
Austin Borgerc8099762023-01-12 17:08:46 -0800347void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
348 // We're only interested in this notification if overrideToPortrait is turned on.
349 if (!TClientBase::mOverrideToPortrait) {
350 return;
351 }
352
Austin Borger0fb3ad92023-06-01 16:51:35 -0700353 auto physicalCameraMetadata = mDevice->infoPhysical(physicalId);
Austin Borgerc8099762023-01-12 17:08:46 -0800354 auto orientationEntry = physicalCameraMetadata.find(ANDROID_SENSOR_ORIENTATION);
355
356 if (orientationEntry.count == 1) {
357 int orientation = orientationEntry.data.i32[0];
358 int rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
359
360 if (orientation == 0 || orientation == 180) {
361 rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_90;
362 }
363
364 static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode);
365 }
366}
367
368template <typename TClientBase>
Austin Borger4a870a32022-02-25 01:48:41 +0000369status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700370 if (!mDeviceActive) {
371 status_t res = TClientBase::startCameraStreamingOps();
372 if (res != OK) {
373 ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700374 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700375 return res;
376 }
Austin Borger4a870a32022-02-25 01:48:41 +0000377 CameraServiceProxyWrapper::logActive(TClientBase::mCameraIdStr, maxPreviewFps);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700378 }
379 mDeviceActive = true;
380
381 ALOGV("Camera device is now active");
382 return OK;
383}
384
385template <typename TClientBase>
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800386void Camera2ClientBase<TClientBase>::notifyIdleWithUserTag(
Shuzhen Wang316781a2020-08-18 18:11:01 -0700387 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800388 const std::vector<hardware::CameraStreamStats>& streamStats,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700389 const std::string& userTag, int videoStabilizationMode) {
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700390 if (mDeviceActive) {
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700391 status_t res = TClientBase::finishCameraStreamingOps();
392 if (res != OK) {
393 ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700394 TClientBase::mCameraIdStr.c_str(), res);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -0700395 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700396 CameraServiceProxyWrapper::logIdle(TClientBase::mCameraIdStr,
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700397 requestCount, resultErrorCount, deviceError, userTag, videoStabilizationMode,
398 streamStats);
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700399 }
400 mDeviceActive = false;
401
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700402 ALOGV("Camera device is now idle");
403}
404
405template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800406void Camera2ClientBase<TClientBase>::notifyShutter(
407 [[maybe_unused]] const CaptureResultExtras& resultExtras,
408 [[maybe_unused]] nsecs_t timestamp) {
Jianing Weicb0652e2014-03-12 18:29:36 -0700409 ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64,
410 __FUNCTION__, resultExtras.requestId, timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800411}
412
413template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800414void Camera2ClientBase<TClientBase>::notifyAutoFocus([[maybe_unused]] uint8_t newState,
415 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800416 ALOGV("%s: Autofocus state now %d, last trigger %d",
417 __FUNCTION__, newState, triggerId);
418
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800419}
420
421template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800422void Camera2ClientBase<TClientBase>::notifyAutoExposure([[maybe_unused]] uint8_t newState,
423 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800424 ALOGV("%s: Autoexposure state now %d, last trigger %d",
425 __FUNCTION__, newState, triggerId);
426}
427
428template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800429void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(
430 [[maybe_unused]] uint8_t newState,
431 [[maybe_unused]] int triggerId) {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800432 ALOGV("%s: Auto-whitebalance state now %d, last trigger %d",
433 __FUNCTION__, newState, triggerId);
434}
435
436template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800437void Camera2ClientBase<TClientBase>::notifyPrepared([[maybe_unused]] int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700438 ALOGV("%s: Stream %d now prepared",
439 __FUNCTION__, streamId);
440}
441
442template <typename TClientBase>
Shuzhen Wang9d066012016-09-30 11:30:20 -0700443void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() {
444
445 ALOGV("%s: Request queue now empty", __FUNCTION__);
446}
447
448template <typename TClientBase>
Jing Mikec7f9b132023-03-12 11:12:04 +0800449void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(
450 [[maybe_unused]] long lastFrameNumber) {
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700451 ALOGV("%s: Repeating request was stopped. Last frame number is %ld",
452 __FUNCTION__, lastFrameNumber);
453}
454
455template <typename TClientBase>
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800456int Camera2ClientBase<TClientBase>::getCameraId() const {
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800457 return mApi1CameraId;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800458}
459
460template <typename TClientBase>
461const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() {
462 return mDevice;
463}
464
465template <typename TClientBase>
466const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800467 return TClientBase::sCameraService;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800468}
469
470template <typename TClientBase>
471Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock(
472 SharedCameraCallbacks &client) :
473
474 mRemoteCallback(client.mRemoteCallback),
475 mSharedClient(client) {
476
477 mSharedClient.mRemoteCallbackLock.lock();
478}
479
480template <typename TClientBase>
481Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() {
482 mSharedClient.mRemoteCallbackLock.unlock();
483}
484
485template <typename TClientBase>
486Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks(
487 const sp<TCamCallbacks>&client) :
488
489 mRemoteCallback(client) {
490}
491
492template <typename TClientBase>
493typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks&
494Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=(
495 const sp<TCamCallbacks>&client) {
496
497 Mutex::Autolock l(mRemoteCallbackLock);
498 mRemoteCallback = client;
499 return *this;
500}
501
502template <typename TClientBase>
503void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() {
504 Mutex::Autolock l(mRemoteCallbackLock);
505 mRemoteCallback.clear();
506}
507
Cliff Wud3a05312021-04-26 23:07:31 +0800508template <typename TClientBase>
Austin Borger0fb3ad92023-06-01 16:51:35 -0700509status_t Camera2ClientBase<TClientBase>::injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800510 sp<CameraProviderManager> manager) {
511 return mDevice->injectCamera(injectedCamId, manager);
512}
513
514template <typename TClientBase>
515status_t Camera2ClientBase<TClientBase>::stopInjection() {
516 return mDevice->stopInjection();
517}
518
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800519template class Camera2ClientBase<CameraService::Client>;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700520template class Camera2ClientBase<CameraDeviceClientBase>;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800521
522} // namespace android