public abstract class CameraDevice
extends Object
implements AutoCloseable
java.lang.Object | |
↳ | android.hardware.camera2.CameraDevice |
CameraDevice类是连接到Android设备的单个摄像头的代表,允许在高帧率下进行图像捕获和后期处理的细粒度控制。
您的应用程序必须在其清单中声明 Camera
权限才能访问摄像头设备。
给定的相机设备可以在两个级别中的一个级别上提供支持:有限或全部。 如果设备仅支持有限级别,那么Camera2公开的功能集大致等同于较旧的Camera
API,但具有更清洁和更高效的接口。 实现完全支持级别的设备相对于旧版相机API提供了显着改进的功能。 针对有限级别设备的应用程序将在全层设备上保持不变; 如果您的应用程序需要完整级别的设备才能正常运行,请在清单中声明“android.hardware.camera.level.full”功能。
Nested classes |
|
---|---|
class |
CameraDevice.StateCallback 用于接收有关相机设备状态更新的回调对象。 |
Constants |
|
---|---|
int |
TEMPLATE_MANUAL 捕获参数直接应用控制的基本模板。 |
int |
TEMPLATE_PREVIEW 创建一个适合相机预览窗口的请求。 |
int |
TEMPLATE_RECORD 创建适合视频录制的请求。 |
int |
TEMPLATE_STILL_CAPTURE 创建适合静态图像捕获的请求。 |
int |
TEMPLATE_VIDEO_SNAPSHOT 在录制视频时创建适合拍摄静态图像的请求。 |
int |
TEMPLATE_ZERO_SHUTTER_LAG 创建一个适合于零快门滞后仍然捕捉的请求。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
|
From interface java.lang.AutoCloseable
|
int TEMPLATE_MANUAL
捕获参数直接应用控制的基本模板。 所有自动控制均被禁用(自动曝光,自动白平衡,自动对焦),并且后期处理参数被设置为预览画质。 手动捕获参数(暴露量,灵敏度等)被设置为合理的默认值,但应由应用程序根据预期用例重写。 此模板保证在支持MANUAL_SENSOR
功能的相机设备上受支持。
也可以看看:
常数值:6(0x00000006)
int TEMPLATE_PREVIEW
创建一个适合相机预览窗口的请求。 具体而言,这意味着高帧速率优先于最高质量的后处理。 这些请求通常会与setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler)
方法一起使用。 该模板保证在所有相机设备上均受支持。
也可以看看:
常数值:1(0x00000001)
int TEMPLATE_RECORD
创建适合视频录制的请求。 具体而言,这意味着使用稳定的帧速率,并且为记录质量设置后处理。 这些请求通常会与setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler)
方法一起使用。 该模板保证在所有相机设备上均受支持。
也可以看看:
常量值:3(0x00000003)
int TEMPLATE_STILL_CAPTURE
创建适合静态图像捕获的请求。 具体来说,这意味着优先考虑帧速率的图像质量。 这些请求通常会与capture(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler)
方法一起使用。 该模板保证在所有相机设备上均受支持。
也可以看看:
常量值:2(0x00000002)
int TEMPLATE_VIDEO_SNAPSHOT
在录制视频时创建适合拍摄静态图像的请求。 具体而言,这意味着在不中断正在进行的记录的情况下使图像质量最大化 这些请求通常会与capture(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler)
方法一起使用,而基于TEMPLATE_RECORD
的请求正在与setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler)
一起使用。 除了传统设备以外,所有相机设备都支持此模板( INFO_SUPPORTED_HARDWARE_LEVEL
==
LEGACY
)
也可以看看:
常量值:4(0x00000004)
int TEMPLATE_ZERO_SHUTTER_LAG
创建一个适合于零快门滞后仍然捕捉的请求。 这意味着在不影响预览帧速率的情况下最大限度提高图像质量。 AE / AWB / AF应处于自动模式。 该模板可保证在支持PRIVATE_REPROCESSING
功能或YUV_REPROCESSING
功能的相机设备上受支持。
也可以看看:
常量值:5(0x00000005)
void close ()
尽可能快地关闭与相机设备的连接。
紧接此通话后,除相对于关闭()的呼叫外,对相机设备或活动会话界面的所有呼叫都会IllegalStateException
。 一旦设备完全关闭, onClosed(CameraDevice)
回调将被调用,并且相机可以自由重新打开。
本次调用之后,除了最终的 onClosed(CameraDevice)
调用之外,不会再发生来自设备或活动会话的回调,并且任何剩余的已提交捕捉请求都将被丢弃,就好像 abortCaptures()
了 abortCaptures()
一样,除了不会成功或失败回调调用。
CaptureRequest.Builder createCaptureRequest (int templateType)
为新的捕获请求创建一个CaptureRequest.Builder
,使用目标用例的模板进行初始化。 这些设置被选择为特定相机设备的最佳选项,因此不建议对不同的相机设备重复使用相同的请求; 相反,创建特定于该设备和模板的构建器并根据需要覆盖设置。
Parameters | |
---|---|
templateType |
int : An enumeration selecting the use case for this request; one of the CameraDevice.TEMPLATE_ values. Not all template types are supported on every device. See the documentation for each template type for details. |
Returns | |
---|---|
CaptureRequest.Builder |
a builder for a capture request, initialized with default settings for that template, and no output streams |
Throws | |
---|---|
IllegalArgumentException |
if the templateType is not supported by this device. |
CameraAccessException |
if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException |
if the camera device has been closed |
void createCaptureSession (List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler)
通过向摄像机设备提供Surfaces的目标输出集,创建新的摄像头捕获会话。
主动捕捉会话为每个捕捉请求确定相机设备的潜在输出曲面集。 给定的请求可以使用全部或仅部分输出。 一旦CameraCaptureSession创建,请求可以提交capture
, captureBurst
, setRepeatingRequest
,或setRepeatingBurst
。
可以为各种使用情况和目标创建适合作为相机输出的表面:
SurfaceView
: Once the SurfaceView's Surface is created
, set the size of the Surface with setFixedSize(int, int)
to be one of the sizes returned by getOutputSizes(SurfaceHolder.class)
and then obtain the Surface by calling getSurface()
. If the size is not set by the application, it will be rounded to the nearest supported size less than 1080p, by the camera device.SurfaceTexture
: Set the size of the SurfaceTexture with setDefaultBufferSize(int, int)
to be one of the sizes returned by getOutputSizes(SurfaceTexture.class)
before creating a Surface from the SurfaceTexture with Surface(SurfaceTexture)
. If the size is not set by the application, it will be set to be the smallest supported size less than 1080p, by the camera device.MediaCodec
: Call createInputSurface()
after configuring the media codec to use one of the sizes returned by getOutputSizes(MediaCodec.class)
MediaRecorder
: Call getSurface()
after configuring the media recorder to use one of the sizes returned by getOutputSizes(MediaRecorder.class)
, or configuring it to use one of the supported CamcorderProfiles
.android.renderscript
: Create a RenderScript Allocation
with a supported YUV type, the IO_INPUT flag, and one of the sizes returned by getOutputSizes(Allocation.class)
, Then obtain the Surface with getSurface()
.ImageReader
object with one of the supported output formats given by getOutputFormats()
, setting its size to one of the corresponding supported sizes by passing the chosen output format into getOutputSizes(int)
. Then obtain a Surface
from it with getSurface()
. If the ImageReader size is not set to a supported size, it will be rounded to a supported size less than 1080p by the camera device. 相机设备将在此次通话中查询每个Surface的尺寸和格式,因此此时它们必须设置为有效设置。
会话的配置可能需要几百毫秒才能完成,因为相机硬件可能需要启动或重新配置。 一旦配置完成并且会话准备好实际捕获数据,将会调用提供的CameraCaptureSession.StateCallback
的onConfigured(CameraCaptureSession)
回调。
如果在调用此方法时以前的CameraCaptureSession已存在,则以前的会话将不再能够接受新的捕获请求并将被关闭。 在上届会议上进行的任何正在进行的捕获请求将在其结束之前完成。 onConfigured(CameraCaptureSession)
可能会在先前会话调用onClosed(CameraCaptureSession)
之前调用新会话。 一旦新会话是configured
,它就能够开始捕获自己的请求。 为了最小化转换时间,可以使用abortCaptures()
调用在abortCaptures()
调用之前放弃先前捕捉会话的其余请求。 请注意,一旦创建新会话,旧会话将不能再中止其捕获。
使用更大的分辨率输出或更多输出可能会导致设备的输出速率变慢。
使用空列表或空列表配置会话将关闭当前会话(如果有的话)。 这可用于释放当前会话的目标曲面以供其他用途。
虽然可以在配置单个输出流时使用getOutputSizes(int)
任何尺寸, getOutputSizes(int)
当同时配置多个输出时,给定的相机设备可能无法支持所有尺寸,格式和目标的组合。 下表列出了考虑到相机设备功能的流和目标组合的最大保证分辨率。
如果应用程序尝试使用超出下表中所述限制的一组目标创建会话,则可能会出现三种可能性之一。 首先,会话可能会成功创建并正常工作。 其次,会话可能已成功创建,但摄像机设备将不符合getOutputMinFrameDuration(int, Size)
所述的帧率保证。 或者第三,如果输出集根本无法使用,会话创建将完全失败,调用onConfigureFailed(CameraCaptureSession)
。
对于类型列, PRIV
指任何目标,其提供的尺寸使用中发现 getOutputSizes(Class)
没有直接的应用程序可见格式, YUV
是指使用目标表面 YUV_420_888
格式, JPEG
指 JPEG
格式,并 RAW
指 RAW_SENSOR
格式。
对于最大尺寸列, PREVIEW
指的是与设备的屏幕分辨率匹配的最佳尺寸,或与1080p( 1920x1080
)中的较小者相1920x1080
。 RECORD
指的是相机设备支持的最大记录分辨率,由CamcorderProfile
确定。 而MAXIMUM
指的是摄像机设备对于该格式或目标的最大输出分辨率,来自getOutputSizes(int)
。
要使用这些表格,请确定所需输出的数量和格式/目标,并查找包含这些目标的表格的行。 尺寸表示可以使用的最大尺寸组合; 保证对于这些目标,列出的大小和getOutputSizes(int)
给出的列表中较小的任何内容均可成功用于创建会话。 例如,如果一行表示800万像素(MP)YUV_420_888输出可以与2 MP PRIV
输出一起使用,则可以创建一个会话,目标[8 MP YUV, 2 MP PRIV]
或目标[2 MP YUV, 2 MP PRIV]
; 但目标[8 MP YUV, 4 MP PRIV]
,目标[4 MP YUV, 4 MP PRIV]
或目标[8 MP PRIV, 2 MP YUV]
将无法保证正常工作,除非表格的某些其他行列出了此类组合。
传统设备( INFO_SUPPORTED_HARDWARE_LEVEL
==
LEGACY
)至少支持以下流组合:
LEGACY-level guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
PRIV |
MAXIMUM |
Simple preview, GPU video processing, or no-preview video recording. | ||||
JPEG |
MAXIMUM |
No-viewfinder still image capture. | ||||
YUV |
MAXIMUM |
In-application video/image processing. | ||||
PRIV |
PREVIEW |
JPEG |
MAXIMUM |
Standard still imaging. | ||
YUV |
PREVIEW |
JPEG |
MAXIMUM |
In-app processing plus still capture. | ||
PRIV |
PREVIEW |
PRIV |
PREVIEW |
Standard recording. | ||
PRIV |
PREVIEW |
YUV |
PREVIEW |
Preview plus in-app processing. | ||
PRIV |
PREVIEW |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
Still capture plus in-app processing. |
有限级( INFO_SUPPORTED_HARDWARE_LEVEL
==
LIMITED
)设备支持至少以下除了那些流组合 LEGACY
装置:
LIMITED-level additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
PRIV |
PREVIEW |
PRIV |
RECORD |
High-resolution video recording with preview. | ||
PRIV |
PREVIEW |
YUV |
RECORD |
High-resolution in-app video processing with preview. | ||
YUV |
PREVIEW |
YUV |
RECORD |
Two-input in-app video processing. | ||
PRIV |
PREVIEW |
PRIV |
RECORD |
JPEG |
RECORD |
High-resolution recording with video snapshot. |
PRIV |
PREVIEW |
YUV |
RECORD |
JPEG |
RECORD |
High-resolution in-app processing with video snapshot. |
YUV |
PREVIEW |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
Two-input in-app processing with still capture. |
满级( INFO_SUPPORTED_HARDWARE_LEVEL
==
FULL
)设备支持至少以下除了那些流组合 LIMITED
装置:
FULL-level additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
PRIV |
PREVIEW |
PRIV |
MAXIMUM |
Maximum-resolution GPU processing with preview. | ||
PRIV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution in-app processing with preview. | ||
YUV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution two-input in-app processsing. | ||
PRIV |
PREVIEW |
PRIV |
PREVIEW |
JPEG |
MAXIMUM |
Video recording with maximum-size video snapshot |
YUV |
640x480 |
PRIV |
PREVIEW |
YUV |
MAXIMUM |
Standard video recording plus maximum-resolution in-app processing. |
YUV |
640x480 |
YUV |
PREVIEW |
YUV |
MAXIMUM |
Preview plus two-input maximum-resolution in-app processing. |
RAW能力( REQUEST_AVAILABLE_CAPABILITIES
包括 RAW
)设备在 FULL
和 LIMITED
设备上至少还支持以下流组合:
RAW-capability additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
RAW |
MAXIMUM |
No-preview DNG capture. | ||||
PRIV |
PREVIEW |
RAW |
MAXIMUM |
Standard DNG capture. | ||
YUV |
PREVIEW |
RAW |
MAXIMUM |
In-app processing plus DNG capture. | ||
PRIV |
PREVIEW |
PRIV |
PREVIEW |
RAW |
MAXIMUM |
Video recording with DNG capture. |
PRIV |
PREVIEW |
YUV |
PREVIEW |
RAW |
MAXIMUM |
Preview with in-app processing and DNG capture. |
YUV |
PREVIEW |
YUV |
PREVIEW |
RAW |
MAXIMUM |
Two-input in-app processing plus DNG capture. |
PRIV |
PREVIEW |
JPEG |
MAXIMUM |
RAW |
MAXIMUM |
Still capture with simultaneous JPEG and DNG. |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
RAW |
MAXIMUM |
In-app processing with simultaneous JPEG and DNG. |
突发能力( REQUEST_AVAILABLE_CAPABILITIES
包括BURST_CAPTURE
)设备支持至少以下流组合除了那些LIMITED
设备。 请注意,所有FULL级别的设备都支持BURST功能,并且以下列表是FULL-level设备列表的严格子集,因此此表仅适用于支持BURST_CAPTURE功能的限制级设备。
BURST-capability additional guaranteed configurations | ||||
---|---|---|---|---|
Target 1 | Target 2 | Sample use case(s) | ||
Type | Max size | Type | Max size | |
PRIV |
PREVIEW |
PRIV |
MAXIMUM |
Maximum-resolution GPU processing with preview. |
PRIV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution in-app processing with preview. |
YUV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution two-input in-app processsing. |
LEVEL-3( INFO_SUPPORTED_HARDWARE_LEVEL
==
LEVEL_3
)除了 FULL
和RAW能力组合( REQUEST_AVAILABLE_CAPABILITIES
包括 RAW
)之外,至少支持以下流组合:
LEVEL-3 additional guaranteed configurations | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Target 4 | Sample use case(s) | ||||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | |||
PRIV |
PREVIEW |
PRIV |
640x480 |
YUV |
MAXIMUM |
RAW |
MAXIMUM |
In-app viewfinder analysis with dynamic selection of output format. | ||
PRIV |
PREVIEW |
PRIV |
640x480 |
JPEG |
MAXIMUM |
RAW |
MAXIMUM |
In-app viewfinder analysis with dynamic selection of output format. |
由于相机设备的功能差别很大,因此给定的相机设备可能支持超出这些保证范围的目标组合,但这只能通过尝试与此类目标建立会话来进行测试。
Parameters | |
---|---|
outputs |
List : The new set of Surfaces that should be made available as targets for captured image data. |
callback |
CameraCaptureSession.StateCallback : The callback to notify about the status of the new capture session. |
handler |
Handler : The handler on which the callback should be invoked, or null to use the current thread's looper . |
Throws | |
---|---|
IllegalArgumentException |
if the set of output Surfaces do not meet the requirements, the callback is null, or the handler is null but the current thread has no looper. |
CameraAccessException |
if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException |
if the camera device has been closed |
void createCaptureSessionByOutputConfigurations (List<OutputConfiguration> outputConfigurations, CameraCaptureSession.StateCallback callback, Handler handler)
通过向相机设备提供目标输出设置的曲面及其相应的曲面配置,创建一个新的相机捕捉会话。
Parameters | |
---|---|
outputConfigurations |
List
|
callback |
CameraCaptureSession.StateCallback
|
handler |
Handler
|
Throws | |
---|---|
CameraAccessException |
void createConstrainedHighSpeedCaptureSession (List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler)
创建一个新的约束高速捕捉会话。
如果所需的高速FPS范围通过 CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES
,则应用程序可以使用普通捕获会话(通过 createCaptureSession(List
创建)进行高速捕获,在这种情况下,所有与正常捕获会话相关的API语义均适用。
如果摄像设备支持高速视频功能(例如, REQUEST_AVAILABLE_CAPABILITIES
包含REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO
),该方法将创建专门的捕获会话,该会话仅针对高速视频记录(> = 120fps)的使用情况。 因此,它与正常捕捉会话相比具有特殊的特征:
createCaptureSession(List
, CameraCaptureSession.StateCallback, Handler)
method, an active high speed capture session will support up to 2 output Surfaces, though the application might choose to configure just one Surface (e.g., preview only). All Surfaces must be either video encoder surfaces (acquired by getSurface()
or createInputSurface()
) or preview surfaces (obtained from SurfaceView
, SurfaceTexture
via Surface(android.graphics.SurfaceTexture)
). The Surface sizes must be one of the sizes reported by getHighSpeedVideoSizes()
. When multiple Surfaces are configured, their size must be same.createHighSpeedRequestList(CaptureRequest)
, and the request list can only be submitted to this session via captureBurst
, or setRepeatingBurst
.getHighSpeedVideoFpsRangesFor(Size)
. The application can still use CONTROL_AE_TARGET_FPS_RANGE
to control the desired FPS range. Switching to an FPS range that has different maximum FPS
may trigger some camera device reconfigurations, which may introduce extra latency. It is recommended that the application avoids unnecessary maximum target FPS changes as much as possible during high speed streaming.control mode
, auto-exposure (AE), auto-white balance (AWB) and auto-focus (AF) to CONTROL_MODE_AUTO
, CONTROL_AE_MODE_ON
, CONTROL_AWB_MODE_AUTO
and CONTROL_AF_MODE_CONTINUOUS_VIDEO
, respectively. All post-processing block mode controls will be overridden to be FAST. Therefore, no manual control of capture and post-processing parameters is possible. Beside these, only a subset of controls will work, see REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO
for more details.Parameters | |
---|---|
outputs |
List : The new set of Surfaces that should be made available as targets for captured high speed image data. |
callback |
CameraCaptureSession.StateCallback : The callback to notify about the status of the new capture session. |
handler |
Handler : The handler on which the callback should be invoked, or null to use the current thread's looper . |
Throws | |
---|---|
IllegalArgumentException |
if the set of output Surfaces do not meet the requirements, the callback is null, or the handler is null but the current thread has no looper, or the camera device doesn't support high speed video capability. |
CameraAccessException |
if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException |
if the camera device has been closed |
也可以看看:
createCaptureSession(List
, CameraCaptureSession.StateCallback, Handler)
CONTROL_AE_TARGET_FPS_RANGE
getHighSpeedVideoSizes()
getHighSpeedVideoFpsRangesFor(Size)
REQUEST_AVAILABLE_CAPABILITIES
REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO
captureBurst(List
, CameraCaptureSession.CaptureCallback, Handler)
setRepeatingBurst(List
, CameraCaptureSession.CaptureCallback, Handler)
createHighSpeedRequestList(CaptureRequest)
CaptureRequest.Builder createReprocessCaptureRequest (TotalCaptureResult inputResult)
创建 CaptureRequest.Builder
一个新的再加工 CaptureRequest
从 TotalCaptureResult
。
每个重新处理CaptureRequest
将CameraCaptureSession
的输入Surface
一个缓冲区处理为包含在重新处理捕获请求中的所有输出Surfaces
。 重新处理输入图像必须从一个或多个从同一摄像机设备捕获的输出图像中生成。 应用程序可以通过queueInputImage(Image)
向摄像机设备提供输入图像。 应用程序必须使用其中一个输出图像的捕获结果来创建重新处理捕获请求,以便相机设备可以使用这些信息来实现最佳再处理图像质量。 对于仅支持1个输出Surface
摄像机设备,提交具有多个输出目标的重新处理CaptureRequest
将导致CaptureFailure
。
Parameters | |
---|---|
inputResult |
TotalCaptureResult : The capture result of the output image or one of the output images used to generate the reprocess input image for this capture request. |
Returns | |
---|---|
CaptureRequest.Builder |
Throws | |
---|---|
IllegalArgumentException |
if inputResult is null. |
CameraAccessException |
if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException |
if the camera device has been closed |
void createReprocessableCaptureSession (InputConfiguration inputConfig, List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler)
通过向摄像设备提供所需的再处理输入表面配置和Surfaces的目标输出设置,创建一个新的可重新处理的摄像头捕捉会话。
如果摄像设备支持YUV重新处理( REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING
)或PRIVATE重新处理( REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING
),除了通过createCaptureSession
创建的捕获会话createCaptureSession
,应用程序还可以创建可重新处理的捕获会话,以提交除常规捕获请求外的重新处理捕获请求。 重新处理捕获请求从会话的输入Surface获取下一个可用缓冲区,并再次通过相机设备的处理管道发送它,以便为请求的目标输出Surfaces生成缓冲区。 重新处理请求不会捕获新的图像数据。 但是,应用程序提供的输入缓冲区必须先由相同的摄像机设备在同一会话中直接捕获(例如,零快门 - 滞后使用情况)或间接(例如组合多个输出图像)。
活动的可重新处理捕获会话确定输入Surface
以及针对每个捕获请求的相机设备的潜在输出表面集合。 应用程序可以使用createCaptureRequest
创建常规捕捉请求以从相机设备捕捉新图像,并使用createReprocessCaptureRequest
创建再处理捕捉请求以处理来自输入Surface
缓冲区。 会话中输出曲面的某些组合可能不会同时用于请求中。 createCaptureSession
下的表中列出了可同时用于请求的输出表面的保证组合。 根据请求是否是重新处理捕获请求,一个捕获请求中的所有输出表面将来自相同的来源,无论是来自相机设备的新捕获还是来自输入Surface。
相机设备支持的输入格式和尺寸可以通过getInputFormats()
和getInputSizes(int)
查询。 对于每种支持的输入格式,相机设备都支持一组输出格式和尺寸,以便通过getValidOutputFormatsForInput(int)
和getOutputSizes(int)
查询再处理。 虽然对输入配置格式不是有效的重新处理输出目标的输出表面可以是会话的一部分,但它们不能用作重新处理请求的目标。
由于应用程序无法直接访问PRIVATE
图像, newInstance(int, int, int, int)
PRIVATE
作为格式创建的输出曲面将被视为预期用于重新处理输入,因此ImageReader
尺寸必须与PRIVATE
格式支持的输入尺寸之一PRIVATE
。 否则,创建可重新处理的捕获会话将失败。
createCaptureSession
中列出的保证流配置也保证适用于createReprocessableCaptureSession
。 此外,如果相机设备支持YUV重新处理或PRIVATE重新处理,下表中的配置也可用于创建可重新处理的捕获会话。 但是,并非所有用于创建可重新处理会话的输出目标都可以同时用于CaptureRequest
。 对于在重新处理CaptureRequest
仅支持1个输出目标的CaptureRequest
,提交具有多个输出目标的重新处理CaptureRequest
将导致CaptureFailure
。 对于支持在再处理多输出目标装置CaptureRequest
,可被包括在保证输出目标CaptureRequest
同时在表中列出下createCaptureSession
。 例如,对于一个全能力( INFO_SUPPORTED_HARDWARE_LEVEL
==
FULL
支持PRIVATE再处理)设备,一个应用程序可与1个输入,(创建可再加工的捕获会话PRIV
, MAXIMUM
),和3个输出,( PRIV
, MAXIMUM
),( PRIV
, PREVIEW
),和( YUV
, MAXIMUM
)。 但是,它不能保证应用程序可以提交定期或再加工的捕获与( PRIV
, MAXIMUM
)和( YUV
, MAXIMUM
)的基础上输出下面列出的表createCaptureSession
。 换句话说,使用下表来确定用于创建可重新处理捕获会话的保证流配置,并使用createCaptureSession
下的表来确定可同时在常规或重新处理CaptureRequest
提交的保证输出目标。
LIMITED级( INFO_SUPPORTED_HARDWARE_LEVEL
==
LIMITED
)设备支持至少用于产生除了那些中列出可再加工的捕获会话以下流组合 createCaptureSession
为 LIMITED
装置:
LIMITED-level additional guaranteed configurations for creating a reprocessable capture session ( PRIV input is guaranteed only if PRIVATE reprocessing is supported. YUV input is guaranteed only if YUV reprocessing is supported) |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Input | Target 1 | Target 2 | Target 3 | Target 4 | Sample use case(s) | |||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | Type | Max size | |
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
JPEG |
MAXIMUM |
No-viewfinder still image reprocessing. | ||||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
JPEG |
MAXIMUM |
ZSL(Zero-Shutter-Lag) still imaging. | ||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
ZSL still and in-app processing imaging. | ||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
YUV |
PREVIEW |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
ZSL in-app processing with still capture. |
满级( INFO_SUPPORTED_HARDWARE_LEVEL
==
FULL
)设备支持至少用于产生除了那些可再加工的捕获会话以下流组合 LIMITED
装置:
FULL-level additional guaranteed configurations for creating a reprocessable capture session ( PRIV input is guaranteed only if PRIVATE reprocessing is supported. YUV input is guaranteed only if YUV reprocessing is supported) |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Input | Target 1 | Target 2 | Target 3 | Target 4 | Sample use case(s) | |||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | Type | Max size | |
YUV |
MAXIMUM |
YUV |
MAXIMUM |
PRIV |
PREVIEW |
Maximum-resolution multi-frame image fusion in-app processing with regular preview. | ||||
YUV |
MAXIMUM |
YUV |
MAXIMUM |
YUV |
PREVIEW |
Maximum-resolution multi-frame image fusion two-input in-app processing. | ||||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
YUV |
RECORD |
High-resolution ZSL in-app video processing with regular preview. | ||
PRIV |
MAXIMUM |
PRIV |
MAXIMUM |
PRIV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution ZSL in-app processing with regular preview. | ||
PRIV |
MAXIMUM |
PRIV |
MAXIMUM |
YUV |
PREVIEW |
YUV |
MAXIMUM |
Maximum-resolution two-input ZSL in-app processing. | ||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
ZSL still capture and in-app processing. |
RAW能力( REQUEST_AVAILABLE_CAPABILITIES
包括 RAW
)设备还支持至少以下流组合,用于在 FULL
和 LIMITED
设备上创建可重新处理的捕获会话
RAW-capability additional guaranteed configurations for creating a reprocessable capture session ( PRIV input is guaranteed only if PRIVATE reprocessing is supported. YUV input is guaranteed only if YUV reprocessing is supported) |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Input | Target 1 | Target 2 | Target 3 | Target 4 | Sample use case(s) | |||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | Type | Max size | |
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
YUV |
PREVIEW |
RAW |
MAXIMUM |
Mutually exclusive ZSL in-app processing and DNG capture. | ||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
YUV |
PREVIEW |
RAW |
MAXIMUM |
Mutually exclusive ZSL in-app processing and preview with DNG capture. |
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
YUV |
PREVIEW |
YUV |
PREVIEW |
RAW |
MAXIMUM |
Mutually exclusive ZSL two-input in-app processing and DNG capture. |
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
JPEG |
MAXIMUM |
RAW |
MAXIMUM |
Mutually exclusive ZSL still capture and preview with DNG capture. |
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
YUV |
PREVIEW |
JPEG |
MAXIMUM |
RAW |
MAXIMUM |
Mutually exclusive ZSL in-app processing with still capture and DNG capture. |
LEVEL-3( INFO_SUPPORTED_HARDWARE_LEVEL
==
LEVEL_3
)设备支持至少为除了那些用于创建可再加工的捕获会话以下流组合FULL
设备。 请注意,虽然第二种配置允许同时配置MAXIMUM
YUV
和JPEG
输出,但该配置未列入常规捕获会话,因此不允许同时向两个目标输出。
LEVEL-3 additional guaranteed configurations for creating a reprocessable capture session ( PRIV input is guaranteed only if PRIVATE reprocessing is supported. YUV input is always guaranteed. |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Input | Target 1 | Target 2 | Target 3 | Target 4 | Target 5 | Sample use case(s) | ||||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | Type | Max size | Type | Max size | |
YUV |
MAXIMUM |
YUV |
MAXIMUM |
PRIV |
PREVIEW |
PRIV |
640x480 |
RAW |
MAXIMUM |
In-app viewfinder analysis with ZSL and RAW. | ||
PRIV /YUV |
MAXIMUM |
Same as input | MAXIMUM |
PRIV |
PREVIEW |
PRIV |
640x480 |
RAW |
MAXIMUM |
JPEG |
MAXIMUM |
In-app viewfinder analysis with ZSL, RAW, and JPEG reprocessing output. |
Parameters | |
---|---|
inputConfig |
InputConfiguration : The configuration for the input Surface |
outputs |
List : The new set of Surfaces that should be made available as targets for captured image data. |
callback |
CameraCaptureSession.StateCallback : The callback to notify about the status of the new capture session. |
handler |
Handler : The handler on which the callback should be invoked, or null to use the current thread's looper . |
Throws | |
---|---|
IllegalArgumentException |
if the input configuration is null or not supported, the set of output Surfaces do not meet the requirements, the callback is null, or the handler is null but the current thread has no looper. |
CameraAccessException |
if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException |
if the camera device has been closed |
void createReprocessableCaptureSessionByConfigurations (InputConfiguration inputConfig, List<OutputConfiguration> outputs, CameraCaptureSession.StateCallback callback, Handler handler)
通过提供所需的再处理输入配置并输出 OutputConfiguration
到相机设备,创建一个新的可重新处理的相机捕捉会话。
Parameters | |
---|---|
inputConfig |
InputConfiguration
|
outputs |
List
|
callback |
CameraCaptureSession.StateCallback
|
handler |
Handler
|
Throws | |
---|---|
CameraAccessException |
String getId ()
获取此相机设备的ID。
这与给予 openCamera(String, CameraDevice.StateCallback, Handler)
的ID匹配以实例化此相机设备。
这个ID可以用于查询相机设备的 fixed properties
与 getCameraCharacteristics(String)
。
即使设备已关闭或遇到严重错误,也可以调用此方法。
Returns | |
---|---|
String |
the ID for this camera device |