Skip to content

Commit

Permalink
9432 : Added support for filtering forced text tracks
Browse files Browse the repository at this point in the history
1. Added filtering for forced text tracks.
2. Support for disabling all other tracks other than forced track when None is selected.
  • Loading branch information
LuGO0 committed Mar 11, 2022
1 parent b31cd08 commit f46d549
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
Expand Up @@ -98,6 +98,7 @@ public static class Builder {
private ImmutableList<String> preferredTextLanguages;
private @C.RoleFlags int preferredTextRoleFlags;
private boolean selectUndeterminedTextLanguage;
private @C.SelectionFlags int disabledTextTrackSelectionFlags;
// General
private boolean forceLowestBitrate;
private boolean forceHighestSupportedBitrate;
Expand Down Expand Up @@ -130,6 +131,7 @@ public Builder() {
preferredTextLanguages = ImmutableList.of();
preferredTextRoleFlags = 0;
selectUndeterminedTextLanguage = false;
disabledTextTrackSelectionFlags = 0;
// General
forceLowestBitrate = false;
forceHighestSupportedBitrate = false;
Expand Down Expand Up @@ -231,6 +233,10 @@ protected Builder(Bundle bundle) {
bundle.getBoolean(
keyForField(FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE),
DEFAULT_WITHOUT_CONTEXT.selectUndeterminedTextLanguage);
disabledTextTrackSelectionFlags = bundle.getInt(
keyForField(FIELD_DISABLED_TEXT_TRACK_SELECTION_FLAGS),
DEFAULT_WITHOUT_CONTEXT.disabledTextTrackSelectionFlags);

// General
forceLowestBitrate =
bundle.getBoolean(
Expand Down Expand Up @@ -264,7 +270,7 @@ protected Builder(Bundle bundle) {
"preferredAudioMimeTypes",
"preferredTextLanguages",
"overrides",
"disabledTrackTypes",
"disabledTrackTypes"
})
private void init(@UnknownInitialization Builder this, TrackSelectionParameters parameters) {
// Video
Expand Down Expand Up @@ -296,6 +302,7 @@ private void init(@UnknownInitialization Builder this, TrackSelectionParameters
forceHighestSupportedBitrate = parameters.forceHighestSupportedBitrate;
disabledTrackTypes = new HashSet<>(parameters.disabledTrackTypes);
overrides = new HashMap<>(parameters.overrides);
disabledTextTrackSelectionFlags = parameters.disabledTextTrackSelectionFlags;
}

/** Overrides the value of the builder with the value of {@link TrackSelectionParameters}. */
Expand Down Expand Up @@ -757,6 +764,12 @@ private static ImmutableList<String> normalizeLanguageCodes(String[] preferredTe
}
return listBuilder.build();
}

public Builder setDisabledTextTrackSelectionFlags(
@C.SelectionFlags int disabledTextTrackSelectionFlags) {
this.disabledTextTrackSelectionFlags = disabledTextTrackSelectionFlags;
return this;
}
}

/**
Expand Down Expand Up @@ -924,6 +937,12 @@ public static TrackSelectionParameters getDefaults(Context context) {
*/
public final ImmutableSet<@C.TrackType Integer> disabledTrackTypes;

/**
* The track selectionFlags bitmap that are disabled. No track of a disabled selectionFlag will be selected,
* thus no track selectionFlag contained in the bitmap will be played. The default value is that no selectionFlag is disabled(0)
*/
public final @C.SelectionFlags int disabledTextTrackSelectionFlags;

protected TrackSelectionParameters(Builder builder) {
// Video
this.maxVideoWidth = builder.maxVideoWidth;
Expand Down Expand Up @@ -954,6 +973,7 @@ protected TrackSelectionParameters(Builder builder) {
this.forceHighestSupportedBitrate = builder.forceHighestSupportedBitrate;
this.overrides = ImmutableMap.copyOf(builder.overrides);
this.disabledTrackTypes = ImmutableSet.copyOf(builder.disabledTrackTypes);
this.disabledTextTrackSelectionFlags = builder.disabledTextTrackSelectionFlags;
}

/** Creates a new {@link Builder}, copying the initial values from this instance. */
Expand Down Expand Up @@ -998,7 +1018,8 @@ public boolean equals(@Nullable Object obj) {
&& forceLowestBitrate == other.forceLowestBitrate
&& forceHighestSupportedBitrate == other.forceHighestSupportedBitrate
&& overrides.equals(other.overrides)
&& disabledTrackTypes.equals(other.disabledTrackTypes);
&& disabledTrackTypes.equals(other.disabledTrackTypes)
&& disabledTextTrackSelectionFlags == other.disabledTextTrackSelectionFlags;
}

@Override
Expand Down Expand Up @@ -1033,6 +1054,7 @@ public int hashCode() {
result = 31 * result + (forceHighestSupportedBitrate ? 1 : 0);
result = 31 * result + overrides.hashCode();
result = 31 * result + disabledTrackTypes.hashCode();
result = 31 * result + disabledTextTrackSelectionFlags;
return result;
}

Expand Down Expand Up @@ -1065,7 +1087,8 @@ public int hashCode() {
FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE,
FIELD_SELECTION_OVERRIDES,
FIELD_DISABLED_TRACK_TYPE,
FIELD_PREFERRED_VIDEO_ROLE_FLAGS
FIELD_PREFERRED_VIDEO_ROLE_FLAGS,
FIELD_DISABLED_TEXT_TRACK_SELECTION_FLAGS
})
private @interface FieldNumber {}

Expand Down Expand Up @@ -1094,6 +1117,7 @@ public int hashCode() {
private static final int FIELD_SELECTION_OVERRIDES = 23;
private static final int FIELD_DISABLED_TRACK_TYPE = 24;
private static final int FIELD_PREFERRED_VIDEO_ROLE_FLAGS = 25;
private static final int FIELD_DISABLED_TEXT_TRACK_SELECTION_FLAGS = 26;

@Override
public Bundle toBundle() {
Expand Down Expand Up @@ -1139,6 +1163,7 @@ public Bundle toBundle() {
bundle.putParcelableArrayList(
keyForField(FIELD_SELECTION_OVERRIDES), toBundleArrayList(overrides.values()));
bundle.putIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE), Ints.toArray(disabledTrackTypes));
bundle.putInt(keyForField(disabledTextTrackSelectionFlags), disabledTextTrackSelectionFlags);

return bundle;
}
Expand Down
Expand Up @@ -573,6 +573,7 @@ public ParametersBuilder setSelectUndeterminedTextLanguage(
*/
public ParametersBuilder setDisabledTextTrackSelectionFlags(
@C.SelectionFlags int disabledTextTrackSelectionFlags) {
super.setDisabledTextTrackSelectionFlags(disabledTextTrackSelectionFlags);
this.disabledTextTrackSelectionFlags = disabledTextTrackSelectionFlags;
return this;
}
Expand Down
Expand Up @@ -59,6 +59,7 @@
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ForwardingPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.Events;
Expand All @@ -67,6 +68,7 @@
import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.TracksInfo.TrackGroupInfo;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.util.Assertions;
Expand Down Expand Up @@ -1130,8 +1132,14 @@ private ImmutableList<TrackInformation> gatherSupportedTrackInfosOfType(
if (!trackGroupInfo.isTrackSupported(trackIndex)) {
continue;
}
String trackName =
trackNameProvider.getTrackName(trackGroupInfo.getTrackFormat(trackIndex));

Format trackFormat = trackGroupInfo.getTrackFormat(trackIndex);

if (trackFormat.selectionFlags == C.SELECTION_FLAG_FORCED) {
continue;
}

String trackName = trackNameProvider.getTrackName(trackFormat);
tracks.add(new TrackInformation(tracksInfo, trackGroupIndex, trackIndex, trackName));
}
}
Expand Down Expand Up @@ -1867,10 +1875,12 @@ public void onBindViewHolderAtZeroPosition(SubSettingViewHolder holder) {
if (player != null) {
TrackSelectionParameters trackSelectionParameters =
player.getTrackSelectionParameters();

player.setTrackSelectionParameters(
trackSelectionParameters
.buildUpon()
.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, /* disabled= */ true)
.clearOverridesOfType(C.TRACK_TYPE_TEXT)
.setDisabledTextTrackSelectionFlags(~C.SELECTION_FLAG_FORCED)
.build());
settingsWindow.dismiss();
}
Expand Down

0 comments on commit f46d549

Please sign in to comment.