自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
单个生产者-多个消费者摄像头缓冲区传输
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
该功能引入了一组方法,当拍摄会话处于活动状态且摄像头流式传输正在进行时,摄像头客户端可通过该功能动态添加和移除输出 Surface。新的输出可以映射到用户选择的特定共享摄像头信息流。Surface 添加后,您可以随时将其移除。
其总体思路是在多个输出 Surface 中共享与特定摄像头信息流关联的缓冲区。当缓冲区准备好在消费方端进行进一步处理时,内部引用计数器便开始跟踪缓冲区。当所有消费方完成各自的任务后,缓冲区便会离开队列,并可供摄像头使用。
图 1. 缓冲区共享
图 1 描绘了一个示例场景:系统采用动态方式连接和分离由相机信息流 2 处理的缓冲区,并由相机服务内的专用共享输出流内部的信息流分流器组件对引用进行计数和管理。
示例和源代码
可在 Camera3StreamSplitter
模块中找到该功能的核心实现,并可在面向开发者的参考资料中找到关于该功能的文档:
实现
相机 HAL 端不需要任何实现,因为该功能在框架端实现。
验证
您的实现必须通过 MultiViewTest 模块中以及原生 API 的原生 JNI 库中涵盖该功能的 CTS 测试。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Single producer, multiple consumer camera buffer transport\n\nThis feature introduces a set of methods that allows camera clients to add and\nremove output surfaces dynamically while the capture session is active and\ncamera streaming is ongoing. A new output can map to a specific, user-selected\n[shared camera](https://developer.android.com/reference/android/hardware/camera2/params/OutputConfiguration#enableSurfaceSharing())\nstream. After a surface is added, it can be removed at any time.\n\nThe general idea is to share the buffers associated with a particular camera\nstream within several output surfaces. An internal reference counter keeps track\nof the buffers as they become ready for further processing on the consumer side.\nWhen all consumers complete their respective tasks the buffer gets dequeued and\nis available for the camera.\n\n**Figure 1.** Buffer sharing\n\nFigure 1 depicts one example scenario where the buffers processed by camera\nstream 2 are dynamically attached and detached, reference counted, and managed\nby the stream splitter component inside a dedicated shared output stream within\nthe camera service.\n\nExamples and source\n-------------------\n\nThe core implementation of this feature can be found in the\n[`Camera3StreamSplitter`](https://android.googlesource.com/platform/frameworks/av/+/android16-release/services/camera/libcameraservice/device3/Camera3StreamSplitter.cpp)\nmodule. Documentation on this feature can be found in the developer reference:\n\n- [`updateOutputConfiguration()`](https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#updateOutputConfiguration(android.hardware.camera2.params.OutputConfiguration))\n- [`addSurface()`](https://developer.android.com/reference/android/hardware/camera2/params/OutputConfiguration#addSurface(android.view.Surface))\n- [`removeSurface()`](https://developer.android.com/reference/android/hardware/camera2/params/OutputConfiguration#removeSurface(android.view.Surface))\n\nImplementation\n--------------\n\nNo implementation is required on the Camera HAL side as this feature is\nimplemented on the framework side.\n\nValidation\n----------\n\nYour implementation must pass CTS cases that cover this feature from the\n[MultiViewTest](https://android.googlesource.com/platform/cts/+/android16-release/tests/camera/src/android/hardware/camera2/cts/MultiViewTest.java)\nmodule and the\n[native JNI library](https://android.googlesource.com/platform/cts/+/android16-release/tests/camera/libctscamera2jni/native-camera-jni.cpp)\nfor the native API."]]