Commit 7eb01e21 by olly Committed by Ian Baker

Move TrackGroupArray back to ExoPlayer

PiperOrigin-RevId: 435325454
parent ef9076c1
...@@ -41,8 +41,8 @@ public final class TracksInfo implements Bundleable { ...@@ -41,8 +41,8 @@ public final class TracksInfo implements Bundleable {
/** /**
* Information about a single group of tracks, including the underlying {@link TrackGroup}, the * Information about a single group of tracks, including the underlying {@link TrackGroup}, the
* {@link C.TrackType type} of tracks it contains, and the level to which each track is supported * level to which each track is supported by the player, and whether any of the tracks are
* by the player. * selected.
*/ */
public static final class TrackGroupInfo implements Bundleable { public static final class TrackGroupInfo implements Bundleable {
...@@ -55,25 +55,25 @@ public final class TracksInfo implements Bundleable { ...@@ -55,25 +55,25 @@ public final class TracksInfo implements Bundleable {
private final boolean[] trackSelected; private final boolean[] trackSelected;
/** /**
* Constructs a TrackGroupInfo. * Constructs an instance.
* *
* @param trackGroup The {@link TrackGroup} described. * @param trackGroup The underlying {@link TrackGroup}.
* @param adaptiveSupported Whether adaptive selections containing more than one track in the * @param adaptiveSupported Whether the player supports adaptive selections containing more than
* {@code trackGroup} are supported. * one track in the group.
* @param trackSupport The {@link C.FormatSupport} of each track in the {@code trackGroup}. * @param trackSupport The {@link C.FormatSupport} of each track in the group.
* @param tracksSelected Whether each track in the {@code trackGroup} is selected. * @param trackSelected Whether each track in the {@code trackGroup} is selected.
*/ */
public TrackGroupInfo( public TrackGroupInfo(
TrackGroup trackGroup, TrackGroup trackGroup,
boolean adaptiveSupported, boolean adaptiveSupported,
@C.FormatSupport int[] trackSupport, @C.FormatSupport int[] trackSupport,
boolean[] tracksSelected) { boolean[] trackSelected) {
length = trackGroup.length; length = trackGroup.length;
checkArgument(length == trackSupport.length && length == tracksSelected.length); checkArgument(length == trackSupport.length && length == trackSelected.length);
this.trackGroup = trackGroup; this.trackGroup = trackGroup;
this.adaptiveSupported = adaptiveSupported && length > 1; this.adaptiveSupported = adaptiveSupported && length > 1;
this.trackSupport = trackSupport.clone(); this.trackSupport = trackSupport.clone();
this.trackSelected = tracksSelected.clone(); this.trackSelected = trackSelected.clone();
} }
/** Returns the underlying {@link TrackGroup}. */ /** Returns the underlying {@link TrackGroup}. */
...@@ -263,11 +263,11 @@ public final class TracksInfo implements Bundleable { ...@@ -263,11 +263,11 @@ public final class TracksInfo implements Bundleable {
} }
} }
private final ImmutableList<TrackGroupInfo> trackGroupInfos;
/** An {@code TrackInfo} that contains no tracks. */ /** An {@code TrackInfo} that contains no tracks. */
public static final TracksInfo EMPTY = new TracksInfo(ImmutableList.of()); public static final TracksInfo EMPTY = new TracksInfo(ImmutableList.of());
private final ImmutableList<TrackGroupInfo> trackGroupInfos;
/** /**
* Constructs an instance. * Constructs an instance.
* *
......
...@@ -37,7 +37,21 @@ import java.lang.annotation.Target; ...@@ -37,7 +37,21 @@ import java.lang.annotation.Target;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/** Defines an immutable group of tracks identified by their format identity. */ /**
* An immutable group of tracks. All tracks in a group present the same content, but their formats
* may differ.
*
* <p>As an example of how tracks can be grouped, consider an adaptive playback where a main video
* feed is provided in five resolutions, and an alternative video feed (e.g., a different camera
* angle in a sports match) is provided in two resolutions. In this case there will be two video
* track groups, one corresponding to the main video feed containing five tracks, and a second for
* the alternative video feed containing two tracks.
*
* <p>Note that audio tracks whose languages differ are not grouped, because content in different
* languages is not considered to be the same. Conversely, audio tracks in the same language that
* only differ in properties such as bitrate, sampling rate, channel count and so on can be grouped.
* This also applies to text tracks.
*/
public final class TrackGroup implements Bundleable { public final class TrackGroup implements Bundleable {
private static final String TAG = "TrackGroup"; private static final String TAG = "TrackGroup";
......
...@@ -33,16 +33,21 @@ import java.lang.annotation.RetentionPolicy; ...@@ -33,16 +33,21 @@ import java.lang.annotation.RetentionPolicy;
import java.util.List; import java.util.List;
/** /**
* Forces the selection of {@link #trackIndices} for a {@link TrackGroup}. * A track selection override, consisting of a {@link TrackGroup} and the indices of the tracks
* within the group that should be selected.
* *
* <p>If multiple tracks in {@link #trackGroup} are overridden, as many as possible will be selected * <p>A track selection override is applied during playback if the media being played contains a
* depending on the player capabilities. * {@link TrackGroup} equal to the one in the override. If a {@link TrackSelectionParameters}
* contains only one override of a given track type that applies to the media, this override will be
* used to control the track selection for that type. If multiple overrides of a given track type
* apply then the player will apply only one of them.
* *
* <p>If {@link #trackIndices} is empty, no tracks from {@link #trackGroup} will be played. This is * <p>If {@link #trackIndices} is empty then the override specifies that no tracks should be
* similar to {@link TrackSelectionParameters#disabledTrackTypes}, except it will only affect the * selected. Adding an empty override to a {@link TrackSelectionParameters} is similar to {@link
* playback of the associated {@link TrackGroup}. For example, if the only {@link * TrackSelectionParameters.Builder#setTrackTypeDisabled disabling a track type}, except that an
* C#TRACK_TYPE_VIDEO} {@link TrackGroup} is associated with no tracks, no video will play until the * empty override will only be applied if the media being played contains a {@link TrackGroup} equal
* next video starts. * to the one in the override. Conversely, disabling a track type will prevent selection of tracks
* of that type for all media.
*/ */
public final class TrackSelectionOverride implements Bundleable { public final class TrackSelectionOverride implements Bundleable {
......
...@@ -49,10 +49,11 @@ import org.checkerframework.checker.initialization.qual.UnknownInitialization; ...@@ -49,10 +49,11 @@ import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
/** /**
* Constraint parameters for track selection. * Parameters for controlling track selection.
* *
* <p>For example the following code modifies the parameters to restrict video track selections to * <p>Parameters can be queried and set on a {@link Player}. For example the following code modifies
* SD, and to select a German audio track if there is one: * the parameters to restrict video track selections to SD, and to select a German audio track if
* there is one:
* *
* <pre>{@code * <pre>{@code
* // Build on the current parameters. * // Build on the current parameters.
...@@ -654,28 +655,26 @@ public class TrackSelectionParameters implements Bundleable { ...@@ -654,28 +655,26 @@ public class TrackSelectionParameters implements Bundleable {
return this; return this;
} }
/** Adds an override for the provided {@link TrackGroup}. */ /** Adds an override, replacing any override for the same {@link TrackGroup}. */
public Builder addOverride(TrackSelectionOverride override) { public Builder addOverride(TrackSelectionOverride override) {
overrides.put(override.trackGroup, override); overrides.put(override.trackGroup, override);
return this; return this;
} }
/** Removes the override associated with the provided {@link TrackGroup} if present. */ /** Sets an override, replacing all existing overrides with the same track type. */
public Builder clearOverride(TrackGroup trackGroup) {
overrides.remove(trackGroup);
return this;
}
/** Set the override for the type of the provided {@link TrackGroup}. */
public Builder setOverrideForType(TrackSelectionOverride override) { public Builder setOverrideForType(TrackSelectionOverride override) {
clearOverridesOfType(override.getTrackType()); clearOverridesOfType(override.getTrackType());
overrides.put(override.trackGroup, override); overrides.put(override.trackGroup, override);
return this; return this;
} }
/** /** Removes the override for the provided {@link TrackGroup}, if there is one. */
* Remove any override associated with {@link TrackGroup TrackGroups} of type {@code trackType}. public Builder clearOverride(TrackGroup trackGroup) {
*/ overrides.remove(trackGroup);
return this;
}
/** Removes all overrides of the provided track type. */
public Builder clearOverridesOfType(@C.TrackType int trackType) { public Builder clearOverridesOfType(@C.TrackType int trackType) {
Iterator<TrackSelectionOverride> it = overrides.values().iterator(); Iterator<TrackSelectionOverride> it = overrides.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
...@@ -687,7 +686,7 @@ public class TrackSelectionParameters implements Bundleable { ...@@ -687,7 +686,7 @@ public class TrackSelectionParameters implements Bundleable {
return this; return this;
} }
/** Removes all track overrides. */ /** Removes all overrides. */
public Builder clearOverrides() { public Builder clearOverrides() {
overrides.clear(); overrides.clear();
return this; return this;
......
...@@ -152,7 +152,7 @@ public final class MetadataRetriever { ...@@ -152,7 +152,7 @@ public final class MetadataRetriever {
mediaPeriod.maybeThrowPrepareError(); mediaPeriod.maybeThrowPrepareError();
} }
mediaSourceHandler.sendEmptyMessageDelayed( mediaSourceHandler.sendEmptyMessageDelayed(
MESSAGE_CHECK_FOR_FAILURE, /* delayMillis= */ ERROR_POLL_INTERVAL_MS); MESSAGE_CHECK_FOR_FAILURE, /* delayMs= */ ERROR_POLL_INTERVAL_MS);
} catch (Exception e) { } catch (Exception e) {
trackGroupsFuture.setException(e); trackGroupsFuture.setException(e);
mediaSourceHandler.obtainMessage(MESSAGE_RELEASE).sendToTarget(); mediaSourceHandler.obtainMessage(MESSAGE_RELEASE).sendToTarget();
......
...@@ -31,7 +31,16 @@ import java.lang.annotation.RetentionPolicy; ...@@ -31,7 +31,16 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.List; import java.util.List;
/** An immutable array of {@link TrackGroup}s. */ /**
* An immutable array of {@link TrackGroup}s.
*
* <p>This class is typically used to represent all of the tracks available in a piece of media.
* Tracks that are known to present the same content are grouped together (e.g., the same video feed
* provided at different resolutions in an adaptive stream). Tracks that are known to present
* different content are in separate track groups (e.g., an audio track will not be in the same
* group as a video track, and an audio track in one language will be in a different group to an
* audio track in another language).
*/
public final class TrackGroupArray implements Bundleable { public final class TrackGroupArray implements Bundleable {
private static final String TAG = "TrackGroupArray"; private static final String TAG = "TrackGroupArray";
......
...@@ -82,11 +82,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -82,11 +82,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
* .setMaxVideoSizeSd() * .setMaxVideoSizeSd()
* .setPreferredAudioLanguage("de") * .setPreferredAudioLanguage("de")
* .build()); * .build());
*
* }</pre> * }</pre>
* *
* Some specialized parameters are only available in the extended {@link Parameters} class, which * Some specialized parameters are only available in the extended {@link Parameters} class, which
* can be retrieved and modified in a similar way in this track selector: * can be retrieved and modified in a similar way by calling methods directly on this class:
* *
* <pre>{@code * <pre>{@code
* defaultTrackSelector.setParameters( * defaultTrackSelector.setParameters(
...@@ -94,7 +93,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -94,7 +93,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
* .buildUpon() * .buildUpon()
* .setTunnelingEnabled(true) * .setTunnelingEnabled(true)
* .build()); * .build());
*
* }</pre> * }</pre>
*/ */
public class DefaultTrackSelector extends MappingTrackSelector { public class DefaultTrackSelector extends MappingTrackSelector {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment