Home | History | Annotate | Download | only in portability
      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.ex.camera2.portability;
     18 
     19 import android.hardware.Camera;
     20 import com.android.ex.camera2.portability.debug.Log;
     21 
     22 /**
     23  * The subclass of {@link CameraSettings} for Android Camera 1 API.
     24  */
     25 public class AndroidCameraSettings extends CameraSettings {
     26     private static final Log.Tag TAG = new Log.Tag("AndCamSet");
     27 
     28     private static final String TRUE = "true";
     29     private static final String RECORDING_HINT = "recording-hint";
     30 
     31     public AndroidCameraSettings(CameraCapabilities capabilities, Camera.Parameters params) {
     32         if (params == null) {
     33             Log.w(TAG, "Settings ctor requires a non-null Camera.Parameters.");
     34             return;
     35         }
     36 
     37         CameraCapabilities.Stringifier stringifier = capabilities.getStringifier();
     38 
     39         setSizesLocked(false);
     40 
     41         // Preview
     42         Camera.Size paramPreviewSize = params.getPreviewSize();
     43         setPreviewSize(new Size(paramPreviewSize.width, paramPreviewSize.height));
     44         setPreviewFrameRate(params.getPreviewFrameRate());
     45         int[] previewFpsRange = new int[2];
     46         params.getPreviewFpsRange(previewFpsRange);
     47         setPreviewFpsRange(previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
     48                 previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
     49         setPreviewFormat(params.getPreviewFormat());
     50 
     51         // Capture: Focus, flash, zoom, exposure, scene mode.
     52         if (capabilities.supports(CameraCapabilities.Feature.ZOOM)) {
     53             setZoomRatio(params.getZoomRatios().get(params.getZoom()) / 100f);
     54         } else {
     55             setZoomRatio(CameraCapabilities.ZOOM_RATIO_UNZOOMED);
     56         }
     57         setExposureCompensationIndex(params.getExposureCompensation());
     58         setFlashMode(stringifier.flashModeFromString(params.getFlashMode()));
     59         setFocusMode(stringifier.focusModeFromString(params.getFocusMode()));
     60         setSceneMode(stringifier.sceneModeFromString(params.getSceneMode()));
     61 
     62         // Video capture.
     63         if (capabilities.supports(CameraCapabilities.Feature.VIDEO_STABILIZATION)) {
     64             setVideoStabilization(isVideoStabilizationEnabled());
     65         }
     66         setRecordingHintEnabled(TRUE.equals(params.get(RECORDING_HINT)));
     67 
     68         // Output: Photo size, compression quality
     69         setPhotoJpegCompressionQuality(params.getJpegQuality());
     70         Camera.Size paramPictureSize = params.getPictureSize();
     71         setPhotoSize(new Size(paramPictureSize.width, paramPictureSize.height));
     72         setPhotoFormat(params.getPictureFormat());
     73     }
     74 
     75     public AndroidCameraSettings(AndroidCameraSettings other) {
     76         super(other);
     77     }
     78 
     79     @Override
     80     public CameraSettings copy() {
     81         return new AndroidCameraSettings(this);
     82     }
     83 }
     84