From fea2140d57e5e4d422b923790018017f5aa71ab9 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 10 Apr 2015 23:15:52 +0100 Subject: [PATCH] Add ability to query size/rate support in MediaCodecUtil. --- .../android/exoplayer/MediaCodecUtil.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java index f3dbc7e7d1..5dbe3c5a11 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer; +import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.Util; @@ -179,6 +180,33 @@ public class MediaCodecUtil { return capabilities.isFeatureSupported(CodecCapabilities.FEATURE_AdaptivePlayback); } + /** + * Tests whether the device advertises it can decode video of a given type at a specified + * width, height, and frame rate. + *

+ * Must not be called if the device SDK version is less than 21. + * + * @param mimeType The mime type. + * @param secure Whether the decoder is required to support secure decryption. Always pass false + * unless secure decryption really is required. + * @param width Width in pixels. + * @param height Height in pixels. + * @param frameRate Frame rate in frames per second. + * @return Whether the decoder advertises support of the given size and frame rate. + */ + @TargetApi(21) + public static boolean isSizeAndRateSupportedV21(String mimeType, boolean secure, + int width, int height, double frameRate) throws DecoderQueryException { + Assertions.checkState(Util.SDK_INT >= 21); + Pair info = getMediaCodecInfo(mimeType, secure); + if (info == null) { + return false; + } + MediaCodecInfo.VideoCapabilities videoCapabilities = info.second.getVideoCapabilities(); + return videoCapabilities != null + && videoCapabilities.areSizeAndRateSupported(width, height, frameRate); + } + /** * @param profile An AVC profile constant from {@link CodecProfileLevel}. * @param level An AVC profile level from {@link CodecProfileLevel}.