1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file types.h 18 * 19 * @brief Declares data types 20 * used by the Hardware Driver Interfaces (HDIs) of this module. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 #ifndef CAMERA_DEVICE_DRIVER_TYPES_H 27 #define CAMERA_DEVICE_DRIVER_TYPES_H 28 29 #include <functional> 30 #include <iostream> 31 #include <memory> 32 #include <string> 33 #include <vector> 34 #include <surface.h> 35 #include "camera_metadata_info.h" 36 37 namespace OHOS::Camera { 38 using CameraAbility = CameraStandard::CameraMetadata; 39 using CameraSetting = CameraStandard::CameraMetadata; 40 41 /** 42 * @brief buffer key information of ExtraGet() and ExtraSet(). 43 */ 44 const std::string dataSize = "dataSize"; // int32_t 45 const std::string timeStamp = "timeStamp"; // int64_t 46 const std::string isKeyFrame = "isKeyFrame"; // int32_t 1:true 0:false 47 48 /** 49 * @brief Enumerates return values of the HDIs. 50 */ 51 using CamRetCode = enum _CamRetCode : int32_t { 52 /** 53 * Successful call. 54 */ 55 NO_ERROR = 0, 56 57 /** 58 * The camera device is busy. 59 */ 60 CAMERA_BUSY = 1, 61 62 /** 63 * Insufficient resources. 64 */ 65 INSUFFICIENT_RESOURCES = 2, 66 67 /** 68 * Invalid parameters. 69 */ 70 INVALID_ARGUMENT = 3, 71 72 /** 73 * Unsupported function. 74 */ 75 METHOD_NOT_SUPPORTED = 4, 76 77 /** 78 * The camera device is closed. 79 */ 80 CAMERA_CLOSED = 5, 81 82 /** 83 * A critical error occurs at the driver layer. 84 */ 85 DEVICE_ERROR = 6, 86 }; 87 88 /** 89 * @brief Enumerates metadata reporting modes. 90 */ 91 using ResultCallbackMode = enum _ResultCallbackMode : int32_t { 92 /** 93 * Frame-by-frame reporting 94 */ 95 PER_FRAME, 96 97 /** 98 * Reporting upon device status change 99 */ 100 ON_CHANGED 101 }; 102 103 /** 104 * @brief Enumerates stream operation modes. 105 */ 106 using OperationMode = enum _OperationMode : int32_t { 107 /** 108 * Normal 109 */ 110 NORMAL = 0, 111 }; 112 113 /** 114 * @brief Enumerates stream types. 115 */ 116 using StreamIntent = enum _StreamIntent : int32_t { 117 /** 118 * Preview streams, indicating that stream data is used for preview 119 */ 120 PREVIEW = 0, 121 122 /** 123 * Video streams, indicating that stream data is used to encode and generate videos 124 */ 125 VIDEO = 1, 126 127 /** 128 * Photographing streams, indicating that stream data is used to encode and generate images 129 */ 130 STILL_CAPTURE = 2, 131 132 /** 133 * Stream data that is used to store thumbnails 134 */ 135 POST_VIEW = 3, 136 137 /** 138 * Stream data that is used for image analysis 139 */ 140 ANALYZE = 4, 141 142 /** 143 * Custom type 144 */ 145 CUSTOM = 5, 146 }; 147 148 /** 149 * @brief Enumerates encoding types of stream data. 150 */ 151 using EncodeType = enum _EncodeType : int32_t { 152 /** 153 * Unspecified 154 */ 155 ENCODE_TYPE_NULL = 0, 156 157 /** 158 * H.264 159 */ 160 ENCODE_TYPE_H264 = 1, 161 162 /** 163 * H.265 164 */ 165 ENCODE_TYPE_H265 = 2, 166 167 /** 168 * JPEG 169 */ 170 ENCODE_TYPE_JPEG = 3, 171 }; 172 173 /** 174 * @brief Defines the stream information, which is used to pass configuration parameters during stream creation. 175 */ 176 using StreamInfo = struct _StreamInfo { 177 /** 178 * Stream ID, which uniquely identifies a stream on a camera device. 179 */ 180 int streamId_; 181 182 /** 183 * Image width. 184 */ 185 int width_; 186 187 /** 188 * Image height. 189 */ 190 int height_; 191 192 /** 193 * Image format. 194 */ 195 int format_; 196 197 /** 198 * Image color space. 199 */ 200 int datasapce_; 201 202 /** 203 * Stream type. 204 */ 205 StreamIntent intent_; 206 207 /** 208 * Tunnel mode. The value <b>true</b> means that the tunnel mode is enabled, and <b>false</b> means the opposite. 209 * 210 * After the tunnel mode is enabled, 211 * the hardware abstraction layer (HAL) does not directly interact with the upper layer. 212 * Instead, it uses the producer handle provided by the graphics layer to transfer frame data. 213 * You need to disable the tunnel mode for IoT devices that do not support 214 * or require image data caching and forwarding of preview streams. 215 */ 216 bool tunneledMode_; 217 218 /** 219 * Producer handle provided by the graphics layer. 220 */ 221 OHOS::sptr<OHOS::IBufferProducer> bufferQueue_; 222 223 /** 224 * Minimum frame interval. 225 */ 226 int minFrameDuration_; 227 228 /** 229 * Encoding type. 230 */ 231 EncodeType encodeType_; 232 }; 233 234 /** 235 * @brief Enumerates the support types of the stream. For details about the application scenario, 236 * see {@link IsStreamsSupported}. 237 */ 238 using StreamSupportType = enum _StreamSupportType : int32_t { 239 /** 240 * The stream can be dynamically created, and the corresponding stream parameters take effect directly. 241 */ 242 DYNAMIC_SUPPORTED, 243 244 /** 245 * The stream cannot be dynamically created, 246 * and the corresponding parameters take effect only after the existing stream is stopped and reconfigured. 247 */ 248 RE_CONFIGURED_REQUIRED, 249 250 /** 251 * The stream cannot be dynamically created. 252 */ 253 NOT_SUPPORTED, 254 }; 255 256 /** 257 * @brief Defines the stream attributes. 258 */ 259 using StreamAttribute = struct _StreamAttribute { 260 /** 261 * Stream ID, which uniquely identifies a stream on a camera device. 262 */ 263 int streamId_; 264 265 /** 266 * Image width. 267 */ 268 int width_; 269 270 /** 271 * Image height. 272 */ 273 int height_; 274 275 /** 276 * New image format. 277 */ 278 int overrideFormat_; 279 280 /** 281 * New image color space. 282 */ 283 int overrideDatasapce_; 284 285 /** 286 * New procedure usage. 287 */ 288 int producerUsage_; 289 290 /** 291 * New number of produce buffers. 292 */ 293 int producerBufferCount_; 294 295 /** 296 * Maximum number of frames that can be captured in a continuous capture. 297 */ 298 int maxBatchCaptureCount_; 299 300 /** 301 * Maximum number of concurrent capture requests. The default value is <b>1</b>. 302 */ 303 int maxCaptureCount_; 304 }; 305 306 /** 307 * @brief Defines the information about a capture request. 308 */ 309 using CaptureInfo = struct _CaptureInfo { 310 /** 311 * IDs of captured streams. 312 */ 313 std::vector<int> streamIds_; 314 315 /** 316 * Captured configuration information. 317 */ 318 std::shared_ptr<CameraStandard::CameraMetadata> captureSetting_; 319 320 /** 321 * Whether to enable callback for each capture. If enabled, {@link OnFrameShutter} is called upon each capture. 322 */ 323 bool enableShutterCallback_; 324 }; 325 326 /** 327 * @brief Enumerates camera device statuses. 328 */ 329 using CameraStatus = enum _CameraStatus { 330 /** 331 * The camera device is not in position or is unavailable. 332 */ 333 UN_AVAILABLE = 0, 334 335 /** 336 * The camera device is available. 337 */ 338 AVAILABLE = 1, 339 }; 340 341 /** 342 * @brief Enumerates flash statuses. 343 */ 344 using FlashlightStatus = enum _FlashlightStatus : uint32_t { 345 /** 346 * The flash is off. 347 */ 348 FLASHLIGHT_OFF = 0, 349 350 /** 351 * The flash is on. 352 */ 353 FLASHLIGHT_ON = 1, 354 355 /** 356 * The flash is unavailable. 357 */ 358 FLASHLIGHT_UNAVAILABLE = 2, 359 }; 360 361 /** 362 * @brief Enumerates camera device error types, which are used by {@link OnError}. 363 */ 364 using ErrorType = enum _ErrorTyp : uint32_t { 365 /** 366 * A critical error occurs. The camera device needs to be closed. 367 */ 368 FATAL_ERROR = 0, 369 370 /** 371 * A request timeout occurs. The camera device needs to be closed. 372 */ 373 REQUEST_TIMEOUT = 1, 374 }; 375 376 /** 377 * @brief Defines the information about the end of packet capture, which is used by {@link OnCaptureEnded}. 378 */ 379 using CaptureEndedInfo = struct _CaptureEndedInfo { 380 /** 381 * ID of a captured stream. 382 */ 383 int streamId_; 384 385 /** 386 * Number of frames that have been captured when the capture ends. 387 */ 388 int frameCount_; 389 }; 390 391 /** 392 * @brief Enumerates stream error types, which are used by {@link CaptureErrorInfo}. 393 */ 394 using StreamError = enum _StreamError { 395 /** 396 * Unknown error 397 */ 398 UNKNOWN_ERROR = 0, 399 400 /** 401 * Packet loss 402 */ 403 BUFFER_LOST = 1, 404 }; 405 406 /** 407 * @brief Defines the stream error information, which is used by {@link OnCaptureError}. 408 */ 409 using CaptureErrorInfo = struct _CaptureErrorInfo { 410 /** 411 * Stream ID 412 */ 413 int streamId_; 414 415 /** 416 * Error type 417 */ 418 StreamError error_; 419 }; 420 421 using MetaType = int32_t; 422 423 class IBuffer; 424 } 425 #endif /* CAMERA_DEVICE_DRIVER_TYPES_H */ 426