Commit 4c39627e by olly Committed by Oliver Woodman

Some minor cleanup related to track selection and caching

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155103828
parent ba9cbfbb
...@@ -261,10 +261,10 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -261,10 +261,10 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this,
drmSessionManager, extensionRendererMode); drmSessionManager, extensionRendererMode);
TrackSelection.Factory videoTrackSelectionFactory = TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory);
lastSeenTrackGroupArray = null; lastSeenTrackGroupArray = null;
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector); player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
......
...@@ -24,6 +24,7 @@ import com.google.android.exoplayer2.Format; ...@@ -24,6 +24,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -376,10 +377,21 @@ public class DefaultTrackSelector extends MappingTrackSelector { ...@@ -376,10 +377,21 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private final AtomicReference<Parameters> paramsReference; private final AtomicReference<Parameters> paramsReference;
/** /**
* Constructs an instance that does not support adaptive tracks. * Constructs an instance that does not support adaptive track selection.
*/ */
public DefaultTrackSelector() { public DefaultTrackSelector() {
this(null); this((TrackSelection.Factory) null);
}
/**
* Constructs an instance that supports adaptive track selection. Adaptive track selections use
* the provided {@link BandwidthMeter} to determine which individual track should be used during
* playback.
*
* @param bandwidthMeter The {@link BandwidthMeter}.
*/
public DefaultTrackSelector(BandwidthMeter bandwidthMeter) {
this(new AdaptiveTrackSelection.Factory(bandwidthMeter));
} }
/** /**
......
...@@ -54,8 +54,8 @@ public final class CacheDataSource implements DataSource { ...@@ -54,8 +54,8 @@ public final class CacheDataSource implements DataSource {
FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}) FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS})
public @interface Flags {} public @interface Flags {}
/** /**
* A flag indicating whether we will block reads if the cache key is locked. If this flag is * A flag indicating whether we will block reads if the cache key is locked. If unset then data is
* set, then we will read from upstream if the cache key is locked. * read from upstream if the cache key is locked, regardless of whether the data is cached.
*/ */
public static final int FLAG_BLOCK_ON_CACHE = 1 << 0; public static final int FLAG_BLOCK_ON_CACHE = 1 << 0;
...@@ -110,7 +110,23 @@ public final class CacheDataSource implements DataSource { ...@@ -110,7 +110,23 @@ public final class CacheDataSource implements DataSource {
/** /**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache and with {@link #DEFAULT_MAX_CACHE_FILE_SIZE}. * reading and writing the cache.
*
* @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache.
*/
public CacheDataSource(Cache cache, DataSource upstream) {
this(cache, upstream, 0, DEFAULT_MAX_CACHE_FILE_SIZE);
}
/**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache.
*
* @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
* and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
*/ */
public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) { public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) {
this(cache, upstream, flags, DEFAULT_MAX_CACHE_FILE_SIZE); this(cache, upstream, flags, DEFAULT_MAX_CACHE_FILE_SIZE);
...@@ -123,8 +139,8 @@ public final class CacheDataSource implements DataSource { ...@@ -123,8 +139,8 @@ public final class CacheDataSource implements DataSource {
* *
* @param cache The cache. * @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache. * @param upstream A {@link DataSource} for reading data not in the cache.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE} and {@link * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
* #FLAG_IGNORE_CACHE_ON_ERROR} or 0. * and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size * @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size
* exceeds this value, then the data will be fragmented into multiple cache files. The * exceeds this value, then the data will be fragmented into multiple cache files. The
* finer-grained this is the finer-grained the eviction policy can be. * finer-grained this is the finer-grained the eviction policy can be.
...@@ -145,8 +161,8 @@ public final class CacheDataSource implements DataSource { ...@@ -145,8 +161,8 @@ public final class CacheDataSource implements DataSource {
* @param cacheReadDataSource A {@link DataSource} for reading data from the cache. * @param cacheReadDataSource A {@link DataSource} for reading data from the cache.
* @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is * @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is
* accessed read-only. * accessed read-only.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE} and {@link * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
* #FLAG_IGNORE_CACHE_ON_ERROR} or 0. * and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
* @param eventListener An optional {@link EventListener} to receive events. * @param eventListener An optional {@link EventListener} to receive events.
*/ */
public CacheDataSource(Cache cache, DataSource upstream, DataSource cacheReadDataSource, public CacheDataSource(Cache cache, DataSource upstream, DataSource cacheReadDataSource,
......
...@@ -34,17 +34,25 @@ public final class CacheDataSourceFactory implements DataSource.Factory { ...@@ -34,17 +34,25 @@ public final class CacheDataSourceFactory implements DataSource.Factory {
private final EventListener eventListener; private final EventListener eventListener;
/** /**
* @see CacheDataSource#CacheDataSource(Cache, DataSource)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory) {
this(cache, upstreamFactory, 0);
}
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int) * @see CacheDataSource#CacheDataSource(Cache, DataSource, int)
*/ */
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory, int flags) { public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory,
@CacheDataSource.Flags int flags) {
this(cache, upstreamFactory, flags, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE); this(cache, upstreamFactory, flags, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
} }
/** /**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long) * @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long)
*/ */
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory, int flags, public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory,
long maxCacheFileSize) { @CacheDataSource.Flags int flags, long maxCacheFileSize) {
this(cache, upstreamFactory, new FileDataSourceFactory(), this(cache, upstreamFactory, new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null); new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null);
} }
...@@ -54,8 +62,8 @@ public final class CacheDataSourceFactory implements DataSource.Factory { ...@@ -54,8 +62,8 @@ public final class CacheDataSourceFactory implements DataSource.Factory {
* EventListener) * EventListener)
*/ */
public CacheDataSourceFactory(Cache cache, Factory upstreamFactory, public CacheDataSourceFactory(Cache cache, Factory upstreamFactory,
Factory cacheReadDataSourceFactory, Factory cacheReadDataSourceFactory, DataSink.Factory cacheWriteDataSinkFactory,
DataSink.Factory cacheWriteDataSinkFactory, int flags, EventListener eventListener) { @CacheDataSource.Flags int flags, EventListener eventListener) {
this.cache = cache; this.cache = cache;
this.upstreamFactory = upstreamFactory; this.upstreamFactory = upstreamFactory;
this.cacheReadDataSourceFactory = cacheReadDataSourceFactory; this.cacheReadDataSourceFactory = cacheReadDataSourceFactory;
......
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