Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9432 : Added filtering for forced text tracks #10003

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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 @@ -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,11 +1881,7 @@ 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();
}
Expand Down