1 /* 2 * Copyright (C) 2014 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 package com.android.camera.one.v2.photo; 18 19 import static com.android.camera.one.v2.core.ResponseListeners.forPartialMetadata; 20 21 import android.hardware.camera2.CameraDevice; 22 23 import com.android.camera.async.BufferQueue; 24 import com.android.camera.async.MainThread; 25 import com.android.camera.debug.Logger; 26 import com.android.camera.one.OneCamera; 27 import com.android.camera.one.v2.camera2proxy.ImageProxy; 28 import com.android.camera.one.v2.commands.CameraCommandExecutor; 29 import com.android.camera.one.v2.core.FrameServer; 30 import com.android.camera.one.v2.core.ResponseManager; 31 import com.android.camera.one.v2.core.RequestBuilder; 32 import com.android.camera.one.v2.imagesaver.ImageSaver; 33 import com.android.camera.one.v2.photo.zsl.AcceptableZslImageFilter; 34 import com.android.camera.one.v2.photo.zsl.AutoFlashZslImageFilter; 35 import com.android.camera.one.v2.photo.zsl.ZslImageCaptureCommand; 36 import com.android.camera.one.v2.sharedimagereader.ManagedImageReader; 37 import com.android.camera.one.v2.sharedimagereader.metadatasynchronizer.MetadataPool; 38 import com.google.common.base.Supplier; 39 40 import java.util.Arrays; 41 42 /** 43 * Wires together a PictureTaker with zero shutter lag. 44 */ 45 public class ZslPictureTakerFactory { 46 /** 47 * The maximum amount of time (in nanoseconds) to look-back in the zsl 48 * ring-buffer for an image with AE and/or AF convergence. 49 */ 50 private static final long MAX_LOOKBACK_NANOS = 100000000; // 100 ms 51 private final PictureTakerImpl mPictureTaker; 52 53 private ZslPictureTakerFactory(PictureTakerImpl pictureTaker) { 54 mPictureTaker = pictureTaker; 55 } 56 57 public static ZslPictureTakerFactory create(Logger.Factory logFactory, 58 MainThread mainExecutor, 59 CameraCommandExecutor commandExecutor, 60 ImageSaver.Builder imageSaverBuilder, 61 FrameServer frameServer, 62 RequestBuilder.Factory rootRequestBuilder, 63 ManagedImageReader sharedImageReader, 64 BufferQueue<ImageProxy> ringBuffer, 65 MetadataPool metadataPool, 66 Supplier<OneCamera.PhotoCaptureParameters.Flash> flashMode, 67 ResponseManager globalResponseManager) { 68 // When flash is ON, always use the ConvergedImageCaptureCommand which 69 // performs the AF & AE precapture sequence. 70 ImageCaptureCommand flashOnCommand = new ConvergedImageCaptureCommand( 71 sharedImageReader, frameServer, rootRequestBuilder, 72 CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, 73 Arrays.asList(rootRequestBuilder), true, true); 74 // When flash is OFF, use ZSL and filter images to require AF 75 // convergence, but not AE convergence (AE can take a long time to 76 // converge, making capture feel slow). 77 ImageCaptureCommand flashOffFallback = new ConvergedImageCaptureCommand( 78 sharedImageReader, frameServer, rootRequestBuilder, 79 CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, 80 Arrays.asList(rootRequestBuilder), /* ae */false, /* af */true); 81 ImageCaptureCommand flashOffCommand = 82 new ZslImageCaptureCommand(logFactory, ringBuffer, metadataPool, flashOffFallback, 83 new AcceptableZslImageFilter(true, false), MAX_LOOKBACK_NANOS); 84 // When flash is Auto, use ZSL and filter images to require AF 85 // convergence, and AE convergence. 86 AutoFlashZslImageFilter autoFlashZslImageFilter = AutoFlashZslImageFilter.create( 87 logFactory, /* afConvergence */true); 88 globalResponseManager.addResponseListener(forPartialMetadata(autoFlashZslImageFilter)); 89 ImageCaptureCommand flashAutoCommand = 90 new ZslImageCaptureCommand(logFactory, ringBuffer, metadataPool, flashOnCommand, 91 autoFlashZslImageFilter, MAX_LOOKBACK_NANOS); 92 93 ImageCaptureCommand flashBasedCommand = new FlashBasedPhotoCommand(logFactory, flashMode, 94 flashOnCommand, flashAutoCommand, flashOffCommand); 95 PictureTakerImpl pictureTaker = new PictureTakerImpl(mainExecutor, commandExecutor, 96 imageSaverBuilder, 97 flashBasedCommand); 98 99 return new ZslPictureTakerFactory(pictureTaker); 100 } 101 102 public PictureTaker providePictureTaker() { 103 return mPictureTaker; 104 } 105 } 106