OneCameraCharacteristicsImpl.java revision 5cbdddd3ba0241b60dbd7a0ab44cfc08dc5e8fc9
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.graphics.Rect;
20import android.graphics.SurfaceTexture;
21import android.hardware.camera2.CameraCharacteristics;
22import android.hardware.camera2.params.StreamConfigurationMap;
23
24import com.android.camera.one.OneCamera;
25import com.android.camera.one.OneCameraCharacteristics;
26import com.android.camera.util.Size;
27
28import java.util.ArrayList;
29import java.util.List;
30
31import static com.google.common.base.Preconditions.checkNotNull;
32
33/**
34 * Describes a OneCamera device which is on top of camera2 API. This is
35 * essential a wrapper for #{link
36 * android.hardware.camera2.CameraCharacteristics}.
37 */
38public class OneCameraCharacteristicsImpl implements OneCameraCharacteristics {
39    private final CameraCharacteristics mCameraCharacteristics;
40
41    public OneCameraCharacteristicsImpl(CameraCharacteristics cameraCharacteristics) {
42        mCameraCharacteristics = cameraCharacteristics;
43    }
44
45    @Override
46    public List<Size> getSupportedPictureSizes(int imageFormat) {
47        StreamConfigurationMap configMap =
48                mCameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
49        ArrayList<Size> supportedPictureSizes = new ArrayList<>();
50        for (android.util.Size androidSize : configMap.getOutputSizes(imageFormat)) {
51            supportedPictureSizes.add(new Size(androidSize));
52        }
53        return supportedPictureSizes;
54    }
55
56    @Override
57    public List<Size> getSupportedPreviewSizes() {
58        StreamConfigurationMap configMap =
59                mCameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
60        ArrayList<Size> supportedPictureSizes = new ArrayList<>();
61        for (android.util.Size androidSize : configMap.getOutputSizes(SurfaceTexture.class)) {
62            supportedPictureSizes.add(new Size(androidSize));
63        }
64        return supportedPictureSizes;
65    }
66
67    @Override
68    public int getSensorOrientation() {
69        return mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
70    }
71
72    @Override
73    public OneCamera.Facing getCameraDirection() {
74        int direction = mCameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
75        if (direction == CameraCharacteristics.LENS_FACING_BACK) {
76            return OneCamera.Facing.BACK;
77        } else {
78            return OneCamera.Facing.FRONT;
79        }
80    }
81
82    @Override
83    public Rect getSensorInfoActiveArraySize() {
84        return mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
85    }
86
87    @Override
88    public float getAvailableMaxDigitalZoom() {
89        return mCameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
90    }
91
92    @Override
93    public boolean isFlashSupported() {
94        return mCameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
95    }
96
97    @Override
98    public SupportedHardwareLevel getSupportedHardwareLevel() {
99        Integer supportedHardwareLevel = mCameraCharacteristics.get(CameraCharacteristics
100                .INFO_SUPPORTED_HARDWARE_LEVEL);
101        // If this fails, it is a framework bug, per API documentation.
102        checkNotNull(supportedHardwareLevel, "INFO_SUPPORTED_HARDWARE_LEVEL not found");
103        switch ((int) supportedHardwareLevel) {
104            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
105                return SupportedHardwareLevel.FULL;
106            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
107                return SupportedHardwareLevel.LIMITED;
108            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
109                return SupportedHardwareLevel.LEGACY;
110            default:
111                throw new IllegalStateException("Invalid value for INFO_SUPPORTED_HARDWARE_LEVEL");
112        }
113    }
114}
115