Most visited

Recently visited

Added in API level 21

CameraCaptureSession.CaptureCallback

public static abstract class CameraCaptureSession.CaptureCallback
extends Object

java.lang.Object
   ↳ android.hardware.camera2.CameraCaptureSession.CaptureCallback


用于跟踪提交给相机设备的 CaptureRequest的进度的回调对象。

当请求触发捕获开始以及捕获完成时,会调用此回调。 如果捕获图像时发生错误,则将触发错误方法而不是完成方法。

也可以看看:

Summary

Public constructors

CameraCaptureSession.CaptureCallback()

Public methods

void onCaptureBufferLost(CameraCaptureSession session, CaptureRequest request, Surface target, long frameNumber)

如果捕获的单个缓冲区无法发送到目标表面,则调用此方法。

void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)

当图像捕捉已完全完成并且所有结果元数据可用时调用此方法。

void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure)

这种方法被称为代替 onCaptureCompleted(CameraCaptureSession, CaptureRequest, TotalCaptureResult)当相机设备未能产生 CaptureResult的请求。

void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)

此方法在图像捕捉部分向前进度时调用; 一些(但不是全部)来自图像捕获的结果是可用的。

void onCaptureSequenceAborted(CameraCaptureSession session, int sequenceId)

当捕获序列在任何 CaptureResultCaptureFailure之前通过此侦听器返回时,捕获序列将中止,此方法在CaptureCallback中独立于其他方式调用。

void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber)

当捕获序列完成并且所有 CaptureResultCaptureFailure已通过此侦听器返回时,此方法在CaptureCallback中独立于其他方式调用。

void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber)

当相机设备已开始捕获请求的输出图像时,在图像曝光开始时,或者相机设备已开始处理输入图像以进行重新处理请求时,将调用此方法。

Inherited methods

From class java.lang.Object

Public constructors

CameraCaptureSession.CaptureCallback

Added in API level 21
CameraCaptureSession.CaptureCallback ()

Public methods

onCaptureBufferLost

Added in API level 24
void onCaptureBufferLost (CameraCaptureSession session, 
                CaptureRequest request, 
                Surface target, 
                long frameNumber)

如果捕获的单个缓冲区无法发送到目标表面,则调用此方法。

如果整个捕获失败,则将onCaptureFailed(CameraCaptureSession, CaptureRequest, CaptureFailure) 如果一些但不是所有的缓冲区都被捕获,但结果元数据将不可用,那么将调用wasImageCaptured()wasImageCaptured()返回true,并对失败的输出进行一次或多次调用onCaptureBufferLost(CameraCaptureSession, CaptureRequest, Surface, long)

Parameters
session CameraCaptureSession: The session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
request CaptureRequest: The request that was given to the CameraDevice
target Surface: The target Surface that the buffer will not be produced for
frameNumber long: The frame number for the request

onCaptureCompleted

Added in API level 21
void onCaptureCompleted (CameraCaptureSession session, 
                CaptureRequest request, 
                TotalCaptureResult result)

当图像捕捉已完全完成并且所有结果元数据可用时调用此方法。

此回调将始终在最后onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult)之后onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult) ; 换句话说,一旦完成的结果可用,就不会有更多的部分结果。

对于延迟是一个因素的性能密集型使用案例,请考虑使用 onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult)

此方法的默认实现不做任何事情。

Parameters
session CameraCaptureSession: the session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
request CaptureRequest: The request that was given to the CameraDevice
result TotalCaptureResult: The total output metadata from the capture, including the final capture parameters and the state of the camera system during capture.

也可以看看:

onCaptureFailed

Added in API level 21
void onCaptureFailed (CameraCaptureSession session, 
                CaptureRequest request, 
                CaptureFailure failure)

这种方法被称为代替 onCaptureCompleted(CameraCaptureSession, CaptureRequest, TotalCaptureResult)当相机设备未能产生 CaptureResult的请求。

其他请求不受影响,来自捕获的一些或全部图像缓冲区可能已被推送到它们各自的输出流。

此方法的默认实现不做任何事情。

Parameters
session CameraCaptureSession: The session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
request CaptureRequest: The request that was given to the CameraDevice
failure CaptureFailure: The output failure from the capture, including the failure reason and the frame number.

也可以看看:

onCaptureProgressed

Added in API level 21
void onCaptureProgressed (CameraCaptureSession session, 
                CaptureRequest request, 
                CaptureResult partialResult)

此方法在图像捕捉部分向前进度时调用; 一些(但不是全部)来自图像捕获的结果是可用的。

此处提供的结果将包含完整结果的一些字段子集。 每次捕捉可能会发生多个onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult)调用; 给定的结果字段最多只会出现在一个部分捕获中。 最后的onCaptureCompleted(CameraCaptureSession, CaptureRequest, TotalCaptureResult)调用将始终包含所有字段(特别是组成总结果的所有部分结果的所有字段的并集)。

对于每个请求,某些结果数据可能比其他结果数据更早可用。 每个部分结果(每个请求)之间的典型延迟是单个帧间隔。 对于面向性能的用例,应用程序应查询它们需要的元数据,以从部分结果中获得进展,并避免等待完成的结果。

对于特定请求, onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult)可能在 onCaptureStarted(CameraCaptureSession, CaptureRequest, long, long)之前或之后 onCaptureStarted(CameraCaptureSession, CaptureRequest, long, long)

每个请求将至少生成 1部分结果,并至多 REQUEST_PARTIAL_RESULT_COUNT部分结果。

根据请求设置,每个请求的部分结果数量会有所不同,但通常只要启用的摄像机设备子系统保持不变,部分计数可以相同。

此方法的默认实现不做任何事情。

Parameters
session CameraCaptureSession: the session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
request CaptureRequest: The request that was given to the CameraDevice
partialResult CaptureResult: The partial output metadata from the capture, which includes a subset of the TotalCaptureResult fields.

也可以看看:

onCaptureSequenceAborted

Added in API level 21
void onCaptureSequenceAborted (CameraCaptureSession session, 
                int sequenceId)

当捕获序列在通过此侦听器返回任何 CaptureResultCaptureFailure之前中止时,此方法独立于CaptureCallback中的其他方法调用。

由于相机设备的异步性质,并非所有提交的捕捉都立即进行处理。 可以通过各种操作(如stopRepeating()abortCaptures()清除待处理的请求。 发生此类事件时,将不会调用onCaptureSequenceCompleted(CameraCaptureSession, int, long)

默认实现什么都不做。

Parameters
session CameraCaptureSession: The session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
sequenceId int: A sequence ID returned by the capture(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler) family of functions.

也可以看看:

onCaptureSequenceCompleted

Added in API level 21
void onCaptureSequenceCompleted (CameraCaptureSession session, 
                int sequenceId, 
                long frameNumber)

当捕获序列完成并且所有 CaptureResultCaptureFailure已通过此侦听器返回时,此方法独立于CaptureCallback中的其他方法调用。

总的来说,在调用此回调之前,此侦听器至少会返回一个结果/失败。 如果捕获序列在处理任何请求之前中止,则调用onCaptureSequenceAborted(CameraCaptureSession, int)

默认实现什么都不做。

Parameters
session CameraCaptureSession: The session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
sequenceId int: A sequence ID returned by the capture(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler) family of functions.
frameNumber long: The last frame number (returned by getFrameNumber() or getFrameNumber()) in the capture sequence.

也可以看看:

onCaptureStarted

Added in API level 21
void onCaptureStarted (CameraCaptureSession session, 
                CaptureRequest request, 
                long timestamp, 
                long frameNumber)

当相机设备已开始捕获请求的输出图像时,在图像曝光开始时,或者相机设备已开始处理输入图像以进行重新处理请求时,将调用此方法。

对于常规的捕捉请求,此回调将在帧的捕捉开始时立即调用,因此它是播放快门声音或触发UI捕捉指示符的最佳时机。

提供了用于此捕获的请求以及开始曝光的实际时间戳。 用于再处理请求,该时间戳将曝光的输入图像的开始相匹配the result timestamp field所述的TotalCaptureResult曾用于create the reprocess request 此时间戳匹配将包含在the result timestamp field中的时间戳和发送到每个输出表面的缓冲区中的时间戳。 这些缓冲区时间戳可以通过例如Image.getTimestamp()getTimestamp() 包含的帧号等于将包含在getFrameNumber()的帧号。

有关播放快门声相机快门或视频录制开始/停止声音的最简单方法,请参阅 MediaActionSound课程。

此方法的默认实现不做任何事情。

Parameters
session CameraCaptureSession: the session returned by createCaptureSession(List , CameraCaptureSession.StateCallback, Handler)
request CaptureRequest: the request for the capture that just begun
timestamp long: the timestamp at start of capture for a regular request, or the timestamp at the input image's start of capture for a reprocess request, in nanoseconds.
frameNumber long: the frame number for this capture

也可以看看:

Hooray!