package com.applovin.impl; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.applovin.impl.n; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ public final class m implements q7 { private final ah a; private final bh b; private final String c; private String d; private qo e; private int f; private int g; private boolean h; private boolean i; private long j; private f9 k; private int l; private long m; @Override // com.applovin.impl.q7 public void a() { this.f = 0; this.g = 0; this.h = false; this.i = false; this.m = C.TIME_UNSET; } @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.m = j; } } @Override // com.applovin.impl.q7 public void b() { } public m() { this(null); } @Override // com.applovin.impl.q7 public void a(bh bhVar) { b1.b(this.e); while (bhVar.a() > 0) { int i = this.f; if (i != 0) { if (i != 1) { if (i == 2) { int min = Math.min(bhVar.a(), this.l - this.g); this.e.a(bhVar, min); int i2 = this.g + min; this.g = i2; int i3 = this.l; if (i2 == i3) { long j = this.m; if (j != C.TIME_UNSET) { this.e.a(j, 1, i3, 0, null); this.m += this.j; } this.f = 0; } } } else if (a(bhVar, this.b.c(), 16)) { c(); this.b.f(0); this.e.a(this.b, 16); this.f = 2; } } else if (b(bhVar)) { this.f = 1; this.b.c()[0] = -84; this.b.c()[1] = (byte) (this.i ? 65 : 64); this.g = 2; } } } public m(String str) { ah ahVar = new ah(new byte[16]); this.a = ahVar; this.b = new bh(ahVar.a); this.f = 0; this.g = 0; this.h = false; this.i = false; this.m = C.TIME_UNSET; this.c = str; } private boolean b(bh bhVar) { int w; while (true) { if (bhVar.a() <= 0) { return false; } if (!this.h) { this.h = bhVar.w() == 172; } else { w = bhVar.w(); this.h = w == 172; if (w == 64 || w == 65) { break; } } } this.i = w == 65; return true; } private void c() { this.a.c(0); n.b a = n.a(this.a); f9 f9Var = this.k; if (f9Var == null || a.c != f9Var.z || a.b != f9Var.A || !"audio/ac4".equals(f9Var.m)) { f9 a2 = new f9.b().c(this.d).f("audio/ac4").c(a.c).n(a.b).e(this.c).a(); this.k = a2; this.e.a(a2); } this.l = a.d; this.j = (a.e * 1000000) / this.k.A; } private boolean a(bh bhVar, byte[] bArr, int i) { int min = Math.min(bhVar.a(), i - this.g); bhVar.a(bArr, this.g, min); int i2 = this.g + min; this.g = i2; return i2 == i; } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.d = dVar.b(); this.e = m8Var.a(dVar.c(), 1); } }