1 /* 2 * Copyright (C) 2019 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 #ifndef EMULATOR_CAMERA_HAL_HWL_REQUEST_STATE_H 18 #define EMULATOR_CAMERA_HAL_HWL_REQUEST_STATE_H 19 20 #include <mutex> 21 #include <unordered_map> 22 23 #include "EmulatedSensor.h" 24 #include "hwl_types.h" 25 26 namespace android { 27 28 using google_camera_hal::HalCameraMetadata; 29 using google_camera_hal::HalStream; 30 using google_camera_hal::HwlPipelineCallback; 31 using google_camera_hal::HwlPipelineRequest; 32 using google_camera_hal::RequestTemplate; 33 34 struct PendingRequest; 35 36 class EmulatedRequestState { 37 public: EmulatedRequestState(uint32_t camera_id)38 EmulatedRequestState(uint32_t camera_id) : camera_id_(camera_id) { 39 } ~EmulatedRequestState()40 virtual ~EmulatedRequestState() { 41 } 42 43 status_t Initialize(std::unique_ptr<HalCameraMetadata> static_meta); 44 45 status_t GetDefaultRequest( 46 RequestTemplate type, 47 std::unique_ptr<HalCameraMetadata>* default_settings /*out*/); 48 49 std::unique_ptr<HwlPipelineResult> InitializeResult(uint32_t pipeline_id, 50 uint32_t frame_number); 51 52 status_t InitializeSensorSettings( 53 std::unique_ptr<HalCameraMetadata> request_settings, 54 uint32_t override_frame_number, 55 EmulatedSensor::SensorSettings* sensor_settings /*out*/); 56 57 private: 58 bool SupportsCapability(uint8_t cap); 59 60 status_t InitializeRequestDefaults(); 61 status_t InitializeSensorDefaults(); 62 status_t InitializeFlashDefaults(); 63 status_t InitializeControlDefaults(); 64 status_t InitializeControlAEDefaults(); 65 status_t InitializeControlAWBDefaults(); 66 status_t InitializeControlAFDefaults(); 67 status_t InitializeControlSceneDefaults(); 68 status_t InitializeHotPixelDefaults(); 69 status_t InitializeStatisticsDefaults(); 70 status_t InitializeTonemapDefaults(); 71 status_t InitializeBlackLevelDefaults(); 72 status_t InitializeEdgeDefaults(); 73 status_t InitializeShadingDefaults(); 74 status_t InitializeNoiseReductionDefaults(); 75 status_t InitializeColorCorrectionDefaults(); 76 status_t InitializeScalerDefaults(); 77 status_t InitializeReprocessDefaults(); 78 status_t InitializeMeteringRegionDefault(uint32_t tag, 79 int32_t* region /*out*/); 80 status_t InitializeControlefaults(); 81 status_t InitializeInfoDefaults(); 82 status_t InitializeLensDefaults(); 83 84 status_t ProcessAE(); 85 status_t ProcessAF(); 86 status_t ProcessAWB(); 87 status_t DoFakeAE(); 88 status_t CompensateAE(); 89 status_t Update3AMeteringRegion(uint32_t tag, 90 const HalCameraMetadata& settings, 91 int32_t* region /*out*/); 92 93 std::mutex request_state_mutex_; 94 std::unique_ptr<HalCameraMetadata> request_settings_; 95 96 // Supported capabilities and features 97 static const std::set<uint8_t> kSupportedCapabilites; 98 static const std::set<uint8_t> kSupportedHWLevels; 99 std::unique_ptr<HalCameraMetadata> static_metadata_; 100 static const std::vector<int64_t> kSupportedUseCases; 101 102 // android.blacklevel.* 103 uint8_t black_level_lock_ = ANDROID_BLACK_LEVEL_LOCK_ON; 104 bool report_black_level_lock_ = false; 105 106 // android.colorcorrection.* 107 std::set<uint8_t> available_color_aberration_modes_; 108 109 // android.edge.* 110 std::set<uint8_t> available_edge_modes_; 111 bool report_edge_mode_ = false; 112 113 // android.shading.* 114 std::set<uint8_t> available_shading_modes_; 115 116 // android.noiseReduction.* 117 std::set<uint8_t> available_noise_reduction_modes_; 118 119 // android.request.* 120 std::set<uint8_t> available_capabilities_; 121 std::set<int32_t> available_characteristics_; 122 std::set<int32_t> available_results_; 123 std::set<int32_t> available_requests_; 124 uint8_t max_pipeline_depth_ = 0; 125 int32_t partial_result_count_ = 1; // TODO: add support for partial results 126 bool supports_manual_sensor_ = false; 127 bool supports_manual_post_processing_ = false; 128 bool is_backward_compatible_ = false; 129 bool is_raw_capable_ = false; 130 bool supports_private_reprocessing_ = false; 131 bool supports_yuv_reprocessing_ = false; 132 bool supports_remosaic_reprocessing_ = false; 133 bool supports_stream_use_case_ = false; 134 135 // android.control.* 136 struct SceneOverride { 137 uint8_t ae_mode, awb_mode, af_mode; SceneOverrideSceneOverride138 SceneOverride() 139 : ae_mode(ANDROID_CONTROL_AE_MODE_OFF), 140 awb_mode(ANDROID_CONTROL_AWB_MODE_OFF), 141 af_mode(ANDROID_CONTROL_AF_MODE_OFF) { 142 } SceneOverrideSceneOverride143 SceneOverride(uint8_t ae, uint8_t awb, uint8_t af) 144 : ae_mode(ae), awb_mode(awb), af_mode(af) { 145 } 146 }; 147 148 struct FPSRange { 149 int32_t min_fps, max_fps; FPSRangeFPSRange150 FPSRange() : min_fps(-1), max_fps(-1) { 151 } FPSRangeFPSRange152 FPSRange(int32_t min, int32_t max) : min_fps(min), max_fps(max) { 153 } 154 }; 155 156 struct ExtendedSceneModeCapability { 157 int32_t mode, max_width, max_height; 158 float min_zoom, max_zoom; ExtendedSceneModeCapabilityExtendedSceneModeCapability159 ExtendedSceneModeCapability() 160 : mode(ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED), 161 max_width(-1), 162 max_height(-1), 163 min_zoom(1.0f), 164 max_zoom(1.0f) { 165 } ExtendedSceneModeCapabilityExtendedSceneModeCapability166 ExtendedSceneModeCapability(int32_t m, int32_t w, int32_t h, float min_z, 167 float max_z) 168 : mode(m), max_width(w), max_height(h), min_zoom(min_z), max_zoom(max_z) { 169 } 170 }; 171 172 std::set<uint8_t> available_control_modes_; 173 std::set<uint8_t> available_ae_modes_; 174 std::set<uint8_t> available_af_modes_; 175 std::set<uint8_t> available_awb_modes_; 176 std::set<uint8_t> available_scenes_; 177 std::set<uint8_t> available_antibanding_modes_; 178 std::set<uint8_t> available_effects_; 179 std::set<uint8_t> available_vstab_modes_; 180 std::set<uint8_t> available_sensor_pixel_modes_; 181 std::vector<ExtendedSceneModeCapability> available_extended_scene_mode_caps_; 182 std::unordered_map<uint8_t, SceneOverride> scene_overrides_; 183 std::vector<FPSRange> available_fps_ranges_; 184 int32_t exposure_compensation_range_[2] = {0, 0}; 185 float max_zoom_ = 1.0f; 186 bool zoom_ratio_supported_ = false; 187 float min_zoom_ = 1.0f; 188 camera_metadata_rational exposure_compensation_step_ = {0, 1}; 189 bool exposure_compensation_supported_ = false; 190 int32_t exposure_compensation_ = 0; 191 int32_t ae_metering_region_[5] = {0, 0, 0, 0, 0}; 192 int32_t awb_metering_region_[5] = {0, 0, 0, 0, 0}; 193 int32_t af_metering_region_[5] = {0, 0, 0, 0, 0}; 194 size_t max_ae_regions_ = 0; 195 size_t max_awb_regions_ = 0; 196 size_t max_af_regions_ = 0; 197 uint8_t control_mode_ = ANDROID_CONTROL_MODE_AUTO; 198 uint8_t sensor_pixel_mode_ = ANDROID_SENSOR_PIXEL_MODE_DEFAULT; 199 uint8_t scene_mode_ = ANDROID_CONTROL_SCENE_MODE_DISABLED; 200 uint8_t ae_mode_ = ANDROID_CONTROL_AE_MODE_ON; 201 uint8_t awb_mode_ = ANDROID_CONTROL_AWB_MODE_AUTO; 202 uint8_t af_mode_ = ANDROID_CONTROL_AF_MODE_AUTO; 203 uint8_t ae_lock_ = ANDROID_CONTROL_AE_LOCK_OFF; 204 uint8_t ae_state_ = ANDROID_CONTROL_AE_STATE_INACTIVE; 205 uint8_t awb_state_ = ANDROID_CONTROL_AWB_STATE_INACTIVE; 206 uint8_t awb_lock_ = ANDROID_CONTROL_AWB_LOCK_OFF; 207 uint8_t af_state_ = ANDROID_CONTROL_AF_STATE_INACTIVE; 208 uint8_t af_trigger_ = ANDROID_CONTROL_AF_TRIGGER_IDLE; 209 uint8_t ae_trigger_ = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; 210 uint8_t autoframing_ = ANDROID_CONTROL_AUTOFRAMING_OFF; 211 FPSRange ae_target_fps_ = {0, 0}; 212 float zoom_ratio_ = 1.0f; 213 uint8_t extended_scene_mode_ = ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED; 214 static const int32_t kMinimumStreamingFPS = 20; 215 bool ae_lock_available_ = false; 216 bool report_ae_lock_ = false; 217 bool scenes_supported_ = false; 218 size_t ae_frame_counter_ = 0; 219 bool vstab_available_ = false; 220 const size_t kAEPrecaptureMinFrames = 10; 221 // Fake AE related constants 222 const float kExposureTrackRate = .2f; // This is the rate at which the fake 223 // AE will reach the calculated target 224 const size_t kStableAeMaxFrames = 225 100; // The number of frames the fake AE will stay in converged state 226 // After fake AE switches to state searching the exposure 227 // time will wander randomly in region defined by min/max below. 228 const float kExposureWanderMin = -2; 229 const float kExposureWanderMax = 1; 230 const uint32_t kAETargetThreshold = 231 10; // Defines a threshold for reaching the AE target 232 int32_t post_raw_boost_ = 100; 233 bool report_post_raw_boost_ = false; 234 nsecs_t ae_target_exposure_time_ = EmulatedSensor::kDefaultExposureTime; 235 nsecs_t current_exposure_time_ = EmulatedSensor::kDefaultExposureTime; 236 bool awb_lock_available_ = false; 237 bool report_awb_lock_ = false; 238 bool af_mode_changed_ = false; 239 bool af_supported_ = false; 240 bool picture_caf_supported_ = false; 241 bool video_caf_supported_ = false; 242 int32_t settings_override_ = ANDROID_CONTROL_SETTINGS_OVERRIDE_OFF; 243 uint32_t settings_overriding_frame_number_ = 0; 244 245 // android.flash.* 246 bool is_flash_supported_ = false; 247 uint8_t flash_state_ = ANDROID_FLASH_STATE_UNAVAILABLE; 248 249 // android.sensor.* 250 std::pair<int32_t, int32_t> sensor_sensitivity_range_; 251 std::pair<nsecs_t, nsecs_t> sensor_exposure_time_range_; 252 nsecs_t sensor_max_frame_duration_ = 253 EmulatedSensor::kSupportedFrameDurationRange[1]; 254 nsecs_t sensor_exposure_time_ = EmulatedSensor::kDefaultExposureTime; 255 nsecs_t sensor_frame_duration_ = EmulatedSensor::kDefaultFrameDuration; 256 int32_t sensor_sensitivity_ = EmulatedSensor::kDefaultSensitivity; 257 bool report_frame_duration_ = false; 258 bool report_sensitivity_ = false; 259 bool report_exposure_time_ = false; 260 std::set<int32_t> available_test_pattern_modes_; 261 bool report_rolling_shutter_skew_ = false; 262 bool report_neutral_color_point_ = false; 263 bool report_green_split_ = false; 264 bool report_noise_profile_ = false; 265 bool report_extended_scene_mode_ = false; 266 267 // android.scaler.* 268 bool report_rotate_and_crop_ = false; 269 uint8_t rotate_and_crop_ = ANDROID_SCALER_ROTATE_AND_CROP_NONE; 270 int32_t scaler_crop_region_default_[4] = {0, 0, 0, 0}; 271 int32_t scaler_crop_region_max_resolution_[4] = {0, 0, 0, 0}; 272 std::set<uint8_t> available_rotate_crop_modes_; 273 274 // android.statistics.* 275 std::set<uint8_t> available_hot_pixel_map_modes_; 276 std::set<uint8_t> available_lens_shading_map_modes_; 277 std::set<uint8_t> available_face_detect_modes_; 278 uint8_t current_scene_flicker_ = ANDROID_STATISTICS_SCENE_FLICKER_NONE; 279 bool report_scene_flicker_ = false; 280 281 // android.tonemap.* 282 std::set<uint8_t> available_tonemap_modes_; 283 284 // android.info.* 285 uint8_t supported_hw_level_ = 0; 286 static const size_t kTemplateCount = 287 static_cast<size_t>(RequestTemplate::kManual) + 1; 288 std::unique_ptr<HalCameraMetadata> default_requests_[kTemplateCount]; 289 // Set to true if the camera device has HW level FULL or LEVEL3 290 bool is_level_full_or_higher_ = false; 291 292 // android.lens.* 293 float minimum_focus_distance_ = 0.f; 294 float aperture_ = 0.f; 295 float focal_length_ = 0.f; 296 float focus_distance_ = 0.f; 297 bool report_focus_distance_ = false; 298 uint8_t lens_state_ = ANDROID_LENS_STATE_STATIONARY; 299 bool report_focus_range_ = false; 300 float filter_density_ = 0.f; 301 bool report_filter_density_ = false; 302 std::set<uint8_t> available_ois_modes_; 303 uint8_t ois_mode_ = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; 304 bool report_ois_mode_ = false; 305 float pose_rotation_[4] = {.0f}; 306 float pose_translation_[3] = {.0f}; 307 float distortion_[5] = {.0f}; 308 float intrinsic_calibration_[5] = {.0f}; 309 bool report_pose_rotation_ = false; 310 bool report_pose_translation_ = false; 311 bool report_distortion_ = false; 312 bool report_intrinsic_calibration_ = false; 313 int32_t shading_map_size_[2] = {0}; 314 315 unsigned int rand_seed_ = 1; 316 317 // android.hotpixel.* 318 std::set<uint8_t> available_hot_pixel_modes_; 319 320 uint32_t camera_id_; 321 322 EmulatedRequestState(const EmulatedRequestState&) = delete; 323 EmulatedRequestState& operator=(const EmulatedRequestState&) = delete; 324 }; 325 326 } // namespace android 327 328 #endif // EMULATOR_CAMERA_HAL_HWL_REQUEST_STATE_H 329