diff options
author | xianming wang <mingwax@codeaurora.org> | 2017-12-19 10:59:10 +0800 |
---|---|---|
committer | xianming wang <mingwax@codeaurora.org> | 2017-12-19 11:02:12 +0800 |
commit | 868f9317a442bcab83798427ac99f015414df700 (patch) | |
tree | 3a110d35f9e58b7196049559adcb275d7c40e71b | |
parent | 5c7d3d53d845fedccf4eb930da539db5c495d686 (diff) | |
download | android_packages_apps_Snap-868f9317a442bcab83798427ac99f015414df700.tar.gz android_packages_apps_Snap-868f9317a442bcab83798427ac99f015414df700.tar.bz2 android_packages_apps_Snap-868f9317a442bcab83798427ac99f015414df700.zip |
SnapdragonCamera: Set the preview size of video
(1)When videoSize is 4k/1080p, videoPreviewSize is no more
than 1080p.
(2)When videoSize is 720p, videoPreviewSize is no more than 720p.
CRs-Fixed: 2160890
Change-Id: I41bf061152e32c8904a6e26417d816eeb021aad6
-rwxr-xr-x | src/com/android/camera/CaptureModule.java | 16 | ||||
-rw-r--r-- | src/com/android/camera/util/CameraUtil.java | 65 |
2 files changed, 79 insertions, 2 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index bd3e4bec5..87b03d141 100755 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -3160,13 +3160,13 @@ public class CaptureModule implements CameraModule, PhotoController, mVideoSize = parsePictureSize(videoSize); Size[] prevSizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), MediaRecorder.class); - mVideoPreviewSize = getOptimalPreviewSize(mVideoSize, prevSizes); + mVideoPreviewSize = getOptimalVideoPreviewSize(mVideoSize, prevSizes); Point previewSize = PersistUtil.getCameraPreviewSize(); if (previewSize != null) { mVideoPreviewSize = new Size(previewSize.x, previewSize.y); } - Log.d(TAG, "updatePreviewSize final preview size = " + mVideoPreviewSize.getWidth() + Log.d(TAG, "updateVideoPreviewSize final video Preview size = " + mVideoPreviewSize.getWidth() + ", " + mVideoPreviewSize.getHeight()); } @@ -4889,6 +4889,18 @@ public class CaptureModule implements CameraModule, PhotoController, return (optimalPickIndex == -1) ? null : prevSizes[optimalPickIndex]; } + private Size getOptimalVideoPreviewSize(Size VideoSize, Size[] prevSizes) { + Point[] points = new Point[prevSizes.length]; + + int index = 0; + for (Size s : prevSizes) { + points[index++] = new Point(s.getWidth(), s.getHeight()); + } + + int optimalPickIndex = CameraUtil.getOptimalVideoPreviewSize(mActivity, points, VideoSize); + return (optimalPickIndex == -1) ? null : prevSizes[optimalPickIndex]; + } + private Size getMaxPictureSizeLessThan4k() { Size[] sizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), ImageFormat.JPEG); float ratio = (float) mVideoSize.getWidth() / mVideoSize.getHeight(); diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java index d6c1956d9..5c55422e8 100644 --- a/src/com/android/camera/util/CameraUtil.java +++ b/src/com/android/camera/util/CameraUtil.java @@ -617,6 +617,71 @@ public class CameraUtil { return optimalSizeIndex; } + public static Size getOptimalVideoPreviewSize(Activity currentActivity, + List<Size> sizes, android.util.Size targetSize) { + + Point[] points = new Point[sizes.size()]; + + int index = 0; + for (Size s : sizes) { + points[index++] = new Point(s.width, s.height); + } + + int optimalPickIndex = getOptimalVideoPreviewSize(currentActivity, points, targetSize); + return (optimalPickIndex == -1) ? null : sizes.get(optimalPickIndex); + } + + public static int getOptimalVideoPreviewSize(Activity currentActivity, + Point[] sizes, android.util.Size targetSize) { + // Use a very small tolerance because we want an exact match. + final double ASPECT_TOLERANCE = 0.01; + double targetRatio = (double) targetSize.getWidth() / targetSize.getHeight(); + if (sizes == null) return -1; + + int optimalSizeIndex = -1; + double minDiff = Double.MAX_VALUE; + + // we want the video preview size is not bigger than 1080p + // This point is for 1080p + Point point = new Point(1920, 1080); + int targetHeight = Math.min(point.x, point.y); + // we want the video preview size is not bigger than video size + int videoMiniHeight = Math.min(targetSize.getWidth(), targetSize.getHeight()); + // Try to find an size match aspect ratio and size + for (int i = 0; i < sizes.length; i++) { + Point size = sizes[i]; + double ratio = (double) size.x / size.y; + if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; + + double heightDiff = Math.abs(size.y - targetHeight); + if (heightDiff < minDiff && size.y <= videoMiniHeight) { + optimalSizeIndex = i; + minDiff = Math.abs(size.y - targetHeight); + } else if (heightDiff == minDiff) { + // Prefer resolutions smaller-than-display when an equally close + // larger-than-display resolution is available + if (size.y < targetHeight && size.y <= videoMiniHeight) { + optimalSizeIndex = i; + minDiff = heightDiff; + } + } + } + // Cannot find the one match the aspect ratio. This should not happen. + // Ignore the requirement. + if (optimalSizeIndex == -1) { + Log.w(TAG, "No preview size match the aspect ratio"); + minDiff = Double.MAX_VALUE; + for (int i = 0; i < sizes.length; i++) { + Point size = sizes[i]; + if (Math.abs(size.y - targetHeight) < minDiff) { + optimalSizeIndex = i; + minDiff = Math.abs(size.y - targetHeight); + } + } + } + return optimalSizeIndex; + } + // Returns the largest picture size which matches the given aspect ratio. public static Size getOptimalVideoSnapshotPictureSize( List<Size> sizes, double targetRatio) { |