Remove allocator param from MediaSourceTestRunner constructor

Currently every test in the library passes `null` here, which seems to
end up being passed into non-null places in the library. This change
removes the parameter and instead initializes the field to a
`DefaultAllocator` instance in the same way that `DefaultLoadControl`
creates one.

PiperOrigin-RevId: 686823273
This commit is contained in:
ibaker 2024-10-17 01:57:47 -07:00 committed by Copybara-Service
parent 2e61c93dba
commit d2ccace75c
5 changed files with 17 additions and 16 deletions

View file

@ -610,8 +610,7 @@ public final class ClippingMediaSourceTest {
ClippingMediaSource clippingMediaSource, ClippingMediaSource clippingMediaSource,
Timeline... additionalTimelines) Timeline... additionalTimelines)
throws IOException { throws IOException {
MediaSourceTestRunner testRunner = MediaSourceTestRunner testRunner = new MediaSourceTestRunner(clippingMediaSource);
new MediaSourceTestRunner(clippingMediaSource, /* allocator= */ null);
Timeline[] clippedTimelines = new Timeline[additionalTimelines.length + 1]; Timeline[] clippedTimelines = new Timeline[additionalTimelines.length + 1];
try { try {
clippedTimelines[0] = testRunner.prepareSource(); clippedTimelines[0] = testRunner.prepareSource();

View file

@ -55,7 +55,7 @@ public final class ConcatenatingMediaSourceTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */ false, new FakeShuffleOrder(0)); mediaSource = new ConcatenatingMediaSource(/* isAtomic= */ false, new FakeShuffleOrder(0));
testRunner = new MediaSourceTestRunner(mediaSource, null); testRunner = new MediaSourceTestRunner(mediaSource);
} }
@After @After
@ -722,7 +722,7 @@ public final class ConcatenatingMediaSourceTest {
testRunner.release(); testRunner.release();
ConcatenatingMediaSource mediaSource = ConcatenatingMediaSource mediaSource =
new ConcatenatingMediaSource(/* isAtomic= */ true, new FakeShuffleOrder(0)); new ConcatenatingMediaSource(/* isAtomic= */ true, new FakeShuffleOrder(0));
testRunner = new MediaSourceTestRunner(mediaSource, null); testRunner = new MediaSourceTestRunner(mediaSource);
mediaSource.addMediaSources(Arrays.asList(createMediaSources(3))); mediaSource.addMediaSources(Arrays.asList(createMediaSources(3)));
Timeline timeline = testRunner.prepareSource(); Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertWindowTags(timeline, 111, 222, 333); TimelineAsserts.assertWindowTags(timeline, 111, 222, 333);
@ -958,7 +958,7 @@ public final class ConcatenatingMediaSourceTest {
/* useLazyPreparation= */ true, /* useLazyPreparation= */ true,
new DefaultShuffleOrder(0), new DefaultShuffleOrder(0),
childSources); childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */ null); testRunner = new MediaSourceTestRunner(mediaSource);
testRunner.prepareSource(); testRunner.prepareSource();
assertThat(childSources[0].isPrepared()).isFalse(); assertThat(childSources[0].isPrepared()).isFalse();
@ -974,7 +974,7 @@ public final class ConcatenatingMediaSourceTest {
/* useLazyPreparation= */ true, /* useLazyPreparation= */ true,
new DefaultShuffleOrder(0), new DefaultShuffleOrder(0),
childSources); childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */ null); testRunner = new MediaSourceTestRunner(mediaSource);
Timeline timeline = testRunner.prepareSource(); Timeline timeline = testRunner.prepareSource();
testRunner.createPeriod( testRunner.createPeriod(
new MediaPeriodId( new MediaPeriodId(
@ -993,7 +993,7 @@ public final class ConcatenatingMediaSourceTest {
/* useLazyPreparation= */ true, /* useLazyPreparation= */ true,
new DefaultShuffleOrder(0), new DefaultShuffleOrder(0),
childSources); childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */ null); testRunner = new MediaSourceTestRunner(mediaSource);
Timeline timeline = testRunner.prepareSource(); Timeline timeline = testRunner.prepareSource();
// The lazy preparation must only be triggered once, even if we create multiple periods from // The lazy preparation must only be triggered once, even if we create multiple periods from
@ -1015,7 +1015,7 @@ public final class ConcatenatingMediaSourceTest {
/* useLazyPreparation= */ true, /* useLazyPreparation= */ true,
new DefaultShuffleOrder(0), new DefaultShuffleOrder(0),
childSources); childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */ null); testRunner = new MediaSourceTestRunner(mediaSource);
testRunner.prepareSource(); testRunner.prepareSource();
// Check that removal doesn't throw even though the child sources are unprepared. // Check that removal doesn't throw even though the child sources are unprepared.

View file

@ -167,7 +167,7 @@ public class LoopingMediaSourceTest {
private static Timeline getLoopingTimeline(Timeline timeline, int loopCount) throws IOException { private static Timeline getLoopingTimeline(Timeline timeline, int loopCount) throws IOException {
FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline); FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline);
LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount); LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount);
MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource, null); MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource);
try { try {
Timeline loopingTimeline = testRunner.prepareSource(); Timeline loopingTimeline = testRunner.prepareSource();
testRunner.releaseSource(); testRunner.releaseSource();
@ -185,7 +185,7 @@ public class LoopingMediaSourceTest {
private static void testMediaPeriodCreation(Timeline timeline, int loopCount) throws Exception { private static void testMediaPeriodCreation(Timeline timeline, int loopCount) throws Exception {
FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline); FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline);
LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount); LoopingMediaSource mediaSource = new LoopingMediaSource(fakeMediaSource, loopCount);
MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource, null); MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource);
try { try {
testRunner.prepareSource(); testRunner.prepareSource();
testRunner.assertPrepareAndReleaseAllPeriods(); testRunner.assertPrepareAndReleaseAllPeriods();

View file

@ -99,7 +99,7 @@ public class MergingMediaSourceTest {
mediaSources[i] = new FakeMediaSource(new FakeTimeline(/* windowCount= */ 2)); mediaSources[i] = new FakeMediaSource(new FakeTimeline(/* windowCount= */ 2));
} }
MergingMediaSource mediaSource = new MergingMediaSource(mediaSources); MergingMediaSource mediaSource = new MergingMediaSource(mediaSources);
MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource, null); MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mediaSource);
try { try {
testRunner.prepareSource(); testRunner.prepareSource();
testRunner.assertPrepareAndReleaseAllPeriods(); testRunner.assertPrepareAndReleaseAllPeriods();
@ -124,8 +124,7 @@ public class MergingMediaSourceTest {
} }
MergingMediaSource mergingMediaSource = MergingMediaSource mergingMediaSource =
new MergingMediaSource(/* adjustPeriodTimeOffsets= */ false, clipDurations, mediaSources); new MergingMediaSource(/* adjustPeriodTimeOffsets= */ false, clipDurations, mediaSources);
MediaSourceTestRunner testRunner = MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mergingMediaSource);
new MediaSourceTestRunner(mergingMediaSource, /* allocator= */ null);
try { try {
Timeline timeline = testRunner.prepareSource(); Timeline timeline = testRunner.prepareSource();
testRunner.releaseSource(); testRunner.releaseSource();

View file

@ -26,6 +26,7 @@ import android.os.HandlerThread;
import android.os.Looper; import android.os.Looper;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.Timeline; import androidx.media3.common.Timeline;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.NullableType; import androidx.media3.common.util.NullableType;
@ -40,6 +41,7 @@ import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller; import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller;
import androidx.media3.exoplayer.source.MediaSourceEventListener; import androidx.media3.exoplayer.source.MediaSourceEventListener;
import androidx.media3.exoplayer.upstream.Allocator; import androidx.media3.exoplayer.upstream.Allocator;
import androidx.media3.exoplayer.upstream.DefaultAllocator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -68,12 +70,13 @@ public class MediaSourceTestRunner {
@Nullable private Timeline timeline; @Nullable private Timeline timeline;
/** /**
* Creates an instance.
*
* @param mediaSource The source under test. * @param mediaSource The source under test.
* @param allocator The allocator to use during the test run.
*/ */
public MediaSourceTestRunner(MediaSource mediaSource, Allocator allocator) { public MediaSourceTestRunner(MediaSource mediaSource) {
this.mediaSource = mediaSource; this.mediaSource = mediaSource;
this.allocator = allocator; this.allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
playbackThread = new HandlerThread("TestHandler"); playbackThread = new HandlerThread("TestHandler");
playbackThread.start(); playbackThread.start();
Looper playbackLooper = playbackThread.getLooper(); Looper playbackLooper = playbackThread.getLooper();