mirror of
https://github.com/androidx/media.git
synced 2025-05-06 07:00:19 +08:00
Add flag to CacheDataSource to disable caching unset length requests.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=139377417
This commit is contained in:
parent
d6eb9cb79f
commit
92d34cd877
@ -49,7 +49,8 @@ public final class CacheDataSource implements DataSource {
|
|||||||
* Flags controlling the cache's behavior.
|
* Flags controlling the cache's behavior.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef(flag = true, value = {FLAG_BLOCK_ON_CACHE, FLAG_IGNORE_CACHE_ON_ERROR})
|
@IntDef(flag = true, value = {FLAG_BLOCK_ON_CACHE, FLAG_IGNORE_CACHE_ON_ERROR,
|
||||||
|
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 this flag is
|
||||||
@ -64,6 +65,11 @@ public final class CacheDataSource implements DataSource {
|
|||||||
*/
|
*/
|
||||||
public static final int FLAG_IGNORE_CACHE_ON_ERROR = 1 << 1;
|
public static final int FLAG_IGNORE_CACHE_ON_ERROR = 1 << 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating that the cache should be bypassed for requests whose lengths are unset.
|
||||||
|
*/
|
||||||
|
public static final int FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS = 1 << 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener of {@link CacheDataSource} events.
|
* Listener of {@link CacheDataSource} events.
|
||||||
*/
|
*/
|
||||||
@ -87,6 +93,7 @@ public final class CacheDataSource implements DataSource {
|
|||||||
|
|
||||||
private final boolean blockOnCache;
|
private final boolean blockOnCache;
|
||||||
private final boolean ignoreCacheOnError;
|
private final boolean ignoreCacheOnError;
|
||||||
|
private final boolean ignoreCacheForUnsetLengthRequests;
|
||||||
|
|
||||||
private DataSource currentDataSource;
|
private DataSource currentDataSource;
|
||||||
private boolean currentRequestUnbounded;
|
private boolean currentRequestUnbounded;
|
||||||
@ -146,6 +153,8 @@ public final class CacheDataSource implements DataSource {
|
|||||||
this.cacheReadDataSource = cacheReadDataSource;
|
this.cacheReadDataSource = cacheReadDataSource;
|
||||||
this.blockOnCache = (flags & FLAG_BLOCK_ON_CACHE) != 0;
|
this.blockOnCache = (flags & FLAG_BLOCK_ON_CACHE) != 0;
|
||||||
this.ignoreCacheOnError = (flags & FLAG_IGNORE_CACHE_ON_ERROR) != 0;
|
this.ignoreCacheOnError = (flags & FLAG_IGNORE_CACHE_ON_ERROR) != 0;
|
||||||
|
this.ignoreCacheForUnsetLengthRequests =
|
||||||
|
(flags & FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS) != 0;
|
||||||
this.upstreamDataSource = upstream;
|
this.upstreamDataSource = upstream;
|
||||||
if (cacheWriteDataSink != null) {
|
if (cacheWriteDataSink != null) {
|
||||||
this.cacheWriteDataSource = new TeeDataSource(upstream, cacheWriteDataSink);
|
this.cacheWriteDataSource = new TeeDataSource(upstream, cacheWriteDataSink);
|
||||||
@ -162,7 +171,8 @@ public final class CacheDataSource implements DataSource {
|
|||||||
flags = dataSpec.flags;
|
flags = dataSpec.flags;
|
||||||
key = dataSpec.key != null ? dataSpec.key : uri.toString();
|
key = dataSpec.key != null ? dataSpec.key : uri.toString();
|
||||||
readPosition = dataSpec.position;
|
readPosition = dataSpec.position;
|
||||||
currentRequestIgnoresCache = ignoreCacheOnError && seenCacheError;
|
currentRequestIgnoresCache = (ignoreCacheOnError && seenCacheError)
|
||||||
|
|| (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests);
|
||||||
if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
|
if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
|
||||||
bytesRemaining = dataSpec.length;
|
bytesRemaining = dataSpec.length;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user