From a1c9803e3283d41da0256779a01e355a881d407b Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Tue, 3 Mar 2015 10:54:07 +0000 Subject: [PATCH] Fix crash in setPictureSize on Galaxy Nexus. This cl tries to find the best supported pictureSize before setting it. BUG=4197 R=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45419004 Cr-Commit-Position: refs/heads/master@{#8571} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8571 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../src/org/webrtc/VideoCapturerAndroid.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java index bb0b338aaa..ef6666a538 100644 --- a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java +++ b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java @@ -247,7 +247,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba json_format.put("framerate", (format.maxFramerate + 999) / 1000); json_formats.put(json_format); } - Log.d(TAG, "Supported formats: " + json_formats.toString(2)); + Log.d(TAG, "Supported formats for camera " + id + ": " + + json_formats.toString(2)); return json_formats.toString(); } @@ -265,8 +266,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba if (listFpsRange != null) range = listFpsRange.get(listFpsRange.size() -1); - List supportedSizes = - parameters.getSupportedPreviewSizes(); + List supportedSizes = parameters.getSupportedPreviewSizes(); for (Camera.Size size : supportedSizes) { if (size.width % 16 != 0) { // If the width is not a multiple of 16, the frames received from the @@ -394,7 +394,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } - parameters.setPictureSize(width, height); + Camera.Size pictureSize = getPictureSize(parameters, width, height); + parameters.setPictureSize(pictureSize.width, pictureSize.height); parameters.setPreviewSize(width, height); int format = ImageFormat.YV12; parameters.setPreviewFormat(format); @@ -516,6 +517,22 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba return bestRange; } + private static Camera.Size getPictureSize(Camera.Parameters parameters, + int width, int height) { + int bestAreaDiff = Integer.MAX_VALUE; + Camera.Size bestSize = null; + int requestedArea = width * height; + for (Camera.Size pictureSize : parameters.getSupportedPictureSizes()) { + int areaDiff = abs(requestedArea + - pictureSize.width * pictureSize.height); + if (areaDiff < bestAreaDiff) { + bestAreaDiff = areaDiff; + bestSize = pictureSize; + } + } + return bestSize; + } + // Called on cameraThread so must not "synchronized". @Override public void onPreviewFrame(byte[] data, Camera callbackCamera) {