mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Allow to set selection reason and data when specifying an override.
It's currently very difficult to actually set a reason for track selection triggered by a SelectionOverride. It would require creating a new custom TrackSelection.Factory where the reason gets injected somehow before the override is specified on the player. Simplify this whole procedure by allowing to set the reason directly and forward this reason to all fixed selections created based on this override. PiperOrigin-RevId: 240114942
This commit is contained in:
parent
6f9d33dbd3
commit
b0bb6ec8a5
5 changed files with 52 additions and 5 deletions
|
|
@ -22,6 +22,7 @@
|
|||
([#3314](https://github.com/google/ExoPlayer/issues/3314)).
|
||||
* Update `TrackSelection.Factory` interface to support creating all track
|
||||
selections together.
|
||||
* Allow to specify a selection reason for a `SelectionOverride`.
|
||||
* Do not retry failed loads whose error is `FileNotFoundException`.
|
||||
* Support Dolby Vision extraction in MP4 and fMP4.
|
||||
* Offline:
|
||||
|
|
|
|||
|
|
@ -242,7 +242,9 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
createAdaptiveTrackSelection(definition.group, bandwidthMeter, definition.tracks);
|
||||
selections[i] = adaptiveSelection;
|
||||
} else {
|
||||
selections[i] = new FixedTrackSelection(definition.group, definition.tracks[0]);
|
||||
selections[i] =
|
||||
new FixedTrackSelection(
|
||||
definition.group, definition.tracks[0], definition.reason, definition.data);
|
||||
int trackBitrate = definition.group.getFormat(definition.tracks[0]).bitrate;
|
||||
if (trackBitrate != Format.NO_VALUE) {
|
||||
totalFixedBandwidth += trackBitrate;
|
||||
|
|
|
|||
|
|
@ -1173,15 +1173,29 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
public final int groupIndex;
|
||||
public final int[] tracks;
|
||||
public final int length;
|
||||
public final int reason;
|
||||
public final int data;
|
||||
|
||||
/**
|
||||
* @param groupIndex The overriding track group index.
|
||||
* @param tracks The overriding track indices within the track group.
|
||||
*/
|
||||
public SelectionOverride(int groupIndex, int... tracks) {
|
||||
this(groupIndex, tracks, C.SELECTION_REASON_MANUAL, /* data= */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupIndex The overriding track group index.
|
||||
* @param tracks The overriding track indices within the track group.
|
||||
* @param reason The reason for the override. One of the {@link C} SELECTION_REASON_ constants.
|
||||
* @param data Optional data associated with this override.
|
||||
*/
|
||||
public SelectionOverride(int groupIndex, int[] tracks, int reason, int data) {
|
||||
this.groupIndex = groupIndex;
|
||||
this.tracks = Arrays.copyOf(tracks, tracks.length);
|
||||
this.length = tracks.length;
|
||||
this.reason = reason;
|
||||
this.data = data;
|
||||
Arrays.sort(this.tracks);
|
||||
}
|
||||
|
||||
|
|
@ -1190,6 +1204,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
length = in.readByte();
|
||||
tracks = new int[length];
|
||||
in.readIntArray(tracks);
|
||||
reason = in.readInt();
|
||||
data = in.readInt();
|
||||
}
|
||||
|
||||
/** Returns whether this override contains the specified track index. */
|
||||
|
|
@ -1204,7 +1220,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * groupIndex + Arrays.hashCode(tracks);
|
||||
int hash = 31 * groupIndex + Arrays.hashCode(tracks);
|
||||
hash = 31 * hash + reason;
|
||||
return 31 * hash + data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1216,7 +1234,10 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
return false;
|
||||
}
|
||||
SelectionOverride other = (SelectionOverride) obj;
|
||||
return groupIndex == other.groupIndex && Arrays.equals(tracks, other.tracks);
|
||||
return groupIndex == other.groupIndex
|
||||
&& Arrays.equals(tracks, other.tracks)
|
||||
&& reason == other.reason
|
||||
&& data == other.data;
|
||||
}
|
||||
|
||||
// Parcelable implementation.
|
||||
|
|
@ -1231,6 +1252,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
dest.writeInt(groupIndex);
|
||||
dest.writeInt(tracks.length);
|
||||
dest.writeIntArray(tracks);
|
||||
dest.writeInt(reason);
|
||||
dest.writeInt(data);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SelectionOverride> CREATOR =
|
||||
|
|
@ -1405,7 +1428,10 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||
override == null
|
||||
? null
|
||||
: new TrackSelection.Definition(
|
||||
rendererTrackGroups.get(override.groupIndex), override.tracks);
|
||||
rendererTrackGroups.get(override.groupIndex),
|
||||
override.tracks,
|
||||
override.reason,
|
||||
override.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ public interface TrackSelection {
|
|||
public final TrackGroup group;
|
||||
/** The indices of the selected tracks in {@link #group}. */
|
||||
public final int[] tracks;
|
||||
/** The track selection reason. One of the {@link C} SELECTION_REASON_ constants. */
|
||||
public final int reason;
|
||||
/** Optional data associated with this selection of tracks. */
|
||||
@Nullable public final Object data;
|
||||
|
||||
/**
|
||||
* @param group The {@link TrackGroup}. Must not be null.
|
||||
|
|
@ -50,8 +54,20 @@ public interface TrackSelection {
|
|||
* null or empty. May be in any order.
|
||||
*/
|
||||
public Definition(TrackGroup group, int... tracks) {
|
||||
this(group, tracks, C.SELECTION_REASON_UNKNOWN, /* data= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group The {@link TrackGroup}. Must not be null.
|
||||
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
|
||||
* @param reason The track selection reason. One of the {@link C} SELECTION_REASON_ constants.
|
||||
* @param data Optional data associated with this selection of tracks.
|
||||
*/
|
||||
public Definition(TrackGroup group, int[] tracks, int reason, @Nullable Object data) {
|
||||
this.group = group;
|
||||
this.tracks = tracks;
|
||||
this.reason = reason;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@ public final class TrackSelectionUtil {
|
|||
createdAdaptiveTrackSelection = true;
|
||||
selections[i] = adaptiveTrackSelectionFactory.createAdaptiveTrackSelection(definition);
|
||||
} else {
|
||||
selections[i] = new FixedTrackSelection(definition.group, definition.tracks[0]);
|
||||
selections[i] =
|
||||
new FixedTrackSelection(
|
||||
definition.group, definition.tracks[0], definition.reason, definition.data);
|
||||
}
|
||||
}
|
||||
return selections;
|
||||
|
|
|
|||
Loading…
Reference in a new issue