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