mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
1bc01c09ee
commit
0411add91e
2 changed files with 59 additions and 2 deletions
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ import junit.framework.Assert;
|
||||||
*/
|
*/
|
||||||
public class FakeMediaSource implements MediaSource {
|
public class FakeMediaSource implements MediaSource {
|
||||||
|
|
||||||
private final Timeline timeline;
|
protected final Timeline timeline;
|
||||||
private final Object manifest;
|
private final Object manifest;
|
||||||
private final TrackGroupArray trackGroupArray;
|
private final TrackGroupArray trackGroupArray;
|
||||||
private final ArrayList<FakeMediaPeriod> activeMediaPeriods;
|
private final ArrayList<FakeMediaPeriod> activeMediaPeriods;
|
||||||
|
|
@ -82,7 +82,7 @@ public class FakeMediaSource implements MediaSource {
|
||||||
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
|
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
|
||||||
Assert.assertTrue(preparedSource);
|
Assert.assertTrue(preparedSource);
|
||||||
Assert.assertFalse(releasedSource);
|
Assert.assertFalse(releasedSource);
|
||||||
FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray);
|
FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator);
|
||||||
activeMediaPeriods.add(mediaPeriod);
|
activeMediaPeriods.add(mediaPeriod);
|
||||||
return mediaPeriod;
|
return mediaPeriod;
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +104,11 @@ public class FakeMediaSource implements MediaSource {
|
||||||
releasedSource = true;
|
releasedSource = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray,
|
||||||
|
Allocator allocator) {
|
||||||
|
return new FakeMediaPeriod(trackGroupArray);
|
||||||
|
}
|
||||||
|
|
||||||
private static TrackGroupArray buildTrackGroupArray(Format... formats) {
|
private static TrackGroupArray buildTrackGroupArray(Format... formats) {
|
||||||
TrackGroup[] trackGroups = new TrackGroup[formats.length];
|
TrackGroup[] trackGroups = new TrackGroup[formats.length];
|
||||||
for (int i = 0; i < formats.length; i++) {
|
for (int i = 0; i < formats.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue