Commit 74b43e26 by olly Committed by Oliver Woodman

Allow injection of custom ChunkSources

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=127737169
parent 5360ddc5
......@@ -40,7 +40,9 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator.AdaptiveEvaluator;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSmoothStreamingChunkSource;
import com.google.android.exoplayer2.source.smoothstreaming.SmoothStreamingMediaSource;
import com.google.android.exoplayer2.text.CaptionStyleCompat;
import com.google.android.exoplayer2.text.Cue;
......@@ -131,7 +133,8 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
private SubtitleLayout subtitleLayout;
private Button retryButton;
private DataSource.Factory dataSourceFactory;
private DataSource.Factory manifestDataSourceFactory;
private DataSource.Factory mediaDataSourceFactory;
private FormatEvaluator.Factory formatEvaluatorFactory;
private SimpleExoPlayer player;
private MappingTrackSelector trackSelector;
......@@ -148,8 +151,9 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
manifestDataSourceFactory = new DefaultDataSourceFactory(this, userAgent);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
dataSourceFactory = new DefaultDataSourceFactory(this, userAgent, bandwidthMeter);
mediaDataSourceFactory = new DefaultDataSourceFactory(this, userAgent, bandwidthMeter);
formatEvaluatorFactory = new AdaptiveEvaluator.Factory(bandwidthMeter);
mainHandler = new Handler();
......@@ -343,16 +347,21 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
int type = Util.inferContentType(lastPathSegment);
switch (type) {
case Util.TYPE_SS:
return new SmoothStreamingMediaSource(uri, dataSourceFactory, formatEvaluatorFactory,
mainHandler, eventLogger);
DefaultSmoothStreamingChunkSource.Factory factory =
new DefaultSmoothStreamingChunkSource.Factory(mediaDataSourceFactory,
formatEvaluatorFactory);
return new SmoothStreamingMediaSource(uri, manifestDataSourceFactory, factory, mainHandler,
eventLogger);
case Util.TYPE_DASH:
return new DashMediaSource(uri, dataSourceFactory, formatEvaluatorFactory, mainHandler,
DefaultDashChunkSource.Factory factory2 = new DefaultDashChunkSource.Factory(
mediaDataSourceFactory, formatEvaluatorFactory);
return new DashMediaSource(uri, mediaDataSourceFactory, factory2, mainHandler,
eventLogger);
case Util.TYPE_HLS:
return new HlsMediaSource(uri, dataSourceFactory, formatEvaluatorFactory, mainHandler,
return new HlsMediaSource(uri, mediaDataSourceFactory, formatEvaluatorFactory, mainHandler,
eventLogger);
case Util.TYPE_OTHER:
return new ExtractorMediaSource(uri, dataSourceFactory, new DefaultExtractorsFactory(),
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
mainHandler, eventLogger);
default:
throw new IllegalStateException("Unsupported type: " + type);
......
......@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.util.MimeTypes;
import android.test.InstrumentationTestCase;
/**
* Tests {@link DashChunkSource}.
* Tests {@link DefaultDashChunkSource}.
*/
public class DashChunkSourceTest extends InstrumentationTestCase {
......
......@@ -25,14 +25,12 @@ import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.chunk.ChunkSampleStream;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator;
import com.google.android.exoplayer2.source.dash.mpd.AdaptationSet;
import com.google.android.exoplayer2.source.dash.mpd.MediaPresentationDescription;
import com.google.android.exoplayer2.source.dash.mpd.Period;
import com.google.android.exoplayer2.source.dash.mpd.Representation;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.Loader;
import android.util.Pair;
......@@ -47,8 +45,7 @@ import java.util.List;
/* package */ final class DashMediaPeriod implements MediaPeriod,
SequenceableLoader.Callback<ChunkSampleStream<DashChunkSource>> {
private final DataSource.Factory dataSourceFactory;
private final FormatEvaluator.Factory formatEvaluatorFactory;
private final DashChunkSource.Factory chunkSourceFactory;
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;
private final long elapsedRealtimeOffset;
......@@ -66,13 +63,11 @@ import java.util.List;
private Period period;
public DashMediaPeriod(MediaPresentationDescription manifest, int index,
DataSource.Factory dataSourceFactory, FormatEvaluator.Factory formatEvaluatorFactory,
int minLoadableRetryCount, EventDispatcher eventDispatcher, long elapsedRealtimeOffset,
Loader loader) {
DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount,
EventDispatcher eventDispatcher, long elapsedRealtimeOffset, Loader loader) {
this.manifest = manifest;
this.index = index;
this.dataSourceFactory = dataSourceFactory;
this.formatEvaluatorFactory = formatEvaluatorFactory;
this.chunkSourceFactory = chunkSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventDispatcher = eventDispatcher;
this.elapsedRealtimeOffset = elapsedRealtimeOffset;
......@@ -242,16 +237,12 @@ import java.util.List;
private ChunkSampleStream<DashChunkSource> buildSampleStream(TrackSelection selection,
long positionUs) {
int[] selectedTracks = selection.getTracks();
FormatEvaluator adaptiveEvaluator = selectedTracks.length > 1
? formatEvaluatorFactory.createFormatEvaluator() : null;
int adaptationSetIndex = trackGroupAdaptationSetIndices[selection.group];
AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
int adaptationSetType = adaptationSet.type;
DataSource dataSource = dataSourceFactory.createDataSource();
DashChunkSource chunkSource = new DashChunkSource(loader, manifest, index, adaptationSetIndex,
trackGroups.get(selection.group), selectedTracks, dataSource, adaptiveEvaluator,
DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(loader, manifest, index,
adaptationSetIndex, trackGroups.get(selection.group), selectedTracks,
elapsedRealtimeOffset);
return new ChunkSampleStream<>(adaptationSetType, chunkSource, this, allocator, positionUs,
return new ChunkSampleStream<>(adaptationSet.type, chunkSource, this, allocator, positionUs,
minLoadableRetryCount, eventDispatcher);
}
......
......@@ -21,7 +21,6 @@ import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator;
import com.google.android.exoplayer2.source.dash.mpd.MediaPresentationDescription;
import com.google.android.exoplayer2.source.dash.mpd.MediaPresentationDescriptionParser;
import com.google.android.exoplayer2.source.dash.mpd.UtcTimingElement;
......@@ -56,8 +55,8 @@ public final class DashMediaSource implements MediaSource {
private static final String TAG = "DashMediaSource";
private final DataSource.Factory dataSourceFactory;
private final FormatEvaluator.Factory formatEvaluatorFactory;
private final DataSource.Factory manifestDataSourceFactory;
private final DashChunkSource.Factory chunkSourceFactory;
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;
private final MediaPresentationDescriptionParser manifestParser;
......@@ -74,19 +73,19 @@ public final class DashMediaSource implements MediaSource {
private DashMediaPeriod[] periods;
private long elapsedRealtimeOffset;
public DashMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
FormatEvaluator.Factory formatEvaluatorFactory, Handler eventHandler,
public DashMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory,
DashChunkSource.Factory chunkSourceFactory, Handler eventHandler,
AdaptiveMediaSourceEventListener eventListener) {
this(manifestUri, dataSourceFactory, formatEvaluatorFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT,
eventHandler, eventListener);
this(manifestUri, manifestDataSourceFactory, chunkSourceFactory,
DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler, eventListener);
}
public DashMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
FormatEvaluator.Factory formatEvaluatorFactory, int minLoadableRetryCount,
public DashMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory,
DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount,
Handler eventHandler, AdaptiveMediaSourceEventListener eventListener) {
this.manifestUri = manifestUri;
this.dataSourceFactory = dataSourceFactory;
this.formatEvaluatorFactory = formatEvaluatorFactory;
this.manifestDataSourceFactory = manifestDataSourceFactory;
this.chunkSourceFactory = chunkSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
manifestParser = new MediaPresentationDescriptionParser();
......@@ -97,7 +96,7 @@ public final class DashMediaSource implements MediaSource {
@Override
public void prepareSource() {
dataSource = dataSourceFactory.createDataSource();
dataSource = manifestDataSourceFactory.createDataSource();
loader = new Loader("Loader:DashMediaSource");
manifestRefreshHandler = new Handler();
startLoadingManifest();
......@@ -244,8 +243,8 @@ public final class DashMediaSource implements MediaSource {
int periodCount = manifest.getPeriodCount();
periods = new DashMediaPeriod[periodCount];
for (int i = 0; i < periodCount; i++) {
periods[i] = new DashMediaPeriod(manifest, i, dataSourceFactory, formatEvaluatorFactory,
minLoadableRetryCount, eventDispatcher, elapsedRealtimeOffset, loader);
periods[i] = new DashMediaPeriod(manifest, i, chunkSourceFactory, minLoadableRetryCount,
eventDispatcher, elapsedRealtimeOffset, loader);
}
scheduleManifestRefresh();
}
......
......@@ -29,7 +29,6 @@ import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.chunk.ChunkSampleStream;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator;
import com.google.android.exoplayer2.source.smoothstreaming.SmoothStreamingManifest.ProtectionElement;
import com.google.android.exoplayer2.source.smoothstreaming.SmoothStreamingManifest.StreamElement;
import com.google.android.exoplayer2.trackselection.TrackSelection;
......@@ -66,7 +65,7 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
private final Uri manifestUri;
private final DataSource.Factory dataSourceFactory;
private final FormatEvaluator.Factory formatEvaluatorFactory;
private final SmoothStreamingChunkSource.Factory chunkSourceFactory;
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;
private final SmoothStreamingManifestParser manifestParser;
......@@ -88,20 +87,20 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
private TrackGroupArray trackGroups;
private int[] trackGroupElementIndices;
public SmoothStreamingMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
FormatEvaluator.Factory formatEvaluatorFactory, Handler eventHandler,
public SmoothStreamingMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory,
SmoothStreamingChunkSource.Factory chunkSourceFactory, Handler eventHandler,
AdaptiveMediaSourceEventListener eventListener) {
this(manifestUri, dataSourceFactory, formatEvaluatorFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT,
eventHandler, eventListener);
this(manifestUri, manifestDataSourceFactory, chunkSourceFactory,
DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler, eventListener);
}
public SmoothStreamingMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
FormatEvaluator.Factory formatEvaluatorFactory, int minLoadableRetryCount,
SmoothStreamingChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount,
Handler eventHandler, AdaptiveMediaSourceEventListener eventListener) {
this.manifestUri = Util.toLowerInvariant(manifestUri.getLastPathSegment()).equals("manifest")
? manifestUri : Uri.withAppendedPath(manifestUri, "Manifest");
this.dataSourceFactory = dataSourceFactory;
this.formatEvaluatorFactory = formatEvaluatorFactory;
this.chunkSourceFactory = chunkSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventDispatcher = new EventDispatcher(eventHandler, eventListener);
manifestParser = new SmoothStreamingManifestParser();
......@@ -354,17 +353,12 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
private ChunkSampleStream<SmoothStreamingChunkSource> buildSampleStream(TrackSelection selection,
long positionUs) {
int[] selectedTracks = selection.getTracks();
FormatEvaluator adaptiveEvaluator = selectedTracks.length > 1
? formatEvaluatorFactory.createFormatEvaluator() : null;
int streamElementIndex = trackGroupElementIndices[selection.group];
StreamElement streamElement = manifest.streamElements[streamElementIndex];
int streamElementType = streamElement.type;
DataSource dataSource = dataSourceFactory.createDataSource();
SmoothStreamingChunkSource chunkSource = new SmoothStreamingChunkSource(manifestLoader,
manifest, streamElementIndex, trackGroups.get(selection.group), selectedTracks, dataSource,
adaptiveEvaluator, trackEncryptionBoxes);
return new ChunkSampleStream<>(streamElementType, chunkSource, this, allocator, positionUs,
minLoadableRetryCount, eventDispatcher);
SmoothStreamingChunkSource chunkSource = chunkSourceFactory.createChunkSource(manifestLoader,
manifest, streamElementIndex, trackGroups.get(selection.group), selectedTracks,
trackEncryptionBoxes);
return new ChunkSampleStream<>(manifest.streamElements[streamElementIndex].type, chunkSource,
this, allocator, positionUs, minLoadableRetryCount, eventDispatcher);
}
@SuppressWarnings("unchecked")
......
......@@ -34,6 +34,7 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator;
import com.google.android.exoplayer2.source.chunk.FormatEvaluator.AdaptiveEvaluator;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
......@@ -423,12 +424,15 @@ public final class DashTest extends ActivityInstrumentationTestCase2<HostActivit
@Override
public MediaSource buildSource(HostActivity host, String userAgent) {
DataSource.Factory manifestDataSourceFactory = new DefaultDataSourceFactory(host, userAgent);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(host, userAgent,
DataSource.Factory mediaDataSourceFactory = new DefaultDataSourceFactory(host, userAgent,
bandwidthMeter);
FormatEvaluator.Factory formatEvaluatorFactory = new AdaptiveEvaluator.Factory(
bandwidthMeter);
return new DashMediaSource(manifestUri, dataSourceFactory, formatEvaluatorFactory,
DefaultDashChunkSource.Factory chunkSourceFactory = new DefaultDashChunkSource.Factory(
mediaDataSourceFactory, formatEvaluatorFactory);
return new DashMediaSource(manifestUri, manifestDataSourceFactory, chunkSourceFactory,
MIN_LOADABLE_RETRY_COUNT, null, null);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment