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 typedef camera_metadata_enum_android_request_available_dynamic_range_profiles_map 109 DynamicRangeProfile; 110 typedef camera_metadata_enum_android_request_available_color_space_profiles_map 111 ColorSpaceProfile; 112 typedef camera_metadata_enum_android_scaler_available_stream_use_cases 113 StreamUseCase; 114 115 // See the definition of 116 // ::android::hardware::camera::device::V3_8::Stream; 117 struct Stream { 118 int32_t id = -1; 119 StreamType stream_type = StreamType::kOutput; 120 uint32_t width = 0; 121 uint32_t height = 0; 122 android_pixel_format_t format = HAL_PIXEL_FORMAT_RGBA_8888; 123 uint64_t usage = 0; 124 android_dataspace_t data_space = HAL_DATASPACE_UNKNOWN; 125 StreamRotation rotation = StreamRotation::kRotation0; 126 bool is_physical_camera_stream = false; 127 uint32_t physical_camera_id = 0; 128 uint32_t buffer_size = 0; 129 int32_t group_id = -1; 130 bool intended_for_max_resolution_mode = false; 131 bool intended_for_default_resolution_mode = true; 132 DynamicRangeProfile dynamic_profile = 133 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD; 134 StreamUseCase use_case = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT; 135 ColorSpaceProfile color_space = 136 ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED; 137 }; 138 139 // See the definition of 140 // ::android::hardware::camera::device::V3_2::StreamConfigurationMode; 141 enum class StreamConfigurationMode : uint32_t { 142 kNormal = 0, 143 kConstrainedHighSpeed, 144 }; 145 146 // See the definition of 147 // ::android::hardware::camera::device::V3_8::StreamConfiguration; 148 struct StreamConfiguration { 149 std::vector<Stream> streams; 150 StreamConfigurationMode operation_mode; 151 std::unique_ptr<HalCameraMetadata> session_params; 152 uint32_t stream_config_counter = 0; 153 bool multi_resolution_input_image = false; 154 long log_id = 0; 155 }; 156 157 struct CameraIdAndStreamConfiguration { 158 uint32_t camera_id = 0; 159 StreamConfiguration stream_configuration; 160 }; 161 162 // See the definition of 163 // ::android::hardware::camera::device::V3_4::HalStream 164 struct HalStream { 165 int32_t id = -1; 166 android_pixel_format_t override_format = HAL_PIXEL_FORMAT_RGBA_8888; 167 uint64_t producer_usage = 0; 168 uint64_t consumer_usage = 0; 169 uint32_t max_buffers = 0; 170 android_dataspace_t override_data_space = HAL_DATASPACE_UNKNOWN; 171 bool is_physical_camera_stream = false; 172 uint32_t physical_camera_id = 0; 173 }; 174 175 // See the definition of 176 // ::android::hardware::camera::device::V3_2::BufferCache 177 struct BufferCache { 178 int32_t stream_id = -1; 179 uint64_t buffer_id = 0; 180 181 bool operator==(const BufferCache& other) const { 182 return stream_id == other.stream_id && buffer_id == other.buffer_id; 183 } 184 }; 185 186 // See the definition of 187 // ::android::hardware::camera::device::V3_2::BufferStatus 188 enum class BufferStatus : uint32_t { 189 kOk = 0, 190 kError, 191 }; 192 193 // See the definition of 194 // ::android::hardware::camera::device::V3_2::StreamBuffer 195 struct StreamBuffer { 196 int32_t stream_id = -1; 197 uint64_t buffer_id = 0; 198 buffer_handle_t buffer = nullptr; 199 BufferStatus status = BufferStatus::kOk; 200 201 // The fences are owned by the caller. If they will be used after a call 202 // returns, the callee should duplicate it. 203 const native_handle_t* acquire_fence = nullptr; 204 const native_handle_t* release_fence = nullptr; 205 }; 206 207 // See the definition of 208 // ::android::hardware::camera::device::V3_4::CaptureRequest 209 struct CaptureRequest { 210 uint32_t frame_number = 0; 211 std::unique_ptr<HalCameraMetadata> settings; 212 213 // If empty, the output buffers are captured from the camera sensors. If 214 // not empty, the output buffers are captured from the input buffers. 215 std::vector<StreamBuffer> input_buffers; 216 217 // The metadata of the input_buffers. This is used for multi-frame merging 218 // like HDR+. The input_buffer_metadata at entry k must be for the input 219 // buffer at entry k in the input_buffers. 220 std::vector<std::unique_ptr<HalCameraMetadata>> input_buffer_metadata; 221 222 std::vector<StreamBuffer> output_buffers; 223 224 // Maps from physical camera ID to physical camera settings. 225 std::unordered_map<uint32_t, std::unique_ptr<HalCameraMetadata>> 226 physical_camera_settings; 227 228 uint32_t input_width; 229 uint32_t input_height; 230 }; 231 232 // See the definition of 233 // ::android::hardware::camera::device::V3_2::RequestTemplate 234 enum class RequestTemplate : uint32_t { 235 kPreview = 1, 236 kStillCapture = 2, 237 kVideoRecord = 3, 238 kVideoSnapshot = 4, 239 kZeroShutterLag = 5, 240 kManual = 6, 241 kVendorTemplateStart = 0x40000000, 242 }; 243 244 // See the definition of 245 // ::android::hardware::camera::device::V3_2::MsgType 246 enum class MessageType : uint32_t { 247 kError = 1, 248 kShutter = 2, 249 }; 250 251 // See the definition of 252 // ::android::hardware::camera::device::V3_2::ErrorCode 253 enum class ErrorCode : uint32_t { 254 kErrorDevice = 1, 255 kErrorRequest = 2, 256 kErrorResult = 3, 257 kErrorBuffer = 4, 258 }; 259 260 // See the definition of 261 // ::android::hardware::camera::device::V3_2::ErrorMsg 262 struct ErrorMessage { 263 uint32_t frame_number = 0; 264 int32_t error_stream_id = -1; 265 ErrorCode error_code = ErrorCode::kErrorDevice; 266 }; 267 268 // See the definition of 269 // ::android::hardware::camera::device::V3_8::ShutterMsg 270 struct ShutterMessage { 271 uint32_t frame_number = 0; 272 uint64_t timestamp_ns = 0; 273 uint64_t readout_timestamp_ns = 0; 274 }; 275 276 // See the definition of 277 // ::android::hardware::camera::device::V3_8::NotifyMsg 278 struct NotifyMessage { 279 MessageType type = MessageType::kError; 280 281 union Message { 282 ErrorMessage error; 283 ShutterMessage shutter; 284 } message; 285 }; 286 287 // See the definition of 288 // ::android::hardware::camera::device::V3_4::PhysicalCameraMetadata 289 struct PhysicalCameraMetadata { 290 uint32_t physical_camera_id = 0; 291 std::unique_ptr<HalCameraMetadata> metadata; 292 }; 293 294 // See the definition of 295 // ::android::hardware::camera::device::V3_4::CaptureResult 296 struct CaptureResult { 297 uint32_t frame_number = 0; 298 std::unique_ptr<HalCameraMetadata> result_metadata; 299 std::vector<StreamBuffer> output_buffers; 300 std::vector<StreamBuffer> input_buffers; 301 uint32_t partial_result = 0; 302 std::vector<PhysicalCameraMetadata> physical_metadata; 303 }; 304 305 struct Rect { 306 uint32_t left; 307 uint32_t top; 308 uint32_t right; 309 uint32_t bottom; 310 }; 311 312 struct WeightedRect : Rect { 313 int32_t weight; 314 }; 315 316 struct Dimension { 317 uint32_t width = 0; 318 uint32_t height = 0; 319 }; 320 321 struct Point { 322 uint32_t x; 323 uint32_t y; 324 }; 325 326 struct PointI { 327 int32_t x; 328 int32_t y; 329 }; 330 331 struct PointF { 332 float x = 0.0f; 333 float y = 0.0f; 334 }; 335 336 // Hash function for std::pair 337 struct PairHash { 338 template <class T1, class T2> operatorPairHash339 std::size_t operator()(const std::pair<T1, T2>& p) const { 340 return std::hash<T1>{}(p.first) ^ std::hash<T2>{}(p.second); 341 } 342 }; 343 344 // See the definition of 345 // ::android::hardware::camera::device::V3_5::BufferRequestStatus; 346 enum class BufferRequestStatus : uint32_t { 347 kOk = 0, 348 kFailedPartial = 1, 349 kFailedConfiguring = 2, 350 kFailedIllegalArgs = 3, 351 kFailedUnknown = 4, 352 }; 353 354 // See the definition of 355 // ::android::hardware::camera::device::V3_5::StreamBufferRequestError 356 enum class StreamBufferRequestError : uint32_t { 357 kOk = 0, 358 kNoBufferAvailable = 1, 359 kMaxBufferExceeded = 2, 360 kStreamDisconnected = 3, 361 kUnknownError = 4, 362 }; 363 364 // See the definition of 365 // ::android::hardware::camera::device::V3_5::BufferRequest 366 struct BufferRequest { 367 int32_t stream_id = -1; 368 uint32_t num_buffers_requested = 0; 369 }; 370 371 // See the definition of 372 // ::android::hardware::camera::device::V3_5::StreamBuffersVal 373 struct BuffersValue { 374 StreamBufferRequestError error = StreamBufferRequestError::kUnknownError; 375 std::vector<StreamBuffer> buffers; 376 }; 377 378 // See the definition of 379 // ::android::hardware::camera::device::V3_5::StreamBufferRet 380 struct BufferReturn { 381 int32_t stream_id = -1; 382 BuffersValue val; 383 }; 384 385 // See the definition of 386 // ::android::hardware::camera::provider::V2_5::DeviceState 387 enum class DeviceState : uint64_t { 388 kNormal = 0ull, 389 kBackCovered = 1 << 0, 390 kFrontCovered = 1 << 1, 391 kFolded = 1 << 2, 392 kMaxDeviceState = 1 << 3 // for data validation 393 }; 394 395 // Callback function invoked to process capture results. 396 using ProcessCaptureResultFunc = 397 std::function<void(std::unique_ptr<CaptureResult> /*result*/)>; 398 399 // Callback function invoked to notify messages. 400 using NotifyFunc = std::function<void(const NotifyMessage& /*message*/)>; 401 402 // HAL buffer allocation descriptor 403 struct HalBufferDescriptor { 404 int32_t stream_id = -1; 405 uint32_t width = 0; 406 uint32_t height = 0; 407 android_pixel_format_t format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; 408 uint64_t producer_flags = 0; 409 uint64_t consumer_flags = 0; 410 uint32_t immediate_num_buffers = 0; 411 uint32_t max_num_buffers = 0; 412 uint64_t allocator_id_ = 0; 413 }; 414 415 // Callback function invoked to request stream buffers. 416 using RequestStreamBuffersFunc = std::function<BufferRequestStatus( 417 const std::vector<BufferRequest>& /*buffer_requests*/, 418 std::vector<BufferReturn>* /*buffer_returns*/)>; 419 420 // Callback function invoked to return stream buffers. 421 using ReturnStreamBuffersFunc = 422 std::function<void(const std::vector<StreamBuffer>& /*buffers*/)>; 423 424 struct ZoomRatioRange { 425 float min = 1.0f; 426 float max = 1.0f; 427 }; 428 429 } // namespace google_camera_hal 430 } // namespace android 431 432 #endif // HARDWARE_GOOGLE_CAMERA_HAL_COMMON_HAL_TYPES_H_ 433