Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
/* loaded from: classes4.dex */
public final class Allocation {
public final byte[] data;
public final int offset;
public Allocation(byte[] bArr, int i) {
this.data = bArr;
this.offset = i;
}
}

View File

@@ -0,0 +1,16 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
/* loaded from: classes4.dex */
public interface Allocator {
Allocation allocate();
int getIndividualAllocationLength();
int getTotalBytesAllocated();
void release(Allocation allocation);
void release(Allocation[] allocationArr);
void trim();
}

View File

@@ -0,0 +1,133 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class AssetDataSource implements DataSource {
private final AssetManager assetManager;
private long bytesRemaining;
private InputStream inputStream;
private final TransferListener<? super AssetDataSource> listener;
private boolean opened;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static final class AssetDataSourceException extends IOException {
public AssetDataSourceException(IOException iOException) {
super(iOException);
}
}
public AssetDataSource(Context context) {
this(context, null);
}
public AssetDataSource(Context context, TransferListener<? super AssetDataSource> transferListener) {
this.assetManager = context.getAssets();
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws AssetDataSourceException {
try {
Uri uri = dataSpec.uri;
this.uri = uri;
String path = uri.getPath();
if (path.startsWith("/android_asset/")) {
path = path.substring(15);
} else if (path.startsWith("/")) {
path = path.substring(1);
}
InputStream open = this.assetManager.open(path, 1);
this.inputStream = open;
if (open.skip(dataSpec.position) < dataSpec.position) {
throw new EOFException();
}
long j = dataSpec.length;
if (j != -1) {
this.bytesRemaining = j;
} else {
long available = this.inputStream.available();
this.bytesRemaining = available;
if (available == 2147483647L) {
this.bytesRemaining = -1L;
}
}
this.opened = true;
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesRemaining;
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws AssetDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
if (j != -1) {
try {
i2 = (int) Math.min(j, i2);
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
}
int read = this.inputStream.read(bArr, i, i2);
if (read == -1) {
if (this.bytesRemaining == -1) {
return -1;
}
throw new AssetDataSourceException(new EOFException());
}
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - read;
}
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws AssetDataSourceException {
this.uri = null;
try {
try {
InputStream inputStream = this.inputStream;
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
} finally {
this.inputStream = null;
if (this.opened) {
this.opened = false;
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
/* loaded from: classes4.dex */
public interface BandwidthMeter {
public interface EventListener {
void onBandwidthSample(int i, long j, long j2);
}
long getBitrateEstimate();
}

View File

@@ -0,0 +1,39 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class ByteArrayDataSink implements DataSink {
private ByteArrayOutputStream stream;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void open(DataSpec dataSpec) throws IOException {
long j = dataSpec.length;
if (j == -1) {
this.stream = new ByteArrayOutputStream();
} else {
Assertions.checkArgument(j <= 2147483647L);
this.stream = new ByteArrayOutputStream((int) dataSpec.length);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void close() throws IOException {
this.stream.close();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void write(byte[] bArr, int i, int i2) throws IOException {
this.stream.write(bArr, i, i2);
}
public final byte[] getData() {
ByteArrayOutputStream byteArrayOutputStream = this.stream;
if (byteArrayOutputStream == null) {
return null;
}
return byteArrayOutputStream.toByteArray();
}
}

View File

@@ -0,0 +1,63 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class ByteArrayDataSource implements DataSource {
private int bytesRemaining;
private final byte[] data;
private int readPosition;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
this.uri = null;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public ByteArrayDataSource(byte[] bArr) {
Assertions.checkNotNull(bArr);
Assertions.checkArgument(bArr.length > 0);
this.data = bArr;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
this.uri = dataSpec.uri;
long j = dataSpec.position;
int i = (int) j;
this.readPosition = i;
long j2 = dataSpec.length;
if (j2 == -1) {
j2 = this.data.length - j;
}
int i2 = (int) j2;
this.bytesRemaining = i2;
if (i2 > 0 && i + i2 <= this.data.length) {
return i2;
}
throw new IOException("Unsatisfiable range: [" + this.readPosition + ", " + dataSpec.length + "], length: " + this.data.length);
}
@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;
}
int i3 = this.bytesRemaining;
if (i3 == 0) {
return -1;
}
int min = Math.min(i2, i3);
System.arraycopy(this.data, this.readPosition, bArr, i, min);
this.readPosition += min;
this.bytesRemaining -= min;
return min;
}
}

View File

@@ -0,0 +1,185 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.FileChannel;
/* loaded from: classes4.dex */
public final class ContentDataSource implements DataSource {
private AssetFileDescriptor assetFileDescriptor;
private long bytesRemaining;
private FileInputStream inputStream;
private final TransferListener<? super ContentDataSource> listener;
private boolean opened;
private final ContentResolver resolver;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static class ContentDataSourceException extends IOException {
public ContentDataSourceException(IOException iOException) {
super(iOException);
}
}
public ContentDataSource(Context context) {
this(context, null);
}
public ContentDataSource(Context context, TransferListener<? super ContentDataSource> transferListener) {
this.resolver = context.getContentResolver();
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws ContentDataSourceException {
try {
Uri uri = dataSpec.uri;
this.uri = uri;
AssetFileDescriptor openAssetFileDescriptor = this.resolver.openAssetFileDescriptor(uri, "r");
this.assetFileDescriptor = openAssetFileDescriptor;
if (openAssetFileDescriptor == null) {
throw new FileNotFoundException("Could not open file descriptor for: " + this.uri);
}
this.inputStream = new FileInputStream(this.assetFileDescriptor.getFileDescriptor());
long startOffset = this.assetFileDescriptor.getStartOffset();
long skip = this.inputStream.skip(dataSpec.position + startOffset) - startOffset;
if (skip != dataSpec.position) {
throw new EOFException();
}
long j = dataSpec.length;
long j2 = -1;
if (j != -1) {
this.bytesRemaining = j;
} else {
long length = this.assetFileDescriptor.getLength();
if (length == -1) {
FileChannel channel = this.inputStream.getChannel();
long size = channel.size();
if (size != 0) {
j2 = size - channel.position();
}
this.bytesRemaining = j2;
} else {
this.bytesRemaining = length - skip;
}
}
this.opened = true;
TransferListener<? super ContentDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesRemaining;
} catch (IOException e) {
throw new ContentDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws ContentDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
if (j != -1) {
try {
i2 = (int) Math.min(j, i2);
} catch (IOException e) {
throw new ContentDataSourceException(e);
}
}
int read = this.inputStream.read(bArr, i, i2);
if (read == -1) {
if (this.bytesRemaining == -1) {
return -1;
}
throw new ContentDataSourceException(new EOFException());
}
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - read;
}
TransferListener<? super ContentDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws ContentDataSourceException {
this.uri = null;
try {
try {
FileInputStream fileInputStream = this.inputStream;
if (fileInputStream != null) {
fileInputStream.close();
}
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor = this.assetFileDescriptor;
if (assetFileDescriptor != null) {
assetFileDescriptor.close();
}
} catch (IOException e) {
throw new ContentDataSourceException(e);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super ContentDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
} catch (IOException e2) {
throw new ContentDataSourceException(e2);
}
} catch (Throwable th) {
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor2 = this.assetFileDescriptor;
if (assetFileDescriptor2 != null) {
assetFileDescriptor2.close();
}
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super ContentDataSource> transferListener2 = this.listener;
if (transferListener2 != null) {
transferListener2.onTransferEnd(this);
}
}
throw th;
} catch (IOException e3) {
throw new ContentDataSourceException(e3);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super ContentDataSource> transferListener3 = this.listener;
if (transferListener3 != null) {
transferListener3.onTransferEnd(this);
}
}
}
}
}
}

View File

@@ -0,0 +1,71 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import android.util.Base64;
import com.mbridge.msdk.playercommon.exoplayer2.ParserException;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.IOException;
import java.net.URLDecoder;
/* loaded from: classes4.dex */
public final class DataSchemeDataSource implements DataSource {
public static final String SCHEME_DATA = "data";
private int bytesRead;
private byte[] data;
private DataSpec dataSpec;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
this.dataSpec = null;
this.data = null;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
this.dataSpec = dataSpec;
Uri uri = dataSpec.uri;
String scheme = uri.getScheme();
if (!"data".equals(scheme)) {
throw new ParserException("Unsupported scheme: " + scheme);
}
String[] split = Util.split(uri.getSchemeSpecificPart(), ",");
if (split.length != 2) {
throw new ParserException("Unexpected URI format: " + uri);
}
String str = split[1];
if (split[0].contains(";base64")) {
try {
this.data = Base64.decode(str, 0);
} catch (IllegalArgumentException e) {
throw new ParserException("Error while parsing Base64 encoded string: " + str, e);
}
} else {
this.data = URLDecoder.decode(str, "US-ASCII").getBytes();
}
return this.data.length;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) {
if (i2 == 0) {
return 0;
}
int length = this.data.length - this.bytesRead;
if (length == 0) {
return -1;
}
int min = Math.min(i2, length);
System.arraycopy(this.data, this.bytesRead, bArr, i, min);
this.bytesRead += min;
return min;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
DataSpec dataSpec = this.dataSpec;
if (dataSpec != null) {
return dataSpec.uri;
}
return null;
}
}

View File

@@ -0,0 +1,17 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import java.io.IOException;
/* loaded from: classes4.dex */
public interface DataSink {
public interface Factory {
DataSink createDataSink();
}
void close() throws IOException;
void open(DataSpec dataSpec) throws IOException;
void write(byte[] bArr, int i, int i2) throws IOException;
}

View File

@@ -0,0 +1,22 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import androidx.annotation.Nullable;
import java.io.IOException;
/* loaded from: classes4.dex */
public interface DataSource {
public interface Factory {
DataSource createDataSource();
}
void close() throws IOException;
@Nullable
Uri getUri();
long open(DataSpec dataSpec) throws IOException;
int read(byte[] bArr, int i, int i2) throws IOException;
}

View File

@@ -0,0 +1,13 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class DataSourceException extends IOException {
public static final int POSITION_OUT_OF_RANGE = 0;
public final int reason;
public DataSourceException(int i) {
this.reason = i;
}
}

View File

@@ -0,0 +1,71 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import androidx.annotation.NonNull;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class DataSourceInputStream extends InputStream {
private final DataSource dataSource;
private final DataSpec dataSpec;
private long totalBytesRead;
private boolean opened = false;
private boolean closed = false;
private final byte[] singleByteArray = new byte[1];
public final long bytesRead() {
return this.totalBytesRead;
}
public DataSourceInputStream(DataSource dataSource, DataSpec dataSpec) {
this.dataSource = dataSource;
this.dataSpec = dataSpec;
}
public final void open() throws IOException {
checkOpened();
}
@Override // java.io.InputStream
public final int read() throws IOException {
if (read(this.singleByteArray) == -1) {
return -1;
}
return this.singleByteArray[0] & 255;
}
@Override // java.io.InputStream
public final int read(@NonNull byte[] bArr) throws IOException {
return read(bArr, 0, bArr.length);
}
@Override // java.io.InputStream
public final int read(@NonNull byte[] bArr, int i, int i2) throws IOException {
Assertions.checkState(!this.closed);
checkOpened();
int read = this.dataSource.read(bArr, i, i2);
if (read == -1) {
return -1;
}
this.totalBytesRead += read;
return read;
}
@Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
if (this.closed) {
return;
}
this.dataSource.close();
this.closed = true;
}
private void checkOpened() throws IOException {
if (this.opened) {
return;
}
this.dataSource.open(this.dataSpec);
this.opened = true;
}
}

View File

@@ -0,0 +1,88 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.ironsource.v8;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
/* loaded from: classes4.dex */
public final class DataSpec {
public static final int FLAG_ALLOW_CACHING_UNKNOWN_LENGTH = 2;
public static final int FLAG_ALLOW_GZIP = 1;
public final long absoluteStreamPosition;
public final int flags;
@Nullable
public final String key;
public final long length;
public final long position;
@Nullable
public final byte[] postBody;
public final Uri uri;
@Retention(RetentionPolicy.SOURCE)
public @interface Flags {
}
public final boolean isFlagSet(int i) {
return (this.flags & i) == i;
}
public DataSpec(Uri uri) {
this(uri, 0);
}
public DataSpec(Uri uri, int i) {
this(uri, 0L, -1L, null, i);
}
public DataSpec(Uri uri, long j, long j2, @Nullable String str) {
this(uri, j, j, j2, str, 0);
}
public DataSpec(Uri uri, long j, long j2, @Nullable String str, int i) {
this(uri, j, j, j2, str, i);
}
public DataSpec(Uri uri, long j, long j2, long j3, @Nullable String str, int i) {
this(uri, null, j, j2, j3, str, i);
}
public DataSpec(Uri uri, @Nullable byte[] bArr, long j, long j2, long j3, @Nullable String str, int i) {
boolean z = true;
Assertions.checkArgument(j >= 0);
Assertions.checkArgument(j2 >= 0);
if (j3 <= 0 && j3 != -1) {
z = false;
}
Assertions.checkArgument(z);
this.uri = uri;
this.postBody = bArr;
this.absoluteStreamPosition = j;
this.position = j2;
this.length = j3;
this.key = str;
this.flags = i;
}
public final String toString() {
return "DataSpec[" + this.uri + ", " + Arrays.toString(this.postBody) + ", " + this.absoluteStreamPosition + ", " + this.position + ", " + this.length + ", " + this.key + ", " + this.flags + v8.i.e;
}
public final DataSpec subrange(long j) {
long j2 = this.length;
return subrange(j, j2 != -1 ? j2 - j : -1L);
}
public final DataSpec subrange(long j, long j2) {
return (j == 0 && this.length == j2) ? this : new DataSpec(this.uri, this.postBody, this.absoluteStreamPosition + j, this.position + j, j2, this.key, this.flags);
}
public final DataSpec withUri(Uri uri) {
return new DataSpec(uri, this.postBody, this.absoluteStreamPosition, this.position, this.length, this.key, this.flags);
}
}

View File

@@ -0,0 +1,160 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.util.Arrays;
/* loaded from: classes4.dex */
public final class DefaultAllocator implements Allocator {
private static final int AVAILABLE_EXTRA_CAPACITY = 100;
private int allocatedCount;
private Allocation[] availableAllocations;
private int availableCount;
private final int individualAllocationSize;
private final byte[] initialAllocationBlock;
private final Allocation[] singleAllocationReleaseHolder;
private int targetBufferSize;
private final boolean trimOnReset;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final int getIndividualAllocationLength() {
return this.individualAllocationSize;
}
public DefaultAllocator(boolean z, int i) {
this(z, i, 0);
}
public DefaultAllocator(boolean z, int i, int i2) {
Assertions.checkArgument(i > 0);
Assertions.checkArgument(i2 >= 0);
this.trimOnReset = z;
this.individualAllocationSize = i;
this.availableCount = i2;
this.availableAllocations = new Allocation[i2 + 100];
if (i2 > 0) {
this.initialAllocationBlock = new byte[i2 * i];
for (int i3 = 0; i3 < i2; i3++) {
this.availableAllocations[i3] = new Allocation(this.initialAllocationBlock, i3 * i);
}
} else {
this.initialAllocationBlock = null;
}
this.singleAllocationReleaseHolder = new Allocation[1];
}
public final synchronized void reset() {
if (this.trimOnReset) {
setTargetBufferSize(0);
}
}
public final synchronized void setTargetBufferSize(int i) {
boolean z = i < this.targetBufferSize;
this.targetBufferSize = i;
if (z) {
trim();
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final synchronized Allocation allocate() {
Allocation allocation;
try {
this.allocatedCount++;
int i = this.availableCount;
if (i > 0) {
Allocation[] allocationArr = this.availableAllocations;
int i2 = i - 1;
this.availableCount = i2;
allocation = allocationArr[i2];
allocationArr[i2] = null;
} else {
allocation = new Allocation(new byte[this.individualAllocationSize], 0);
}
} catch (Throwable th) {
throw th;
}
return allocation;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final synchronized void release(Allocation allocation) {
Allocation[] allocationArr = this.singleAllocationReleaseHolder;
allocationArr[0] = allocation;
release(allocationArr);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final synchronized void release(Allocation[] allocationArr) {
try {
int i = this.availableCount;
int length = allocationArr.length + i;
Allocation[] allocationArr2 = this.availableAllocations;
if (length >= allocationArr2.length) {
this.availableAllocations = (Allocation[]) Arrays.copyOf(allocationArr2, Math.max(allocationArr2.length * 2, i + allocationArr.length));
}
for (Allocation allocation : allocationArr) {
byte[] bArr = allocation.data;
if (bArr != this.initialAllocationBlock && bArr.length != this.individualAllocationSize) {
throw new IllegalArgumentException("Unexpected allocation: " + System.identityHashCode(allocation.data) + ", " + System.identityHashCode(this.initialAllocationBlock) + ", " + allocation.data.length + ", " + this.individualAllocationSize);
}
Allocation[] allocationArr3 = this.availableAllocations;
int i2 = this.availableCount;
this.availableCount = i2 + 1;
allocationArr3[i2] = allocation;
}
this.allocatedCount -= allocationArr.length;
notifyAll();
} catch (Throwable th) {
throw th;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final synchronized void trim() {
try {
int i = 0;
int max = Math.max(0, Util.ceilDivide(this.targetBufferSize, this.individualAllocationSize) - this.allocatedCount);
int i2 = this.availableCount;
if (max >= i2) {
return;
}
if (this.initialAllocationBlock != null) {
int i3 = i2 - 1;
while (i <= i3) {
Allocation[] allocationArr = this.availableAllocations;
Allocation allocation = allocationArr[i];
byte[] bArr = allocation.data;
byte[] bArr2 = this.initialAllocationBlock;
if (bArr == bArr2) {
i++;
} else {
Allocation allocation2 = allocationArr[i3];
if (allocation2.data != bArr2) {
i3--;
} else {
allocationArr[i] = allocation2;
allocationArr[i3] = allocation;
i3--;
i++;
}
}
}
max = Math.max(max, i);
if (max >= this.availableCount) {
return;
}
}
Arrays.fill(this.availableAllocations, max, this.availableCount, (Object) null);
this.availableCount = max;
} catch (Throwable th) {
throw th;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Allocator
public final synchronized int getTotalBytesAllocated() {
return this.allocatedCount * this.individualAllocationSize;
}
}

View File

@@ -0,0 +1,156 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.os.Handler;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.BandwidthMeter;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Clock;
import com.mbridge.msdk.playercommon.exoplayer2.util.SlidingPercentile;
/* loaded from: classes4.dex */
public final class DefaultBandwidthMeter implements BandwidthMeter, TransferListener<Object> {
private static final int BYTES_TRANSFERRED_FOR_ESTIMATE = 524288;
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE = 1000000;
public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000;
private static final int ELAPSED_MILLIS_FOR_ESTIMATE = 2000;
private long bitrateEstimate;
private final Clock clock;
@Nullable
private final Handler eventHandler;
@Nullable
private final BandwidthMeter.EventListener eventListener;
private long sampleBytesTransferred;
private long sampleStartTimeMs;
private final SlidingPercentile slidingPercentile;
private int streamCount;
private long totalBytesTransferred;
private long totalElapsedTimeMs;
public static final class Builder {
@Nullable
private Handler eventHandler;
@Nullable
private BandwidthMeter.EventListener eventListener;
private long initialBitrateEstimate = 1000000;
private int slidingWindowMaxWeight = 2000;
private Clock clock = Clock.DEFAULT;
public final Builder setClock(Clock clock) {
this.clock = clock;
return this;
}
public final Builder setInitialBitrateEstimate(long j) {
this.initialBitrateEstimate = j;
return this;
}
public final Builder setSlidingWindowMaxWeight(int i) {
this.slidingWindowMaxWeight = i;
return this;
}
public final Builder setEventListener(Handler handler, BandwidthMeter.EventListener eventListener) {
Assertions.checkArgument((handler == null || eventListener == null) ? false : true);
this.eventHandler = handler;
this.eventListener = eventListener;
return this;
}
public final DefaultBandwidthMeter build() {
return new DefaultBandwidthMeter(this.eventHandler, this.eventListener, this.initialBitrateEstimate, this.slidingWindowMaxWeight, this.clock);
}
}
public DefaultBandwidthMeter() {
this(null, null, 1000000L, 2000, Clock.DEFAULT);
}
@Deprecated
public DefaultBandwidthMeter(Handler handler, BandwidthMeter.EventListener eventListener) {
this(handler, eventListener, 1000000L, 2000, Clock.DEFAULT);
}
@Deprecated
public DefaultBandwidthMeter(Handler handler, BandwidthMeter.EventListener eventListener, int i) {
this(handler, eventListener, 1000000L, i, Clock.DEFAULT);
}
private DefaultBandwidthMeter(@Nullable Handler handler, @Nullable BandwidthMeter.EventListener eventListener, long j, int i, Clock clock) {
this.eventHandler = handler;
this.eventListener = eventListener;
this.slidingPercentile = new SlidingPercentile(i);
this.clock = clock;
this.bitrateEstimate = j;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.BandwidthMeter
public final synchronized long getBitrateEstimate() {
return this.bitrateEstimate;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.TransferListener
public final synchronized void onTransferStart(Object obj, DataSpec dataSpec) {
try {
if (this.streamCount == 0) {
this.sampleStartTimeMs = this.clock.elapsedRealtime();
}
this.streamCount++;
} catch (Throwable th) {
throw th;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.TransferListener
public final synchronized void onBytesTransferred(Object obj, int i) {
this.sampleBytesTransferred += i;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.TransferListener
public final synchronized void onTransferEnd(Object obj) {
try {
Assertions.checkState(this.streamCount > 0);
long elapsedRealtime = this.clock.elapsedRealtime();
int i = (int) (elapsedRealtime - this.sampleStartTimeMs);
this.totalElapsedTimeMs += i;
long j = this.totalBytesTransferred;
long j2 = this.sampleBytesTransferred;
this.totalBytesTransferred = j + j2;
if (i > 0) {
this.slidingPercentile.addSample((int) Math.sqrt(j2), (8000 * j2) / r7);
if (this.totalElapsedTimeMs < 2000) {
if (this.totalBytesTransferred >= PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE_ENABLED) {
}
}
this.bitrateEstimate = (long) this.slidingPercentile.getPercentile(0.5f);
}
notifyBandwidthSample(i, this.sampleBytesTransferred, this.bitrateEstimate);
int i2 = this.streamCount - 1;
this.streamCount = i2;
if (i2 > 0) {
this.sampleStartTimeMs = elapsedRealtime;
}
this.sampleBytesTransferred = 0L;
} catch (Throwable th) {
throw th;
}
}
private void notifyBandwidthSample(final int i, final long j, final long j2) {
Handler handler = this.eventHandler;
if (handler == null || this.eventListener == null) {
return;
}
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.upstream.DefaultBandwidthMeter.1
@Override // java.lang.Runnable
public void run() {
DefaultBandwidthMeter.this.eventListener.onBandwidthSample(i, j, j2);
}
});
}
}

View File

@@ -0,0 +1,144 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class DefaultDataSource implements DataSource {
private static final String SCHEME_ASSET = "asset";
private static final String SCHEME_CONTENT = "content";
private static final String SCHEME_RAW = "rawresource";
private static final String SCHEME_RTMP = "rtmp";
private static final String TAG = "DefaultDataSource";
private DataSource assetDataSource;
private final DataSource baseDataSource;
private DataSource contentDataSource;
private final Context context;
private DataSource dataSchemeDataSource;
private DataSource dataSource;
private DataSource fileDataSource;
private final TransferListener<? super DataSource> listener;
private DataSource rawResourceDataSource;
private DataSource rtmpDataSource;
public DefaultDataSource(Context context, TransferListener<? super DataSource> transferListener, String str, boolean z) {
this(context, transferListener, str, 8000, 8000, z);
}
public DefaultDataSource(Context context, TransferListener<? super DataSource> transferListener, String str, int i, int i2, boolean z) {
this(context, transferListener, new DefaultHttpDataSource(str, null, transferListener, i, i2, z, null));
}
public DefaultDataSource(Context context, TransferListener<? super DataSource> transferListener, DataSource dataSource) {
this.context = context.getApplicationContext();
this.listener = transferListener;
this.baseDataSource = (DataSource) Assertions.checkNotNull(dataSource);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
Assertions.checkState(this.dataSource == null);
String scheme = dataSpec.uri.getScheme();
if (Util.isLocalFileUri(dataSpec.uri)) {
if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
this.dataSource = getAssetDataSource();
} else {
this.dataSource = getFileDataSource();
}
} else if (SCHEME_ASSET.equals(scheme)) {
this.dataSource = getAssetDataSource();
} else if ("content".equals(scheme)) {
this.dataSource = getContentDataSource();
} else if (SCHEME_RTMP.equals(scheme)) {
this.dataSource = getRtmpDataSource();
} else if ("data".equals(scheme)) {
this.dataSource = getDataSchemeDataSource();
} else if ("rawresource".equals(scheme)) {
this.dataSource = getRawResourceDataSource();
} else {
this.dataSource = this.baseDataSource;
}
return this.dataSource.open(dataSpec);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws IOException {
return this.dataSource.read(bArr, i, i2);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
DataSource dataSource = this.dataSource;
if (dataSource == null) {
return null;
}
return dataSource.getUri();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
DataSource dataSource = this.dataSource;
if (dataSource != null) {
try {
dataSource.close();
} finally {
this.dataSource = null;
}
}
}
private DataSource getFileDataSource() {
if (this.fileDataSource == null) {
this.fileDataSource = new FileDataSource(this.listener);
}
return this.fileDataSource;
}
private DataSource getAssetDataSource() {
if (this.assetDataSource == null) {
this.assetDataSource = new AssetDataSource(this.context, this.listener);
}
return this.assetDataSource;
}
private DataSource getContentDataSource() {
if (this.contentDataSource == null) {
this.contentDataSource = new ContentDataSource(this.context, this.listener);
}
return this.contentDataSource;
}
private DataSource getRtmpDataSource() {
if (this.rtmpDataSource == null) {
try {
this.rtmpDataSource = (DataSource) Class.forName("com.mbridge.msdk.playercommon.exoplayer2.ext.rtmp.RtmpDataSource").getConstructor(new Class[0]).newInstance(new Object[0]);
} catch (ClassNotFoundException unused) {
Log.w(TAG, "Attempting to play RTMP stream without depending on the RTMP extension");
} catch (Exception e) {
throw new RuntimeException("Error instantiating RTMP extension", e);
}
if (this.rtmpDataSource == null) {
this.rtmpDataSource = this.baseDataSource;
}
}
return this.rtmpDataSource;
}
private DataSource getDataSchemeDataSource() {
if (this.dataSchemeDataSource == null) {
this.dataSchemeDataSource = new DataSchemeDataSource();
}
return this.dataSchemeDataSource;
}
private DataSource getRawResourceDataSource() {
if (this.rawResourceDataSource == null) {
this.rawResourceDataSource = new RawResourceDataSource(this.context, this.listener);
}
return this.rawResourceDataSource;
}
}

View File

@@ -0,0 +1,30 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.Context;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
/* loaded from: classes4.dex */
public final class DefaultDataSourceFactory implements DataSource.Factory {
private final DataSource.Factory baseDataSourceFactory;
private final Context context;
private final TransferListener<? super DataSource> listener;
public DefaultDataSourceFactory(Context context, String str) {
this(context, str, (TransferListener<? super DataSource>) null);
}
public DefaultDataSourceFactory(Context context, String str, TransferListener<? super DataSource> transferListener) {
this(context, transferListener, new DefaultHttpDataSourceFactory(str, transferListener));
}
public DefaultDataSourceFactory(Context context, TransferListener<? super DataSource> transferListener, DataSource.Factory factory) {
this.context = context.getApplicationContext();
this.listener = transferListener;
this.baseDataSourceFactory = factory;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public final DefaultDataSource createDataSource() {
return new DefaultDataSource(this.context, this.listener, this.baseDataSourceFactory.createDataSource());
}
}

View File

@@ -0,0 +1,488 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import android.util.Log;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
import com.mbridge.msdk.foundation.download.Command;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Predicate;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.NoRouteToHostException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import org.apache.http.protocol.HTTP;
/* loaded from: classes4.dex */
public class DefaultHttpDataSource implements HttpDataSource {
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 8000;
public static final int DEFAULT_READ_TIMEOUT_MILLIS = 8000;
private static final long MAX_BYTES_TO_DRAIN = 2048;
private static final int MAX_REDIRECTS = 20;
private static final String TAG = "DefaultHttpDataSource";
private final boolean allowCrossProtocolRedirects;
private long bytesRead;
private long bytesSkipped;
private long bytesToRead;
private long bytesToSkip;
private final int connectTimeoutMillis;
private HttpURLConnection connection;
private final Predicate<String> contentTypePredicate;
private DataSpec dataSpec;
private final HttpDataSource.RequestProperties defaultRequestProperties;
private InputStream inputStream;
private final TransferListener<? super DefaultHttpDataSource> listener;
private boolean opened;
private final int readTimeoutMillis;
private final HttpDataSource.RequestProperties requestProperties;
private final String userAgent;
private static final Pattern CONTENT_RANGE_HEADER = Pattern.compile("^bytes (\\d+)-(\\d+)/(\\d+)$");
private static final AtomicReference<byte[]> skipBufferReference = new AtomicReference<>();
public final long bytesRead() {
return this.bytesRead;
}
public final long bytesRemaining() {
long j = this.bytesToRead;
return j == -1 ? j : j - this.bytesRead;
}
public final long bytesSkipped() {
return this.bytesSkipped;
}
public final HttpURLConnection getConnection() {
return this.connection;
}
public DefaultHttpDataSource(String str, Predicate<String> predicate) {
this(str, predicate, null);
}
public DefaultHttpDataSource(String str, Predicate<String> predicate, TransferListener<? super DefaultHttpDataSource> transferListener) {
this(str, predicate, transferListener, 8000, 8000);
}
public DefaultHttpDataSource(String str, Predicate<String> predicate, TransferListener<? super DefaultHttpDataSource> transferListener, int i, int i2) {
this(str, predicate, transferListener, i, i2, false, null);
}
public DefaultHttpDataSource(String str, Predicate<String> predicate, TransferListener<? super DefaultHttpDataSource> transferListener, int i, int i2, boolean z, HttpDataSource.RequestProperties requestProperties) {
this.userAgent = Assertions.checkNotEmpty(str);
this.contentTypePredicate = predicate;
this.listener = transferListener;
this.requestProperties = new HttpDataSource.RequestProperties();
this.connectTimeoutMillis = i;
this.readTimeoutMillis = i2;
this.allowCrossProtocolRedirects = z;
this.defaultRequestProperties = requestProperties;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public Uri getUri() {
HttpURLConnection httpURLConnection = this.connection;
if (httpURLConnection == null) {
return null;
}
return Uri.parse(httpURLConnection.getURL().toString());
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource
public Map<String, List<String>> getResponseHeaders() {
HttpURLConnection httpURLConnection = this.connection;
if (httpURLConnection == null) {
return null;
}
return httpURLConnection.getHeaderFields();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource
public void setRequestProperty(String str, String str2) {
Assertions.checkNotNull(str);
Assertions.checkNotNull(str2);
this.requestProperties.set(str, str2);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource
public void clearRequestProperty(String str) {
Assertions.checkNotNull(str);
this.requestProperties.remove(str);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource
public void clearAllRequestProperties() {
this.requestProperties.clear();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource, com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public long open(DataSpec dataSpec) throws HttpDataSource.HttpDataSourceException {
this.dataSpec = dataSpec;
long j = 0;
this.bytesRead = 0L;
this.bytesSkipped = 0L;
try {
HttpURLConnection makeConnection = makeConnection(dataSpec);
this.connection = makeConnection;
try {
int responseCode = makeConnection.getResponseCode();
if (responseCode < 200 || responseCode > 299) {
Map<String, List<String>> headerFields = this.connection.getHeaderFields();
closeConnectionQuietly();
HttpDataSource.InvalidResponseCodeException invalidResponseCodeException = new HttpDataSource.InvalidResponseCodeException(responseCode, headerFields, dataSpec);
if (responseCode == 416) {
invalidResponseCodeException.initCause(new DataSourceException(0));
throw invalidResponseCodeException;
}
throw invalidResponseCodeException;
}
String contentType = this.connection.getContentType();
Predicate<String> predicate = this.contentTypePredicate;
if (predicate != null && !predicate.evaluate(contentType)) {
closeConnectionQuietly();
throw new HttpDataSource.InvalidContentTypeException(contentType, dataSpec);
}
if (responseCode == 200) {
long j2 = dataSpec.position;
if (j2 != 0) {
j = j2;
}
}
this.bytesToSkip = j;
if (!dataSpec.isFlagSet(1)) {
long j3 = dataSpec.length;
if (j3 != -1) {
this.bytesToRead = j3;
} else {
long contentLength = getContentLength(this.connection);
this.bytesToRead = contentLength != -1 ? contentLength - this.bytesToSkip : -1L;
}
} else {
this.bytesToRead = dataSpec.length;
}
try {
this.inputStream = this.connection.getInputStream();
this.opened = true;
TransferListener<? super DefaultHttpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesToRead;
} catch (IOException e) {
closeConnectionQuietly();
throw new HttpDataSource.HttpDataSourceException(e, dataSpec, 1);
}
} catch (IOException e2) {
closeConnectionQuietly();
throw new HttpDataSource.HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e2, dataSpec, 1);
}
} catch (IOException e3) {
throw new HttpDataSource.HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e3, dataSpec, 1);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource, com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public int read(byte[] bArr, int i, int i2) throws HttpDataSource.HttpDataSourceException {
try {
skipInternal();
return readInternal(bArr, i, i2);
} catch (IOException e) {
throw new HttpDataSource.HttpDataSourceException(e, this.dataSpec, 2);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource, com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public void close() throws HttpDataSource.HttpDataSourceException {
try {
if (this.inputStream != null) {
maybeTerminateInputStream(this.connection, bytesRemaining());
try {
this.inputStream.close();
} catch (IOException e) {
throw new HttpDataSource.HttpDataSourceException(e, this.dataSpec, 3);
}
}
} finally {
this.inputStream = null;
closeConnectionQuietly();
if (this.opened) {
this.opened = false;
TransferListener<? super DefaultHttpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
}
private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
HttpURLConnection makeConnection;
URL url = new URL(dataSpec.uri.toString());
byte[] bArr = dataSpec.postBody;
long j = dataSpec.position;
long j2 = dataSpec.length;
boolean isFlagSet = dataSpec.isFlagSet(1);
if (!this.allowCrossProtocolRedirects) {
return makeConnection(url, bArr, j, j2, isFlagSet, true);
}
int i = 0;
while (true) {
int i2 = i + 1;
if (i <= 20) {
long j3 = j;
makeConnection = makeConnection(url, bArr, j, j2, isFlagSet, false);
int responseCode = makeConnection.getResponseCode();
if (responseCode == 300 || responseCode == 301 || responseCode == 302 || responseCode == 303 || (bArr == null && (responseCode == 307 || responseCode == 308))) {
String headerField = makeConnection.getHeaderField("Location");
makeConnection.disconnect();
url = handleRedirect(url, headerField);
bArr = null;
i = i2;
j = j3;
}
} else {
throw new NoRouteToHostException("Too many redirects: " + i2);
}
}
return makeConnection;
}
private HttpURLConnection makeConnection(URL url, byte[] bArr, long j, long j2, boolean z, boolean z2) throws IOException {
HttpURLConnection httpURLConnection = (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection()));
httpURLConnection.setConnectTimeout(this.connectTimeoutMillis);
httpURLConnection.setReadTimeout(this.readTimeoutMillis);
HttpDataSource.RequestProperties requestProperties = this.defaultRequestProperties;
if (requestProperties != null) {
for (Map.Entry<String, String> entry : requestProperties.getSnapshot().entrySet()) {
httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, String> entry2 : this.requestProperties.getSnapshot().entrySet()) {
httpURLConnection.setRequestProperty(entry2.getKey(), entry2.getValue());
}
if (j != 0 || j2 != -1) {
String str = "bytes=" + j + "-";
if (j2 != -1) {
str = str + ((j + j2) - 1);
}
httpURLConnection.setRequestProperty(Command.HTTP_HEADER_RANGE, str);
}
httpURLConnection.setRequestProperty("User-Agent", this.userAgent);
if (!z) {
httpURLConnection.setRequestProperty("Accept-Encoding", HTTP.IDENTITY_CODING);
}
httpURLConnection.setInstanceFollowRedirects(z2);
httpURLConnection.setDoOutput(bArr != null);
if (bArr != null) {
httpURLConnection.setRequestMethod("POST");
if (bArr.length != 0) {
httpURLConnection.setFixedLengthStreamingMode(bArr.length);
httpURLConnection.connect();
OutputStream outputStream = httpURLConnection.getOutputStream();
outputStream.write(bArr);
outputStream.close();
return httpURLConnection;
}
}
httpURLConnection.connect();
return httpURLConnection;
}
private static URL handleRedirect(URL url, String str) throws IOException {
if (str == null) {
throw new ProtocolException("Null location redirect");
}
URL url2 = new URL(url, str);
String protocol = url2.getProtocol();
if ("https".equals(protocol) || "http".equals(protocol)) {
return url2;
}
throw new ProtocolException("Unsupported protocol redirect: " + protocol);
}
/* JADX WARN: Removed duplicated region for block: B:24:? A[RETURN, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:6:0x003a */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private static long getContentLength(java.net.HttpURLConnection r10) {
/*
java.lang.String r0 = "Content-Length"
java.lang.String r0 = r10.getHeaderField(r0)
boolean r1 = android.text.TextUtils.isEmpty(r0)
java.lang.String r2 = "]"
java.lang.String r3 = "DefaultHttpDataSource"
if (r1 != 0) goto L2c
long r4 = java.lang.Long.parseLong(r0) // Catch: java.lang.NumberFormatException -> L15
goto L2e
L15:
java.lang.StringBuilder r1 = new java.lang.StringBuilder
r1.<init>()
java.lang.String r4 = "Unexpected Content-Length ["
r1.append(r4)
r1.append(r0)
r1.append(r2)
java.lang.String r1 = r1.toString()
android.util.Log.e(r3, r1)
L2c:
r4 = -1
L2e:
java.lang.String r1 = "Content-Range"
java.lang.String r10 = r10.getHeaderField(r1)
boolean r1 = android.text.TextUtils.isEmpty(r10)
if (r1 != 0) goto La3
java.util.regex.Pattern r1 = com.mbridge.msdk.playercommon.exoplayer2.upstream.DefaultHttpDataSource.CONTENT_RANGE_HEADER
java.util.regex.Matcher r1 = r1.matcher(r10)
boolean r6 = r1.find()
if (r6 == 0) goto La3
r6 = 2
java.lang.String r6 = r1.group(r6) // Catch: java.lang.NumberFormatException -> L8c
long r6 = java.lang.Long.parseLong(r6) // Catch: java.lang.NumberFormatException -> L8c
r8 = 1
java.lang.String r1 = r1.group(r8) // Catch: java.lang.NumberFormatException -> L8c
long r8 = java.lang.Long.parseLong(r1) // Catch: java.lang.NumberFormatException -> L8c
long r6 = r6 - r8
r8 = 1
long r6 = r6 + r8
r8 = 0
int r1 = (r4 > r8 ? 1 : (r4 == r8 ? 0 : -1))
if (r1 >= 0) goto L64
r4 = r6
goto La3
L64:
int r1 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1))
if (r1 == 0) goto La3
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.lang.NumberFormatException -> L8c
r1.<init>() // Catch: java.lang.NumberFormatException -> L8c
java.lang.String r8 = "Inconsistent headers ["
r1.append(r8) // Catch: java.lang.NumberFormatException -> L8c
r1.append(r0) // Catch: java.lang.NumberFormatException -> L8c
java.lang.String r0 = "] ["
r1.append(r0) // Catch: java.lang.NumberFormatException -> L8c
r1.append(r10) // Catch: java.lang.NumberFormatException -> L8c
r1.append(r2) // Catch: java.lang.NumberFormatException -> L8c
java.lang.String r0 = r1.toString() // Catch: java.lang.NumberFormatException -> L8c
android.util.Log.w(r3, r0) // Catch: java.lang.NumberFormatException -> L8c
long r4 = java.lang.Math.max(r4, r6) // Catch: java.lang.NumberFormatException -> L8c
goto La3
L8c:
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>()
java.lang.String r1 = "Unexpected Content-Range ["
r0.append(r1)
r0.append(r10)
r0.append(r2)
java.lang.String r10 = r0.toString()
android.util.Log.e(r3, r10)
La3:
return r4
*/
throw new UnsupportedOperationException("Method not decompiled: com.mbridge.msdk.playercommon.exoplayer2.upstream.DefaultHttpDataSource.getContentLength(java.net.HttpURLConnection):long");
}
private void skipInternal() throws IOException {
if (this.bytesSkipped == this.bytesToSkip) {
return;
}
byte[] andSet = skipBufferReference.getAndSet(null);
if (andSet == null) {
andSet = new byte[4096];
}
while (true) {
long j = this.bytesSkipped;
long j2 = this.bytesToSkip;
if (j != j2) {
int read = this.inputStream.read(andSet, 0, (int) Math.min(j2 - j, andSet.length));
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedIOException();
}
if (read == -1) {
throw new EOFException();
}
this.bytesSkipped += read;
TransferListener<? super DefaultHttpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
} else {
skipBufferReference.set(andSet);
return;
}
}
}
private int readInternal(byte[] bArr, int i, int i2) throws IOException {
if (i2 == 0) {
return 0;
}
long j = this.bytesToRead;
if (j != -1) {
long j2 = j - this.bytesRead;
if (j2 == 0) {
return -1;
}
i2 = (int) Math.min(i2, j2);
}
int read = this.inputStream.read(bArr, i, i2);
if (read == -1) {
if (this.bytesToRead == -1) {
return -1;
}
throw new EOFException();
}
this.bytesRead += read;
TransferListener<? super DefaultHttpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
return read;
}
private static void maybeTerminateInputStream(HttpURLConnection httpURLConnection, long j) {
int i = Util.SDK_INT;
if (i == 19 || i == 20) {
try {
InputStream inputStream = httpURLConnection.getInputStream();
if (j == -1) {
if (inputStream.read() == -1) {
return;
}
} else if (j <= 2048) {
return;
}
String name = inputStream.getClass().getName();
if ("com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream".equals(name) || "com.android.okhttp.internal.http.HttpTransport$FixedLengthInputStream".equals(name)) {
Method declaredMethod = inputStream.getClass().getSuperclass().getDeclaredMethod("unexpectedEndOfInput", new Class[0]);
declaredMethod.setAccessible(true);
declaredMethod.invoke(inputStream, new Object[0]);
}
} catch (Exception unused) {
}
}
}
private void closeConnectionQuietly() {
HttpURLConnection httpURLConnection = this.connection;
if (httpURLConnection != null) {
try {
httpURLConnection.disconnect();
} catch (Exception e) {
Log.e(TAG, "Unexpected error while disconnecting", e);
}
this.connection = null;
}
}
}

View File

@@ -0,0 +1,33 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource;
/* loaded from: classes4.dex */
public final class DefaultHttpDataSourceFactory extends HttpDataSource.BaseFactory {
private final boolean allowCrossProtocolRedirects;
private final int connectTimeoutMillis;
private final TransferListener<? super DataSource> listener;
private final int readTimeoutMillis;
private final String userAgent;
public DefaultHttpDataSourceFactory(String str) {
this(str, null);
}
public DefaultHttpDataSourceFactory(String str, TransferListener<? super DataSource> transferListener) {
this(str, transferListener, 8000, 8000, false);
}
public DefaultHttpDataSourceFactory(String str, TransferListener<? super DataSource> transferListener, int i, int i2, boolean z) {
this.userAgent = str;
this.listener = transferListener;
this.connectTimeoutMillis = i;
this.readTimeoutMillis = i2;
this.allowCrossProtocolRedirects = z;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.BaseFactory
public final DefaultHttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties requestProperties) {
return new DefaultHttpDataSource(this.userAgent, null, this.listener, this.connectTimeoutMillis, this.readTimeoutMillis, this.allowCrossProtocolRedirects, requestProperties);
}
}

View File

@@ -0,0 +1,38 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class DummyDataSource implements DataSource {
public static final DummyDataSource INSTANCE = new DummyDataSource();
public static final DataSource.Factory FACTORY = new DataSource.Factory() { // from class: com.mbridge.msdk.playercommon.exoplayer2.upstream.DummyDataSource.1
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public DataSource createDataSource() {
return new DummyDataSource();
}
};
private DummyDataSource() {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return null;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
throw new IOException("Dummy source");
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws IOException {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,108 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import java.io.EOFException;
import java.io.IOException;
import java.io.RandomAccessFile;
/* loaded from: classes4.dex */
public final class FileDataSource implements DataSource {
private long bytesRemaining;
private RandomAccessFile file;
private final TransferListener<? super FileDataSource> listener;
private boolean opened;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static class FileDataSourceException extends IOException {
public FileDataSourceException(IOException iOException) {
super(iOException);
}
}
public FileDataSource() {
this(null);
}
public FileDataSource(TransferListener<? super FileDataSource> transferListener) {
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws FileDataSourceException {
try {
this.uri = dataSpec.uri;
RandomAccessFile randomAccessFile = new RandomAccessFile(dataSpec.uri.getPath(), "r");
this.file = randomAccessFile;
randomAccessFile.seek(dataSpec.position);
long j = dataSpec.length;
if (j == -1) {
j = this.file.length() - dataSpec.position;
}
this.bytesRemaining = j;
if (j < 0) {
throw new EOFException();
}
this.opened = true;
TransferListener<? super FileDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesRemaining;
} catch (IOException e) {
throw new FileDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws FileDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
try {
int read = this.file.read(bArr, i, (int) Math.min(j, i2));
if (read > 0) {
this.bytesRemaining -= read;
TransferListener<? super FileDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
}
return read;
} catch (IOException e) {
throw new FileDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws FileDataSourceException {
this.uri = null;
try {
try {
RandomAccessFile randomAccessFile = this.file;
if (randomAccessFile != null) {
randomAccessFile.close();
}
} catch (IOException e) {
throw new FileDataSourceException(e);
}
} finally {
this.file = null;
if (this.opened) {
this.opened = false;
TransferListener<? super FileDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
/* loaded from: classes4.dex */
public final class FileDataSourceFactory implements DataSource.Factory {
private final TransferListener<? super FileDataSource> listener;
public FileDataSourceFactory() {
this(null);
}
public FileDataSourceFactory(TransferListener<? super FileDataSource> transferListener) {
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public final DataSource createDataSource() {
return new FileDataSource(this.listener);
}
}

View File

@@ -0,0 +1,190 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.text.TextUtils;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes;
import com.mbridge.msdk.playercommon.exoplayer2.util.Predicate;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import com.tapjoy.TJAdUnitConstants;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes4.dex */
public interface HttpDataSource extends DataSource {
public static final Predicate<String> REJECT_PAYWALL_TYPES = new Predicate<String>() { // from class: com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.1
@Override // com.mbridge.msdk.playercommon.exoplayer2.util.Predicate
public boolean evaluate(String str) {
String lowerInvariant = Util.toLowerInvariant(str);
return (TextUtils.isEmpty(lowerInvariant) || (lowerInvariant.contains("text") && !lowerInvariant.contains(MimeTypes.TEXT_VTT)) || lowerInvariant.contains(TJAdUnitConstants.String.HTML) || lowerInvariant.contains("xml")) ? false : true;
}
};
public interface Factory extends DataSource.Factory {
@Deprecated
void clearAllDefaultRequestProperties();
@Deprecated
void clearDefaultRequestProperty(String str);
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
HttpDataSource createDataSource();
RequestProperties getDefaultRequestProperties();
@Deprecated
void setDefaultRequestProperty(String str, String str2);
}
void clearAllRequestProperties();
void clearRequestProperty(String str);
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
void close() throws HttpDataSourceException;
Map<String, List<String>> getResponseHeaders();
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
long open(DataSpec dataSpec) throws HttpDataSourceException;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
int read(byte[] bArr, int i, int i2) throws HttpDataSourceException;
void setRequestProperty(String str, String str2);
public static final class RequestProperties {
private final Map<String, String> requestProperties = new HashMap();
private Map<String, String> requestPropertiesSnapshot;
public final synchronized void set(String str, String str2) {
this.requestPropertiesSnapshot = null;
this.requestProperties.put(str, str2);
}
public final synchronized void set(Map<String, String> map) {
this.requestPropertiesSnapshot = null;
this.requestProperties.putAll(map);
}
public final synchronized void clearAndSet(Map<String, String> map) {
this.requestPropertiesSnapshot = null;
this.requestProperties.clear();
this.requestProperties.putAll(map);
}
public final synchronized void remove(String str) {
this.requestPropertiesSnapshot = null;
this.requestProperties.remove(str);
}
public final synchronized void clear() {
this.requestPropertiesSnapshot = null;
this.requestProperties.clear();
}
public final synchronized Map<String, String> getSnapshot() {
try {
if (this.requestPropertiesSnapshot == null) {
this.requestPropertiesSnapshot = Collections.unmodifiableMap(new HashMap(this.requestProperties));
}
} catch (Throwable th) {
throw th;
}
return this.requestPropertiesSnapshot;
}
}
public static abstract class BaseFactory implements Factory {
private final RequestProperties defaultRequestProperties = new RequestProperties();
public abstract HttpDataSource createDataSourceInternal(RequestProperties requestProperties);
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.Factory
public final RequestProperties getDefaultRequestProperties() {
return this.defaultRequestProperties;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.Factory, com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public final HttpDataSource createDataSource() {
return createDataSourceInternal(this.defaultRequestProperties);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.Factory
@Deprecated
public final void setDefaultRequestProperty(String str, String str2) {
this.defaultRequestProperties.set(str, str2);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.Factory
@Deprecated
public final void clearDefaultRequestProperty(String str) {
this.defaultRequestProperties.remove(str);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.HttpDataSource.Factory
@Deprecated
public final void clearAllDefaultRequestProperties() {
this.defaultRequestProperties.clear();
}
}
public static class HttpDataSourceException extends IOException {
public static final int TYPE_CLOSE = 3;
public static final int TYPE_OPEN = 1;
public static final int TYPE_READ = 2;
public final DataSpec dataSpec;
public final int type;
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
}
public HttpDataSourceException(DataSpec dataSpec, int i) {
this.dataSpec = dataSpec;
this.type = i;
}
public HttpDataSourceException(String str, DataSpec dataSpec, int i) {
super(str);
this.dataSpec = dataSpec;
this.type = i;
}
public HttpDataSourceException(IOException iOException, DataSpec dataSpec, int i) {
super(iOException);
this.dataSpec = dataSpec;
this.type = i;
}
public HttpDataSourceException(String str, IOException iOException, DataSpec dataSpec, int i) {
super(str, iOException);
this.dataSpec = dataSpec;
this.type = i;
}
}
public static final class InvalidContentTypeException extends HttpDataSourceException {
public final String contentType;
public InvalidContentTypeException(String str, DataSpec dataSpec) {
super("Invalid content type: " + str, dataSpec, 1);
this.contentType = str;
}
}
public static final class InvalidResponseCodeException extends HttpDataSourceException {
public final Map<String, List<String>> headerFields;
public final int responseCode;
public InvalidResponseCodeException(int i, Map<String, List<String>> map, DataSpec dataSpec) {
super("Response code: " + i, dataSpec, 1);
this.responseCode = i;
this.headerFields = map;
}
}
}

View File

@@ -0,0 +1,305 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.TraceUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.ExecutorService;
/* loaded from: classes4.dex */
public final class Loader implements LoaderErrorThrower {
public static final int DONT_RETRY = 2;
public static final int DONT_RETRY_FATAL = 3;
public static final int RETRY = 0;
public static final int RETRY_RESET_ERROR_COUNT = 1;
private LoadTask<? extends Loadable> currentTask;
private final ExecutorService downloadExecutorService;
private IOException fatalError;
public interface Callback<T extends Loadable> {
void onLoadCanceled(T t, long j, long j2, boolean z);
void onLoadCompleted(T t, long j, long j2);
int onLoadError(T t, long j, long j2, IOException iOException);
}
public interface Loadable {
void cancelLoad();
void load() throws IOException, InterruptedException;
}
public interface ReleaseCallback {
void onLoaderReleased();
}
@Retention(RetentionPolicy.SOURCE)
public @interface RetryAction {
}
public final boolean isLoading() {
return this.currentTask != null;
}
public static final class UnexpectedLoaderException extends IOException {
public UnexpectedLoaderException(Throwable th) {
super("Unexpected " + th.getClass().getSimpleName() + ": " + th.getMessage(), th);
}
}
public Loader(String str) {
this.downloadExecutorService = Util.newSingleThreadExecutor(str);
}
public final <T extends Loadable> long startLoading(T t, Callback<T> callback, int i) {
Looper myLooper = Looper.myLooper();
Assertions.checkState(myLooper != null);
this.fatalError = null;
long elapsedRealtime = SystemClock.elapsedRealtime();
new LoadTask(myLooper, t, callback, i, elapsedRealtime).start(0L);
return elapsedRealtime;
}
public final void cancelLoading() {
this.currentTask.cancel(false);
}
public final void release() {
release(null);
}
public final void release(@Nullable ReleaseCallback releaseCallback) {
LoadTask<? extends Loadable> loadTask = this.currentTask;
if (loadTask != null) {
loadTask.cancel(true);
}
if (releaseCallback != null) {
this.downloadExecutorService.execute(new ReleaseTask(releaseCallback));
}
this.downloadExecutorService.shutdown();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.LoaderErrorThrower
public final void maybeThrowError() throws IOException {
maybeThrowError(Integer.MIN_VALUE);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.LoaderErrorThrower
public final void maybeThrowError(int i) throws IOException {
IOException iOException = this.fatalError;
if (iOException != null) {
throw iOException;
}
LoadTask<? extends Loadable> loadTask = this.currentTask;
if (loadTask != null) {
if (i == Integer.MIN_VALUE) {
i = loadTask.defaultMinRetryCount;
}
loadTask.maybeThrowError(i);
}
}
@SuppressLint({"HandlerLeak"})
public final class LoadTask<T extends Loadable> extends Handler implements Runnable {
private static final int MSG_CANCEL = 1;
private static final int MSG_END_OF_SOURCE = 2;
private static final int MSG_FATAL_ERROR = 4;
private static final int MSG_IO_EXCEPTION = 3;
private static final int MSG_START = 0;
private static final String TAG = "LoadTask";
@Nullable
private Callback<T> callback;
private volatile boolean canceled;
private IOException currentError;
public final int defaultMinRetryCount;
private int errorCount;
private volatile Thread executorThread;
private final T loadable;
private volatile boolean released;
private final long startTimeMs;
public LoadTask(Looper looper, T t, Callback<T> callback, int i, long j) {
super(looper);
this.loadable = t;
this.callback = callback;
this.defaultMinRetryCount = i;
this.startTimeMs = j;
}
public final void maybeThrowError(int i) throws IOException {
IOException iOException = this.currentError;
if (iOException != null && this.errorCount > i) {
throw iOException;
}
}
public final void start(long j) {
Assertions.checkState(Loader.this.currentTask == null);
Loader.this.currentTask = this;
if (j > 0) {
sendEmptyMessageDelayed(0, j);
} else {
execute();
}
}
public final void cancel(boolean z) {
this.released = z;
this.currentError = null;
if (hasMessages(0)) {
removeMessages(0);
if (!z) {
sendEmptyMessage(1);
}
} else {
this.canceled = true;
this.loadable.cancelLoad();
if (this.executorThread != null) {
this.executorThread.interrupt();
}
}
if (z) {
finish();
long elapsedRealtime = SystemClock.elapsedRealtime();
this.callback.onLoadCanceled(this.loadable, elapsedRealtime, elapsedRealtime - this.startTimeMs, true);
this.callback = null;
}
}
@Override // java.lang.Runnable
public final void run() {
try {
this.executorThread = Thread.currentThread();
if (!this.canceled) {
TraceUtil.beginSection("load:" + this.loadable.getClass().getSimpleName());
try {
this.loadable.load();
TraceUtil.endSection();
} catch (Throwable th) {
TraceUtil.endSection();
throw th;
}
}
if (this.released) {
return;
}
sendEmptyMessage(2);
} catch (IOException e) {
if (this.released) {
return;
}
obtainMessage(3, e).sendToTarget();
} catch (OutOfMemoryError e2) {
Log.e(TAG, "OutOfMemory error loading stream", e2);
if (this.released) {
return;
}
obtainMessage(3, new UnexpectedLoaderException(e2)).sendToTarget();
} catch (Error e3) {
Log.e(TAG, "Unexpected error loading stream", e3);
if (!this.released) {
obtainMessage(4, e3).sendToTarget();
}
throw e3;
} catch (InterruptedException unused) {
Assertions.checkState(this.canceled);
if (this.released) {
return;
}
sendEmptyMessage(2);
} catch (Exception e4) {
Log.e(TAG, "Unexpected exception loading stream", e4);
if (this.released) {
return;
}
obtainMessage(3, new UnexpectedLoaderException(e4)).sendToTarget();
}
}
@Override // android.os.Handler
public final void handleMessage(Message message) {
if (this.released) {
return;
}
int i = message.what;
if (i == 0) {
execute();
return;
}
if (i == 4) {
throw ((Error) message.obj);
}
finish();
long elapsedRealtime = SystemClock.elapsedRealtime();
long j = elapsedRealtime - this.startTimeMs;
if (this.canceled) {
this.callback.onLoadCanceled(this.loadable, elapsedRealtime, j, false);
return;
}
int i2 = message.what;
if (i2 == 1) {
this.callback.onLoadCanceled(this.loadable, elapsedRealtime, j, false);
return;
}
if (i2 == 2) {
try {
this.callback.onLoadCompleted(this.loadable, elapsedRealtime, j);
return;
} catch (RuntimeException e) {
Log.e(TAG, "Unexpected exception handling load completed", e);
Loader.this.fatalError = new UnexpectedLoaderException(e);
return;
}
}
if (i2 != 3) {
return;
}
IOException iOException = (IOException) message.obj;
this.currentError = iOException;
int onLoadError = this.callback.onLoadError(this.loadable, elapsedRealtime, j, iOException);
if (onLoadError == 3) {
Loader.this.fatalError = this.currentError;
} else if (onLoadError != 2) {
this.errorCount = onLoadError != 1 ? 1 + this.errorCount : 1;
start(getRetryDelayMillis());
}
}
private void execute() {
this.currentError = null;
Loader.this.downloadExecutorService.execute(Loader.this.currentTask);
}
private void finish() {
Loader.this.currentTask = null;
}
private long getRetryDelayMillis() {
return Math.min((this.errorCount - 1) * 1000, 5000);
}
}
public static final class ReleaseTask implements Runnable {
private final ReleaseCallback callback;
public ReleaseTask(ReleaseCallback releaseCallback) {
this.callback = releaseCallback;
}
@Override // java.lang.Runnable
public final void run() {
this.callback.onLoaderReleased();
}
}
}

View File

@@ -0,0 +1,21 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import java.io.IOException;
/* loaded from: classes4.dex */
public interface LoaderErrorThrower {
public static final class Dummy implements LoaderErrorThrower {
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.LoaderErrorThrower
public final void maybeThrowError() throws IOException {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.LoaderErrorThrower
public final void maybeThrowError(int i) throws IOException {
}
}
void maybeThrowError() throws IOException;
void maybeThrowError(int i) throws IOException;
}

View File

@@ -0,0 +1,62 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.Loader;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class ParsingLoadable<T> implements Loader.Loadable {
private volatile long bytesLoaded;
private final DataSource dataSource;
public final DataSpec dataSpec;
private final Parser<? extends T> parser;
private volatile T result;
public final int type;
public interface Parser<T> {
T parse(Uri uri, InputStream inputStream) throws IOException;
}
public final long bytesLoaded() {
return this.bytesLoaded;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Loader.Loadable
public final void cancelLoad() {
}
public final T getResult() {
return this.result;
}
public static <T> T load(DataSource dataSource, Parser<? extends T> parser, Uri uri) throws IOException {
ParsingLoadable parsingLoadable = new ParsingLoadable(dataSource, uri, 0, parser);
parsingLoadable.load();
return (T) parsingLoadable.getResult();
}
public ParsingLoadable(DataSource dataSource, Uri uri, int i, Parser<? extends T> parser) {
this(dataSource, new DataSpec(uri, 3), i, parser);
}
public ParsingLoadable(DataSource dataSource, DataSpec dataSpec, int i, Parser<? extends T> parser) {
this.dataSource = dataSource;
this.dataSpec = dataSpec;
this.type = i;
this.parser = parser;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.Loader.Loadable
public final void load() throws IOException {
DataSourceInputStream dataSourceInputStream = new DataSourceInputStream(this.dataSource, this.dataSpec);
try {
dataSourceInputStream.open();
this.result = this.parser.parse(this.dataSource.getUri(), dataSourceInputStream);
} finally {
this.bytesLoaded = dataSourceInputStream.bytesRead();
Util.closeQuietly(dataSourceInputStream);
}
}
}

View File

@@ -0,0 +1,43 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class PriorityDataSource implements DataSource {
private final int priority;
private final PriorityTaskManager priorityTaskManager;
private final DataSource upstream;
public PriorityDataSource(DataSource dataSource, PriorityTaskManager priorityTaskManager, int i) {
this.upstream = (DataSource) Assertions.checkNotNull(dataSource);
this.priorityTaskManager = (PriorityTaskManager) Assertions.checkNotNull(priorityTaskManager);
this.priority = i;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
this.priorityTaskManager.proceedOrThrow(this.priority);
return this.upstream.open(dataSpec);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws IOException {
this.priorityTaskManager.proceedOrThrow(this.priority);
return this.upstream.read(bArr, i, i2);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
@Nullable
public final Uri getUri() {
return this.upstream.getUri();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
this.upstream.close();
}
}

View File

@@ -0,0 +1,22 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
/* loaded from: classes4.dex */
public final class PriorityDataSourceFactory implements DataSource.Factory {
private final int priority;
private final PriorityTaskManager priorityTaskManager;
private final DataSource.Factory upstreamFactory;
public PriorityDataSourceFactory(DataSource.Factory factory, PriorityTaskManager priorityTaskManager, int i) {
this.upstreamFactory = factory;
this.priorityTaskManager = priorityTaskManager;
this.priority = i;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource.Factory
public final PriorityDataSource createDataSource() {
return new PriorityDataSource(this.upstreamFactory.createDataSource(), this.priorityTaskManager, this.priority);
}
}

View File

@@ -0,0 +1,191 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class RawResourceDataSource implements DataSource {
public static final String RAW_RESOURCE_SCHEME = "rawresource";
private AssetFileDescriptor assetFileDescriptor;
private long bytesRemaining;
private InputStream inputStream;
private final TransferListener<? super RawResourceDataSource> listener;
private boolean opened;
private final Resources resources;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static class RawResourceDataSourceException extends IOException {
public RawResourceDataSourceException(String str) {
super(str);
}
public RawResourceDataSourceException(IOException iOException) {
super(iOException);
}
}
public static Uri buildRawResourceUri(int i) {
return Uri.parse("rawresource:///" + i);
}
public RawResourceDataSource(Context context) {
this(context, null);
}
public RawResourceDataSource(Context context, TransferListener<? super RawResourceDataSource> transferListener) {
this.resources = context.getResources();
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws RawResourceDataSourceException {
try {
Uri uri = dataSpec.uri;
this.uri = uri;
if (!TextUtils.equals(RAW_RESOURCE_SCHEME, uri.getScheme())) {
throw new RawResourceDataSourceException("URI must use scheme rawresource");
}
try {
this.assetFileDescriptor = this.resources.openRawResourceFd(Integer.parseInt(this.uri.getLastPathSegment()));
FileInputStream fileInputStream = new FileInputStream(this.assetFileDescriptor.getFileDescriptor());
this.inputStream = fileInputStream;
fileInputStream.skip(this.assetFileDescriptor.getStartOffset());
if (this.inputStream.skip(dataSpec.position) < dataSpec.position) {
throw new EOFException();
}
long j = dataSpec.length;
long j2 = -1;
if (j != -1) {
this.bytesRemaining = j;
} else {
long length = this.assetFileDescriptor.getLength();
if (length != -1) {
j2 = length - dataSpec.position;
}
this.bytesRemaining = j2;
}
this.opened = true;
TransferListener<? super RawResourceDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesRemaining;
} catch (NumberFormatException unused) {
throw new RawResourceDataSourceException("Resource identifier must be an integer.");
}
} catch (IOException e) {
throw new RawResourceDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws RawResourceDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
if (j != -1) {
try {
i2 = (int) Math.min(j, i2);
} catch (IOException e) {
throw new RawResourceDataSourceException(e);
}
}
int read = this.inputStream.read(bArr, i, i2);
if (read == -1) {
if (this.bytesRemaining == -1) {
return -1;
}
throw new RawResourceDataSourceException(new EOFException());
}
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - read;
}
TransferListener<? super RawResourceDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws RawResourceDataSourceException {
this.uri = null;
try {
try {
InputStream inputStream = this.inputStream;
if (inputStream != null) {
inputStream.close();
}
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor = this.assetFileDescriptor;
if (assetFileDescriptor != null) {
assetFileDescriptor.close();
}
} catch (IOException e) {
throw new RawResourceDataSourceException(e);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super RawResourceDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
} catch (IOException e2) {
throw new RawResourceDataSourceException(e2);
}
} catch (Throwable th) {
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor2 = this.assetFileDescriptor;
if (assetFileDescriptor2 != null) {
assetFileDescriptor2.close();
}
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super RawResourceDataSource> transferListener2 = this.listener;
if (transferListener2 != null) {
transferListener2.onTransferEnd(this);
}
}
throw th;
} catch (IOException e3) {
throw new RawResourceDataSourceException(e3);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
TransferListener<? super RawResourceDataSource> transferListener3 = this.listener;
if (transferListener3 != null) {
transferListener3.onTransferEnd(this);
}
}
}
}
}
}

View File

@@ -0,0 +1,66 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class TeeDataSource implements DataSource {
private long bytesRemaining;
private final DataSink dataSink;
private boolean dataSinkNeedsClosing;
private final DataSource upstream;
public TeeDataSource(DataSource dataSource, DataSink dataSink) {
this.upstream = (DataSource) Assertions.checkNotNull(dataSource);
this.dataSink = (DataSink) Assertions.checkNotNull(dataSink);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
long open = this.upstream.open(dataSpec);
this.bytesRemaining = open;
if (open == 0) {
return 0L;
}
if (dataSpec.length == -1 && open != -1) {
dataSpec = new DataSpec(dataSpec.uri, dataSpec.absoluteStreamPosition, dataSpec.position, open, dataSpec.key, dataSpec.flags);
}
this.dataSinkNeedsClosing = true;
this.dataSink.open(dataSpec);
return this.bytesRemaining;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws IOException {
if (this.bytesRemaining == 0) {
return -1;
}
int read = this.upstream.read(bArr, i, i2);
if (read > 0) {
this.dataSink.write(bArr, i, read);
long j = this.bytesRemaining;
if (j != -1) {
this.bytesRemaining = j - read;
}
}
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.upstream.getUri();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
try {
this.upstream.close();
} finally {
if (this.dataSinkNeedsClosing) {
this.dataSinkNeedsClosing = false;
this.dataSink.close();
}
}
}
}

View File

@@ -0,0 +1,10 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
/* loaded from: classes4.dex */
public interface TransferListener<S> {
void onBytesTransferred(S s, int i);
void onTransferEnd(S s);
void onTransferStart(S s, DataSpec dataSpec);
}

View File

@@ -0,0 +1,142 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.net.Uri;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
/* loaded from: classes4.dex */
public final class UdpDataSource implements DataSource {
public static final int DEAFULT_SOCKET_TIMEOUT_MILLIS = 8000;
public static final int DEFAULT_MAX_PACKET_SIZE = 2000;
private InetAddress address;
private final TransferListener<? super UdpDataSource> listener;
private MulticastSocket multicastSocket;
private boolean opened;
private final DatagramPacket packet;
private final byte[] packetBuffer;
private int packetRemaining;
private DatagramSocket socket;
private InetSocketAddress socketAddress;
private final int socketTimeoutMillis;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static final class UdpDataSourceException extends IOException {
public UdpDataSourceException(IOException iOException) {
super(iOException);
}
}
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener) {
this(transferListener, 2000);
}
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener, int i) {
this(transferListener, i, 8000);
}
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener, int i, int i2) {
this.listener = transferListener;
this.socketTimeoutMillis = i2;
byte[] bArr = new byte[i];
this.packetBuffer = bArr;
this.packet = new DatagramPacket(bArr, 0, i);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws UdpDataSourceException {
Uri uri = dataSpec.uri;
this.uri = uri;
String host = uri.getHost();
int port = this.uri.getPort();
try {
this.address = InetAddress.getByName(host);
this.socketAddress = new InetSocketAddress(this.address, port);
if (this.address.isMulticastAddress()) {
MulticastSocket multicastSocket = new MulticastSocket(this.socketAddress);
this.multicastSocket = multicastSocket;
multicastSocket.joinGroup(this.address);
this.socket = this.multicastSocket;
} else {
this.socket = new DatagramSocket(this.socketAddress);
}
try {
this.socket.setSoTimeout(this.socketTimeoutMillis);
this.opened = true;
TransferListener<? super UdpDataSource> transferListener = this.listener;
if (transferListener == null) {
return -1L;
}
transferListener.onTransferStart(this, dataSpec);
return -1L;
} catch (SocketException e) {
throw new UdpDataSourceException(e);
}
} catch (IOException e2) {
throw new UdpDataSourceException(e2);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws UdpDataSourceException {
if (i2 == 0) {
return 0;
}
if (this.packetRemaining == 0) {
try {
this.socket.receive(this.packet);
int length = this.packet.getLength();
this.packetRemaining = length;
TransferListener<? super UdpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, length);
}
} catch (IOException e) {
throw new UdpDataSourceException(e);
}
}
int length2 = this.packet.getLength();
int i3 = this.packetRemaining;
int min = Math.min(i3, i2);
System.arraycopy(this.packetBuffer, length2 - i3, bArr, i, min);
this.packetRemaining -= min;
return min;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() {
this.uri = null;
MulticastSocket multicastSocket = this.multicastSocket;
if (multicastSocket != null) {
try {
multicastSocket.leaveGroup(this.address);
} catch (IOException unused) {
}
this.multicastSocket = null;
}
DatagramSocket datagramSocket = this.socket;
if (datagramSocket != null) {
datagramSocket.close();
this.socket = null;
}
this.address = null;
this.socketAddress = null;
this.packetRemaining = 0;
if (this.opened) {
this.opened = false;
TransferListener<? super UdpDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
}

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));
}
}

View File

@@ -0,0 +1,51 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.crypto;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class AesCipherDataSink implements DataSink {
private AesFlushingCipher cipher;
private final byte[] scratch;
private final byte[] secretKey;
private final DataSink wrappedDataSink;
public AesCipherDataSink(byte[] bArr, DataSink dataSink) {
this(bArr, dataSink, null);
}
public AesCipherDataSink(byte[] bArr, DataSink dataSink, byte[] bArr2) {
this.wrappedDataSink = dataSink;
this.secretKey = bArr;
this.scratch = bArr2;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void open(DataSpec dataSpec) throws IOException {
this.wrappedDataSink.open(dataSpec);
this.cipher = new AesFlushingCipher(1, this.secretKey, CryptoUtil.getFNV64Hash(dataSpec.key), dataSpec.absoluteStreamPosition);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void write(byte[] bArr, int i, int i2) throws IOException {
if (this.scratch == null) {
this.cipher.updateInPlace(bArr, i, i2);
this.wrappedDataSink.write(bArr, i, i2);
return;
}
int i3 = 0;
while (i3 < i2) {
int min = Math.min(i2 - i3, this.scratch.length);
this.cipher.update(bArr, i + i3, min, this.scratch, 0);
this.wrappedDataSink.write(this.scratch, 0, min);
i3 += min;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink
public final void close() throws IOException {
this.cipher = null;
this.wrappedDataSink.close();
}
}

View File

@@ -0,0 +1,49 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.crypto;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class AesCipherDataSource implements DataSource {
private AesFlushingCipher cipher;
private final byte[] secretKey;
private final DataSource upstream;
public AesCipherDataSource(byte[] bArr, DataSource dataSource) {
this.upstream = dataSource;
this.secretKey = bArr;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws IOException {
long open = this.upstream.open(dataSpec);
this.cipher = new AesFlushingCipher(2, this.secretKey, CryptoUtil.getFNV64Hash(dataSpec.key), dataSpec.absoluteStreamPosition);
return open;
}
@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;
}
int read = this.upstream.read(bArr, i, i2);
if (read == -1) {
return -1;
}
this.cipher.updateInPlace(bArr, i, read);
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws IOException {
this.cipher = null;
this.upstream.close();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.upstream.getUri();
}
}

View File

@@ -0,0 +1,89 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.crypto;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.nio.ByteBuffer;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/* loaded from: classes4.dex */
public final class AesFlushingCipher {
private final int blockSize;
private final Cipher cipher;
private final byte[] flushedBlock;
private int pendingXorBytes;
private final byte[] zerosBlock;
public AesFlushingCipher(int i, byte[] bArr, long j, long j2) {
try {
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
this.cipher = cipher;
int blockSize = cipher.getBlockSize();
this.blockSize = blockSize;
this.zerosBlock = new byte[blockSize];
this.flushedBlock = new byte[blockSize];
long j3 = j2 / blockSize;
int i2 = (int) (j2 % blockSize);
cipher.init(i, new SecretKeySpec(bArr, Util.splitAtFirst(cipher.getAlgorithm(), "/")[0]), new IvParameterSpec(getInitializationVector(j, j3)));
if (i2 != 0) {
updateInPlace(new byte[i2], 0, i2);
}
} catch (InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException(e);
}
}
public final void updateInPlace(byte[] bArr, int i, int i2) {
update(bArr, i, i2, bArr, i);
}
public final void update(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
int i4 = i;
do {
int i5 = this.pendingXorBytes;
if (i5 > 0) {
bArr2[i3] = (byte) (bArr[i4] ^ this.flushedBlock[this.blockSize - i5]);
i3++;
i4++;
this.pendingXorBytes = i5 - 1;
i2--;
} else {
int nonFlushingUpdate = nonFlushingUpdate(bArr, i4, i2, bArr2, i3);
if (i2 == nonFlushingUpdate) {
return;
}
int i6 = i2 - nonFlushingUpdate;
int i7 = 0;
Assertions.checkState(i6 < this.blockSize);
int i8 = i3 + nonFlushingUpdate;
int i9 = this.blockSize - i6;
this.pendingXorBytes = i9;
Assertions.checkState(nonFlushingUpdate(this.zerosBlock, 0, i9, this.flushedBlock, 0) == this.blockSize);
while (i7 < i6) {
bArr2[i8] = this.flushedBlock[i7];
i7++;
i8++;
}
return;
}
} while (i2 != 0);
}
private int nonFlushingUpdate(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
try {
return this.cipher.update(bArr, i, i2, bArr2, i3);
} catch (ShortBufferException e) {
throw new RuntimeException(e);
}
}
private byte[] getInitializationVector(long j, long j2) {
return ByteBuffer.allocate(16).putLong(j).putLong(j2).array();
}
}

View File

@@ -0,0 +1,19 @@
package com.mbridge.msdk.playercommon.exoplayer2.upstream.crypto;
/* loaded from: classes4.dex */
final class CryptoUtil {
private CryptoUtil() {
}
public static long getFNV64Hash(String str) {
long j = 0;
if (str == null) {
return 0L;
}
for (int i = 0; i < str.length(); i++) {
long charAt = j ^ str.charAt(i);
j = charAt + (charAt << 1) + (charAt << 4) + (charAt << 5) + (charAt << 7) + (charAt << 8) + (charAt << 40);
}
return j;
}
}