package com.applovin.impl; import com.applovin.exoplayer2.common.base.Ascii; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.applovin.impl.k; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ public final class j 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 long i; private f9 j; private int k; private long l; @Override // com.applovin.impl.q7 public void a() { this.f = 0; this.g = 0; this.h = 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 j() { 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.k - this.g); this.e.a(bhVar, min); int i2 = this.g + min; this.g = i2; int i3 = this.k; if (i2 == i3) { long j = this.l; if (j != C.TIME_UNSET) { this.e.a(j, 1, i3, 0, null); this.l += this.i; } this.f = 0; } } } else if (a(bhVar, this.b.c(), 128)) { c(); this.b.f(0); this.e.a(this.b, 128); this.f = 2; } } else if (b(bhVar)) { this.f = 1; this.b.c()[0] = Ascii.VT; this.b.c()[1] = 119; this.g = 2; } } } public j(String str) { ah ahVar = new ah(new byte[128]); this.a = ahVar; this.b = new bh(ahVar.a); this.f = 0; this.l = C.TIME_UNSET; this.c = str; } private boolean b(bh bhVar) { while (true) { if (bhVar.a() <= 0) { return false; } if (!this.h) { this.h = bhVar.w() == 11; } else { int w = bhVar.w(); if (w == 119) { this.h = false; return true; } this.h = w == 11; } } } private void c() { this.a.c(0); k.b a = k.a(this.a); f9 f9Var = this.j; if (f9Var == null || a.d != f9Var.z || a.c != f9Var.A || !xp.a((Object) a.a, (Object) f9Var.m)) { f9 a2 = new f9.b().c(this.d).f(a.a).c(a.d).n(a.c).e(this.c).a(); this.j = a2; this.e.a(a2); } this.k = a.e; this.i = (a.f * 1000000) / this.j.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); } }