OSDN Git Service

media: use blocks number to find closest size
authorRonghua Wu <ronghuawu@google.com>
Thu, 30 Jul 2015 17:54:47 +0000 (10:54 -0700)
committerRonghua Wu <ronghuawu@google.com>
Thu, 30 Jul 2015 20:01:20 +0000 (13:01 -0700)
Bug: 22504214
Change-Id: I056e19ac5fdbdff2c5d297b600210c07ae5ed4f4

media/java/android/media/MediaCodecInfo.java

index 65d0450..8243d40 100644 (file)
@@ -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;
                 }
             }