package com.applovin.impl; import com.applovin.impl.a; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.mbridge.msdk.playercommon.exoplayer2.C; import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes; import java.util.Arrays; import java.util.Collections; /* loaded from: classes.dex */ public final class k0 implements q7 { private static final byte[] v = {73, 68, 51}; private final boolean a; private final ah b; private final bh c; private final String d; private String e; private qo f; private qo g; private int h; private int i; private int j; private boolean k; private boolean l; private int m; private int n; private int o; private boolean p; private long q; private int r; private long s; private qo t; private long u; private void a(qo qoVar, long j, int i, int i2) { this.h = 4; this.i = i; this.t = qoVar; this.u = j; this.r = i2; } public static boolean a(int i) { return (i & 65526) == 65520; } private void h() { this.h = 1; this.i = 0; } private void i() { this.h = 0; this.i = 0; this.j = 256; } private void j() { this.h = 3; this.i = 0; } @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.s = j; } } @Override // com.applovin.impl.q7 public void b() { } public long d() { return this.q; } public k0(boolean z) { this(z, null); } private void g() { this.l = false; i(); } public k0(boolean z, String str) { this.b = new ah(new byte[7]); this.c = new bh(Arrays.copyOf(v, 10)); i(); this.m = -1; this.n = -1; this.q = C.TIME_UNSET; this.s = C.TIME_UNSET; this.a = z; this.d = str; } private void k() { this.h = 2; this.i = v.length; this.r = 0; this.c.f(0); } private void b(bh bhVar) { if (bhVar.a() == 0) { return; } this.b.a[0] = bhVar.c()[bhVar.d()]; this.b.c(2); int a = this.b.a(4); int i = this.n; if (i != -1 && a != i) { g(); return; } if (!this.l) { this.l = true; this.m = this.o; this.n = a; } j(); } private boolean a(bh bhVar, int i) { bhVar.f(i + 1); if (!b(bhVar, this.b.a, 1)) { return false; } this.b.c(4); int a = this.b.a(1); int i2 = this.m; if (i2 != -1 && a != i2) { return false; } if (this.n != -1) { if (!b(bhVar, this.b.a, 1)) { return true; } this.b.c(2); if (this.b.a(4) != this.n) { return false; } bhVar.f(i + 2); } if (!b(bhVar, this.b.a, 4)) { return true; } this.b.c(14); int a2 = this.b.a(13); if (a2 < 7) { return false; } byte[] c = bhVar.c(); int e = bhVar.e(); int i3 = i + a2; if (i3 >= e) { return true; } byte b = c[i3]; if (b == -1) { int i4 = i3 + 1; if (i4 == e) { return true; } return a((byte) -1, c[i4]) && ((c[i4] & 8) >> 3) == a; } if (b != 73) { return false; } int i5 = i3 + 1; if (i5 == e) { return true; } if (c[i5] != 68) { return false; } int i6 = i3 + 2; return i6 == e || c[i6] == 51; } private void f() { this.g.a(this.c, 10); this.c.f(6); a(this.g, 0L, 10, this.c.v() + 10); } private void e() { this.b.c(0); if (!this.p) { int i = 2; int a = this.b.a(2) + 1; if (a != 2) { pc.d("AdtsReader", "Detected audio object type: " + a + ", but assuming AAC LC."); } else { i = a; } this.b.d(5); byte[] a2 = a.a(i, this.n, this.b.a(3)); a.b a3 = a.a(a2); f9 a4 = new f9.b().c(this.e).f(MimeTypes.AUDIO_AAC).a(a3.c).c(a3.b).n(a3.a).a(Collections.singletonList(a2)).e(this.d).a(); this.q = 1024000000 / a4.A; this.f.a(a4); this.p = true; } else { this.b.d(10); } this.b.d(4); int a5 = this.b.a(13); int i2 = a5 - 7; if (this.k) { i2 = a5 - 9; } a(this.f, this.q, 0, i2); } private void c() { b1.a(this.f); xp.a(this.t); xp.a(this.g); } @Override // com.applovin.impl.q7 public void a(bh bhVar) { c(); while (bhVar.a() > 0) { int i = this.h; if (i == 0) { c(bhVar); } else if (i == 1) { b(bhVar); } else if (i != 2) { if (i == 3) { if (a(bhVar, this.b.a, this.k ? 7 : 5)) { e(); } } else { if (i != 4) { throw new IllegalStateException(); } d(bhVar); } } else if (a(bhVar, this.c.c(), 10)) { f(); } } } private void d(bh bhVar) { int min = Math.min(bhVar.a(), this.r - this.i); this.t.a(bhVar, min); int i = this.i + min; this.i = i; int i2 = this.r; if (i == i2) { long j = this.s; if (j != C.TIME_UNSET) { this.t.a(j, 1, i2, 0, null); this.s += this.u; } i(); } } private boolean b(bh bhVar, byte[] bArr, int i) { if (bhVar.a() < i) { return false; } bhVar.a(bArr, 0, i); return true; } private void c(bh bhVar) { byte[] c = bhVar.c(); int d = bhVar.d(); int e = bhVar.e(); while (d < e) { int i = d + 1; byte b = c[d]; int i2 = b & 255; if (this.j == 512 && a((byte) -1, (byte) i2) && (this.l || a(bhVar, d - 1))) { this.o = (b & 8) >> 3; this.k = (b & 1) == 0; if (!this.l) { h(); } else { j(); } bhVar.f(i); return; } int i3 = this.j; int i4 = i2 | i3; if (i4 == 329) { this.j = 768; } else if (i4 == 511) { this.j = 512; } else if (i4 == 836) { this.j = 1024; } else if (i4 == 1075) { k(); bhVar.f(i); return; } else if (i3 != 256) { this.j = 256; } d = i; } bhVar.f(d); } private boolean a(bh bhVar, byte[] bArr, int i) { int min = Math.min(bhVar.a(), i - this.i); bhVar.a(bArr, this.i, min); int i2 = this.i + min; this.i = i2; return i2 == i; } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.e = dVar.b(); qo a = m8Var.a(dVar.c(), 1); this.f = a; this.t = a; if (this.a) { dVar.a(); qo a2 = m8Var.a(dVar.c(), 5); this.g = a2; a2.a(new f9.b().c(dVar.b()).f(MimeTypes.APPLICATION_ID3).a()); return; } this.g = new i7(); } private boolean a(byte b, byte b2) { return a(((b & 255) << 8) | (b2 & 255)); } @Override // com.applovin.impl.q7 public void a() { this.s = C.TIME_UNSET; g(); } }