Skip to content

Commit

Permalink
Disable video capture for legacy camera devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Oct 25, 2019
1 parent 1ccce24 commit 5e96832
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,15 @@ public boolean onDoubleTap(MotionEvent e) {
galleryButton.setOnClickListener(v -> controller.onGalleryClicked());
countButton.setOnClickListener(v -> controller.onCameraCountButtonClicked());

if (MediaConstraints.isVideoTranscodeAvailable()) {
if (isVideoRecordingSupported(requireContext())) {
try {
closeVideoFileDescriptor();
videoFileDescriptor = CameraXVideoCaptureHelper.createFileDescriptor(requireContext());

Animation inAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in);
Animation outAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_out);

if (CameraXUtil.isMixedModeSupported(requireContext())) {
Log.i(TAG, "Device supports mixed mode recording. [" + CameraXUtil.getLowestSupportedHardwareLevel(requireContext()) + "]");
camera.setCaptureMode(CameraXView.CaptureMode.MIXED);
} else {
Log.i(TAG, "Device does not support mixed mode recording, falling back to IMAGE [" + CameraXUtil.getLowestSupportedHardwareLevel(requireContext()) + "]");
camera.setCaptureMode(CameraXView.CaptureMode.IMAGE);
}
camera.setCaptureMode(CameraXView.CaptureMode.MIXED);

captureButton.setVideoCaptureListener(new CameraXVideoCaptureHelper(
this,
Expand All @@ -251,9 +245,6 @@ public boolean onDoubleTap(MotionEvent e) {
new CameraXVideoCaptureHelper.Callback() {
@Override
public void onVideoRecordStarted() {
if (camera.getCaptureMode() == CameraXView.CaptureMode.IMAGE) {
camera.setCaptureMode(CameraXView.CaptureMode.VIDEO);
}
hideAndDisableControlsForVideoRecording(captureButton, flashButton, flipButton, outAnimation);
}

Expand All @@ -275,12 +266,16 @@ public void onVideoError(@Nullable Throwable cause) {
Log.w(TAG, "Video capture is not supported on this device.", e);
}
} else {
Log.i(TAG, "Video capture not supported. API: " + Build.VERSION.SDK_INT + ", MFD: " + MemoryFileDescriptor.supported());
Log.i(TAG, "Video capture not supported. API: " + Build.VERSION.SDK_INT + ", MFD: " + MemoryFileDescriptor.supported() + ", Camera: " + CameraXUtil.getLowestSupportedHardwareLevel(requireContext()));
}

viewModel.onCameraControlsInitialized();
}

private boolean isVideoRecordingSupported(@NonNull Context context) {
return MediaConstraints.isVideoTranscodeAvailable() && CameraXUtil.isMixedModeSupported(context);
}

private void displayVideoRecordingTooltipIfNecessary(CameraButtonView captureButton) {
if (shouldDisplayVideoRecordingTooltip()) {
int displayRotation = requireActivity().getWindowManager().getDefaultDisplay().getRotation();
Expand Down Expand Up @@ -332,12 +327,6 @@ private void showAndEnableControlsAfterVideoRecording(@NonNull View captureButto
}

private void onCaptureClicked() {
if (camera.getCaptureMode() == CameraXView.CaptureMode.VIDEO) {
camera.setCaptureMode(CameraXView.CaptureMode.IMAGE);
Util.runOnMainDelayed(this::onCaptureClicked, 100);
return;
}

Stopwatch stopwatch = new Stopwatch("Capture");

CameraXSelfieFlashHelper flashHelper = new CameraXSelfieFlashHelper(
Expand Down

0 comments on commit 5e96832

Please sign in to comment.