Don't check a framerate if we don't have one.
Seems (marginally) nicer than making one up :). I didn't realize there was a method that didn't require a framerate to be passed! ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=110456874
This commit is contained in:
parent
6eea4bdbc3
commit
dd497b1259
@ -240,6 +240,27 @@ public final 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
|
||||
* and height.
|
||||
* <p>
|
||||
* 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.
|
||||
* @return Whether the decoder advertises support of the given size.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public static boolean isSizeSupportedV21(String mimeType, boolean secure, int width,
|
||||
int height) throws DecoderQueryException {
|
||||
Assertions.checkState(Util.SDK_INT >= 21);
|
||||
MediaCodecInfo.VideoCapabilities videoCapabilities = getVideoCapabilitiesV21(mimeType, secure);
|
||||
return videoCapabilities != null && videoCapabilities.isSizeSupported(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the device advertises it can decode video of a given type at a specified
|
||||
* width, height, and frame rate.
|
||||
@ -258,11 +279,7 @@ public final class MediaCodecUtil {
|
||||
public static boolean isSizeAndRateSupportedV21(String mimeType, boolean secure,
|
||||
int width, int height, double frameRate) throws DecoderQueryException {
|
||||
Assertions.checkState(Util.SDK_INT >= 21);
|
||||
Pair<String, CodecCapabilities> info = getMediaCodecInfo(mimeType, secure);
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
MediaCodecInfo.VideoCapabilities videoCapabilities = info.second.getVideoCapabilities();
|
||||
MediaCodecInfo.VideoCapabilities videoCapabilities = getVideoCapabilitiesV21(mimeType, secure);
|
||||
return videoCapabilities != null
|
||||
&& videoCapabilities.areSizeAndRateSupported(width, height, frameRate);
|
||||
}
|
||||
@ -310,6 +327,16 @@ public final class MediaCodecUtil {
|
||||
return maxH264DecodableFrameSize;
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
private static MediaCodecInfo.VideoCapabilities getVideoCapabilitiesV21(String mimeType,
|
||||
boolean secure) throws DecoderQueryException {
|
||||
Pair<String, CodecCapabilities> info = getMediaCodecInfo(mimeType, secure);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
return info.second.getVideoCapabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversion values taken from: https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC.
|
||||
*
|
||||
|
@ -154,9 +154,13 @@ public final class VideoFormatSelectorUtil {
|
||||
if (format.width > 0 && format.height > 0) {
|
||||
String videoMediaMimeType = MimeTypes.getVideoMediaMimeType(format.codecs);
|
||||
if (Util.SDK_INT >= 21 && !MimeTypes.VIDEO_UNKNOWN.equals(videoMediaMimeType)) {
|
||||
float frameRate = (format.frameRate > 0) ? format.frameRate : 30.0f;
|
||||
return MediaCodecUtil.isSizeAndRateSupportedV21(videoMediaMimeType, false,
|
||||
format.width, format.height, frameRate);
|
||||
if (format.frameRate > 0) {
|
||||
return MediaCodecUtil.isSizeAndRateSupportedV21(videoMediaMimeType, false, format.width,
|
||||
format.height, format.frameRate);
|
||||
} else {
|
||||
return MediaCodecUtil.isSizeSupportedV21(videoMediaMimeType, false, format.width,
|
||||
format.height);
|
||||
}
|
||||
}
|
||||
//Assuming that the media is H.264
|
||||
if (format.width * format.height > maxDecodableFrameSize) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user