From 3a54d744b94f38e626af696d7083d71b679d3494 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 23 Jan 2019 10:51:02 +0000 Subject: [PATCH] Default to respecting the DataSpec cache fragmentation flag Issue: #4253 PiperOrigin-RevId: 230497544 --- .../offline/DownloaderConstructorHelper.java | 4 +--- .../upstream/cache/CacheDataSink.java | 20 +------------------ .../upstream/cache/CacheDataSinkFactory.java | 13 ------------ 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java index 59a11934b19..48e70e37fcc 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java @@ -110,10 +110,8 @@ public DownloaderConstructorHelper( ? cacheReadDataSourceFactory : new FileDataSourceFactory(); if (cacheWriteDataSinkFactory == null) { - CacheDataSinkFactory factory = + cacheWriteDataSinkFactory = new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE); - factory.experimental_setRespectCacheFragmentationFlag(true); - cacheWriteDataSinkFactory = factory; } onlineCacheDataSourceFactory = new CacheDataSourceFactory( diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java index d527805120b..2caf4c92f89 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java @@ -50,7 +50,6 @@ public final class CacheDataSink implements DataSink { private final int bufferSize; private boolean syncFileDescriptor; - private boolean respectCacheFragmentationFlag; private DataSpec dataSpec; private long dataSpecFragmentSize; private File file; @@ -123,20 +122,6 @@ public void experimental_setSyncFileDescriptor(boolean syncFileDescriptor) { this.syncFileDescriptor = syncFileDescriptor; } - /** - * Sets whether this instance respects the {@link DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag. - * If set to {@code false} requests will always be fragmented. If set to {@code true} requests - * will be fragmented only if the flag is set. - * - *

This method is experimental, and will be renamed or removed in a future release. - * - * @param respectCacheFragmentationFlag Whether to respect the {@link - * DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag. - */ - public void experimental_setRespectCacheFragmentationFlag(boolean respectCacheFragmentationFlag) { - this.respectCacheFragmentationFlag = respectCacheFragmentationFlag; - } - @Override public void open(DataSpec dataSpec) throws CacheDataSinkException { if (dataSpec.length == C.LENGTH_UNSET @@ -146,10 +131,7 @@ public void open(DataSpec dataSpec) throws CacheDataSinkException { } this.dataSpec = dataSpec; this.dataSpecFragmentSize = - !respectCacheFragmentationFlag - || dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) - ? fragmentSize - : Long.MAX_VALUE; + dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE; dataSpecBytesWritten = 0; try { openNextOutputStream(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java index 9540597c2ef..856e9db168e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java @@ -27,7 +27,6 @@ public final class CacheDataSinkFactory implements DataSink.Factory { private final int bufferSize; private boolean syncFileDescriptor; - private boolean respectCacheFragmentationFlag; /** @see CacheDataSink#CacheDataSink(Cache, long) */ public CacheDataSinkFactory(Cache cache, long fragmentSize) { @@ -51,22 +50,10 @@ public CacheDataSinkFactory experimental_setSyncFileDescriptor(boolean syncFileD return this; } - /** - * See {@link CacheDataSink#experimental_setRespectCacheFragmentationFlag(boolean)}. - * - *

This method is experimental, and will be renamed or removed in a future release. - */ - public CacheDataSinkFactory experimental_setRespectCacheFragmentationFlag( - boolean respectCacheFragmentationFlag) { - this.respectCacheFragmentationFlag = respectCacheFragmentationFlag; - return this; - } - @Override public DataSink createDataSink() { CacheDataSink dataSink = new CacheDataSink(cache, fragmentSize, bufferSize); dataSink.experimental_setSyncFileDescriptor(syncFileDescriptor); - dataSink.experimental_setRespectCacheFragmentationFlag(respectCacheFragmentationFlag); return dataSink; } }