Android Camera2 configure crashes without reporting proper error

不打扰是莪最后的温柔 提交于 2019-12-11 01:47:01

问题


I am trying some preview frame processing on top of camera2basic example from android. createCaptureSession call is failing with no so useful error reporting. Can someone help me understand whats going wrong?

Following works and still image capturing works as expected

mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),

Following also works with my custom frame processing happening

mPreviewRequestBuilder.addTarget(mFrameReader.getSurface());
mCameraDevice.createCaptureSession(Arrays.asList(surface, mFrameReader.getSurface()), ....

However, its fails without proper error reporting when try both the things together

mPreviewRequestBuilder.addTarget(mFrameReader.getSurface());
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface(), mFrameReader.getSurface()),

I see following error in logs and my app crashes

06-20 06:37:56.430 28839-29176/com.example.android.camera2basic E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed

For reference heres the whole method

    /**
 * Creates a new {@link CameraCaptureSession} for camera preview.
 */
private void createCameraPreviewSession() {
    try {
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;

        // 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);

        mPreviewRequestBuilder.addTarget(mFrameReader.getSurface());

        // Here, we create a CameraCaptureSession for camera preview.
        mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface(), mFrameReader.getSurface()),
                new CameraCaptureSession.StateCallback() {

                    @Override
                    public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                        // The camera is already closed
                        if (null == mCameraDevice) {
                            return;
                        }

                        // When the session is ready, we start displaying the preview.
                        mCaptureSession = cameraCaptureSession;
                        try {
                            // Auto focus should be continuous for camera preview.
                            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
                            // Flash is automatically enabled when necessary.
                            setAutoFlash(mPreviewRequestBuilder);

                            // Finally, we start displaying the camera preview.
                            mPreviewRequest = mPreviewRequestBuilder.build();
                            mCaptureSession.setRepeatingRequest(mPreviewRequest,
                                    mCaptureCallback, mBackgroundHandler);
                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onConfigureFailed(
                            @NonNull CameraCaptureSession cameraCaptureSession) {
                        showToast("Failed");
                    }
                }, null
        );
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

来源:https://stackoverflow.com/questions/44650843/android-camera2-configure-crashes-without-reporting-proper-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!