How to use a reprocessCaptureRequest with camera2 API
<p>I'm trying to update a camera project to Android N and in consequence I'm moving my old <a href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createCaptureSession(java.util.List%3Candroid.view.Surface%3E,%20android.hardware.camera2.CameraCaptureSession.StateCallback,%20android.os.Handler)" rel="nofollow noreferrer">CameraCaptureSession</a> to a <a href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createReprocessableCaptureSession(android.hardware.camera2.params.InputConfiguration,%20java.util.List%3Candroid.view.Surface%3E,%20android.hardware.camera2.CameraCaptureSession.StateCallback,%20android.os.Handler)" rel="nofollow noreferrer">ReprocessableCaptureSession</a>. I did it and it is working fine, but with this new feature I can use the <code>CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG</code> template in my device and I can reprocess frames with the <a href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createReprocessCaptureRequest(android.hardware.camera2.TotalCaptureResult)" rel="nofollow noreferrer">reprocessCaptureRequest</a>.</p>

<p>Here is where my problem appear. Because I don't find any example, and I don't really understand the little documentation about how to use a <code>reprocessCaptureRequest</code>:</p>

<blockquote>
  <p>Each reprocess CaptureRequest processes one buffer from CameraCaptureSession's input Surface to all output Surfaces included in the reprocess capture request. The reprocess input images must be generated from one or multiple output images captured from the same camera device. The application can provide input images to camera device via queueInputImage(Image). The application must use the capture result of one of those output images to create a reprocess capture request so that the camera device can use the information to achieve optimal reprocess image quality. For camera devices that support only 1 output Surface, submitting a reprocess CaptureRequest with multiple output targets will result in a CaptureFailure.</p>
</blockquote>

<p>I tried to have a look to the CTS tests about the camera in <a href="https://android.googlesource.com/platform/cts/+/99d6332/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java" rel="nofollow noreferrer">google.sources</a> but they do the same than me. Using multiples imageReaders, saving the <code>TotalCaptureResult</code> of the pictures in a <code>LinkedBlockingQueue&lt;TotalCaptureResult&gt;</code>. And later just calling: </p>

<pre><code>TotalCaptureResult totalCaptureResult = state.captureCallback.getTotalCaptureResult();
CaptureRequest.Builder reprocessCaptureRequest = cameraStore.state().cameraDevice.createReprocessCaptureRequest(totalCaptureResult);
reprocessCaptureRequest.addTarget(state.yuvImageReader.getSurface());
sessionStore.state().session.capture(reprocessCaptureRequest.build(), null, this.handlers.bg());
</code></pre>

<p>But it always throw me a RuntimeException:
<code>java.lang.RuntimeException: Capture failed: Reason 0 in frame 170,</code></p>

<p>I just want to know which is the right way to work with the ReprocessableCaptureSession because I already tried everything and I don't know what I'm doing wrong.</p>