package com.applovin.impl; import com.applovin.impl.be; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ final class xd { public final wd a; public final Object b; public final cj[] c; public boolean d; public boolean e; public zd f; public boolean g; private final boolean[] h; private final ri[] i; private final vo j; private final fe k; private xd l; private po m; private wo n; private long o; private boolean k() { return this.l == null; } public void c(long j) { this.o = j; } public xd d() { return this.l; } public long f() { return this.o; } public po h() { return this.m; } public wo i() { return this.n; } public xd(ri[] riVarArr, long j, vo voVar, n0 n0Var, fe feVar, zd zdVar, wo woVar) { this.i = riVarArr; this.o = j; this.j = voVar; this.k = feVar; be.a aVar = zdVar.a; this.b = aVar.a; this.f = zdVar; this.m = po.d; this.n = woVar; this.c = new cj[riVarArr.length]; this.h = new boolean[riVarArr.length]; this.a = a(aVar, feVar, n0Var, zdVar.b, zdVar.d); } public long g() { return this.f.b + this.o; } public boolean j() { return this.d && (!this.e || this.a.e() == Long.MIN_VALUE); } public long c() { if (!this.d) { return this.f.b; } long e = this.e ? this.a.e() : Long.MIN_VALUE; return e == Long.MIN_VALUE ? this.f.e : e; } public long e() { if (this.d) { return this.a.g(); } return 0L; } public long a(wo woVar, long j, boolean z) { return a(woVar, j, z, new boolean[this.i.length]); } public long e(long j) { return j + f(); } public void l() { a(); a(this.k, this.a); } public void m() { wd wdVar = this.a; if (wdVar instanceof k3) { long j = this.f.d; if (j == C.TIME_UNSET) { j = Long.MIN_VALUE; } ((k3) wdVar).a(0L, j); } } private void b(cj[] cjVarArr) { int i = 0; while (true) { ri[] riVarArr = this.i; if (i >= riVarArr.length) { return; } if (riVarArr[i].e() == -2) { cjVarArr[i] = null; } i++; } } public long d(long j) { return j - f(); } public long a(wo woVar, long j, boolean z, boolean[] zArr) { int i = 0; while (true) { boolean z2 = true; if (i >= woVar.a) { break; } boolean[] zArr2 = this.h; if (z || !woVar.a(this.n, i)) { z2 = false; } zArr2[i] = z2; i++; } b(this.c); a(); this.n = woVar; b(); long a = this.a.a(woVar.c, this.h, this.c, zArr, j); a(this.c); this.e = false; int i2 = 0; while (true) { cj[] cjVarArr = this.c; if (i2 >= cjVarArr.length) { return a; } if (cjVarArr[i2] != null) { b1.b(woVar.a(i2)); if (this.i[i2].e() != -2) { this.e = true; } } else { b1.b(woVar.c[i2] == null); } i2++; } } private void b() { if (!k()) { return; } int i = 0; while (true) { wo woVar = this.n; if (i >= woVar.a) { return; } boolean a = woVar.a(i); h8 h8Var = this.n.c[i]; if (a && h8Var != null) { h8Var.i(); } i++; } } public void b(long j) { b1.b(k()); if (this.d) { this.a.c(d(j)); } } private void a(cj[] cjVarArr) { int i = 0; while (true) { ri[] riVarArr = this.i; if (i >= riVarArr.length) { return; } if (riVarArr[i].e() == -2 && this.n.a(i)) { cjVarArr[i] = new s7(); } i++; } } public void a(long j) { b1.b(k()); this.a.b(d(j)); } public wo b(float f, fo foVar) { wo a = this.j.a(this.i, h(), this.f.a, foVar); for (h8 h8Var : a.c) { if (h8Var != null) { h8Var.a(f); } } return a; } private static wd a(be.a aVar, fe feVar, n0 n0Var, long j, long j2) { wd a = feVar.a(aVar, n0Var, j); return j2 != C.TIME_UNSET ? new k3(a, true, 0L, j2) : a; } private void a() { if (!k()) { return; } int i = 0; while (true) { wo woVar = this.n; if (i >= woVar.a) { return; } boolean a = woVar.a(i); h8 h8Var = this.n.c[i]; if (a && h8Var != null) { h8Var.f(); } i++; } } public void a(float f, fo foVar) { this.d = true; this.m = this.a.b(); wo b = b(f, foVar); zd zdVar = this.f; long j = zdVar.b; long j2 = zdVar.e; if (j2 != C.TIME_UNSET && j >= j2) { j = Math.max(0L, j2 - 1); } long a = a(b, j, false); long j3 = this.o; zd zdVar2 = this.f; this.o = j3 + (zdVar2.b - a); this.f = zdVar2.b(a); } private static void a(fe feVar, wd wdVar) { try { if (wdVar instanceof k3) { feVar.a(((k3) wdVar).a); } else { feVar.a(wdVar); } } catch (RuntimeException e) { pc.a("MediaPeriodHolder", "Period release failed.", e); } } public void a(xd xdVar) { if (xdVar == this.l) { return; } a(); this.l = xdVar; b(); } }