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
This commit is contained in:
tonihei 2018-08-24 02:40:21 -07:00 committed by Oliver Woodman
parent 9c36773602
commit a71e28440d
2 changed files with 32 additions and 2 deletions

View File

@ -168,6 +168,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private boolean selectUndeterminedTextLanguage; private boolean selectUndeterminedTextLanguage;
private int disabledTextTrackSelectionFlags; private int disabledTextTrackSelectionFlags;
private boolean forceLowestBitrate; private boolean forceLowestBitrate;
private boolean forceHighestSupportedBitrate;
private boolean allowMixedMimeAdaptiveness; private boolean allowMixedMimeAdaptiveness;
private boolean allowNonSeamlessAdaptiveness; private boolean allowNonSeamlessAdaptiveness;
private int maxVideoWidth; private int maxVideoWidth;
@ -197,6 +198,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
selectUndeterminedTextLanguage = initialValues.selectUndeterminedTextLanguage; selectUndeterminedTextLanguage = initialValues.selectUndeterminedTextLanguage;
disabledTextTrackSelectionFlags = initialValues.disabledTextTrackSelectionFlags; disabledTextTrackSelectionFlags = initialValues.disabledTextTrackSelectionFlags;
forceLowestBitrate = initialValues.forceLowestBitrate; forceLowestBitrate = initialValues.forceLowestBitrate;
forceHighestSupportedBitrate = initialValues.forceHighestSupportedBitrate;
allowMixedMimeAdaptiveness = initialValues.allowMixedMimeAdaptiveness; allowMixedMimeAdaptiveness = initialValues.allowMixedMimeAdaptiveness;
allowNonSeamlessAdaptiveness = initialValues.allowNonSeamlessAdaptiveness; allowNonSeamlessAdaptiveness = initialValues.allowNonSeamlessAdaptiveness;
maxVideoWidth = initialValues.maxVideoWidth; maxVideoWidth = initialValues.maxVideoWidth;
@ -262,6 +264,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
return this; return this;
} }
/**
* See {@link Parameters#forceHighestSupportedBitrate}.
*
* @return This builder.
*/
public ParametersBuilder setForceHighestSupportedBitrate(boolean forceHighestSupportedBitrate) {
this.forceHighestSupportedBitrate = forceHighestSupportedBitrate;
return this;
}
/** /**
* See {@link Parameters#allowMixedMimeAdaptiveness}. * See {@link Parameters#allowMixedMimeAdaptiveness}.
* *
@ -520,6 +532,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
selectUndeterminedTextLanguage, selectUndeterminedTextLanguage,
disabledTextTrackSelectionFlags, disabledTextTrackSelectionFlags,
forceLowestBitrate, forceLowestBitrate,
forceHighestSupportedBitrate,
allowMixedMimeAdaptiveness, allowMixedMimeAdaptiveness,
allowNonSeamlessAdaptiveness, allowNonSeamlessAdaptiveness,
maxVideoWidth, maxVideoWidth,
@ -634,6 +647,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
* with all other constraints. The default value is {@code false}. * with all other constraints. The default value is {@code false}.
*/ */
public final boolean forceLowestBitrate; 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 * Whether to allow adaptive selections containing mixed mime types. The default value is {@code
* false}. * false}.
@ -670,6 +688,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
/* selectUndeterminedTextLanguage= */ false, /* selectUndeterminedTextLanguage= */ false,
/* disabledTextTrackSelectionFlags= */ 0, /* disabledTextTrackSelectionFlags= */ 0,
/* forceLowestBitrate= */ false, /* forceLowestBitrate= */ false,
/* forceHighestSupportedBitrate= */ false,
/* allowMixedMimeAdaptiveness= */ false, /* allowMixedMimeAdaptiveness= */ false,
/* allowNonSeamlessAdaptiveness= */ true, /* allowNonSeamlessAdaptiveness= */ true,
/* maxVideoWidth= */ Integer.MAX_VALUE, /* maxVideoWidth= */ Integer.MAX_VALUE,
@ -691,6 +710,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
boolean selectUndeterminedTextLanguage, boolean selectUndeterminedTextLanguage,
int disabledTextTrackSelectionFlags, int disabledTextTrackSelectionFlags,
boolean forceLowestBitrate, boolean forceLowestBitrate,
boolean forceHighestSupportedBitrate,
boolean allowMixedMimeAdaptiveness, boolean allowMixedMimeAdaptiveness,
boolean allowNonSeamlessAdaptiveness, boolean allowNonSeamlessAdaptiveness,
int maxVideoWidth, int maxVideoWidth,
@ -709,6 +729,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
this.selectUndeterminedTextLanguage = selectUndeterminedTextLanguage; this.selectUndeterminedTextLanguage = selectUndeterminedTextLanguage;
this.disabledTextTrackSelectionFlags = disabledTextTrackSelectionFlags; this.disabledTextTrackSelectionFlags = disabledTextTrackSelectionFlags;
this.forceLowestBitrate = forceLowestBitrate; this.forceLowestBitrate = forceLowestBitrate;
this.forceHighestSupportedBitrate = forceHighestSupportedBitrate;
this.allowMixedMimeAdaptiveness = allowMixedMimeAdaptiveness; this.allowMixedMimeAdaptiveness = allowMixedMimeAdaptiveness;
this.allowNonSeamlessAdaptiveness = allowNonSeamlessAdaptiveness; this.allowNonSeamlessAdaptiveness = allowNonSeamlessAdaptiveness;
this.maxVideoWidth = maxVideoWidth; this.maxVideoWidth = maxVideoWidth;
@ -730,6 +751,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
this.selectUndeterminedTextLanguage = Util.readBoolean(in); this.selectUndeterminedTextLanguage = Util.readBoolean(in);
this.disabledTextTrackSelectionFlags = in.readInt(); this.disabledTextTrackSelectionFlags = in.readInt();
this.forceLowestBitrate = Util.readBoolean(in); this.forceLowestBitrate = Util.readBoolean(in);
this.forceHighestSupportedBitrate = Util.readBoolean(in);
this.allowMixedMimeAdaptiveness = Util.readBoolean(in); this.allowMixedMimeAdaptiveness = Util.readBoolean(in);
this.allowNonSeamlessAdaptiveness = Util.readBoolean(in); this.allowNonSeamlessAdaptiveness = Util.readBoolean(in);
this.maxVideoWidth = in.readInt(); this.maxVideoWidth = in.readInt();
@ -797,6 +819,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
return selectUndeterminedTextLanguage == other.selectUndeterminedTextLanguage return selectUndeterminedTextLanguage == other.selectUndeterminedTextLanguage
&& disabledTextTrackSelectionFlags == other.disabledTextTrackSelectionFlags && disabledTextTrackSelectionFlags == other.disabledTextTrackSelectionFlags
&& forceLowestBitrate == other.forceLowestBitrate && forceLowestBitrate == other.forceLowestBitrate
&& forceHighestSupportedBitrate == other.forceHighestSupportedBitrate
&& allowMixedMimeAdaptiveness == other.allowMixedMimeAdaptiveness && allowMixedMimeAdaptiveness == other.allowMixedMimeAdaptiveness
&& allowNonSeamlessAdaptiveness == other.allowNonSeamlessAdaptiveness && allowNonSeamlessAdaptiveness == other.allowNonSeamlessAdaptiveness
&& maxVideoWidth == other.maxVideoWidth && maxVideoWidth == other.maxVideoWidth
@ -819,6 +842,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
int result = selectUndeterminedTextLanguage ? 1 : 0; int result = selectUndeterminedTextLanguage ? 1 : 0;
result = 31 * result + disabledTextTrackSelectionFlags; result = 31 * result + disabledTextTrackSelectionFlags;
result = 31 * result + (forceLowestBitrate ? 1 : 0); result = 31 * result + (forceLowestBitrate ? 1 : 0);
result = 31 * result + (forceHighestSupportedBitrate ? 1 : 0);
result = 31 * result + (allowMixedMimeAdaptiveness ? 1 : 0); result = 31 * result + (allowMixedMimeAdaptiveness ? 1 : 0);
result = 31 * result + (allowNonSeamlessAdaptiveness ? 1 : 0); result = 31 * result + (allowNonSeamlessAdaptiveness ? 1 : 0);
result = 31 * result + maxVideoWidth; result = 31 * result + maxVideoWidth;
@ -852,6 +876,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
Util.writeBoolean(dest, selectUndeterminedTextLanguage); Util.writeBoolean(dest, selectUndeterminedTextLanguage);
dest.writeInt(disabledTextTrackSelectionFlags); dest.writeInt(disabledTextTrackSelectionFlags);
Util.writeBoolean(dest, forceLowestBitrate); Util.writeBoolean(dest, forceLowestBitrate);
Util.writeBoolean(dest, forceHighestSupportedBitrate);
Util.writeBoolean(dest, allowMixedMimeAdaptiveness); Util.writeBoolean(dest, allowMixedMimeAdaptiveness);
Util.writeBoolean(dest, allowNonSeamlessAdaptiveness); Util.writeBoolean(dest, allowNonSeamlessAdaptiveness);
dest.writeInt(maxVideoWidth); dest.writeInt(maxVideoWidth);
@ -1355,7 +1380,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
@Nullable TrackSelection.Factory adaptiveTrackSelectionFactory) @Nullable TrackSelection.Factory adaptiveTrackSelectionFactory)
throws ExoPlaybackException { throws ExoPlaybackException {
TrackSelection selection = null; TrackSelection selection = null;
if (!params.forceLowestBitrate && adaptiveTrackSelectionFactory != null) { if (!params.forceHighestSupportedBitrate
&& !params.forceLowestBitrate
&& adaptiveTrackSelectionFactory != null) {
selection = selection =
selectAdaptiveVideoTrack( selectAdaptiveVideoTrack(
groups, groups,
@ -1606,7 +1633,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
} }
TrackGroup selectedGroup = groups.get(selectedGroupIndex); 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. // If the group of the track with the highest score allows it, try to enable adaptation.
int[] adaptiveTracks = int[] adaptiveTracks =
getAdaptiveAudioTracks( getAdaptiveAudioTracks(

View File

@ -147,6 +147,7 @@ public final class DefaultTrackSelectorTest {
/* selectUndeterminedTextLanguage= */ false, /* selectUndeterminedTextLanguage= */ false,
/* disabledTextTrackSelectionFlags= */ 0, /* disabledTextTrackSelectionFlags= */ 0,
/* forceLowestBitrate= */ true, /* forceLowestBitrate= */ true,
/* forceHighestSupportedBitrate= */ true,
/* allowMixedMimeAdaptiveness= */ false, /* allowMixedMimeAdaptiveness= */ false,
/* allowNonSeamlessAdaptiveness= */ true, /* allowNonSeamlessAdaptiveness= */ true,
/* maxVideoWidth= */ 1, /* maxVideoWidth= */ 1,