From 0411add91e383bead238403c584fbb01edebc25b Mon Sep 17 00:00:00 2001 From: tonihei Date: Mon, 24 Jul 2017 04:15:22 -0700 Subject: [PATCH] Add fake adaptive media source. This class extends the existing FakeMediaSource by creating a FakeAdaptiveMediaPeriod instead of a FakeMediaPeriod. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162918487 --- .../testutil/FakeAdaptiveMediaSource.java | 52 +++++++++++++++++++ .../exoplayer2/testutil/FakeMediaSource.java | 9 +++- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java new file mode 100644 index 0000000000..59bcaf3e7c --- /dev/null +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.testutil; + +import android.os.Handler; +import com.google.android.exoplayer2.Timeline; +import com.google.android.exoplayer2.Timeline.Period; +import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener; +import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher; +import com.google.android.exoplayer2.source.MediaSource; +import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.upstream.Allocator; + +/** + * Fake {@link MediaSource} that provides a given timeline. Creating the period returns a + * {@link FakeAdaptiveMediaPeriod} from the given {@link TrackGroupArray}. + */ +public class FakeAdaptiveMediaSource extends FakeMediaSource { + + private final EventDispatcher eventDispatcher; + private final FakeChunkSource.Factory chunkSourceFactory; + + public FakeAdaptiveMediaSource(Timeline timeline, Object manifest, + TrackGroupArray trackGroupArray, Handler eventHandler, + AdaptiveMediaSourceEventListener eventListener, FakeChunkSource.Factory chunkSourceFactory) { + super(timeline, manifest, trackGroupArray); + this.eventDispatcher = new EventDispatcher(eventHandler, eventListener); + this.chunkSourceFactory = chunkSourceFactory; + } + + @Override + protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, + Allocator allocator) { + Period period = timeline.getPeriod(id.periodIndex, new Period()); + return new FakeAdaptiveMediaPeriod(trackGroupArray, eventDispatcher, allocator, + chunkSourceFactory, period.durationUs); + } + +} diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java index a2c1e9879e..9e7b498269 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java @@ -34,7 +34,7 @@ import junit.framework.Assert; */ public class FakeMediaSource implements MediaSource { - private final Timeline timeline; + protected final Timeline timeline; private final Object manifest; private final TrackGroupArray trackGroupArray; private final ArrayList activeMediaPeriods; @@ -82,7 +82,7 @@ public class FakeMediaSource implements MediaSource { Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount()); Assert.assertTrue(preparedSource); Assert.assertFalse(releasedSource); - FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray); + FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator); activeMediaPeriods.add(mediaPeriod); return mediaPeriod; } @@ -104,6 +104,11 @@ public class FakeMediaSource implements MediaSource { releasedSource = true; } + protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, + Allocator allocator) { + return new FakeMediaPeriod(trackGroupArray); + } + private static TrackGroupArray buildTrackGroupArray(Format... formats) { TrackGroup[] trackGroups = new TrackGroup[formats.length]; for (int i = 0; i < formats.length; i++) {