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