I'm encountering an issue with using a RenderScript Allocation as the preview output surface using Android's Camera2 API on some Android 5.0 devices and I'm struggling to identify the cause.
I create the input allocation as below:
Type.Builder yuvTypeBuilder = new Type.Builder(mRenderScript, Element.YUV(mRenderScript));
yuvTypeBuilder.setX(width);
yuvTypeBuilder.setY(height);
yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888);
mInputAllocation = Allocation.createTyped(mRenderScript, yuvTypeBuilder.create(), Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
And then use this allocation as the preview surface for the request builder and the capture session :
mPreviewRequestBuilder = mCamera.createCaptureRequest( CameraDevice.TEMPLATE_PREVIEW );
mPreviewRequestBuilder.addTarget( mInputAllocation.getSurface() );
List<Surface> outputSurfaces = Arrays.asList( mInputAllocation.getSurface() );
mCamera.createCaptureSession( outputSurfaces, mCallback, mHandler );
However whenever I then attempt to make a capture on the session eg the following in onConfigured
:
mCaptureSession.setRepeatingRequest( mPreviewRequestBuilder.build(), mCaptureCallback, mHandler );
It throws an IllegalArgumentException and an error log like the following:
I/CameraManager(16589): Using legacy camera HAL.
...
D/Camera (16589): app passed NULL surface
E/CameraDevice-0-LE(16589): submitRequestList - cannot use a surface that wasn't configured
This exact same code works without issues on the 6.0 devices I've tested, also the 5.0 device works if I change the preview surface to an ImageReader.