共用方式為


OutputConfiguration.EnableSurfaceSharing Method

Definition

Enable multiple surfaces sharing the same OutputConfiguration

[Android.Runtime.Register("enableSurfaceSharing", "()V", "", ApiSince=26)]
public void EnableSurfaceSharing ();
[<Android.Runtime.Register("enableSurfaceSharing", "()V", "", ApiSince=26)>]
member this.EnableSurfaceSharing : unit -> unit
Attributes

Remarks

Enable multiple surfaces sharing the same OutputConfiguration

For advanced use cases, a camera application may require more streams than the combination guaranteed by CameraDevice#createCaptureSession. In this case, more than one compatible surface can be attached to an OutputConfiguration so that they map to one camera stream, and the outputs share memory buffers when possible. Due to buffer sharing clients should be careful when adding surface outputs that modify their input data. If such case exists, camera clients should have an additional mechanism to synchronize read and write access between individual consumers.

Two surfaces are compatible in the below cases:

<li> Surfaces with the same size, format, dataSpace, and Surface source class. In this case, CameraDevice#createCaptureSessionByOutputConfigurations is guaranteed to succeed.

<li> Surfaces with the same size, format, and dataSpace, but different Surface source classes that are generally not compatible. However, on some devices, the underlying camera device is able to use the same buffer layout for both surfaces. The only way to discover if this is the case is to create a capture session with that output configuration. For example, if the camera device uses the same private buffer format between a SurfaceView/SurfaceTexture and a MediaRecorder/MediaCodec, CameraDevice#createCaptureSessionByOutputConfigurations will succeed. Otherwise, it fails with CameraCaptureSession.StateCallback#onConfigureFailed. </ol>

To enable surface sharing, this function must be called before CameraDevice#createCaptureSessionByOutputConfigurations or CameraDevice#createReprocessableCaptureSessionByConfigurations. Calling this function after CameraDevice#createCaptureSessionByOutputConfigurations has no effect.

Up to #getMaxSharedSurfaceCount surfaces can be shared for an OutputConfiguration. The supported surfaces for sharing must be of type SurfaceTexture, SurfaceView, MediaRecorder, MediaCodec, or implementation defined ImageReader.

This function must not be called from OutputConfigurations created by #createInstancesForMultiResolutionOutput.

Java documentation for android.hardware.camera2.params.OutputConfiguration.enableSurfaceSharing().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to