Search in sources :

Example 11 with CameraCaptureSession

use of android.hardware.camera2.CameraCaptureSession in project android_packages_apps_Snap by LineageOS.

the class Camera2GraphView method applyZoomAndUpdate.

private void applyZoomAndUpdate(int id) {
    if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
        return;
    }
    applyZoom(mPreviewRequestBuilder[id], id);
    try {
        if (id == MONO_ID && !canStartMonoPreview()) {
            mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
        } else {
            CameraCaptureSession session = mCaptureSession[id];
            if (session instanceof CameraConstrainedHighSpeedCaptureSession) {
                List list = CameraUtil.createHighSpeedRequestList(mPreviewRequestBuilder[id].build(), id);
                ((CameraConstrainedHighSpeedCaptureSession) session).setRepeatingBurst(list, mCaptureCallback, mCameraHandler);
            } else {
                mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
            }
        }
    } catch (CameraAccessException | IllegalStateException e) {
        e.printStackTrace();
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) CameraConstrainedHighSpeedCaptureSession(android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession)

Example 12 with CameraCaptureSession

use of android.hardware.camera2.CameraCaptureSession in project robolectric by robolectric.

the class ShadowCameraDeviceImpl method createCaptureSession.

@Implementation(minSdk = VERSION_CODES.P)
protected void createCaptureSession(List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler) throws CameraAccessException {
    checkIfCameraClosedOrInError();
    CameraCaptureSession session = createCameraCaptureSession(callback);
    handler.post(() -> callback.onConfigured(session));
}
Also used : CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Implementation(org.robolectric.annotation.Implementation)

Example 13 with CameraCaptureSession

use of android.hardware.camera2.CameraCaptureSession in project robolectric by robolectric.

the class ShadowCameraDeviceImpl method createCameraCaptureSession.

private CameraCaptureSession createCameraCaptureSession(CameraCaptureSession.StateCallback callback) {
    CameraCaptureSession sess = Shadow.newInstanceOf(CameraCaptureSessionImpl.class);
    ReflectionHelpers.setField(CameraCaptureSessionImpl.class, sess, "mStateCallback", callback);
    ReflectionHelpers.setField(CameraCaptureSessionImpl.class, sess, "mDeviceImpl", realObject);
    return sess;
}
Also used : CameraCaptureSession(android.hardware.camera2.CameraCaptureSession)

Example 14 with CameraCaptureSession

use of android.hardware.camera2.CameraCaptureSession in project react-native-camera by lwansbrough.

the class Camera2 method setFocusArea.

/**
 * Auto focus on input coordinates
 */
// Much credit - https://gist.github.com/royshil/8c760c2485257c85a11cafd958548482
void setFocusArea(float x, float y) {
    if (mCaptureSession == null) {
        return;
    }
    CameraCaptureSession.CaptureCallback captureCallbackHandler = new CameraCaptureSession.CaptureCallback() {

        @Override
        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
            super.onCaptureCompleted(session, request, result);
            if (request.getTag() == "FOCUS_TAG") {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
                try {
                    mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, null);
                } catch (CameraAccessException e) {
                    Log.e(TAG, "Failed to manual focus.", e);
                }
            }
        }

        @Override
        public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
            super.onCaptureFailed(session, request, failure);
            Log.e(TAG, "Manual AF failure: " + failure);
        }
    };
    try {
        mCaptureSession.stopRepeating();
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to manual focus.", e);
    }
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), captureCallbackHandler, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to manual focus.", e);
    }
    if (isMeteringAreaAFSupported()) {
        MeteringRectangle focusAreaTouch = calculateFocusArea(x, y);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { focusAreaTouch });
    }
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
    mPreviewRequestBuilder.setTag("FOCUS_TAG");
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), captureCallbackHandler, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to manual focus.", e);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CaptureFailure(android.hardware.camera2.CaptureFailure) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) MeteringRectangle(android.hardware.camera2.params.MeteringRectangle) CaptureRequest(android.hardware.camera2.CaptureRequest) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession)

Example 15 with CameraCaptureSession

use of android.hardware.camera2.CameraCaptureSession in project collect by opendatakit.

the class Camera2VideoFragment method startRecordingVideo.

private void startRecordingVideo() {
    if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) {
        return;
    }
    try {
        closePreviewSession();
        setUpMediaRecorder();
        SurfaceTexture texture = textureView.getSurfaceTexture();
        assert texture != null;
        texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
        previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        List<Surface> surfaces = new ArrayList<>();
        // Set up Surface for the camera preview
        Surface previewSurface = new Surface(texture);
        surfaces.add(previewSurface);
        previewBuilder.addTarget(previewSurface);
        // Set up Surface for the MediaRecorder
        Surface recorderSurface = mediaRecorder.getSurface();
        surfaces.add(recorderSurface);
        previewBuilder.addTarget(recorderSurface);
        // Start a capture session
        // Once the session starts, we can update the UI and start recording
        cameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {

            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                previewSession = cameraCaptureSession;
                updatePreview();
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // UI
                        isRecordingVideo = true;
                        // Start recording
                        mediaRecorder.start();
                        ToastUtils.showLongToast(getActivity(), getActivity().getString(R.string.stop_video_capture_instruction));
                    }
                });
            }

            @Override
            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                Activity activity = getActivity();
                if (null != activity) {
                    ToastUtils.showShortToast(getActivity(), "Failed");
                }
            }
        }, backgroundHandler);
    } catch (CameraAccessException | IOException e) {
        Timber.e(e);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) SurfaceTexture(android.graphics.SurfaceTexture) ArrayList(java.util.ArrayList) Activity(android.app.Activity) IOException(java.io.IOException) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Surface(android.view.Surface)

Aggregations

CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)38 CameraAccessException (android.hardware.camera2.CameraAccessException)18 Surface (android.view.Surface)18 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)10 ArrayList (java.util.ArrayList)10 CaptureRequest (android.hardware.camera2.CaptureRequest)9 TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)8 SurfaceTexture (android.graphics.SurfaceTexture)6 CameraDevice (android.hardware.camera2.CameraDevice)6 Activity (android.app.Activity)5 Point (android.graphics.Point)5 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)4 CaptureFailure (android.hardware.camera2.CaptureFailure)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 CameraManager (android.hardware.camera2.CameraManager)3 Image (android.media.Image)3 NonNull (android.support.annotation.NonNull)3 Size (android.util.Size)3 IOException (java.io.IOException)3