347 /**
348 * Take picture, initiating an auto focus scan if needed.
349 */
350 @Override
351 public void takePicture(final PhotoCaptureParameters params, final CaptureSession session) {
352 // Do not do anything when a picture is already requested.
353 if (mTakePictureWhenLensIsStopped) {
354 return;
355 }
356
357 // Not ready until the picture comes back.
358 broadcastReadyState(false);
359
360 mTakePictureRunnable = new Runnable() {
361 @Override
362 public void run() {
363 takePictureNow(params, session);
364 }
365 };
366 mLastPictureCallback = params.callback;
367 mTakePictureStartMillis = SystemClock.uptimeMillis();
368
369 // This class implements a very simple version of AF, which
370 // only delays capture if the lens is scanning.
371 if (mLastResultAFState == AutoFocusState.ACTIVE_SCAN) {
372 Log.v(TAG, "Waiting until scan is done before taking shot.");
373 mTakePictureWhenLensIsStopped = true;
374 } else {
375 // We could do CONTROL_AF_TRIGGER_START and wait until lens locks,
376 // but this would slow down the capture.
377 takePictureNow(params, session);
378 }
379 }
380
381 /**
382 * Take picture immediately. Parameters passed through from takePicture().
383 */
384 public void takePictureNow(PhotoCaptureParameters params, CaptureSession session) {
385 long dt = SystemClock.uptimeMillis() - mTakePictureStartMillis;
386 Log.v(TAG, "Taking shot with extra AF delay of " + dt + " ms.");
387 try {
388 // JPEG capture.
//TEMPLATE_STILL_CAPTURE 表示当前创建的request是拍照
389 CaptureRequest.Builder builder = mDevice
390 .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
391 builder.setTag(RequestTag.CAPTURE);
392 addBaselineCaptureKeysToRequest(builder);
393
394 // Enable lens-shading correction for even better DNGs.
395 if (sCaptureImageFormat == ImageFormat.RAW_SENSOR) {
396 builder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE,
397 CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE_ON);
398