package com.applovin.impl; import androidx.work.WorkRequest; import com.applovin.impl.ij; import java.io.EOFException; import java.io.IOException; /* loaded from: classes.dex */ final class j6 implements kg { private final jg a; private final long b; private final long c; private final gl d; private int e; private long f; private long g; private long h; private long i; private long j; private long k; private long l; public j6(gl glVar, long j, long j2, long j3, long j4, boolean z) { b1.a(j >= 0 && j2 > j); this.d = glVar; this.b = j; this.c = j2; if (j3 == j2 - j || z) { this.f = j4; this.e = 4; } else { this.e = 0; } this.a = new jg(); } @Override // com.applovin.impl.kg /* renamed from: b, reason: merged with bridge method [inline-methods] */ public b a() { if (this.f != 0) { return new b(); } return null; } @Override // com.applovin.impl.kg public long a(l8 l8Var) { int i = this.e; if (i == 0) { long f = l8Var.f(); this.g = f; this.e = 1; long j = this.c - 65307; if (j > f) { return j; } } else if (i != 1) { if (i == 2) { long b2 = b(l8Var); if (b2 != -1) { return b2; } this.e = 3; } else if (i != 3) { if (i == 4) { return -1L; } throw new IllegalStateException(); } d(l8Var); this.e = 4; return -(this.k + 2); } this.f = c(l8Var); this.e = 4; return this.g; } private void d(l8 l8Var) { while (true) { this.a.a(l8Var); this.a.a(l8Var, false); jg jgVar = this.a; if (jgVar.c > this.h) { l8Var.b(); return; } else { l8Var.a(jgVar.h + jgVar.i); this.i = l8Var.f(); this.k = this.a.c; } } } public final class b implements ij { @Override // com.applovin.impl.ij public boolean b() { return true; } private b() { } @Override // com.applovin.impl.ij public ij.a b(long j) { return new ij.a(new kj(j, xp.b((j6.this.b + ((j6.this.d.b(j) * (j6.this.c - j6.this.b)) / j6.this.f)) - WorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS, j6.this.b, j6.this.c - 1))); } @Override // com.applovin.impl.ij public long d() { return j6.this.d.a(j6.this.f); } } public long c(l8 l8Var) { this.a.a(); if (this.a.a(l8Var)) { this.a.a(l8Var, false); jg jgVar = this.a; l8Var.a(jgVar.h + jgVar.i); long j = this.a.c; while (true) { jg jgVar2 = this.a; if ((jgVar2.b & 4) == 4 || !jgVar2.a(l8Var) || l8Var.f() >= this.c || !this.a.a(l8Var, true)) { break; } jg jgVar3 = this.a; if (!n8.a(l8Var, jgVar3.h + jgVar3.i)) { break; } j = this.a.c; } return j; } throw new EOFException(); } private long b(l8 l8Var) { if (this.i == this.j) { return -1L; } long f = l8Var.f(); if (!this.a.a(l8Var, this.j)) { long j = this.i; if (j != f) { return j; } throw new IOException("No ogg page can be found."); } this.a.a(l8Var, false); l8Var.b(); long j2 = this.h; jg jgVar = this.a; long j3 = jgVar.c; long j4 = j2 - j3; int i = jgVar.h + jgVar.i; if (0 <= j4 && j4 < 72000) { return -1L; } if (j4 < 0) { this.j = f; this.l = j3; } else { this.i = l8Var.f() + i; this.k = this.a.c; } long j5 = this.j; long j6 = this.i; if (j5 - j6 < 100000) { this.j = j6; return j6; } long f2 = l8Var.f() - (i * (j4 <= 0 ? 2L : 1L)); long j7 = this.j; long j8 = this.i; return xp.b(f2 + ((j4 * (j7 - j8)) / (this.l - this.k)), j8, j7 - 1); } @Override // com.applovin.impl.kg public void a(long j) { this.h = xp.b(j, 0L, this.f - 1); this.e = 2; this.i = this.b; this.j = this.c; this.k = 0L; this.l = this.f; } }