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 HARDWARE_GOOGLE_CAMERA_HAL_COMMON_HAL_TYPES_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_COMMON_HAL_TYPES_H_ 19 20 #include <cutils/native_handle.h> 21 #include <system/graphics-base-v1.0.h> 22 #include <string> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "hal_camera_metadata.h" 27 28 namespace android { 29 namespace google_camera_hal { 30 31 using ::android::status_t; 32 33 // Used to identify an invalid buffer handle. 34 static constexpr buffer_handle_t kInvalidBufferHandle = nullptr; 35 36 // See the definition of 37 // ::android::hardware::camera::common::V1_0::TorchMode 38 enum class TorchMode : uint32_t { 39 kOff = 0, 40 kOn = 1, 41 }; 42 43 // See the definition of 44 // ::hardware::camera::common::V1_0::CameraDeviceStatus 45 enum class CameraDeviceStatus : uint32_t { 46 kNotPresent = 0, 47 kPresent, 48 kEnumerating, 49 }; 50 51 // See the definition of 52 // ::hardware::camera::common::V1_0::TorchModeStatus 53 enum class TorchModeStatus : uint32_t { 54 kNotAvailable = 0, 55 kAvailableOff, 56 kAvailableOn, 57 }; 58 59 // See the definition of 60 // ::android::hardware::camera::common::V1_0::CameraResourceCost 61 struct CameraResourceCost { 62 uint32_t resource_cost = 0; 63 std::vector<uint32_t> conflicting_devices; 64 }; 65 66 // See the definition of 67 // ::android::hardware::camera::common::V1_0::CameraMetadataType 68 enum class CameraMetadataType : uint32_t { 69 kByte = 0, 70 kInt32, 71 kFloat, 72 kInt64, 73 kDouble, 74 kRational, 75 }; 76 77 // See the definition of 78 // ::android::hardware::camera::common::V1_0::VendorTag 79 struct VendorTag { 80 uint32_t tag_id = 0; 81 std::string tag_name; 82 CameraMetadataType tag_type = CameraMetadataType::kByte; 83 }; 84 85 // See the definition of 86 // ::android::hardware::camera::common::V1_0::VendorTagSection 87 struct VendorTagSection { 88 std::string section_name; 89 std::vector<VendorTag> tags; 90 }; 91 92 // See the definition of 93 // ::android::hardware::camera::device::V3_2::StreamType; 94 enum class StreamType : uint32_t { 95 kOutput = 0, 96 kInput, 97 }; 98 99 // See the definition of 100 // ::android::hardware::camera::device::V3_2::StreamRotation; 101 enum class StreamRotation : uint32_t { 102 kRotation0 = 0, 103 kRotation90, 104 kRotation180, 105 kRotation270, 106 }; 107 108 // See the definition of 109 // ::android::hardware::camera::device::V3_8::Stream; 110 struct Stream { 111 int32_t id = -1; 112 StreamType stream_type = StreamType::kOutput; 113 uint32_t width = 0; 114 uint32_t height = 0; 115 android_pixel_format_t format = HAL_PIXEL_FORMAT_RGBA_8888; 116 uint64_t usage = 0; 117 android_dataspace_t data_space = HAL_DATASPACE_UNKNOWN; 118 StreamRotation rotation = StreamRotation::kRotation0; 119 bool is_physical_camera_stream = false; 120 uint32_t physical_camera_id = 0; 121 uint32_t buffer_size = 0; 122 int32_t group_id = -1; 123 bool used_in_max_resolution_mode = false; 124 bool used_in_default_resolution_mode = true; 125 camera_metadata_enum_android_request_available_dynamic_range_profiles_map 126 dynamic_profile = 127 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD; 128 camera_metadata_enum_android_scaler_available_stream_use_cases use_case = 129 ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT; 130 }; 131 132 // See the definition of 133 // ::android::hardware::camera::device::V3_2::StreamConfigurationMode; 134 enum class StreamConfigurationMode : uint32_t { 135 kNormal = 0, 136 kConstrainedHighSpeed, 137 }; 138 139 // See the definition of 140 // ::android::hardware::camera::device::V3_8::StreamConfiguration; 141 struct StreamConfiguration { 142 std::vector<Stream> streams; 143 StreamConfigurationMode operation_mode; 144 std::unique_ptr<HalCameraMetadata> session_params; 145 uint32_t stream_config_counter = 0; 146 bool multi_resolution_input_image = false; 147 }; 148 149 struct CameraIdAndStreamConfiguration { 150 uint32_t camera_id = 0; 151 StreamConfiguration stream_configuration; 152 }; 153 154 // See the definition of 155 // ::android::hardware::camera::device::V3_4::HalStream 156 struct HalStream { 157 int32_t id = -1; 158 android_pixel_format_t override_format = HAL_PIXEL_FORMAT_RGBA_8888; 159 uint64_t producer_usage = 0; 160 uint64_t consumer_usage = 0; 161 uint32_t max_buffers = 0; 162 android_dataspace_t override_data_space = HAL_DATASPACE_UNKNOWN; 163 bool is_physical_camera_stream = false; 164 uint32_t physical_camera_id = 0; 165 }; 166 167 // See the definition of 168 // ::android::hardware::camera::device::V3_2::BufferCache 169 struct BufferCache { 170 int32_t stream_id = -1; 171 uint64_t buffer_id = 0; 172 173 bool operator==(const BufferCache& other) const { 174 return stream_id == other.stream_id && buffer_id == other.buffer_id; 175 } 176 }; 177 178 // See the definition of 179 // ::android::hardware::camera::device::V3_2::BufferStatus 180 enum class BufferStatus : uint32_t { 181 kOk = 0, 182 kError, 183 }; 184 185 // See the definition of 186 // ::android::hardware::camera::device::V3_2::StreamBuffer 187 struct StreamBuffer { 188 int32_t stream_id = -1; 189 uint64_t buffer_id = 0; 190 buffer_handle_t buffer = nullptr; 191 BufferStatus status = BufferStatus::kOk; 192 193 // The fences are owned by the caller. If they will be used after a call 194 // returns, the callee should duplicate it. 195 const native_handle_t* acquire_fence = nullptr; 196 const native_handle_t* release_fence = nullptr; 197 }; 198 199 // See the definition of 200 // ::android::hardware::camera::device::V3_4::CaptureRequest 201 struct CaptureRequest { 202 uint32_t frame_number = 0; 203 std::unique_ptr<HalCameraMetadata> settings; 204 205 // If empty, the output buffers are captured from the camera sensors. If 206 // not empty, the output buffers are captured from the input buffers. 207 std::vector<StreamBuffer> input_buffers; 208 209 // The metadata of the input_buffers. This is used for multi-frame merging 210 // like HDR+. The input_buffer_metadata at entry k must be for the input 211 // buffer at entry k in the input_buffers. 212 std::vector<std::unique_ptr<HalCameraMetadata>> input_buffer_metadata; 213 214 std::vector<StreamBuffer> output_buffers; 215 216 // Maps from physical camera ID to physical camera settings. 217 std::unordered_map<uint32_t, std::unique_ptr<HalCameraMetadata>> 218 physical_camera_settings; 219 220 uint32_t input_width; 221 uint32_t input_height; 222 }; 223 224 // See the definition of 225 // ::android::hardware::camera::device::V3_2::RequestTemplate 226 enum class RequestTemplate : uint32_t { 227 kPreview = 1, 228 kStillCapture = 2, 229 kVideoRecord = 3, 230 kVideoSnapshot = 4, 231 kZeroShutterLag = 5, 232 kManual = 6, 233 kVendorTemplateStart = 0x40000000, 234 }; 235 236 // See the definition of 237 // ::android::hardware::camera::device::V3_2::MsgType 238 enum class MessageType : uint32_t { 239 kError = 1, 240 kShutter = 2, 241 }; 242 243 // See the definition of 244 // ::android::hardware::camera::device::V3_2::ErrorCode 245 enum class ErrorCode : uint32_t { 246 kErrorDevice = 1, 247 kErrorRequest = 2, 248 kErrorResult = 3, 249 kErrorBuffer = 4, 250 }; 251 252 // See the definition of 253 // ::android::hardware::camera::device::V3_2::ErrorMsg 254 struct ErrorMessage { 255 uint32_t frame_number = 0; 256 int32_t error_stream_id = -1; 257 ErrorCode error_code = ErrorCode::kErrorDevice; 258 }; 259 260 // See the definition of 261 // ::android::hardware::camera::device::V3_8::ShutterMsg 262 struct ShutterMessage { 263 uint32_t frame_number = 0; 264 uint64_t timestamp_ns = 0; 265 uint64_t readout_timestamp_ns = 0; 266 }; 267 268 // See the definition of 269 // ::android::hardware::camera::device::V3_8::NotifyMsg 270 struct NotifyMessage { 271 MessageType type = MessageType::kError; 272 273 union Message { 274 ErrorMessage error; 275 ShutterMessage shutter; 276 } message; 277 }; 278 279 // See the definition of 280 // ::android::hardware::camera::device::V3_4::PhysicalCameraMetadata 281 struct PhysicalCameraMetadata { 282 uint32_t physical_camera_id = 0; 283 std::unique_ptr<HalCameraMetadata> metadata; 284 }; 285 286 // See the definition of 287 // ::android::hardware::camera::device::V3_4::CaptureResult 288 struct CaptureResult { 289 uint32_t frame_number = 0; 290 std::unique_ptr<HalCameraMetadata> result_metadata; 291 std::vector<StreamBuffer> output_buffers; 292 std::vector<StreamBuffer> input_buffers; 293 uint32_t partial_result = 0; 294 std::vector<PhysicalCameraMetadata> physical_metadata; 295 }; 296 297 struct Rect { 298 uint32_t left; 299 uint32_t top; 300 uint32_t right; 301 uint32_t bottom; 302 }; 303 304 struct WeightedRect : Rect { 305 int32_t weight; 306 }; 307 308 struct Dimension { 309 uint32_t width = 0; 310 uint32_t height = 0; 311 }; 312 313 struct Point { 314 uint32_t x; 315 uint32_t y; 316 }; 317 318 struct PointI { 319 int32_t x; 320 int32_t y; 321 }; 322 323 struct PointF { 324 float x = 0.0f; 325 float y = 0.0f; 326 }; 327 328 // Hash function for std::pair 329 struct PairHash { 330 template <class T1, class T2> operatorPairHash331 std::size_t operator()(const std::pair<T1, T2>& p) const { 332 return std::hash<T1>{}(p.first) ^ std::hash<T2>{}(p.second); 333 } 334 }; 335 336 // See the definition of 337 // ::android::hardware::camera::device::V3_5::BufferRequestStatus; 338 enum class BufferRequestStatus : uint32_t { 339 kOk = 0, 340 kFailedPartial = 1, 341 kFailedConfiguring = 2, 342 kFailedIllegalArgs = 3, 343 kFailedUnknown = 4, 344 }; 345 346 // See the definition of 347 // ::android::hardware::camera::device::V3_5::StreamBufferRequestError 348 enum class StreamBufferRequestError : uint32_t { 349 kOk = 0, 350 kNoBufferAvailable = 1, 351 kMaxBufferExceeded = 2, 352 kStreamDisconnected = 3, 353 kUnknownError = 4, 354 }; 355 356 // See the definition of 357 // ::android::hardware::camera::device::V3_5::BufferRequest 358 struct BufferRequest { 359 int32_t stream_id = -1; 360 uint32_t num_buffers_requested = 0; 361 }; 362 363 // See the definition of 364 // ::android::hardware::camera::device::V3_5::StreamBuffersVal 365 struct BuffersValue { 366 StreamBufferRequestError error = StreamBufferRequestError::kUnknownError; 367 std::vector<StreamBuffer> buffers; 368 }; 369 370 // See the definition of 371 // ::android::hardware::camera::device::V3_5::StreamBufferRet 372 struct BufferReturn { 373 int32_t stream_id = -1; 374 BuffersValue val; 375 }; 376 377 // See the definition of 378 // ::android::hardware::camera::provider::V2_5::DeviceState 379 enum class DeviceState : uint64_t { 380 kNormal = 0ull, 381 kBackCovered = 1ull, 382 kFrontCovered = 2ull, 383 kFolded = 4ull 384 }; 385 386 // Callback function invoked to process capture results. 387 using ProcessCaptureResultFunc = 388 std::function<void(std::unique_ptr<CaptureResult> /*result*/)>; 389 390 // Callback function invoked to notify messages. 391 using NotifyFunc = std::function<void(const NotifyMessage& /*message*/)>; 392 393 // HAL buffer allocation descriptor 394 struct HalBufferDescriptor { 395 int32_t stream_id = -1; 396 uint32_t width = 0; 397 uint32_t height = 0; 398 android_pixel_format_t format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; 399 uint64_t producer_flags = 0; 400 uint64_t consumer_flags = 0; 401 uint32_t immediate_num_buffers = 0; 402 uint32_t max_num_buffers = 0; 403 uint64_t allocator_id_ = 0; 404 }; 405 406 // Callback function invoked to request stream buffers. 407 using RequestStreamBuffersFunc = std::function<BufferRequestStatus( 408 const std::vector<BufferRequest>& /*buffer_requests*/, 409 std::vector<BufferReturn>* /*buffer_returns*/)>; 410 411 // Callback function invoked to return stream buffers. 412 using ReturnStreamBuffersFunc = 413 std::function<void(const std::vector<StreamBuffer>& /*buffers*/)>; 414 415 struct ZoomRatioRange { 416 float min = 1.0f; 417 float max = 1.0f; 418 }; 419 420 } // namespace google_camera_hal 421 } // namespace android 422 423 #endif // HARDWARE_GOOGLE_CAMERA_HAL_COMMON_HAL_TYPES_H_ 424