Default to 1x camera in video recording.

Addresses #11955, #12482, #13017

Shout out to @tedgravlin for #13411.
This commit is contained in:
Nicholas Tinsley
2024-02-13 12:44:09 -05:00
committed by Cody Henthorne
parent 36ea2a7f5d
commit 6a65a1c149
2 changed files with 24 additions and 7 deletions

View File

@@ -31,6 +31,7 @@ import org.thoughtcrime.securesms.mediasend.camerax.CameraXModePolicy;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.util.ContextUtil;
import org.thoughtcrime.securesms.util.Debouncer;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
import org.thoughtcrime.securesms.video.VideoUtil;
@@ -42,7 +43,7 @@ import java.util.concurrent.TimeUnit;
@RequiresApi(26)
class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener {
private static final String TAG = CameraXVideoCaptureHelper.class.getName();
private static final String TAG = Log.tag(CameraXVideoCaptureHelper.class);
private static final String VIDEO_DEBUG_LABEL = "video-capture";
private static final long VIDEO_SIZE = 10 * 1024 * 1024;
@@ -74,7 +75,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
} else {
try {
debouncer.clear();
cameraController.setZoomRatio(Objects.requireNonNull(cameraController.getZoomState().getValue()).getMinZoomRatio());
cameraController.setZoomRatio(getDefaultVideoZoomRatio());
memoryFileDescriptor.seek(0);
callback.onVideoSaved(memoryFileDescriptor.getFileDescriptor());
} catch (IOException e) {
@@ -142,7 +143,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
@SuppressLint("RestrictedApi")
private void beginCameraRecording() {
cameraXModePolicy.setToVideo(cameraController);
this.cameraController.setZoomRatio(Objects.requireNonNull(this.cameraController.getZoomState().getValue()).getMinZoomRatio());
this.cameraController.setZoomRatio(getDefaultVideoZoomRatio());
callback.onVideoRecordStarted();
shrinkCaptureArea();
@@ -232,8 +233,8 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
@Override
public void onZoomIncremented(float increment) {
ZoomState zoomState = Objects.requireNonNull(cameraController.getZoomState().getValue());
float range = zoomState.getMaxZoomRatio() - zoomState.getMinZoomRatio();
cameraController.setZoomRatio((range * increment) + zoomState.getMinZoomRatio());
float range = zoomState.getMaxZoomRatio() - getDefaultVideoZoomRatio();
cameraController.setZoomRatio((range * increment) + getDefaultVideoZoomRatio());
}
@Override
@@ -254,6 +255,14 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
);
}
public float getDefaultVideoZoomRatio() {
if (FeatureFlags.startVideoRecordAt1x()) {
return 1f;
} else {
return Objects.requireNonNull(cameraController.getZoomState().getValue()).getMinZoomRatio();
}
}
interface Callback {
void onVideoRecordStarted();

View File

@@ -120,6 +120,7 @@ public final class FeatureFlags {
private static final String USE_ACTIVE_CALL_MANAGER = "android.calling.useActiveCallManager.4";
private static final String GIF_SEARCH = "global.gifSearch";
private static final String AUDIO_REMUXING = "android.media.audioRemux";
private static final String VIDEO_RECORD_1X_ZOOM = "android.media.videoCaptureDefaultZoom";
/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
@@ -192,7 +193,8 @@ public final class FeatureFlags {
PHONE_NUMBER_PRIVACY,
USE_ACTIVE_CALL_MANAGER,
GIF_SEARCH,
AUDIO_REMUXING
AUDIO_REMUXING,
VIDEO_RECORD_1X_ZOOM
);
@VisibleForTesting
@@ -262,7 +264,8 @@ public final class FeatureFlags {
CALLING_REACTIONS,
NOTIFICATION_THUMBNAIL_BLOCKLIST,
CALLING_RAISE_HAND,
PHONE_NUMBER_PRIVACY
PHONE_NUMBER_PRIVACY,
VIDEO_RECORD_1X_ZOOM
);
/**
@@ -690,6 +693,11 @@ public final class FeatureFlags {
return getBoolean(AUDIO_REMUXING, false);
}
/** Get the default video zoom, expressed as 10x the actual Float value due to the service limiting us to whole numbers. */
public static boolean startVideoRecordAt1x() {
return getBoolean(VIDEO_RECORD_1X_ZOOM, false);
}
/** Only for rendering debug info. */
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
return new TreeMap<>(REMOTE_VALUES);