Add Discord community version (64-bit only)

- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
This commit is contained in:
2026-02-18 15:48:36 -08:00
parent c19eb3d7ff
commit c080f0d97f
26930 changed files with 2529574 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.NavigableSet;
import java.util.Set;
/* loaded from: classes4.dex */
public interface Cache {
public interface Listener {
void onSpanAdded(Cache cache, CacheSpan cacheSpan);
void onSpanRemoved(Cache cache, CacheSpan cacheSpan);
void onSpanTouched(Cache cache, CacheSpan cacheSpan, CacheSpan cacheSpan2);
}
@NonNull
NavigableSet<CacheSpan> addListener(String str, Listener listener);
void applyContentMetadataMutations(String str, ContentMetadataMutations contentMetadataMutations) throws CacheException;
void commitFile(File file) throws CacheException;
long getCacheSpace();
long getCachedLength(String str, long j, long j2);
@NonNull
NavigableSet<CacheSpan> getCachedSpans(String str);
long getContentLength(String str);
ContentMetadata getContentMetadata(String str);
Set<String> getKeys();
boolean isCached(String str, long j, long j2);
void release() throws CacheException;
void releaseHoleSpan(CacheSpan cacheSpan);
void removeListener(String str, Listener listener);
void removeSpan(CacheSpan cacheSpan) throws CacheException;
void setContentLength(String str, long j) throws CacheException;
File startFile(String str, long j, long j2) throws CacheException;
CacheSpan startReadWrite(String str, long j) throws InterruptedException, CacheException;
@Nullable
CacheSpan startReadWriteNonBlocking(String str, long j) throws CacheException;
public static class CacheException extends IOException {
public CacheException(String str) {
super(str);
}
public CacheException(Throwable th) {
super(th);
}
}
}

View File

@@ -0,0 +1,151 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.ReusableBufferedOutputStream;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/* loaded from: classes4.dex */
public final class CacheDataSink implements DataSink {
public static final int DEFAULT_BUFFER_SIZE = 20480;
private final int bufferSize;
private ReusableBufferedOutputStream bufferedOutputStream;
private final Cache cache;
private DataSpec dataSpec;
private long dataSpecBytesWritten;
private File file;
private final long maxCacheFileSize;
private OutputStream outputStream;
private long outputStreamBytesWritten;
private final boolean syncFileDescriptor;
private FileOutputStream underlyingFileOutputStream;
public static class CacheDataSinkException extends Cache.CacheException {
public CacheDataSinkException(IOException iOException) {
super(iOException);
}
}
public CacheDataSink(Cache cache, long j) {
this(cache, j, DEFAULT_BUFFER_SIZE, true);
}
public CacheDataSink(Cache cache, long j, boolean z) {
this(cache, j, DEFAULT_BUFFER_SIZE, z);
}
public CacheDataSink(Cache cache, long j, int i) {
this(cache, j, i, true);
}
public CacheDataSink(Cache cache, long j, int i, boolean z) {
this.cache = (Cache) Assertions.checkNotNull(cache);
this.maxCacheFileSize = j;
this.bufferSize = i;
this.syncFileDescriptor = z;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void open(DataSpec dataSpec) throws CacheDataSinkException {
if (dataSpec.length == -1 && !dataSpec.isFlagSet(2)) {
this.dataSpec = null;
return;
}
this.dataSpec = dataSpec;
this.dataSpecBytesWritten = 0L;
try {
openNextOutputStream();
} catch (IOException e) {
throw new CacheDataSinkException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void write(byte[] bArr, int i, int i2) throws CacheDataSinkException {
if (this.dataSpec == null) {
return;
}
int i3 = 0;
while (i3 < i2) {
try {
if (this.outputStreamBytesWritten == this.maxCacheFileSize) {
closeCurrentOutputStream();
openNextOutputStream();
}
int min = (int) Math.min(i2 - i3, this.maxCacheFileSize - this.outputStreamBytesWritten);
this.outputStream.write(bArr, i + i3, min);
i3 += min;
long j = min;
this.outputStreamBytesWritten += j;
this.dataSpecBytesWritten += j;
} catch (IOException e) {
throw new CacheDataSinkException(e);
}
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void close() throws CacheDataSinkException {
if (this.dataSpec == null) {
return;
}
try {
closeCurrentOutputStream();
} catch (IOException e) {
throw new CacheDataSinkException(e);
}
}
private void openNextOutputStream() throws IOException {
long j = this.dataSpec.length;
long min = j == -1 ? this.maxCacheFileSize : Math.min(j - this.dataSpecBytesWritten, this.maxCacheFileSize);
Cache cache = this.cache;
DataSpec dataSpec = this.dataSpec;
this.file = cache.startFile(dataSpec.key, this.dataSpecBytesWritten + dataSpec.absoluteStreamPosition, min);
FileOutputStream fileOutputStream = new FileOutputStream(this.file);
this.underlyingFileOutputStream = fileOutputStream;
if (this.bufferSize > 0) {
ReusableBufferedOutputStream reusableBufferedOutputStream = this.bufferedOutputStream;
if (reusableBufferedOutputStream == null) {
this.bufferedOutputStream = new ReusableBufferedOutputStream(this.underlyingFileOutputStream, this.bufferSize);
} else {
reusableBufferedOutputStream.reset(fileOutputStream);
}
this.outputStream = this.bufferedOutputStream;
} else {
this.outputStream = fileOutputStream;
}
this.outputStreamBytesWritten = 0L;
}
private void closeCurrentOutputStream() throws IOException {
OutputStream outputStream = this.outputStream;
if (outputStream == null) {
return;
}
try {
outputStream.flush();
if (this.syncFileDescriptor) {
this.underlyingFileOutputStream.getFD().sync();
}
Util.closeQuietly(this.outputStream);
this.outputStream = null;
File file = this.file;
this.file = null;
this.cache.commitFile(file);
} catch (Throwable th) {
Util.closeQuietly(this.outputStream);
this.outputStream = null;
File file2 = this.file;
this.file = null;
file2.delete();
throw th;
}
}
}

View File

@@ -0,0 +1,25 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
/* loaded from: classes4.dex */
public final class CacheDataSinkFactory implements DataSink.Factory {
private final int bufferSize;
private final Cache cache;
private final long maxCacheFileSize;
public CacheDataSinkFactory(Cache cache, long j) {
this(cache, j, CacheDataSink.DEFAULT_BUFFER_SIZE);
}
public CacheDataSinkFactory(Cache cache, long j, int i) {
this.cache = cache;
this.maxCacheFileSize = j;
this.bufferSize = i;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink.Factory
public final DataSink createDataSink() {
return new CacheDataSink(this.cache, this.maxCacheFileSize, this.bufferSize);
}
}

View File

@@ -0,0 +1,370 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSourceException;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.FileDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.TeeDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/* loaded from: classes4.dex */
public final class CacheDataSource implements DataSource {
public static final int CACHE_IGNORED_REASON_ERROR = 0;
public static final int CACHE_IGNORED_REASON_UNSET_LENGTH = 1;
private static final int CACHE_NOT_IGNORED = -1;
public static final long DEFAULT_MAX_CACHE_FILE_SIZE = 2097152;
public static final int FLAG_BLOCK_ON_CACHE = 1;
public static final int FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS = 4;
public static final int FLAG_IGNORE_CACHE_ON_ERROR = 2;
private static final long MIN_READ_BEFORE_CHECKING_CACHE = 102400;
private Uri actualUri;
private final boolean blockOnCache;
private long bytesRemaining;
private final Cache cache;
private final DataSource cacheReadDataSource;
private final DataSource cacheWriteDataSource;
private long checkCachePosition;
private DataSource currentDataSource;
private boolean currentDataSpecLengthUnset;
private CacheSpan currentHoleSpan;
private boolean currentRequestIgnoresCache;
@Nullable
private final EventListener eventListener;
private int flags;
private final boolean ignoreCacheForUnsetLengthRequests;
private final boolean ignoreCacheOnError;
private String key;
private long readPosition;
private boolean seenCacheError;
private long totalCachedBytesRead;
private final DataSource upstreamDataSource;
private Uri uri;
@Retention(RetentionPolicy.SOURCE)
public @interface CacheIgnoredReason {
}
public interface EventListener {
void onCacheIgnored(int i);
void onCachedBytesRead(long j, long j2);
}
@Retention(RetentionPolicy.SOURCE)
public @interface Flags {
}
private boolean isBypassingCache() {
return this.currentDataSource == this.upstreamDataSource;
}
private boolean isReadingFromCache() {
return this.currentDataSource == this.cacheReadDataSource;
}
private boolean isWritingToCache() {
return this.currentDataSource == this.cacheWriteDataSource;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.actualUri;
}
public CacheDataSource(Cache cache, DataSource dataSource) {
this(cache, dataSource, 0, 2097152L);
}
public CacheDataSource(Cache cache, DataSource dataSource, int i) {
this(cache, dataSource, i, 2097152L);
}
public CacheDataSource(Cache cache, DataSource dataSource, int i, long j) {
this(cache, dataSource, new FileDataSource(), new CacheDataSink(cache, j), i, null);
}
public CacheDataSource(Cache cache, DataSource dataSource, DataSource dataSource2, DataSink dataSink, int i, @Nullable EventListener eventListener) {
this.cache = cache;
this.cacheReadDataSource = dataSource2;
this.blockOnCache = (i & 1) != 0;
this.ignoreCacheOnError = (i & 2) != 0;
this.ignoreCacheForUnsetLengthRequests = (i & 4) != 0;
this.upstreamDataSource = dataSource;
if (dataSink != null) {
this.cacheWriteDataSource = new TeeDataSource(dataSource, dataSink);
} else {
this.cacheWriteDataSource = null;
}
this.eventListener = eventListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
try {
String key = CacheUtil.getKey(dataSpec);
this.key = key;
Uri uri = dataSpec.uri;
this.uri = uri;
this.actualUri = getRedirectedUriOrDefault(this.cache, key, uri);
this.flags = dataSpec.flags;
this.readPosition = dataSpec.position;
int shouldIgnoreCacheForRequest = shouldIgnoreCacheForRequest(dataSpec);
boolean z = shouldIgnoreCacheForRequest != -1;
this.currentRequestIgnoresCache = z;
if (z) {
notifyCacheIgnored(shouldIgnoreCacheForRequest);
}
long j = dataSpec.length;
if (j == -1 && !this.currentRequestIgnoresCache) {
long contentLength = this.cache.getContentLength(this.key);
this.bytesRemaining = contentLength;
if (contentLength != -1) {
long j2 = contentLength - dataSpec.position;
this.bytesRemaining = j2;
if (j2 <= 0) {
throw new DataSourceException(0);
}
}
openNextSource(false);
return this.bytesRemaining;
}
this.bytesRemaining = j;
openNextSource(false);
return this.bytesRemaining;
} catch (IOException e) {
handleBeforeThrow(e);
throw e;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws IOException {
if (i2 == 0) {
return 0;
}
if (this.bytesRemaining == 0) {
return -1;
}
try {
if (this.readPosition >= this.checkCachePosition) {
openNextSource(true);
}
int read = this.currentDataSource.read(bArr, i, i2);
if (read != -1) {
if (isReadingFromCache()) {
this.totalCachedBytesRead += read;
}
long j = read;
this.readPosition += j;
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - j;
}
} else if (this.currentDataSpecLengthUnset) {
setNoBytesRemainingAndMaybeStoreLength();
} else {
long j3 = this.bytesRemaining;
if (j3 <= 0) {
if (j3 == -1) {
}
}
closeCurrentSource();
openNextSource(false);
return read(bArr, i, i2);
}
return read;
} catch (IOException e) {
if (this.currentDataSpecLengthUnset && isCausedByPositionOutOfRange(e)) {
setNoBytesRemainingAndMaybeStoreLength();
return -1;
}
handleBeforeThrow(e);
throw e;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
this.uri = null;
this.actualUri = null;
notifyBytesRead();
try {
closeCurrentSource();
} catch (IOException e) {
handleBeforeThrow(e);
throw e;
}
}
private void openNextSource(boolean z) throws IOException {
CacheSpan startReadWrite;
long j;
DataSpec dataSpec;
DataSource dataSource;
if (this.currentRequestIgnoresCache) {
startReadWrite = null;
} else if (this.blockOnCache) {
try {
startReadWrite = this.cache.startReadWrite(this.key, this.readPosition);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
throw new InterruptedIOException();
}
} else {
startReadWrite = this.cache.startReadWriteNonBlocking(this.key, this.readPosition);
}
if (startReadWrite == null) {
dataSource = this.upstreamDataSource;
dataSpec = new DataSpec(this.uri, this.readPosition, this.bytesRemaining, this.key, this.flags);
} else if (startReadWrite.isCached) {
Uri fromFile = Uri.fromFile(startReadWrite.file);
long j2 = this.readPosition - startReadWrite.position;
long j3 = startReadWrite.length - j2;
long j4 = this.bytesRemaining;
if (j4 != -1) {
j3 = Math.min(j3, j4);
}
dataSpec = new DataSpec(fromFile, this.readPosition, j2, j3, this.key, this.flags);
dataSource = this.cacheReadDataSource;
} else {
if (startReadWrite.isOpenEnded()) {
j = this.bytesRemaining;
} else {
j = startReadWrite.length;
long j5 = this.bytesRemaining;
if (j5 != -1) {
j = Math.min(j, j5);
}
}
DataSpec dataSpec2 = new DataSpec(this.uri, this.readPosition, j, this.key, this.flags);
DataSource dataSource2 = this.cacheWriteDataSource;
if (dataSource2 == null) {
dataSource2 = this.upstreamDataSource;
this.cache.releaseHoleSpan(startReadWrite);
startReadWrite = null;
}
dataSpec = dataSpec2;
dataSource = dataSource2;
}
this.checkCachePosition = (this.currentRequestIgnoresCache || dataSource != this.upstreamDataSource) ? Long.MAX_VALUE : this.readPosition + MIN_READ_BEFORE_CHECKING_CACHE;
if (z) {
Assertions.checkState(isBypassingCache());
if (dataSource == this.upstreamDataSource) {
return;
}
try {
closeCurrentSource();
} catch (Throwable th) {
if (startReadWrite.isHoleSpan()) {
this.cache.releaseHoleSpan(startReadWrite);
}
throw th;
}
}
if (startReadWrite != null && startReadWrite.isHoleSpan()) {
this.currentHoleSpan = startReadWrite;
}
this.currentDataSource = dataSource;
this.currentDataSpecLengthUnset = dataSpec.length == -1;
long open = dataSource.open(dataSpec);
ContentMetadataMutations contentMetadataMutations = new ContentMetadataMutations();
if (this.currentDataSpecLengthUnset && open != -1) {
this.bytesRemaining = open;
ContentMetadataInternal.setContentLength(contentMetadataMutations, this.readPosition + open);
}
if (isReadingFromUpstream()) {
Uri uri = this.currentDataSource.getUri();
this.actualUri = uri;
if (true ^ this.uri.equals(uri)) {
ContentMetadataInternal.setRedirectedUri(contentMetadataMutations, this.actualUri);
} else {
ContentMetadataInternal.removeRedirectedUri(contentMetadataMutations);
}
}
if (isWritingToCache()) {
this.cache.applyContentMetadataMutations(this.key, contentMetadataMutations);
}
}
private void setNoBytesRemainingAndMaybeStoreLength() throws IOException {
this.bytesRemaining = 0L;
if (isWritingToCache()) {
this.cache.setContentLength(this.key, this.readPosition);
}
}
private static Uri getRedirectedUriOrDefault(Cache cache, String str, Uri uri) {
Uri redirectedUri = ContentMetadataInternal.getRedirectedUri(cache.getContentMetadata(str));
return redirectedUri == null ? uri : redirectedUri;
}
private static boolean isCausedByPositionOutOfRange(IOException iOException) {
for (IOException iOException2 = iOException; iOException2 != null; iOException2 = iOException2.getCause()) {
if ((iOException2 instanceof DataSourceException) && ((DataSourceException) iOException2).reason == 0) {
return true;
}
}
return false;
}
private boolean isReadingFromUpstream() {
return !isReadingFromCache();
}
/* JADX WARN: Multi-variable type inference failed */
private void closeCurrentSource() throws IOException {
DataSource dataSource = this.currentDataSource;
if (dataSource == null) {
return;
}
try {
dataSource.close();
} finally {
this.currentDataSource = null;
this.currentDataSpecLengthUnset = false;
CacheSpan cacheSpan = this.currentHoleSpan;
if (cacheSpan != null) {
this.cache.releaseHoleSpan(cacheSpan);
this.currentHoleSpan = null;
}
}
}
private void handleBeforeThrow(IOException iOException) {
if (isReadingFromCache() || (iOException instanceof Cache.CacheException)) {
this.seenCacheError = true;
}
}
private int shouldIgnoreCacheForRequest(DataSpec dataSpec) {
if (this.ignoreCacheOnError && this.seenCacheError) {
return 0;
}
return (this.ignoreCacheForUnsetLengthRequests && dataSpec.length == -1) ? 1 : -1;
}
private void notifyCacheIgnored(int i) {
EventListener eventListener = this.eventListener;
if (eventListener != null) {
eventListener.onCacheIgnored(i);
}
}
private void notifyBytesRead() {
EventListener eventListener = this.eventListener;
if (eventListener == null || this.totalCachedBytesRead <= 0) {
return;
}
eventListener.onCachedBytesRead(this.cache.getCacheSpace(), this.totalCachedBytesRead);
this.totalCachedBytesRead = 0L;
}
}

View File

@@ -0,0 +1,46 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.FileDataSourceFactory;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheDataSource;
/* loaded from: classes4.dex */
public final class CacheDataSourceFactory implements DataSource.Factory {
private final Cache cache;
private final DataSource.Factory cacheReadDataSourceFactory;
private final DataSink.Factory cacheWriteDataSinkFactory;
private final CacheDataSource.EventListener eventListener;
private final int flags;
private final DataSource.Factory upstreamFactory;
public CacheDataSourceFactory(Cache cache, DataSource.Factory factory) {
this(cache, factory, 0);
}
public CacheDataSourceFactory(Cache cache, DataSource.Factory factory, int i) {
this(cache, factory, i, 2097152L);
}
public CacheDataSourceFactory(Cache cache, DataSource.Factory factory, int i, long j) {
this(cache, factory, new FileDataSourceFactory(), new CacheDataSinkFactory(cache, j), i, null);
}
public CacheDataSourceFactory(Cache cache, DataSource.Factory factory, DataSource.Factory factory2, DataSink.Factory factory3, int i, CacheDataSource.EventListener eventListener) {
this.cache = cache;
this.upstreamFactory = factory;
this.cacheReadDataSourceFactory = factory2;
this.cacheWriteDataSinkFactory = factory3;
this.flags = i;
this.eventListener = eventListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public final CacheDataSource createDataSource() {
Cache cache = this.cache;
DataSource createDataSource = this.upstreamFactory.createDataSource();
DataSource createDataSource2 = this.cacheReadDataSourceFactory.createDataSource();
DataSink.Factory factory = this.cacheWriteDataSinkFactory;
return new CacheDataSource(cache, createDataSource, createDataSource2, factory != null ? factory.createDataSink() : null, this.flags, this.eventListener);
}
}

View File

@@ -0,0 +1,10 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
/* loaded from: classes4.dex */
public interface CacheEvictor extends Cache.Listener {
void onCacheInitialized();
void onStartFile(Cache cache, String str, long j, long j2);
}

View File

@@ -0,0 +1,51 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import java.io.File;
/* loaded from: classes4.dex */
public class CacheSpan implements Comparable<CacheSpan> {
@Nullable
public final File file;
public final boolean isCached;
public final String key;
public final long lastAccessTimestamp;
public final long length;
public final long position;
public boolean isHoleSpan() {
return !this.isCached;
}
public boolean isOpenEnded() {
return this.length == -1;
}
public CacheSpan(String str, long j, long j2) {
this(str, j, j2, C.TIME_UNSET, null);
}
public CacheSpan(String str, long j, long j2, long j3, @Nullable File file) {
this.key = str;
this.position = j;
this.length = j2;
this.isCached = file != null;
this.file = file;
this.lastAccessTimestamp = j3;
}
@Override // java.lang.Comparable
public int compareTo(@NonNull CacheSpan cacheSpan) {
if (!this.key.equals(cacheSpan.key)) {
return this.key.compareTo(cacheSpan.key);
}
long j = this.position - cacheSpan.position;
if (j == 0) {
return 0;
}
return j < 0 ? -1 : 1;
}
}

View File

@@ -0,0 +1,185 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.EOFException;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicBoolean;
/* loaded from: classes4.dex */
public final class CacheUtil {
public static final int DEFAULT_BUFFER_SIZE_BYTES = 131072;
public static class CachingCounters {
public volatile long alreadyCachedBytes;
public volatile long contentLength = -1;
public volatile long newlyCachedBytes;
public long totalCachedBytes() {
return this.alreadyCachedBytes + this.newlyCachedBytes;
}
}
private CacheUtil() {
}
public static String generateKey(Uri uri) {
return uri.toString();
}
public static String getKey(DataSpec dataSpec) {
String str = dataSpec.key;
return str != null ? str : generateKey(dataSpec.uri);
}
public static void getCached(DataSpec dataSpec, Cache cache, CachingCounters cachingCounters) {
String key = getKey(dataSpec);
long j = dataSpec.absoluteStreamPosition;
long j2 = dataSpec.length;
if (j2 == -1) {
j2 = cache.getContentLength(key);
}
cachingCounters.contentLength = j2;
cachingCounters.alreadyCachedBytes = 0L;
cachingCounters.newlyCachedBytes = 0L;
long j3 = j;
long j4 = j2;
while (j4 != 0) {
long cachedLength = cache.getCachedLength(key, j3, j4 != -1 ? j4 : Long.MAX_VALUE);
if (cachedLength > 0) {
cachingCounters.alreadyCachedBytes += cachedLength;
} else {
cachedLength = -cachedLength;
if (cachedLength == Long.MAX_VALUE) {
return;
}
}
j3 += cachedLength;
if (j4 == -1) {
cachedLength = 0;
}
j4 -= cachedLength;
}
}
public static void cache(DataSpec dataSpec, Cache cache, DataSource dataSource, @Nullable CachingCounters cachingCounters, @Nullable AtomicBoolean atomicBoolean) throws IOException, InterruptedException {
cache(dataSpec, cache, new CacheDataSource(cache, dataSource), new byte[131072], null, 0, cachingCounters, atomicBoolean, false);
}
public static void cache(DataSpec dataSpec, Cache cache, CacheDataSource cacheDataSource, byte[] bArr, PriorityTaskManager priorityTaskManager, int i, @Nullable CachingCounters cachingCounters, @Nullable AtomicBoolean atomicBoolean, boolean z) throws IOException, InterruptedException {
CachingCounters cachingCounters2 = cachingCounters;
Assertions.checkNotNull(cacheDataSource);
Assertions.checkNotNull(bArr);
if (cachingCounters2 != null) {
getCached(dataSpec, cache, cachingCounters2);
} else {
cachingCounters2 = new CachingCounters();
}
CachingCounters cachingCounters3 = cachingCounters2;
String key = getKey(dataSpec);
long j = dataSpec.absoluteStreamPosition;
long j2 = dataSpec.length;
if (j2 == -1) {
j2 = cache.getContentLength(key);
}
long j3 = j;
long j4 = j2;
while (true) {
long j5 = 0;
if (j4 == 0) {
return;
}
if (atomicBoolean != null && atomicBoolean.get()) {
throw new InterruptedException();
}
long cachedLength = cache.getCachedLength(key, j3, j4 != -1 ? j4 : Long.MAX_VALUE);
if (cachedLength <= 0) {
long j6 = -cachedLength;
if (readAndDiscard(dataSpec, j3, j6, cacheDataSource, bArr, priorityTaskManager, i, cachingCounters3) < j6) {
if (z && j4 != -1) {
throw new EOFException();
}
return;
}
cachedLength = j6;
}
j3 += cachedLength;
if (j4 != -1) {
j5 = cachedLength;
}
j4 -= j5;
}
}
private static long readAndDiscard(DataSpec dataSpec, long j, long j2, DataSource dataSource, byte[] bArr, PriorityTaskManager priorityTaskManager, int i, CachingCounters cachingCounters) throws IOException, InterruptedException {
int length;
DataSpec dataSpec2 = dataSpec;
while (true) {
if (priorityTaskManager != null) {
priorityTaskManager.proceed(i);
}
try {
try {
if (Thread.interrupted()) {
throw new InterruptedException();
}
DataSpec dataSpec3 = new DataSpec(dataSpec2.uri, dataSpec2.postBody, j, (dataSpec2.position + j) - dataSpec2.absoluteStreamPosition, -1L, dataSpec2.key, dataSpec2.flags | 2);
try {
long open = dataSource.open(dataSpec3);
if (cachingCounters.contentLength == -1 && open != -1) {
cachingCounters.contentLength = dataSpec3.absoluteStreamPosition + open;
}
long j3 = 0;
while (true) {
if (j3 == j2) {
break;
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
if (j2 != -1) {
length = (int) Math.min(bArr.length, j2 - j3);
} else {
length = bArr.length;
}
int read = dataSource.read(bArr, 0, length);
if (read != -1) {
long j4 = read;
j3 += j4;
cachingCounters.newlyCachedBytes += j4;
} else if (cachingCounters.contentLength == -1) {
cachingCounters.contentLength = dataSpec3.absoluteStreamPosition + j3;
}
}
Util.closeQuietly(dataSource);
return j3;
} catch (PriorityTaskManager.PriorityTooLowException unused) {
dataSpec2 = dataSpec3;
}
} catch (Throwable th) {
Util.closeQuietly(dataSource);
throw th;
}
} catch (PriorityTaskManager.PriorityTooLowException unused2) {
}
Util.closeQuietly(dataSource);
}
}
public static void remove(Cache cache, String str) {
Iterator<CacheSpan> it = cache.getCachedSpans(str).iterator();
while (it.hasNext()) {
try {
cache.removeSpan(it.next());
} catch (Cache.CacheException unused) {
}
}
}
}

View File

@@ -0,0 +1,156 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.TreeSet;
/* loaded from: classes4.dex */
final class CachedContent {
private static final int VERSION_MAX = Integer.MAX_VALUE;
private static final int VERSION_METADATA_INTRODUCED = 2;
public final int id;
public final String key;
private boolean locked;
private DefaultContentMetadata metadata = DefaultContentMetadata.EMPTY;
private final TreeSet<SimpleCacheSpan> cachedSpans = new TreeSet<>();
public final ContentMetadata getMetadata() {
return this.metadata;
}
public final TreeSet<SimpleCacheSpan> getSpans() {
return this.cachedSpans;
}
public final boolean isLocked() {
return this.locked;
}
public final void setLocked(boolean z) {
this.locked = z;
}
public static CachedContent readFromStream(int i, DataInputStream dataInputStream) throws IOException {
CachedContent cachedContent = new CachedContent(dataInputStream.readInt(), dataInputStream.readUTF());
if (i < 2) {
long readLong = dataInputStream.readLong();
ContentMetadataMutations contentMetadataMutations = new ContentMetadataMutations();
ContentMetadataInternal.setContentLength(contentMetadataMutations, readLong);
cachedContent.applyMetadataMutations(contentMetadataMutations);
} else {
cachedContent.metadata = DefaultContentMetadata.readFromStream(dataInputStream);
}
return cachedContent;
}
public CachedContent(int i, String str) {
this.id = i;
this.key = str;
}
public final void writeToStream(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(this.id);
dataOutputStream.writeUTF(this.key);
this.metadata.writeToStream(dataOutputStream);
}
public final boolean applyMetadataMutations(ContentMetadataMutations contentMetadataMutations) {
this.metadata = this.metadata.copyWithMutationsApplied(contentMetadataMutations);
return !r2.equals(r0);
}
public final void addSpan(SimpleCacheSpan simpleCacheSpan) {
this.cachedSpans.add(simpleCacheSpan);
}
public final SimpleCacheSpan getSpan(long j) {
SimpleCacheSpan createLookup = SimpleCacheSpan.createLookup(this.key, j);
SimpleCacheSpan floor = this.cachedSpans.floor(createLookup);
if (floor != null && floor.position + floor.length > j) {
return floor;
}
SimpleCacheSpan ceiling = this.cachedSpans.ceiling(createLookup);
if (ceiling == null) {
return SimpleCacheSpan.createOpenHole(this.key, j);
}
return SimpleCacheSpan.createClosedHole(this.key, j, ceiling.position - j);
}
public final long getCachedBytesLength(long j, long j2) {
SimpleCacheSpan span = getSpan(j);
if (span.isHoleSpan()) {
return -Math.min(span.isOpenEnded() ? Long.MAX_VALUE : span.length, j2);
}
long j3 = j + j2;
long j4 = span.position + span.length;
if (j4 < j3) {
for (SimpleCacheSpan simpleCacheSpan : this.cachedSpans.tailSet(span, false)) {
long j5 = simpleCacheSpan.position;
if (j5 > j4) {
break;
}
j4 = Math.max(j4, j5 + simpleCacheSpan.length);
if (j4 >= j3) {
break;
}
}
}
return Math.min(j4 - j, j2);
}
public final SimpleCacheSpan touch(SimpleCacheSpan simpleCacheSpan) throws Cache.CacheException {
Assertions.checkState(this.cachedSpans.remove(simpleCacheSpan));
SimpleCacheSpan copyWithUpdatedLastAccessTime = simpleCacheSpan.copyWithUpdatedLastAccessTime(this.id);
if (!simpleCacheSpan.file.renameTo(copyWithUpdatedLastAccessTime.file)) {
throw new Cache.CacheException("Renaming of " + simpleCacheSpan.file + " to " + copyWithUpdatedLastAccessTime.file + " failed.");
}
this.cachedSpans.add(copyWithUpdatedLastAccessTime);
return copyWithUpdatedLastAccessTime;
}
public final boolean isEmpty() {
return this.cachedSpans.isEmpty();
}
public final boolean removeSpan(CacheSpan cacheSpan) {
if (!this.cachedSpans.remove(cacheSpan)) {
return false;
}
cacheSpan.file.delete();
return true;
}
public final int headerHashCode(int i) {
int i2;
int hashCode;
int hashCode2 = (this.id * 31) + this.key.hashCode();
if (i < 2) {
long contentLength = ContentMetadataInternal.getContentLength(this.metadata);
i2 = hashCode2 * 31;
hashCode = (int) (contentLength ^ (contentLength >>> 32));
} else {
i2 = hashCode2 * 31;
hashCode = this.metadata.hashCode();
}
return i2 + hashCode;
}
public final int hashCode() {
return (headerHashCode(Integer.MAX_VALUE) * 31) + this.cachedSpans.hashCode();
}
public final boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || CachedContent.class != obj.getClass()) {
return false;
}
CachedContent cachedContent = (CachedContent) obj;
return this.id == cachedContent.id && this.key.equals(cachedContent.key) && this.cachedSpans.equals(cachedContent.cachedSpans) && this.metadata.equals(cachedContent.metadata);
}
}

View File

@@ -0,0 +1,303 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.util.SparseArray;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.AtomicFile;
import com.mbridge.msdk.playercommon.exoplayer2.util.ReusableBufferedOutputStream;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/* loaded from: classes4.dex */
class CachedContentIndex {
public static final String FILE_NAME = "cached_content_index.exi";
private static final int FLAG_ENCRYPTED_INDEX = 1;
private static final int VERSION = 2;
private final AtomicFile atomicFile;
private ReusableBufferedOutputStream bufferedOutputStream;
private boolean changed;
private final Cipher cipher;
private final boolean encrypt;
private final SparseArray<String> idToKey;
private final HashMap<String, CachedContent> keyToContent;
private final SecretKeySpec secretKeySpec;
public CachedContentIndex(File file) {
this(file, null);
}
public CachedContentIndex(File file, byte[] bArr) {
this(file, bArr, bArr != null);
}
public CachedContentIndex(File file, byte[] bArr, boolean z) {
this.encrypt = z;
if (bArr != null) {
Assertions.checkArgument(bArr.length == 16);
try {
this.cipher = getCipher();
this.secretKeySpec = new SecretKeySpec(bArr, "AES");
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new IllegalStateException(e);
}
} else {
Assertions.checkState(!z);
this.cipher = null;
this.secretKeySpec = null;
}
this.keyToContent = new HashMap<>();
this.idToKey = new SparseArray<>();
this.atomicFile = new AtomicFile(new File(file, FILE_NAME));
}
public void load() {
Assertions.checkState(!this.changed);
if (readFile()) {
return;
}
this.atomicFile.delete();
this.keyToContent.clear();
this.idToKey.clear();
}
public void store() throws Cache.CacheException {
if (this.changed) {
writeFile();
this.changed = false;
}
}
public CachedContent getOrAdd(String str) {
CachedContent cachedContent = this.keyToContent.get(str);
return cachedContent == null ? addNew(str) : cachedContent;
}
public CachedContent get(String str) {
return this.keyToContent.get(str);
}
public Collection<CachedContent> getAll() {
return this.keyToContent.values();
}
public int assignIdForKey(String str) {
return getOrAdd(str).id;
}
public String getKeyForId(int i) {
return this.idToKey.get(i);
}
public void maybeRemove(String str) {
CachedContent cachedContent = this.keyToContent.get(str);
if (cachedContent == null || !cachedContent.isEmpty() || cachedContent.isLocked()) {
return;
}
this.keyToContent.remove(str);
this.idToKey.remove(cachedContent.id);
this.changed = true;
}
public void removeEmpty() {
int size = this.keyToContent.size();
String[] strArr = new String[size];
this.keyToContent.keySet().toArray(strArr);
for (int i = 0; i < size; i++) {
maybeRemove(strArr[i]);
}
}
public Set<String> getKeys() {
return this.keyToContent.keySet();
}
public void applyContentMetadataMutations(String str, ContentMetadataMutations contentMetadataMutations) {
if (getOrAdd(str).applyMetadataMutations(contentMetadataMutations)) {
this.changed = true;
}
}
public ContentMetadata getContentMetadata(String str) {
CachedContent cachedContent = get(str);
return cachedContent != null ? cachedContent.getMetadata() : DefaultContentMetadata.EMPTY;
}
private boolean readFile() {
DataInputStream dataInputStream = null;
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(this.atomicFile.openRead());
DataInputStream dataInputStream2 = new DataInputStream(bufferedInputStream);
try {
int readInt = dataInputStream2.readInt();
if (readInt >= 0 && readInt <= 2) {
if ((dataInputStream2.readInt() & 1) != 0) {
if (this.cipher != null) {
byte[] bArr = new byte[16];
dataInputStream2.readFully(bArr);
try {
this.cipher.init(2, this.secretKeySpec, new IvParameterSpec(bArr));
dataInputStream2 = new DataInputStream(new CipherInputStream(bufferedInputStream, this.cipher));
} catch (InvalidAlgorithmParameterException e) {
e = e;
throw new IllegalStateException(e);
} catch (InvalidKeyException e2) {
e = e2;
throw new IllegalStateException(e);
}
} else {
Util.closeQuietly(dataInputStream2);
return false;
}
} else if (this.encrypt) {
this.changed = true;
}
int readInt2 = dataInputStream2.readInt();
int i = 0;
for (int i2 = 0; i2 < readInt2; i2++) {
CachedContent readFromStream = CachedContent.readFromStream(readInt, dataInputStream2);
add(readFromStream);
i += readFromStream.headerHashCode(readInt);
}
int readInt3 = dataInputStream2.readInt();
boolean z = dataInputStream2.read() == -1;
if (readInt3 == i && z) {
Util.closeQuietly(dataInputStream2);
return true;
}
Util.closeQuietly(dataInputStream2);
return false;
}
Util.closeQuietly(dataInputStream2);
return false;
} catch (IOException unused) {
dataInputStream = dataInputStream2;
if (dataInputStream != null) {
Util.closeQuietly(dataInputStream);
}
return false;
} catch (Throwable th) {
th = th;
dataInputStream = dataInputStream2;
if (dataInputStream != null) {
Util.closeQuietly(dataInputStream);
}
throw th;
}
} catch (IOException unused2) {
} catch (Throwable th2) {
th = th2;
}
}
private void writeFile() throws Cache.CacheException {
DataOutputStream dataOutputStream;
Closeable closeable = null;
try {
try {
OutputStream startWrite = this.atomicFile.startWrite();
ReusableBufferedOutputStream reusableBufferedOutputStream = this.bufferedOutputStream;
if (reusableBufferedOutputStream == null) {
this.bufferedOutputStream = new ReusableBufferedOutputStream(startWrite);
} else {
reusableBufferedOutputStream.reset(startWrite);
}
dataOutputStream = new DataOutputStream(this.bufferedOutputStream);
} catch (Throwable th) {
th = th;
}
} catch (IOException e) {
e = e;
}
try {
dataOutputStream.writeInt(2);
int i = 0;
dataOutputStream.writeInt(this.encrypt ? 1 : 0);
if (this.encrypt) {
byte[] bArr = new byte[16];
new Random().nextBytes(bArr);
dataOutputStream.write(bArr);
try {
this.cipher.init(1, this.secretKeySpec, new IvParameterSpec(bArr));
dataOutputStream.flush();
dataOutputStream = new DataOutputStream(new CipherOutputStream(this.bufferedOutputStream, this.cipher));
} catch (InvalidAlgorithmParameterException e2) {
e = e2;
throw new IllegalStateException(e);
} catch (InvalidKeyException e3) {
e = e3;
throw new IllegalStateException(e);
}
}
dataOutputStream.writeInt(this.keyToContent.size());
for (CachedContent cachedContent : this.keyToContent.values()) {
cachedContent.writeToStream(dataOutputStream);
i += cachedContent.headerHashCode(2);
}
dataOutputStream.writeInt(i);
this.atomicFile.endWrite(dataOutputStream);
Util.closeQuietly((Closeable) null);
} catch (IOException e4) {
e = e4;
throw new Cache.CacheException(e);
} catch (Throwable th2) {
th = th2;
closeable = dataOutputStream;
Util.closeQuietly(closeable);
throw th;
}
}
private CachedContent addNew(String str) {
CachedContent cachedContent = new CachedContent(getNewId(this.idToKey), str);
add(cachedContent);
this.changed = true;
return cachedContent;
}
private void add(CachedContent cachedContent) {
this.keyToContent.put(cachedContent.key, cachedContent);
this.idToKey.put(cachedContent.id, cachedContent.key);
}
private static Cipher getCipher() throws NoSuchPaddingException, NoSuchAlgorithmException {
if (Util.SDK_INT == 18) {
try {
return Cipher.getInstance("AES/CBC/PKCS5PADDING", "BC");
} catch (Throwable unused) {
}
}
return Cipher.getInstance("AES/CBC/PKCS5PADDING");
}
public static int getNewId(SparseArray<String> sparseArray) {
int size = sparseArray.size();
int i = 0;
int keyAt = size == 0 ? 0 : sparseArray.keyAt(size - 1) + 1;
if (keyAt >= 0) {
return keyAt;
}
while (i < size && i == sparseArray.keyAt(i)) {
i++;
}
return i;
}
}

View File

@@ -0,0 +1,169 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.util.Log;
import androidx.annotation.NonNull;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ChunkIndex;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import java.util.Arrays;
import java.util.Iterator;
import java.util.TreeSet;
/* loaded from: classes4.dex */
public final class CachedRegionTracker implements Cache.Listener {
public static final int CACHED_TO_END = -2;
public static final int NOT_CACHED = -1;
private static final String TAG = "CachedRegionTracker";
private final Cache cache;
private final String cacheKey;
private final ChunkIndex chunkIndex;
private final TreeSet<Region> regions = new TreeSet<>();
private final Region lookupRegion = new Region(0, 0);
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanTouched(Cache cache, CacheSpan cacheSpan, CacheSpan cacheSpan2) {
}
public CachedRegionTracker(Cache cache, String str, ChunkIndex chunkIndex) {
this.cache = cache;
this.cacheKey = str;
this.chunkIndex = chunkIndex;
synchronized (this) {
try {
Iterator<CacheSpan> descendingIterator = cache.addListener(str, this).descendingIterator();
while (descendingIterator.hasNext()) {
mergeSpan(descendingIterator.next());
}
} catch (Throwable th) {
throw th;
}
}
}
public final void release() {
this.cache.removeListener(this.cacheKey, this);
}
public final synchronized int getRegionEndTimeMs(long j) {
int i;
Region region = this.lookupRegion;
region.startOffset = j;
Region floor = this.regions.floor(region);
if (floor != null) {
long j2 = floor.endOffset;
if (j <= j2 && (i = floor.endOffsetIndex) != -1) {
ChunkIndex chunkIndex = this.chunkIndex;
if (i == chunkIndex.length - 1) {
if (j2 == chunkIndex.offsets[i] + chunkIndex.sizes[i]) {
return -2;
}
}
return (int) ((chunkIndex.timesUs[i] + ((chunkIndex.durationsUs[i] * (j2 - chunkIndex.offsets[i])) / chunkIndex.sizes[i])) / 1000);
}
}
return -1;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final synchronized void onSpanAdded(Cache cache, CacheSpan cacheSpan) {
mergeSpan(cacheSpan);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final synchronized void onSpanRemoved(Cache cache, CacheSpan cacheSpan) {
long j = cacheSpan.position;
Region region = new Region(j, cacheSpan.length + j);
Region floor = this.regions.floor(region);
if (floor == null) {
Log.e(TAG, "Removed a span we were not aware of");
return;
}
this.regions.remove(floor);
long j2 = floor.startOffset;
long j3 = region.startOffset;
if (j2 < j3) {
Region region2 = new Region(j2, j3);
int binarySearch = Arrays.binarySearch(this.chunkIndex.offsets, region2.endOffset);
if (binarySearch < 0) {
binarySearch = (-binarySearch) - 2;
}
region2.endOffsetIndex = binarySearch;
this.regions.add(region2);
}
long j4 = floor.endOffset;
long j5 = region.endOffset;
if (j4 > j5) {
Region region3 = new Region(j5 + 1, j4);
region3.endOffsetIndex = floor.endOffsetIndex;
this.regions.add(region3);
}
}
private void mergeSpan(CacheSpan cacheSpan) {
long j = cacheSpan.position;
Region region = new Region(j, cacheSpan.length + j);
Region floor = this.regions.floor(region);
Region ceiling = this.regions.ceiling(region);
boolean regionsConnect = regionsConnect(floor, region);
if (regionsConnect(region, ceiling)) {
if (regionsConnect) {
floor.endOffset = ceiling.endOffset;
floor.endOffsetIndex = ceiling.endOffsetIndex;
} else {
region.endOffset = ceiling.endOffset;
region.endOffsetIndex = ceiling.endOffsetIndex;
this.regions.add(region);
}
this.regions.remove(ceiling);
return;
}
if (regionsConnect) {
floor.endOffset = region.endOffset;
int i = floor.endOffsetIndex;
while (true) {
ChunkIndex chunkIndex = this.chunkIndex;
if (i >= chunkIndex.length - 1) {
break;
}
int i2 = i + 1;
if (chunkIndex.offsets[i2] > floor.endOffset) {
break;
} else {
i = i2;
}
}
floor.endOffsetIndex = i;
return;
}
int binarySearch = Arrays.binarySearch(this.chunkIndex.offsets, region.endOffset);
if (binarySearch < 0) {
binarySearch = (-binarySearch) - 2;
}
region.endOffsetIndex = binarySearch;
this.regions.add(region);
}
private boolean regionsConnect(Region region, Region region2) {
return (region == null || region2 == null || region.endOffset != region2.startOffset) ? false : true;
}
public static class Region implements Comparable<Region> {
public long endOffset;
public int endOffsetIndex;
public long startOffset;
public Region(long j, long j2) {
this.startOffset = j;
this.endOffset = j2;
}
@Override // java.lang.Comparable
public int compareTo(@NonNull Region region) {
long j = this.startOffset;
long j2 = region.startOffset;
if (j < j2) {
return -1;
}
return j == j2 ? 0 : 1;
}
}
}

View File

@@ -0,0 +1,14 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
/* loaded from: classes4.dex */
public interface ContentMetadata {
public static final String INTERNAL_METADATA_NAME_PREFIX = "exo_";
boolean contains(String str);
long get(String str, long j);
String get(String str, String str2);
byte[] get(String str, byte[] bArr);
}

View File

@@ -0,0 +1,43 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.net.Uri;
import androidx.annotation.Nullable;
/* loaded from: classes4.dex */
final class ContentMetadataInternal {
private static final String METADATA_NAME_CONTENT_LENGTH = "exo_len";
private static final String METADATA_NAME_REDIRECTED_URI = "exo_redir";
private static final String PREFIX = "exo_";
public static long getContentLength(ContentMetadata contentMetadata) {
return contentMetadata.get(METADATA_NAME_CONTENT_LENGTH, -1L);
}
public static void setContentLength(ContentMetadataMutations contentMetadataMutations, long j) {
contentMetadataMutations.set(METADATA_NAME_CONTENT_LENGTH, j);
}
public static void removeContentLength(ContentMetadataMutations contentMetadataMutations) {
contentMetadataMutations.remove(METADATA_NAME_CONTENT_LENGTH);
}
@Nullable
public static Uri getRedirectedUri(ContentMetadata contentMetadata) {
String str = contentMetadata.get(METADATA_NAME_REDIRECTED_URI, (String) null);
if (str == null) {
return null;
}
return Uri.parse(str);
}
public static void setRedirectedUri(ContentMetadataMutations contentMetadataMutations, Uri uri) {
contentMetadataMutations.set(METADATA_NAME_REDIRECTED_URI, uri.toString());
}
public static void removeRedirectedUri(ContentMetadataMutations contentMetadataMutations) {
contentMetadataMutations.remove(METADATA_NAME_REDIRECTED_URI);
}
private ContentMetadataInternal() {
}
}

View File

@@ -0,0 +1,55 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public class ContentMetadataMutations {
private final Map<String, Object> editedValues = new HashMap();
private final List<String> removedValues = new ArrayList();
public ContentMetadataMutations set(String str, String str2) {
return checkAndSet(str, str2);
}
public ContentMetadataMutations set(String str, long j) {
return checkAndSet(str, Long.valueOf(j));
}
public ContentMetadataMutations set(String str, byte[] bArr) {
return checkAndSet(str, Arrays.copyOf(bArr, bArr.length));
}
public ContentMetadataMutations remove(String str) {
this.removedValues.add(str);
this.editedValues.remove(str);
return this;
}
public List<String> getRemovedValues() {
return Collections.unmodifiableList(new ArrayList(this.removedValues));
}
public Map<String, Object> getEditedValues() {
HashMap hashMap = new HashMap(this.editedValues);
for (Map.Entry entry : hashMap.entrySet()) {
Object value = entry.getValue();
if (value instanceof byte[]) {
byte[] bArr = (byte[]) value;
entry.setValue(Arrays.copyOf(bArr, bArr.length));
}
}
return Collections.unmodifiableMap(hashMap);
}
private ContentMetadataMutations checkAndSet(String str, Object obj) {
this.editedValues.put((String) Assertions.checkNotNull(str), Assertions.checkNotNull(obj));
this.removedValues.remove(str);
return this;
}
}

View File

@@ -0,0 +1,149 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import androidx.annotation.Nullable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public final class DefaultContentMetadata implements ContentMetadata {
public static final DefaultContentMetadata EMPTY = new DefaultContentMetadata(Collections.emptyMap());
private static final int MAX_VALUE_LENGTH = 10485760;
private int hashCode;
private final Map<String, byte[]> metadata;
public static DefaultContentMetadata readFromStream(DataInputStream dataInputStream) throws IOException {
int readInt = dataInputStream.readInt();
HashMap hashMap = new HashMap();
for (int i = 0; i < readInt; i++) {
String readUTF = dataInputStream.readUTF();
int readInt2 = dataInputStream.readInt();
if (readInt2 < 0 || readInt2 > MAX_VALUE_LENGTH) {
throw new IOException("Invalid value size: " + readInt2);
}
byte[] bArr = new byte[readInt2];
dataInputStream.readFully(bArr);
hashMap.put(readUTF, bArr);
}
return new DefaultContentMetadata(hashMap);
}
private DefaultContentMetadata(Map<String, byte[]> map) {
this.metadata = Collections.unmodifiableMap(map);
}
public final DefaultContentMetadata copyWithMutationsApplied(ContentMetadataMutations contentMetadataMutations) {
Map<String, byte[]> applyMutations = applyMutations(this.metadata, contentMetadataMutations);
return isMetadataEqual(applyMutations) ? this : new DefaultContentMetadata(applyMutations);
}
public final void writeToStream(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(this.metadata.size());
for (Map.Entry<String, byte[]> entry : this.metadata.entrySet()) {
dataOutputStream.writeUTF(entry.getKey());
byte[] value = entry.getValue();
dataOutputStream.writeInt(value.length);
dataOutputStream.write(value);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.ContentMetadata
public final byte[] get(String str, byte[] bArr) {
if (!this.metadata.containsKey(str)) {
return bArr;
}
byte[] bArr2 = this.metadata.get(str);
return Arrays.copyOf(bArr2, bArr2.length);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.ContentMetadata
public final String get(String str, String str2) {
return this.metadata.containsKey(str) ? new String(this.metadata.get(str), Charset.forName("UTF-8")) : str2;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.ContentMetadata
public final long get(String str, long j) {
return this.metadata.containsKey(str) ? ByteBuffer.wrap(this.metadata.get(str)).getLong() : j;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.ContentMetadata
public final boolean contains(String str) {
return this.metadata.containsKey(str);
}
public final boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || DefaultContentMetadata.class != obj.getClass()) {
return false;
}
return isMetadataEqual(((DefaultContentMetadata) obj).metadata);
}
private boolean isMetadataEqual(Map<String, byte[]> map) {
if (this.metadata.size() != map.size()) {
return false;
}
for (Map.Entry<String, byte[]> entry : this.metadata.entrySet()) {
if (!Arrays.equals(entry.getValue(), map.get(entry.getKey()))) {
return false;
}
}
return true;
}
public final int hashCode() {
if (this.hashCode == 0) {
int i = 0;
for (Map.Entry<String, byte[]> entry : this.metadata.entrySet()) {
i += Arrays.hashCode(entry.getValue()) ^ entry.getKey().hashCode();
}
this.hashCode = i;
}
return this.hashCode;
}
private static Map<String, byte[]> applyMutations(Map<String, byte[]> map, ContentMetadataMutations contentMetadataMutations) {
HashMap hashMap = new HashMap(map);
removeValues(hashMap, contentMetadataMutations.getRemovedValues());
addValues(hashMap, contentMetadataMutations.getEditedValues());
return hashMap;
}
private static void removeValues(HashMap<String, byte[]> hashMap, List<String> list) {
for (int i = 0; i < list.size(); i++) {
hashMap.remove(list.get(i));
}
}
private static void addValues(HashMap<String, byte[]> hashMap, Map<String, Object> map) {
for (String str : map.keySet()) {
byte[] bytes = getBytes(map.get(str));
if (bytes.length > MAX_VALUE_LENGTH) {
throw new IllegalArgumentException(String.format("The size of %s (%d) is greater than maximum allowed: %d", str, Integer.valueOf(bytes.length), Integer.valueOf(MAX_VALUE_LENGTH)));
}
hashMap.put(str, bytes);
}
}
private static byte[] getBytes(Object obj) {
if (obj instanceof Long) {
return ByteBuffer.allocate(8).putLong(((Long) obj).longValue()).array();
}
if (obj instanceof String) {
return ((String) obj).getBytes(Charset.forName("UTF-8"));
}
if (obj instanceof byte[]) {
return (byte[]) obj;
}
throw new IllegalArgumentException();
}
}

View File

@@ -0,0 +1,63 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import java.util.Comparator;
import java.util.TreeSet;
/* loaded from: classes4.dex */
public final class LeastRecentlyUsedCacheEvictor implements CacheEvictor, Comparator<CacheSpan> {
private long currentSize;
private final TreeSet<CacheSpan> leastRecentlyUsed = new TreeSet<>(this);
private final long maxBytes;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheEvictor
public final void onCacheInitialized() {
}
public LeastRecentlyUsedCacheEvictor(long j) {
this.maxBytes = j;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheEvictor
public final void onStartFile(Cache cache, String str, long j, long j2) {
evictCache(cache, j2);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanAdded(Cache cache, CacheSpan cacheSpan) {
this.leastRecentlyUsed.add(cacheSpan);
this.currentSize += cacheSpan.length;
evictCache(cache, 0L);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanRemoved(Cache cache, CacheSpan cacheSpan) {
this.leastRecentlyUsed.remove(cacheSpan);
this.currentSize -= cacheSpan.length;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanTouched(Cache cache, CacheSpan cacheSpan, CacheSpan cacheSpan2) {
onSpanRemoved(cache, cacheSpan);
onSpanAdded(cache, cacheSpan2);
}
@Override // java.util.Comparator
public final int compare(CacheSpan cacheSpan, CacheSpan cacheSpan2) {
long j = cacheSpan.lastAccessTimestamp;
long j2 = cacheSpan2.lastAccessTimestamp;
if (j - j2 == 0) {
return cacheSpan.compareTo(cacheSpan2);
}
return j < j2 ? -1 : 1;
}
private void evictCache(Cache cache, long j) {
while (this.currentSize + j > this.maxBytes && !this.leastRecentlyUsed.isEmpty()) {
try {
cache.removeSpan(this.leastRecentlyUsed.first());
} catch (Cache.CacheException unused) {
}
}
}
}

View File

@@ -0,0 +1,24 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
/* loaded from: classes4.dex */
public final class NoOpCacheEvictor implements CacheEvictor {
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheEvictor
public final void onCacheInitialized() {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanAdded(Cache cache, CacheSpan cacheSpan) {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanRemoved(Cache cache, CacheSpan cacheSpan) {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache.Listener
public final void onSpanTouched(Cache cache, CacheSpan cacheSpan, CacheSpan cacheSpan2) {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheEvictor
public final void onStartFile(Cache cache, String str, long j, long j2) {
}
}

View File

@@ -0,0 +1,420 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import android.os.ConditionVariable;
import android.util.Log;
import androidx.annotation.NonNull;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
/* loaded from: classes4.dex */
public final class SimpleCache implements Cache {
private static final String TAG = "SimpleCache";
private static boolean cacheFolderLockingDisabled;
private static final HashSet<File> lockedCacheDirs = new HashSet<>();
private final File cacheDir;
private final CacheEvictor evictor;
private final CachedContentIndex index;
private final HashMap<String, ArrayList<Cache.Listener>> listeners;
private boolean released;
private long totalSpace;
public static synchronized boolean isCacheFolderLocked(File file) {
boolean contains;
synchronized (SimpleCache.class) {
contains = lockedCacheDirs.contains(file.getAbsoluteFile());
}
return contains;
}
@Deprecated
public static synchronized void disableCacheFolderLocking() {
synchronized (SimpleCache.class) {
cacheFolderLockingDisabled = true;
lockedCacheDirs.clear();
}
}
public SimpleCache(File file, CacheEvictor cacheEvictor) {
this(file, cacheEvictor, null, false);
}
public SimpleCache(File file, CacheEvictor cacheEvictor, byte[] bArr) {
this(file, cacheEvictor, bArr, bArr != null);
}
public SimpleCache(File file, CacheEvictor cacheEvictor, byte[] bArr, boolean z) {
this(file, cacheEvictor, new CachedContentIndex(file, bArr, z));
}
public SimpleCache(File file, CacheEvictor cacheEvictor, CachedContentIndex cachedContentIndex) {
if (!lockFolder(file)) {
throw new IllegalStateException("Another SimpleCache instance uses the folder: " + file);
}
this.cacheDir = file;
this.evictor = cacheEvictor;
this.index = cachedContentIndex;
this.listeners = new HashMap<>();
final ConditionVariable conditionVariable = new ConditionVariable();
new Thread("SimpleCache.initialize()") { // from class: com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.SimpleCache.1
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
synchronized (SimpleCache.this) {
conditionVariable.open();
SimpleCache.this.initialize();
SimpleCache.this.evictor.onCacheInitialized();
}
}
}.start();
conditionVariable.block();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void release() throws Cache.CacheException {
if (this.released) {
return;
}
this.listeners.clear();
try {
removeStaleSpansAndCachedContents();
} finally {
unlockFolder(this.cacheDir);
this.released = true;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized NavigableSet<CacheSpan> addListener(String str, Cache.Listener listener) {
try {
Assertions.checkState(!this.released);
ArrayList<Cache.Listener> arrayList = this.listeners.get(str);
if (arrayList == null) {
arrayList = new ArrayList<>();
this.listeners.put(str, arrayList);
}
arrayList.add(listener);
} catch (Throwable th) {
throw th;
}
return getCachedSpans(str);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void removeListener(String str, Cache.Listener listener) {
if (this.released) {
return;
}
ArrayList<Cache.Listener> arrayList = this.listeners.get(str);
if (arrayList != null) {
arrayList.remove(listener);
if (arrayList.isEmpty()) {
this.listeners.remove(str);
}
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
@NonNull
public final synchronized NavigableSet<CacheSpan> getCachedSpans(String str) {
TreeSet treeSet;
try {
Assertions.checkState(!this.released);
CachedContent cachedContent = this.index.get(str);
if (cachedContent != null && !cachedContent.isEmpty()) {
treeSet = new TreeSet((Collection) cachedContent.getSpans());
}
treeSet = new TreeSet();
} catch (Throwable th) {
throw th;
}
return treeSet;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized Set<String> getKeys() {
Assertions.checkState(!this.released);
return new HashSet(this.index.getKeys());
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized long getCacheSpace() {
Assertions.checkState(!this.released);
return this.totalSpace;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized SimpleCacheSpan startReadWrite(String str, long j) throws InterruptedException, Cache.CacheException {
SimpleCacheSpan startReadWriteNonBlocking;
while (true) {
startReadWriteNonBlocking = startReadWriteNonBlocking(str, j);
if (startReadWriteNonBlocking == null) {
wait();
}
}
return startReadWriteNonBlocking;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized SimpleCacheSpan startReadWriteNonBlocking(String str, long j) throws Cache.CacheException {
Assertions.checkState(!this.released);
SimpleCacheSpan span = getSpan(str, j);
if (span.isCached) {
SimpleCacheSpan simpleCacheSpan = this.index.get(str).touch(span);
notifySpanTouched(span, simpleCacheSpan);
return simpleCacheSpan;
}
CachedContent orAdd = this.index.getOrAdd(str);
if (orAdd.isLocked()) {
return null;
}
orAdd.setLocked(true);
return span;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized File startFile(String str, long j, long j2) throws Cache.CacheException {
CachedContent cachedContent;
try {
Assertions.checkState(!this.released);
cachedContent = this.index.get(str);
Assertions.checkNotNull(cachedContent);
Assertions.checkState(cachedContent.isLocked());
if (!this.cacheDir.exists()) {
this.cacheDir.mkdirs();
removeStaleSpansAndCachedContents();
}
this.evictor.onStartFile(this, str, j, j2);
} catch (Throwable th) {
throw th;
}
return SimpleCacheSpan.getCacheFile(this.cacheDir, cachedContent.id, j, System.currentTimeMillis());
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void commitFile(File file) throws Cache.CacheException {
Assertions.checkState(!this.released);
SimpleCacheSpan createCacheEntry = SimpleCacheSpan.createCacheEntry(file, this.index);
Assertions.checkState(createCacheEntry != null);
CachedContent cachedContent = this.index.get(createCacheEntry.key);
Assertions.checkNotNull(cachedContent);
Assertions.checkState(cachedContent.isLocked());
if (file.exists()) {
if (file.length() == 0) {
file.delete();
return;
}
long contentLength = ContentMetadataInternal.getContentLength(cachedContent.getMetadata());
if (contentLength != -1) {
Assertions.checkState(createCacheEntry.position + createCacheEntry.length <= contentLength);
}
addSpan(createCacheEntry);
this.index.store();
notifyAll();
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void releaseHoleSpan(CacheSpan cacheSpan) {
Assertions.checkState(!this.released);
CachedContent cachedContent = this.index.get(cacheSpan.key);
Assertions.checkNotNull(cachedContent);
Assertions.checkState(cachedContent.isLocked());
cachedContent.setLocked(false);
this.index.maybeRemove(cachedContent.key);
notifyAll();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void removeSpan(CacheSpan cacheSpan) throws Cache.CacheException {
Assertions.checkState(!this.released);
removeSpan(cacheSpan, true);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized boolean isCached(String str, long j, long j2) {
boolean z;
z = false;
Assertions.checkState(!this.released);
CachedContent cachedContent = this.index.get(str);
if (cachedContent != null) {
if (cachedContent.getCachedBytesLength(j, j2) >= j2) {
z = true;
}
}
return z;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized long getCachedLength(String str, long j, long j2) {
CachedContent cachedContent;
Assertions.checkState(!this.released);
cachedContent = this.index.get(str);
return cachedContent != null ? cachedContent.getCachedBytesLength(j, j2) : -j2;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void setContentLength(String str, long j) throws Cache.CacheException {
ContentMetadataMutations contentMetadataMutations = new ContentMetadataMutations();
ContentMetadataInternal.setContentLength(contentMetadataMutations, j);
applyContentMetadataMutations(str, contentMetadataMutations);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized long getContentLength(String str) {
return ContentMetadataInternal.getContentLength(getContentMetadata(str));
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized void applyContentMetadataMutations(String str, ContentMetadataMutations contentMetadataMutations) throws Cache.CacheException {
Assertions.checkState(!this.released);
this.index.applyContentMetadataMutations(str, contentMetadataMutations);
this.index.store();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache
public final synchronized ContentMetadata getContentMetadata(String str) {
Assertions.checkState(!this.released);
return this.index.getContentMetadata(str);
}
private SimpleCacheSpan getSpan(String str, long j) throws Cache.CacheException {
SimpleCacheSpan span;
CachedContent cachedContent = this.index.get(str);
if (cachedContent == null) {
return SimpleCacheSpan.createOpenHole(str, j);
}
while (true) {
span = cachedContent.getSpan(j);
if (!span.isCached || span.file.exists()) {
break;
}
removeStaleSpansAndCachedContents();
}
return span;
}
/* JADX INFO: Access modifiers changed from: private */
public void initialize() {
if (!this.cacheDir.exists()) {
this.cacheDir.mkdirs();
return;
}
this.index.load();
File[] listFiles = this.cacheDir.listFiles();
if (listFiles == null) {
return;
}
for (File file : listFiles) {
if (!file.getName().equals(CachedContentIndex.FILE_NAME)) {
SimpleCacheSpan createCacheEntry = file.length() > 0 ? SimpleCacheSpan.createCacheEntry(file, this.index) : null;
if (createCacheEntry != null) {
addSpan(createCacheEntry);
} else {
file.delete();
}
}
}
this.index.removeEmpty();
try {
this.index.store();
} catch (Cache.CacheException e) {
Log.e(TAG, "Storing index file failed", e);
}
}
private void addSpan(SimpleCacheSpan simpleCacheSpan) {
this.index.getOrAdd(simpleCacheSpan.key).addSpan(simpleCacheSpan);
this.totalSpace += simpleCacheSpan.length;
notifySpanAdded(simpleCacheSpan);
}
private void removeSpan(CacheSpan cacheSpan, boolean z) throws Cache.CacheException {
CachedContent cachedContent = this.index.get(cacheSpan.key);
if (cachedContent == null || !cachedContent.removeSpan(cacheSpan)) {
return;
}
this.totalSpace -= cacheSpan.length;
if (z) {
try {
this.index.maybeRemove(cachedContent.key);
this.index.store();
} finally {
notifySpanRemoved(cacheSpan);
}
}
}
private void removeStaleSpansAndCachedContents() throws Cache.CacheException {
ArrayList arrayList = new ArrayList();
Iterator<CachedContent> it = this.index.getAll().iterator();
while (it.hasNext()) {
Iterator<SimpleCacheSpan> it2 = it.next().getSpans().iterator();
while (it2.hasNext()) {
SimpleCacheSpan next = it2.next();
if (!next.file.exists()) {
arrayList.add(next);
}
}
}
for (int i = 0; i < arrayList.size(); i++) {
removeSpan((CacheSpan) arrayList.get(i), false);
}
this.index.removeEmpty();
this.index.store();
}
private void notifySpanRemoved(CacheSpan cacheSpan) {
ArrayList<Cache.Listener> arrayList = this.listeners.get(cacheSpan.key);
if (arrayList != null) {
for (int size = arrayList.size() - 1; size >= 0; size--) {
arrayList.get(size).onSpanRemoved(this, cacheSpan);
}
}
this.evictor.onSpanRemoved(this, cacheSpan);
}
private void notifySpanAdded(SimpleCacheSpan simpleCacheSpan) {
ArrayList<Cache.Listener> arrayList = this.listeners.get(simpleCacheSpan.key);
if (arrayList != null) {
for (int size = arrayList.size() - 1; size >= 0; size--) {
arrayList.get(size).onSpanAdded(this, simpleCacheSpan);
}
}
this.evictor.onSpanAdded(this, simpleCacheSpan);
}
private void notifySpanTouched(SimpleCacheSpan simpleCacheSpan, CacheSpan cacheSpan) {
ArrayList<Cache.Listener> arrayList = this.listeners.get(simpleCacheSpan.key);
if (arrayList != null) {
for (int size = arrayList.size() - 1; size >= 0; size--) {
arrayList.get(size).onSpanTouched(this, simpleCacheSpan, cacheSpan);
}
}
this.evictor.onSpanTouched(this, simpleCacheSpan, cacheSpan);
}
private static synchronized boolean lockFolder(File file) {
synchronized (SimpleCache.class) {
if (cacheFolderLockingDisabled) {
return true;
}
return lockedCacheDirs.add(file.getAbsoluteFile());
}
}
private static synchronized void unlockFolder(File file) {
synchronized (SimpleCache.class) {
if (!cacheFolderLockingDisabled) {
lockedCacheDirs.remove(file.getAbsoluteFile());
}
}
}
}

View File

@@ -0,0 +1,91 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.cache;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import csdk.gluads.Consts;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* loaded from: classes4.dex */
final class SimpleCacheSpan extends CacheSpan {
private static final Pattern CACHE_FILE_PATTERN_V1 = Pattern.compile("^(.+)\\.(\\d+)\\.(\\d+)\\.v1\\.exo$", 32);
private static final Pattern CACHE_FILE_PATTERN_V2 = Pattern.compile("^(.+)\\.(\\d+)\\.(\\d+)\\.v2\\.exo$", 32);
private static final Pattern CACHE_FILE_PATTERN_V3 = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)\\.v3\\.exo$", 32);
private static final String SUFFIX = ".v3.exo";
public static File getCacheFile(File file, int i, long j, long j2) {
return new File(file, i + Consts.STRING_PERIOD + j + Consts.STRING_PERIOD + j2 + SUFFIX);
}
public static SimpleCacheSpan createLookup(String str, long j) {
return new SimpleCacheSpan(str, j, -1L, C.TIME_UNSET, null);
}
public static SimpleCacheSpan createOpenHole(String str, long j) {
return new SimpleCacheSpan(str, j, -1L, C.TIME_UNSET, null);
}
public static SimpleCacheSpan createClosedHole(String str, long j, long j2) {
return new SimpleCacheSpan(str, j, j2, C.TIME_UNSET, null);
}
@Nullable
public static SimpleCacheSpan createCacheEntry(File file, CachedContentIndex cachedContentIndex) {
String name = file.getName();
if (!name.endsWith(SUFFIX)) {
file = upgradeFile(file, cachedContentIndex);
if (file == null) {
return null;
}
name = file.getName();
}
File file2 = file;
Matcher matcher = CACHE_FILE_PATTERN_V3.matcher(name);
if (!matcher.matches()) {
return null;
}
long length = file2.length();
String keyForId = cachedContentIndex.getKeyForId(Integer.parseInt(matcher.group(1)));
if (keyForId == null) {
return null;
}
return new SimpleCacheSpan(keyForId, Long.parseLong(matcher.group(2)), length, Long.parseLong(matcher.group(3)), file2);
}
@Nullable
private static File upgradeFile(File file, CachedContentIndex cachedContentIndex) {
String group;
String name = file.getName();
Matcher matcher = CACHE_FILE_PATTERN_V2.matcher(name);
if (matcher.matches()) {
group = Util.unescapeFileName(matcher.group(1));
if (group == null) {
return null;
}
} else {
matcher = CACHE_FILE_PATTERN_V1.matcher(name);
if (!matcher.matches()) {
return null;
}
group = matcher.group(1);
}
File cacheFile = getCacheFile(file.getParentFile(), cachedContentIndex.assignIdForKey(group), Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3)));
if (file.renameTo(cacheFile)) {
return cacheFile;
}
return null;
}
private SimpleCacheSpan(String str, long j, long j2, long j3, @Nullable File file) {
super(str, j, j2, j3, file);
}
public final SimpleCacheSpan copyWithUpdatedLastAccessTime(int i) {
Assertions.checkState(this.isCached);
long currentTimeMillis = System.currentTimeMillis();
return new SimpleCacheSpan(this.key, this.position, this.length, currentTimeMillis, getCacheFile(this.file.getParentFile(), i, this.position, currentTimeMillis));
}
}