Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8b7febd authored by Ronghua Wu's avatar Ronghua Wu Committed by Android (Google) Code Review
Browse files

Merge "media: use blocks number to find closest size" into mnc-dev

parents 5db4cc8f e595268e
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -1198,15 +1198,20 @@ public final class MediaCodecInfo {
                            (double) mFrameRateRange.getUpper()));
        }

        private int getBlockCount(int width, int height) {
            return Utils.divUp(width, mBlockWidth) * Utils.divUp(height, mBlockHeight);
        }

        @NonNull
        private Size findClosestSize(int width, int height) {
            int targetPixels = width * height;
            int targetBlockCount = getBlockCount(width, height);
            Size closestSize = null;
            int mimPixelsDiff = Integer.MAX_VALUE;
            int minDiff = Integer.MAX_VALUE;
            for (Size size : mMeasuredFrameRates.keySet()) {
                int pixelsDiff = Math.abs(targetPixels - size.getWidth() * size.getHeight());
                if (pixelsDiff < mimPixelsDiff) {
                    mimPixelsDiff = pixelsDiff;
                int diff = Math.abs(targetBlockCount -
                        getBlockCount(size.getWidth(), size.getHeight()));
                if (diff < minDiff) {
                    minDiff = diff;
                    closestSize = size;
                }
            }