mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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 final Clock clock;
|
||||||
|
|
||||||
private TrackBitrateEstimator trackBitrateEstimator;
|
private TrackBitrateEstimator trackBitrateEstimator;
|
||||||
private boolean blockFixedTrackSelectionBandwidth;
|
|
||||||
|
|
||||||
/** Creates an adaptive track selection factory with default parameters. */
|
/** Creates an adaptive track selection factory with default parameters. */
|
||||||
public Factory() {
|
public Factory() {
|
||||||
|
|
@ -218,15 +217,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
this.trackBitrateEstimator = trackBitrateEstimator;
|
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
|
@Override
|
||||||
public final @NullableType TrackSelection[] createTrackSelections(
|
public final @NullableType TrackSelection[] createTrackSelections(
|
||||||
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
|
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
|
||||||
|
|
@ -234,20 +224,11 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
bandwidthMeter = this.bandwidthMeter;
|
bandwidthMeter = this.bandwidthMeter;
|
||||||
}
|
}
|
||||||
TrackSelection[] selections = new TrackSelection[definitions.length];
|
TrackSelection[] selections = new TrackSelection[definitions.length];
|
||||||
List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>();
|
|
||||||
int totalFixedBandwidth = 0;
|
int totalFixedBandwidth = 0;
|
||||||
for (int i = 0; i < definitions.length; i++) {
|
for (int i = 0; i < definitions.length; i++) {
|
||||||
Definition definition = definitions[i];
|
Definition definition = definitions[i];
|
||||||
if (definition == null) {
|
if (definition != null && definition.tracks.length == 1) {
|
||||||
continue;
|
// Make fixed selections first to know their total bandwidth.
|
||||||
}
|
|
||||||
if (definition.tracks.length > 1) {
|
|
||||||
AdaptiveTrackSelection adaptiveSelection =
|
|
||||||
createAdaptiveTrackSelection(definition.group, bandwidthMeter, definition.tracks);
|
|
||||||
adaptiveSelection.experimental_setTrackBitrateEstimator(trackBitrateEstimator);
|
|
||||||
adaptiveSelections.add(adaptiveSelection);
|
|
||||||
selections[i] = adaptiveSelection;
|
|
||||||
} else {
|
|
||||||
selections[i] =
|
selections[i] =
|
||||||
new FixedTrackSelection(
|
new FixedTrackSelection(
|
||||||
definition.group, definition.tracks[0], definition.reason, definition.data);
|
definition.group, definition.tracks[0], definition.reason, definition.data);
|
||||||
|
|
@ -257,9 +238,16 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blockFixedTrackSelectionBandwidth) {
|
List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>();
|
||||||
for (int i = 0; i < adaptiveSelections.size(); i++) {
|
for (int i = 0; i < definitions.length; i++) {
|
||||||
adaptiveSelections.get(i).experimental_setNonAllocatableBandwidth(totalFixedBandwidth);
|
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) {
|
if (adaptiveSelections.size() > 1) {
|
||||||
|
|
@ -288,14 +276,19 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
* @param group The {@link TrackGroup}.
|
* @param group The {@link TrackGroup}.
|
||||||
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
|
* @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 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.
|
* @return An {@link AdaptiveTrackSelection} for the specified tracks.
|
||||||
*/
|
*/
|
||||||
protected AdaptiveTrackSelection createAdaptiveTrackSelection(
|
protected AdaptiveTrackSelection createAdaptiveTrackSelection(
|
||||||
TrackGroup group, BandwidthMeter bandwidthMeter, int[] tracks) {
|
TrackGroup group,
|
||||||
|
BandwidthMeter bandwidthMeter,
|
||||||
|
int[] tracks,
|
||||||
|
int totalFixedTrackBandwidth) {
|
||||||
return new AdaptiveTrackSelection(
|
return new AdaptiveTrackSelection(
|
||||||
group,
|
group,
|
||||||
tracks,
|
tracks,
|
||||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction),
|
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction, totalFixedTrackBandwidth),
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
minDurationToRetainAfterDiscardMs,
|
minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -341,6 +334,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
group,
|
group,
|
||||||
tracks,
|
tracks,
|
||||||
bandwidthMeter,
|
bandwidthMeter,
|
||||||
|
/* reservedBandwidth= */ 0,
|
||||||
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_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
|
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
|
||||||
* empty. May be in any order.
|
* empty. May be in any order.
|
||||||
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
|
* @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
|
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
|
||||||
* selected track to switch to one of higher quality.
|
* selected track to switch to one of higher quality.
|
||||||
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
|
||||||
|
|
@ -381,6 +377,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
TrackGroup group,
|
TrackGroup group,
|
||||||
int[] tracks,
|
int[] tracks,
|
||||||
BandwidthMeter bandwidthMeter,
|
BandwidthMeter bandwidthMeter,
|
||||||
|
long reservedBandwidth,
|
||||||
long minDurationForQualityIncreaseMs,
|
long minDurationForQualityIncreaseMs,
|
||||||
long maxDurationForQualityDecreaseMs,
|
long maxDurationForQualityDecreaseMs,
|
||||||
long minDurationToRetainAfterDiscardMs,
|
long minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -391,7 +388,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
this(
|
this(
|
||||||
group,
|
group,
|
||||||
tracks,
|
tracks,
|
||||||
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction),
|
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction, reservedBandwidth),
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
minDurationToRetainAfterDiscardMs,
|
minDurationToRetainAfterDiscardMs,
|
||||||
|
|
@ -445,18 +442,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
this.trackBitrateEstimator = trackBitrateEstimator;
|
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.
|
* 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 BandwidthMeter bandwidthMeter;
|
||||||
private final float bandwidthFraction;
|
private final float bandwidthFraction;
|
||||||
|
private final long reservedBandwidth;
|
||||||
private long nonAllocatableBandwidth;
|
|
||||||
|
|
||||||
@Nullable private long[][] allocationCheckpoints;
|
@Nullable private long[][] allocationCheckpoints;
|
||||||
|
|
||||||
/* package */ DefaultBandwidthProvider(BandwidthMeter bandwidthMeter, float bandwidthFraction) {
|
/* package */ DefaultBandwidthProvider(
|
||||||
|
BandwidthMeter bandwidthMeter, float bandwidthFraction, long reservedBandwidth) {
|
||||||
this.bandwidthMeter = bandwidthMeter;
|
this.bandwidthMeter = bandwidthMeter;
|
||||||
this.bandwidthFraction = bandwidthFraction;
|
this.bandwidthFraction = bandwidthFraction;
|
||||||
|
this.reservedBandwidth = reservedBandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAllocatedBandwidth() {
|
public long getAllocatedBandwidth() {
|
||||||
long totalBandwidth = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction);
|
long totalBandwidth = (long) (bandwidthMeter.getBitrateEstimate() * bandwidthFraction);
|
||||||
long allocatableBandwidth = Math.max(0L, totalBandwidth - nonAllocatableBandwidth);
|
long allocatableBandwidth = Math.max(0L, totalBandwidth - reservedBandwidth);
|
||||||
if (allocationCheckpoints == null) {
|
if (allocationCheckpoints == null) {
|
||||||
return allocatableBandwidth;
|
return allocatableBandwidth;
|
||||||
}
|
}
|
||||||
|
|
@ -695,10 +681,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
|
||||||
return previous[1] + (long) (fractionBetweenCheckpoints * (next[1] - previous[1]));
|
return previous[1] + (long) (fractionBetweenCheckpoints * (next[1] - previous[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void experimental_setNonAllocatableBandwidth(long nonAllocatableBandwidth) {
|
|
||||||
this.nonAllocatableBandwidth = nonAllocatableBandwidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* package */ void experimental_setBandwidthAllocationCheckpoints(
|
/* package */ void experimental_setBandwidthAllocationCheckpoints(
|
||||||
long[][] allocationCheckpoints) {
|
long[][] allocationCheckpoints) {
|
||||||
Assertions.checkArgument(allocationCheckpoints.length >= 2);
|
Assertions.checkArgument(allocationCheckpoints.length >= 2);
|
||||||
|
|
|
||||||
|
|
@ -392,6 +392,7 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
|
/* reservedBandwidth= */ 0,
|
||||||
minDurationForQualityIncreaseMs,
|
minDurationForQualityIncreaseMs,
|
||||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -408,6 +409,7 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
|
/* reservedBandwidth= */ 0,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
maxDurationForQualityDecreaseMs,
|
maxDurationForQualityDecreaseMs,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
|
||||||
|
|
@ -426,6 +428,7 @@ public final class AdaptiveTrackSelectionTest {
|
||||||
trackGroup,
|
trackGroup,
|
||||||
selectedAllTracksInGroup(trackGroup),
|
selectedAllTracksInGroup(trackGroup),
|
||||||
mockBandwidthMeter,
|
mockBandwidthMeter,
|
||||||
|
/* reservedBandwidth= */ 0,
|
||||||
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
|
||||||
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
|
||||||
durationToRetainAfterDiscardMs,
|
durationToRetainAfterDiscardMs,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue