diff --git a/sdk/android/src/java/org/webrtc/Camera1Session.java b/sdk/android/src/java/org/webrtc/Camera1Session.java index 80d28c47e5..08502dc630 100644 --- a/sdk/android/src/java/org/webrtc/Camera1Session.java +++ b/sdk/android/src/java/org/webrtc/Camera1Session.java @@ -86,12 +86,17 @@ class Camera1Session implements CameraSession { final android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); - final android.hardware.Camera.Parameters parameters = camera.getParameters(); - final CaptureFormat captureFormat = - findClosestCaptureFormat(parameters, width, height, framerate); - final Size pictureSize = findClosestPictureSize(parameters, width, height); - - updateCameraParameters(camera, parameters, captureFormat, pictureSize, captureToTexture); + final CaptureFormat captureFormat; + try { + final android.hardware.Camera.Parameters parameters = camera.getParameters(); + captureFormat = findClosestCaptureFormat(parameters, width, height, framerate); + final Size pictureSize = findClosestPictureSize(parameters, width, height); + updateCameraParameters(camera, parameters, captureFormat, pictureSize, captureToTexture); + } catch (RuntimeException e) { + camera.release(); + callback.onFailure(FailureType.ERROR, e.getMessage()); + return; + } if (!captureToTexture) { final int frameSize = captureFormat.frameSize();