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 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 30 | #include "common/Camera2ClientBase.h" |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 31 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 32 | #include "api2/CameraDeviceClient.h" |
| 33 | |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 34 | #include "device3/Camera3Device.h" |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 35 | |
| 36 | namespace android { |
| 37 | using namespace camera2; |
| 38 | |
| 39 | static int getCallingPid() { |
| 40 | return IPCThreadState::self()->getCallingPid(); |
| 41 | } |
| 42 | |
| 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, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 50 | const String8& cameraId, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 51 | int cameraFacing, |
| 52 | int clientPid, |
| 53 | uid_t clientUid, |
| 54 | int servicePid): |
| 55 | TClientBase(cameraService, remoteCallback, clientPackageName, |
| 56 | cameraId, cameraFacing, clientPid, clientUid, servicePid), |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 57 | mSharedCameraCallbacks(remoteCallback), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 58 | mDeviceVersion(cameraService->getDeviceVersion(TClientBase::mCameraIdStr)), |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 59 | mDeviceActive(false) |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 60 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 61 | 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] | 62 | String8(clientPackageName).string(), clientPid, clientUid); |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 63 | |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 64 | mInitialClientPid = clientPid; |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 65 | mDevice = new Camera3Device(cameraId); |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 66 | LOG_ALWAYS_FATAL_IF(mDevice == 0, "Device should never be NULL here."); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | template <typename TClientBase> |
| 70 | status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation) |
| 71 | const { |
| 72 | |
| 73 | int callingPid = getCallingPid(); |
| 74 | if (callingPid == TClientBase::mClientPid) return NO_ERROR; |
| 75 | |
| 76 | ALOGE("%s: attempt to use a locked camera from a different process" |
| 77 | " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid); |
| 78 | return PERMISSION_DENIED; |
| 79 | } |
| 80 | |
| 81 | template <typename TClientBase> |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 82 | status_t Camera2ClientBase<TClientBase>::initialize(CameraModule *module) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 83 | return initializeImpl(module); |
| 84 | } |
| 85 | |
| 86 | template <typename TClientBase> |
| 87 | status_t Camera2ClientBase<TClientBase>::initialize(sp<CameraProviderManager> manager) { |
| 88 | return initializeImpl(manager); |
| 89 | } |
| 90 | |
| 91 | template <typename TClientBase> |
| 92 | template <typename TProviderPtr> |
| 93 | status_t Camera2ClientBase<TClientBase>::initializeImpl(TProviderPtr providerPtr) { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 94 | ATRACE_CALL(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 95 | ALOGV("%s: Initializing client for camera %s", __FUNCTION__, |
| 96 | TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 97 | status_t res; |
| 98 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 99 | // Verify ops permissions |
| 100 | res = TClientBase::startCameraOps(); |
| 101 | if (res != OK) { |
| 102 | return res; |
| 103 | } |
| 104 | |
| 105 | if (mDevice == NULL) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 106 | ALOGE("%s: Camera %s: No device connected", |
| 107 | __FUNCTION__, TClientBase::mCameraIdStr.string()); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 108 | return NO_INIT; |
| 109 | } |
| 110 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 111 | res = mDevice->initialize(providerPtr); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 112 | if (res != OK) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 113 | ALOGE("%s: Camera %s: unable to initialize device: %s (%d)", |
| 114 | __FUNCTION__, TClientBase::mCameraIdStr.string(), strerror(-res), res); |
Zhijun He | 66281c3 | 2013-09-13 17:59:59 -0700 | [diff] [blame] | 115 | return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Yin-Chia Yeh | e1c8063 | 2016-08-08 14:48:05 -0700 | [diff] [blame] | 118 | wp<CameraDeviceBase::NotificationListener> weakThis(this); |
| 119 | res = mDevice->setNotifyCallback(weakThis); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 120 | |
| 121 | return OK; |
| 122 | } |
| 123 | |
| 124 | template <typename TClientBase> |
| 125 | Camera2ClientBase<TClientBase>::~Camera2ClientBase() { |
| 126 | ATRACE_CALL(); |
| 127 | |
| 128 | TClientBase::mDestructionStarted = true; |
| 129 | |
| 130 | disconnect(); |
| 131 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 132 | ALOGI("Closed Camera %s. Client was: %s (PID %d, UID %u)", |
| 133 | TClientBase::mCameraIdStr.string(), |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 134 | String8(TClientBase::mClientPackageName).string(), |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 135 | mInitialClientPid, TClientBase::mClientUid); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | template <typename TClientBase> |
Eino-Ville Talvala | c400396 | 2016-01-13 10:07:04 -0800 | [diff] [blame] | 139 | status_t Camera2ClientBase<TClientBase>::dumpClient(int fd, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 140 | const Vector<String16>& args) { |
| 141 | String8 result; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 142 | result.appendFormat("Camera2ClientBase[%s] (%p) PID: %d, dump:\n", |
| 143 | TClientBase::mCameraIdStr.string(), |
Eino-Ville Talvala | e992e75 | 2014-11-07 16:17:48 -0800 | [diff] [blame] | 144 | (TClientBase::getRemoteCallback() != NULL ? |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 145 | IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL), |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 146 | TClientBase::mClientPid); |
| 147 | result.append(" State: "); |
| 148 | |
| 149 | write(fd, result.string(), result.size()); |
| 150 | // TODO: print dynamic/request section from most recent requests |
| 151 | |
| 152 | return dumpDevice(fd, args); |
| 153 | } |
| 154 | |
| 155 | template <typename TClientBase> |
| 156 | status_t Camera2ClientBase<TClientBase>::dumpDevice( |
| 157 | int fd, |
| 158 | const Vector<String16>& args) { |
| 159 | String8 result; |
| 160 | |
| 161 | result = " Device dump:\n"; |
| 162 | write(fd, result.string(), result.size()); |
| 163 | |
| 164 | if (!mDevice.get()) { |
| 165 | result = " *** Device is detached\n"; |
| 166 | write(fd, result.string(), result.size()); |
| 167 | return NO_ERROR; |
| 168 | } |
| 169 | |
| 170 | status_t res = mDevice->dump(fd, args); |
| 171 | if (res != OK) { |
| 172 | result = String8::format(" Error dumping device: %s (%d)", |
| 173 | strerror(-res), res); |
| 174 | write(fd, result.string(), result.size()); |
| 175 | } |
| 176 | |
| 177 | return NO_ERROR; |
| 178 | } |
| 179 | |
| 180 | // ICameraClient2BaseUser interface |
| 181 | |
| 182 | |
| 183 | template <typename TClientBase> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 184 | binder::Status Camera2ClientBase<TClientBase>::disconnect() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 185 | ATRACE_CALL(); |
| 186 | Mutex::Autolock icl(mBinderSerializationLock); |
| 187 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 188 | binder::Status res = binder::Status::ok(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 189 | // Allow both client and the media server to disconnect at all times |
| 190 | int callingPid = getCallingPid(); |
| 191 | if (callingPid != TClientBase::mClientPid && |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 192 | callingPid != TClientBase::mServicePid) return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 193 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 194 | ALOGV("Camera %s: Shutting down", TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 195 | |
| 196 | detachDevice(); |
| 197 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 198 | CameraService::BasicClient::disconnect(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 199 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 200 | ALOGV("Camera %s: Shut down complete complete", TClientBase::mCameraIdStr.string()); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 201 | |
| 202 | return res; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | template <typename TClientBase> |
| 206 | void Camera2ClientBase<TClientBase>::detachDevice() { |
| 207 | if (mDevice == 0) return; |
| 208 | mDevice->disconnect(); |
| 209 | |
| 210 | mDevice.clear(); |
| 211 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 212 | ALOGV("Camera %s: Detach complete", TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | template <typename TClientBase> |
| 216 | status_t Camera2ClientBase<TClientBase>::connect( |
| 217 | const sp<TCamCallbacks>& client) { |
| 218 | ATRACE_CALL(); |
| 219 | ALOGV("%s: E", __FUNCTION__); |
| 220 | Mutex::Autolock icl(mBinderSerializationLock); |
| 221 | |
| 222 | if (TClientBase::mClientPid != 0 && |
| 223 | getCallingPid() != TClientBase::mClientPid) { |
| 224 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 225 | ALOGE("%s: Camera %s: Connection attempt from pid %d; " |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 226 | "current locked to pid %d", |
| 227 | __FUNCTION__, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 228 | TClientBase::mCameraIdStr.string(), |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 229 | getCallingPid(), |
| 230 | TClientBase::mClientPid); |
| 231 | return BAD_VALUE; |
| 232 | } |
| 233 | |
| 234 | TClientBase::mClientPid = getCallingPid(); |
| 235 | |
| 236 | TClientBase::mRemoteCallback = client; |
| 237 | mSharedCameraCallbacks = client; |
| 238 | |
| 239 | return OK; |
| 240 | } |
| 241 | |
| 242 | /** Device-related methods */ |
| 243 | |
| 244 | template <typename TClientBase> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 245 | void Camera2ClientBase<TClientBase>::notifyError( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 246 | int32_t errorCode, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 247 | const CaptureResultExtras& resultExtras) { |
| 248 | ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode, |
| 249 | resultExtras.requestId); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | template <typename TClientBase> |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 253 | void Camera2ClientBase<TClientBase>::notifyIdle() { |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 254 | if (mDeviceActive) { |
| 255 | getCameraService()->updateProxyDeviceState( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 256 | ICameraServiceProxy::CAMERA_STATE_IDLE, TClientBase::mCameraIdStr); |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 257 | } |
| 258 | mDeviceActive = false; |
| 259 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 260 | ALOGV("Camera device is now idle"); |
| 261 | } |
| 262 | |
| 263 | template <typename TClientBase> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 264 | void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 265 | nsecs_t timestamp) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 266 | (void)resultExtras; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 267 | (void)timestamp; |
| 268 | |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 269 | if (!mDeviceActive) { |
| 270 | getCameraService()->updateProxyDeviceState( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 271 | ICameraServiceProxy::CAMERA_STATE_ACTIVE, TClientBase::mCameraIdStr); |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 272 | } |
| 273 | mDeviceActive = true; |
| 274 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 275 | ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64, |
| 276 | __FUNCTION__, resultExtras.requestId, timestamp); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | template <typename TClientBase> |
| 280 | void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState, |
| 281 | int triggerId) { |
| 282 | (void)newState; |
| 283 | (void)triggerId; |
| 284 | |
| 285 | ALOGV("%s: Autofocus state now %d, last trigger %d", |
| 286 | __FUNCTION__, newState, triggerId); |
| 287 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | template <typename TClientBase> |
| 291 | void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState, |
| 292 | int triggerId) { |
| 293 | (void)newState; |
| 294 | (void)triggerId; |
| 295 | |
| 296 | ALOGV("%s: Autoexposure state now %d, last trigger %d", |
| 297 | __FUNCTION__, newState, triggerId); |
| 298 | } |
| 299 | |
| 300 | template <typename TClientBase> |
| 301 | void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState, |
| 302 | int triggerId) { |
| 303 | (void)newState; |
| 304 | (void)triggerId; |
| 305 | |
| 306 | ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", |
| 307 | __FUNCTION__, newState, triggerId); |
| 308 | } |
| 309 | |
| 310 | template <typename TClientBase> |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 311 | void Camera2ClientBase<TClientBase>::notifyPrepared(int streamId) { |
| 312 | (void)streamId; |
| 313 | |
| 314 | ALOGV("%s: Stream %d now prepared", |
| 315 | __FUNCTION__, streamId); |
| 316 | } |
| 317 | |
| 318 | template <typename TClientBase> |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 319 | void Camera2ClientBase<TClientBase>::notifyRequestQueueEmpty() { |
| 320 | |
| 321 | ALOGV("%s: Request queue now empty", __FUNCTION__); |
| 322 | } |
| 323 | |
| 324 | template <typename TClientBase> |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 325 | void Camera2ClientBase<TClientBase>::notifyRepeatingRequestError(long lastFrameNumber) { |
| 326 | (void)lastFrameNumber; |
| 327 | |
| 328 | ALOGV("%s: Repeating request was stopped. Last frame number is %ld", |
| 329 | __FUNCTION__, lastFrameNumber); |
| 330 | } |
| 331 | |
| 332 | template <typename TClientBase> |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 333 | int Camera2ClientBase<TClientBase>::getCameraId() const { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 334 | return std::stoi(TClientBase::mCameraIdStr.string()); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | template <typename TClientBase> |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 338 | int Camera2ClientBase<TClientBase>::getCameraDeviceVersion() const { |
| 339 | return mDeviceVersion; |
| 340 | } |
| 341 | |
| 342 | template <typename TClientBase> |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 343 | const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() { |
| 344 | return mDevice; |
| 345 | } |
| 346 | |
| 347 | template <typename TClientBase> |
| 348 | const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 349 | return TClientBase::sCameraService; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | template <typename TClientBase> |
| 353 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock( |
| 354 | SharedCameraCallbacks &client) : |
| 355 | |
| 356 | mRemoteCallback(client.mRemoteCallback), |
| 357 | mSharedClient(client) { |
| 358 | |
| 359 | mSharedClient.mRemoteCallbackLock.lock(); |
| 360 | } |
| 361 | |
| 362 | template <typename TClientBase> |
| 363 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() { |
| 364 | mSharedClient.mRemoteCallbackLock.unlock(); |
| 365 | } |
| 366 | |
| 367 | template <typename TClientBase> |
| 368 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks( |
| 369 | const sp<TCamCallbacks>&client) : |
| 370 | |
| 371 | mRemoteCallback(client) { |
| 372 | } |
| 373 | |
| 374 | template <typename TClientBase> |
| 375 | typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks& |
| 376 | Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=( |
| 377 | const sp<TCamCallbacks>&client) { |
| 378 | |
| 379 | Mutex::Autolock l(mRemoteCallbackLock); |
| 380 | mRemoteCallback = client; |
| 381 | return *this; |
| 382 | } |
| 383 | |
| 384 | template <typename TClientBase> |
| 385 | void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() { |
| 386 | Mutex::Autolock l(mRemoteCallbackLock); |
| 387 | mRemoteCallback.clear(); |
| 388 | } |
| 389 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 390 | template class Camera2ClientBase<CameraService::Client>; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 391 | template class Camera2ClientBase<CameraDeviceClientBase>; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 392 | |
| 393 | } // namespace android |