| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2012 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 |  | 
| Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 17 | #define LOG_TAG "Camera2-CaptureSequencer" | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA | 
 | 19 | //#define LOG_NDEBUG 0 | 
 | 20 |  | 
 | 21 | #include <utils/Log.h> | 
 | 22 | #include <utils/Trace.h> | 
 | 23 | #include <utils/Vector.h> | 
 | 24 |  | 
 | 25 | #include "CaptureSequencer.h" | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 26 | #include "BurstCapture.h" | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 27 | #include "../Camera2Device.h" | 
 | 28 | #include "../Camera2Client.h" | 
 | 29 | #include "Parameters.h" | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 30 | #include "ZslProcessorInterface.h" | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 31 |  | 
 | 32 | namespace android { | 
 | 33 | namespace camera2 { | 
 | 34 |  | 
 | 35 | /** Public members */ | 
 | 36 |  | 
 | 37 | CaptureSequencer::CaptureSequencer(wp<Camera2Client> client): | 
 | 38 |         Thread(false), | 
 | 39 |         mStartCapture(false), | 
 | 40 |         mBusy(false), | 
 | 41 |         mNewAEState(false), | 
 | 42 |         mNewFrameReceived(false), | 
 | 43 |         mNewCaptureReceived(false), | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 44 |         mShutterNotified(false), | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 45 |         mClient(client), | 
 | 46 |         mCaptureState(IDLE), | 
 | 47 |         mTriggerId(0), | 
 | 48 |         mTimeoutCount(0), | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 49 |         mCaptureId(Camera2Client::kCaptureRequestIdStart), | 
 | 50 |         mMsgType(0) { | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 51 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 52 | } | 
 | 53 |  | 
 | 54 | CaptureSequencer::~CaptureSequencer() { | 
 | 55 |     ALOGV("%s: Exit", __FUNCTION__); | 
 | 56 | } | 
 | 57 |  | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 58 | void CaptureSequencer::setZslProcessor(wp<ZslProcessorInterface> processor) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 59 |     Mutex::Autolock l(mInputMutex); | 
 | 60 |     mZslProcessor = processor; | 
 | 61 | } | 
 | 62 |  | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 63 | status_t CaptureSequencer::startCapture(int msgType) { | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 64 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 65 |     ATRACE_CALL(); | 
 | 66 |     Mutex::Autolock l(mInputMutex); | 
 | 67 |     if (mBusy) { | 
 | 68 |         ALOGE("%s: Already busy capturing!", __FUNCTION__); | 
 | 69 |         return INVALID_OPERATION; | 
 | 70 |     } | 
 | 71 |     if (!mStartCapture) { | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 72 |         mMsgType = msgType; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 73 |         mStartCapture = true; | 
 | 74 |         mStartCaptureSignal.signal(); | 
 | 75 |     } | 
 | 76 |     return OK; | 
 | 77 | } | 
 | 78 |  | 
| Eino-Ville Talvala | e049384 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 79 | status_t CaptureSequencer::waitUntilIdle(nsecs_t timeout) { | 
 | 80 |     ATRACE_CALL(); | 
 | 81 |     ALOGV("%s: Waiting for idle", __FUNCTION__); | 
 | 82 |     Mutex::Autolock l(mStateMutex); | 
 | 83 |     status_t res = -1; | 
 | 84 |     while (mCaptureState != IDLE) { | 
 | 85 |         nsecs_t startTime = systemTime(); | 
 | 86 |  | 
 | 87 |         res = mStateChanged.waitRelative(mStateMutex, timeout); | 
 | 88 |         if (res != OK) return res; | 
 | 89 |  | 
 | 90 |         timeout -= (systemTime() - startTime); | 
 | 91 |     } | 
 | 92 |     ALOGV("%s: Now idle", __FUNCTION__); | 
 | 93 |     return OK; | 
 | 94 | } | 
 | 95 |  | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 96 | void CaptureSequencer::notifyAutoExposure(uint8_t newState, int triggerId) { | 
 | 97 |     ATRACE_CALL(); | 
 | 98 |     Mutex::Autolock l(mInputMutex); | 
 | 99 |     mAEState = newState; | 
 | 100 |     mAETriggerId = triggerId; | 
 | 101 |     if (!mNewAEState) { | 
 | 102 |         mNewAEState = true; | 
 | 103 |         mNewNotifySignal.signal(); | 
 | 104 |     } | 
 | 105 | } | 
 | 106 |  | 
 | 107 | void CaptureSequencer::onFrameAvailable(int32_t frameId, | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 108 |         const CameraMetadata &frame) { | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 109 |     ALOGV("%s: Listener found new frame", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 110 |     ATRACE_CALL(); | 
 | 111 |     Mutex::Autolock l(mInputMutex); | 
 | 112 |     mNewFrameId = frameId; | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 113 |     mNewFrame = frame; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 114 |     if (!mNewFrameReceived) { | 
 | 115 |         mNewFrameReceived = true; | 
 | 116 |         mNewFrameSignal.signal(); | 
 | 117 |     } | 
 | 118 | } | 
 | 119 |  | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 120 | void CaptureSequencer::onCaptureAvailable(nsecs_t timestamp, | 
 | 121 |         sp<MemoryBase> captureBuffer) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 122 |     ATRACE_CALL(); | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 123 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 124 |     Mutex::Autolock l(mInputMutex); | 
 | 125 |     mCaptureTimestamp = timestamp; | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 126 |     mCaptureBuffer = captureBuffer; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 127 |     if (!mNewCaptureReceived) { | 
 | 128 |         mNewCaptureReceived = true; | 
 | 129 |         mNewCaptureSignal.signal(); | 
 | 130 |     } | 
 | 131 | } | 
 | 132 |  | 
 | 133 |  | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 134 | void CaptureSequencer::dump(int fd, const Vector<String16>& /*args*/) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 135 |     String8 result; | 
 | 136 |     if (mCaptureRequest.entryCount() != 0) { | 
 | 137 |         result = "    Capture request:\n"; | 
 | 138 |         write(fd, result.string(), result.size()); | 
 | 139 |         mCaptureRequest.dump(fd, 2, 6); | 
 | 140 |     } else { | 
 | 141 |         result = "    Capture request: undefined\n"; | 
 | 142 |         write(fd, result.string(), result.size()); | 
 | 143 |     } | 
 | 144 |     result = String8::format("    Current capture state: %s\n", | 
 | 145 |             kStateNames[mCaptureState]); | 
 | 146 |     result.append("    Latest captured frame:\n"); | 
 | 147 |     write(fd, result.string(), result.size()); | 
 | 148 |     mNewFrame.dump(fd, 2, 6); | 
 | 149 | } | 
 | 150 |  | 
 | 151 | /** Private members */ | 
 | 152 |  | 
 | 153 | const char* CaptureSequencer::kStateNames[CaptureSequencer::NUM_CAPTURE_STATES+1] = | 
 | 154 | { | 
 | 155 |     "IDLE", | 
 | 156 |     "START", | 
 | 157 |     "ZSL_START", | 
 | 158 |     "ZSL_WAITING", | 
 | 159 |     "ZSL_REPROCESSING", | 
 | 160 |     "STANDARD_START", | 
| Eino-Ville Talvala | e049384 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 161 |     "STANDARD_PRECAPTURE_WAIT", | 
 | 162 |     "STANDARD_CAPTURE", | 
 | 163 |     "STANDARD_CAPTURE_WAIT", | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 164 |     "BURST_CAPTURE_START", | 
 | 165 |     "BURST_CAPTURE_WAIT", | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 166 |     "DONE", | 
 | 167 |     "ERROR", | 
 | 168 |     "UNKNOWN" | 
 | 169 | }; | 
 | 170 |  | 
 | 171 | const CaptureSequencer::StateManager | 
 | 172 |         CaptureSequencer::kStateManagers[CaptureSequencer::NUM_CAPTURE_STATES-1] = { | 
 | 173 |     &CaptureSequencer::manageIdle, | 
 | 174 |     &CaptureSequencer::manageStart, | 
 | 175 |     &CaptureSequencer::manageZslStart, | 
 | 176 |     &CaptureSequencer::manageZslWaiting, | 
 | 177 |     &CaptureSequencer::manageZslReprocessing, | 
 | 178 |     &CaptureSequencer::manageStandardStart, | 
 | 179 |     &CaptureSequencer::manageStandardPrecaptureWait, | 
 | 180 |     &CaptureSequencer::manageStandardCapture, | 
 | 181 |     &CaptureSequencer::manageStandardCaptureWait, | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 182 |     &CaptureSequencer::manageBurstCaptureStart, | 
 | 183 |     &CaptureSequencer::manageBurstCaptureWait, | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 184 |     &CaptureSequencer::manageDone, | 
 | 185 | }; | 
 | 186 |  | 
 | 187 | bool CaptureSequencer::threadLoop() { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 188 |  | 
 | 189 |     sp<Camera2Client> client = mClient.promote(); | 
 | 190 |     if (client == 0) return false; | 
 | 191 |  | 
| Eino-Ville Talvala | e049384 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 192 |     CaptureState currentState; | 
 | 193 |     { | 
 | 194 |         Mutex::Autolock l(mStateMutex); | 
 | 195 |         currentState = mCaptureState; | 
 | 196 |     } | 
 | 197 |  | 
 | 198 |     currentState = (this->*kStateManagers[currentState])(client); | 
 | 199 |  | 
 | 200 |     Mutex::Autolock l(mStateMutex); | 
 | 201 |     if (currentState != mCaptureState) { | 
 | 202 |         mCaptureState = currentState; | 
 | 203 |         ATRACE_INT("cam2_capt_state", mCaptureState); | 
 | 204 |         ALOGV("Camera %d: New capture state %s", | 
 | 205 |                 client->getCameraId(), kStateNames[mCaptureState]); | 
 | 206 |         mStateChanged.signal(); | 
 | 207 |     } | 
 | 208 |  | 
 | 209 |     if (mCaptureState == ERROR) { | 
 | 210 |         ALOGE("Camera %d: Stopping capture sequencer due to error", | 
 | 211 |                 client->getCameraId()); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 212 |         return false; | 
 | 213 |     } | 
 | 214 |  | 
 | 215 |     return true; | 
 | 216 | } | 
 | 217 |  | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 218 | CaptureSequencer::CaptureState CaptureSequencer::manageIdle( | 
 | 219 |         sp<Camera2Client> &/*client*/) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 220 |     status_t res; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 221 |     Mutex::Autolock l(mInputMutex); | 
 | 222 |     while (!mStartCapture) { | 
 | 223 |         res = mStartCaptureSignal.waitRelative(mInputMutex, | 
 | 224 |                 kWaitDuration); | 
 | 225 |         if (res == TIMED_OUT) break; | 
 | 226 |     } | 
 | 227 |     if (mStartCapture) { | 
 | 228 |         mStartCapture = false; | 
 | 229 |         mBusy = true; | 
 | 230 |         return START; | 
 | 231 |     } | 
 | 232 |     return IDLE; | 
 | 233 | } | 
 | 234 |  | 
 | 235 | CaptureSequencer::CaptureState CaptureSequencer::manageDone(sp<Camera2Client> &client) { | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 236 |     status_t res = OK; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 237 |     ATRACE_CALL(); | 
 | 238 |     mCaptureId++; | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 239 |     if (mCaptureId >= Camera2Client::kCaptureRequestIdEnd) { | 
 | 240 |         mCaptureId = Camera2Client::kCaptureRequestIdStart; | 
 | 241 |     } | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 242 |     { | 
 | 243 |         Mutex::Autolock l(mInputMutex); | 
 | 244 |         mBusy = false; | 
 | 245 |     } | 
 | 246 |  | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 247 |     { | 
 | 248 |         SharedParameters::Lock l(client->getParameters()); | 
 | 249 |         switch (l.mParameters.state) { | 
| Eino-Ville Talvala | e049384 | 2012-10-05 12:03:10 -0700 | [diff] [blame] | 250 |             case Parameters::DISCONNECTED: | 
 | 251 |                 ALOGW("%s: Camera %d: Discarding image data during shutdown ", | 
 | 252 |                         __FUNCTION__, client->getCameraId()); | 
 | 253 |                 res = INVALID_OPERATION; | 
 | 254 |                 break; | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 255 |             case Parameters::STILL_CAPTURE: | 
 | 256 |                 l.mParameters.state = Parameters::STOPPED; | 
 | 257 |                 break; | 
 | 258 |             case Parameters::VIDEO_SNAPSHOT: | 
 | 259 |                 l.mParameters.state = Parameters::RECORD; | 
 | 260 |                 break; | 
 | 261 |             default: | 
 | 262 |                 ALOGE("%s: Camera %d: Still image produced unexpectedly " | 
 | 263 |                         "in state %s!", | 
 | 264 |                         __FUNCTION__, client->getCameraId(), | 
 | 265 |                         Parameters::getStateName(l.mParameters.state)); | 
 | 266 |                 res = INVALID_OPERATION; | 
 | 267 |         } | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 268 |     } | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 269 |     sp<ZslProcessorInterface> processor = mZslProcessor.promote(); | 
| Eino-Ville Talvala | 5a8fed0 | 2012-09-19 17:11:04 -0700 | [diff] [blame] | 270 |     if (processor != 0) { | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 271 |         ALOGV("%s: Memory optimization, clearing ZSL queue", | 
 | 272 |               __FUNCTION__); | 
| Eino-Ville Talvala | 5a8fed0 | 2012-09-19 17:11:04 -0700 | [diff] [blame] | 273 |         processor->clearZslQueue(); | 
 | 274 |     } | 
 | 275 |  | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 276 |     /** | 
 | 277 |      * Fire the jpegCallback in Camera#takePicture(..., jpegCallback) | 
 | 278 |      */ | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 279 |     if (mCaptureBuffer != 0 && res == OK) { | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 280 |         Camera2Client::SharedCameraCallbacks::Lock | 
 | 281 |             l(client->mSharedCameraCallbacks); | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 282 |         ALOGV("%s: Sending still image to client", __FUNCTION__); | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 283 |         if (l.mRemoteCallback != 0) { | 
 | 284 |             l.mRemoteCallback->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, | 
| Eino-Ville Talvala | 52e9ad4 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 285 |                     mCaptureBuffer, NULL); | 
 | 286 |         } else { | 
 | 287 |             ALOGV("%s: No client!", __FUNCTION__); | 
 | 288 |         } | 
 | 289 |     } | 
 | 290 |     mCaptureBuffer.clear(); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 291 |  | 
 | 292 |     return IDLE; | 
 | 293 | } | 
 | 294 |  | 
 | 295 | CaptureSequencer::CaptureState CaptureSequencer::manageStart( | 
 | 296 |         sp<Camera2Client> &client) { | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 297 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 298 |     status_t res; | 
 | 299 |     ATRACE_CALL(); | 
 | 300 |     SharedParameters::Lock l(client->getParameters()); | 
 | 301 |     CaptureState nextState = DONE; | 
 | 302 |  | 
 | 303 |     res = updateCaptureRequest(l.mParameters, client); | 
 | 304 |     if (res != OK ) { | 
 | 305 |         ALOGE("%s: Camera %d: Can't update still image capture request: %s (%d)", | 
 | 306 |                 __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 307 |         return DONE; | 
 | 308 |     } | 
 | 309 |  | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 310 |     if(l.mParameters.lightFx != Parameters::LIGHTFX_NONE && | 
 | 311 |             l.mParameters.state == Parameters::STILL_CAPTURE) { | 
 | 312 |         nextState = BURST_CAPTURE_START; | 
 | 313 |     } | 
 | 314 |     else if (l.mParameters.zslMode && | 
| Eino-Ville Talvala | 5a07a62 | 2012-09-21 16:30:42 -0700 | [diff] [blame] | 315 |             l.mParameters.state == Parameters::STILL_CAPTURE && | 
 | 316 |             l.mParameters.flashMode != Parameters::FLASH_MODE_ON) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 317 |         nextState = ZSL_START; | 
 | 318 |     } else { | 
 | 319 |         nextState = STANDARD_START; | 
 | 320 |     } | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 321 |     mShutterNotified = false; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 322 |  | 
 | 323 |     return nextState; | 
 | 324 | } | 
 | 325 |  | 
 | 326 | CaptureSequencer::CaptureState CaptureSequencer::manageZslStart( | 
 | 327 |         sp<Camera2Client> &client) { | 
| Eino-Ville Talvala | 2954fe9 | 2012-09-12 10:42:10 -0700 | [diff] [blame] | 328 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 329 |     status_t res; | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 330 |     sp<ZslProcessorInterface> processor = mZslProcessor.promote(); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 331 |     if (processor == 0) { | 
 | 332 |         ALOGE("%s: No ZSL queue to use!", __FUNCTION__); | 
 | 333 |         return DONE; | 
 | 334 |     } | 
 | 335 |  | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 336 |     client->registerFrameListener(mCaptureId, mCaptureId + 1, | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 337 |             this); | 
 | 338 |  | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 339 |     // TODO: Actually select the right thing here. | 
| Eino-Ville Talvala | 2954fe9 | 2012-09-12 10:42:10 -0700 | [diff] [blame] | 340 |     res = processor->pushToReprocess(mCaptureId); | 
 | 341 |     if (res != OK) { | 
| Eino-Ville Talvala | 2274549 | 2012-09-17 17:55:07 -0700 | [diff] [blame] | 342 |         if (res == NOT_ENOUGH_DATA) { | 
 | 343 |             ALOGV("%s: Camera %d: ZSL queue doesn't have good frame, " | 
 | 344 |                     "falling back to normal capture", __FUNCTION__, | 
 | 345 |                     client->getCameraId()); | 
 | 346 |         } else { | 
 | 347 |             ALOGE("%s: Camera %d: Error in ZSL queue: %s (%d)", | 
 | 348 |                     __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 349 |         } | 
| Eino-Ville Talvala | 2954fe9 | 2012-09-12 10:42:10 -0700 | [diff] [blame] | 350 |         return STANDARD_START; | 
 | 351 |     } | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 352 |  | 
| Eino-Ville Talvala | a4247b8 | 2012-09-19 17:12:50 -0700 | [diff] [blame] | 353 |     SharedParameters::Lock l(client->getParameters()); | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 354 |     /* warning: this also locks a SharedCameraCallbacks */ | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 355 |     shutterNotifyLocked(l.mParameters, client, mMsgType); | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 356 |     mShutterNotified = true; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 357 |     mTimeoutCount = kMaxTimeoutsForCaptureEnd; | 
 | 358 |     return STANDARD_CAPTURE_WAIT; | 
 | 359 | } | 
 | 360 |  | 
 | 361 | CaptureSequencer::CaptureState CaptureSequencer::manageZslWaiting( | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 362 |         sp<Camera2Client> &/*client*/) { | 
| Eino-Ville Talvala | 2954fe9 | 2012-09-12 10:42:10 -0700 | [diff] [blame] | 363 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 364 |     return DONE; | 
 | 365 | } | 
 | 366 |  | 
 | 367 | CaptureSequencer::CaptureState CaptureSequencer::manageZslReprocessing( | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 368 |         sp<Camera2Client> &/*client*/) { | 
| Eino-Ville Talvala | 2954fe9 | 2012-09-12 10:42:10 -0700 | [diff] [blame] | 369 |     ALOGV("%s", __FUNCTION__); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 370 |     return START; | 
 | 371 | } | 
 | 372 |  | 
 | 373 | CaptureSequencer::CaptureState CaptureSequencer::manageStandardStart( | 
 | 374 |         sp<Camera2Client> &client) { | 
 | 375 |     ATRACE_CALL(); | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 376 |  | 
 | 377 |     // Get the onFrameAvailable callback when the requestID == mCaptureId | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 378 |     client->registerFrameListener(mCaptureId, mCaptureId + 1, | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 379 |             this); | 
 | 380 |     { | 
 | 381 |         SharedParameters::Lock l(client->getParameters()); | 
 | 382 |         mTriggerId = l.mParameters.precaptureTriggerCounter++; | 
 | 383 |     } | 
 | 384 |     client->getCameraDevice()->triggerPrecaptureMetering(mTriggerId); | 
 | 385 |  | 
 | 386 |     mAeInPrecapture = false; | 
 | 387 |     mTimeoutCount = kMaxTimeoutsForPrecaptureStart; | 
 | 388 |     return STANDARD_PRECAPTURE_WAIT; | 
 | 389 | } | 
 | 390 |  | 
 | 391 | CaptureSequencer::CaptureState CaptureSequencer::manageStandardPrecaptureWait( | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 392 |         sp<Camera2Client> &/*client*/) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 393 |     status_t res; | 
 | 394 |     ATRACE_CALL(); | 
 | 395 |     Mutex::Autolock l(mInputMutex); | 
 | 396 |     while (!mNewAEState) { | 
 | 397 |         res = mNewNotifySignal.waitRelative(mInputMutex, kWaitDuration); | 
 | 398 |         if (res == TIMED_OUT) { | 
 | 399 |             mTimeoutCount--; | 
 | 400 |             break; | 
 | 401 |         } | 
 | 402 |     } | 
 | 403 |     if (mTimeoutCount <= 0) { | 
 | 404 |         ALOGW("Timed out waiting for precapture %s", | 
 | 405 |                 mAeInPrecapture ? "end" : "start"); | 
 | 406 |         return STANDARD_CAPTURE; | 
 | 407 |     } | 
 | 408 |     if (mNewAEState) { | 
 | 409 |         if (!mAeInPrecapture) { | 
 | 410 |             // Waiting to see PRECAPTURE state | 
 | 411 |             if (mAETriggerId == mTriggerId && | 
 | 412 |                     mAEState == ANDROID_CONTROL_AE_STATE_PRECAPTURE) { | 
 | 413 |                 ALOGV("%s: Got precapture start", __FUNCTION__); | 
 | 414 |                 mAeInPrecapture = true; | 
 | 415 |                 mTimeoutCount = kMaxTimeoutsForPrecaptureEnd; | 
 | 416 |             } | 
 | 417 |         } else { | 
 | 418 |             // Waiting to see PRECAPTURE state end | 
 | 419 |             if (mAETriggerId == mTriggerId && | 
 | 420 |                     mAEState != ANDROID_CONTROL_AE_STATE_PRECAPTURE) { | 
 | 421 |                 ALOGV("%s: Got precapture end", __FUNCTION__); | 
 | 422 |                 return STANDARD_CAPTURE; | 
 | 423 |             } | 
 | 424 |         } | 
 | 425 |         mNewAEState = false; | 
 | 426 |     } | 
 | 427 |     return STANDARD_PRECAPTURE_WAIT; | 
 | 428 | } | 
 | 429 |  | 
 | 430 | CaptureSequencer::CaptureState CaptureSequencer::manageStandardCapture( | 
 | 431 |         sp<Camera2Client> &client) { | 
 | 432 |     status_t res; | 
 | 433 |     ATRACE_CALL(); | 
 | 434 |     SharedParameters::Lock l(client->getParameters()); | 
 | 435 |     Vector<uint8_t> outputStreams; | 
 | 436 |  | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 437 |     /** | 
 | 438 |      * Set up output streams in the request | 
 | 439 |      *  - preview | 
 | 440 |      *  - capture/jpeg | 
 | 441 |      *  - callback (if preview callbacks enabled) | 
 | 442 |      *  - recording (if recording enabled) | 
 | 443 |      */ | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 444 |     outputStreams.push(client->getPreviewStreamId()); | 
 | 445 |     outputStreams.push(client->getCaptureStreamId()); | 
 | 446 |  | 
 | 447 |     if (l.mParameters.previewCallbackFlags & | 
 | 448 |             CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) { | 
 | 449 |         outputStreams.push(client->getCallbackStreamId()); | 
 | 450 |     } | 
 | 451 |  | 
 | 452 |     if (l.mParameters.state == Parameters::VIDEO_SNAPSHOT) { | 
 | 453 |         outputStreams.push(client->getRecordingStreamId()); | 
 | 454 |     } | 
 | 455 |  | 
 | 456 |     res = mCaptureRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, | 
 | 457 |             outputStreams); | 
 | 458 |     if (res == OK) { | 
 | 459 |         res = mCaptureRequest.update(ANDROID_REQUEST_ID, | 
 | 460 |                 &mCaptureId, 1); | 
 | 461 |     } | 
 | 462 |     if (res == OK) { | 
 | 463 |         res = mCaptureRequest.sort(); | 
 | 464 |     } | 
 | 465 |  | 
 | 466 |     if (res != OK) { | 
 | 467 |         ALOGE("%s: Camera %d: Unable to set up still capture request: %s (%d)", | 
 | 468 |                 __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 469 |         return DONE; | 
 | 470 |     } | 
 | 471 |  | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 472 |     // Create a capture copy since CameraDeviceBase#capture takes ownership | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 473 |     CameraMetadata captureCopy = mCaptureRequest; | 
 | 474 |     if (captureCopy.entryCount() == 0) { | 
 | 475 |         ALOGE("%s: Camera %d: Unable to copy capture request for HAL device", | 
 | 476 |                 __FUNCTION__, client->getCameraId()); | 
 | 477 |         return DONE; | 
 | 478 |     } | 
 | 479 |  | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 480 |     /** | 
 | 481 |      * Clear the streaming request for still-capture pictures | 
 | 482 |      *   (as opposed to i.e. video snapshots) | 
 | 483 |      */ | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 484 |     if (l.mParameters.state == Parameters::STILL_CAPTURE) { | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 485 |         // API definition of takePicture() - stop preview before taking pic | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 486 |         res = client->stopStream(); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 487 |         if (res != OK) { | 
 | 488 |             ALOGE("%s: Camera %d: Unable to stop preview for still capture: " | 
 | 489 |                     "%s (%d)", | 
 | 490 |                     __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 491 |             return DONE; | 
 | 492 |         } | 
 | 493 |     } | 
 | 494 |     // TODO: Capture should be atomic with setStreamingRequest here | 
 | 495 |     res = client->getCameraDevice()->capture(captureCopy); | 
 | 496 |     if (res != OK) { | 
 | 497 |         ALOGE("%s: Camera %d: Unable to submit still image capture request: " | 
 | 498 |                 "%s (%d)", | 
 | 499 |                 __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 500 |         return DONE; | 
 | 501 |     } | 
 | 502 |  | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 503 |     mTimeoutCount = kMaxTimeoutsForCaptureEnd; | 
 | 504 |     return STANDARD_CAPTURE_WAIT; | 
 | 505 | } | 
 | 506 |  | 
 | 507 | CaptureSequencer::CaptureState CaptureSequencer::manageStandardCaptureWait( | 
 | 508 |         sp<Camera2Client> &client) { | 
 | 509 |     status_t res; | 
 | 510 |     ATRACE_CALL(); | 
 | 511 |     Mutex::Autolock l(mInputMutex); | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 512 |  | 
 | 513 |     // Wait for new metadata result (mNewFrame) | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 514 |     while (!mNewFrameReceived) { | 
 | 515 |         res = mNewFrameSignal.waitRelative(mInputMutex, kWaitDuration); | 
 | 516 |         if (res == TIMED_OUT) { | 
 | 517 |             mTimeoutCount--; | 
 | 518 |             break; | 
 | 519 |         } | 
 | 520 |     } | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 521 |  | 
 | 522 |     // Approximation of the shutter being closed | 
 | 523 |     // - TODO: use the hal3 exposure callback in Camera3Device instead | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 524 |     if (mNewFrameReceived && !mShutterNotified) { | 
 | 525 |         SharedParameters::Lock l(client->getParameters()); | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 526 |         /* warning: this also locks a SharedCameraCallbacks */ | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 527 |         shutterNotifyLocked(l.mParameters, client, mMsgType); | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 528 |         mShutterNotified = true; | 
 | 529 |     } | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 530 |  | 
 | 531 |     // Wait until jpeg was captured by JpegProcessor | 
| Eino-Ville Talvala | ad21da9 | 2012-10-07 22:43:48 -0700 | [diff] [blame] | 532 |     while (mNewFrameReceived && !mNewCaptureReceived) { | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 533 |         res = mNewCaptureSignal.waitRelative(mInputMutex, kWaitDuration); | 
 | 534 |         if (res == TIMED_OUT) { | 
 | 535 |             mTimeoutCount--; | 
 | 536 |             break; | 
 | 537 |         } | 
 | 538 |     } | 
 | 539 |     if (mTimeoutCount <= 0) { | 
 | 540 |         ALOGW("Timed out waiting for capture to complete"); | 
 | 541 |         return DONE; | 
 | 542 |     } | 
 | 543 |     if (mNewFrameReceived && mNewCaptureReceived) { | 
 | 544 |         if (mNewFrameId != mCaptureId) { | 
 | 545 |             ALOGW("Mismatched capture frame IDs: Expected %d, got %d", | 
 | 546 |                     mCaptureId, mNewFrameId); | 
 | 547 |         } | 
 | 548 |         camera_metadata_entry_t entry; | 
 | 549 |         entry = mNewFrame.find(ANDROID_SENSOR_TIMESTAMP); | 
 | 550 |         if (entry.count == 0) { | 
 | 551 |             ALOGE("No timestamp field in capture frame!"); | 
 | 552 |         } | 
 | 553 |         if (entry.data.i64[0] != mCaptureTimestamp) { | 
 | 554 |             ALOGW("Mismatched capture timestamps: Metadata frame %lld," | 
| Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 555 |                     " captured buffer %lld", | 
 | 556 |                     entry.data.i64[0], | 
 | 557 |                     mCaptureTimestamp); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 558 |         } | 
| Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 559 |         client->removeFrameListener(mCaptureId, mCaptureId + 1, this); | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 560 |  | 
 | 561 |         mNewFrameReceived = false; | 
 | 562 |         mNewCaptureReceived = false; | 
 | 563 |         return DONE; | 
 | 564 |     } | 
 | 565 |     return STANDARD_CAPTURE_WAIT; | 
 | 566 | } | 
 | 567 |  | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 568 | CaptureSequencer::CaptureState CaptureSequencer::manageBurstCaptureStart( | 
 | 569 |         sp<Camera2Client> &client) { | 
 | 570 |     ALOGV("%s", __FUNCTION__); | 
 | 571 |     status_t res; | 
 | 572 |     ATRACE_CALL(); | 
 | 573 |  | 
 | 574 |     // check which burst mode is set, create respective burst object | 
 | 575 |     { | 
 | 576 |         SharedParameters::Lock l(client->getParameters()); | 
 | 577 |  | 
 | 578 |         res = updateCaptureRequest(l.mParameters, client); | 
 | 579 |         if(res != OK) { | 
 | 580 |             return DONE; | 
 | 581 |         } | 
 | 582 |  | 
 | 583 |         // | 
 | 584 |         // check for burst mode type in mParameters here | 
 | 585 |         // | 
 | 586 |         mBurstCapture = new BurstCapture(client, this); | 
 | 587 |     } | 
 | 588 |  | 
 | 589 |     res = mCaptureRequest.update(ANDROID_REQUEST_ID, &mCaptureId, 1); | 
 | 590 |     if (res == OK) { | 
 | 591 |         res = mCaptureRequest.sort(); | 
 | 592 |     } | 
 | 593 |     if (res != OK) { | 
 | 594 |         ALOGE("%s: Camera %d: Unable to set up still capture request: %s (%d)", | 
 | 595 |                 __FUNCTION__, client->getCameraId(), strerror(-res), res); | 
 | 596 |         return DONE; | 
 | 597 |     } | 
 | 598 |  | 
 | 599 |     CameraMetadata captureCopy = mCaptureRequest; | 
 | 600 |     if (captureCopy.entryCount() == 0) { | 
 | 601 |         ALOGE("%s: Camera %d: Unable to copy capture request for HAL device", | 
 | 602 |                 __FUNCTION__, client->getCameraId()); | 
 | 603 |         return DONE; | 
 | 604 |     } | 
 | 605 |  | 
 | 606 |     Vector<CameraMetadata> requests; | 
 | 607 |     requests.push(mCaptureRequest); | 
 | 608 |     res = mBurstCapture->start(requests, mCaptureId); | 
 | 609 |     mTimeoutCount = kMaxTimeoutsForCaptureEnd * 10; | 
 | 610 |     return BURST_CAPTURE_WAIT; | 
 | 611 | } | 
 | 612 |  | 
 | 613 | CaptureSequencer::CaptureState CaptureSequencer::manageBurstCaptureWait( | 
| Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 614 |         sp<Camera2Client> &/*client*/) { | 
| James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 615 |     status_t res; | 
 | 616 |     ATRACE_CALL(); | 
 | 617 |  | 
 | 618 |     while (!mNewCaptureReceived) { | 
 | 619 |         res = mNewCaptureSignal.waitRelative(mInputMutex, kWaitDuration); | 
 | 620 |         if (res == TIMED_OUT) { | 
 | 621 |             mTimeoutCount--; | 
 | 622 |             break; | 
 | 623 |         } | 
 | 624 |     } | 
 | 625 |  | 
 | 626 |     if (mTimeoutCount <= 0) { | 
 | 627 |         ALOGW("Timed out waiting for burst capture to complete"); | 
 | 628 |         return DONE; | 
 | 629 |     } | 
 | 630 |     if (mNewCaptureReceived) { | 
 | 631 |         mNewCaptureReceived = false; | 
 | 632 |         // TODO: update mCaptureId to last burst's capture ID + 1? | 
 | 633 |         return DONE; | 
 | 634 |     } | 
 | 635 |  | 
 | 636 |     return BURST_CAPTURE_WAIT; | 
 | 637 | } | 
 | 638 |  | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 639 | status_t CaptureSequencer::updateCaptureRequest(const Parameters ¶ms, | 
 | 640 |         sp<Camera2Client> &client) { | 
 | 641 |     ATRACE_CALL(); | 
 | 642 |     status_t res; | 
 | 643 |     if (mCaptureRequest.entryCount() == 0) { | 
 | 644 |         res = client->getCameraDevice()->createDefaultRequest( | 
 | 645 |                 CAMERA2_TEMPLATE_STILL_CAPTURE, | 
 | 646 |                 &mCaptureRequest); | 
 | 647 |         if (res != OK) { | 
 | 648 |             ALOGE("%s: Camera %d: Unable to create default still image request:" | 
 | 649 |                     " %s (%d)", __FUNCTION__, client->getCameraId(), | 
 | 650 |                     strerror(-res), res); | 
 | 651 |             return res; | 
 | 652 |         } | 
 | 653 |     } | 
 | 654 |  | 
 | 655 |     res = params.updateRequest(&mCaptureRequest); | 
 | 656 |     if (res != OK) { | 
 | 657 |         ALOGE("%s: Camera %d: Unable to update common entries of capture " | 
 | 658 |                 "request: %s (%d)", __FUNCTION__, client->getCameraId(), | 
 | 659 |                 strerror(-res), res); | 
 | 660 |         return res; | 
 | 661 |     } | 
 | 662 |  | 
| Eino-Ville Talvala | db30e68 | 2012-10-04 13:21:08 -0700 | [diff] [blame] | 663 |     res = params.updateRequestJpeg(&mCaptureRequest); | 
 | 664 |     if (res != OK) { | 
 | 665 |         ALOGE("%s: Camera %d: Unable to update JPEG entries of capture " | 
 | 666 |                 "request: %s (%d)", __FUNCTION__, client->getCameraId(), | 
 | 667 |                 strerror(-res), res); | 
 | 668 |         return res; | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 669 |     } | 
 | 670 |  | 
 | 671 |     return OK; | 
 | 672 | } | 
 | 673 |  | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 674 | /*static*/ void CaptureSequencer::shutterNotifyLocked(const Parameters ¶ms, | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 675 |             sp<Camera2Client> client, int msgType) { | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 676 |     ATRACE_CALL(); | 
 | 677 |  | 
| Igor Murashkin | 786a8da | 2012-11-26 10:50:55 -0800 | [diff] [blame] | 678 |     if (params.state == Parameters::STILL_CAPTURE | 
 | 679 |         && params.playShutterSound | 
 | 680 |         && (msgType & CAMERA_MSG_SHUTTER)) { | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 681 |         client->getCameraService()->playSound(CameraService::SOUND_SHUTTER); | 
 | 682 |     } | 
 | 683 |  | 
 | 684 |     { | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 685 |         Camera2Client::SharedCameraCallbacks::Lock | 
 | 686 |             l(client->mSharedCameraCallbacks); | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 687 |  | 
 | 688 |         ALOGV("%s: Notifying of shutter close to client", __FUNCTION__); | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 689 |         if (l.mRemoteCallback != 0) { | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 690 |             // ShutterCallback | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 691 |             l.mRemoteCallback->notifyCallback(CAMERA_MSG_SHUTTER, | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 692 |                                             /*ext1*/0, /*ext2*/0); | 
 | 693 |  | 
 | 694 |             // RawCallback with null buffer | 
| Igor Murashkin | a2e203b | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 695 |             l.mRemoteCallback->notifyCallback(CAMERA_MSG_RAW_IMAGE_NOTIFY, | 
| Igor Murashkin | 707c3e3 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 696 |                                             /*ext1*/0, /*ext2*/0); | 
 | 697 |         } else { | 
 | 698 |             ALOGV("%s: No client!", __FUNCTION__); | 
 | 699 |         } | 
 | 700 |     } | 
 | 701 | } | 
 | 702 |  | 
| Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 703 |  | 
 | 704 | }; // namespace camera2 | 
 | 705 | }; // namespace android |