Allow simplified custom adaptive track selection factories.

Custom factories currently need to copy most of the code in the
AdaptiveTrackSelection.Factory to make use of the same functionality.
Simplify this by allowing to overwrite the factory.

PiperOrigin-RevId: 240773271
This commit is contained in:
tonihei 2019-03-28 14:58:49 +00:00 committed by Toni
parent bb48dc9916
commit e8cf67c0cd

View File

@ -36,10 +36,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
*/ */
public class AdaptiveTrackSelection extends BaseTrackSelection { public class AdaptiveTrackSelection extends BaseTrackSelection {
/** /** Factory for {@link AdaptiveTrackSelection} instances. */
* Factory for {@link AdaptiveTrackSelection} instances. public static class Factory implements TrackSelection.Factory {
*/
public static final class Factory implements TrackSelection.Factory {
private final @Nullable BandwidthMeter bandwidthMeter; private final @Nullable BandwidthMeter bandwidthMeter;
private final int minDurationForQualityIncreaseMs; private final int minDurationForQualityIncreaseMs;
@ -215,7 +213,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* *
* @param trackBitrateEstimator A {@link TrackBitrateEstimator}. * @param trackBitrateEstimator A {@link TrackBitrateEstimator}.
*/ */
public void experimental_setTrackBitrateEstimator(TrackBitrateEstimator trackBitrateEstimator) { public final void experimental_setTrackBitrateEstimator(
TrackBitrateEstimator trackBitrateEstimator) {
this.trackBitrateEstimator = trackBitrateEstimator; this.trackBitrateEstimator = trackBitrateEstimator;
} }
@ -224,13 +223,16 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* *
* <p>This method is experimental, and will be renamed or removed in a future release. * <p>This method is experimental, and will be renamed or removed in a future release.
*/ */
public void experimental_enableBlockFixedTrackSelectionBandwidth() { public final void experimental_enableBlockFixedTrackSelectionBandwidth() {
this.blockFixedTrackSelectionBandwidth = true; this.blockFixedTrackSelectionBandwidth = true;
} }
@Override @Override
public @NullableType TrackSelection[] createTrackSelections( public final @NullableType TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) { @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
if (this.bandwidthMeter != null) {
bandwidthMeter = this.bandwidthMeter;
}
TrackSelection[] selections = new TrackSelection[definitions.length]; TrackSelection[] selections = new TrackSelection[definitions.length];
List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>(); List<AdaptiveTrackSelection> adaptiveSelections = new ArrayList<>();
int totalFixedBandwidth = 0; int totalFixedBandwidth = 0;
@ -242,6 +244,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
if (definition.tracks.length > 1) { if (definition.tracks.length > 1) {
AdaptiveTrackSelection adaptiveSelection = AdaptiveTrackSelection adaptiveSelection =
createAdaptiveTrackSelection(definition.group, bandwidthMeter, definition.tracks); createAdaptiveTrackSelection(definition.group, bandwidthMeter, definition.tracks);
adaptiveSelection.experimental_setTrackBitrateEstimator(trackBitrateEstimator);
adaptiveSelections.add(adaptiveSelection); adaptiveSelections.add(adaptiveSelection);
selections[i] = adaptiveSelection; selections[i] = adaptiveSelection;
} else { } else {
@ -279,24 +282,26 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
return selections; return selections;
} }
private AdaptiveTrackSelection createAdaptiveTrackSelection( /**
* Creates a single adaptive selection for the given group, bandwidth meter and tracks.
*
* @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.
* @return An {@link AdaptiveTrackSelection} for the specified tracks.
*/
protected AdaptiveTrackSelection createAdaptiveTrackSelection(
TrackGroup group, BandwidthMeter bandwidthMeter, int[] tracks) { TrackGroup group, BandwidthMeter bandwidthMeter, int[] tracks) {
if (this.bandwidthMeter != null) { return new AdaptiveTrackSelection(
bandwidthMeter = this.bandwidthMeter; group,
} tracks,
AdaptiveTrackSelection adaptiveTrackSelection = new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction),
new AdaptiveTrackSelection( minDurationForQualityIncreaseMs,
group, maxDurationForQualityDecreaseMs,
tracks, minDurationToRetainAfterDiscardMs,
new DefaultBandwidthProvider(bandwidthMeter, bandwidthFraction), bufferedFractionToLiveEdgeForQualityIncrease,
minDurationForQualityIncreaseMs, minTimeBetweenBufferReevaluationMs,
maxDurationForQualityDecreaseMs, clock);
minDurationToRetainAfterDiscardMs,
bufferedFractionToLiveEdgeForQualityIncrease,
minTimeBetweenBufferReevaluationMs,
clock);
adaptiveTrackSelection.experimental_setTrackBitrateEstimator(trackBitrateEstimator);
return adaptiveTrackSelection;
} }
} }