mirror of
https://github.com/samsonjs/media.git
synced 2026-04-03 10:55:48 +00:00
Remove boilerplate setting up FakeTimeline and FakeMediaSource.
In many cases it doesn't matter for the test itself how many windows a timeline has, or even how the timeline of a MediaSource looks like. And since we introduced the MediaItem-based APIs, single-window Timelines are the only fully supported Timelines. Thus there is no point in specifiying this explicitly. Using these assumptions, we can remove some boilerplate when setting up standard FakeTimelines or FakeMediaSources with a standard FakeTimeline. #exofixit PiperOrigin-RevId: 344210395
This commit is contained in:
parent
b7047a2467
commit
87e141d376
10 changed files with 158 additions and 264 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -30,7 +30,6 @@ import com.google.android.exoplayer2.source.MediaSource;
|
|||
import com.google.android.exoplayer2.source.ShuffleOrder;
|
||||
import com.google.android.exoplayer2.testutil.FakeMediaSource;
|
||||
import com.google.android.exoplayer2.testutil.FakeShuffleOrder;
|
||||
import com.google.android.exoplayer2.testutil.FakeTimeline;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -528,11 +527,11 @@ public class MediaSourceListTest {
|
|||
}
|
||||
|
||||
private static List<MediaSourceList.MediaSourceHolder> createFakeHolders() {
|
||||
MediaSource fakeMediaSource = new FakeMediaSource(new FakeTimeline(1));
|
||||
List<MediaSourceList.MediaSourceHolder> holders = new ArrayList<>();
|
||||
for (int i = 0; i < MEDIA_SOURCE_LIST_SIZE; i++) {
|
||||
holders.add(
|
||||
new MediaSourceList.MediaSourceHolder(fakeMediaSource, /* useLazyPreparation= */ true));
|
||||
new MediaSourceList.MediaSourceHolder(
|
||||
new FakeMediaSource(), /* useLazyPreparation= */ true));
|
||||
}
|
||||
return holders;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public final class AnalyticsCollectorTest {
|
|||
ExoPlayerTestRunner.VIDEO_FORMAT.buildUpon().setDrmInitData(DRM_DATA_1).build();
|
||||
|
||||
private static final int TIMEOUT_MS = 10_000;
|
||||
private static final Timeline SINGLE_PERIOD_TIMELINE = new FakeTimeline(/* windowCount= */ 1);
|
||||
private static final Timeline SINGLE_PERIOD_TIMELINE = new FakeTimeline();
|
||||
private static final EventWindowAndPeriodId WINDOW_0 =
|
||||
new EventWindowAndPeriodId(/* windowIndex= */ 0, /* mediaPeriodId= */ null);
|
||||
private static final EventWindowAndPeriodId WINDOW_1 =
|
||||
|
|
@ -1520,11 +1520,9 @@ public final class AnalyticsCollectorTest {
|
|||
public void onPlayerError_thrownDuringRendererEnableAtPeriodTransition_isReportedForNewPeriod()
|
||||
throws Exception {
|
||||
FakeMediaSource source0 =
|
||||
new FakeMediaSource(
|
||||
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||
FakeMediaSource source1 =
|
||||
new FakeMediaSource(
|
||||
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
RenderersFactory renderersFactory =
|
||||
(eventHandler, videoListener, audioListener, textOutput, metadataOutput) ->
|
||||
new Renderer[] {
|
||||
|
|
@ -1554,11 +1552,9 @@ public final class AnalyticsCollectorTest {
|
|||
public void onPlayerError_thrownDuringRenderAtPeriodTransition_isReportedForNewPeriod()
|
||||
throws Exception {
|
||||
FakeMediaSource source0 =
|
||||
new FakeMediaSource(
|
||||
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||
FakeMediaSource source1 =
|
||||
new FakeMediaSource(
|
||||
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
RenderersFactory renderersFactory =
|
||||
(eventHandler, videoListener, audioListener, textOutput, metadataOutput) ->
|
||||
new Renderer[] {
|
||||
|
|
@ -1589,8 +1585,7 @@ public final class AnalyticsCollectorTest {
|
|||
onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod()
|
||||
throws Exception {
|
||||
FakeMediaSource source =
|
||||
new FakeMediaSource(
|
||||
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
RenderersFactory renderersFactory =
|
||||
(eventHandler, videoListener, audioListener, textOutput, metadataOutput) ->
|
||||
new Renderer[] {
|
||||
|
|
@ -1634,7 +1629,7 @@ public final class AnalyticsCollectorTest {
|
|||
player.addAnalyticsListener(listener);
|
||||
|
||||
// Trigger some simultaneous events.
|
||||
player.setMediaSource(new FakeMediaSource(new FakeTimeline(/* windowCount= */ 1), formats));
|
||||
player.setMediaSource(new FakeMediaSource(new FakeTimeline(), formats));
|
||||
player.seekTo(2_000);
|
||||
player.setPlaybackParameters(new PlaybackParameters(/* speed= */ 2.0f));
|
||||
ShadowLooper.runMainLooperToNextTask();
|
||||
|
|
@ -1642,7 +1637,7 @@ public final class AnalyticsCollectorTest {
|
|||
// Move to another item and fail with a third one to trigger events with different EventTimes.
|
||||
player.prepare();
|
||||
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
|
||||
player.addMediaSource(new FakeMediaSource(new FakeTimeline(/* windowCount= */ 1), formats));
|
||||
player.addMediaSource(new FakeMediaSource(new FakeTimeline(), formats));
|
||||
player.play();
|
||||
TestPlayerRunHelper.runUntilPositionDiscontinuity(
|
||||
player, Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_withoutMediaPeriodId_createsNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
EventTime eventTime = createEventTime(timeline, /* windowIndex= */ 0, /* mediaPeriodId */ null);
|
||||
|
||||
sessionManager.updateSessions(eventTime);
|
||||
|
|
@ -73,7 +73,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_withMediaPeriodId_createsNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -92,7 +92,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
@Test
|
||||
public void
|
||||
updateSessions_ofSameWindow_withMediaPeriodId_afterWithoutMediaPeriodId_doesNotCreateNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -113,7 +113,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_ofSameWindow_withAd_afterWithoutMediaPeriodId_createsNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0),
|
||||
|
|
@ -141,7 +141,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
@Test
|
||||
public void
|
||||
updateSessions_ofSameWindow_withoutMediaPeriodId_afterMediaPeriodId_doesNotCreateNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -310,7 +310,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_ofSameWindow_withNewWindowSequenceNumber_createsNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId1 =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -339,7 +339,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
@Test
|
||||
public void
|
||||
updateSessions_withoutMediaPeriodId_andPreviouslyCreatedSessions_doesNotCreateNewSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId1 =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -372,7 +372,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_afterSessionForMediaPeriodId_withSameMediaPeriodId_returnsSameValue() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -390,7 +390,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void updateSessions_withoutMediaPeriodId_afterSessionForMediaPeriodId_returnsSameValue() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -474,7 +474,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void getSessionForMediaPeriodId_returnsValue_butDoesNotCreateSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -488,7 +488,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
public void belongsToSession_withSameWindowIndex_returnsTrue() {
|
||||
EventTime eventTime =
|
||||
createEventTime(Timeline.EMPTY, /* windowIndex= */ 0, /* mediaPeriodId= */ null);
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
EventTime eventTimeWithTimeline =
|
||||
createEventTime(timeline, /* windowIndex= */ 0, /* mediaPeriodId= */ null);
|
||||
MediaPeriodId mediaPeriodId =
|
||||
|
|
@ -532,7 +532,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void belongsToSession_withOtherWindowSequenceNumber_returnsFalse() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
MediaPeriodId mediaPeriodId1 =
|
||||
new MediaPeriodId(
|
||||
timeline.getUidOfPeriod(/* periodIndex= */ 0), /* windowSequenceNumber= */ 0);
|
||||
|
|
@ -592,7 +592,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
createEventTime(Timeline.EMPTY, /* windowIndex= */ 1, /* mediaPeriodId= */ null);
|
||||
sessionManager.updateSessions(eventTime1);
|
||||
sessionManager.updateSessions(eventTime2);
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
EventTime newTimelineEventTime =
|
||||
createEventTime(timeline, /* windowIndex= */ 0, /* mediaPeriodId= */ null);
|
||||
|
||||
|
|
@ -827,7 +827,7 @@ public final class DefaultPlaybackSessionManagerTest {
|
|||
|
||||
@Test
|
||||
public void positionDiscontinuity_toSameWindow_withoutMediaPeriodId_doesNotFinishSession() {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline timeline = new FakeTimeline();
|
||||
EventTime eventTime1 =
|
||||
createEventTime(
|
||||
timeline,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public final class PlaybackStatsListenerTest {
|
|||
/* currentMediaPeriodId= */ null,
|
||||
/* currentPlaybackPositionMs= */ 0,
|
||||
/* totalBufferedDurationMs= */ 0);
|
||||
private static final Timeline TEST_TIMELINE = new FakeTimeline(/* windowCount= */ 1);
|
||||
private static final Timeline TEST_TIMELINE = new FakeTimeline();
|
||||
private static final MediaSource.MediaPeriodId TEST_MEDIA_PERIOD_ID =
|
||||
new MediaSource.MediaPeriodId(
|
||||
TEST_TIMELINE.getPeriod(/* periodIndex= */ 0, new Timeline.Period(), /* setIds= */ true)
|
||||
|
|
|
|||
|
|
@ -854,7 +854,7 @@ public final class ConcatenatingMediaSourceTest {
|
|||
|
||||
@Test
|
||||
public void duplicateNestedMediaSources() throws IOException, InterruptedException {
|
||||
Timeline childTimeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Timeline childTimeline = new FakeTimeline();
|
||||
FakeMediaSource childSource = new FakeMediaSource(childTimeline);
|
||||
ConcatenatingMediaSource nestedConcatenation = new ConcatenatingMediaSource();
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public final class DefaultTrackSelectorTest {
|
|||
private static final TrackSelection[] TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER =
|
||||
new TrackSelection[] {new FixedTrackSelection(VIDEO_TRACK_GROUP, 0), null};
|
||||
|
||||
private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1);
|
||||
private static final Timeline TIMELINE = new FakeTimeline();
|
||||
|
||||
private static MediaPeriodId periodId;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public final class MappingTrackSelectorTest {
|
|||
private static final TrackGroup AUDIO_TRACK_GROUP = buildTrackGroup(MimeTypes.AUDIO_AAC);
|
||||
private static final TrackGroup METADATA_TRACK_GROUP = buildTrackGroup(MimeTypes.APPLICATION_ID3);
|
||||
|
||||
private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1);
|
||||
private static final Timeline TIMELINE = new FakeTimeline();
|
||||
|
||||
private static MediaPeriodId periodId;
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,11 @@ public class FakeMediaSource extends BaseMediaSource {
|
|||
@Nullable private Handler sourceInfoRefreshHandler;
|
||||
@Nullable private TransferListener transferListener;
|
||||
|
||||
/** Creates a {@link FakeMediaSource} with a default {@link FakeTimeline}. */
|
||||
public FakeMediaSource() {
|
||||
this(new FakeTimeline());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with a
|
||||
* {@link TrackGroupArray} using the given {@link Format}s. The provided {@link Timeline} may be
|
||||
|
|
|
|||
|
|
@ -266,6 +266,14 @@ public final class FakeTimeline extends Timeline {
|
|||
return adPlaybackState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake timeline with one seekable, non-dynamic window with one period and a duration of
|
||||
* {@link TimelineWindowDefinition#DEFAULT_WINDOW_DURATION_US}.
|
||||
*/
|
||||
public FakeTimeline() {
|
||||
this(/* windowCount= */ 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fake timeline with the given number of seekable, non-dynamic windows with one period
|
||||
* with a duration of {@link TimelineWindowDefinition#DEFAULT_WINDOW_DURATION_US} each.
|
||||
|
|
|
|||
Loading…
Reference in a new issue