From e65f7264583d3ccc49143b6e442381a4ead91261 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Tue, 17 Nov 2015 16:06:43 +0000 Subject: [PATCH] Allow video format filtering without viewport constraint. --- .../chunk/VideoFormatSelectorUtil.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 92d4da5ad5..3b56746c41 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 @@ -82,10 +82,10 @@ public final class VideoFormatSelectorUtil { * viewport during playback. * @param viewportWidth The width in pixels of the viewport within which the video will be * displayed. If the viewport size may change, this should be set to the maximum possible - * width. + * width. -1 if selection should not be constrained by a viewport. * @param viewportHeight The height in pixels of the viewport within which the video will be * displayed. If the viewport size may change, this should be set to the maximum possible - * height. + * height. -1 if selection should not be constrained by a viewport. * @return An array holding the indices of the selected formats. * @throws DecoderQueryException */ @@ -107,7 +107,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 > 0 && format.height > 0) { + if (format.width > 0 && format.height > 0 && viewportWidth > 0 && viewportHeight > 0) { Point maxVideoSizeInViewport = getMaxVideoSizeInViewport(orientationMayChange, viewportWidth, viewportHeight, format.width, format.height); int videoPixels = format.width * format.height; @@ -123,11 +123,13 @@ public final class VideoFormatSelectorUtil { // Second pass to filter out formats that exceed maxVideoPixelsToRetain. These formats are have // unnecessarily high resolution given the size at which the video will be displayed within the // viewport. - for (int i = selectedIndexList.size() - 1; i >= 0; i--) { - Format format = formatWrappers.get(selectedIndexList.get(i)).getFormat(); - if (format.width > 0 && format.height > 0 - && format.width * format.height > maxVideoPixelsToRetain) { - selectedIndexList.remove(i); + if (maxVideoPixelsToRetain != Integer.MAX_VALUE) { + for (int i = selectedIndexList.size() - 1; i >= 0; i--) { + Format format = formatWrappers.get(selectedIndexList.get(i)).getFormat(); + if (format.width > 0 && format.height > 0 + && format.width * format.height > maxVideoPixelsToRetain) { + selectedIndexList.remove(i); + } } }