This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

A, CameraCaptureSession

CameraCaptureSession is a configured capture session for CameraDevice that captures images from the camera or reprocesses images previously captured from the camera in the same session.

Inner class

1. CameraCaptureSession.StateCallback

When the state of the transaction captured by the camera changes, the corresponding method in this class is called back.

try { mCameraDevice.createCaptureSession(Arrays.asList(mPreviewSurface, mImageReader.getSurface()), new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession session) { mCaptureSession = session; // The camera device is configured. } @override public void onConfigureFailed(@nonnull CameraCaptureSession Session) {log. e(TAG, "ConfigureFailed. session: mCaptureSession"); }}, mBackgroundHandler); // Handle passes null to use the current thread's Looper} catch (CameraAccessException e) {e.printStackTrace(); }Copy the code

createCaptureSession(List outputs, CameraCaptureSession.StateCallback callback, Handler handler)

Outputs: Output Surface collection.

Callback: Creates a callback for the session.

Handler: Specifies the thread in which the callback is executed.

2. CameraCaptureSession.CaptureCallback

This class can be used to track the progress of the camera device that captures the request being sent.

OnCaptureStarted (when the camera device starts capturing the output image for the request),

OnCaptureCompleted (which calls back to the method when the image capture is complete and the results are available),

OnCaptureFailed (corresponding to onCaptureCompleted method, which is called back when the camera device fails to generate TotalCaptureResult), etc.

Three, common methods

1. int setRepeatingRequest(CaptureRequest request, CameraCaptureSession.CaptureCallback listener, Handler handler)

Repeated requests to capture images, often used to preview or shoot scenes.

2. int capture(CaptureRequest request, CameraCaptureSession.CaptureCallback listener, Handler handler)

Submit a capture request for a single image, often used to photograph a scene.

3. void close()

Asynchronously close this CameraCaptureSession.

4. CameraDevice getDevice()

Get the CameraCaptureSession to create the corresponding CameraDevice object.

Four, the last

Creating a session takes a few hundred milliseconds, so you need to configure the camera device’s pipes, then control the allocation of memory buffers, and send the image to the target.

So, setting is asynchronous, CameraDevice createCaptureSession and CameraDevice createReprocessableCaptureSession will send session can be used in the message, By the listener CameraCaptureSession StateCallback callback, able to complete the configuration is called onConfigured callback, will the session becomes active. If the configuration cannot be completed, the onConfigureFailed callback is invoked and the session does not become active.