• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "SessionConfigurationUtilsHost.h"
18 
19 namespace android {
20 namespace camera3 {
21 namespace SessionConfigurationUtils {
22 
getAppropriateModeTag(int32_t defaultTag,bool maxResolution)23 int32_t getAppropriateModeTag(int32_t defaultTag, bool maxResolution) {
24     if (!maxResolution) {
25         return defaultTag;
26     }
27     switch (defaultTag) {
28         case ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS:
29             return ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION;
30         case ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS:
31             return ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION;
32         case ANDROID_SCALER_AVAILABLE_STALL_DURATIONS:
33             return ANDROID_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION;
34         case ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS:
35             return ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION;
36         case ANDROID_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS:
37             return ANDROID_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION;
38         case ANDROID_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS:
39             return ANDROID_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS_MAXIMUM_RESOLUTION;
40         case ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS:
41             return ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION;
42         case ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_MIN_FRAME_DURATIONS:
43             return ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION;
44         case ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS:
45             return ANDROID_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS_MAXIMUM_RESOLUTION;
46         case ANDROID_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS:
47             return ANDROID_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION;
48         case ANDROID_HEIC_AVAILABLE_HEIC_MIN_FRAME_DURATIONS:
49             return ANDROID_HEIC_AVAILABLE_HEIC_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION;
50         case ANDROID_HEIC_AVAILABLE_HEIC_STALL_DURATIONS:
51             return ANDROID_HEIC_AVAILABLE_HEIC_STALL_DURATIONS_MAXIMUM_RESOLUTION;
52         case ANDROID_JPEGR_AVAILABLE_JPEG_R_STREAM_CONFIGURATIONS:
53             return ANDROID_JPEGR_AVAILABLE_JPEG_R_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION;
54         case ANDROID_JPEGR_AVAILABLE_JPEG_R_MIN_FRAME_DURATIONS:
55             return ANDROID_JPEGR_AVAILABLE_JPEG_R_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION;
56         case ANDROID_JPEGR_AVAILABLE_JPEG_R_STALL_DURATIONS:
57             return ANDROID_JPEGR_AVAILABLE_JPEG_R_STALL_DURATIONS_MAXIMUM_RESOLUTION;
58         case ANDROID_SENSOR_OPAQUE_RAW_SIZE:
59             return ANDROID_SENSOR_OPAQUE_RAW_SIZE_MAXIMUM_RESOLUTION;
60         case ANDROID_LENS_INTRINSIC_CALIBRATION:
61             return ANDROID_LENS_INTRINSIC_CALIBRATION_MAXIMUM_RESOLUTION;
62         case ANDROID_LENS_DISTORTION:
63             return ANDROID_LENS_DISTORTION_MAXIMUM_RESOLUTION;
64         case ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE:
65             return ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION;
66         case ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE:
67             return ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION;
68         default:
69             ALOGE("%s: Tag %d doesn't have a maximum resolution counterpart", __FUNCTION__,
70                     defaultTag);
71             return -1;
72     }
73     return -1;
74 }
75 
isKeyPresentWithCount(const CameraMetadata & deviceInfo,uint32_t tag,uint32_t count)76 static bool isKeyPresentWithCount(const CameraMetadata &deviceInfo, uint32_t tag, uint32_t count) {
77     auto countFound = deviceInfo.find(tag).count;
78     return (countFound != 0) && (countFound % count == 0);
79 }
80 
supportsKeysForBasicUltraHighResolutionCapture(const CameraMetadata & deviceInfo)81 static bool supportsKeysForBasicUltraHighResolutionCapture(const CameraMetadata &deviceInfo) {
82     // Check whether the following conditions are satisfied for reduced ultra high
83     // resolution support :
84     // 1) SENSOR_PIXEL_MODE is advertised in ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS
85     // 2) The following keys are present in CameraCharacteristics for basic functionality
86     //        a) ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION
87     //        b) ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION
88     //        c) ANDROID_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION
89     //        d) ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
90     //        e) ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
91     //        f) ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE_MAXIMUM_RESOLUTION
92     camera_metadata_ro_entry_t entryChar;
93     entryChar = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
94     bool supportsSensorPixelMode = false;
95     for (size_t i = 0; i < entryChar.count; i++) {
96         int32_t key = entryChar.data.i32[i];
97         if (key == ANDROID_SENSOR_PIXEL_MODE) {
98             supportsSensorPixelMode = true;
99             break;
100         }
101     }
102     if (!supportsSensorPixelMode) {
103         return false;
104     }
105 
106     // Basic sensor array size information tags are present
107     if (!isKeyPresentWithCount(deviceInfo, ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE_MAXIMUM_RESOLUTION,
108             /*count*/2) ||
109             !isKeyPresentWithCount(deviceInfo,
110                     ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION,
111                     /*count*/4) ||
112             !isKeyPresentWithCount(deviceInfo,
113                     ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION, /*count*/4) ||
114             !isKeyPresentWithCount(deviceInfo, ANDROID_SENSOR_INFO_BINNING_FACTOR, /*count*/2)) {
115         return false;
116     }
117 
118     // Basic stream configuration tags are present
119     if (!isKeyPresentWithCount(deviceInfo,
120             ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION, /*count*/4) ||
121             !isKeyPresentWithCount(deviceInfo,
122                     ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION, /*count*/4) ||
123             !isKeyPresentWithCount(deviceInfo,
124                     ANDROID_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION, /*count*/ 4)) {
125         return false;
126     }
127 
128     return true;
129 }
130 
supportsUltraHighResolutionCapture(const CameraMetadata & deviceInfo)131 bool supportsUltraHighResolutionCapture(const CameraMetadata &deviceInfo) {
132     camera_metadata_ro_entry_t entryCap;
133     entryCap = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
134     // Go through the capabilities and check if it has
135     // ANDROID_REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR
136     for (size_t i = 0; i < entryCap.count; ++i) {
137         uint8_t capability = entryCap.data.u8[i];
138         if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR) {
139             return true;
140         }
141     }
142 
143     // If not, then check that the keys which guarantee basic supports for
144     // ultra high resolution capture are supported.
145     return supportsKeysForBasicUltraHighResolutionCapture(deviceInfo);
146 }
147 
getArrayWidthAndHeight(const CameraMetadata * deviceInfo,int32_t arrayTag,int32_t * width,int32_t * height)148 bool getArrayWidthAndHeight(const CameraMetadata *deviceInfo,
149         int32_t arrayTag, int32_t *width, int32_t *height) {
150     if (width == nullptr || height == nullptr) {
151         ALOGE("%s: width / height nullptr", __FUNCTION__);
152         return false;
153     }
154     camera_metadata_ro_entry_t entry;
155     entry = deviceInfo->find(arrayTag);
156     if (entry.count != 4) return false;
157     *width = entry.data.i32[2];
158     *height = entry.data.i32[3];
159     return true;
160 }
161 
162 } // namespace SessionConfigurationUtils
163 } // namespace camera3
164 } // namespace android
165