what-the-bank/sources/o/C1083Vek.java

262 lines
7.8 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package o;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Pair;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import o.C6318cPT;
/* renamed from: o.Vek, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1083Vek implements AutoCloseable {
public C6318cPT b;
public final int c;
final int d;
MediaMuxer e;
final int f;
final int g;
int h;
int i;
private final Handler k;
int[] l;
public boolean n;
/* renamed from: o, reason: collision with root package name */
private final HandlerThread f8420o;
public final LWm j = new LWm();
final AtomicBoolean a = new AtomicBoolean(false);
private final List<Pair<Integer, ByteBuffer>> m = new ArrayList();
/* renamed from: o.Vek$HBt */
/* loaded from: classes.dex */
public static final class HBt {
public final FileDescriptor a;
public boolean b;
public final int c;
public final int d;
public Handler e;
public final String f;
public int g;
public int h;
public int i;
public int j;
/* renamed from: o, reason: collision with root package name */
public final int f8421o;
public HBt(String str, int i, int i2, byte b) {
this(str, i, i2);
}
private HBt(String str, int i, int i2) {
this.b = true;
this.i = 100;
this.j = 1;
this.h = 0;
this.g = 0;
if (i <= 0 || i2 <= 0) {
StringBuilder sb = new StringBuilder("Invalid image size: ");
sb.append(i);
sb.append("x");
sb.append(i2);
throw new IllegalArgumentException(sb.toString());
}
this.f = str;
this.a = null;
this.f8421o = i;
this.d = i2;
this.c = 2;
}
}
public C1083Vek(String str, FileDescriptor fileDescriptor, int i, int i2, int i3, boolean z, int i4, int i5, int i6, int i7, Handler handler) throws IOException {
if (i6 >= i5) {
StringBuilder sb = new StringBuilder("Invalid maxImages (");
sb.append(i5);
sb.append(") or primaryIndex (");
sb.append(i6);
sb.append(")");
throw new IllegalArgumentException(sb.toString());
}
MediaFormat.createVideoFormat("image/vnd.android.heic", i, i2);
this.h = 1;
this.g = i3;
this.c = i7;
this.d = i5;
this.f = i6;
Looper looper = handler != null ? handler.getLooper() : null;
if (looper == null) {
HandlerThread handlerThread = new HandlerThread("HeifEncoderThread", -2);
this.f8420o = handlerThread;
handlerThread.start();
looper = handlerThread.getLooper();
} else {
this.f8420o = null;
}
Handler handler2 = new Handler(looper);
this.k = handler2;
this.e = str != null ? new MediaMuxer(str, 3) : new MediaMuxer(fileDescriptor, 3);
this.b = new C6318cPT(i, i2, z, i4, i7, handler2, new IeS(this));
}
public final void e() {
Pair<Integer, ByteBuffer> remove;
if (!this.a.get()) {
return;
}
while (true) {
synchronized (this.m) {
if (this.m.isEmpty()) {
return;
} else {
remove = this.m.remove(0);
}
}
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
bufferInfo.set(((ByteBuffer) remove.second).position(), ((ByteBuffer) remove.second).remaining(), 0L, 16);
this.e.writeSampleData(this.l[((Integer) remove.first).intValue()], (ByteBuffer) remove.second, bufferInfo);
}
}
public final void b() {
MediaMuxer mediaMuxer = this.e;
if (mediaMuxer != null) {
mediaMuxer.stop();
this.e.release();
this.e = null;
}
C6318cPT c6318cPT = this.b;
if (c6318cPT != null) {
c6318cPT.close();
synchronized (this) {
this.b = null;
}
}
}
/* renamed from: o.Vek$IeS */
/* loaded from: classes.dex */
class IeS extends C6318cPT.Sts {
private boolean a;
final C1083Vek b;
IeS(C1083Vek c1083Vek) {
this.b = c1083Vek;
}
@Override // o.C6318cPT.Sts
public final void zr_(MediaFormat mediaFormat) {
if (this.a) {
return;
}
if (this.b.l != null) {
d(new IllegalStateException("Output format changed after muxer started"));
return;
}
try {
this.b.h = mediaFormat.getInteger("grid-rows") * mediaFormat.getInteger("grid-cols");
} catch (ClassCastException | NullPointerException unused) {
this.b.h = 1;
}
C1083Vek c1083Vek = this.b;
c1083Vek.l = new int[c1083Vek.d];
if (this.b.g > 0) {
int i = this.b.g;
this.b.e.setOrientationHint(this.b.g);
}
int i2 = 0;
while (i2 < this.b.l.length) {
mediaFormat.setInteger("is-default", i2 == this.b.f ? 1 : 0);
this.b.l[i2] = this.b.e.addTrack(mediaFormat);
i2++;
}
this.b.e.start();
this.b.a.set(true);
this.b.e();
}
@Override // o.C6318cPT.Sts
public final void c(ByteBuffer byteBuffer) {
if (this.a) {
return;
}
if (this.b.l == null) {
d(new IllegalStateException("Output buffer received before format info"));
return;
}
if (this.b.i < this.b.d * this.b.h) {
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
bufferInfo.set(byteBuffer.position(), byteBuffer.remaining(), 0L, 0);
this.b.e.writeSampleData(this.b.l[this.b.i / this.b.h], byteBuffer, bufferInfo);
}
this.b.i++;
if (this.b.i == this.b.d * this.b.h) {
d(null);
}
}
@Override // o.C6318cPT.Sts
public final void a() {
d(null);
}
@Override // o.C6318cPT.Sts
public final void zq_(MediaCodec.CodecException codecException) {
d(codecException);
}
private void d(Exception exc) {
if (this.a) {
return;
}
this.a = true;
LWm lWm = this.b.j;
synchronized (lWm) {
if (!lWm.e) {
lWm.e = true;
lWm.a = exc;
lWm.notifyAll();
}
}
}
}
/* renamed from: o.Vek$LWm */
/* loaded from: classes.dex */
public static class LWm {
public Exception a;
public boolean e;
LWm() {
}
}
@Override // java.lang.AutoCloseable
public final void close() {
this.k.postAtFrontOfQueue(new Runnable(this) { // from class: o.Vek.3
final C1083Vek d;
{
this.d = this;
}
@Override // java.lang.Runnable
public final void run() {
try {
this.d.b();
} catch (Exception unused) {
}
}
});
}
}