package com.applovin.impl; import com.applovin.impl.f9; import com.applovin.impl.ij; import com.mbridge.msdk.playercommon.exoplayer2.C; import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes; import java.io.EOFException; import java.util.Arrays; /* loaded from: classes.dex */ public final class q0 implements k8 { private static final int[] r; private static final int u; private final byte[] a; private final int b; private boolean c; private long d; private int e; private int f; private boolean g; private long h; private int i; private int j; private long k; private m8 l; private qo m; private ij n; private boolean o; public static final o8 p = new o8() { // from class: com.applovin.impl.q0$$ExternalSyntheticLambda0 @Override // com.applovin.impl.o8 public final k8[] a() { k8[] c; c = q0.c(); return c; } }; private static final int[] q = {13, 14, 16, 18, 20, 21, 27, 32, 6, 7, 6, 6, 1, 1, 1, 1}; private static final byte[] s = xp.c("#!AMR\n"); private static final byte[] t = xp.c("#!AMR-WB\n"); static { int[] iArr = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 1, 1, 1, 1, 1, 1}; r = iArr; u = iArr[8]; } private boolean b(int i) { return !this.c && (i < 12 || i > 14); } private boolean d(int i) { return this.c && (i < 10 || i > 13); } @Override // com.applovin.impl.k8 public void a() { } public q0() { this(0); } public q0(int i) { this.b = (i & 2) != 0 ? i | 1 : i; this.a = new byte[1]; this.i = -1; } private boolean c(int i) { return i >= 0 && i <= 15 && (d(i) || b(i)); } private void b() { b1.b(this.m); xp.a(this.l); } private static int a(int i, long j) { return (int) (((i * 8) * 1000000) / j); } private boolean c(l8 l8Var) { byte[] bArr = s; if (a(l8Var, bArr)) { this.c = false; l8Var.a(bArr.length); return true; } byte[] bArr2 = t; if (!a(l8Var, bArr2)) { return false; } this.c = true; l8Var.a(bArr2.length); return true; } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ k8[] c() { return new k8[]{new q0()}; } private void d() { if (this.o) { return; } this.o = true; boolean z = this.c; this.m.a(new f9.b().f(z ? MimeTypes.AUDIO_AMR_WB : MimeTypes.AUDIO_AMR_NB).i(u).c(1).n(z ? 16000 : 8000).a()); } private ij a(long j, boolean z) { return new p4(j, this.h, a(this.i, 20000L), this.i, z); } private int d(l8 l8Var) { if (this.f == 0) { try { int b = b(l8Var); this.e = b; this.f = b; if (this.i == -1) { this.h = l8Var.f(); this.i = this.e; } if (this.i == this.e) { this.j++; } } catch (EOFException unused) { return -1; } } int a = this.m.a((g5) l8Var, this.f, true); if (a == -1) { return -1; } int i = this.f - a; this.f = i; if (i > 0) { return 0; } this.m.a(this.k + this.d, 1, this.e, 0, null); this.d += 20000; return 0; } private int b(l8 l8Var) { l8Var.b(); l8Var.c(this.a, 0, 1); byte b = this.a[0]; if ((b & 131) <= 0) { return a((b >> 3) & 15); } throw dh.a("Invalid padding bits for frame header " + ((int) b), null); } private int a(int i) { if (c(i)) { return this.c ? r[i] : q[i]; } StringBuilder sb = new StringBuilder(); sb.append("Illegal AMR "); sb.append(this.c ? "WB" : "NB"); sb.append(" frame type "); sb.append(i); throw dh.a(sb.toString(), null); } @Override // com.applovin.impl.k8 public void a(m8 m8Var) { this.l = m8Var; this.m = m8Var.a(0, 1); m8Var.c(); } private void a(long j, int i) { int i2; if (this.g) { return; } int i3 = this.b; if ((i3 & 1) == 0 || j == -1 || !((i2 = this.i) == -1 || i2 == this.e)) { ij.b bVar = new ij.b(C.TIME_UNSET); this.n = bVar; this.l.a(bVar); this.g = true; return; } if (this.j >= 20 || i == -1) { ij a = a(j, (i3 & 2) != 0); this.n = a; this.l.a(a); this.g = true; } } private static boolean a(l8 l8Var, byte[] bArr) { l8Var.b(); byte[] bArr2 = new byte[bArr.length]; l8Var.c(bArr2, 0, bArr.length); return Arrays.equals(bArr2, bArr); } @Override // com.applovin.impl.k8 public int a(l8 l8Var, th thVar) { b(); if (l8Var.f() == 0 && !c(l8Var)) { throw dh.a("Could not find AMR header.", null); } d(); int d = d(l8Var); a(l8Var.a(), d); return d; } @Override // com.applovin.impl.k8 public void a(long j, long j2) { this.d = 0L; this.e = 0; this.f = 0; if (j != 0) { ij ijVar = this.n; if (ijVar instanceof p4) { this.k = ((p4) ijVar).d(j); return; } } this.k = 0L; } @Override // com.applovin.impl.k8 public boolean a(l8 l8Var) { return c(l8Var); } }