Android 5.0上的RenderScript Allocation使Camera2输出表面失败

时间:2016-08-26 07:10:03

标签: android renderscript camera2

我在某些Android 5.0设备上使用Android的Camera2 API将RenderScript Allocation用作预览输出表面时遇到了问题,我很难确定原因。

我创建输入分配如下:

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

然后将此分配用作请求构建器和捕获会话的预览表面:

mPreviewRequestBuilder = mCamera.createCaptureRequest( CameraDevice.TEMPLATE_PREVIEW );
mPreviewRequestBuilder.addTarget( mInputAllocation.getSurface() );

List<Surface> outputSurfaces = Arrays.asList( mInputAllocation.getSurface() );
mCamera.createCaptureSession( outputSurfaces, mCallback, mHandler );

然而,每当我尝试在会话上进行捕获时,例如onConfigured中的以下内容:

mCaptureSession.setRepeatingRequest( mPreviewRequestBuilder.build(), mCaptureCallback, mHandler );

它会抛出IllegalArgumentException和错误日志,如下所示:

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

这个完全相同的代码在我测试过的6.0设备上没有问题,如果我将预览曲面更改为ImageReader,5.0设备也能正常工作。

0 个答案:

没有答案