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.Collections; /* loaded from: classes.dex */ public final class bc implements q7 { private final String a; private final bh b; private final ah c; private qo d; private String e; private f9 f; private int g; private int h; private int i; private int j; private long 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 int t; private String u; @Override // com.applovin.impl.q7 public void a() { this.g = 0; this.k = C.TIME_UNSET; this.l = false; } @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.k = j; } } @Override // com.applovin.impl.q7 public void b() { } public bc(String str) { this.a = str; bh bhVar = new bh(1024); this.b = bhVar; this.c = new ah(bhVar.c()); this.k = C.TIME_UNSET; } @Override // com.applovin.impl.q7 public void a(bh bhVar) { b1.b(this.d); while (bhVar.a() > 0) { int i = this.g; if (i != 0) { if (i == 1) { int w = bhVar.w(); if ((w & 224) == 224) { this.j = w; this.g = 2; } else if (w != 86) { this.g = 0; } } else if (i == 2) { int w2 = ((this.j & (-225)) << 8) | bhVar.w(); this.i = w2; if (w2 > this.b.c().length) { a(this.i); } this.h = 0; this.g = 3; } else { if (i != 3) { throw new IllegalStateException(); } int min = Math.min(bhVar.a(), this.i - this.h); bhVar.a(this.c.a, this.h, min); int i2 = this.h + min; this.h = i2; if (i2 == this.i) { this.c.c(0); b(this.c); this.g = 0; } } } else if (bhVar.w() == 86) { this.g = 1; } } } private void b(ah ahVar) { if (!ahVar.f()) { this.l = true; f(ahVar); } else if (!this.l) { return; } if (this.m != 0) { throw dh.a(null, null); } if (this.n == 0) { a(ahVar, e(ahVar)); if (this.p) { ahVar.d((int) this.q); return; } return; } throw dh.a(null, null); } private void f(ah ahVar) { boolean f; int a = ahVar.a(1); int a2 = a == 1 ? ahVar.a(1) : 0; this.m = a2; if (a2 == 0) { if (a == 1) { a(ahVar); } if (ahVar.f()) { this.n = ahVar.a(6); int a3 = ahVar.a(4); int a4 = ahVar.a(3); if (a3 == 0 && a4 == 0) { if (a == 0) { int e = ahVar.e(); int c = c(ahVar); ahVar.c(e); byte[] bArr = new byte[(c + 7) / 8]; ahVar.a(bArr, 0, c); f9 a5 = new f9.b().c(this.e).f(MimeTypes.AUDIO_AAC).a(this.u).c(this.t).n(this.r).a(Collections.singletonList(bArr)).e(this.a).a(); if (!a5.equals(this.f)) { this.f = a5; this.s = 1024000000 / a5.A; this.d.a(a5); } } else { ahVar.d(((int) a(ahVar)) - c(ahVar)); } d(ahVar); boolean f2 = ahVar.f(); this.p = f2; this.q = 0L; if (f2) { if (a == 1) { this.q = a(ahVar); } else { do { f = ahVar.f(); this.q = (this.q << 8) + ahVar.a(8); } while (f); } } if (ahVar.f()) { ahVar.d(8); return; } return; } throw dh.a(null, null); } throw dh.a(null, null); } throw dh.a(null, null); } private void d(ah ahVar) { int a = ahVar.a(3); this.o = a; if (a == 0) { ahVar.d(8); return; } if (a == 1) { ahVar.d(9); return; } if (a == 3 || a == 4 || a == 5) { ahVar.d(6); } else { if (a != 6 && a != 7) { throw new IllegalStateException(); } ahVar.d(1); } } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.d = m8Var.a(dVar.c(), 1); this.e = dVar.b(); } private int c(ah ahVar) { int b = ahVar.b(); a.b a = a.a(ahVar, true); this.u = a.c; this.r = a.a; this.t = a.b; return b - ahVar.b(); } private int e(ah ahVar) { int a; if (this.o != 0) { throw dh.a(null, null); } int i = 0; do { a = ahVar.a(8); i += a; } while (a == 255); return i; } private static long a(ah ahVar) { return ahVar.a((ahVar.a(2) + 1) * 8); } private void a(ah ahVar, int i) { int e = ahVar.e(); if ((e & 7) == 0) { this.b.f(e >> 3); } else { ahVar.a(this.b.c(), 0, i * 8); this.b.f(0); } this.d.a(this.b, i); long j = this.k; if (j != C.TIME_UNSET) { this.d.a(j, 1, i, 0, null); this.k += this.s; } } private void a(int i) { this.b.d(i); this.c.a(this.b.c()); } }