package com.applovin.impl; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.applovin.impl.tf; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ public final class sf implements q7 { private final bh a; private final tf.a b; private final String c; private qo d; private String e; private int f; private int g; private boolean h; private boolean i; private long j; private int k; private long l; @Override // com.applovin.impl.q7 public void a() { this.f = 0; this.g = 0; this.i = false; this.l = C.TIME_UNSET; } @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.l = j; } } @Override // com.applovin.impl.q7 public void b() { } public sf() { this(null); } @Override // com.applovin.impl.q7 public void a(bh bhVar) { b1.b(this.d); while (bhVar.a() > 0) { int i = this.f; if (i == 0) { b(bhVar); } else if (i == 1) { d(bhVar); } else if (i == 2) { c(bhVar); } else { throw new IllegalStateException(); } } } public sf(String str) { this.f = 0; bh bhVar = new bh(4); this.a = bhVar; bhVar.c()[0] = -1; this.b = new tf.a(); this.l = C.TIME_UNSET; this.c = str; } private void b(bh bhVar) { byte[] c = bhVar.c(); int e = bhVar.e(); for (int d = bhVar.d(); d < e; d++) { byte b = c[d]; boolean z = (b & 255) == 255; boolean z2 = this.i && (b & 224) == 224; this.i = z; if (z2) { bhVar.f(d + 1); this.i = false; this.a.c()[1] = c[d]; this.g = 2; this.f = 1; return; } } bhVar.f(e); } private void d(bh bhVar) { int min = Math.min(bhVar.a(), 4 - this.g); bhVar.a(this.a.c(), this.g, min); int i = this.g + min; this.g = i; if (i < 4) { return; } this.a.f(0); if (!this.b.a(this.a.j())) { this.g = 0; this.f = 1; return; } this.k = this.b.c; if (!this.h) { this.j = (r8.g * 1000000) / r8.d; this.d.a(new f9.b().c(this.e).f(this.b.b).i(4096).c(this.b.e).n(this.b.d).e(this.c).a()); this.h = true; } this.a.f(0); this.d.a(this.a, 4); this.f = 2; } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.e = dVar.b(); this.d = m8Var.a(dVar.c(), 1); } private void c(bh bhVar) { int min = Math.min(bhVar.a(), this.k - this.g); this.d.a(bhVar, min); int i = this.g + min; this.g = i; int i2 = this.k; if (i < i2) { return; } long j = this.l; if (j != C.TIME_UNSET) { this.d.a(j, 1, i2, 0, null); this.l += this.j; } this.g = 0; this.f = 0; } }