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