Learn from android document:https://developer.android.com/reference/android/hardware/camera2/package-summary
【Highlight Summary】
Replace the deprecated Camera class, camera2 models a camera device as a pipeline, which takes in input requests for capturing a single frame, captures the single image per the request, and then outputs one capture result metadata packet, plus a set of output image buffers for the request. The requests are processed in-order, and multiple requests can be in flight at once. Since the camera device is a pipeline with multiple stages, having multiple requests in flight is required to maintain full framerate on most Android devices.
- CameraManager: to enumerate, query, open available camera devices.
- CameraDevices: provide a set of static property information that describes the hardware device and the available settings and output parameters for device. CameraCharateristics object is such information.
- CameraCaptureSession.CaptureCallback: a callback object for tracking the progress of a
CaptureRequest
submitted to the camera device. - CaptureResult: the subset of the results of a single image capture from the image sensor. Contains a subset of the final configuration for the capture hardware (sensor, lens, flash), the processing pipeline, the control algorithms, and the output buffers.
- STATISTICS_FACE_DETECT_MODE: operating mode for the face detector unit.List of the faces detected through camera face detection in this capture, only available if CaptureRequest.statistics_face_detect_mode!=OFF. Available on all devices.
- FULL: face rectangles, scores, landmarks, and face IDs are all valid.
- OFF: don't include face detection statistics in capture results.
- SIMPLE: return face rectangle and confidence values only.
- STATICSTICS_FACES: list of the faces deteccted through camera face detection in this capture.
- SHADING_MODE_HIGH_QUALITY: apply high-quality lens shading correction, at the cost of possibly reduced frame rate.
- SHADING_MODE_FAST: apply lens shading corrections, without slowing framerate relative to sensor raw output.
- STATISTICS_FACE_DETECT_MODE: operating mode for the face detector unit.List of the faces detected through camera face detection in this capture, only available if CaptureRequest.statistics_face_detect_mode!=OFF. Available on all devices.
- CameraDevice: the CameraDevice class is a representation of a single camera connected to an Android device, allowing for fine-grain control of image capture and post-processing at high frame rates.
- CaptureRequest: an immutable package of settings and outputs needed to capture a single image from the camera device
- Pipline:
- To capture or stream images from a camera device, the application must first create a
camera capture session
with a set of output Surfaces for use with the camera device, withcreateCaptureSession(SessionConfiguration)
. Each Surface has to be pre-configured with anappropriate size and format
(if applicable) to match the sizes and formats available from the camera device. A target Surface can be obtained from a variety of classes, includingSurfaceView
,SurfaceTexture
viaSurface(SurfaceTexture)
,MediaCodec
,MediaRecorder
,Allocation
, andImageReader
. - Generally, camera preview images are sent to
SurfaceView
orTextureView
(via itsSurfaceTexture
). Capture of JPEG images or RAW buffers forDngCreator
can be done withImageReader
with theJPEG
andRAW_SENSOR
formats. Application-driven processing of camera data in RenderScript, OpenGL ES, or directly in managed or native code is best done throughAllocation
with a YUVType
,SurfaceTexture
, andImageReader
with aYUV_420_888
format, respectively. - The application then needs to construct a
CaptureRequest
, which defines all the capture parameters needed by a camera device to capture a single image. The request also lists which of the configured output Surfaces should be used as targets for this capture. The CameraDevice has afactory method
for creating arequest builder
for a given use case, which is optimized for the Android device the application is running on. - Once the request has been set up, it can be handed to the active capture session either for a one-shot
capture
or for an endlesslyrepeating
use. Both methods also have a variant that accepts a list of requests to use as a burst capture / repeating burst. Repeating requests have a lower priority than captures, so a request submitted throughcapture()
while there's a repeating request configured will be captured before any new instances of the currently repeating (burst) capture will begin capture. - After processing a request, the cam era device will produce a
TotalCaptureResult
object, which contains information about the state of the camera device at time of capture, and the final settings used. These may vary somewhat from the request, if rounding or resolving contradictory parameters was necessary. The camera device will also send a frame of image data into each of the outputSurfaces
included in the request. These are produced asynchronously relative to the output CaptureResult, sometimes substantially later.
- To capture or stream images from a camera device, the application must first create a