Example usage for android.hardware.camera2 CameraCaptureSession setRepeatingRequest

List of usage examples for android.hardware.camera2 CameraCaptureSession setRepeatingRequest

Introduction

In this page you can find the example usage for android.hardware.camera2 CameraCaptureSession setRepeatingRequest.

Prototype

public abstract int setRepeatingRequest(@NonNull CaptureRequest request, @Nullable CaptureCallback listener,
        @Nullable Handler handler) throws CameraAccessException;

Source Link

Document

Request endlessly repeating capture of images by this capture session.

Usage

From source file:com.google.android.apps.watchme.StreamerActivity.java

void startPreview() {
    SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
    surfaceTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
    Surface previewSurface = new Surface(surfaceTexture);
    try {/* w  w  w.  ja va2s. c o m*/
        captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        captureRequestBuilder.addTarget(previewSurface);

        cameraDevice.createCaptureSession(Arrays.asList(previewSurface),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(@NonNull CameraCaptureSession session) {
                        try {
                            session.setRepeatingRequest(captureRequestBuilder.build(), null, backgroundHandler);
                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onConfigureFailed(@NonNull CameraCaptureSession session) {
                        Toast.makeText(getApplicationContext(), "The preview failed to setup",
                                Toast.LENGTH_SHORT).show();
                    }
                }, null);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.aschere.cdhprototype2.Camera2RawFragment.java

/**
 * Creates a new {@link CameraCaptureSession} for camera preview.
 * <p/>//from w w  w.jav a  2  s  . c om
 * Call this only with {@link #mCameraStateLock} held.
 */
private void createCameraPreviewSessionLocked() {
    try {
        Log.i(TAG, "create camera preview called");
        SurfaceTexture texture = new SurfaceTexture(2);

        // This is the output Surface we need to start preview.
        Surface surface = new Surface(texture);

        // We set up a CaptureRequest.Builder with the output Surface.
        if (mCameraDevice == null) {
            setUpCameraOutputs();
            openCamera();
        }
        if (mCameraDevice != null) {
            mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            mPreviewRequestBuilder.addTarget(surface);

            // Here, we create a CameraCaptureSession for camera preview.
            mCameraDevice.createCaptureSession(Arrays.asList(surface, mJpegImageReader.get().getSurface(),
                    mRawImageReader.get().getSurface()), new CameraCaptureSession.StateCallback() {
                        @Override
                        public void onConfigured(CameraCaptureSession cameraCaptureSession) {
                            synchronized (mCameraStateLock) {
                                // The camera is already closed
                                if (null == mCameraDevice) {
                                    return;
                                }

                                try {
                                    setup3AControlsLocked(mPreviewRequestBuilder);
                                    // Finally, we start displaying the camera preview.
                                    cameraCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
                                            mPreCaptureCallback, mBackgroundHandler);
                                    mState = STATE_PREVIEW;
                                } catch (CameraAccessException | IllegalStateException e) {
                                    e.printStackTrace();
                                    return;
                                }
                                // When the session is ready, we start displaying the preview.
                                mCaptureSession = cameraCaptureSession;
                            }
                        }

                        @Override
                        public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
                            showToast("Failed to configure camera.");
                        }
                    }, mBackgroundHandler);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.ape.camera2raw.Camera2RawFragment.java

/**
 * Creates a new {@link CameraCaptureSession} for camera preview.
 * <p/>//w w w  .  jav  a 2  s. c  o  m
 * Call this only with {@link #mCameraStateLock} held.
 */
private void createCameraPreviewSessionLocked() {
    try {
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        // We configure the size of default buffer to be the size of camera preview we want.
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

        // This is the output Surface we need to start preview.
        Surface surface = new Surface(texture);

        // We set up a CaptureRequest.Builder with the output Surface.
        mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);

        // Here, we create a CameraCaptureSession for camera preview.
        mCameraDevice.createCaptureSession(
                Arrays.asList(surface, mJpegImageReader.get().getSurface(), mRawImageReader.get().getSurface()),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(CameraCaptureSession cameraCaptureSession) {
                        synchronized (mCameraStateLock) {
                            // The camera is already closed
                            if (null == mCameraDevice) {
                                return;
                            }

                            try {
                                setup3AControlsLocked(mPreviewRequestBuilder);
                                // Finally, we start displaying the camera preview.
                                cameraCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
                                        mPreCaptureCallback, mBackgroundHandler);
                                mState = STATE_PREVIEW;
                            } catch (CameraAccessException | IllegalStateException e) {
                                e.printStackTrace();
                                return;
                            }
                            // When the session is ready, we start displaying the preview.
                            mCaptureSession = cameraCaptureSession;
                        }
                    }

                    @Override
                    public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
                        showToast("Failed to configure camera.");
                    }
                }, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}