|
|
|
@ -539,11 +539,19 @@ public class Camera2Engine extends CameraBaseEngine implements |
|
|
|
|
// 4. FRAME PROCESSING
|
|
|
|
|
if (hasFrameProcessors()) { |
|
|
|
|
mFrameProcessingSize = computeFrameProcessingSize(); |
|
|
|
|
// Hard to write down why, but in Camera2 we need a number of Frames that's one less
|
|
|
|
|
// than the number of Images. If we let all Images be part of Frames, thus letting all
|
|
|
|
|
// Images be used by processor at any given moment, the Camera2 output breaks.
|
|
|
|
|
// In fact, if there are no Images available, the sensor BLOCKS until it finds one,
|
|
|
|
|
// which is a big issue because processor times become a bottleneck for the preview.
|
|
|
|
|
// This is a design flaw in the ImageReader / sensor implementation, as they should
|
|
|
|
|
// simply DROP frames written to the surface if there are no Images available.
|
|
|
|
|
// Since this is not how things work, we ensure that one Image is always available here.
|
|
|
|
|
mFrameProcessingReader = ImageReader.newInstance( |
|
|
|
|
mFrameProcessingSize.getWidth(), |
|
|
|
|
mFrameProcessingSize.getHeight(), |
|
|
|
|
mFrameProcessingFormat, |
|
|
|
|
getFrameProcessingPoolSize()); |
|
|
|
|
getFrameProcessingPoolSize() + 1); |
|
|
|
|
mFrameProcessingReader.setOnImageAvailableListener(this, |
|
|
|
|
null); |
|
|
|
|
mFrameProcessingSurface = mFrameProcessingReader.getSurface(); |
|
|
|
@ -1407,13 +1415,13 @@ public class Camera2Engine extends CameraBaseEngine implements |
|
|
|
|
@EngineThread |
|
|
|
|
@Override |
|
|
|
|
public void onImageAvailable(ImageReader reader) { |
|
|
|
|
LOG.v("onImageAvailable", "trying to acquire Image."); |
|
|
|
|
LOG.v("onImageAvailable:", "trying to acquire Image."); |
|
|
|
|
Image image = null; |
|
|
|
|
try { |
|
|
|
|
image = reader.acquireLatestImage(); |
|
|
|
|
} catch (Exception ignore) { } |
|
|
|
|
if (image == null) { |
|
|
|
|
LOG.w("onImageAvailable", "failed to acquire Image!"); |
|
|
|
|
LOG.w("onImageAvailable:", "failed to acquire Image!"); |
|
|
|
|
} else if (getState() == CameraState.PREVIEW && !isChangingState()) { |
|
|
|
|
// After preview, the frame manager is correctly set up
|
|
|
|
|
//noinspection unchecked
|
|
|
|
@ -1422,8 +1430,14 @@ public class Camera2Engine extends CameraBaseEngine implements |
|
|
|
|
getAngles().offset(Reference.SENSOR, |
|
|
|
|
Reference.OUTPUT, |
|
|
|
|
Axis.RELATIVE_TO_SENSOR)); |
|
|
|
|
getCallback().dispatchFrame(frame); |
|
|
|
|
if (frame != null) { |
|
|
|
|
LOG.v("onImageAvailable:", "Image acquired, dispatching."); |
|
|
|
|
getCallback().dispatchFrame(frame); |
|
|
|
|
} else { |
|
|
|
|
LOG.i("onImageAvailable:", "Image acquired, but no free frames. DROPPING."); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
LOG.i("onImageAvailable:", "Image acquired in wrong state. Closing it now."); |
|
|
|
|
image.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|