Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright (C) 2013, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ProCamera" |
| 20 | #include <utils/Log.h> |
| 21 | #include <utils/threads.h> |
| 22 | #include <utils/Mutex.h> |
| 23 | |
| 24 | #include <binder/IPCThreadState.h> |
| 25 | #include <binder/IServiceManager.h> |
| 26 | #include <binder/IMemory.h> |
| 27 | |
| 28 | #include <camera/ProCamera.h> |
| 29 | #include <camera/ICameraService.h> |
| 30 | #include <camera/IProCameraUser.h> |
| 31 | #include <camera/IProCameraCallbacks.h> |
| 32 | |
| 33 | #include <gui/IGraphicBufferProducer.h> |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 34 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 35 | #include <system/camera_metadata.h> |
| 36 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 39 | sp<ProCamera> ProCamera::connect(int cameraId) |
| 40 | { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 41 | return CameraBaseT::connect(cameraId, String16(), |
| 42 | ICameraService::USE_CALLING_UID); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 45 | ProCamera::ProCamera(int cameraId) |
| 46 | : CameraBase(cameraId) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 47 | { |
| 48 | } |
| 49 | |
| 50 | ProCamera::~ProCamera() |
| 51 | { |
| 52 | |
| 53 | } |
| 54 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 55 | /* IProCameraUser's implementation */ |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 56 | |
| 57 | // callback from camera service |
| 58 | void ProCamera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 59 | { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 60 | return CameraBaseT::notifyCallback(msgType, ext1, ext2); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Igor Murashkin | 5376573 | 2013-02-20 17:41:57 -0800 | [diff] [blame] | 63 | void ProCamera::onLockStatusChanged( |
| 64 | IProCameraCallbacks::LockStatus newLockStatus) |
| 65 | { |
| 66 | ALOGV("%s: newLockStatus = %d", __FUNCTION__, newLockStatus); |
| 67 | |
| 68 | sp<ProCameraListener> listener; |
| 69 | { |
| 70 | Mutex::Autolock _l(mLock); |
| 71 | listener = mListener; |
| 72 | } |
| 73 | if (listener != NULL) { |
| 74 | switch (newLockStatus) { |
| 75 | case IProCameraCallbacks::LOCK_ACQUIRED: |
| 76 | listener->onLockAcquired(); |
| 77 | break; |
| 78 | case IProCameraCallbacks::LOCK_RELEASED: |
| 79 | listener->onLockReleased(); |
| 80 | break; |
| 81 | case IProCameraCallbacks::LOCK_STOLEN: |
| 82 | listener->onLockStolen(); |
| 83 | break; |
| 84 | default: |
| 85 | ALOGE("%s: Unknown lock status: %d", |
| 86 | __FUNCTION__, newLockStatus); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 91 | void ProCamera::onResultReceived(int32_t frameId, camera_metadata* result) { |
| 92 | ALOGV("%s: frameId = %d, result = %p", __FUNCTION__, frameId, result); |
| 93 | |
| 94 | sp<ProCameraListener> listener; |
| 95 | { |
| 96 | Mutex::Autolock _l(mLock); |
| 97 | listener = mListener; |
| 98 | } |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 99 | |
| 100 | CameraMetadata tmp(result); |
| 101 | |
| 102 | // Unblock waitForFrame(id) callers |
| 103 | { |
| 104 | Mutex::Autolock al(mWaitMutex); |
| 105 | mMetadataReady = true; |
Igor Murashkin | 65d7986 | 2013-03-27 11:07:06 -0700 | [diff] [blame] | 106 | mLatestMetadata = tmp; // make copy |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 107 | mWaitCondition.broadcast(); |
| 108 | } |
| 109 | |
| 110 | result = tmp.release(); |
| 111 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 112 | if (listener != NULL) { |
| 113 | listener->onResultReceived(frameId, result); |
| 114 | } else { |
| 115 | free_camera_metadata(result); |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 120 | status_t ProCamera::exclusiveTryLock() |
| 121 | { |
| 122 | sp <IProCameraUser> c = mCamera; |
| 123 | if (c == 0) return NO_INIT; |
| 124 | |
| 125 | return c->exclusiveTryLock(); |
| 126 | } |
| 127 | status_t ProCamera::exclusiveLock() |
| 128 | { |
| 129 | sp <IProCameraUser> c = mCamera; |
| 130 | if (c == 0) return NO_INIT; |
| 131 | |
| 132 | return c->exclusiveLock(); |
| 133 | } |
| 134 | status_t ProCamera::exclusiveUnlock() |
| 135 | { |
| 136 | sp <IProCameraUser> c = mCamera; |
| 137 | if (c == 0) return NO_INIT; |
| 138 | |
| 139 | return c->exclusiveUnlock(); |
| 140 | } |
| 141 | bool ProCamera::hasExclusiveLock() |
| 142 | { |
| 143 | sp <IProCameraUser> c = mCamera; |
| 144 | if (c == 0) return NO_INIT; |
| 145 | |
| 146 | return c->hasExclusiveLock(); |
| 147 | } |
| 148 | |
| 149 | // Note that the callee gets a copy of the metadata. |
| 150 | int ProCamera::submitRequest(const struct camera_metadata* metadata, |
| 151 | bool streaming) |
| 152 | { |
| 153 | sp <IProCameraUser> c = mCamera; |
| 154 | if (c == 0) return NO_INIT; |
| 155 | |
| 156 | return c->submitRequest(const_cast<struct camera_metadata*>(metadata), |
| 157 | streaming); |
| 158 | } |
| 159 | |
| 160 | status_t ProCamera::cancelRequest(int requestId) |
| 161 | { |
| 162 | sp <IProCameraUser> c = mCamera; |
| 163 | if (c == 0) return NO_INIT; |
| 164 | |
| 165 | return c->cancelRequest(requestId); |
| 166 | } |
| 167 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 168 | status_t ProCamera::deleteStream(int streamId) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 169 | { |
| 170 | sp <IProCameraUser> c = mCamera; |
| 171 | if (c == 0) return NO_INIT; |
| 172 | |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 173 | status_t s = c->deleteStream(streamId); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 174 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 175 | mStreams.removeItem(streamId); |
| 176 | |
| 177 | return s; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 180 | status_t ProCamera::createStream(int width, int height, int format, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 181 | const sp<Surface>& surface, |
| 182 | /*out*/ |
| 183 | int* streamId) |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 184 | { |
| 185 | *streamId = -1; |
| 186 | |
| 187 | ALOGV("%s: createStreamW %dx%d (fmt=0x%x)", __FUNCTION__, width, height, |
| 188 | format); |
| 189 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 190 | if (surface == 0) { |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 191 | return BAD_VALUE; |
| 192 | } |
| 193 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 194 | return createStream(width, height, format, |
| 195 | surface->getIGraphicBufferProducer(), |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 196 | streamId); |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | status_t ProCamera::createStream(int width, int height, int format, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 200 | const sp<IGraphicBufferProducer>& bufferProducer, |
| 201 | /*out*/ |
| 202 | int* streamId) { |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 203 | *streamId = -1; |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 204 | |
| 205 | ALOGV("%s: createStreamT %dx%d (fmt=0x%x)", __FUNCTION__, width, height, |
| 206 | format); |
| 207 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 208 | if (bufferProducer == 0) { |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 209 | return BAD_VALUE; |
| 210 | } |
| 211 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 212 | sp <IProCameraUser> c = mCamera; |
| 213 | status_t stat = c->createStream(width, height, format, bufferProducer, |
| 214 | streamId); |
| 215 | |
| 216 | if (stat == OK) { |
| 217 | StreamInfo s(*streamId); |
| 218 | |
| 219 | mStreams.add(*streamId, s); |
| 220 | } |
| 221 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 222 | return stat; |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 225 | status_t ProCamera::createStreamCpu(int width, int height, int format, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 226 | int heapCount, |
| 227 | /*out*/ |
| 228 | sp<CpuConsumer>* cpuConsumer, |
Igor Murashkin | ba5ca4e | 2013-02-28 11:21:00 -0800 | [diff] [blame] | 229 | int* streamId) { |
| 230 | return createStreamCpu(width, height, format, heapCount, |
| 231 | /*synchronousMode*/true, |
| 232 | cpuConsumer, streamId); |
| 233 | } |
| 234 | |
| 235 | status_t ProCamera::createStreamCpu(int width, int height, int format, |
| 236 | int heapCount, |
| 237 | bool synchronousMode, |
| 238 | /*out*/ |
| 239 | sp<CpuConsumer>* cpuConsumer, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 240 | int* streamId) |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 241 | { |
| 242 | ALOGV("%s: createStreamW %dx%d (fmt=0x%x)", __FUNCTION__, width, height, |
| 243 | format); |
| 244 | |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 245 | *cpuConsumer = NULL; |
| 246 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 247 | sp <IProCameraUser> c = mCamera; |
| 248 | if (c == 0) return NO_INIT; |
| 249 | |
Mathias Agopian | 8d764bf | 2013-07-12 22:06:20 -0700 | [diff] [blame] | 250 | sp<BufferQueue> bq = new BufferQueue(); |
Mathias Agopian | 5e1f08b | 2013-07-16 22:54:39 -0700 | [diff] [blame] | 251 | sp<CpuConsumer> cc = new CpuConsumer(bq, heapCount/*, synchronousMode*/); |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 252 | cc->setName(String8("ProCamera::mCpuConsumer")); |
| 253 | |
| 254 | sp<Surface> stc = new Surface( |
| 255 | cc->getProducerInterface()); |
| 256 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 257 | status_t s = createStream(width, height, format, |
| 258 | stc->getIGraphicBufferProducer(), |
| 259 | streamId); |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 260 | |
| 261 | if (s != OK) { |
| 262 | ALOGE("%s: Failure to create stream %dx%d (fmt=0x%x)", __FUNCTION__, |
| 263 | width, height, format); |
| 264 | return s; |
| 265 | } |
| 266 | |
| 267 | sp<ProFrameListener> frameAvailableListener = |
| 268 | new ProFrameListener(this, *streamId); |
| 269 | |
| 270 | getStreamInfo(*streamId).cpuStream = true; |
| 271 | getStreamInfo(*streamId).cpuConsumer = cc; |
Igor Murashkin | ba5ca4e | 2013-02-28 11:21:00 -0800 | [diff] [blame] | 272 | getStreamInfo(*streamId).synchronousMode = synchronousMode; |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 273 | getStreamInfo(*streamId).stc = stc; |
| 274 | // for lifetime management |
| 275 | getStreamInfo(*streamId).frameAvailableListener = frameAvailableListener; |
| 276 | |
| 277 | cc->setFrameAvailableListener(frameAvailableListener); |
| 278 | |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 279 | *cpuConsumer = cc; |
| 280 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 281 | return s; |
| 282 | } |
| 283 | |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 284 | camera_metadata* ProCamera::getCameraInfo(int cameraId) { |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 285 | ALOGV("%s: cameraId = %d", __FUNCTION__, cameraId); |
Igor Murashkin | 7b33a74 | 2013-02-21 13:49:26 -0800 | [diff] [blame] | 286 | |
| 287 | sp <IProCameraUser> c = mCamera; |
| 288 | if (c == 0) return NULL; |
| 289 | |
| 290 | camera_metadata* ptr = NULL; |
| 291 | status_t status = c->getCameraInfo(cameraId, &ptr); |
| 292 | |
| 293 | if (status != OK) { |
| 294 | ALOGE("%s: Failed to get camera info, error = %d", __FUNCTION__, status); |
| 295 | } |
| 296 | |
| 297 | return ptr; |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | status_t ProCamera::createDefaultRequest(int templateId, |
| 301 | camera_metadata** request) const { |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 302 | ALOGV("%s: templateId = %d", __FUNCTION__, templateId); |
| 303 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 304 | sp <IProCameraUser> c = mCamera; |
| 305 | if (c == 0) return NO_INIT; |
| 306 | |
| 307 | return c->createDefaultRequest(templateId, request); |
Igor Murashkin | 68506fd | 2013-02-20 17:57:31 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 310 | void ProCamera::onFrameAvailable(int streamId) { |
| 311 | ALOGV("%s: streamId = %d", __FUNCTION__, streamId); |
| 312 | |
| 313 | sp<ProCameraListener> listener = mListener; |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 314 | StreamInfo& stream = getStreamInfo(streamId); |
| 315 | |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 316 | if (listener.get() != NULL) { |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 317 | listener->onFrameAvailable(streamId, stream.cpuConsumer); |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 318 | } |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 319 | |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 320 | // Unblock waitForFrame(id) callers |
| 321 | { |
| 322 | Mutex::Autolock al(mWaitMutex); |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 323 | getStreamInfo(streamId).frameReady++; |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 324 | mWaitCondition.broadcast(); |
| 325 | } |
| 326 | } |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 327 | |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 328 | int ProCamera::waitForFrameBuffer(int streamId) { |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 329 | status_t stat = BAD_VALUE; |
| 330 | Mutex::Autolock al(mWaitMutex); |
| 331 | |
| 332 | StreamInfo& si = getStreamInfo(streamId); |
| 333 | |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 334 | if (si.frameReady > 0) { |
| 335 | int numFrames = si.frameReady; |
| 336 | si.frameReady = 0; |
| 337 | return numFrames; |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 338 | } else { |
| 339 | while (true) { |
| 340 | stat = mWaitCondition.waitRelative(mWaitMutex, |
| 341 | mWaitTimeout); |
| 342 | if (stat != OK) { |
| 343 | ALOGE("%s: Error while waiting for frame buffer: %d", |
| 344 | __FUNCTION__, stat); |
| 345 | return stat; |
| 346 | } |
| 347 | |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 348 | if (si.frameReady > 0) { |
| 349 | int numFrames = si.frameReady; |
| 350 | si.frameReady = 0; |
| 351 | return numFrames; |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 352 | } |
| 353 | // else it was some other stream that got unblocked |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 356 | |
| 357 | return stat; |
| 358 | } |
| 359 | |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 360 | int ProCamera::dropFrameBuffer(int streamId, int count) { |
| 361 | StreamInfo& si = getStreamInfo(streamId); |
| 362 | |
| 363 | if (!si.cpuStream) { |
| 364 | return BAD_VALUE; |
| 365 | } else if (count < 0) { |
| 366 | return BAD_VALUE; |
| 367 | } |
| 368 | |
Igor Murashkin | ba5ca4e | 2013-02-28 11:21:00 -0800 | [diff] [blame] | 369 | if (!si.synchronousMode) { |
| 370 | ALOGW("%s: No need to drop frames on asynchronous streams," |
| 371 | " as asynchronous mode only keeps 1 latest frame around.", |
| 372 | __FUNCTION__); |
| 373 | return BAD_VALUE; |
| 374 | } |
| 375 | |
Igor Murashkin | 4bc4a38 | 2013-02-20 13:36:17 -0800 | [diff] [blame] | 376 | int numDropped = 0; |
| 377 | for (int i = 0; i < count; ++i) { |
| 378 | CpuConsumer::LockedBuffer buffer; |
| 379 | if (si.cpuConsumer->lockNextBuffer(&buffer) != OK) { |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | si.cpuConsumer->unlockBuffer(buffer); |
| 384 | numDropped++; |
| 385 | } |
| 386 | |
| 387 | return numDropped; |
| 388 | } |
| 389 | |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 390 | status_t ProCamera::waitForFrameMetadata() { |
| 391 | status_t stat = BAD_VALUE; |
| 392 | Mutex::Autolock al(mWaitMutex); |
| 393 | |
| 394 | if (mMetadataReady) { |
| 395 | return OK; |
| 396 | } else { |
| 397 | while (true) { |
| 398 | stat = mWaitCondition.waitRelative(mWaitMutex, |
| 399 | mWaitTimeout); |
| 400 | |
| 401 | if (stat != OK) { |
| 402 | ALOGE("%s: Error while waiting for metadata: %d", |
| 403 | __FUNCTION__, stat); |
| 404 | return stat; |
| 405 | } |
| 406 | |
| 407 | if (mMetadataReady) { |
| 408 | mMetadataReady = false; |
| 409 | return OK; |
| 410 | } |
| 411 | // else it was some other stream or metadata |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return stat; |
| 416 | } |
| 417 | |
| 418 | CameraMetadata ProCamera::consumeFrameMetadata() { |
| 419 | Mutex::Autolock al(mWaitMutex); |
| 420 | |
| 421 | // Destructive: Subsequent calls return empty metadatas |
| 422 | CameraMetadata tmp = mLatestMetadata; |
Igor Murashkin | 65d7986 | 2013-03-27 11:07:06 -0700 | [diff] [blame] | 423 | mLatestMetadata.clear(); |
Igor Murashkin | a140a6e | 2013-02-21 14:45:03 -0800 | [diff] [blame] | 424 | |
| 425 | return tmp; |
Igor Murashkin | 5835cc4 | 2013-02-20 19:29:53 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | ProCamera::StreamInfo& ProCamera::getStreamInfo(int streamId) { |
| 429 | return mStreams.editValueFor(streamId); |
| 430 | } |
| 431 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 432 | }; // namespace android |