camera2.h revision 7f8dd0ad2d3d40b57c8359971a351fd194668613
1/* 2 * Copyright (C) 2012 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 ANDROID_INCLUDE_CAMERA2_H 18#define ANDROID_INCLUDE_CAMERA2_H 19 20#include "camera_common.h" 21#include "system/camera_metadata.h" 22 23/** 24 * Camera device HAL 2.0 [ CAMERA_DEVICE_API_VERSION_2_0 ] 25 * 26 * EXPERIMENTAL. 27 * 28 * Supports both the android.hardware.ProCamera and 29 * android.hardware.Camera APIs. 30 * 31 * Camera devices that support this version of the HAL must return 32 * CAMERA_DEVICE_API_VERSION_2_0 in camera_device_t.common.version and in 33 * camera_info_t.device_version (from camera_module_t.get_camera_info). 34 * 35 * Camera modules that may contain version 2.0 devices must implement at least 36 * version 2.0 of the camera module interface (as defined by 37 * camera_module_t.common.module_api_version). 38 * 39 * See camera_common.h for more versioning details. 40 * 41 */ 42 43__BEGIN_DECLS 44 45struct camera2_device; 46 47/********************************************************************** 48 * 49 * Input/output stream buffer queue interface definitions 50 * 51 */ 52 53/** 54 * Output image stream queue interface. A set of these methods is provided to 55 * the HAL device in allocate_stream(), and are used to interact with the 56 * gralloc buffer queue for that stream. They may not be called until after 57 * allocate_stream returns. 58 */ 59typedef struct camera2_stream_ops { 60 /** 61 * Get a buffer to fill from the queue. The size and format of the buffer 62 * are fixed for a given stream (defined in allocate_stream), and the stride 63 * should be queried from the platform gralloc module. The gralloc buffer 64 * will have been allocated based on the usage flags provided by 65 * allocate_stream, and will be locked for use. 66 */ 67 int (*dequeue_buffer)(const struct camera2_stream_ops* w, 68 buffer_handle_t** buffer); 69 70 /** 71 * Push a filled buffer to the stream to be used by the consumer. 72 * 73 * The timestamp represents the time at start of exposure of the first row 74 * of the image; it must be from a monotonic clock, and is measured in 75 * nanoseconds. The timestamps do not need to be comparable between 76 * different cameras, or consecutive instances of the same camera. However, 77 * they must be comparable between streams from the same camera. If one 78 * capture produces buffers for multiple streams, each stream must have the 79 * same timestamp for that buffer, and that timestamp must match the 80 * timestamp in the output frame metadata. 81 */ 82 int (*enqueue_buffer)(const struct camera2_stream_ops* w, 83 int64_t timestamp, 84 buffer_handle_t* buffer); 85 /** 86 * Return a buffer to the queue without marking it as filled. 87 */ 88 int (*cancel_buffer)(const struct camera2_stream_ops* w, 89 buffer_handle_t* buffer); 90 /** 91 * Set the crop window for subsequently enqueued buffers. The parameters are 92 * measured in pixels relative to the buffer width and height. 93 */ 94 int (*set_crop)(const struct camera2_stream_ops *w, 95 int left, int top, int right, int bottom); 96 97} camera2_stream_ops_t; 98 99/** 100 * Temporary definition during transition. TODO: Remove once HALs no longer 101 * reference this */ 102enum { 103 CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED 104}; 105 106/** 107 * Input reprocess stream queue management. A set of these methods is provided 108 * to the HAL device in allocate_reprocess_stream(); they are used to interact 109 * with the reprocess stream's input gralloc buffer queue. 110 */ 111typedef struct camera2_stream_in_ops { 112 /** 113 * Get the next buffer of image data to reprocess. The width, height, and 114 * format of the buffer is fixed in allocate_reprocess_stream(), and the 115 * stride and other details should be queried from the platform gralloc 116 * module as needed. The buffer will already be locked for use. 117 */ 118 int (*acquire_buffer)(const struct camera2_stream_in_ops *w, 119 buffer_handle_t** buffer); 120 /** 121 * Return a used buffer to the buffer queue for reuse. 122 */ 123 int (*release_buffer)(const struct camera2_stream_in_ops *w, 124 buffer_handle_t* buffer); 125 126} camera2_stream_in_ops_t; 127 128/********************************************************************** 129 * 130 * Metadata queue management, used for requests sent to HAL module, and for 131 * frames produced by the HAL. 132 * 133 */ 134 135enum { 136 CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1 137}; 138 139/** 140 * Request input queue protocol: 141 * 142 * The framework holds the queue and its contents. At start, the queue is empty. 143 * 144 * 1. When the first metadata buffer is placed into the queue, the framework 145 * signals the device by calling notify_request_queue_not_empty(). 146 * 147 * 2. After receiving notify_request_queue_not_empty, the device must call 148 * dequeue() once it's ready to handle the next buffer. 149 * 150 * 3. Once the device has processed a buffer, and is ready for the next buffer, 151 * it must call dequeue() again instead of waiting for a notification. If 152 * there are no more buffers available, dequeue() will return NULL. After 153 * this point, when a buffer becomes available, the framework must call 154 * notify_request_queue_not_empty() again. If the device receives a NULL 155 * return from dequeue, it does not need to query the queue again until a 156 * notify_request_queue_not_empty() call is received from the source. 157 * 158 * 4. If the device calls buffer_count() and receives 0, this does not mean that 159 * the framework will provide a notify_request_queue_not_empty() call. The 160 * framework will only provide such a notification after the device has 161 * received a NULL from dequeue, or on initial startup. 162 * 163 * 5. The dequeue() call in response to notify_request_queue_not_empty() may be 164 * on the same thread as the notify_request_queue_not_empty() call, and may 165 * be performed from within the notify call. 166 * 167 * 6. All dequeued request buffers must be returned to the framework by calling 168 * free_request, including when errors occur, a device flush is requested, or 169 * when the device is shutting down. 170 */ 171typedef struct camera2_request_queue_src_ops { 172 /** 173 * Get the count of request buffers pending in the queue. May return 174 * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream 175 * request) is currently configured. Calling this method has no effect on 176 * whether the notify_request_queue_not_empty() method will be called by the 177 * framework. 178 */ 179 int (*request_count)(const struct camera2_request_queue_src_ops *q); 180 181 /** 182 * Get a metadata buffer from the framework. Returns OK if there is no 183 * error. If the queue is empty, returns NULL in buffer. In that case, the 184 * device must wait for a notify_request_queue_not_empty() message before 185 * attempting to dequeue again. Buffers obtained in this way must be 186 * returned to the framework with free_request(). 187 */ 188 int (*dequeue_request)(const struct camera2_request_queue_src_ops *q, 189 camera_metadata_t **buffer); 190 /** 191 * Return a metadata buffer to the framework once it has been used, or if 192 * an error or shutdown occurs. 193 */ 194 int (*free_request)(const struct camera2_request_queue_src_ops *q, 195 camera_metadata_t *old_buffer); 196 197} camera2_request_queue_src_ops_t; 198 199/** 200 * Frame output queue protocol: 201 * 202 * The framework holds the queue and its contents. At start, the queue is empty. 203 * 204 * 1. When the device is ready to fill an output metadata frame, it must dequeue 205 * a metadata buffer of the required size. 206 * 207 * 2. It should then fill the metadata buffer, and place it on the frame queue 208 * using enqueue_frame. The framework takes ownership of the frame. 209 * 210 * 3. In case of an error, a request to flush the pipeline, or shutdown, the 211 * device must return any affected dequeued frames to the framework by 212 * calling cancel_frame. 213 */ 214typedef struct camera2_frame_queue_dst_ops { 215 /** 216 * Get an empty metadata buffer to fill from the framework. The new metadata 217 * buffer will have room for entries number of metadata entries, plus 218 * data_bytes worth of extra storage. Frames dequeued here must be returned 219 * to the framework with either cancel_frame or enqueue_frame. 220 */ 221 int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q, 222 size_t entries, size_t data_bytes, 223 camera_metadata_t **buffer); 224 225 /** 226 * Return a dequeued metadata buffer to the framework for reuse; do not mark it as 227 * filled. Use when encountering errors, or flushing the internal request queue. 228 */ 229 int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q, 230 camera_metadata_t *buffer); 231 232 /** 233 * Place a completed metadata frame on the frame output queue. 234 */ 235 int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q, 236 camera_metadata_t *buffer); 237 238} camera2_frame_queue_dst_ops_t; 239 240/********************************************************************** 241 * 242 * Notification callback and message definition, and trigger definitions 243 * 244 */ 245 246/** 247 * Asynchronous notification callback from the HAL, fired for various 248 * reasons. Only for information independent of frame capture, or that require 249 * specific timing. The user pointer must be the same one that was passed to the 250 * device in set_notify_callback(). 251 */ 252typedef void (*camera2_notify_callback)(int32_t msg_type, 253 int32_t ext1, 254 int32_t ext2, 255 int32_t ext3, 256 void *user); 257 258/** 259 * Possible message types for camera2_notify_callback 260 */ 261enum { 262 /** 263 * An error has occurred. Argument ext1 contains the error code, and 264 * ext2 and ext3 contain any error-specific information. 265 */ 266 CAMERA2_MSG_ERROR = 0x0001, 267 /** 268 * The exposure of a given request has begun. Argument ext1 contains the 269 * frame number, and ext2 and ext3 contain the low-order and high-order 270 * bytes of the timestamp for when exposure began. 271 * (timestamp = (ext3 << 32 | ext2)) 272 */ 273 CAMERA2_MSG_SHUTTER = 0x0010, 274 /** 275 * The autofocus routine has changed state. Argument ext1 contains the new 276 * state; the values are the same as those for the metadata field 277 * android.control.afState. Ext2 contains the latest trigger ID passed to 278 * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or 279 * trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not 280 * been called with either of those actions. 281 */ 282 CAMERA2_MSG_AUTOFOCUS = 0x0020, 283 /** 284 * The autoexposure routine has changed state. Argument ext1 contains the 285 * new state; the values are the same as those for the metadata field 286 * android.control.aeState. Ext2 contains the latest trigger ID value passed to 287 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method 288 * has not been called. 289 */ 290 CAMERA2_MSG_AUTOEXPOSURE = 0x0021, 291 /** 292 * The auto-whitebalance routine has changed state. Argument ext1 contains 293 * the new state; the values are the same as those for the metadata field 294 * android.control.awbState. Ext2 contains the latest trigger ID passed to 295 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method 296 * has not been called. 297 */ 298 CAMERA2_MSG_AUTOWB = 0x0022 299}; 300 301/** 302 * Error codes for CAMERA_MSG_ERROR 303 */ 304enum { 305 /** 306 * A serious failure occured. Camera device may not work without reboot, and 307 * no further frames or buffer streams will be produced by the 308 * device. Device should be treated as closed. 309 */ 310 CAMERA2_MSG_ERROR_HARDWARE = 0x0001, 311 /** 312 * A serious failure occured. No further frames or buffer streams will be 313 * produced by the device. Device should be treated as closed. The client 314 * must reopen the device to use it again. 315 */ 316 CAMERA2_MSG_ERROR_DEVICE, 317 /** 318 * An error has occurred in processing a request. No output (metadata or 319 * buffers) will be produced for this request. ext2 contains the frame 320 * number of the request. Subsequent requests are unaffected, and the device 321 * remains operational. 322 */ 323 CAMERA2_MSG_ERROR_REQUEST, 324 /** 325 * An error has occurred in producing an output frame metadata buffer for a 326 * request, but image buffers for it will still be available. Subsequent 327 * requests are unaffected, and the device remains operational. ext2 328 * contains the frame number of the request. 329 */ 330 CAMERA2_MSG_ERROR_FRAME, 331 /** 332 * An error has occurred in placing an output buffer into a stream for a 333 * request. The frame metadata and other buffers may still be 334 * available. Subsequent requests are unaffected, and the device remains 335 * operational. ext2 contains the frame number of the request, and ext3 336 * contains the stream id. 337 */ 338 CAMERA2_MSG_ERROR_STREAM, 339 /** 340 * Number of error types 341 */ 342 CAMERA2_MSG_NUM_ERRORS 343}; 344 345/** 346 * Possible trigger ids for trigger_action() 347 */ 348enum { 349 /** 350 * Trigger an autofocus cycle. The effect of the trigger depends on the 351 * autofocus mode in effect when the trigger is received, which is the mode 352 * listed in the latest capture request to be dequeued by the HAL. If the 353 * mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO, 354 * or CONTINUOUS_* modes, see below for the expected behavior. The state of 355 * the autofocus cycle can be tracked in android.control.afMode and the 356 * corresponding notifications. 357 * 358 ** 359 * In AUTO or MACRO mode, the AF state transitions (and notifications) 360 * when calling with trigger ID = N with the previous ID being K are: 361 * 362 * Initial state Transitions 363 * INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 364 * AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 365 * AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 366 * ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N) 367 * PASSIVE_SCAN (K) Not used in AUTO/MACRO mode 368 * PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode 369 * 370 ** 371 * In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current 372 * lens position and transition the AF state to either AF_FOCUSED or 373 * NOT_FOCUSED. If a passive scan is underway, that scan must complete and 374 * then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS 375 * will allow the AF to restart its operation. 376 * 377 * Initial state Transitions 378 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 379 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 380 * PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 381 * AF_FOCUSED (K) no effect except to change next notification ID to N 382 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N 383 * 384 ** 385 * In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current 386 * lens position and transition the AF state to either AF_FOCUSED or 387 * NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in 388 * contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will 389 * allow the AF to restart its operation. 390 * 391 * Initial state Transitions 392 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 393 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 394 * PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N) 395 * AF_FOCUSED (K) no effect except to change next notification ID to N 396 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N 397 * 398 * Ext1 is an ID that must be returned in subsequent auto-focus state change 399 * notifications through camera2_notify_callback() and stored in 400 * android.control.afTriggerId. 401 */ 402 CAMERA2_TRIGGER_AUTOFOCUS = 0x0001, 403 /** 404 * Send a cancel message to the autofocus algorithm. The effect of the 405 * cancellation depends on the autofocus mode in effect when the trigger is 406 * received, which is the mode listed in the latest capture request to be 407 * dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no 408 * effect. For other modes, the lens should return to its default position, 409 * any current autofocus scan must be canceled, and the AF state should be 410 * set to INACTIVE. 411 * 412 * The state of the autofocus cycle can be tracked in android.control.afMode 413 * and the corresponding notification. Continuous autofocus modes may resume 414 * focusing operations thereafter exactly as if the camera had just been set 415 * to a continuous AF mode. 416 * 417 * Ext1 is an ID that must be returned in subsequent auto-focus state change 418 * notifications through camera2_notify_callback() and stored in 419 * android.control.afTriggerId. 420 */ 421 CAMERA2_TRIGGER_CANCEL_AUTOFOCUS, 422 /** 423 * Trigger a pre-capture metering cycle, which may include firing the flash 424 * to determine proper capture parameters. Typically, this trigger would be 425 * fired for a half-depress of a camera shutter key, or before a snapshot 426 * capture in general. The state of the metering cycle can be tracked in 427 * android.control.aeMode and the corresponding notification. If the 428 * auto-exposure mode is OFF, the trigger does nothing. 429 * 430 * Ext1 is an ID that must be returned in subsequent 431 * auto-exposure/auto-white balance state change notifications through 432 * camera2_notify_callback() and stored in android.control.aePrecaptureId. 433 */ 434 CAMERA2_TRIGGER_PRECAPTURE_METERING 435}; 436 437/** 438 * Possible template types for construct_default_request() 439 */ 440enum { 441 /** 442 * Standard camera preview operation with 3A on auto. 443 */ 444 CAMERA2_TEMPLATE_PREVIEW = 1, 445 /** 446 * Standard camera high-quality still capture with 3A and flash on auto. 447 */ 448 CAMERA2_TEMPLATE_STILL_CAPTURE, 449 /** 450 * Standard video recording plus preview with 3A on auto, torch off. 451 */ 452 CAMERA2_TEMPLATE_VIDEO_RECORD, 453 /** 454 * High-quality still capture while recording video. Application will 455 * include preview, video record, and full-resolution YUV or JPEG streams in 456 * request. Must not cause stuttering on video stream. 3A on auto. 457 */ 458 CAMERA2_TEMPLATE_VIDEO_SNAPSHOT, 459 /** 460 * Zero-shutter-lag mode. Application will request preview and 461 * full-resolution data for each frame, and reprocess it to JPEG when a 462 * still image is requested by user. Settings should provide highest-quality 463 * full-resolution images without compromising preview frame rate. 3A on 464 * auto. 465 */ 466 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG, 467 468 /* Total number of templates */ 469 CAMERA2_TEMPLATE_COUNT 470}; 471 472 473/********************************************************************** 474 * 475 * Camera device operations 476 * 477 */ 478typedef struct camera2_device_ops { 479 480 /********************************************************************** 481 * Request and frame queue setup and management methods 482 */ 483 484 /** 485 * Pass in input request queue interface methods. 486 */ 487 int (*set_request_queue_src_ops)(const struct camera2_device *, 488 const camera2_request_queue_src_ops_t *request_src_ops); 489 490 /** 491 * Notify device that the request queue is no longer empty. Must only be 492 * called when the first buffer is added a new queue, or after the source 493 * has returned NULL in response to a dequeue call. 494 */ 495 int (*notify_request_queue_not_empty)(const struct camera2_device *); 496 497 /** 498 * Pass in output frame queue interface methods 499 */ 500 int (*set_frame_queue_dst_ops)(const struct camera2_device *, 501 const camera2_frame_queue_dst_ops_t *frame_dst_ops); 502 503 /** 504 * Number of camera requests being processed by the device at the moment 505 * (captures/reprocesses that have had their request dequeued, but have not 506 * yet been enqueued onto output pipeline(s) ). No streams may be released 507 * by the framework until the in-progress count is 0. 508 */ 509 int (*get_in_progress_count)(const struct camera2_device *); 510 511 /** 512 * Flush all in-progress captures. This includes all dequeued requests 513 * (regular or reprocessing) that have not yet placed any outputs into a 514 * stream or the frame queue. Partially completed captures must be completed 515 * normally. No new requests may be dequeued from the request queue until 516 * the flush completes. 517 */ 518 int (*flush_captures_in_progress)(const struct camera2_device *); 519 520 /** 521 * Create a filled-in default request for standard camera use cases. 522 * 523 * The device must return a complete request that is configured to meet the 524 * requested use case, which must be one of the CAMERA2_TEMPLATE_* 525 * enums. All request control fields must be included, except for 526 * android.request.outputStreams. 527 * 528 * The metadata buffer returned must be allocated with 529 * allocate_camera_metadata. The framework takes ownership of the buffer. 530 */ 531 int (*construct_default_request)(const struct camera2_device *, 532 int request_template, 533 camera_metadata_t **request); 534 535 /********************************************************************** 536 * Stream management 537 */ 538 539 /** 540 * allocate_stream: 541 * 542 * Allocate a new output stream for use, defined by the output buffer width, 543 * height, target, and possibly the pixel format. Returns the new stream's 544 * ID, gralloc usage flags, minimum queue buffer count, and possibly the 545 * pixel format, on success. Error conditions: 546 * 547 * - Requesting a width/height/format combination not listed as 548 * supported by the sensor's static characteristics 549 * 550 * - Asking for too many streams of a given format type (2 bayer raw 551 * streams, for example). 552 * 553 * Input parameters: 554 * 555 * - width, height, format: Specification for the buffers to be sent through 556 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If 557 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform 558 * gralloc module will select a format based on the usage flags provided 559 * by the camera HAL and the consumer of the stream. The camera HAL should 560 * inspect the buffers handed to it in the register_stream_buffers call to 561 * obtain the implementation-specific format if necessary. 562 * 563 * - stream_ops: A structure of function pointers for obtaining and queuing 564 * up buffers for this stream. The underlying stream will be configured 565 * based on the usage and max_buffers outputs. The methods in this 566 * structure may not be called until after allocate_stream returns. 567 * 568 * Output parameters: 569 * 570 * - stream_id: An unsigned integer identifying this stream. This value is 571 * used in incoming requests to identify the stream, and in releasing the 572 * stream. 573 * 574 * - usage: The gralloc usage mask needed by the HAL device for producing 575 * the requested type of data. This is used in allocating new gralloc 576 * buffers for the stream buffer queue. 577 * 578 * - max_buffers: The maximum number of buffers the HAL device may need to 579 * have dequeued at the same time. The device may not dequeue more buffers 580 * than this value at the same time. 581 * 582 */ 583 int (*allocate_stream)( 584 const struct camera2_device *, 585 // inputs 586 uint32_t width, 587 uint32_t height, 588 int format, 589 const camera2_stream_ops_t *stream_ops, 590 // outputs 591 uint32_t *stream_id, 592 uint32_t *format_actual, // IGNORED, will be removed 593 uint32_t *usage, 594 uint32_t *max_buffers); 595 596 /** 597 * Register buffers for a given stream. This is called after a successful 598 * allocate_stream call, and before the first request referencing the stream 599 * is enqueued. This method is intended to allow the HAL device to map or 600 * otherwise prepare the buffers for later use. num_buffers is guaranteed to 601 * be at least max_buffers (from allocate_stream), but may be larger. The 602 * buffers will already be locked for use. At the end of the call, all the 603 * buffers must be ready to be returned to the queue. If the stream format 604 * was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should 605 * inspect the passed-in buffers here to determine any platform-private 606 * pixel format information. 607 */ 608 int (*register_stream_buffers)( 609 const struct camera2_device *, 610 uint32_t stream_id, 611 int num_buffers, 612 buffer_handle_t *buffers); 613 614 /** 615 * Release a stream. Returns an error if called when get_in_progress_count 616 * is non-zero, or if the stream id is invalid. 617 */ 618 int (*release_stream)( 619 const struct camera2_device *, 620 uint32_t stream_id); 621 622 /** 623 * allocate_reprocess_stream: 624 * 625 * Allocate a new input stream for use, defined by the output buffer width, 626 * height, and the pixel format. Returns the new stream's ID, gralloc usage 627 * flags, and required simultaneously acquirable buffer count, on 628 * success. Error conditions: 629 * 630 * - Requesting a width/height/format combination not listed as 631 * supported by the sensor's static characteristics 632 * 633 * - Asking for too many reprocessing streams to be configured at once. 634 * 635 * Input parameters: 636 * 637 * - width, height, format: Specification for the buffers to be sent through 638 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list. 639 * 640 * - reprocess_stream_ops: A structure of function pointers for acquiring 641 * and releasing buffers for this stream. The underlying stream will be 642 * configured based on the usage and max_buffers outputs. 643 * 644 * Output parameters: 645 * 646 * - stream_id: An unsigned integer identifying this stream. This value is 647 * used in incoming requests to identify the stream, and in releasing the 648 * stream. These ids are numbered separately from the input stream ids. 649 * 650 * - consumer_usage: The gralloc usage mask needed by the HAL device for 651 * consuming the requested type of data. This is used in allocating new 652 * gralloc buffers for the stream buffer queue. 653 * 654 * - max_buffers: The maximum number of buffers the HAL device may need to 655 * have acquired at the same time. The device may not have more buffers 656 * acquired at the same time than this value. 657 * 658 */ 659 int (*allocate_reprocess_stream)(const struct camera2_device *, 660 uint32_t width, 661 uint32_t height, 662 uint32_t format, 663 const camera2_stream_in_ops_t *reprocess_stream_ops, 664 // outputs 665 uint32_t *stream_id, 666 uint32_t *consumer_usage, 667 uint32_t *max_buffers); 668 669 /** 670 * allocate_reprocess_stream_from_stream: 671 * 672 * Allocate a new input stream for use, which will use the buffers allocated 673 * for an existing output stream. That is, after the HAL enqueues a buffer 674 * onto the output stream, it may see that same buffer handed to it from 675 * this input reprocessing stream. After the HAL releases the buffer back to 676 * the reprocessing stream, it will be returned to the output queue for 677 * reuse. 678 * 679 * Error conditions: 680 * 681 * - Using an output stream of unsuitable size/format for the basis of the 682 * reprocessing stream. 683 * 684 * - Attempting to allocatee too many reprocessing streams at once. 685 * 686 * Input parameters: 687 * 688 * - output_stream_id: The ID of an existing output stream which has 689 * a size and format suitable for reprocessing. 690 * 691 * - reprocess_stream_ops: A structure of function pointers for acquiring 692 * and releasing buffers for this stream. The underlying stream will use 693 * the same graphics buffer handles as the output stream uses. 694 * 695 * Output parameters: 696 * 697 * - stream_id: An unsigned integer identifying this stream. This value is 698 * used in incoming requests to identify the stream, and in releasing the 699 * stream. These ids are numbered separately from the input stream ids. 700 * 701 * The HAL client must always release the reprocessing stream before it 702 * releases the output stream it is based on. 703 * 704 */ 705 int (*allocate_reprocess_stream_from_stream)(const struct camera2_device *, 706 uint32_t output_stream_id, 707 const camera2_stream_in_ops_t *reprocess_stream_ops, 708 // outputs 709 uint32_t *stream_id); 710 711 /** 712 * Release a reprocessing stream. Returns an error if called when 713 * get_in_progress_count is non-zero, or if the stream id is not 714 * valid. 715 */ 716 int (*release_reprocess_stream)( 717 const struct camera2_device *, 718 uint32_t stream_id); 719 720 /********************************************************************** 721 * Miscellaneous methods 722 */ 723 724 /** 725 * Trigger asynchronous activity. This is used for triggering special 726 * behaviors of the camera 3A routines when they are in use. See the 727 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids 728 * and their arguments. 729 */ 730 int (*trigger_action)(const struct camera2_device *, 731 uint32_t trigger_id, 732 int32_t ext1, 733 int32_t ext2); 734 735 /** 736 * Notification callback setup 737 */ 738 int (*set_notify_callback)(const struct camera2_device *, 739 camera2_notify_callback notify_cb, 740 void *user); 741 742 /** 743 * Get methods to query for vendor extension metadata tag infomation. May 744 * set ops to NULL if no vendor extension tags are defined. 745 */ 746 int (*get_metadata_vendor_tag_ops)(const struct camera2_device*, 747 vendor_tag_query_ops_t **ops); 748 749 /** 750 * Dump state of the camera hardware 751 */ 752 int (*dump)(const struct camera2_device *, int fd); 753 754} camera2_device_ops_t; 755 756/********************************************************************** 757 * 758 * Camera device definition 759 * 760 */ 761typedef struct camera2_device { 762 /** 763 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify 764 * this device as implementing version 2.0 of the camera device HAL. 765 */ 766 hw_device_t common; 767 camera2_device_ops_t *ops; 768 void *priv; 769} camera2_device_t; 770 771__END_DECLS 772 773#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */ 774