- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
250 lines
8.6 KiB
Java
250 lines
8.6 KiB
Java
package com.mbridge.msdk.playercommon.exoplayer2.decoder;
|
|
|
|
import com.mbridge.msdk.playercommon.exoplayer2.decoder.DecoderInputBuffer;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.decoder.OutputBuffer;
|
|
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
|
|
import java.lang.Exception;
|
|
import java.util.ArrayDeque;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends OutputBuffer, E extends Exception> implements Decoder<I, O, E> {
|
|
private int availableInputBufferCount;
|
|
private final I[] availableInputBuffers;
|
|
private int availableOutputBufferCount;
|
|
private final O[] availableOutputBuffers;
|
|
private final Thread decodeThread;
|
|
private I dequeuedInputBuffer;
|
|
private E exception;
|
|
private boolean flushed;
|
|
private final Object lock = new Object();
|
|
private final ArrayDeque<I> queuedInputBuffers = new ArrayDeque<>();
|
|
private final ArrayDeque<O> queuedOutputBuffers = new ArrayDeque<>();
|
|
private boolean released;
|
|
private int skippedOutputBufferCount;
|
|
|
|
public abstract I createInputBuffer();
|
|
|
|
public abstract O createOutputBuffer();
|
|
|
|
public abstract E createUnexpectedDecodeException(Throwable th);
|
|
|
|
public abstract E decode(I i, O o, boolean z);
|
|
|
|
public SimpleDecoder(I[] iArr, O[] oArr) {
|
|
this.availableInputBuffers = iArr;
|
|
this.availableInputBufferCount = iArr.length;
|
|
for (int i = 0; i < this.availableInputBufferCount; i++) {
|
|
this.availableInputBuffers[i] = createInputBuffer();
|
|
}
|
|
this.availableOutputBuffers = oArr;
|
|
this.availableOutputBufferCount = oArr.length;
|
|
for (int i2 = 0; i2 < this.availableOutputBufferCount; i2++) {
|
|
this.availableOutputBuffers[i2] = createOutputBuffer();
|
|
}
|
|
Thread thread = new Thread() { // from class: com.mbridge.msdk.playercommon.exoplayer2.decoder.SimpleDecoder.1
|
|
@Override // java.lang.Thread, java.lang.Runnable
|
|
public void run() {
|
|
SimpleDecoder.this.run();
|
|
}
|
|
};
|
|
this.decodeThread = thread;
|
|
thread.start();
|
|
}
|
|
|
|
public final void setInitialInputBufferSize(int i) {
|
|
Assertions.checkState(this.availableInputBufferCount == this.availableInputBuffers.length);
|
|
for (I i2 : this.availableInputBuffers) {
|
|
i2.ensureSpaceForWrite(i);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Decoder
|
|
public final I dequeueInputBuffer() throws Exception {
|
|
I i;
|
|
synchronized (this.lock) {
|
|
maybeThrowException();
|
|
Assertions.checkState(this.dequeuedInputBuffer == null);
|
|
int i2 = this.availableInputBufferCount;
|
|
if (i2 == 0) {
|
|
i = null;
|
|
} else {
|
|
I[] iArr = this.availableInputBuffers;
|
|
int i3 = i2 - 1;
|
|
this.availableInputBufferCount = i3;
|
|
i = iArr[i3];
|
|
}
|
|
this.dequeuedInputBuffer = i;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Decoder
|
|
public final void queueInputBuffer(I i) throws Exception {
|
|
synchronized (this.lock) {
|
|
maybeThrowException();
|
|
Assertions.checkArgument(i == this.dequeuedInputBuffer);
|
|
this.queuedInputBuffers.addLast(i);
|
|
maybeNotifyDecodeLoop();
|
|
this.dequeuedInputBuffer = null;
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Decoder
|
|
public final O dequeueOutputBuffer() throws Exception {
|
|
synchronized (this.lock) {
|
|
try {
|
|
maybeThrowException();
|
|
if (this.queuedOutputBuffers.isEmpty()) {
|
|
return null;
|
|
}
|
|
return this.queuedOutputBuffers.removeFirst();
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void releaseOutputBuffer(O o) {
|
|
synchronized (this.lock) {
|
|
releaseOutputBufferInternal(o);
|
|
maybeNotifyDecodeLoop();
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Decoder
|
|
public final void flush() {
|
|
synchronized (this.lock) {
|
|
try {
|
|
this.flushed = true;
|
|
this.skippedOutputBufferCount = 0;
|
|
I i = this.dequeuedInputBuffer;
|
|
if (i != null) {
|
|
releaseInputBufferInternal(i);
|
|
this.dequeuedInputBuffer = null;
|
|
}
|
|
while (!this.queuedInputBuffers.isEmpty()) {
|
|
releaseInputBufferInternal(this.queuedInputBuffers.removeFirst());
|
|
}
|
|
while (!this.queuedOutputBuffers.isEmpty()) {
|
|
releaseOutputBufferInternal(this.queuedOutputBuffers.removeFirst());
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Decoder
|
|
public void release() {
|
|
synchronized (this.lock) {
|
|
this.released = true;
|
|
this.lock.notify();
|
|
}
|
|
try {
|
|
this.decodeThread.join();
|
|
} catch (InterruptedException unused) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
|
|
private void maybeThrowException() throws Exception {
|
|
E e = this.exception;
|
|
if (e != null) {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
private void maybeNotifyDecodeLoop() {
|
|
if (canDecodeBuffer()) {
|
|
this.lock.notify();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void run() {
|
|
do {
|
|
try {
|
|
} catch (InterruptedException e) {
|
|
throw new IllegalStateException(e);
|
|
}
|
|
} while (decode());
|
|
}
|
|
|
|
private boolean decode() throws InterruptedException {
|
|
synchronized (this.lock) {
|
|
while (!this.released && !canDecodeBuffer()) {
|
|
try {
|
|
this.lock.wait();
|
|
} finally {
|
|
}
|
|
}
|
|
if (this.released) {
|
|
return false;
|
|
}
|
|
I removeFirst = this.queuedInputBuffers.removeFirst();
|
|
O[] oArr = this.availableOutputBuffers;
|
|
int i = this.availableOutputBufferCount - 1;
|
|
this.availableOutputBufferCount = i;
|
|
O o = oArr[i];
|
|
boolean z = this.flushed;
|
|
this.flushed = false;
|
|
if (removeFirst.isEndOfStream()) {
|
|
o.addFlag(4);
|
|
} else {
|
|
if (removeFirst.isDecodeOnly()) {
|
|
o.addFlag(Integer.MIN_VALUE);
|
|
}
|
|
try {
|
|
this.exception = decode(removeFirst, o, z);
|
|
} catch (OutOfMemoryError e) {
|
|
this.exception = createUnexpectedDecodeException(e);
|
|
} catch (RuntimeException e2) {
|
|
this.exception = createUnexpectedDecodeException(e2);
|
|
}
|
|
if (this.exception != null) {
|
|
synchronized (this.lock) {
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
synchronized (this.lock) {
|
|
try {
|
|
if (this.flushed) {
|
|
releaseOutputBufferInternal(o);
|
|
} else if (o.isDecodeOnly()) {
|
|
this.skippedOutputBufferCount++;
|
|
releaseOutputBufferInternal(o);
|
|
} else {
|
|
o.skippedOutputBufferCount = this.skippedOutputBufferCount;
|
|
this.skippedOutputBufferCount = 0;
|
|
this.queuedOutputBuffers.addLast(o);
|
|
}
|
|
releaseInputBufferInternal(removeFirst);
|
|
} finally {
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private boolean canDecodeBuffer() {
|
|
return !this.queuedInputBuffers.isEmpty() && this.availableOutputBufferCount > 0;
|
|
}
|
|
|
|
private void releaseInputBufferInternal(I i) {
|
|
i.clear();
|
|
I[] iArr = this.availableInputBuffers;
|
|
int i2 = this.availableInputBufferCount;
|
|
this.availableInputBufferCount = i2 + 1;
|
|
iArr[i2] = i;
|
|
}
|
|
|
|
private void releaseOutputBufferInternal(O o) {
|
|
o.clear();
|
|
O[] oArr = this.availableOutputBuffers;
|
|
int i = this.availableOutputBufferCount;
|
|
this.availableOutputBufferCount = i + 1;
|
|
oArr[i] = o;
|
|
}
|
|
}
|