Skip to content

Commit

Permalink
Merge branch 'termux:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tareksander authored Dec 15, 2021
2 parents afdb1b3 + a5f7d14 commit d91b0a9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/src/main/java/com/termux/api/PhotoAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -170,13 +170,17 @@ 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);
}
}

@Override
public void onConfigureFailed(CameraCaptureSession session) {
TermuxApiLogger.error("onConfigureFailed() error in preview");
mImageReader.close();
releaseSurfaces(outputSurfaces);
closeCamera(camera, looper);
}
}, null);
Expand All @@ -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);
}
Expand Down Expand Up @@ -244,6 +247,13 @@ static int correctOrientation(final Context context, final CameraCharacteristics
return jpegOrientation;
}

static void releaseSurfaces(List<Surface> outputSurfaces) {
for (Surface outputSurface : outputSurfaces) {
outputSurface.release();
}
TermuxApiLogger.info("surfaces released");
}

static void closeCamera(CameraDevice camera, Looper looper) {
try {
camera.close();
Expand Down

0 comments on commit d91b0a9

Please sign in to comment.