diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/camera/Camera2Session.java b/TMessagesProj/src/main/java/org/telegram/messenger/camera/Camera2Session.java index bc37ca6d8..2e821daf1 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/camera/Camera2Session.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/camera/Camera2Session.java @@ -479,6 +479,8 @@ public class Camera2Session { if (recordingVideo) { captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range(30, 60)); captureRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD); + + isStabilizationAvailable(builder); } if (sensorSize != null && Math.abs(currentZoom - 1f) >= 0.01f) { @@ -502,6 +504,41 @@ public class Camera2Session { } } + private void isStabilizationAvailable(CaptureRequest.Builder builder) { + if (setModeIfAvailable( + builder, + CameraCharacteristics.LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, + CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON, + CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE)) { + builder.set( + CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, + CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_OFF); + FileLog.d("Camera2Sessions use OpticalImageStabilization"); + } else if (setModeIfAvailable( + builder, + CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, + CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_ON, + CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE)) { + builder.set( + CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE, + CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_OFF); + FileLog.d("Camera2Sessions use ElectronicImageStabilization"); + } else { + FileLog.d("Camera2Sessions stabilization is not available"); + } + } + + private boolean setModeIfAvailable( + CameraCharacteristics.Key key, int desiredMode, + CaptureRequest.Builder builder, CaptureRequest.Key requestKey) { + int[] availableModes = cameraCharacteristics.get(key); + if (availableModes != null && Arrays.stream(availableModes).anyMatch(mode -> mode == desiredMode)) { + builder.set(requestKey, desiredMode); + return true; + } + return false; + } + public boolean takePicture(final File file, Utilities.Callback whenDone) { if (cameraDevice == null || captureSession == null) return false; try {