Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -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 "ProCamera2Client" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/Trace.h> |
| 23 | |
| 24 | #include <cutils/properties.h> |
| 25 | #include <gui/Surface.h> |
| 26 | #include <gui/Surface.h> |
| 27 | #include "camera2/Parameters.h" |
| 28 | #include "ProCamera2Client.h" |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 29 | #include "camera2/ProFrameProcessor.h" |
Igor Murashkin | ce124da | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 30 | #include "CameraDeviceBase.h" |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | using namespace camera2; |
| 34 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 35 | // Interface used by CameraService |
| 36 | |
| 37 | ProCamera2Client::ProCamera2Client(const sp<CameraService>& cameraService, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 38 | const sp<IProCameraCallbacks>& remoteCallback, |
| 39 | const String16& clientPackageName, |
| 40 | int cameraId, |
| 41 | int cameraFacing, |
| 42 | int clientPid, |
| 43 | uid_t clientUid, |
| 44 | int servicePid) : |
| 45 | Camera2ClientBase(cameraService, remoteCallback, clientPackageName, |
| 46 | cameraId, cameraFacing, clientPid, clientUid, servicePid) |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 47 | { |
| 48 | ATRACE_CALL(); |
| 49 | ALOGI("ProCamera %d: Opened", cameraId); |
| 50 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 51 | mExclusiveLock = false; |
| 52 | } |
| 53 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 54 | status_t ProCamera2Client::initialize(camera_module_t *module) |
| 55 | { |
| 56 | ATRACE_CALL(); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 57 | status_t res; |
| 58 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 59 | res = Camera2ClientBase::initialize(module); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 60 | if (res != OK) { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 61 | return res; |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 64 | String8 threadName; |
Igor Murashkin | ce124da | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 65 | mFrameProcessor = new ProFrameProcessor(mDevice); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 66 | threadName = String8::format("PC2-%d-FrameProc", mCameraId); |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 67 | mFrameProcessor->run(threadName.string()); |
| 68 | |
| 69 | mFrameProcessor->registerListener(FRAME_PROCESSOR_LISTENER_MIN_ID, |
| 70 | FRAME_PROCESSOR_LISTENER_MAX_ID, |
| 71 | /*listener*/this); |
| 72 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 73 | return OK; |
| 74 | } |
| 75 | |
| 76 | ProCamera2Client::~ProCamera2Client() { |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | status_t ProCamera2Client::exclusiveTryLock() { |
| 80 | ATRACE_CALL(); |
| 81 | ALOGV("%s", __FUNCTION__); |
| 82 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 83 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 84 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); |
| 85 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 86 | if (!mDevice.get()) return PERMISSION_DENIED; |
| 87 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 88 | if (!mExclusiveLock) { |
| 89 | mExclusiveLock = true; |
| 90 | |
| 91 | if (mRemoteCallback != NULL) { |
| 92 | mRemoteCallback->onLockStatusChanged( |
| 93 | IProCameraCallbacks::LOCK_ACQUIRED); |
| 94 | } |
| 95 | |
| 96 | ALOGV("%s: exclusive lock acquired", __FUNCTION__); |
| 97 | |
| 98 | return OK; |
| 99 | } |
| 100 | |
| 101 | // TODO: have a PERMISSION_DENIED case for when someone else owns the lock |
| 102 | |
| 103 | // don't allow recursive locking |
| 104 | ALOGW("%s: exclusive lock already exists - recursive locking is not" |
| 105 | "allowed", __FUNCTION__); |
| 106 | |
| 107 | return ALREADY_EXISTS; |
| 108 | } |
| 109 | |
| 110 | status_t ProCamera2Client::exclusiveLock() { |
| 111 | ATRACE_CALL(); |
| 112 | ALOGV("%s", __FUNCTION__); |
| 113 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 114 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 115 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); |
| 116 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 117 | if (!mDevice.get()) return PERMISSION_DENIED; |
| 118 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 119 | /** |
| 120 | * TODO: this should asynchronously 'wait' until the lock becomes available |
| 121 | * if another client already has an exclusive lock. |
| 122 | * |
| 123 | * once we have proper sharing support this will need to do |
| 124 | * more than just return immediately |
| 125 | */ |
| 126 | if (!mExclusiveLock) { |
| 127 | mExclusiveLock = true; |
| 128 | |
| 129 | if (mRemoteCallback != NULL) { |
| 130 | mRemoteCallback->onLockStatusChanged(IProCameraCallbacks::LOCK_ACQUIRED); |
| 131 | } |
| 132 | |
| 133 | ALOGV("%s: exclusive lock acquired", __FUNCTION__); |
| 134 | |
| 135 | return OK; |
| 136 | } |
| 137 | |
| 138 | // don't allow recursive locking |
| 139 | ALOGW("%s: exclusive lock already exists - recursive locking is not allowed" |
| 140 | , __FUNCTION__); |
| 141 | return ALREADY_EXISTS; |
| 142 | } |
| 143 | |
| 144 | status_t ProCamera2Client::exclusiveUnlock() { |
| 145 | ATRACE_CALL(); |
| 146 | ALOGV("%s", __FUNCTION__); |
| 147 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 148 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 149 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); |
| 150 | |
| 151 | // don't allow unlocking if we have no lock |
| 152 | if (!mExclusiveLock) { |
| 153 | ALOGW("%s: cannot unlock, no lock was held in the first place", |
| 154 | __FUNCTION__); |
| 155 | return BAD_VALUE; |
| 156 | } |
| 157 | |
| 158 | mExclusiveLock = false; |
| 159 | if (mRemoteCallback != NULL ) { |
| 160 | mRemoteCallback->onLockStatusChanged( |
| 161 | IProCameraCallbacks::LOCK_RELEASED); |
| 162 | } |
| 163 | ALOGV("%s: exclusive lock released", __FUNCTION__); |
| 164 | |
| 165 | return OK; |
| 166 | } |
| 167 | |
| 168 | bool ProCamera2Client::hasExclusiveLock() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 169 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 170 | return mExclusiveLock; |
| 171 | } |
| 172 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 173 | void ProCamera2Client::onExclusiveLockStolen() { |
| 174 | ALOGV("%s: ProClient lost exclusivity (id %d)", |
| 175 | __FUNCTION__, mCameraId); |
| 176 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 177 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 178 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); |
| 179 | |
| 180 | if (mExclusiveLock && mRemoteCallback.get() != NULL) { |
| 181 | mRemoteCallback->onLockStatusChanged( |
| 182 | IProCameraCallbacks::LOCK_STOLEN); |
| 183 | } |
| 184 | |
| 185 | mExclusiveLock = false; |
| 186 | |
| 187 | //TODO: we should not need to detach the device, merely reset it. |
| 188 | detachDevice(); |
| 189 | } |
| 190 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 191 | status_t ProCamera2Client::submitRequest(camera_metadata_t* request, |
| 192 | bool streaming) { |
| 193 | ATRACE_CALL(); |
| 194 | ALOGV("%s", __FUNCTION__); |
| 195 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 196 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 197 | |
| 198 | if (!mDevice.get()) return DEAD_OBJECT; |
| 199 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 200 | if (!mExclusiveLock) { |
| 201 | return PERMISSION_DENIED; |
| 202 | } |
| 203 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 204 | CameraMetadata metadata(request); |
| 205 | |
| 206 | if (streaming) { |
| 207 | return mDevice->setStreamingRequest(metadata); |
| 208 | } else { |
| 209 | return mDevice->capture(metadata); |
| 210 | } |
| 211 | |
| 212 | // unreachable. thx gcc for a useless warning |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 213 | return OK; |
| 214 | } |
| 215 | |
| 216 | status_t ProCamera2Client::cancelRequest(int requestId) { |
| 217 | ATRACE_CALL(); |
| 218 | ALOGV("%s", __FUNCTION__); |
| 219 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 220 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 221 | |
| 222 | if (!mDevice.get()) return DEAD_OBJECT; |
| 223 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 224 | if (!mExclusiveLock) { |
| 225 | return PERMISSION_DENIED; |
| 226 | } |
| 227 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 228 | // TODO: implement |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 229 | ALOGE("%s: not fully implemented yet", __FUNCTION__); |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 230 | return INVALID_OPERATION; |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame^] | 233 | status_t ProCamera2Client::deleteStream(int streamId) { |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 234 | ATRACE_CALL(); |
| 235 | ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 236 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 237 | status_t res; |
| 238 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 239 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 240 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 241 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 242 | if (!mDevice.get()) return DEAD_OBJECT; |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 243 | mDevice->clearStreamingRequest(); |
| 244 | |
| 245 | status_t code; |
| 246 | if ((code = mDevice->waitUntilDrained()) != OK) { |
| 247 | ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__, code); |
| 248 | } |
| 249 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 250 | return mDevice->deleteStream(streamId); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | status_t ProCamera2Client::createStream(int width, int height, int format, |
Igor Murashkin | 76f8b43 | 2013-02-20 19:15:15 -0800 | [diff] [blame] | 254 | const sp<IGraphicBufferProducer>& bufferProducer, |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 255 | /*out*/ |
| 256 | int* streamId) |
| 257 | { |
| 258 | if (streamId) { |
| 259 | *streamId = -1; |
| 260 | } |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 261 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 262 | ATRACE_CALL(); |
| 263 | ALOGV("%s (w = %d, h = %d, f = 0x%x)", __FUNCTION__, width, height, format); |
| 264 | |
| 265 | status_t res; |
| 266 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 267 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 268 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 269 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 270 | if (!mDevice.get()) return DEAD_OBJECT; |
| 271 | |
Igor Murashkin | 76f8b43 | 2013-02-20 19:15:15 -0800 | [diff] [blame] | 272 | sp<IBinder> binder; |
| 273 | sp<ANativeWindow> window; |
| 274 | if (bufferProducer != 0) { |
| 275 | binder = bufferProducer->asBinder(); |
| 276 | window = new Surface(bufferProducer); |
| 277 | } |
| 278 | |
| 279 | return mDevice->createStream(window, width, height, format, /*size*/1, |
| 280 | streamId); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 283 | // Create a request object from a template. |
| 284 | // -- Caller owns the newly allocated metadata |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 285 | status_t ProCamera2Client::createDefaultRequest(int templateId, |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 286 | /*out*/ |
| 287 | camera_metadata** request) |
| 288 | { |
| 289 | ATRACE_CALL(); |
| 290 | ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 291 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 292 | if (request) { |
| 293 | *request = NULL; |
| 294 | } |
| 295 | |
| 296 | status_t res; |
| 297 | if ( (res = checkPid(__FUNCTION__) ) != OK) return res; |
| 298 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 299 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 300 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 301 | if (!mDevice.get()) return DEAD_OBJECT; |
| 302 | |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 303 | CameraMetadata metadata; |
| 304 | if ( (res = mDevice->createDefaultRequest(templateId, &metadata) ) == OK) { |
| 305 | *request = metadata.release(); |
| 306 | } |
| 307 | |
| 308 | return res; |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Igor Murashkin | 7b33a74 | 2013-02-21 13:49:26 -0800 | [diff] [blame] | 311 | status_t ProCamera2Client::getCameraInfo(int cameraId, |
| 312 | /*out*/ |
| 313 | camera_metadata** info) |
| 314 | { |
| 315 | if (cameraId != mCameraId) { |
| 316 | return INVALID_OPERATION; |
| 317 | } |
| 318 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 319 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 320 | |
| 321 | if (!mDevice.get()) return DEAD_OBJECT; |
| 322 | |
Igor Murashkin | 7b33a74 | 2013-02-21 13:49:26 -0800 | [diff] [blame] | 323 | CameraMetadata deviceInfo = mDevice->info(); |
| 324 | *info = deviceInfo.release(); |
| 325 | |
| 326 | return OK; |
| 327 | } |
| 328 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 329 | status_t ProCamera2Client::dump(int fd, const Vector<String16>& args) { |
| 330 | String8 result; |
| 331 | result.appendFormat("ProCamera2Client[%d] (%p) PID: %d, dump:\n", |
| 332 | mCameraId, |
| 333 | getRemoteCallback()->asBinder().get(), |
| 334 | mClientPid); |
| 335 | result.append(" State: "); |
| 336 | |
| 337 | // TODO: print dynamic/request section from most recent requests |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 338 | mFrameProcessor->dump(fd, args); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 339 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 340 | return dumpDevice(fd, args); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // IProCameraUser interface |
| 344 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 345 | void ProCamera2Client::detachDevice() { |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 346 | if (mDevice == 0) return; |
| 347 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 348 | ALOGV("Camera %d: Stopping processors", mCameraId); |
| 349 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 350 | mFrameProcessor->removeListener(FRAME_PROCESSOR_LISTENER_MIN_ID, |
| 351 | FRAME_PROCESSOR_LISTENER_MAX_ID, |
| 352 | /*listener*/this); |
| 353 | mFrameProcessor->requestExit(); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 354 | ALOGV("Camera %d: Waiting for threads", mCameraId); |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 355 | mFrameProcessor->join(); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 356 | ALOGV("Camera %d: Disconnecting device", mCameraId); |
| 357 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 358 | // WORKAROUND: HAL refuses to disconnect while there's streams in flight |
| 359 | { |
| 360 | mDevice->clearStreamingRequest(); |
| 361 | |
| 362 | status_t code; |
| 363 | if ((code = mDevice->waitUntilDrained()) != OK) { |
| 364 | ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__, |
| 365 | code); |
| 366 | } |
| 367 | } |
| 368 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 369 | Camera2ClientBase::detachDevice(); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /** Device-related methods */ |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 373 | void ProCamera2Client::onFrameAvailable(int32_t frameId, |
| 374 | const CameraMetadata& frame) { |
| 375 | ATRACE_CALL(); |
| 376 | ALOGV("%s", __FUNCTION__); |
| 377 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 378 | Mutex::Autolock icl(mBinderSerializationLock); |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 379 | SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); |
| 380 | |
| 381 | if (mRemoteCallback != NULL) { |
| 382 | CameraMetadata tmp(frame); |
| 383 | camera_metadata_t* meta = tmp.release(); |
| 384 | ALOGV("%s: meta = %p ", __FUNCTION__, meta); |
| 385 | mRemoteCallback->onResultReceived(frameId, meta); |
| 386 | tmp.acquire(meta); |
| 387 | } |
| 388 | |
| 389 | } |
| 390 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 391 | } // namespace android |