Bug 1441585 - Set picture size to something valid. r=dminor

MozReview-Commit-ID: 13lZcfR9wlC

--HG--
extra : rebase_source : 4037cca90cccc846f7b4e0c6da12eace3962d5af
This commit is contained in:
Andreas Pehrson 2018-04-05 17:32:09 +02:00
parent 823f7f78af
commit 8333691fd5

View File

@ -197,9 +197,33 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
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();