package com.google.android.gms.internal.ads;

import android.net.Uri;
import android.os.Handler;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes2.dex */
public final class yp2 implements ap2, q2, v, y, iq2 {

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public static final Map f18929p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    public static final zn2 f18930q0;
    public boolean V;
    public boolean W;
    public boolean X;
    public boolean Y;
    public xp2 Z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Uri f18931a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public k3 f18932a0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final sv1 f18933b;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public long f18934b0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final dn2 f18935c;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public boolean f18936c0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final hp2 f18937d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final an2 f18939e;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public boolean f18940e0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final tp2 f18941f;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public boolean f18942f0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final n f18943g;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public boolean f18944g0;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final long f18945h;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public int f18946h0;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final long f18947i;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    public boolean f18948i0;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public long f18950j0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final pp2 f18951k;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public boolean f18954l0;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    public int f18956m0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public boolean f18957n0;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public boolean f18958o0;

    @Nullable
    private zo2 zzs;

    @Nullable
    private e5 zzt;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final z f18949j = new z();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final nn0 f18953l = new nn0();

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final up2 f18955m = new up2(this, 2);
    public final up2 Q = new up2(this, 0);
    public final Handler R = bb1.zzc(null);
    public wp2[] U = new wp2[0];
    public jq2[] T = new jq2[0];
    public rp2[] S = new rp2[0];

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public long f18952k0 = -9223372036854775807L;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public int f18938d0 = 1;

    static {
        HashMap map = new HashMap();
        map.put("Icy-MetaData", "1");
        f18929p0 = Collections.unmodifiableMap(map);
        sm2 sm2Var = new sm2();
        sm2Var.zza("icy");
        sm2Var.zzm(MimeTypes.APPLICATION_ICY);
        f18930q0 = new zn2(sm2Var);
    }

    public yp2(Uri uri, sv1 sv1Var, pp2 pp2Var, dn2 dn2Var, an2 an2Var, u uVar, hp2 hp2Var, tp2 tp2Var, n nVar, @Nullable String str, int i10, boolean z10, int i11, @Nullable zn2 zn2Var, long j10, @Nullable f0 f0Var) {
        this.f18931a = uri;
        this.f18933b = sv1Var;
        this.f18935c = dn2Var;
        this.f18939e = an2Var;
        this.f18937d = hp2Var;
        this.f18941f = tp2Var;
        this.f18943g = nVar;
        this.f18945h = i10;
        this.f18951k = pp2Var;
        this.f18947i = j10;
    }

    public final void A() {
        if (this.W) {
            for (jq2 jq2Var : this.T) {
                jq2Var.p();
                jq2Var.f();
            }
        }
        this.f18949j.zzg(this);
        this.R.removeCallbacksAndMessages(null);
        this.zzs = null;
        this.f18958o0 = true;
    }

    public final void B() {
        ih1.b1(this.W);
        this.Z.getClass();
        this.f18932a0.getClass();
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final void a() throws zzat {
        this.f18949j.f(this.f18938d0 == 7 ? 6 : 3);
        if (this.f18957n0 && !this.W) {
            throw zzat.zzb("Loading finished before preparation is complete.", null);
        }
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final void b(long j10) {
        long jI;
        int i10;
        if (this.Y) {
            return;
        }
        B();
        if (z()) {
            return;
        }
        boolean[] zArr = this.Z.f18513c;
        int length = this.T.length;
        for (int i11 = 0; i11 < length; i11++) {
            jq2 jq2Var = this.T[i11];
            boolean z10 = zArr[i11];
            dq2 dq2Var = jq2Var.f12971a;
            synchronized (jq2Var) {
                try {
                    int i12 = jq2Var.f12981k;
                    if (i12 != 0) {
                        long[] jArr = jq2Var.f12979i;
                        int i13 = jq2Var.f12983m;
                        if (j10 >= jArr[i13]) {
                            int iH = jq2Var.h(i13, (!z10 || (i10 = jq2Var.f12984n) == i12) ? i12 : i10 + 1, j10, false);
                            jI = iH != -1 ? jq2Var.i(iH) : -1L;
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            dq2Var.a(jI);
        }
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final long c(d[] dVarArr, boolean[] zArr, kq2[] kq2VarArr, boolean[] zArr2, long j10) {
        boolean[] zArr3;
        d dVar;
        B();
        xp2 xp2Var = this.Z;
        rq2 rq2Var = xp2Var.f18511a;
        int i10 = this.f18946h0;
        int i11 = 0;
        int i12 = 0;
        while (true) {
            int length = dVarArr.length;
            zArr3 = xp2Var.f18513c;
            if (i12 >= length) {
                break;
            }
            kq2 kq2Var = kq2VarArr[i12];
            if (kq2Var != null && (dVarArr[i12] == null || !zArr[i12])) {
                int i13 = ((vp2) kq2Var).f17746a;
                ih1.b1(zArr3[i13]);
                this.f18946h0--;
                zArr3[i13] = false;
                kq2VarArr[i12] = null;
            }
            i12++;
        }
        boolean z10 = !this.f18940e0 ? j10 == 0 || this.Y : i10 != 0;
        for (int i14 = 0; i14 < dVarArr.length; i14++) {
            if (kq2VarArr[i14] == null && (dVar = dVarArr[i14]) != null) {
                ih1.b1(dVar.zze() == 1);
                ih1.b1(dVar.e(0) == 0);
                int iIndexOf = rq2Var.f16205b.indexOf(dVar.zza());
                if (iIndexOf < 0) {
                    iIndexOf = -1;
                }
                ih1.b1(!zArr3[iIndexOf]);
                this.f18946h0++;
                zArr3[iIndexOf] = true;
                this.f18944g0 = dVar.zzc().f19338k | this.f18944g0;
                kq2VarArr[i14] = new vp2(this, iIndexOf);
                zArr2[i14] = true;
                if (!z10) {
                    jq2 jq2Var = this.T[iIndexOf];
                    z10 = (jq2Var.f12982l + jq2Var.f12984n == 0 || jq2Var.o(j10, true)) ? false : true;
                }
            }
        }
        if (this.f18946h0 == 0) {
            this.f18954l0 = false;
            this.f18942f0 = false;
            this.f18944g0 = false;
            z zVar = this.f18949j;
            if (zVar.d()) {
                jq2[] jq2VarArr = this.T;
                int length2 = jq2VarArr.length;
                while (i11 < length2) {
                    jq2VarArr[i11].p();
                    i11++;
                }
                zVar.e();
            } else {
                this.f18957n0 = false;
                for (jq2 jq2Var2 : this.T) {
                    jq2Var2.k(false);
                }
            }
        } else if (z10) {
            j10 = h(j10);
            while (i11 < kq2VarArr.length) {
                if (kq2VarArr[i11] != null) {
                    zArr2[i11] = true;
                }
                i11++;
            }
        }
        this.f18940e0 = true;
        return j10;
    }

    @Override // com.google.android.gms.internal.ads.q2
    public final void d() {
        this.V = true;
        this.R.post(this.f18955m);
    }

    @Override // com.google.android.gms.internal.ads.q2
    public final u3 e(int i10, int i11) {
        return u(new wp2(i10, false));
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x006b  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00af  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00bd  */
    /* JADX WARN: Removed duplicated region for block: B:75:0x00d4  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x00d8  */
    @Override // com.google.android.gms.internal.ads.ap2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long f(long j10, jj2 jj2Var) {
        boolean z10;
        B();
        if (!this.f18932a0.zzb()) {
            return 0L;
        }
        j3 j3VarZzc = this.f18932a0.zzc(j10);
        l3 l3Var = j3VarZzc.f12687a;
        long j11 = jj2Var.f12911a;
        long j12 = jj2Var.f12912b;
        if (j11 == 0) {
            if (j12 == 0) {
                return j10;
            }
            j11 = 0;
        }
        String str = bb1.f9474a;
        long j13 = j10 - j11;
        long j14 = Long.MAX_VALUE;
        long j15 = (((j10 ^ j13) > 0L ? 1 : ((j10 ^ j13) == 0L ? 0 : -1)) >= 0) | (((j11 ^ j10) > 0L ? 1 : ((j11 ^ j10) == 0L ? 0 : -1)) >= 0) ? j13 : ((j13 >>> 63) ^ 1) + Long.MAX_VALUE;
        long j16 = Long.MIN_VALUE;
        if (j15 == Long.MIN_VALUE) {
            if (j13 == Long.MIN_VALUE) {
                j13 = Long.MIN_VALUE;
                if (j15 == Long.MAX_VALUE) {
                }
            }
        } else if (j15 == Long.MAX_VALUE) {
            j15 = j13 != Long.MAX_VALUE ? Long.MIN_VALUE : Long.MAX_VALUE;
        }
        long j17 = j10 + j12;
        long j18 = (((j10 ^ j17) > 0L ? 1 : ((j10 ^ j17) == 0L ? 0 : -1)) >= 0) | (((j12 ^ j10) > 0L ? 1 : ((j12 ^ j10) == 0L ? 0 : -1)) < 0) ? j17 : ((j17 >>> 63) ^ 1) + Long.MAX_VALUE;
        if (j18 == Long.MIN_VALUE) {
            if (j17 == Long.MIN_VALUE) {
            }
            long j19 = l3Var.f13486a;
            z10 = j15 > j19 && j19 <= j14;
            long j20 = j3VarZzc.f12688b.f13486a;
            boolean z11 = j15 > j20 && j20 <= j14;
            if (z10 || !z11) {
                if (!z10) {
                    return z11 ? j20 : j15;
                }
            } else if (Math.abs(j19 - j10) > Math.abs(j20 - j10)) {
                return j20;
            }
            return j19;
        }
        j16 = j17;
        if (j18 == Long.MAX_VALUE) {
            int i10 = (j16 > Long.MAX_VALUE ? 1 : (j16 == Long.MAX_VALUE ? 0 : -1));
        } else {
            j14 = j18;
        }
        long j192 = l3Var.f13486a;
        if (j15 > j192) {
        }
        long j202 = j3VarZzc.f12688b.f13486a;
        if (j15 > j202) {
        }
        if (z10) {
            if (!z10) {
            }
        }
        return j192;
    }

    @Override // com.google.android.gms.internal.ads.lq2
    public final boolean g(hi2 hi2Var) {
        if (this.f18957n0) {
            return false;
        }
        z zVar = this.f18949j;
        if (zVar.a() || this.f18954l0) {
            return false;
        }
        if (this.W && this.f18946h0 == 0) {
            return false;
        }
        boolean zA = this.f18953l.a();
        if (zVar.d()) {
            return zA;
        }
        w();
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:56:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x00b6  */
    @Override // com.google.android.gms.internal.ads.ap2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long h(long j10) {
        z zVar;
        B();
        boolean[] zArr = this.Z.f18512b;
        if (true != this.f18932a0.zzb()) {
            j10 = 0;
        }
        this.f18942f0 = false;
        long j11 = this.f18950j0;
        this.f18950j0 = j10;
        if (z()) {
            this.f18952k0 = j10;
            return j10;
        }
        if (this.f18938d0 == 7 || !(this.f18957n0 || this.f18949j.d())) {
            this.f18954l0 = false;
            this.f18952k0 = j10;
            this.f18957n0 = false;
            this.f18944g0 = false;
            zVar = this.f18949j;
            if (zVar.d()) {
                for (jq2 jq2Var : this.T) {
                    jq2Var.p();
                }
                zVar.e();
            } else {
                zVar.b();
                for (jq2 jq2Var2 : this.T) {
                    jq2Var2.k(false);
                }
            }
        } else {
            int length = this.T.length;
            for (int i10 = 0; i10 < length; i10++) {
                jq2 jq2Var3 = this.T[i10];
                if (this.S[i10].f16197d.get() == zzxf.f19896a) {
                    int i11 = jq2Var3.f12982l;
                    if (jq2Var3.f12984n + i11 != 0 || j11 != j10) {
                        if (this.Y) {
                            synchronized (jq2Var3) {
                                synchronized (jq2Var3) {
                                    jq2Var3.f12984n = 0;
                                    dq2 dq2Var = jq2Var3.f12971a;
                                    dq2Var.f10485d = dq2Var.f10484c;
                                }
                            }
                            int i12 = jq2Var3.f12982l;
                            if (i11 >= i12 && i11 <= jq2Var3.f12981k + i12) {
                                jq2Var3.f12985o = Long.MIN_VALUE;
                                jq2Var3.f12984n = i11 - i12;
                            }
                            if (!zArr[i10] || !this.X) {
                                this.f18954l0 = false;
                                this.f18952k0 = j10;
                                this.f18957n0 = false;
                                this.f18944g0 = false;
                                zVar = this.f18949j;
                                if (zVar.d()) {
                                }
                            }
                        } else if (jq2Var3.o(j10, this.f18957n0)) {
                            continue;
                        } else {
                            if (!zArr[i10]) {
                            }
                            this.f18954l0 = false;
                            this.f18952k0 = j10;
                            this.f18957n0 = false;
                            this.f18944g0 = false;
                            zVar = this.f18949j;
                            if (zVar.d()) {
                            }
                        }
                    }
                }
            }
        }
        return j10;
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final void i(zo2 zo2Var, long j10) {
        this.zzs = zo2Var;
        this.f18953l.a();
        w();
    }

    @Override // com.google.android.gms.internal.ads.lq2
    public final void j(long j10) {
    }

    @Override // com.google.android.gms.internal.ads.q2
    public final void k(k3 k3Var) {
        this.R.post(new pl2(this, k3Var, 4));
    }

    public final void l(sp2 sp2Var, long j10, long j11, boolean z10) {
        Uri uri = sp2Var.f16537b.f11125c;
        to2 to2Var = new to2();
        yo2 yo2Var = new yo2(1, -1, null, 0, null, bb1.o(sp2Var.f16544i), bb1.o(this.f18934b0));
        hp2 hp2Var = this.f18937d;
        hp2Var.getClass();
        hp2Var.a(new gp2(hp2Var, to2Var, yo2Var, 1));
        if (z10) {
            return;
        }
        for (jq2 jq2Var : this.T) {
            jq2Var.k(false);
        }
        if (this.f18946h0 > 0) {
            zo2 zo2Var = this.zzs;
            zo2Var.getClass();
            zo2Var.d(this);
        }
    }

    public final void m(sp2 sp2Var, long j10, long j11) {
        if (this.f18934b0 == -9223372036854775807L && this.f18932a0 != null) {
            long jY = y(true);
            long j12 = jY == Long.MIN_VALUE ? 0L : jY + 10000;
            this.f18934b0 = j12;
            ((bq2) this.f18941f).o(j12, this.f18932a0, this.f18936c0);
        }
        Uri uri = sp2Var.f16537b.f11125c;
        to2 to2Var = new to2();
        yo2 yo2Var = new yo2(1, -1, null, 0, null, bb1.o(sp2Var.f16544i), bb1.o(this.f18934b0));
        hp2 hp2Var = this.f18937d;
        hp2Var.getClass();
        hp2Var.a(new gp2(hp2Var, to2Var, yo2Var, 0));
        this.f18957n0 = true;
        zo2 zo2Var = this.zzs;
        zo2Var.getClass();
        zo2Var.d(this);
    }

    public final /* synthetic */ void n() {
        if (this.f18958o0) {
            return;
        }
        zo2 zo2Var = this.zzs;
        zo2Var.getClass();
        zo2Var.d(this);
    }

    public final /* synthetic */ void o(k3 k3Var) {
        this.f18932a0 = this.zzt == null ? k3Var : new w2(-9223372036854775807L, 0L);
        this.f18934b0 = k3Var.zza();
        boolean z10 = false;
        if (!this.f18948i0 && k3Var.zza() == -9223372036854775807L) {
            z10 = true;
        }
        this.f18936c0 = z10;
        this.f18938d0 = true == z10 ? 7 : 1;
        if (this.W) {
            ((bq2) this.f18941f).o(this.f18934b0, k3Var, z10);
        } else {
            v();
        }
    }

    public final /* synthetic */ e5 p() {
        return this.zzt;
    }

    public final /* synthetic */ void q(e5 e5Var) {
        this.zzt = e5Var;
    }

    public final void r(int i10) {
        B();
        xp2 xp2Var = this.Z;
        boolean[] zArr = xp2Var.f18514d;
        if (zArr[i10]) {
            return;
        }
        zn2 zn2Var = xp2Var.f18511a.a(i10).f11276d[0];
        yo2 yo2Var = new yo2(1, hc.zzf(zn2Var.zzo), zn2Var, 0, null, bb1.o(this.f18950j0), -9223372036854775807L);
        hp2 hp2Var = this.f18937d;
        hp2Var.getClass();
        hp2Var.a(new uz0(hp2Var, yo2Var, 25));
        zArr[i10] = true;
    }

    public final void s(int i10) {
        B();
        if (this.f18954l0) {
            if ((!this.X || this.Z.f18512b[i10]) && !this.T[i10].m(false)) {
                this.f18952k0 = 0L;
                this.f18954l0 = false;
                this.f18942f0 = true;
                this.f18950j0 = 0L;
                this.f18956m0 = 0;
                for (jq2 jq2Var : this.T) {
                    jq2Var.k(false);
                }
                zo2 zo2Var = this.zzs;
                zo2Var.getClass();
                zo2Var.d(this);
            }
        }
    }

    public final boolean t() {
        return this.f18942f0 || z();
    }

    public final u3 u(wp2 wp2Var) {
        int length = this.T.length;
        for (int i10 = 0; i10 < length; i10++) {
            if (wp2Var.equals(this.U[i10])) {
                return this.T[i10];
            }
        }
        if (this.V) {
            int i11 = wp2Var.f18176a;
            StringBuilder sb = new StringBuilder(String.valueOf(i11).length() + 55);
            sb.append("Extractor added new track (id=");
            sb.append(i11);
            sb.append(") after finishing tracks.");
            vt0.c(sb.toString());
            return new m2();
        }
        jq2 jq2Var = new jq2(this.f18943g, this.f18935c, this.f18939e);
        rp2 rp2Var = new rp2(jq2Var);
        jq2Var.zzy(this);
        int i12 = length + 1;
        wp2[] wp2VarArr = (wp2[]) Arrays.copyOf(this.U, i12);
        wp2VarArr[length] = wp2Var;
        String str = bb1.f9474a;
        this.U = wp2VarArr;
        jq2[] jq2VarArr = (jq2[]) Arrays.copyOf(this.T, i12);
        jq2VarArr[length] = jq2Var;
        this.T = jq2VarArr;
        rp2[] rp2VarArr = (rp2[]) Arrays.copyOf(this.S, i12);
        rp2VarArr[length] = rp2Var;
        this.S = rp2VarArr;
        return rp2Var;
    }

    public final void v() {
        long j10;
        int i10;
        if (this.f18958o0 || this.W || !this.V || this.f18932a0 == null) {
            return;
        }
        for (jq2 jq2Var : this.T) {
            if (jq2Var.zzn() == null) {
                return;
            }
        }
        nn0 nn0Var = this.f18953l;
        synchronized (nn0Var) {
            nn0Var.f14669a = false;
        }
        int length = this.T.length;
        fl[] flVarArr = new fl[length];
        boolean[] zArr = new boolean[length];
        int i11 = 0;
        while (true) {
            j10 = this.f18947i;
            int i12 = 1;
            if (i11 >= length) {
                break;
            }
            zn2 zn2VarZzn = this.T[i11].zzn();
            zn2VarZzn.getClass();
            String str = zn2VarZzn.zzo;
            boolean zZza = hc.zza(str);
            boolean z10 = zZza || hc.zzb(str);
            zArr[i11] = z10;
            this.X = z10 | this.X;
            this.Y = j10 != -9223372036854775807L && length == 1 && hc.zzc(str);
            e5 e5Var = this.zzt;
            if (e5Var != null) {
                if (zZza || this.U[i11].f18177b) {
                    ta taVar = zn2VarZzn.zzl;
                    ta taVar2 = taVar == null ? new ta(e5Var) : taVar.b(e5Var);
                    sm2 sm2Var = new sm2(zn2VarZzn);
                    sm2Var.zzk(taVar2);
                    zn2VarZzn = new zn2(sm2Var);
                }
                if (zZza && zn2VarZzn.f19331d == -1 && zn2VarZzn.f19332e == -1 && (i10 = e5Var.f10634a) != -1) {
                    sm2 sm2Var2 = new sm2(zn2VarZzn);
                    sm2Var2.f16481d = i10;
                    zn2VarZzn = new zn2(sm2Var2);
                }
            }
            ((cn2) this.f18935c).getClass();
            if (zn2VarZzn.zzs == null) {
                i12 = 0;
            }
            sm2 sm2Var3 = new sm2(zn2VarZzn);
            sm2Var3.f16503z = i12;
            zn2 zn2Var = new zn2(sm2Var3);
            flVarArr[i11] = new fl(Integer.toString(i11), zn2Var);
            this.f18944g0 |= zn2Var.f19338k;
            i11++;
        }
        this.Z = new xp2(new rq2(flVarArr), zArr);
        if (this.Y && this.f18934b0 == -9223372036854775807L) {
            this.f18934b0 = j10;
            this.f18932a0 = new qp2(this, this.f18932a0);
        }
        ((bq2) this.f18941f).o(this.f18934b0, this.f18932a0, this.f18936c0);
        this.W = true;
        zo2 zo2Var = this.zzs;
        zo2Var.getClass();
        zo2Var.e(this);
    }

    public final void w() {
        sp2 sp2Var = new sp2(this, this.f18931a, this.f18933b, this.f18951k, this, this.f18953l);
        if (this.W) {
            ih1.b1(z());
            long j10 = this.f18934b0;
            if (j10 != -9223372036854775807L && this.f18952k0 > j10) {
                this.f18957n0 = true;
                this.f18952k0 = -9223372036854775807L;
                return;
            }
            k3 k3Var = this.f18932a0;
            k3Var.getClass();
            l3 l3Var = k3Var.zzc(this.f18952k0).f12687a;
            long j11 = this.f18952k0;
            sp2Var.f16541f.f3366a = l3Var.f13487b;
            sp2Var.f16544i = j11;
            sp2Var.f16543h = true;
            sp2Var.f16546k = false;
            for (jq2 jq2Var : this.T) {
                jq2Var.f12985o = this.f18952k0;
            }
            this.f18952k0 = -9223372036854775807L;
        }
        this.f18956m0 = x();
        this.f18949j.c(sp2Var, this, this.f18938d0 == 7 ? 6 : 3);
    }

    public final int x() {
        int i10 = 0;
        for (jq2 jq2Var : this.T) {
            i10 += jq2Var.f12982l + jq2Var.f12981k;
        }
        return i10;
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x0015  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long y(boolean z10) {
        long j10;
        int i10 = 0;
        long jMax = Long.MIN_VALUE;
        while (true) {
            jq2[] jq2VarArr = this.T;
            if (i10 >= jq2VarArr.length) {
                return jMax;
            }
            if (!z10) {
                xp2 xp2Var = this.Z;
                xp2Var.getClass();
                if (xp2Var.f18513c[i10]) {
                    jq2 jq2Var = jq2VarArr[i10];
                    synchronized (jq2Var) {
                        j10 = jq2Var.f12987q;
                    }
                    jMax = Math.max(jMax, j10);
                } else {
                    continue;
                }
            }
            i10++;
        }
    }

    public final boolean z() {
        return this.f18952k0 != -9223372036854775807L;
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final rq2 zzd() {
        B();
        return this.Z.f18511a;
    }

    @Override // com.google.android.gms.internal.ads.ap2
    public final long zzh() {
        if (this.f18944g0) {
            this.f18944g0 = false;
        } else {
            if (!this.f18942f0) {
                return -9223372036854775807L;
            }
            if (!this.f18957n0 && x() <= this.f18956m0) {
                return -9223372036854775807L;
            }
            this.f18942f0 = false;
        }
        return this.f18950j0;
    }

    @Override // com.google.android.gms.internal.ads.lq2
    public final long zzi() {
        long jY;
        boolean z10;
        long j10;
        B();
        if (this.f18957n0 || this.f18946h0 == 0) {
            return Long.MIN_VALUE;
        }
        if (z()) {
            return this.f18952k0;
        }
        if (this.X) {
            int length = this.T.length;
            jY = Long.MAX_VALUE;
            for (int i10 = 0; i10 < length; i10++) {
                xp2 xp2Var = this.Z;
                if (xp2Var.f18512b[i10] && xp2Var.f18513c[i10]) {
                    jq2 jq2Var = this.T[i10];
                    synchronized (jq2Var) {
                        z10 = jq2Var.f12988r;
                    }
                    if (z10) {
                        continue;
                    } else {
                        jq2 jq2Var2 = this.T[i10];
                        synchronized (jq2Var2) {
                            j10 = jq2Var2.f12987q;
                        }
                        jY = Math.min(jY, j10);
                    }
                }
            }
        } else {
            jY = Long.MAX_VALUE;
        }
        if (jY == Long.MAX_VALUE) {
            jY = y(false);
        }
        return jY == Long.MIN_VALUE ? this.f18950j0 : jY;
    }

    @Override // com.google.android.gms.internal.ads.lq2
    public final long zzl() {
        return zzi();
    }

    @Override // com.google.android.gms.internal.ads.lq2
    public final boolean zzn() {
        boolean z10;
        if (!this.f18949j.d()) {
            return false;
        }
        nn0 nn0Var = this.f18953l;
        synchronized (nn0Var) {
            z10 = nn0Var.f14669a;
        }
        return z10;
    }
}
