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