package com.applovin.impl; import com.applovin.impl.ij; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ abstract class gl { private qo b; private m8 c; private kg d; private long e; private long f; private long g; private int h; private int i; private long k; private boolean l; private boolean m; private final ig a = new ig(); private b j = new b(); public static class b { f9 a; kg b; } public abstract long a(bh bhVar); public abstract boolean a(bh bhVar, long j, b bVar); public void c(long j) { this.g = j; } public static final class c implements kg { private c() { } @Override // com.applovin.impl.kg public long a(l8 l8Var) { return -1L; } @Override // com.applovin.impl.kg public void a(long j) { } @Override // com.applovin.impl.kg public ij a() { return new ij.b(C.TIME_UNSET); } } private void a() { b1.b(this.b); xp.a(this.c); } public long b(long j) { return (this.i * j) / 1000000; } public long a(long j) { return (j * 1000000) / this.i; } private int b(l8 l8Var) { if (!a(l8Var)) { return -1; } f9 f9Var = this.j.a; this.i = f9Var.A; if (!this.m) { this.b.a(f9Var); this.m = true; } kg kgVar = this.j.b; if (kgVar != null) { this.d = kgVar; } else if (l8Var.a() == -1) { this.d = new c(); } else { jg a2 = this.a.a(); this.d = new j6(this, this.f, l8Var.a(), a2.h + a2.i, a2.c, (a2.b & 4) != 0); } this.h = 2; this.a.d(); return 0; } public void a(m8 m8Var, qo qoVar) { this.c = m8Var; this.b = qoVar; a(true); } public final int a(l8 l8Var, th thVar) { a(); int i = this.h; if (i == 0) { return b(l8Var); } if (i == 1) { l8Var.a((int) this.f); this.h = 2; return 0; } if (i == 2) { xp.a(this.d); return b(l8Var, thVar); } if (i == 3) { return -1; } throw new IllegalStateException(); } private int b(l8 l8Var, th thVar) { long a2 = this.d.a(l8Var); if (a2 >= 0) { thVar.a = a2; return 1; } if (a2 < -1) { c(-(a2 + 2)); } if (!this.l) { this.c.a((ij) b1.b(this.d.a())); this.l = true; } if (this.k <= 0 && !this.a.a(l8Var)) { this.h = 3; return -1; } this.k = 0L; bh b2 = this.a.b(); long a3 = a(b2); if (a3 >= 0) { long j = this.g; if (j + a3 >= this.e) { long a4 = a(j); this.b.a(b2, b2.e()); this.b.a(a4, 1, b2.e(), 0, null); this.e = -1L; } } this.g += a3; return 0; } private boolean a(l8 l8Var) { while (this.a.a(l8Var)) { this.k = l8Var.f() - this.f; if (!a(this.a.b(), this.f, this.j)) { return true; } this.f = l8Var.f(); } this.h = 3; return false; } public void a(boolean z) { if (z) { this.j = new b(); this.f = 0L; this.h = 0; } else { this.h = 1; } this.e = -1L; this.g = 0L; } public final void a(long j, long j2) { this.a.c(); if (j == 0) { a(!this.l); } else if (this.h != 0) { this.e = b(j2); ((kg) xp.a(this.d)).a(this.e); this.h = 2; } } }