package com.applovin.impl; import android.os.Looper; import com.applovin.impl.a7; import com.applovin.impl.b7; import com.applovin.impl.bj; import com.applovin.impl.qo; import com.applovin.impl.z6; /* loaded from: classes.dex */ public class bj implements qo { private boolean A; private f9 B; private f9 C; private int D; private boolean E; private boolean F; private long G; private boolean H; private final aj a; private final b7 d; private final a7.a e; private final Looper f; private d g; private f9 h; private z6 i; private int q; private int r; private int s; private int t; private boolean x; private final b b = new b(); private int j = 1000; private int[] k = new int[1000]; private long[] l = new long[1000]; private long[] o = new long[1000]; private int[] n = new int[1000]; private int[] m = new int[1000]; private qo.a[] p = new qo.a[1000]; private final qk c = new qk(new r4() { // from class: com.applovin.impl.bj$$ExternalSyntheticLambda0 @Override // com.applovin.impl.r4 public final void accept(Object obj) { bj.a((bj.c) obj); } }); private long u = Long.MIN_VALUE; private long v = Long.MIN_VALUE; private long w = Long.MIN_VALUE; private boolean z = true; private boolean y = true; public static final class b { public int a; public long b; public qo.a c; } public interface d { void a(f9 f9Var); } private int d(int i) { int i2 = this.s + i; int i3 = this.j; return i2 < i3 ? i2 : i2 - i3; } private boolean h() { return this.t != this.q; } public final void a(d dVar) { this.g = dVar; } public final void c(long j) { this.u = j; } public final int e() { return this.r + this.t; } public final int g() { return this.r + this.q; } public bj(n0 n0Var, Looper looper, b7 b7Var, a7.a aVar) { this.f = looper; this.d = b7Var; this.e = aVar; this.a = new aj(n0Var); } public void l() { b(true); m(); } public final void n() { b(false); } public void k() { b(); m(); } public void j() { z6 z6Var = this.i; if (z6Var != null && z6Var.b() == 1) { throw ((z6.a) b1.a(this.i.getError())); } } public final synchronized f9 f() { return this.z ? null : this.C; } public final synchronized long c() { return this.w; } public final synchronized long d() { return Math.max(this.v, c(this.t)); } public final synchronized boolean i() { return this.x; } private synchronized void o() { this.t = 0; this.a.c(); } private void m() { z6 z6Var = this.i; if (z6Var != null) { z6Var.a(this.e); this.i = null; this.h = null; } } public final synchronized void f(int i) { boolean z; if (i >= 0) { try { if (this.t + i <= this.q) { z = true; b1.a(z); this.t += i; } } catch (Throwable th) { throw th; } } z = false; b1.a(z); this.t += i; } private synchronized boolean a(long j) { if (this.q == 0) { return j > this.v; } if (d() >= j) { return false; } b(this.r + b(j)); return true; } private int b(long j) { int i = this.q; int d2 = d(i - 1); while (i > this.t && this.o[d2] >= j) { i--; d2--; if (d2 == -1) { d2 = this.j - 1; } } return i; } public static final class c { public final f9 a; public final b7.b b; private c(f9 f9Var, b7.b bVar) { this.a = f9Var; this.b = bVar; } } private boolean e(int i) { z6 z6Var = this.i; return z6Var == null || z6Var.b() == 4 || ((this.n[i] & 1073741824) == 0 && this.i.c()); } private long c(int i) { long j = Long.MIN_VALUE; if (i == 0) { return Long.MIN_VALUE; } int d2 = d(i - 1); for (int i2 = 0; i2 < i; i2++) { j = Math.max(j, this.o[d2]); if ((this.n[d2] & 1) != 0) { break; } d2--; if (d2 == -1) { d2 = this.j - 1; } } return j; } public final void b(long j, boolean z, boolean z2) { this.a.a(a(j, z, z2)); } private synchronized void a(long j, int i, long j2, int i2, qo.a aVar) { b7.b bVar; try { int i3 = this.q; if (i3 > 0) { int d2 = d(i3 - 1); b1.a(this.l[d2] + ((long) this.m[d2]) <= j2); } this.x = (536870912 & i) != 0; this.w = Math.max(this.w, j); int d3 = d(this.q); this.o[d3] = j; this.l[d3] = j2; this.m[d3] = i2; this.n[d3] = i; this.p[d3] = aVar; this.k[d3] = this.D; if (this.c.c() || !((c) this.c.b()).a.equals(this.C)) { b7 b7Var = this.d; if (b7Var != null) { bVar = b7Var.b((Looper) b1.a(this.f), this.e, this.C); } else { bVar = b7.b.a; } this.c.a(g(), new c((f9) b1.a(this.C), bVar)); } int i4 = this.q + 1; this.q = i4; int i5 = this.j; if (i4 == i5) { int i6 = i5 + 1000; int[] iArr = new int[i6]; long[] jArr = new long[i6]; long[] jArr2 = new long[i6]; int[] iArr2 = new int[i6]; int[] iArr3 = new int[i6]; qo.a[] aVarArr = new qo.a[i6]; int i7 = this.s; int i8 = i5 - i7; System.arraycopy(this.l, i7, jArr, 0, i8); System.arraycopy(this.o, this.s, jArr2, 0, i8); System.arraycopy(this.n, this.s, iArr2, 0, i8); System.arraycopy(this.m, this.s, iArr3, 0, i8); System.arraycopy(this.p, this.s, aVarArr, 0, i8); System.arraycopy(this.k, this.s, iArr, 0, i8); int i9 = this.s; System.arraycopy(this.l, 0, jArr, i8, i9); System.arraycopy(this.o, 0, jArr2, i8, i9); System.arraycopy(this.n, 0, iArr2, i8, i9); System.arraycopy(this.m, 0, iArr3, i8, i9); System.arraycopy(this.p, 0, aVarArr, i8, i9); System.arraycopy(this.k, 0, iArr, i8, i9); this.l = jArr; this.o = jArr2; this.n = iArr2; this.m = iArr3; this.p = aVarArr; this.k = iArr; this.s = 0; this.j = i6; } } catch (Throwable th) { throw th; } } public final void b() { this.a.a(a()); } private synchronized boolean c(f9 f9Var) { try { this.z = false; if (xp.a(f9Var, this.C)) { return false; } if (this.c.c() || !((c) this.c.b()).a.equals(f9Var)) { this.C = f9Var; } else { this.C = ((c) this.c.b()).a; } f9 f9Var2 = this.C; this.E = Cif.a(f9Var2.m, f9Var2.j); this.F = false; return true; } catch (Throwable th) { throw th; } } private synchronized long a(long j, boolean z, boolean z2) { int i; try { int i2 = this.q; if (i2 != 0) { long[] jArr = this.o; int i3 = this.s; if (j >= jArr[i3]) { if (z2 && (i = this.t) != i2) { i2 = i + 1; } int a2 = a(i3, i2, j, z); if (a2 == -1) { return -1L; } return a(a2); } } return -1L; } finally { } } private long b(int i) { int g = g() - i; boolean z = false; b1.a(g >= 0 && g <= this.q - this.t); int i2 = this.q - g; this.q = i2; this.w = Math.max(this.v, c(i2)); if (g == 0 && this.x) { z = true; } this.x = z; this.c.a(i); int i3 = this.q; if (i3 == 0) { return 0L; } return this.l[d(i3 - 1)] + this.m[r9]; } private synchronized long a() { int i = this.q; if (i == 0) { return -1L; } return a(i); } public f9 b(f9 f9Var) { return (this.G == 0 || f9Var.q == Long.MAX_VALUE) ? f9Var : f9Var.a().a(f9Var.q + this.G).a(); } public void b(boolean z) { this.a.b(); this.q = 0; this.r = 0; this.s = 0; this.t = 0; this.y = true; this.u = Long.MIN_VALUE; this.v = Long.MIN_VALUE; this.w = Long.MIN_VALUE; this.x = false; this.c.a(); if (z) { this.B = null; this.C = null; this.z = true; } } private long a(int i) { this.v = Math.max(this.v, c(i)); this.q -= i; int i2 = this.r + i; this.r = i2; int i3 = this.s + i; this.s = i3; int i4 = this.j; if (i3 >= i4) { this.s = i3 - i4; } int i5 = this.t - i; this.t = i5; if (i5 < 0) { this.t = 0; } this.c.b(i2); if (this.q == 0) { int i6 = this.s; if (i6 == 0) { i6 = this.j; } return this.l[i6 - 1] + this.m[r6]; } return this.l[this.s]; } public final synchronized boolean b(long j, boolean z) { o(); int d2 = d(this.t); if (h() && j >= this.o[d2] && (j <= this.w || z)) { int a2 = a(d2, this.q - this.t, j, true); if (a2 == -1) { return false; } this.u = j; this.t += a2; return true; } return false; } private int a(int i, int i2, long j, boolean z) { int i3 = -1; for (int i4 = 0; i4 < i2; i4++) { long j2 = this.o[i]; if (j2 > j) { break; } if (!z || (this.n[i] & 1) != 0) { i3 = i4; if (j2 == j) { break; } } i++; if (i == this.j) { i = 0; } } return i3; } @Override // com.applovin.impl.qo public final void a(f9 f9Var) { f9 b2 = b(f9Var); this.A = false; this.B = f9Var; boolean c2 = c(b2); d dVar = this.g; if (dVar == null || !c2) { return; } dVar.a(b2); } public final synchronized int a(long j, boolean z) { int d2 = d(this.t); if (h() && j >= this.o[d2]) { if (j > this.w && z) { return this.q - this.t; } int a2 = a(d2, this.q - this.t, j, true); if (a2 == -1) { return 0; } return a2; } return 0; } public synchronized boolean a(boolean z) { f9 f9Var; boolean z2 = true; if (h()) { if (((c) this.c.c(e())).a != this.h) { return true; } return e(d(this.t)); } if (!z && !this.x && ((f9Var = this.C) == null || f9Var == this.h)) { z2 = false; } return z2; } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ void a(c cVar) { cVar.b.a(); } private void a(f9 f9Var, g9 g9Var) { f9 f9Var2 = this.h; boolean z = f9Var2 == null; y6 y6Var = z ? null : f9Var2.p; this.h = f9Var; y6 y6Var2 = f9Var.p; b7 b7Var = this.d; g9Var.b = b7Var != null ? f9Var.a(b7Var.a(f9Var)) : f9Var; g9Var.a = this.i; if (this.d == null) { return; } if (z || !xp.a(y6Var, y6Var2)) { z6 z6Var = this.i; z6 a2 = this.d.a((Looper) b1.a(this.f), this.e, f9Var); this.i = a2; g9Var.a = a2; if (z6Var != null) { z6Var.a(this.e); } } } private synchronized int a(g9 g9Var, p5 p5Var, boolean z, boolean z2, b bVar) { try { p5Var.d = false; if (!h()) { if (!z2 && !this.x) { f9 f9Var = this.C; if (f9Var == null || (!z && f9Var == this.h)) { return -3; } a((f9) b1.a(f9Var), g9Var); return -5; } p5Var.e(4); return -4; } f9 f9Var2 = ((c) this.c.c(e())).a; if (!z && f9Var2 == this.h) { int d2 = d(this.t); if (!e(d2)) { p5Var.d = true; return -3; } p5Var.e(this.n[d2]); long j = this.o[d2]; p5Var.f = j; if (j < this.u) { p5Var.b(Integer.MIN_VALUE); } bVar.a = this.m[d2]; bVar.b = this.l[d2]; bVar.c = this.p[d2]; return -4; } a(f9Var2, g9Var); return -5; } catch (Throwable th) { throw th; } } public int a(g9 g9Var, p5 p5Var, int i, boolean z) { int a2 = a(g9Var, p5Var, (i & 2) != 0, z, this.b); if (a2 == -4 && !p5Var.e()) { boolean z2 = (i & 1) != 0; if ((i & 4) == 0) { if (z2) { this.a.a(p5Var, this.b); } else { this.a.b(p5Var, this.b); } } if (!z2) { this.t++; } } return a2; } @Override // com.applovin.impl.qo public final int a(g5 g5Var, int i, boolean z, int i2) { return this.a.a(g5Var, i, z); } @Override // com.applovin.impl.qo public final void a(bh bhVar, int i, int i2) { this.a.a(bhVar, i); } /* JADX WARN: Removed duplicated region for block: B:25:0x0059 */ @Override // com.applovin.impl.qo /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public void a(long r12, int r14, int r15, int r16, com.applovin.impl.qo.a r17) { /* r11 = this; r8 = r11 boolean r0 = r8.A if (r0 == 0) goto L10 com.applovin.impl.f9 r0 = r8.B java.lang.Object r0 = com.applovin.impl.b1.b(r0) com.applovin.impl.f9 r0 = (com.applovin.impl.f9) r0 r11.a(r0) L10: r0 = r14 & 1 r1 = 0 r2 = 1 if (r0 == 0) goto L18 r3 = r2 goto L19 L18: r3 = r1 L19: boolean r4 = r8.y if (r4 == 0) goto L22 if (r3 != 0) goto L20 return L20: r8.y = r1 L22: long r4 = r8.G long r4 = r4 + r12 boolean r6 = r8.E if (r6 == 0) goto L54 long r6 = r8.u int r6 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1)) if (r6 >= 0) goto L30 return L30: if (r0 != 0) goto L54 boolean r0 = r8.F if (r0 != 0) goto L50 java.lang.StringBuilder r0 = new java.lang.StringBuilder r0.() java.lang.String r6 = "Overriding unexpected non-sync sample for format: " r0.append(r6) com.applovin.impl.f9 r6 = r8.C r0.append(r6) java.lang.String r0 = r0.toString() java.lang.String r6 = "SampleQueue" com.applovin.impl.pc.d(r6, r0) r8.F = r2 L50: r0 = r14 | 1 r6 = r0 goto L55 L54: r6 = r14 L55: boolean r0 = r8.H if (r0 == 0) goto L66 if (r3 == 0) goto L65 boolean r0 = r11.a(r4) if (r0 != 0) goto L62 goto L65 L62: r8.H = r1 goto L66 L65: return L66: com.applovin.impl.aj r0 = r8.a long r0 = r0.a() r7 = r15 long r2 = (long) r7 long r0 = r0 - r2 r2 = r16 long r2 = (long) r2 long r9 = r0 - r2 r0 = r11 r1 = r4 r3 = r6 r4 = r9 r6 = r15 r7 = r17 r0.a(r1, r3, r4, r6, r7) return */ throw new UnsupportedOperationException("Method not decompiled: com.applovin.impl.bj.a(long, int, int, int, com.applovin.impl.qo$a):void"); } public static bj a(n0 n0Var, Looper looper, b7 b7Var, a7.a aVar) { return new bj(n0Var, (Looper) b1.a(looper), (b7) b1.a(b7Var), (a7.a) b1.a(aVar)); } }