diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java index de156ea0db..03adf45819 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java @@ -108,7 +108,7 @@ public final class VideoFormatSelectorUtil { // Keep track of the number of pixels of the selected format whose resolution is the // smallest to exceed the maximum size at which it can be displayed within the viewport. // We'll discard formats of higher resolution in a second pass. - if (format.width != -1 && format.height != -1) { + if (format.width > 0 && format.height > 0) { Point maxVideoSizeInViewport = getMaxVideoSizeInViewport(orientationMayChange, viewportWidth, viewportHeight, format.width, format.height); int videoPixels = format.width * format.height; @@ -126,7 +126,7 @@ public final class VideoFormatSelectorUtil { // viewport. for (int i = selectedIndexList.size() - 1; i >= 0; i--) { Format format = formatWrappers.get(i).getFormat(); - if (format.width != -1 && format.height != -1 + if (format.width > 0 && format.height > 0 && format.width * format.height > maxVideoPixelsToRetain) { selectedIndexList.remove(i); } @@ -150,7 +150,7 @@ public final class VideoFormatSelectorUtil { // Filtering format because it's HD. return false; } - if (format.width != -1 && format.height != -1) { + if (format.width > 0 && format.height > 0) { // TODO: Use MediaCodecUtil.isSizeAndRateSupportedV21 on API levels >= 21 if we know the // mimeType of the media samples within the container. Remove the assumption that we're // dealing with H.264. diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsParserUtil.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsParserUtil.java index 7e5dd64367..2ddfdd081b 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsParserUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsParserUtil.java @@ -51,7 +51,7 @@ import java.util.regex.Pattern; public static String parseOptionalStringAttr(String line, Pattern pattern) { Matcher matcher = pattern.matcher(line); - if (matcher.find() && matcher.groupCount() == 1) { + if (matcher.find()) { return matcher.group(1); } return null; @@ -59,7 +59,7 @@ import java.util.regex.Pattern; public static boolean parseOptionalBooleanAttr(String line, Pattern pattern) { Matcher matcher = pattern.matcher(line); - if (matcher.find() && matcher.groupCount() == 1) { + if (matcher.find()) { return BOOLEAN_YES.equals(matcher.group(1)); } return false; diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java index 316f41a44d..4d0b163cb0 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java @@ -72,7 +72,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser private static final Pattern CODECS_ATTR_REGEX = Pattern.compile(CODECS_ATTR + "=\"(.+?)\""); private static final Pattern RESOLUTION_ATTR_REGEX = - Pattern.compile(RESOLUTION_ATTR + "=(\\d+x\\d+)"); + Pattern.compile(RESOLUTION_ATTR + "=(\\d+(\\.\\d+)?x\\d+(\\.\\d+)?)"); private static final Pattern MEDIA_DURATION_REGEX = Pattern.compile(MEDIA_DURATION_TAG + ":([\\d.]+),"); private static final Pattern MEDIA_SEQUENCE_REGEX = @@ -168,8 +168,16 @@ public final class HlsPlaylistParser implements UriLoadable.Parser RESOLUTION_ATTR_REGEX); if (resolutionString != null) { String[] widthAndHeight = resolutionString.split("x"); - width = Integer.parseInt(widthAndHeight[0]); - height = Integer.parseInt(widthAndHeight[1]); + width = Math.round(Float.parseFloat(widthAndHeight[0])); + if (width <= 0) { + // Width was invalid. + width = -1; + } + height = Math.round(Float.parseFloat(widthAndHeight[1])); + if (height <= 0) { + // Height was invalid. + height = -1; + } } else { width = -1; height = -1;