Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1 | /* |
| 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 Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 21 | #include <inttypes.h> |
| 22 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 23 | #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 Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 29 | |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 30 | #include <camera/CameraSessionStats.h> |
| 31 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 32 | #include "common/Camera2ClientBase.h" |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 33 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 34 | #include "api2/CameraDeviceClient.h" |
| 35 | |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 36 | #include "device3/Camera3Device.h" |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 37 | #include "utils/CameraThreadState.h" |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 38 | #include "utils/CameraServiceProxyWrapper.h" |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 39 | |
| 40 | namespace android { |
| 41 | using namespace camera2; |
| 42 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 43 | // Interface used by CameraService |
| 44 | |
| 45 | template <typename TClientBase> |
| 46 | Camera2ClientBase<TClientBase>::Camera2ClientBase( |
| 47 | const sp<CameraService>& cameraService, |
| 48 | const sp<TCamCallbacks>& remoteCallback, |
| 49 | const String16& clientPackageName, |
Jooyung Han | 3f9a3b4 | 2020-01-23 12:27:18 +0900 | [diff] [blame] | 50 | const std::optional<String16>& clientFeatureId, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 51 | const String8& cameraId, |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 52 | int api1CameraId, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 53 | int cameraFacing, |
Emilian Peev | 8b64f28 | 2021-03-25 16:49:57 -0700 | [diff] [blame] | 54 | int sensorOrientation, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 55 | int clientPid, |
| 56 | uid_t clientUid, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 57 | int servicePid, |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 58 | bool overrideForPerfClass, |
| 59 | bool legacyClient): |
Philip P. Moltmann | 9e648f6 | 2019-11-04 12:52:45 -0800 | [diff] [blame] | 60 | TClientBase(cameraService, remoteCallback, clientPackageName, clientFeatureId, |
Emilian Peev | 8b64f28 | 2021-03-25 16:49:57 -0700 | [diff] [blame] | 61 | cameraId, api1CameraId, cameraFacing, sensorOrientation, clientPid, clientUid, |
| 62 | servicePid), |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 63 | mSharedCameraCallbacks(remoteCallback), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 64 | mDeviceVersion(cameraService->getDeviceVersion(TClientBase::mCameraIdStr)), |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 65 | mDevice(new Camera3Device(cameraId, overrideForPerfClass, legacyClient)), |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 66 | mDeviceActive(false), mApi1CameraId(api1CameraId) |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 67 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 68 | ALOGI("Camera %s: Opened. Client: %s (PID %d, UID %d)", cameraId.string(), |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 69 | String8(clientPackageName).string(), clientPid, clientUid); |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 70 | |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 71 | mInitialClientPid = clientPid; |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 72 | LOG_ALWAYS_FATAL_IF(mDevice == 0, "Device should never be NULL here."); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | template <typename TClientBase> |
| 76 | status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation) |
| 77 | const { |
| 78 | |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 79 | int callingPid = CameraThreadState::getCallingPid(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 80 | if (callingPid == TClientBase::mClientPid) return NO_ERROR; |
| 81 | |
| 82 | ALOGE("%s: attempt to use a locked camera from a different process" |
| 83 | " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid); |
| 84 | return PERMISSION_DENIED; |
| 85 | } |
| 86 | |
| 87 | template <typename TClientBase> |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 88 | status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager, |
| 89 | const String8& monitorTags) { |
| 90 | return initializeImpl(manager, monitorTags); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | template <typename TClientBase> |
| 94 | template <typename TProviderPtr> |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 95 | status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr, |
| 96 | const String8& monitorTags) { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 97 | ATRACE_CALL(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 98 | ALOGV("%s: Initializing client for camera %s", __FUNCTION__, |
| 99 | TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 100 | status_t res; |
| 101 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 102 | // Verify ops permissions |
| 103 | res = TClientBase::startCameraOps(); |
| 104 | if (res != OK) { |
| 105 | return res; |
| 106 | } |
| 107 | |
| 108 | if (mDevice == NULL) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 109 | ALOGE("%s: Camera %s: No device connected", |
| 110 | __FUNCTION__, TClientBase::mCameraIdStr.string()); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 111 | return NO_INIT; |
| 112 | } |
| 113 | |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 114 | res = mDevice->initialize(providerPtr, monitorTags); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 115 | if (res != OK) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 116 | ALOGE("%s: Camera %s: unable to initialize device: %s (%d)", |
| 117 | __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res); |
Zhijun He | 66281c3 | 2013-09-13 17:59:59 -0700 | [diff] [blame] | 118 | return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 121 | wp<NotificationListener> weakThis(this); |
Yin-Chia Yeh | e1c8063 | 2016-08-08 14:48:05 -0700 | [diff] [blame] | 122 | res = mDevice->setNotifyCallback(weakThis); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 123 | |
| 124 | return OK; |
| 125 | } |
| 126 | |
| 127 | template <typename TClientBase> |
| 128 | Camera2ClientBase<TClientBase>::~Camera2ClientBase() { |
| 129 | ATRACE_CALL(); |
| 130 | |
| 131 | TClientBase::mDestructionStarted = true; |
| 132 | |
| 133 | disconnect(); |
| 134 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 135 | ALOGI("Closed Camera %s. Client was: %s (PID %d, UID %u)", |
| 136 | TClientBase::mCameraIdStr.string(), |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 137 | String8(TClientBase::mClientPackageName).string(), |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 138 | mInitialClientPid, TClientBase::mClientUid); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | template <typename TClientBase> |
Eino-Ville Talvala | c400396 | 2016-01-13 10:07:04 -0800 | [diff] [blame] | 142 | status_t Camera2ClientBase<TClientBase>::dumpClient(int fd, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 143 | const Vector<String16>& args) { |
| 144 | String8 result; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 145 | result.appendFormat("Camera2ClientBase[%s] (%p) PID: %d, dump:\n", |
| 146 | TClientBase::mCameraIdStr.string(), |
Eino-Ville Talvala | e992e75 | 2014-11-07 16:17:48 -0800 | [diff] [blame] | 147 | (TClientBase::getRemoteCallback() != NULL ? |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 148 | IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL), |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 149 | TClientBase::mClientPid); |
| 150 | result.append(" State: "); |
| 151 | |
| 152 | write(fd, result.string(), result.size()); |
| 153 | // TODO: print dynamic/request section from most recent requests |
| 154 | |
| 155 | return dumpDevice(fd, args); |
| 156 | } |
| 157 | |
| 158 | template <typename TClientBase> |
Avichal Rakesh | 7e53cad | 2021-10-05 13:46:30 -0700 | [diff] [blame] | 159 | status_t Camera2ClientBase<TClientBase>::startWatchingTags(const String8 &tags, int out) { |
| 160 | sp<CameraDeviceBase> device = mDevice; |
| 161 | if (!device) { |
| 162 | dprintf(out, " Device is detached"); |
| 163 | return OK; |
| 164 | } |
| 165 | |
| 166 | return device->startWatchingTags(tags); |
| 167 | } |
| 168 | |
| 169 | template <typename TClientBase> |
| 170 | status_t Camera2ClientBase<TClientBase>::stopWatchingTags(int out) { |
| 171 | sp<CameraDeviceBase> device = mDevice; |
| 172 | if (!device) { |
| 173 | dprintf(out, " Device is detached"); |
| 174 | return OK; |
| 175 | } |
| 176 | |
| 177 | return device->stopWatchingTags(); |
| 178 | } |
| 179 | |
| 180 | template <typename TClientBase> |
| 181 | status_t Camera2ClientBase<TClientBase>::dumpWatchedEventsToVector(std::vector<std::string> &out) { |
| 182 | sp<CameraDeviceBase> device = mDevice; |
| 183 | if (!device) { |
| 184 | // Nothing to dump if the device is detached |
| 185 | return OK; |
| 186 | } |
| 187 | return device->dumpWatchedEventsToVector(out); |
| 188 | } |
| 189 | |
| 190 | template <typename TClientBase> |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 191 | status_t Camera2ClientBase<TClientBase>::dumpDevice( |
| 192 | int fd, |
| 193 | const Vector<String16>& args) { |
| 194 | String8 result; |
| 195 | |
| 196 | result = " Device dump:\n"; |
| 197 | write(fd, result.string(), result.size()); |
| 198 | |
Yin-Chia Yeh | e5138f1 | 2017-11-10 14:10:05 -0800 | [diff] [blame] | 199 | sp<CameraDeviceBase> device = mDevice; |
| 200 | if (!device.get()) { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 201 | result = " *** Device is detached\n"; |
| 202 | write(fd, result.string(), result.size()); |
| 203 | return NO_ERROR; |
| 204 | } |
| 205 | |
Yin-Chia Yeh | e5138f1 | 2017-11-10 14:10:05 -0800 | [diff] [blame] | 206 | status_t res = device->dump(fd, args); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 207 | if (res != OK) { |
| 208 | result = String8::format(" Error dumping device: %s (%d)", |
| 209 | strerror(-res), res); |
| 210 | write(fd, result.string(), result.size()); |
| 211 | } |
| 212 | |
| 213 | return NO_ERROR; |
| 214 | } |
| 215 | |
| 216 | // ICameraClient2BaseUser interface |
| 217 | |
| 218 | |
| 219 | template <typename TClientBase> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 220 | binder::Status Camera2ClientBase<TClientBase>::disconnect() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 221 | ATRACE_CALL(); |
| 222 | Mutex::Autolock icl(mBinderSerializationLock); |
| 223 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 224 | binder::Status res = binder::Status::ok(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 225 | // Allow both client and the media server to disconnect at all times |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 226 | int callingPid = CameraThreadState::getCallingPid(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 227 | if (callingPid != TClientBase::mClientPid && |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 228 | callingPid != TClientBase::mServicePid) return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 229 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 230 | ALOGV("Camera %s: Shutting down", TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 231 | |
Rucha Katakwar | df22307 | 2021-06-15 10:21:00 -0700 | [diff] [blame] | 232 | // Before detaching the device, cache the info from current open session. |
| 233 | // The disconnected check avoids duplication of info and also prevents |
| 234 | // deadlock while acquiring service lock in cacheDump. |
| 235 | if (!TClientBase::mDisconnected) { |
| 236 | Camera2ClientBase::getCameraService()->cacheDump(); |
| 237 | } |
| 238 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 239 | detachDevice(); |
| 240 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 241 | CameraService::BasicClient::disconnect(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 242 | |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 243 | ALOGV("Camera %s: Shut down complete", TClientBase::mCameraIdStr.string()); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 244 | |
| 245 | return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | template <typename TClientBase> |
| 249 | void Camera2ClientBase<TClientBase>::detachDevice() { |
| 250 | if (mDevice == 0) return; |
| 251 | mDevice->disconnect(); |
| 252 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 253 | ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | template <typename TClientBase> |
| 257 | status_t Camera2ClientBase<TClientBase>::connect( |
| 258 | const sp<TCamCallbacks>& client) { |
| 259 | ATRACE_CALL(); |
| 260 | ALOGV("%s: E", __FUNCTION__); |
| 261 | Mutex::Autolock icl(mBinderSerializationLock); |
| 262 | |
| 263 | if (TClientBase::mClientPid != 0 && |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 264 | CameraThreadState::getCallingPid() != TClientBase::mClientPid) { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 265 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 266 | ALOGE("%s: Camera %s: Connection attempt from pid %d; " |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 267 | "current locked to pid %d", |
| 268 | __FUNCTION__, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 269 | TClientBase::mCameraIdStr.string(), |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 270 | CameraThreadState::getCallingPid(), |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 271 | TClientBase::mClientPid); |
| 272 | return BAD_VALUE; |
| 273 | } |
| 274 | |
Jayant Chowdhary | 1236193 | 2018-08-27 14:46:13 -0700 | [diff] [blame] | 275 | TClientBase::mClientPid = CameraThreadState::getCallingPid(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 276 | |
| 277 | TClientBase::mRemoteCallback = client; |
| 278 | mSharedCameraCallbacks = client; |
| 279 | |
| 280 | return OK; |
| 281 | } |
| 282 | |
| 283 | /** Device-related methods */ |
| 284 | |
| 285 | template <typename TClientBase> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 286 | void Camera2ClientBase<TClientBase>::notifyError( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 287 | int32_t errorCode, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 288 | const CaptureResultExtras& resultExtras) { |
| 289 | ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode, |
| 290 | resultExtras.requestId); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | template <typename TClientBase> |
Eino-Ville Talvala | 178e823 | 2021-04-16 18:41:39 -0700 | [diff] [blame] | 294 | status_t Camera2ClientBase<TClientBase>::notifyActive() { |
| 295 | if (!mDeviceActive) { |
| 296 | status_t res = TClientBase::startCameraStreamingOps(); |
| 297 | if (res != OK) { |
| 298 | ALOGE("%s: Camera %s: Error starting camera streaming ops: %d", __FUNCTION__, |
| 299 | TClientBase::mCameraIdStr.string(), res); |
| 300 | return res; |
| 301 | } |
| 302 | CameraServiceProxyWrapper::logActive(TClientBase::mCameraIdStr); |
| 303 | } |
| 304 | mDeviceActive = true; |
| 305 | |
| 306 | ALOGV("Camera device is now active"); |
| 307 | return OK; |
| 308 | } |
| 309 | |
| 310 | template <typename TClientBase> |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 311 | void Camera2ClientBase<TClientBase>::notifyIdle( |
| 312 | int64_t requestCount, int64_t resultErrorCount, bool deviceError, |
| 313 | const std::vector<hardware::CameraStreamStats>& streamStats) { |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 314 | if (mDeviceActive) { |
Eino-Ville Talvala | 178e823 | 2021-04-16 18:41:39 -0700 | [diff] [blame] | 315 | status_t res = TClientBase::finishCameraStreamingOps(); |
| 316 | if (res != OK) { |
| 317 | ALOGE("%s: Camera %s: Error finishing streaming ops: %d", __FUNCTION__, |
| 318 | TClientBase::mCameraIdStr.string(), res); |
| 319 | } |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 320 | CameraServiceProxyWrapper::logIdle(TClientBase::mCameraIdStr, |
| 321 | requestCount, resultErrorCount, deviceError, streamStats); |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 322 | } |
| 323 | mDeviceActive = false; |
| 324 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 325 | ALOGV("Camera device is now idle"); |
| 326 | } |
| 327 | |
| 328 | template <typename TClientBase> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 329 | void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 330 | nsecs_t timestamp) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 331 | (void)resultExtras; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 332 | (void)timestamp; |
| 333 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 334 | ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64, |
| 335 | __FUNCTION__, resultExtras.requestId, timestamp); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | template <typename TClientBase> |
| 339 | void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState, |
| 340 | int triggerId) { |
| 341 | (void)newState; |
| 342 | (void)triggerId; |
| 343 | |
| 344 | ALOGV("%s: Autofocus state now %d, last trigger %d", |
| 345 | __FUNCTION__, newState, triggerId); |
| 346 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | template <typename TClientBase> |
| 350 | void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState, |
| 351 | int triggerId) { |
| 352 | (void)newState; |
| 353 | (void)triggerId; |
| 354 | |
| 355 | ALOGV("%s: Autoexposure state now %d, last trigger %d", |
| 356 | __FUNCTION__, newState, triggerId); |
| 357 | } |
| 358 | |
| 359 | template <typename TClientBase> |
| 360 | void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState, |
| 361 | int triggerId) { |
| 362 | (void)newState; |
| 363 | (void)triggerId; |
| 364 | |
| 365 | ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", |
| 366 | __FUNCTION__, newState, triggerId); |
| 367 | } |
| 368 | |
| 369 | template <typename TClientBase> |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 370 | void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) { |
| 371 | (void)streamId; |
| 372 | |
| 373 | ALOGV("%s: Stream %d now prepared", |
| 374 | __FUNCTION__, streamId); |
| 375 | } |
| 376 | |
| 377 | template <typename TClientBase> |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 378 | void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() { |
| 379 | |
| 380 | ALOGV("%s: Request queue now empty", __FUNCTION__); |
| 381 | } |
| 382 | |
| 383 | template <typename TClientBase> |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 384 | void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) { |
| 385 | (void)lastFrameNumber; |
| 386 | |
| 387 | ALOGV("%s: Repeating request was stopped. Last frame number is %ld", |
| 388 | __FUNCTION__, lastFrameNumber); |
| 389 | } |
| 390 | |
| 391 | template <typename TClientBase> |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 392 | int Camera2ClientBase<TClientBase>::getCameraId() const { |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 393 | return mApi1CameraId; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | template <typename TClientBase> |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 397 | int Camera2ClientBase<TClientBase>::getCameraDeviceVersion() const { |
| 398 | return mDeviceVersion; |
| 399 | } |
| 400 | |
| 401 | template <typename TClientBase> |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 402 | const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() { |
| 403 | return mDevice; |
| 404 | } |
| 405 | |
| 406 | template <typename TClientBase> |
| 407 | const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 408 | return TClientBase::sCameraService; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | template <typename TClientBase> |
| 412 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock( |
| 413 | SharedCameraCallbacks &client) : |
| 414 | |
| 415 | mRemoteCallback(client.mRemoteCallback), |
| 416 | mSharedClient(client) { |
| 417 | |
| 418 | mSharedClient.mRemoteCallbackLock.lock(); |
| 419 | } |
| 420 | |
| 421 | template <typename TClientBase> |
| 422 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() { |
| 423 | mSharedClient.mRemoteCallbackLock.unlock(); |
| 424 | } |
| 425 | |
| 426 | template <typename TClientBase> |
| 427 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks( |
| 428 | const sp<TCamCallbacks>&client) : |
| 429 | |
| 430 | mRemoteCallback(client) { |
| 431 | } |
| 432 | |
| 433 | template <typename TClientBase> |
| 434 | typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks& |
| 435 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=( |
| 436 | const sp<TCamCallbacks>&client) { |
| 437 | |
| 438 | Mutex::Autolock l(mRemoteCallbackLock); |
| 439 | mRemoteCallback = client; |
| 440 | return *this; |
| 441 | } |
| 442 | |
| 443 | template <typename TClientBase> |
| 444 | void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() { |
| 445 | Mutex::Autolock l(mRemoteCallbackLock); |
| 446 | mRemoteCallback.clear(); |
| 447 | } |
| 448 | |
Cliff Wu | d3a0531 | 2021-04-26 23:07:31 +0800 | [diff] [blame] | 449 | template <typename TClientBase> |
| 450 | status_t Camera2ClientBase<TClientBase>::injectCamera(const String8& injectedCamId, |
| 451 | sp<CameraProviderManager> manager) { |
| 452 | return mDevice->injectCamera(injectedCamId, manager); |
| 453 | } |
| 454 | |
| 455 | template <typename TClientBase> |
| 456 | status_t Camera2ClientBase<TClientBase>::stopInjection() { |
| 457 | return mDevice->stopInjection(); |
| 458 | } |
| 459 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 460 | template class Camera2ClientBase<CameraService::Client>; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 461 | template class Camera2ClientBase<CameraDeviceClientBase>; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 462 | |
| 463 | } // namespace android |