discord-jadx/app/src/main/java/c/i/a/c/b2/l.java

298 lines
8.6 KiB
Java

package c.i.a.c.b2;
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.view.Surface;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import c.i.a.c.b2.n;
import c.i.a.c.b2.r;
import c.i.a.c.i2.f0;
import c.i.a.c.x1.b;
import com.airbnb.lottie.parser.AnimatableValueParser;
import java.nio.ByteBuffer;
import java.util.Objects;
/* compiled from: AsynchronousMediaCodecAdapter */
@RequiresApi(23)
public final class l implements r {
public final MediaCodec a;
public final o b;
/* renamed from: c reason: collision with root package name */
public final n f764c;
public final boolean d;
public boolean e;
public int f = 0;
public l(MediaCodec mediaCodec, HandlerThread handlerThread, HandlerThread handlerThread2, boolean z2, boolean z3, a aVar) {
this.a = mediaCodec;
this.b = new o(handlerThread);
this.f764c = new n(mediaCodec, handlerThread2, z2);
this.d = z3;
}
public static String j(int i, String str) {
StringBuilder sb = new StringBuilder(str);
if (i == 1) {
sb.append("Audio");
} else if (i == 2) {
sb.append("Video");
} else {
sb.append("Unknown(");
sb.append(i);
sb.append(")");
}
return sb.toString();
}
@Override // c.i.a.c.b2.r
public void a(int i, int i2, b bVar, long j, int i3) {
n nVar = this.f764c;
nVar.f();
n.a e = n.e();
e.a = i;
e.b = i2;
e.f766c = 0;
e.e = j;
e.f = i3;
MediaCodec.CryptoInfo cryptoInfo = e.d;
cryptoInfo.numSubSamples = bVar.f;
cryptoInfo.numBytesOfClearData = n.c(bVar.d, cryptoInfo.numBytesOfClearData);
cryptoInfo.numBytesOfEncryptedData = n.c(bVar.e, cryptoInfo.numBytesOfEncryptedData);
byte[] b = n.b(bVar.b, cryptoInfo.key);
Objects.requireNonNull(b);
cryptoInfo.key = b;
byte[] b2 = n.b(bVar.a, cryptoInfo.iv);
Objects.requireNonNull(b2);
cryptoInfo.iv = b2;
cryptoInfo.mode = bVar.f1008c;
if (f0.a >= 24) {
cryptoInfo.setPattern(new MediaCodec.CryptoInfo.Pattern(bVar.g, bVar.h));
}
nVar.e.obtainMessage(1, e).sendToTarget();
}
@Override // c.i.a.c.b2.r
public void b(int i, long j) {
this.a.releaseOutputBuffer(i, j);
}
@Override // c.i.a.c.b2.r
public int c() {
int i;
o oVar = this.b;
synchronized (oVar.a) {
i = -1;
if (!oVar.b()) {
IllegalStateException illegalStateException = oVar.m;
if (illegalStateException == null) {
MediaCodec.CodecException codecException = oVar.j;
if (codecException == null) {
c.i.a.c.i2.n nVar = oVar.d;
if (!(nVar.f906c == 0)) {
i = nVar.b();
}
} else {
oVar.j = null;
throw codecException;
}
} else {
oVar.m = null;
throw illegalStateException;
}
}
}
return i;
}
@Override // c.i.a.c.b2.r
public void configure(@Nullable MediaFormat mediaFormat, @Nullable Surface surface, @Nullable MediaCrypto mediaCrypto, int i) {
o oVar = this.b;
MediaCodec mediaCodec = this.a;
AnimatableValueParser.D(oVar.f767c == null);
oVar.b.start();
Handler handler = new Handler(oVar.b.getLooper());
mediaCodec.setCallback(oVar, handler);
oVar.f767c = handler;
this.a.configure(mediaFormat, surface, mediaCrypto, i);
this.f = 1;
}
@Override // c.i.a.c.b2.r
public int d(MediaCodec.BufferInfo bufferInfo) {
int i;
o oVar = this.b;
synchronized (oVar.a) {
i = -1;
if (!oVar.b()) {
IllegalStateException illegalStateException = oVar.m;
if (illegalStateException == null) {
MediaCodec.CodecException codecException = oVar.j;
if (codecException == null) {
c.i.a.c.i2.n nVar = oVar.e;
if (!(nVar.f906c == 0)) {
i = nVar.b();
if (i >= 0) {
AnimatableValueParser.H(oVar.h);
MediaCodec.BufferInfo remove = oVar.f.remove();
bufferInfo.set(remove.offset, remove.size, remove.presentationTimeUs, remove.flags);
} else if (i == -2) {
oVar.h = oVar.g.remove();
}
}
} else {
oVar.j = null;
throw codecException;
}
} else {
oVar.m = null;
throw illegalStateException;
}
}
}
return i;
}
@Override // c.i.a.c.b2.r
public void e(r.b bVar, Handler handler) {
k();
this.a.setOnFrameRenderedListener(new c(this, bVar), handler);
}
@Override // c.i.a.c.b2.r
public void f(int i) {
k();
this.a.setVideoScalingMode(i);
}
@Override // c.i.a.c.b2.r
public void flush() {
this.f764c.d();
this.a.flush();
o oVar = this.b;
MediaCodec mediaCodec = this.a;
Objects.requireNonNull(mediaCodec);
j jVar = new j(mediaCodec);
synchronized (oVar.a) {
oVar.k++;
Handler handler = oVar.f767c;
int i = f0.a;
handler.post(new d(oVar, jVar));
}
}
@Override // c.i.a.c.b2.r
@Nullable
public ByteBuffer g(int i) {
return this.a.getInputBuffer(i);
}
@Override // c.i.a.c.b2.r
public MediaFormat getOutputFormat() {
MediaFormat mediaFormat;
o oVar = this.b;
synchronized (oVar.a) {
mediaFormat = oVar.h;
if (mediaFormat == null) {
throw new IllegalStateException();
}
}
return mediaFormat;
}
@Override // c.i.a.c.b2.r
public void h(Surface surface) {
k();
this.a.setOutputSurface(surface);
}
@Override // c.i.a.c.b2.r
@Nullable
public ByteBuffer i(int i) {
return this.a.getOutputBuffer(i);
}
public final void k() {
if (this.d) {
try {
this.f764c.a();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
}
}
@Override // c.i.a.c.b2.r
public void queueInputBuffer(int i, int i2, int i3, long j, int i4) {
n nVar = this.f764c;
nVar.f();
n.a e = n.e();
e.a = i;
e.b = i2;
e.f766c = i3;
e.e = j;
e.f = i4;
Handler handler = nVar.e;
int i5 = f0.a;
handler.obtainMessage(0, e).sendToTarget();
}
@Override // c.i.a.c.b2.r
public void release() {
boolean z2 = true;
try {
if (this.f == 2) {
n nVar = this.f764c;
if (nVar.i) {
nVar.d();
nVar.d.quit();
}
nVar.i = false;
}
int i = this.f;
if (i == 1 || i == 2) {
o oVar = this.b;
synchronized (oVar.a) {
oVar.l = true;
oVar.b.quit();
oVar.a();
}
}
this.f = 3;
} finally {
if (!this.e) {
this.a.release();
this.e = z2;
}
}
}
@Override // c.i.a.c.b2.r
public void releaseOutputBuffer(int i, boolean z2) {
this.a.releaseOutputBuffer(i, z2);
}
@Override // c.i.a.c.b2.r
public void setParameters(Bundle bundle) {
k();
this.a.setParameters(bundle);
}
@Override // c.i.a.c.b2.r
public void start() {
n nVar = this.f764c;
if (!nVar.i) {
nVar.d.start();
nVar.e = new m(nVar, nVar.d.getLooper());
nVar.i = true;
}
this.a.start();
this.f = 2;
}
}