From f22d3c48fa14502cd4c8e0ffc4c1eae4d7116b6f Mon Sep 17 00:00:00 2001 From: sakal Date: Wed, 27 Jul 2016 01:28:44 -0700 Subject: [PATCH] Filter to formats that match device sensor array aspect ratio on pre-LMR1 devices offering only legacy camera2 support. There is a bug on pre LMR1 devices that only support legacy implementation of camera2 API where aspect ratio of the camera is incorrect if the output format doesn't match the aspect ratio of the sensor array. On these devices, we want to disable the output formats that have different aspect ratio. Review-Url: https://codereview.webrtc.org/2181803003 Cr-Commit-Position: refs/heads/master@{#13538} --- .../src/org/webrtc/Camera2Enumerator.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java b/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java index 3fd34ddd92..b3a48b3570 100644 --- a/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java +++ b/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java @@ -15,6 +15,7 @@ import org.webrtc.CameraEnumerationAndroid.CaptureFormat; import android.annotation.TargetApi; import android.content.Context; import android.graphics.ImageFormat; +import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCharacteristics; @@ -108,12 +109,30 @@ public class Camera2Enumerator implements CameraEnumerator { CameraCharacteristics cameraCharacteristics) { final StreamConfigurationMap streamMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); - final android.util.Size[] sizes = streamMap.getOutputSizes(SurfaceTexture.class); - if (sizes == null) { - Logging.e(TAG, "No supported camera output sizes."); - return new ArrayList(); + final int supportLevel = + cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); + + final android.util.Size[] nativeSizes = streamMap.getOutputSizes(SurfaceTexture.class); + final List sizes = convertSizes(nativeSizes); + + // Video may be stretched pre LMR1 on legacy implementations. + // Filter out formats that have different aspect ratio than the sensor array. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 && + supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) { + final Rect activeArraySize = + cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); + final ArrayList filteredSizes = new ArrayList(); + + for (Size size : sizes) { + if (activeArraySize.width() * size.height == activeArraySize.height() * size.width) { + filteredSizes.add(size); + } + } + + return filteredSizes; + } else { + return sizes; } - return convertSizes(sizes); } static List getSupportedFormats(Context context, String cameraId) {