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