3

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.

Michael
  • 3,776
  • 1
  • 16
  • 27
  • 1
    Kind of a guess, but have you experimented with changing the format from YUV_420_888 to NV21 or NV16, or seen what camera2.params.StreamConfigurationMap.getOutputFormats() returns for this device? Could you also put the whole logcat somewhere like pastebin? – sakridge Sep 08 '16 at 05:35

0 Answers0