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 17package com.android.camera.one.v2; 18 19import android.content.Context; 20import android.graphics.ImageFormat; 21import android.hardware.camera2.CameraCharacteristics; 22import android.hardware.camera2.CameraDevice; 23import android.util.DisplayMetrics; 24 25import com.android.camera.FatalErrorHandler; 26import com.android.camera.SoundPlayer; 27import com.android.camera.async.MainThread; 28import com.android.camera.burst.BurstFacade; 29import com.android.camera.debug.Log; 30import com.android.camera.one.OneCamera; 31import com.android.camera.one.OneCameraAccessException; 32import com.android.camera.one.OneCameraCaptureSetting; 33import com.android.camera.one.OneCameraCharacteristics; 34import com.android.camera.one.config.OneCameraFeatureConfig; 35import com.android.camera.one.config.OneCameraFeatureConfig.CaptureSupportLevel; 36import com.android.camera.one.v2.camera2proxy.AndroidCameraDeviceProxy; 37import com.android.camera.one.v2.common.PictureSizeCalculator; 38import com.android.camera.one.v2.imagesaver.ImageSaver; 39import com.android.camera.one.v2.imagesaver.JpegImageBackendImageSaver; 40import com.android.camera.one.v2.imagesaver.YuvImageBackendImageSaver; 41import com.android.camera.one.v2.photo.ImageRotationCalculator; 42import com.android.camera.processing.ProcessingServiceManager; 43import com.android.camera.processing.imagebackend.ImageBackend; 44 45public class OneCameraCreator { 46 private static Log.Tag TAG = new Log.Tag("OneCamCreator"); 47 48 public static OneCamera create( 49 CameraDevice device, 50 CameraCharacteristics characteristics, 51 OneCameraFeatureConfig featureConfig, 52 OneCameraCaptureSetting captureSetting, 53 DisplayMetrics displayMetrics, 54 Context context, 55 MainThread mainThread, 56 ImageRotationCalculator imageRotationCalculator, 57 BurstFacade burstController, 58 SoundPlayer soundPlayer, 59 FatalErrorHandler fatalErrorHandler) throws OneCameraAccessException { 60 // TODO: Might want to switch current camera to vendor HDR. 61 62 CaptureSupportLevel captureSupportLevel = featureConfig 63 .getCaptureSupportLevel(characteristics); 64 Log.i(TAG, "Camera support level: " + captureSupportLevel.name()); 65 66 OneCameraCharacteristics oneCharacteristics = 67 new OneCameraCharacteristicsImpl(characteristics); 68 69 PictureSizeCalculator pictureSizeCalculator = 70 new PictureSizeCalculator(oneCharacteristics); 71 PictureSizeCalculator.Configuration configuration = null; 72 73 OneCameraFactory cameraFactory = null; 74 ImageSaver.Builder imageSaverBuilder = null; 75 ImageBackend imageBackend = ProcessingServiceManager.instance().getImageBackend(); 76 77 // Depending on the support level of the camera, choose the right 78 // configuration. 79 switch (captureSupportLevel) { 80 case LIMITED_JPEG: 81 case LEGACY_JPEG: 82 // LIMITED and LEGACY have different picture takers which will 83 // be selected by the support level that is passes into 84 // #createOneCamera below - otherwise they use the same OneCamera and image backend. 85 cameraFactory = new SimpleOneCameraFactory(ImageFormat.JPEG, 86 featureConfig.getMaxAllowedImageReaderCount(), 87 imageRotationCalculator); 88 configuration = pictureSizeCalculator.computeConfiguration( 89 captureSetting.getCaptureSize(), 90 ImageFormat.JPEG); 91 imageSaverBuilder = new JpegImageBackendImageSaver(imageRotationCalculator, 92 imageBackend, configuration.getPostCaptureCrop()); 93 break; 94 case LIMITED_YUV: 95 // Same as above, but we're using YUV images. 96 cameraFactory = new SimpleOneCameraFactory(ImageFormat.YUV_420_888, 97 featureConfig.getMaxAllowedImageReaderCount(), 98 imageRotationCalculator); 99 configuration = pictureSizeCalculator.computeConfiguration( 100 captureSetting.getCaptureSize(), 101 ImageFormat.YUV_420_888); 102 imageSaverBuilder = new YuvImageBackendImageSaver(imageRotationCalculator, 103 imageBackend, 104 configuration.getPostCaptureCrop()); 105 break; 106 case ZSL: 107 // ZSL has its own OneCamera and produces YUV images. 108 cameraFactory = new ZslOneCameraFactory(ImageFormat.YUV_420_888, 109 featureConfig.getMaxAllowedImageReaderCount()); 110 configuration = pictureSizeCalculator.computeConfiguration( 111 captureSetting.getCaptureSize(), 112 ImageFormat.YUV_420_888); 113 imageSaverBuilder = new YuvImageBackendImageSaver(imageRotationCalculator, 114 imageBackend, configuration.getPostCaptureCrop()); 115 break; 116 } 117 118 Log.i(TAG, "Picture Size Configuration: " + configuration); 119 120 return cameraFactory.createOneCamera(new AndroidCameraDeviceProxy(device), 121 new OneCameraCharacteristicsImpl(characteristics), 122 captureSupportLevel, 123 mainThread, 124 configuration.getNativeOutputSize(), 125 imageSaverBuilder, 126 captureSetting.getFlashSetting(), 127 captureSetting.getExposureSetting(), 128 captureSetting.getHdrSceneSetting(), 129 burstController, 130 fatalErrorHandler); 131 } 132} 133