• 一文看懂Camera request、buffer、stream、surface关系 独家原创


    目录

    一、request vs buffer vs stream vs surface

    二、数据结构定义及注释

    camera3_capture_request_t

    camera3_buffer_status_t


    网上博客说一堆,看半小时结果说得不清不楚。本人习惯简明精要,几句话能解释清楚绝不说一堆。

    一、request vs buffer vs stream vs surface

    很简单嘛!看结构定义不就完了。

    request是这个接口里的camera3_capture_request_t:

    static int process_capture_request(const camera3_device_t *dev, camera3_capture_request_t *request)

    写2个调用立马变得清楚:

    request.input_buffer->stream

    request.output_buffers[0]->stream

    很简单,一个request只有最多一个input_buffer,至少一个output_buffer,看到input_buffer和output_buffers(复数)了嘛。一个buffer指向一个stream。当然,几个buffer可以指向一个stream,stream是有格式的,一种格式当然可以几个buffer,比如预览时候是需要几个buffer轮转的,这叫做队列。

    至于surface,就是buffer载体,一个buffer一个surface。

    二、数据结构定义及注释

    我把定义贴上,加上简单明了的注释。

    camera3_capture_request_t

    1. /**
    2. * camera3_capture_request_t:
    3. *
    4. * A single request for image capture/buffer reprocessing, sent to the Camera
    5. * HAL device by the framework in process_capture_request().
    6. *
    7. * The request contains the settings to be used for this capture, and the set of
    8. * output buffers to write the resulting image data in. It may optionally
    9. * contain an input buffer, in which case the request is for reprocessing that
    10. * input buffer instead of capturing a new image with the camera sensor. The
    11. * capture is identified by the frame_number.
    12. *
    13. * In response, the camera HAL device must send a camera3_capture_result
    14. * structure asynchronously to the framework, using the process_capture_result()
    15. * callback.
    16. */
    17. typedef struct camera3_capture_request {
    18. /**
    19. * The frame number is an incrementing integer set by the framework to
    20. * uniquely identify this capture. It needs to be returned in the result
    21. * call, and is also used to identify the request in asynchronous
    22. * notifications sent to camera3_callback_ops_t.notify().
    23. */
    24. uint32_t frame_number; // 本次capture的id,唯一
    25. /**
    26. * The settings buffer contains the capture and processing parameters for
    27. * the request. As a special case, a NULL settings buffer indicates that the
    28. * settings are identical to the most-recently submitted capture request. A
    29. * NULL buffer cannot be used as the first submitted request after a
    30. * configure_streams() call.
    31. * `
    32. */
    33. const camera_metadata_t *settings; // metadata设置,为null表示与上一次一致
    34. /**
    35. * The input stream buffer to use for this request, if any.
    36. *
    37. *
    38. * If input_buffer is NULL, then the request is for a new capture from the
    39. * imager. If input_buffer is valid, the request is for reprocessing the
    40. * image contained in input_buffer.
    41. *
    42. * In the latter case, the HAL must set the release_fence of the
    43. * input_buffer to a valid sync fence, or to -1 if the HAL does not support
    44. * sync, before process_capture_request() returns.
    45. *
    46. * The HAL is required to wait on the acquire sync fence of the input buffer
    47. * before accessing it.
    48. *
    49. * <= CAMERA_DEVICE_API_VERSION_3_1:
    50. *
    51. * Any input buffer included here will have been registered with the HAL
    52. * through register_stream_buffers() before its inclusion in a request.
    53. *
    54. * >= CAMERA_DEVICE_API_VERSION_3_2:
    55. *
    56. * The buffers will not have been pre-registered with the HAL.
    57. * Subsequent requests may reuse buffers, or provide entirely new buffers.
    58. */
    59. camera3_stream_buffer_t *input_buffer; // 如果非空,表示对这个input_buffer重处理
    60. /**
    61. * The number of output buffers for this capture request. Must be at least
    62. * 1.
    63. */
    64. uint32_t num_output_buffers; // >=1
    65. /**
    66. * An array of num_output_buffers stream buffers, to be filled with image
    67. * data from this capture/reprocess. The HAL must wait on the acquire fences
    68. * of each stream buffer before writing to them.
    69. *
    70. * The HAL takes ownership of the actual buffer_handle_t entries in
    71. * output_buffers; the framework does not access them until they are
    72. * returned in a camera3_capture_result_t.
    73. *
    74. * <= CAMERA_DEVICE_API_VERSION_3_1:
    75. *
    76. * All the buffers included here will have been registered with the HAL
    77. * through register_stream_buffers() before their inclusion in a request.
    78. *
    79. * >= CAMERA_DEVICE_API_VERSION_3_2:
    80. *
    81. * Any or all of the buffers included here may be brand new in this
    82. * request (having never before seen by the HAL).
    83. */
    84. const camera3_stream_buffer_t *output_buffers; // n个output_buffer的array
    85. /**
    86. * <= CAMERA_DEVICE_API_VERISON_3_4:
    87. *
    88. * Not defined and must not be accessed.
    89. *
    90. * >= CAMERA_DEVICE_API_VERSION_3_5:
    91. * The number of physical camera settings to be applied. If 'num_physcam_settings'
    92. * equals 0 or a physical device is not included, then Hal must decide the
    93. * specific physical device settings based on the default 'settings'.
    94. */
    95. uint32_t num_physcam_settings; // 物理相机的setting数量
    96. /**
    97. * <= CAMERA_DEVICE_API_VERISON_3_4:
    98. *
    99. * Not defined and must not be accessed.
    100. *
    101. * >= CAMERA_DEVICE_API_VERSION_3_5:
    102. * The physical camera ids. The array will contain 'num_physcam_settings'
    103. * camera id strings for all physical devices that have specific settings.
    104. * In case some id is invalid, the process capture request must fail and return
    105. * -EINVAL.
    106. */
    107. const char **physcam_id; // 物理相机id array
    108. /**
    109. * <= CAMERA_DEVICE_API_VERISON_3_4:
    110. *
    111. * Not defined and must not be accessed.
    112. *
    113. * >= CAMERA_DEVICE_API_VERSION_3_5:
    114. * The capture settings for the physical cameras. The array will contain
    115. * 'num_physcam_settings' settings for invididual physical devices. In
    116. * case the settings at some particular index are empty, the process capture
    117. * request must fail and return -EINVAL.
    118. */
    119. const camera_metadata_t **physcam_settings; // 物理相机setting array
    120. #if defined(CAMX_ANDROID_API) && (CAMX_ANDROID_API >= 31) //Android-S or better
    121. /**
    122. * <= CAMERA_DEVICE_API_VERISON_3_6:
    123. *
    124. * Not defined and must not be accessed.
    125. *
    126. * >= CAMERA_DEVICE_API_VERSION_3_7:
    127. * The width and height of the input buffer for this capture request.
    128. *
    129. * These fields will be [0, 0] if no input buffer exists in the capture
    130. * request.
    131. *
    132. * If the stream configuration contains an input stream and has the
    133. * multiResolutionInputImage flag set to true, the camera client may submit a
    134. * reprocessing request with input buffer size different than the
    135. * configured input stream size. In that case, the inputWith and inputHeight
    136. * fields will be the actual size of the input image.
    137. *
    138. * If the stream configuration contains an input stream and the
    139. * multiResolutionInputImage flag is false, the inputWidth and inputHeight must
    140. * match the input stream size.
    141. */
    142. uint32_t inputWidth;
    143. uint32_t inputHeight;
    144. #endif
    145. } camera3_capture_request_t;

    camera3_buffer_status_t

    1. /**
    2. * camera3_stream_buffer_t:
    3. *
    4. * A single buffer from a camera3 stream. It includes a handle to its parent
    5. * stream, the handle to the gralloc buffer itself, and sync fences
    6. *
    7. * The buffer does not specify whether it is to be used for input or output;
    8. * that is determined by its parent stream type and how the buffer is passed to
    9. * the HAL device.
    10. */
    11. typedef struct camera3_stream_buffer {
    12. /**
    13. * The handle of the stream this buffer is associated with
    14. */
    15. camera3_stream_t *stream; // 这个buffer关联的stream的handle
    16. /**
    17. * The native handle to the buffer
    18. */
    19. buffer_handle_t *buffer; // 该buffer在不同进程中共享的handle
    20. /**
    21. * Current state of the buffer, one of the camera3_buffer_status_t
    22. * values. The framework will not pass buffers to the HAL that are in an
    23. * error state. In case a buffer could not be filled by the HAL, it must
    24. * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
    25. * framework with process_capture_result().
    26. */
    27. int status; // buffer状态
    28. /**
    29. * The acquire sync fence for this buffer. The HAL must wait on this fence
    30. * fd before attempting to read from or write to this buffer.
    31. *
    32. * The framework may be set to -1 to indicate that no waiting is necessary
    33. * for this buffer.
    34. *
    35. * When the HAL returns an output buffer to the framework with
    36. * process_capture_result(), the acquire_fence must be set to -1. If the HAL
    37. * never waits on the acquire_fence due to an error in filling a buffer,
    38. * when calling process_capture_result() the HAL must set the release_fence
    39. * of the buffer to be the acquire_fence passed to it by the framework. This
    40. * will allow the framework to wait on the fence before reusing the buffer.
    41. *
    42. * For input buffers, the HAL must not change the acquire_fence field during
    43. * the process_capture_request() call.
    44. *
    45. * >= CAMERA_DEVICE_API_VERSION_3_2:
    46. *
    47. * When the HAL returns an input buffer to the framework with
    48. * process_capture_result(), the acquire_fence must be set to -1. If the HAL
    49. * never waits on input buffer acquire fence due to an error, the sync
    50. * fences should be handled similarly to the way they are handled for output
    51. * buffers.
    52. */
    53. int acquire_fence; // framework通知hal buffer可以开始处理了
    54. /**
    55. * The release sync fence for this buffer. The HAL must set this fence when
    56. * returning buffers to the framework, or write -1 to indicate that no
    57. * waiting is required for this buffer.
    58. *
    59. * For the output buffers, the fences must be set in the output_buffers
    60. * array passed to process_capture_result().
    61. *
    62. * <= CAMERA_DEVICE_API_VERSION_3_1:
    63. *
    64. * For the input buffer, the release fence must be set by the
    65. * process_capture_request() call.
    66. *
    67. * >= CAMERA_DEVICE_API_VERSION_3_2:
    68. *
    69. * For the input buffer, the fences must be set in the input_buffer
    70. * passed to process_capture_result().
    71. *
    72. * After signaling the release_fence for this buffer, the HAL
    73. * should not make any further attempts to access this buffer as the
    74. * ownership has been fully transferred back to the framework.
    75. *
    76. * If a fence of -1 was specified then the ownership of this buffer
    77. * is transferred back immediately upon the call of process_capture_result.
    78. */
    79. int release_fence; // hal通知framework buffer可用了
    80. } camera3_stream_buffer_t;

  • 相关阅读:
    Java 面试全解析:核心知识点与典型面试题
    【Nginx】MACOS 安装与部署
    C# 共享项目的应用
    Could the Earth be swallowed by a black hole?
    基于YOLOv8模型的水果目标检测系统(PyTorch+Pyside6+YOLOv8模型)
    Python入门 | 输入语句的细节
    [论文笔记]Root Mean Square Layer Normalization
    推荐模型之多任务模型:ESMM、MMOE
    ODrive移植keil(四)—— PWM触发ADC采样
    MapReduce序列化【用户流量使用统计】
  • 原文地址:https://blog.csdn.net/weixin_36389889/article/details/127457959