Bug 1441585 - Set picture size to something valid. r=dminor, a=RyanVM
authorAndreas Pehrson <pehrsons@mozilla.com>
Thu, 05 Apr 2018 17:32:09 +0200
changeset 463113 4ecc63b45a4f0aea3611d61d1df534b1fb36a947
parent 463112 a3dff4cabfb7796847bff64e068e57783e3ac0bd
child 463114 64c9c9119d105548f38b6eb731c6b85b7ff2094b
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor, RyanVM
bugs1441585
milestone60.0
Bug 1441585 - Set picture size to something valid. r=dminor, a=RyanVM MozReview-Commit-ID: 13lZcfR9wlC
media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
@@ -192,19 +192,43 @@ public class VideoCaptureAndroid impleme
       }
 
       List<String> focusModes = parameters.getSupportedFocusModes();
       if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
         Log.d(TAG, "Enable continuous auto focus mode.");
         parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
       }
 
-      parameters.setPictureSize(width, height);
+      // (width,height) is a valid preview size. It might not be a valid picture
+      // size.
       parameters.setPreviewSize(width, height);
 
+      List<Camera.Size> supportedPictureSizes =
+        parameters.getSupportedPictureSizes();
+      Camera.Size pictureSize = supportedPictureSizes.get(0);
+      for (Camera.Size size : supportedPictureSizes) {
+        if (size.width < width || size.height < height) {
+          // We want a picture size larger than the preview size
+          continue;
+        }
+        if (pictureSize.width < width || pictureSize.height < height) {
+          // The so-far chosen pictureSize is smaller than the preview size.
+          // `size` is a better fit.
+          pictureSize = size;
+          continue;
+        }
+        if (size.width <= pictureSize.width &&
+            size.height <= pictureSize.height) {
+          // Both the so-far chosen pictureSize and `size` are larger than the
+          // preview size, but `size` is closest, so it's preferred.
+          pictureSize = size;
+        }
+      }
+      parameters.setPictureSize(pictureSize.width, pictureSize.height);
+
       // Check if requested fps range is supported by camera,
       // otherwise calculate frame drop ratio.
       List<int[]> supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
       frameDropRatio = Integer.MAX_VALUE;
       for (int i = 0; i < supportedFpsRanges.size(); i++) {
         int[] range = supportedFpsRanges.get(i);
         if (range[Parameters.PREVIEW_FPS_MIN_INDEX] == min_mfps &&
             range[Parameters.PREVIEW_FPS_MAX_INDEX] == max_mfps) {