Allow video format filtering without viewport constraint.

This commit is contained in:
Oliver Woodman 2015-11-17 16:06:43 +00:00
parent 80e829d7d1
commit e65f726458

View File

@ -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);
}
}
}