mirror of
https://github.com/samsonjs/media.git
synced 2026-03-28 09:55:48 +00:00
Make blocking fixed track bandwidth the default and remove experimental flag.
PiperOrigin-RevId: 260682878
This commit is contained in:
parent
40926618ad
commit
39d5867c97
2 changed files with 32 additions and 47 deletions
|
|
@ -49,7 +49,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
private final Clock clock;
|
||||
|
||||
private TrackBitrateEstimator trackBitrateEstimator;
|
||||
private boolean blockFixedTrackSelectionBandwidth;
|
||||
|
||||
/** Creates an adaptive track selection factory with default parameters. */
|
||||
public Factory() {
|
||||
|
|
@ -218,15 +217,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
this.trackBitrateEstimator = trackBitrateEstimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables blocking of the total fixed track selection bandwidth.
|
||||
*
|
||||
* <p>This method is experimental, and will be renamed or removed in a future release.
|
||||
*/
|
||||
public final void experimental_enableBlockFixedTrackSelectionBandwidth() {
|
||||
this.blockFixedTrackSelectionBandwidth = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NullableType TrackSelection[] createTrackSelections(
|
||||
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
|
||||
|
|
@ -234,20 +224,11 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
bandwidthMeter = this.bandwidthMeter;
|
||||
}
|
||||
TrackSelection[] selections = new TrackSelection[definitions.length];
|
||||
List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>();
|
||||
int totalFixedBandwidth = 0;
|
||||
for (int i = 0; i < definitions.length; i++) {
|
||||
Definition definition = definitions[i];
|
||||
if (definition == null) {
|
||||
continue;
|
||||
}
|
||||
if (definition.tracks.length > 1) {
|
||||
AdaptiveTrackSelection adaptiveSelection =
|
||||
createAdaptiveTrackSelection(definition.group, bandwidthMeter, definition.tracks);
|
||||
adaptiveSelection.experimental_setTrackBitrateEstimator(trackBitrateEstimator);
|
||||
adaptiveSelections.add(adaptiveSelection);
|
||||
selections[i] = adaptiveSelection;
|
||||
} else {
|
||||
if (definition != null && definition.tracks.length == 1) {
|
||||
// Make fixed selections first to know their total bandwidth.
|
||||
selections[i] =
|
||||
new FixedTrackSelection(
|
||||
definition.group, definition.tracks[0], definition.reason, definition.data);
|
||||
|
|
@ -257,9 +238,16 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (blockFixedTrackSelectionBandwidth) {
|
||||
for (int i = 0; i < adaptiveSelections.size(); i++) {
|
||||
adaptiveSelections.get(i).experimental_setNonAllocatableBandwidth(totalFixedBandwidth);
|
||||
List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>();
|
||||
for (int i = 0; i < definitions.length; i++) {
|
||||
Definition definition = definitions[i];
|
||||
if (definition != null && definition.tracks.length > 1) {
|
||||
AdaptiveTrackSelection adaptiveSelection =
|
||||
createAdaptiveTrackSelection(
|
||||
definition.group, bandwidthMeter, definition.tracks, totalFixedBandwidth);
|
||||
adaptiveSelection.experimental_setTrackBitrateEstimator(trackBitrateEstimator);
|
||||
adaptiveSelections.add(adaptiveSelection);
|
||||
selections[i] = adaptiveSelection;
|
||||
}
|
||||
}
|
||||
if (adaptiveSelections.size() > 1) {
|
||||
|
|
@ -288,14 +276,19 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
* @param group The {@link TrackGroup}.
|
||||
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
|
||||
* @param tracks The indices of the selected tracks in the track group.
|
||||
* @param totalFixedTrackBandwidth The total bandwidth used by all non-adaptive tracks, in bits
|
||||
* per second.
|
||||
* @return An {@link AdaptiveTrackSelection} for the specified tracks.
|
||||
*/
|
||||
protected AdaptiveTrackSelection createAdaptiveTrackSelection(
|
||||
TrackGroup group, BandwidthMeter bandwidthMeter, int[] tracks) {
|
||||
TrackGroup group,
|
||||
BandwidthMeter bandwidthMeter,
|
||||
int[] tracks,
|
||||
int totalFixedTrackBandwidth) {
|
||||
return new AdaptiveTrackSelection(
|
||||
group,
|
||||
tracks,
|
||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction),
|
||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction, totalFixedTrackBandwidth),
|
||||
minDurationForQualityIncreaseMs,
|
||||
maxDurationForQualityDecreaseMs,
|
||||
minDurationToRetainAfterDiscardMs,
|
||||
|
|
@ -341,6 +334,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
group,
|
||||
tracks,
|
||||
bandwidthMeter,
|
||||
/* reservedBandwidth= */ 0,
|
||||
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||
|
|
@ -355,6 +349,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
|
||||
* empty. May be in any order.
|
||||
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
||||
* @param reservedBandwidth The reserved bandwidth, which shouldn't be considered available for
|
||||
* use, in bits per second.
|
||||
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
||||
* selected track to switch to one of higher quality.
|
||||
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
||||
|
|
@ -381,6 +377,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
TrackGroup group,
|
||||
int[] tracks,
|
||||
BandwidthMeter bandwidthMeter,
|
||||
long reservedBandwidth,
|
||||
long minDurationForQualityIncreaseMs,
|
||||
long maxDurationForQualityDecreaseMs,
|
||||
long minDurationToRetainAfterDiscardMs,
|
||||
|
|
@ -391,7 +388,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
this(
|
||||
group,
|
||||
tracks,
|
||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction),
|
||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction, reservedBandwidth),
|
||||
minDurationForQualityIncreaseMs,
|
||||
maxDurationForQualityDecreaseMs,
|
||||
minDurationToRetainAfterDiscardMs,
|
||||
|
|
@ -445,18 +442,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
this.trackBitrateEstimator = trackBitrateEstimator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the non-allocatable bandwidth, which shouldn't be considered available.
|
||||
*
|
||||
* <p>This method is experimental, and will be renamed or removed in a future release.
|
||||
*
|
||||
* @param nonAllocatableBandwidth The non-allocatable bandwidth in bits per second.
|
||||
*/
|
||||
public void experimental_setNonAllocatableBandwidth(long nonAllocatableBandwidth) {
|
||||
((DefaultBandwidthProvider) bandwidthProvider)
|
||||
.experimental_setNonAllocatableBandwidth(nonAllocatableBandwidth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets checkpoints to determine the allocation bandwidth based on the total bandwidth.
|
||||
*
|
||||
|
|
@ -666,20 +651,21 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
|
||||
private final BandwidthMeter bandwidthMeter;
|
||||
private final float bandwidthFraction;
|
||||
|
||||
private long nonAllocatableBandwidth;
|
||||
private final long reservedBandwidth;
|
||||
|
||||
@Nullable private long[][] allocationCheckpoints;
|
||||
|
||||
/* package */ DefaultBandwidthProvider(BandwidthMeter bandwidthMeter, float bandwidthFraction) {
|
||||
/* package */ DefaultBandwidthProvider(
|
||||
BandwidthMeter bandwidthMeter, float bandwidthFraction, long reservedBandwidth) {
|
||||
this.bandwidthMeter = bandwidthMeter;
|
||||
this.bandwidthFraction = bandwidthFraction;
|
||||
this.reservedBandwidth = reservedBandwidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAllocatedBandwidth() {
|
||||
long totalBandwidth = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction);
|
||||
long allocatableBandwidth = Math.max(0L, totalBandwidth - nonAllocatableBandwidth);
|
||||
long allocatableBandwidth = Math.max(0L, totalBandwidth - reservedBandwidth);
|
||||
if (allocationCheckpoints == null) {
|
||||
return allocatableBandwidth;
|
||||
}
|
||||
|
|
@ -695,10 +681,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
|||
return previous[1] + (long) (fractionBetweenCheckpoints * (next[1] - previous[1]));
|
||||
}
|
||||
|
||||
/* package */ void experimental_setNonAllocatableBandwidth(long nonAllocatableBandwidth) {
|
||||
this.nonAllocatableBandwidth = nonAllocatableBandwidth;
|
||||
}
|
||||
|
||||
/* package */ void experimental_setBandwidthAllocationCheckpoints(
|
||||
long[][] allocationCheckpoints) {
|
||||
Assertions.checkArgument(allocationCheckpoints.length >= 2);
|
||||
|
|
|
|||
|
|
@ -392,6 +392,7 @@ public final class AdaptiveTrackSelectionTest {
|
|||
trackGroup,
|
||||
selectedAllTracksInGroup(trackGroup),
|
||||
mockBandwidthMeter,
|
||||
/* reservedBandwidth= */ 0,
|
||||
minDurationForQualityIncreaseMs,
|
||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||
|
|
@ -408,6 +409,7 @@ public final class AdaptiveTrackSelectionTest {
|
|||
trackGroup,
|
||||
selectedAllTracksInGroup(trackGroup),
|
||||
mockBandwidthMeter,
|
||||
/* reservedBandwidth= */ 0,
|
||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||
maxDurationForQualityDecreaseMs,
|
||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||
|
|
@ -426,6 +428,7 @@ public final class AdaptiveTrackSelectionTest {
|
|||
trackGroup,
|
||||
selectedAllTracksInGroup(trackGroup),
|
||||
mockBandwidthMeter,
|
||||
/* reservedBandwidth= */ 0,
|
||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||
durationToRetainAfterDiscardMs,
|
||||
|
|
|
|||
Loading…
Reference in a new issue