|
|
@ -1,8 +1,29 @@ |
|
|
|
package io.legado.app.help.exoplayer; |
|
|
|
package io.legado.app.help.exoplayer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* Copyright (C) 2016 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; |
|
|
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; |
|
|
|
import static com.google.android.exoplayer2.util.Util.castNonNull; |
|
|
|
import static com.google.android.exoplayer2.util.Util.castNonNull; |
|
|
|
import static java.lang.Math.min; |
|
|
|
import static java.lang.Math.min; |
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.FIELD; |
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.LOCAL_VARIABLE; |
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.METHOD; |
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.PARAMETER; |
|
|
|
|
|
|
|
import static java.lang.annotation.ElementType.TYPE_USE; |
|
|
|
|
|
|
|
|
|
|
|
import android.net.Uri; |
|
|
|
import android.net.Uri; |
|
|
|
|
|
|
|
|
|
|
@ -37,10 +58,12 @@ import java.io.InterruptedIOException; |
|
|
|
import java.lang.annotation.Documented; |
|
|
|
import java.lang.annotation.Documented; |
|
|
|
import java.lang.annotation.Retention; |
|
|
|
import java.lang.annotation.Retention; |
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
|
|
|
|
import java.lang.annotation.Target; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A {@link DataSource} that reads and writes a {@link Cache}. Requests are fulfilled from the cache |
|
|
|
* A {@link DataSource} that reads and writes a {@link Cache}. Requests are fulfilled from the cache |
|
|
|
* when possible. When data is not cached it is requested from an upstream {@link DataSource} and |
|
|
|
* when possible. When data is not cached it is requested from an upstream {@link DataSource} and |
|
|
@ -66,8 +89,7 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private PriorityTaskManager upstreamPriorityTaskManager; |
|
|
|
private PriorityTaskManager upstreamPriorityTaskManager; |
|
|
|
private int upstreamPriority; |
|
|
|
private int upstreamPriority; |
|
|
|
@OkhttpCacheDataSource.Flags |
|
|
|
private @OkhttpCacheDataSource.Flags int flags; |
|
|
|
private int flags; |
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private OkhttpCacheDataSource.EventListener eventListener; |
|
|
|
private OkhttpCacheDataSource.EventListener eventListener; |
|
|
|
|
|
|
|
|
|
|
@ -351,6 +373,7 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Documented |
|
|
|
@Documented |
|
|
|
@Retention(RetentionPolicy.SOURCE) |
|
|
|
@Retention(RetentionPolicy.SOURCE) |
|
|
|
|
|
|
|
@Target(TYPE_USE) |
|
|
|
@IntDef( |
|
|
|
@IntDef( |
|
|
|
flag = true, |
|
|
|
flag = true, |
|
|
|
value = { |
|
|
|
value = { |
|
|
@ -384,8 +407,11 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
* Reasons the cache may be ignored. One of {@link #CACHE_IGNORED_REASON_ERROR} or {@link |
|
|
|
* Reasons the cache may be ignored. One of {@link #CACHE_IGNORED_REASON_ERROR} or {@link |
|
|
|
* #CACHE_IGNORED_REASON_UNSET_LENGTH}. |
|
|
|
* #CACHE_IGNORED_REASON_UNSET_LENGTH}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
// @Target list includes both 'default' targets and TYPE_USE, to ensure backwards compatibility
|
|
|
|
|
|
|
|
// with Kotlin usages from before TYPE_USE was added.
|
|
|
|
@Documented |
|
|
|
@Documented |
|
|
|
@Retention(RetentionPolicy.SOURCE) |
|
|
|
@Retention(RetentionPolicy.SOURCE) |
|
|
|
|
|
|
|
@Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) |
|
|
|
@IntDef({CACHE_IGNORED_REASON_ERROR, CACHE_IGNORED_REASON_UNSET_LENGTH}) |
|
|
|
@IntDef({CACHE_IGNORED_REASON_ERROR, CACHE_IGNORED_REASON_UNSET_LENGTH}) |
|
|
|
public @interface CacheIgnoredReason { |
|
|
|
public @interface CacheIgnoredReason { |
|
|
|
} |
|
|
|
} |
|
|
@ -641,15 +667,15 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int read(@NonNull byte[] buffer, int offset, int length) throws IOException { |
|
|
|
public int read(byte[] buffer, int offset, int length) throws IOException { |
|
|
|
DataSpec requestDataSpec = checkNotNull(this.requestDataSpec); |
|
|
|
|
|
|
|
DataSpec currentDataSpec = checkNotNull(this.currentDataSpec); |
|
|
|
|
|
|
|
if (length == 0) { |
|
|
|
if (length == 0) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
if (bytesRemaining == 0) { |
|
|
|
if (bytesRemaining == 0) { |
|
|
|
return C.RESULT_END_OF_INPUT; |
|
|
|
return C.RESULT_END_OF_INPUT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DataSpec requestDataSpec = checkNotNull(this.requestDataSpec); |
|
|
|
|
|
|
|
DataSpec currentDataSpec = checkNotNull(this.currentDataSpec); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (readPosition >= checkCachePosition) { |
|
|
|
if (readPosition >= checkCachePosition) { |
|
|
|
openNextSource(requestDataSpec, true); |
|
|
|
openNextSource(requestDataSpec, true); |
|
|
@ -683,9 +709,8 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Nullable |
|
|
|
public Uri getUri() { |
|
|
|
public Uri getUri() { |
|
|
|
return actualUri; |
|
|
|
return actualUri; |
|
|
|
} |
|
|
|
} |
|
|
@ -693,6 +718,7 @@ public final class OkhttpCacheDataSource implements DataSource { |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, List<String>> getResponseHeaders() { |
|
|
|
public Map<String, List<String>> getResponseHeaders() { |
|
|
|
|
|
|
|
// TODO: Implement.
|
|
|
|
return isReadingFromUpstream() |
|
|
|
return isReadingFromUpstream() |
|
|
|
? upstreamDataSource.getResponseHeaders() |
|
|
|
? upstreamDataSource.getResponseHeaders() |
|
|
|
: Collections.emptyMap(); |
|
|
|
: Collections.emptyMap(); |
|
|
|