Remove randomness from adaptive bitrate tests.

- The order of sample stream (and thus the order in which loads are
  triggered) currently depends on a Set and thus on the hash codes
  of the objects that change with every run. Changing to a List solves
  this problem.
- The FakeAdaptiveDataSet directly created a static Random (with random
  seed) to compute the variation of chunk sizes. Changing this to an
  injected Random object that can always be initialized with the same
  seed also removed this randomness from the tests.

PiperOrigin-RevId: 353878661
This commit is contained in:
tonihei 2021-01-26 17:06:39 +00:00 committed by Ian Baker
parent 2e52c0b8d8
commit 9b3014dd79
3 changed files with 13 additions and 11 deletions

View File

@ -115,6 +115,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@ -4644,7 +4645,7 @@ public final class ExoPlayerTest {
// Use chunked data to ensure the player actually needs to continue loading and playing.
FakeAdaptiveDataSet.Factory dataSetFactory =
new FakeAdaptiveDataSet.Factory(
/* chunkDurationUs= */ 500_000, /* bitratePercentStdDev= */ 10.0);
/* chunkDurationUs= */ 500_000, /* bitratePercentStdDev= */ 10.0, new Random(0));
MediaSource chunkedMediaSource =
new FakeAdaptiveMediaSource(
new FakeTimeline(),
@ -4769,7 +4770,7 @@ public final class ExoPlayerTest {
// Use chunked data to ensure the player actually needs to continue loading and playing.
FakeAdaptiveDataSet.Factory dataSetFactory =
new FakeAdaptiveDataSet.Factory(
/* chunkDurationUs= */ 500_000, /* bitratePercentStdDev= */ 10.0);
/* chunkDurationUs= */ 500_000, /* bitratePercentStdDev= */ 10.0, new Random(0));
MediaSource chunkedMediaSource =
new FakeAdaptiveMediaSource(
new FakeTimeline(),

View File

@ -37,10 +37,9 @@ public final class FakeAdaptiveDataSet extends FakeDataSet {
*/
public static final class Factory {
private static final Random random = new Random();
private final long chunkDurationUs;
private final double bitratePercentStdDev;
private final Random random;
/**
* Set up factory for {@link FakeAdaptiveDataSet}s with a chunk duration and the standard
@ -50,10 +49,12 @@ public final class FakeAdaptiveDataSet extends FakeDataSet {
* @param bitratePercentStdDev The standard deviation used to generate the chunk sizes centered
* around the average bitrate of the {@link Format}s. The standard deviation is given in
* percent (of the average size).
* @param random The random number generator used to generate the chunk size variation.
*/
public Factory(long chunkDurationUs, double bitratePercentStdDev) {
public Factory(long chunkDurationUs, double bitratePercentStdDev, Random random) {
this.chunkDurationUs = chunkDurationUs;
this.bitratePercentStdDev = bitratePercentStdDev;
this.random = random;
}
/**
@ -63,8 +64,8 @@ public final class FakeAdaptiveDataSet extends FakeDataSet {
* @param mediaDurationUs The total duration of the fake data set in microseconds.
*/
public FakeAdaptiveDataSet createDataSet(TrackGroup trackGroup, long mediaDurationUs) {
return new FakeAdaptiveDataSet(trackGroup, mediaDurationUs, chunkDurationUs,
bitratePercentStdDev, random);
return new FakeAdaptiveDataSet(
trackGroup, mediaDurationUs, chunkDurationUs, bitratePercentStdDev, random);
}
}

View File

@ -42,9 +42,9 @@ import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
@ -63,7 +63,7 @@ public class FakeAdaptiveMediaPeriod
private final Allocator allocator;
private final long durationUs;
@Nullable private final TransferListener transferListener;
private final Set<ChunkSampleStream<FakeChunkSource>> sampleStreams;
private final List<ChunkSampleStream<FakeChunkSource>> sampleStreams;
@Nullable private Callback callback;
private boolean prepared;
@ -82,7 +82,7 @@ public class FakeAdaptiveMediaPeriod
this.allocator = allocator;
this.durationUs = durationUs;
this.transferListener = transferListener;
sampleStreams = Sets.newIdentityHashSet();
sampleStreams = new ArrayList<>();
sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
fakePreparationLoadTaskId = LoadEventInfo.getNewId();
}