From a71e28440d2827d202d206a80d1d9c68ad731dbe Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 24 Aug 2018 02:40:21 -0700 Subject: [PATCH] Add parameter to force disable adaptive track selection. This option is currently not available as a non-null adaptive track selection has to be provided. Adds a parameter "forceHighestSupportedBitrate" which corresponds to the default fixed track selection for audio and video. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=210073675 --- .../trackselection/DefaultTrackSelector.java | 33 +++++++++++++++++-- .../DefaultTrackSelectorTest.java | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java index 87c4a50fd5..fbdbb8d95f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java @@ -168,6 +168,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { private boolean selectUndeterminedTextLanguage; private int disabledTextTrackSelectionFlags; private boolean forceLowestBitrate; + private boolean forceHighestSupportedBitrate; private boolean allowMixedMimeAdaptiveness; private boolean allowNonSeamlessAdaptiveness; private int maxVideoWidth; @@ -197,6 +198,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { selectUndeterminedTextLanguage = initialValues.selectUndeterminedTextLanguage; disabledTextTrackSelectionFlags = initialValues.disabledTextTrackSelectionFlags; forceLowestBitrate = initialValues.forceLowestBitrate; + forceHighestSupportedBitrate = initialValues.forceHighestSupportedBitrate; allowMixedMimeAdaptiveness = initialValues.allowMixedMimeAdaptiveness; allowNonSeamlessAdaptiveness = initialValues.allowNonSeamlessAdaptiveness; maxVideoWidth = initialValues.maxVideoWidth; @@ -262,6 +264,16 @@ public class DefaultTrackSelector extends MappingTrackSelector { return this; } + /** + * See {@link Parameters#forceHighestSupportedBitrate}. + * + * @return This builder. + */ + public ParametersBuilder setForceHighestSupportedBitrate(boolean forceHighestSupportedBitrate) { + this.forceHighestSupportedBitrate = forceHighestSupportedBitrate; + return this; + } + /** * See {@link Parameters#allowMixedMimeAdaptiveness}. * @@ -520,6 +532,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { selectUndeterminedTextLanguage, disabledTextTrackSelectionFlags, forceLowestBitrate, + forceHighestSupportedBitrate, allowMixedMimeAdaptiveness, allowNonSeamlessAdaptiveness, maxVideoWidth, @@ -634,6 +647,11 @@ public class DefaultTrackSelector extends MappingTrackSelector { * with all other constraints. The default value is {@code false}. */ public final boolean forceLowestBitrate; + /** + * Whether to force selection of the highest bitrate audio and video tracks that comply with all + * other constraints. The default value is {@code false}. + */ + public final boolean forceHighestSupportedBitrate; /** * Whether to allow adaptive selections containing mixed mime types. The default value is {@code * false}. @@ -670,6 +688,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { /* selectUndeterminedTextLanguage= */ false, /* disabledTextTrackSelectionFlags= */ 0, /* forceLowestBitrate= */ false, + /* forceHighestSupportedBitrate= */ false, /* allowMixedMimeAdaptiveness= */ false, /* allowNonSeamlessAdaptiveness= */ true, /* maxVideoWidth= */ Integer.MAX_VALUE, @@ -691,6 +710,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { boolean selectUndeterminedTextLanguage, int disabledTextTrackSelectionFlags, boolean forceLowestBitrate, + boolean forceHighestSupportedBitrate, boolean allowMixedMimeAdaptiveness, boolean allowNonSeamlessAdaptiveness, int maxVideoWidth, @@ -709,6 +729,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { this.selectUndeterminedTextLanguage = selectUndeterminedTextLanguage; this.disabledTextTrackSelectionFlags = disabledTextTrackSelectionFlags; this.forceLowestBitrate = forceLowestBitrate; + this.forceHighestSupportedBitrate = forceHighestSupportedBitrate; this.allowMixedMimeAdaptiveness = allowMixedMimeAdaptiveness; this.allowNonSeamlessAdaptiveness = allowNonSeamlessAdaptiveness; this.maxVideoWidth = maxVideoWidth; @@ -730,6 +751,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { this.selectUndeterminedTextLanguage = Util.readBoolean(in); this.disabledTextTrackSelectionFlags = in.readInt(); this.forceLowestBitrate = Util.readBoolean(in); + this.forceHighestSupportedBitrate = Util.readBoolean(in); this.allowMixedMimeAdaptiveness = Util.readBoolean(in); this.allowNonSeamlessAdaptiveness = Util.readBoolean(in); this.maxVideoWidth = in.readInt(); @@ -797,6 +819,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { return selectUndeterminedTextLanguage == other.selectUndeterminedTextLanguage && disabledTextTrackSelectionFlags == other.disabledTextTrackSelectionFlags && forceLowestBitrate == other.forceLowestBitrate + && forceHighestSupportedBitrate == other.forceHighestSupportedBitrate && allowMixedMimeAdaptiveness == other.allowMixedMimeAdaptiveness && allowNonSeamlessAdaptiveness == other.allowNonSeamlessAdaptiveness && maxVideoWidth == other.maxVideoWidth @@ -819,6 +842,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { int result = selectUndeterminedTextLanguage ? 1 : 0; result = 31 * result + disabledTextTrackSelectionFlags; result = 31 * result + (forceLowestBitrate ? 1 : 0); + result = 31 * result + (forceHighestSupportedBitrate ? 1 : 0); result = 31 * result + (allowMixedMimeAdaptiveness ? 1 : 0); result = 31 * result + (allowNonSeamlessAdaptiveness ? 1 : 0); result = 31 * result + maxVideoWidth; @@ -852,6 +876,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { Util.writeBoolean(dest, selectUndeterminedTextLanguage); dest.writeInt(disabledTextTrackSelectionFlags); Util.writeBoolean(dest, forceLowestBitrate); + Util.writeBoolean(dest, forceHighestSupportedBitrate); Util.writeBoolean(dest, allowMixedMimeAdaptiveness); Util.writeBoolean(dest, allowNonSeamlessAdaptiveness); dest.writeInt(maxVideoWidth); @@ -1355,7 +1380,9 @@ public class DefaultTrackSelector extends MappingTrackSelector { @Nullable TrackSelection.Factory adaptiveTrackSelectionFactory) throws ExoPlaybackException { TrackSelection selection = null; - if (!params.forceLowestBitrate && adaptiveTrackSelectionFactory != null) { + if (!params.forceHighestSupportedBitrate + && !params.forceLowestBitrate + && adaptiveTrackSelectionFactory != null) { selection = selectAdaptiveVideoTrack( groups, @@ -1606,7 +1633,9 @@ public class DefaultTrackSelector extends MappingTrackSelector { } TrackGroup selectedGroup = groups.get(selectedGroupIndex); - if (!params.forceLowestBitrate && adaptiveTrackSelectionFactory != null) { + if (!params.forceHighestSupportedBitrate + && !params.forceLowestBitrate + && adaptiveTrackSelectionFactory != null) { // If the group of the track with the highest score allows it, try to enable adaptation. int[] adaptiveTracks = getAdaptiveAudioTracks( diff --git a/library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java b/library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java index 13314dccf0..86d810989f 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java @@ -147,6 +147,7 @@ public final class DefaultTrackSelectorTest { /* selectUndeterminedTextLanguage= */ false, /* disabledTextTrackSelectionFlags= */ 0, /* forceLowestBitrate= */ true, + /* forceHighestSupportedBitrate= */ true, /* allowMixedMimeAdaptiveness= */ false, /* allowNonSeamlessAdaptiveness= */ true, /* maxVideoWidth= */ 1,