Files
rr3-apk/decompiled-community/sources/com/applovin/impl/s5.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- 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
2026-02-18 15:48:36 -08:00

1528 lines
42 KiB
Java

package com.applovin.impl;
import android.media.AudioAttributes;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.media.AudioTrack$StreamEventCallback;
import android.media.PlaybackParams;
import android.os.ConditionVariable;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Pair;
import androidx.emoji2.text.ConcurrencyHelpers$$ExternalSyntheticLambda1;
import com.applovin.impl.p1;
import com.applovin.impl.r1;
import com.applovin.impl.u1;
import com.google.android.gms.auth.blockstore.BlockstoreStatusCodes;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ogg.DefaultOggSeeker;
import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
/* loaded from: classes.dex */
public final class s5 implements r1 {
public static boolean a0;
private long A;
private long B;
private long C;
private int D;
private boolean E;
private boolean F;
private long G;
private float H;
private p1[] I;
private ByteBuffer[] J;
private ByteBuffer K;
private int L;
private ByteBuffer M;
private byte[] N;
private int O;
private int P;
private boolean Q;
private boolean R;
private boolean S;
private boolean T;
private int U;
private v1 V;
private boolean W;
private long X;
private boolean Y;
private boolean Z;
private final n1 a;
private final b b;
private final boolean c;
private final d3 d;
private final zo e;
private final p1[] f;
private final p1[] g;
private final ConditionVariable h;
private final u1 i;
private final ArrayDeque j;
private final boolean k;
private final int l;
private i m;
private final g n;
private final g o;
private r1.c p;
private c q;
private c r;
private AudioTrack s;
private l1 t;
private f u;
private f v;
private ph w;
private ByteBuffer x;
private int y;
private long z;
public interface b {
long a(long j);
ph a(ph phVar);
boolean a(boolean z);
p1[] a();
long b();
}
private boolean t() {
return this.s != null;
}
@Override // com.applovin.impl.r1
public void a(r1.c cVar) {
this.p = cVar;
}
@Override // com.applovin.impl.r1
public void h() {
if (xp.a < 25) {
b();
return;
}
this.o.a();
this.n.a();
if (t()) {
w();
if (this.i.d()) {
this.s.pause();
}
this.s.flush();
this.i.g();
u1 u1Var = this.i;
AudioTrack audioTrack = this.s;
c cVar = this.r;
u1Var.a(audioTrack, cVar.c == 2, cVar.g, cVar.d, cVar.h);
this.F = true;
}
}
@Override // com.applovin.impl.r1
public void i() {
this.E = true;
}
public final class h implements u1.a {
@Override // com.applovin.impl.u1.a
public void b(long j, long j2, long j3, long j4) {
String str = "Spurious audio timestamp (system clock mismatch): " + j + ", " + j2 + ", " + j3 + ", " + j4 + ", " + s5.this.q() + ", " + s5.this.r();
if (s5.a0) {
throw new e(str, null);
}
pc.d("DefaultAudioSink", str);
}
@Override // com.applovin.impl.u1.a
public void b(long j) {
pc.d("DefaultAudioSink", "Ignoring impossibly large audio latency: " + j);
}
private h() {
}
@Override // com.applovin.impl.u1.a
public void a(long j) {
if (s5.this.p != null) {
s5.this.p.a(j);
}
}
public /* synthetic */ h(s5 s5Var, a aVar) {
this();
}
@Override // com.applovin.impl.u1.a
public void a(int i, long j) {
if (s5.this.p != null) {
s5.this.p.a(i, j, SystemClock.elapsedRealtime() - s5.this.X);
}
}
@Override // com.applovin.impl.u1.a
public void a(long j, long j2, long j3, long j4) {
String str = "Spurious audio timestamp (frame position mismatch): " + j + ", " + j2 + ", " + j3 + ", " + j4 + ", " + s5.this.q() + ", " + s5.this.r();
if (!s5.a0) {
pc.d("DefaultAudioSink", str);
return;
}
throw new e(str, null);
}
}
private static boolean e(int i2) {
return (xp.a >= 24 && i2 == -6) || i2 == -32;
}
@Override // com.applovin.impl.r1
public void e() {
b1.b(xp.a >= 21);
b1.b(this.T);
if (this.W) {
return;
}
this.W = true;
b();
}
public static final class e extends RuntimeException {
private e(String str) {
super(str);
}
public /* synthetic */ e(String str, a aVar) {
this(str);
}
}
public static class d implements b {
private final p1[] a;
private final ak b;
private final ok c;
@Override // com.applovin.impl.s5.b
public p1[] a() {
return this.a;
}
public d(p1... p1VarArr) {
this(p1VarArr, new ak(), new ok());
}
@Override // com.applovin.impl.s5.b
public ph a(ph phVar) {
this.c.b(phVar.a);
this.c.a(phVar.b);
return phVar;
}
@Override // com.applovin.impl.s5.b
public long b() {
return this.b.j();
}
public d(p1[] p1VarArr, ak akVar, ok okVar) {
p1[] p1VarArr2 = new p1[p1VarArr.length + 2];
this.a = p1VarArr2;
System.arraycopy(p1VarArr, 0, p1VarArr2, 0, p1VarArr.length);
this.b = akVar;
this.c = okVar;
p1VarArr2[p1VarArr.length] = akVar;
p1VarArr2[p1VarArr.length + 1] = okVar;
}
@Override // com.applovin.impl.s5.b
public boolean a(boolean z) {
this.b.a(z);
return z;
}
@Override // com.applovin.impl.s5.b
public long a(long j) {
return this.c.a(j);
}
}
public s5(n1 n1Var, b bVar, boolean z, boolean z2, int i2) {
this.a = n1Var;
this.b = (b) b1.a(bVar);
int i3 = xp.a;
this.c = i3 >= 21 && z;
this.k = i3 >= 23 && z2;
this.l = i3 >= 29 ? i2 : 0;
this.h = new ConditionVariable(true);
this.i = new u1(new h(this, null));
d3 d3Var = new d3();
this.d = d3Var;
zo zoVar = new zo();
this.e = zoVar;
ArrayList arrayList = new ArrayList();
Collections.addAll(arrayList, new wi(), d3Var, zoVar);
Collections.addAll(arrayList, bVar.a());
this.f = (p1[]) arrayList.toArray(new p1[0]);
this.g = new p1[]{new c9()};
this.H = 1.0f;
this.t = l1.g;
this.U = 0;
this.V = new v1(0, 0.0f);
ph phVar = ph.d;
this.v = new f(phVar, false, 0L, 0L, null);
this.w = phVar;
this.P = -1;
this.I = new p1[0];
this.J = new ByteBuffer[0];
this.j = new ArrayDeque();
this.n = new g(100L);
this.o = new g(100L);
}
private void y() {
p1[] p1VarArr = this.r.i;
ArrayList arrayList = new ArrayList();
for (p1 p1Var : p1VarArr) {
if (p1Var.f()) {
arrayList.add(p1Var);
} else {
p1Var.b();
}
}
int size = arrayList.size();
this.I = (p1[]) arrayList.toArray(new p1[size]);
this.J = new ByteBuffer[size];
m();
}
private void m() {
int i2 = 0;
while (true) {
p1[] p1VarArr = this.I;
if (i2 >= p1VarArr.length) {
return;
}
p1 p1Var = p1VarArr[i2];
p1Var.b();
this.J[i2] = p1Var.d();
i2++;
}
}
private void s() {
this.h.block();
AudioTrack k = k();
this.s = k;
if (a(k)) {
b(this.s);
if (this.l != 3) {
AudioTrack audioTrack = this.s;
f9 f9Var = this.r.a;
audioTrack.setOffloadDelayPadding(f9Var.C, f9Var.D);
}
}
this.U = this.s.getAudioSessionId();
u1 u1Var = this.i;
AudioTrack audioTrack2 = this.s;
c cVar = this.r;
u1Var.a(audioTrack2, cVar.c == 2, cVar.g, cVar.d, cVar.h);
x();
int i2 = this.V.a;
if (i2 != 0) {
this.s.attachAuxEffect(i2);
this.s.setAuxEffectSendLevel(this.V.b);
}
this.F = true;
}
@Override // com.applovin.impl.r1
public void j() {
this.S = true;
if (t()) {
this.i.i();
this.s.play();
}
}
private AudioTrack k() {
try {
return ((c) b1.a(this.r)).a(this.W, this.t, this.U);
} catch (r1.b e2) {
u();
r1.c cVar = this.p;
if (cVar != null) {
cVar.a(e2);
}
throw e2;
}
}
private void u() {
if (this.r.b()) {
this.Y = true;
}
}
/* JADX WARN: Removed duplicated region for block: B:15:0x002f */
/* JADX WARN: Removed duplicated region for block: B:7:0x0018 */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:14:0x0029 -> B:4:0x0009). Please report as a decompilation issue!!! */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private boolean l() {
/*
r9 = this;
int r0 = r9.P
r1 = 1
r2 = 0
r3 = -1
if (r0 != r3) goto Lb
r9.P = r2
L9:
r0 = r1
goto Lc
Lb:
r0 = r2
Lc:
int r4 = r9.P
com.applovin.impl.p1[] r5 = r9.I
int r6 = r5.length
r7 = -9223372036854775807(0x8000000000000001, double:-4.9E-324)
if (r4 >= r6) goto L2f
r4 = r5[r4]
if (r0 == 0) goto L1f
r4.e()
L1f:
r9.d(r7)
boolean r0 = r4.c()
if (r0 != 0) goto L29
return r2
L29:
int r0 = r9.P
int r0 = r0 + r1
r9.P = r0
goto L9
L2f:
java.nio.ByteBuffer r0 = r9.M
if (r0 == 0) goto L3b
r9.a(r0, r7)
java.nio.ByteBuffer r0 = r9.M
if (r0 == 0) goto L3b
return r2
L3b:
r9.P = r3
return r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.applovin.impl.s5.l():boolean");
}
@Override // com.applovin.impl.r1
public void f() {
if (!this.Q && t() && l()) {
v();
this.Q = true;
}
}
public boolean p() {
return o().b;
}
@Override // com.applovin.impl.r1
public boolean g() {
return t() && this.i.e(r());
}
private void x() {
if (t()) {
if (xp.a >= 21) {
a(this.s, this.H);
} else {
b(this.s, this.H);
}
}
}
@Override // com.applovin.impl.r1
public void pause() {
this.S = false;
if (t() && this.i.f()) {
this.s.pause();
}
}
public class a extends Thread {
final /* synthetic */ AudioTrack a;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public a(String str, AudioTrack audioTrack) {
super(str);
this.a = audioTrack;
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
try {
this.a.flush();
this.a.release();
} finally {
s5.this.h.open();
}
}
}
@Override // com.applovin.impl.r1
public void d() {
if (this.W) {
this.W = false;
b();
}
}
@Override // com.applovin.impl.r1
public void reset() {
b();
for (p1 p1Var : this.f) {
p1Var.reset();
}
for (p1 p1Var2 : this.g) {
p1Var2.reset();
}
this.S = false;
this.Y = false;
}
private void w() {
this.z = 0L;
this.A = 0L;
this.B = 0L;
this.C = 0L;
this.Z = false;
this.D = 0;
this.v = new f(n(), p(), 0L, 0L, null);
this.G = 0L;
this.u = null;
this.j.clear();
this.K = null;
this.L = 0;
this.M = null;
this.R = false;
this.Q = false;
this.P = -1;
this.x = null;
this.y = 0;
this.e.k();
m();
}
private ph n() {
return o().a;
}
private f o() {
f fVar = this.u;
return fVar != null ? fVar : !this.j.isEmpty() ? (f) this.j.getLast() : this.v;
}
private boolean z() {
return (this.W || !MimeTypes.AUDIO_RAW.equals(this.r.a.m) || f(this.r.a.B)) ? false : true;
}
/* JADX INFO: Access modifiers changed from: private */
public long q() {
return this.r.c == 0 ? this.z / r0.b : this.A;
}
/* JADX INFO: Access modifiers changed from: private */
public long r() {
return this.r.c == 0 ? this.B / r0.d : this.C;
}
private void a(long j) {
ph phVar;
if (z()) {
phVar = this.b.a(n());
} else {
phVar = ph.d;
}
ph phVar2 = phVar;
boolean a2 = z() ? this.b.a(p()) : false;
this.j.add(new f(phVar2, a2, Math.max(0L, j), this.r.b(r()), null));
y();
r1.c cVar = this.p;
if (cVar != null) {
cVar.a(a2);
}
}
private long c(long j) {
return j + this.r.b(this.b.b());
}
private long b(long j) {
while (!this.j.isEmpty() && j >= ((f) this.j.getFirst()).d) {
this.v = (f) this.j.remove();
}
f fVar = this.v;
long j2 = j - fVar.d;
if (fVar.a.equals(ph.d)) {
return this.v.c + j2;
}
if (this.j.isEmpty()) {
return this.v.c + this.b.a(j2);
}
f fVar2 = (f) this.j.getFirst();
return fVar2.c - xp.a(fVar2.d - j, this.v.a.a);
}
private void v() {
if (this.R) {
return;
}
this.R = true;
this.i.d(r());
this.s.stop();
this.y = 0;
}
public final class i {
private final Handler a = new Handler();
private final AudioTrack$StreamEventCallback b;
public i() {
this.b = new a(s5.this);
}
public class a extends AudioTrack$StreamEventCallback {
final /* synthetic */ s5 a;
public a(s5 s5Var) {
this.a = s5Var;
}
public void onDataRequest(AudioTrack audioTrack, int i) {
b1.b(audioTrack == s5.this.s);
if (s5.this.p == null || !s5.this.S) {
return;
}
s5.this.p.a();
}
public void onTearDown(AudioTrack audioTrack) {
b1.b(audioTrack == s5.this.s);
if (s5.this.p == null || !s5.this.S) {
return;
}
s5.this.p.a();
}
}
public void a(AudioTrack audioTrack) {
Handler handler = this.a;
Objects.requireNonNull(handler);
audioTrack.registerStreamEventCallback(new ConcurrencyHelpers$$ExternalSyntheticLambda1(handler), this.b);
}
public void b(AudioTrack audioTrack) {
audioTrack.unregisterStreamEventCallback(this.b);
this.a.removeCallbacksAndMessages(null);
}
}
public static final class f {
public final ph a;
public final boolean b;
public final long c;
public final long d;
private f(ph phVar, boolean z, long j, long j2) {
this.a = phVar;
this.b = z;
this.c = j;
this.d = j2;
}
public /* synthetic */ f(ph phVar, boolean z, long j, long j2, a aVar) {
this(phVar, z, j, j2);
}
}
public static final class c {
public final f9 a;
public final int b;
public final int c;
public final int d;
public final int e;
public final int f;
public final int g;
public final int h;
public final p1[] i;
public boolean b() {
return this.c == 1;
}
public c(f9 f9Var, int i, int i2, int i3, int i4, int i5, int i6, int i7, boolean z, p1[] p1VarArr) {
this.a = f9Var;
this.b = i;
this.c = i2;
this.d = i3;
this.e = i4;
this.f = i5;
this.g = i6;
this.i = p1VarArr;
this.h = a(i7, z);
}
public long b(long j) {
return (j * 1000000) / this.e;
}
public AudioTrack a(boolean z, l1 l1Var, int i) {
try {
AudioTrack b = b(z, l1Var, i);
int state = b.getState();
if (state == 1) {
return b;
}
try {
b.release();
} catch (Exception unused) {
}
throw new r1.b(state, this.e, this.f, this.h, this.a, b(), null);
} catch (IllegalArgumentException | UnsupportedOperationException e) {
throw new r1.b(0, this.e, this.f, this.h, this.a, b(), e);
}
}
private AudioTrack d(boolean z, l1 l1Var, int i) {
AudioTrack.Builder offloadedPlayback;
offloadedPlayback = new AudioTrack.Builder().setAudioAttributes(a(l1Var, z)).setAudioFormat(s5.b(this.e, this.f, this.g)).setTransferMode(1).setBufferSizeInBytes(this.h).setSessionId(i).setOffloadedPlayback(this.c == 1);
return offloadedPlayback.build();
}
private int c(long j) {
int d = s5.d(this.g);
if (this.g == 5) {
d *= 2;
}
return (int) ((j * d) / 1000000);
}
private AudioTrack c(boolean z, l1 l1Var, int i) {
return new AudioTrack(a(l1Var, z), s5.b(this.e, this.f, this.g), this.h, 1, i);
}
public boolean a(c cVar) {
return cVar.c == this.c && cVar.g == this.g && cVar.e == this.e && cVar.f == this.f && cVar.d == this.d;
}
public long d(long j) {
return (j * 1000000) / this.a.A;
}
private AudioTrack b(boolean z, l1 l1Var, int i) {
int i2 = xp.a;
if (i2 >= 29) {
return d(z, l1Var, i);
}
if (i2 >= 21) {
return c(z, l1Var, i);
}
return a(l1Var, i);
}
private int a(int i, boolean z) {
if (i != 0) {
return i;
}
int i2 = this.c;
if (i2 == 0) {
return a(z ? 8.0f : 1.0f);
}
if (i2 == 1) {
return c(50000000L);
}
if (i2 == 2) {
return c(250000L);
}
throw new IllegalStateException();
}
private AudioTrack a(l1 l1Var, int i) {
int e = xp.e(l1Var.c);
if (i == 0) {
return new AudioTrack(e, this.e, this.f, this.g, this.h, 1);
}
return new AudioTrack(e, this.e, this.f, this.g, this.h, 1, i);
}
public long a(long j) {
return (j * this.e) / 1000000;
}
private static AudioAttributes a(l1 l1Var, boolean z) {
if (z) {
return a();
}
return l1Var.a();
}
private int a(float f) {
int minBufferSize = AudioTrack.getMinBufferSize(this.e, this.f, this.g);
b1.b(minBufferSize != -2);
int a = xp.a(minBufferSize * 4, ((int) a(250000L)) * this.d, Math.max(minBufferSize, ((int) a(750000L)) * this.d));
return f != 1.0f ? Math.round(a * f) : a;
}
private static AudioAttributes a() {
return new AudioAttributes.Builder().setContentType(3).setFlags(16).setUsage(1).build();
}
}
@Override // com.applovin.impl.r1
public void a(f9 f9Var, int i2, int[] iArr) {
int i3;
p1[] p1VarArr;
int intValue;
int i4;
int i5;
int intValue2;
int i6;
int[] iArr2;
if (MimeTypes.AUDIO_RAW.equals(f9Var.m)) {
b1.a(xp.g(f9Var.B));
int b2 = xp.b(f9Var.B, f9Var.z);
p1[] p1VarArr2 = f(f9Var.B) ? this.g : this.f;
this.e.a(f9Var.C, f9Var.D);
if (xp.a < 21 && f9Var.z == 8 && iArr == null) {
iArr2 = new int[6];
for (int i7 = 0; i7 < 6; i7++) {
iArr2[i7] = i7;
}
} else {
iArr2 = iArr;
}
this.d.a(iArr2);
p1.a aVar = new p1.a(f9Var.A, f9Var.z, f9Var.B);
for (p1 p1Var : p1VarArr2) {
try {
p1.a a2 = p1Var.a(aVar);
if (p1Var.f()) {
aVar = a2;
}
} catch (p1.b e2) {
throw new r1.a(e2, f9Var);
}
}
int i8 = aVar.c;
i4 = aVar.a;
intValue2 = xp.a(aVar.b);
p1VarArr = p1VarArr2;
intValue = i8;
i5 = b2;
i3 = xp.b(i8, aVar.b);
i6 = 0;
} else {
p1[] p1VarArr3 = new p1[0];
int i9 = f9Var.A;
i3 = -1;
if (a(f9Var, this.t)) {
p1VarArr = p1VarArr3;
intValue = Cif.b((String) b1.a((Object) f9Var.m), f9Var.j);
i6 = 1;
intValue2 = xp.a(f9Var.z);
i4 = i9;
i5 = -1;
} else {
Pair a3 = a(f9Var, this.a);
if (a3 != null) {
p1VarArr = p1VarArr3;
intValue = ((Integer) a3.first).intValue();
i4 = i9;
i5 = -1;
intValue2 = ((Integer) a3.second).intValue();
i6 = 2;
} else {
throw new r1.a("Unable to configure passthrough for: " + f9Var, f9Var);
}
}
}
if (intValue == 0) {
throw new r1.a("Invalid output encoding (mode=" + i6 + ") for: " + f9Var, f9Var);
}
if (intValue2 != 0) {
this.Y = false;
c cVar = new c(f9Var, i5, i6, i3, i4, intValue2, intValue, i2, this.k, p1VarArr);
if (t()) {
this.q = cVar;
return;
} else {
this.r = cVar;
return;
}
}
throw new r1.a("Invalid output channel config (mode=" + i6 + ") for: " + f9Var, f9Var);
}
public static final class g {
private final long a;
private Exception b;
private long c;
public void a() {
this.b = null;
}
public g(long j) {
this.a = j;
}
public void a(Exception exc) {
long elapsedRealtime = SystemClock.elapsedRealtime();
if (this.b == null) {
this.b = exc;
this.c = this.a + elapsedRealtime;
}
if (elapsedRealtime >= this.c) {
Exception exc2 = this.b;
if (exc2 != exc) {
exc2.addSuppressed(exc);
}
Exception exc3 = this.b;
a();
throw exc3;
}
}
}
private boolean f(int i2) {
return this.c && xp.f(i2);
}
@Override // com.applovin.impl.r1
public boolean c() {
return !t() || (this.Q && !g());
}
private static int c(int i2) {
int i3 = xp.a;
if (i3 <= 28) {
if (i2 == 7) {
i2 = 8;
} else if (i2 == 3 || i2 == 4 || i2 == 5) {
i2 = 6;
}
}
if (i3 <= 26 && "fugu".equals(xp.b) && i2 == 1) {
i2 = 2;
}
return xp.a(i2);
}
@Override // com.applovin.impl.r1
public long a(boolean z) {
if (!t() || this.F) {
return Long.MIN_VALUE;
}
return c(b(Math.min(this.i.a(z), this.r.b(r()))));
}
@Override // com.applovin.impl.r1
public void b() {
if (t()) {
w();
if (this.i.d()) {
this.s.pause();
}
if (a(this.s)) {
((i) b1.a(this.m)).b(this.s);
}
AudioTrack audioTrack = this.s;
this.s = null;
if (xp.a < 21 && !this.T) {
this.U = 0;
}
c cVar = this.q;
if (cVar != null) {
this.r = cVar;
this.q = null;
}
this.i.g();
this.h.close();
new a("ExoPlayer:AudioTrackReleaseThread", audioTrack).start();
}
this.o.a();
this.n.a();
}
/* JADX INFO: Access modifiers changed from: private */
public static int d(int i2) {
switch (i2) {
case 5:
return 80000;
case 6:
case 18:
return 768000;
case 7:
return 192000;
case 8:
return 2250000;
case 9:
return BlockstoreStatusCodes.MAX_SIZE_EXCEEDED;
case 10:
return DefaultOggSeeker.MATCH_BYTE_RANGE;
case 11:
return 16000;
case 12:
return 7000;
case 13:
default:
throw new IllegalArgumentException();
case 14:
return 3062500;
case 15:
return 8000;
case 16:
return 256000;
case 17:
return 336000;
}
}
@Override // com.applovin.impl.r1
public int b(f9 f9Var) {
if (!MimeTypes.AUDIO_RAW.equals(f9Var.m)) {
return ((this.Y || !a(f9Var, this.t)) && !b(f9Var, this.a)) ? 0 : 2;
}
if (!xp.g(f9Var.B)) {
pc.d("DefaultAudioSink", "Invalid PCM encoding: " + f9Var.B);
return 0;
}
int i2 = f9Var.B;
return (i2 == 2 || (this.c && i2 == 4)) ? 2 : 1;
}
private void d(long j) {
ByteBuffer byteBuffer;
int length = this.I.length;
int i2 = length;
while (i2 >= 0) {
if (i2 > 0) {
byteBuffer = this.J[i2 - 1];
} else {
byteBuffer = this.K;
if (byteBuffer == null) {
byteBuffer = p1.a;
}
}
if (i2 == length) {
a(byteBuffer, j);
} else {
p1 p1Var = this.I[i2];
if (i2 > this.P) {
p1Var.a(byteBuffer);
}
ByteBuffer d2 = p1Var.d();
this.J[i2] = d2;
if (d2.hasRemaining()) {
i2++;
}
}
if (byteBuffer.hasRemaining()) {
return;
} else {
i2--;
}
}
}
private static Pair a(f9 f9Var, n1 n1Var) {
if (n1Var == null) {
return null;
}
int b2 = Cif.b((String) b1.a((Object) f9Var.m), f9Var.j);
int i2 = 6;
if (b2 != 5 && b2 != 6 && b2 != 18 && b2 != 17 && b2 != 7 && b2 != 8 && b2 != 14) {
return null;
}
if (b2 == 18 && !n1Var.a(18)) {
b2 = 6;
} else if (b2 == 8 && !n1Var.a(8)) {
b2 = 7;
}
if (!n1Var.a(b2)) {
return null;
}
if (b2 == 18) {
if (xp.a >= 29 && (i2 = a(18, f9Var.A)) == 0) {
pc.d("DefaultAudioSink", "E-AC3 JOC encoding supported but no channel count supported");
return null;
}
} else {
i2 = f9Var.z;
if (i2 > n1Var.c()) {
return null;
}
}
int c2 = c(i2);
if (c2 == 0) {
return null;
}
return Pair.create(Integer.valueOf(b2), Integer.valueOf(c2));
}
private static boolean b(f9 f9Var, n1 n1Var) {
return a(f9Var, n1Var) != null;
}
private void b(AudioTrack audioTrack) {
if (this.m == null) {
this.m = new i();
}
this.m.a(audioTrack);
}
private static int a(int i2, ByteBuffer byteBuffer) {
switch (i2) {
case 5:
case 6:
case 18:
return k.b(byteBuffer);
case 7:
case 8:
return f7.a(byteBuffer);
case 9:
int d2 = tf.d(xp.a(byteBuffer, byteBuffer.position()));
if (d2 != -1) {
return d2;
}
throw new IllegalArgumentException();
case 10:
return 1024;
case 11:
case 12:
return 2048;
case 13:
default:
throw new IllegalStateException("Unexpected audio encoding: " + i2);
case 14:
int a2 = k.a(byteBuffer);
if (a2 == -1) {
return 0;
}
return k.a(byteBuffer, a2) * 16;
case 15:
return 512;
case 16:
return 1024;
case 17:
return n.a(byteBuffer);
}
}
private void b(ph phVar) {
if (t()) {
try {
this.s.setPlaybackParams(new PlaybackParams().allowDefaults().setSpeed(phVar.a).setPitch(phVar.b).setAudioFallbackMode(2));
} catch (IllegalArgumentException e2) {
pc.c("DefaultAudioSink", "Failed to set playback params", e2);
}
phVar = new ph(this.s.getPlaybackParams().getSpeed(), this.s.getPlaybackParams().getPitch());
this.i.a(phVar.a);
}
this.w = phVar;
}
@Override // com.applovin.impl.r1
public ph a() {
return this.k ? this.w : n();
}
@Override // com.applovin.impl.r1
public boolean a(ByteBuffer byteBuffer, long j, int i2) {
ByteBuffer byteBuffer2 = this.K;
b1.a(byteBuffer2 == null || byteBuffer == byteBuffer2);
if (this.q != null) {
if (!l()) {
return false;
}
if (!this.q.a(this.r)) {
v();
if (g()) {
return false;
}
b();
} else {
this.r = this.q;
this.q = null;
if (a(this.s) && this.l != 3) {
this.s.setOffloadEndOfStream();
AudioTrack audioTrack = this.s;
f9 f9Var = this.r.a;
audioTrack.setOffloadDelayPadding(f9Var.C, f9Var.D);
this.Z = true;
}
}
a(j);
}
if (!t()) {
try {
s();
} catch (r1.b e2) {
if (!e2.b) {
this.n.a(e2);
return false;
}
throw e2;
}
}
this.n.a();
if (this.F) {
this.G = Math.max(0L, j);
this.E = false;
this.F = false;
if (this.k && xp.a >= 23) {
b(this.w);
}
a(j);
if (this.S) {
j();
}
}
if (!this.i.g(r())) {
return false;
}
if (this.K == null) {
b1.a(byteBuffer.order() == ByteOrder.LITTLE_ENDIAN);
if (!byteBuffer.hasRemaining()) {
return true;
}
c cVar = this.r;
if (cVar.c != 0 && this.D == 0) {
int a2 = a(cVar.g, byteBuffer);
this.D = a2;
if (a2 == 0) {
return true;
}
}
if (this.u != null) {
if (!l()) {
return false;
}
a(j);
this.u = null;
}
long d2 = this.G + this.r.d(q() - this.e.j());
if (!this.E && Math.abs(d2 - j) > 200000) {
this.p.a(new r1.d(j, d2));
this.E = true;
}
if (this.E) {
if (!l()) {
return false;
}
long j2 = j - d2;
this.G += j2;
this.E = false;
a(j);
r1.c cVar2 = this.p;
if (cVar2 != null && j2 != 0) {
cVar2.b();
}
}
if (this.r.c == 0) {
this.z += byteBuffer.remaining();
} else {
this.A += this.D * i2;
}
this.K = byteBuffer;
this.L = i2;
}
d(j);
if (!this.K.hasRemaining()) {
this.K = null;
this.L = 0;
return true;
}
if (!this.i.f(r())) {
return false;
}
pc.d("DefaultAudioSink", "Resetting stalled audio track");
b();
return true;
}
@Override // com.applovin.impl.r1
public void b(boolean z) {
a(n(), z);
}
@Override // com.applovin.impl.r1
public void a(l1 l1Var) {
if (this.t.equals(l1Var)) {
return;
}
this.t = l1Var;
if (this.W) {
return;
}
b();
}
private static void b(AudioTrack audioTrack, float f2) {
audioTrack.setStereoVolume(f2, f2);
}
/* JADX INFO: Access modifiers changed from: private */
public static AudioFormat b(int i2, int i3, int i4) {
return new AudioFormat.Builder().setSampleRate(i2).setChannelMask(i3).setEncoding(i4).build();
}
private void a(ph phVar, boolean z) {
f o = o();
if (phVar.equals(o.a) && z == o.b) {
return;
}
f fVar = new f(phVar, z, C.TIME_UNSET, C.TIME_UNSET, null);
if (t()) {
this.u = fVar;
} else {
this.v = fVar;
}
}
@Override // com.applovin.impl.r1
public void a(int i2) {
if (this.U != i2) {
this.U = i2;
this.T = i2 != 0;
b();
}
}
@Override // com.applovin.impl.r1
public void a(v1 v1Var) {
if (this.V.equals(v1Var)) {
return;
}
int i2 = v1Var.a;
float f2 = v1Var.b;
AudioTrack audioTrack = this.s;
if (audioTrack != null) {
if (this.V.a != i2) {
audioTrack.attachAuxEffect(i2);
}
if (i2 != 0) {
this.s.setAuxEffectSendLevel(f2);
}
}
this.V = v1Var;
}
@Override // com.applovin.impl.r1
public void a(ph phVar) {
ph phVar2 = new ph(xp.a(phVar.a, 0.1f, 8.0f), xp.a(phVar.b, 0.1f, 8.0f));
if (this.k && xp.a >= 23) {
b(phVar2);
} else {
a(phVar2, p());
}
}
@Override // com.applovin.impl.r1
public void a(float f2) {
if (this.H != f2) {
this.H = f2;
x();
}
}
private static void a(AudioTrack audioTrack, float f2) {
audioTrack.setVolume(f2);
}
@Override // com.applovin.impl.r1
public boolean a(f9 f9Var) {
return b(f9Var) != 0;
}
private void a(ByteBuffer byteBuffer, long j) {
int a2;
if (byteBuffer.hasRemaining()) {
ByteBuffer byteBuffer2 = this.M;
if (byteBuffer2 != null) {
b1.a(byteBuffer2 == byteBuffer);
} else {
this.M = byteBuffer;
if (xp.a < 21) {
int remaining = byteBuffer.remaining();
byte[] bArr = this.N;
if (bArr == null || bArr.length < remaining) {
this.N = new byte[remaining];
}
int position = byteBuffer.position();
byteBuffer.get(this.N, 0, remaining);
byteBuffer.position(position);
this.O = 0;
}
}
int remaining2 = byteBuffer.remaining();
if (xp.a < 21) {
int b2 = this.i.b(this.B);
if (b2 > 0) {
a2 = this.s.write(this.N, this.O, Math.min(remaining2, b2));
if (a2 > 0) {
this.O += a2;
byteBuffer.position(byteBuffer.position() + a2);
}
} else {
a2 = 0;
}
} else if (this.W) {
b1.b(j != C.TIME_UNSET);
a2 = a(this.s, byteBuffer, remaining2, j);
} else {
a2 = a(this.s, byteBuffer, remaining2);
}
this.X = SystemClock.elapsedRealtime();
if (a2 < 0) {
boolean e2 = e(a2);
if (e2) {
u();
}
r1.e eVar = new r1.e(a2, this.r.a, e2);
r1.c cVar = this.p;
if (cVar != null) {
cVar.a(eVar);
}
if (!eVar.b) {
this.o.a(eVar);
return;
}
throw eVar;
}
this.o.a();
if (a(this.s)) {
long j2 = this.C;
if (j2 > 0) {
this.Z = false;
}
if (this.S && this.p != null && a2 < remaining2 && !this.Z) {
this.p.b(this.i.c(j2));
}
}
int i2 = this.r.c;
if (i2 == 0) {
this.B += a2;
}
if (a2 == remaining2) {
if (i2 != 0) {
b1.b(byteBuffer == this.K);
this.C += this.D * this.L;
}
this.M = null;
}
}
}
private static int a(AudioTrack audioTrack, ByteBuffer byteBuffer, int i2) {
return audioTrack.write(byteBuffer, i2, 1);
}
private static int a(int i2, int i3) {
boolean isDirectPlaybackSupported;
AudioAttributes build = new AudioAttributes.Builder().setUsage(1).setContentType(3).build();
for (int i4 = 8; i4 > 0; i4--) {
isDirectPlaybackSupported = AudioTrack.isDirectPlaybackSupported(new AudioFormat.Builder().setEncoding(i2).setSampleRate(i3).setChannelMask(xp.a(i4)).build(), build);
if (isDirectPlaybackSupported) {
return i4;
}
}
return 0;
}
private boolean a(f9 f9Var, l1 l1Var) {
int b2;
int a2;
int a3;
if (xp.a < 29 || this.l == 0 || (b2 = Cif.b((String) b1.a((Object) f9Var.m), f9Var.j)) == 0 || (a2 = xp.a(f9Var.z)) == 0 || (a3 = a(b(f9Var.A, a2, b2), l1Var.a())) == 0) {
return false;
}
if (a3 == 1) {
return ((f9Var.C != 0 || f9Var.D != 0) && (this.l == 1)) ? false : true;
}
if (a3 == 2) {
return true;
}
throw new IllegalStateException();
}
private int a(AudioFormat audioFormat, AudioAttributes audioAttributes) {
boolean isOffloadedPlaybackSupported;
int playbackOffloadSupport;
int i2 = xp.a;
if (i2 >= 31) {
playbackOffloadSupport = AudioManager.getPlaybackOffloadSupport(audioFormat, audioAttributes);
return playbackOffloadSupport;
}
isOffloadedPlaybackSupported = AudioManager.isOffloadedPlaybackSupported(audioFormat, audioAttributes);
if (isOffloadedPlaybackSupported) {
return (i2 == 30 && xp.d.startsWith("Pixel")) ? 2 : 1;
}
return 0;
}
private static boolean a(AudioTrack audioTrack) {
boolean isOffloadedPlayback;
if (xp.a >= 29) {
isOffloadedPlayback = audioTrack.isOffloadedPlayback();
if (isOffloadedPlayback) {
return true;
}
}
return false;
}
private int a(AudioTrack audioTrack, ByteBuffer byteBuffer, int i2, long j) {
if (xp.a >= 26) {
return audioTrack.write(byteBuffer, i2, 1, j * 1000);
}
if (this.x == null) {
ByteBuffer allocate = ByteBuffer.allocate(16);
this.x = allocate;
allocate.order(ByteOrder.BIG_ENDIAN);
this.x.putInt(1431633921);
}
if (this.y == 0) {
this.x.putInt(4, i2);
this.x.putLong(8, j * 1000);
this.x.position(0);
this.y = i2;
}
int remaining = this.x.remaining();
if (remaining > 0) {
int write = audioTrack.write(this.x, remaining, 1);
if (write < 0) {
this.y = 0;
return write;
}
if (write < remaining) {
return 0;
}
}
int a2 = a(audioTrack, byteBuffer, i2);
if (a2 < 0) {
this.y = 0;
return a2;
}
this.y -= a2;
return a2;
}
}