我有一个相机应用程序,它有两个输出目标Surface,一个用于ImageReader进行分析,另一个用于SurfaceTexture的Surface。但是,当我将两者都用作CaptureRequestBuilder的目标(或更糟糕的是,两个单独的CaptureRequests)时,每个输出流的感觉就像5-10 fps一样,效果非常差。因此,要解决此问题,我使用了ImageWriter(至少是我的想法),该图像在ImageReader的onImageAvaiableListener()回调中将图像写入SurfaceTexture的Surface:
mImageWriter = ImageWriter.newInstance(surface, 1);
mImageReader = ImageReader.newInstance(1280, 720, PixelFormat.RGBA_8888, 1);
try {
final CaptureRequest.Builder captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
captureRequestBuilder.addTarget(mImageReader.getSurface());
session.setRepeatingRequest(captureRequestBuilder.build(), new CameraCaptureCallback(), cameraThreadHandler);
} catch (CameraAccessException e) {
reportError("Failed to start capture request. " + e);
return;
}
localListener= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Image image = imageReader.acquireLatestImage();
mImageWriter.queueInputImage(image);
}
};
mImageReader.setOnImageAvailableListener(localListener, null);
据我所知,这应该就像使用“ surface”作为目标制作单独的CapturerRequestBuilder一样。但是,在执行时,我在SurfaceTexture的updateTexImage函数中收到以下错误:
E/GLConsumer: [SurfaceTexture-1-20518-1] doGLFenceWait: error dup'ing fence fd: 9
--------- beginning of crash
03-14 23:08:48.246 20518-20750 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Error during updateTexImage (see logcat for details)
at android.graphics.SurfaceTexture.nativeUpdateTexImage(Native Method)
at android.graphics.SurfaceTexture.updateTexImage(SurfaceTexture.java:240)
at org.webrtc.SurfaceTextureHelper.updateTexImage(SurfaceTextureHelper.java:266)
at org.webrtc.SurfaceTextureHelper.tryDeliverTextureFrame(SurfaceTextureHelper.java:280)
at org.webrtc.SurfaceTextureHelper.lambda$new$0(SurfaceTextureHelper.java:137)
at org.webrtc.-$$Lambda$SurfaceTextureHelper$7YTfC0byyd0o_zI7mNhfP12Gm0Q.onFrameAvailable(lambda)
at android.graphics.SurfaceTexture$1.handleMessage(SurfaceTexture.java:203)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
有人可以向我解释该错误的含义是什么,我该如何解决? 甚至可以像我一样将图像写入SurfaceTexture吗? 还是我的代码错了?