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 Feb 23, 2022
1 parent 25e58f5 commit 1d41854
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
Expand Up @@ -97,6 +97,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 @@ -129,6 +130,7 @@ public Builder() {
preferredTextLanguages = ImmutableList.of();
preferredTextRoleFlags = 0;
selectUndeterminedTextLanguage = false;
disabledTextTrackSelectionFlags= 0;
// General
forceLowestBitrate = false;
forceHighestSupportedBitrate = false;
Expand All @@ -146,11 +148,13 @@ public Builder(Context context) {
this();
setPreferredTextLanguageAndRoleFlagsToCaptioningManagerSettings(context);
setViewportSizeToPhysicalDisplaySize(context, /* viewportOrientationMayChange= */ true);
disabledTextTrackSelectionFlags = 0;
}

/** Creates a builder with the initial values specified in {@code initialValues}. */
protected Builder(TrackSelectionParameters initialValues) {
init(initialValues);
disabledTextTrackSelectionFlags = 0;
}

/** Creates a builder with the initial values specified in {@code bundle}. */
Expand Down Expand Up @@ -230,6 +234,10 @@ protected Builder(Bundle bundle) {
bundle.getBoolean(
keyForField(FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE),
DEFAULT_WITHOUT_CONTEXT.selectUndeterminedTextLanguage);
setDisabledTextTrackSelectionFlags(
bundle.getInt(
keyForField(FIELD_DISABLED_TEXT_TRACK_SELECTION_FLAGS),
DEFAULT_WITHOUT_CONTEXT.disabledTextTrackSelectionFlags));
// General
forceLowestBitrate =
bundle.getBoolean(
Expand All @@ -253,6 +261,7 @@ protected Builder(Bundle bundle) {
Ints.asList(
firstNonNull(
bundle.getIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE)), new int[0])));
disabledTextTrackSelectionFlags = 0;
}

/** Overrides the value of the builder with the value of {@link TrackSelectionParameters}. */
Expand Down Expand Up @@ -735,6 +744,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 @@ -902,6 +917,12 @@ public static TrackSelectionParameters getDefaults(Context context) {
*/
public final ImmutableSet<@C.TrackType Integer> disabledTrackTypes;

/**
* The track selectionFlags bitmaps that are disabled. No track of a disabled type 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 @@ -932,6 +953,7 @@ protected TrackSelectionParameters(Builder builder) {
this.forceHighestSupportedBitrate = builder.forceHighestSupportedBitrate;
this.overrides = ImmutableMap.copyOf(builder.overrides);
this.disabledTrackTypes = builder.disabledTrackTypes;
this.disabledTextTrackSelectionFlags = 0;
}

/** Creates a new {@link Builder}, copying the initial values from this instance. */
Expand Down Expand Up @@ -1043,7 +1065,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 @@ -1072,6 +1095,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 @@ -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 @@ -1133,8 +1135,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 @@ -1873,17 +1881,18 @@ public void onBindViewHolderAtZeroPosition(SubSettingViewHolder holder) {
player.setTrackSelectionParameters(
trackSelectionParameters
.buildUpon()
.setDisabledTrackTypes(
new ImmutableSet.Builder<@C.TrackType Integer>()
.addAll(trackSelectionParameters.disabledTrackTypes)
.add(C.TRACK_TYPE_TEXT)
.build())
.setDisabledTextTrackSelectionFlags(~C.SELECTION_FLAG_FORCED)
.build());
settingsWindow.dismiss();
}
});
}

/*
trackSelectionParameters.buildUpon().
setDisabledTextTrackSelectionFlags(0)).build()
*/

@Override
public void onBindViewHolder(SubSettingViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
Expand Down

0 comments on commit 1d41854

Please sign in to comment.