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