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