discord-jadx/app/src/main/java/c/o/a/v/b.java

227 lines
7.3 KiB
Java

package c.o.a.v;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.DngCreator;
import android.hardware.camera2.TotalCaptureResult;
import android.location.Location;
import android.media.Image;
import android.media.ImageReader;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.exifinterface.media.ExifInterface;
import c.o.a.l;
import c.o.a.m.j;
import c.o.a.n.d;
import c.o.a.n.o.c;
import c.o.a.n.o.e;
import c.o.a.r.g;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
/* compiled from: Full2PictureRecorder */
@RequiresApi(21)
public class b extends c implements ImageReader.OnImageAvailableListener {
public final c m;
public final c.o.a.n.o.a n = new a();
public final ImageReader o;
public final CaptureRequest.Builder p;
public DngCreator q;
/* compiled from: Full2PictureRecorder */
public class a extends e {
public a() {
}
@Override // c.o.a.n.o.e, c.o.a.n.o.a
public void b(@NonNull c cVar, @NonNull CaptureRequest captureRequest, @NonNull TotalCaptureResult totalCaptureResult) {
int i;
b bVar = b.this;
if (bVar.i.g == j.DNG) {
bVar.q = new DngCreator(((d) cVar).f1480f0, totalCaptureResult);
b bVar2 = b.this;
DngCreator dngCreator = bVar2.q;
int i2 = bVar2.i.f1473c;
int i3 = (i2 + 360) % 360;
if (i3 == 0) {
i = 1;
} else if (i3 == 90) {
i = 6;
} else if (i3 == 180) {
i = 3;
} else if (i3 == 270) {
i = 8;
} else {
throw new IllegalArgumentException(c.d.b.a.a.l("Invalid orientation: ", i2));
}
dngCreator.setOrientation(i);
b bVar3 = b.this;
Location location = bVar3.i.b;
if (location != null) {
bVar3.q.setLocation(location);
}
}
}
@Override // c.o.a.n.o.e, c.o.a.n.o.a
public void c(@NonNull c cVar, @NonNull CaptureRequest captureRequest) {
if (this.d) {
j(cVar);
this.d = false;
}
if (captureRequest.getTag() == 2) {
c.l.a(1, "onCaptureStarted:", "Dispatching picture shutter.");
b.this.a(false);
l(Integer.MAX_VALUE);
}
}
@Override // c.o.a.n.o.e
public void j(@NonNull c cVar) {
this.f1491c = cVar;
b bVar = b.this;
bVar.p.addTarget(bVar.o.getSurface());
b bVar2 = b.this;
l.a aVar = bVar2.i;
if (aVar.g == j.JPEG) {
bVar2.p.set(CaptureRequest.JPEG_ORIENTATION, Integer.valueOf(aVar.f1473c));
}
b.this.p.setTag(2);
try {
((d) cVar).e1(this, b.this.p);
} catch (CameraAccessException e) {
b bVar3 = b.this;
bVar3.i = null;
bVar3.k = e;
bVar3.b();
l(Integer.MAX_VALUE);
}
}
}
public b(@NonNull l.a aVar, @NonNull d dVar, @NonNull CaptureRequest.Builder builder, @NonNull ImageReader imageReader) {
super(aVar, dVar);
this.m = dVar;
this.p = builder;
this.o = imageReader;
g b = g.b("FallbackCameraThread");
g.f1505c = b;
imageReader.setOnImageAvailableListener(this, b.f);
}
@Override // c.o.a.v.d
public void c() {
this.n.e(this.m);
}
public final void d(@NonNull Image image) {
int i = 0;
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bArr = new byte[buffer.remaining()];
buffer.get(bArr);
l.a aVar = this.i;
aVar.f = bArr;
aVar.f1473c = 0;
try {
int attributeInt = new ExifInterface(new ByteArrayInputStream(this.i.f)).getAttributeInt("Orientation", 1);
l.a aVar2 = this.i;
switch (attributeInt) {
case 3:
case 4:
i = 180;
break;
case 5:
case 6:
i = 90;
break;
case 7:
case 8:
i = 270;
break;
}
aVar2.f1473c = i;
} catch (IOException unused) {
}
}
public final void e(@NonNull Image image) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
try {
this.q.writeImage(bufferedOutputStream, image);
bufferedOutputStream.flush();
this.i.f = byteArrayOutputStream.toByteArray();
} catch (IOException e) {
this.q.close();
try {
bufferedOutputStream.close();
} catch (IOException unused) {
}
throw new RuntimeException(e);
}
}
/* JADX WARNING: Removed duplicated region for block: B:22:0x0061 */
/* JADX WARNING: Removed duplicated region for block: B:26:0x0069 */
/* JADX WARNING: Removed duplicated region for block: B:29:? A[RETURN, SYNTHETIC] */
@Override // android.media.ImageReader.OnImageAvailableListener
public void onImageAvailable(ImageReader imageReader) {
Throwable th;
Image image;
Exception e;
c.o.a.b bVar = c.l;
bVar.a(1, "onImageAvailable started.");
Image image2 = null;
try {
image = imageReader.acquireNextImage();
try {
int ordinal = this.i.g.ordinal();
if (ordinal == 0) {
d(image);
} else if (ordinal == 1) {
e(image);
} else {
throw new IllegalStateException("Unknown format: " + this.i.g);
}
if (image != null) {
image.close();
}
bVar.a(1, "onImageAvailable ended.");
b();
} catch (Exception e2) {
e = e2;
try {
this.i = null;
this.k = e;
b();
if (image == null) {
image.close();
}
} catch (Throwable th2) {
th = th2;
image2 = image;
if (image2 != null) {
image2.close();
}
throw th;
}
}
} catch (Exception e3) {
e = e3;
image = null;
this.i = null;
this.k = e;
b();
if (image == null) {
}
} catch (Throwable th3) {
th = th3;
if (image2 != null) {
}
throw th;
}
}
}