diff --git a/app/src/main/java/com/termux/api/PhotoAPI.java b/app/src/main/java/com/termux/api/PhotoAPI.java index 927b438a..f3448800 100644 --- a/app/src/main/java/com/termux/api/PhotoAPI.java +++ b/app/src/main/java/com/termux/api/PhotoAPI.java @@ -126,9 +126,11 @@ public void run() { } catch (Exception e) { stdout.println("Error writing image: " + e.getMessage()); TermuxApiLogger.error("Error writing image", e); - } finally { - closeCamera(camera, looper); } + } finally { + mImageReader.close(); + releaseSurfaces(outputSurfaces); + closeCamera(camera, looper); } } }.start(), null); @@ -156,8 +158,6 @@ public void onConfigured(final CameraCaptureSession session) { Thread.sleep(500); session.stopRepeating(); TermuxApiLogger.info("preview stoppend"); - previewTexture.release(); - dummySurface.release(); final CaptureRequest.Builder jpegRequest = camera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); // Render to our image reader: @@ -170,6 +170,8 @@ public void onConfigured(final CameraCaptureSession session) { saveImage(camera, session, jpegRequest.build()); } catch (Exception e) { TermuxApiLogger.error("onConfigured() error in preview", e); + mImageReader.close(); + releaseSurfaces(outputSurfaces); closeCamera(camera, looper); } } @@ -177,6 +179,8 @@ public void onConfigured(final CameraCaptureSession session) { @Override public void onConfigureFailed(CameraCaptureSession session) { TermuxApiLogger.error("onConfigureFailed() error in preview"); + mImageReader.close(); + releaseSurfaces(outputSurfaces); closeCamera(camera, looper); } }, null); @@ -187,7 +191,6 @@ static void saveImage(final CameraDevice camera, CameraCaptureSession session, C @Override public void onCaptureCompleted(CameraCaptureSession completedSession, CaptureRequest request, TotalCaptureResult result) { TermuxApiLogger.info("onCaptureCompleted()"); - closeCamera(camera, null); } }, null); } @@ -244,6 +247,13 @@ static int correctOrientation(final Context context, final CameraCharacteristics return jpegOrientation; } + static void releaseSurfaces(List outputSurfaces) { + for (Surface outputSurface : outputSurfaces) { + outputSurface.release(); + } + TermuxApiLogger.info("surfaces released"); + } + static void closeCamera(CameraDevice camera, Looper looper) { try { camera.close();