package F0;

import C3.G;
import L0.A;
import L0.AbstractC0146a;
import L0.C;
import L0.g0;
import P2.C0253j;
import android.net.Uri;
import android.os.Looper;
import android.os.SystemClock;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import u0.AbstractC1589z;
import u0.C1582s;
import u0.C1583t;
import u0.C1584u;
import u0.C1588y;
import x0.AbstractC1709a;
import x0.v;
import z0.y;

/* JADX INFO: loaded from: classes.dex */
public final class l extends AbstractC0146a {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final c f2342h;
    public final K4.c i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final C0253j f2343j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final E0.h f2344k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final C4.f f2345l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final boolean f2346m;

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final G0.c f2348o;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public C1583t f2350q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public y f2351r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public C1588y f2352s;

    static {
        AbstractC1589z.a("media3.exoplayer.hls");
    }

    public l(C1588y c1588y, K4.c cVar, c cVar2, C0253j c0253j, E0.h hVar, C4.f fVar, G0.c cVar3, long j8, boolean z8, int i) {
        this.f2352s = c1588y;
        this.f2350q = c1588y.f17397c;
        this.i = cVar;
        this.f2342h = cVar2;
        this.f2343j = c0253j;
        this.f2344k = hVar;
        this.f2345l = fVar;
        this.f2348o = cVar3;
        this.f2349p = j8;
        this.f2346m = z8;
        this.f2347n = i;
    }

    public static G0.f s(G g8, long j8) {
        G0.f fVar = null;
        for (int i = 0; i < g8.size(); i++) {
            G0.f fVar2 = (G0.f) g8.get(i);
            long j9 = fVar2.f2797u;
            if (j9 > j8 || !fVar2.f2785B) {
                if (j9 > j8) {
                    break;
                }
            } else {
                fVar = fVar2;
            }
        }
        return fVar;
    }

    @Override // L0.AbstractC0146a
    public final A a(C c3, P0.e eVar, long j8) {
        E0.e eVar2 = new E0.e(this.f3758c.f1973c, 0, c3);
        E0.e eVar3 = new E0.e(this.f3759d.f1973c, 0, c3);
        y yVar = this.f2351r;
        C0.l lVar = this.f3762g;
        AbstractC1709a.k(lVar);
        return new k(this.f2342h, this.f2348o, this.i, yVar, this.f2344k, eVar3, this.f2345l, eVar2, eVar, this.f2343j, this.f2346m, this.f2347n, lVar);
    }

    @Override // L0.AbstractC0146a
    public final synchronized C1588y g() {
        return this.f2352s;
    }

    @Override // L0.AbstractC0146a
    public final void i() throws IOException {
        IOException iOException;
        IOException iOException2;
        G0.c cVar = this.f2348o;
        P0.m mVar = cVar.f2764w;
        if (mVar != null) {
            IOException iOException3 = mVar.f5306c;
            if (iOException3 != null) {
                throw iOException3;
            }
            P0.i iVar = mVar.f5305b;
            if (iVar != null && (iOException2 = iVar.f5295u) != null && iVar.f5296v > iVar.f5291q) {
                throw iOException2;
            }
        }
        Uri uri = cVar.f2755A;
        if (uri != null) {
            G0.b bVar = (G0.b) cVar.f2761t.get(uri);
            P0.m mVar2 = bVar.f2745r;
            IOException iOException4 = mVar2.f5306c;
            if (iOException4 != null) {
                throw iOException4;
            }
            P0.i iVar2 = mVar2.f5305b;
            if (iVar2 != null && (iOException = iVar2.f5295u) != null && iVar2.f5296v > iVar2.f5291q) {
                throw iOException;
            }
            IOException iOException5 = bVar.f2753z;
            if (iOException5 != null) {
                throw iOException5;
            }
        }
    }

    @Override // L0.AbstractC0146a
    public final void k(y yVar) {
        this.f2351r = yVar;
        Looper looperMyLooper = Looper.myLooper();
        looperMyLooper.getClass();
        C0.l lVar = this.f3762g;
        AbstractC1709a.k(lVar);
        E0.h hVar = this.f2344k;
        hVar.e(looperMyLooper, lVar);
        hVar.m();
        E0.e eVar = new E0.e(this.f3758c.f1973c, 0, null);
        C1584u c1584u = g().f17396b;
        c1584u.getClass();
        G0.c cVar = this.f2348o;
        cVar.getClass();
        cVar.f2765x = v.n(null);
        cVar.f2763v = eVar;
        cVar.f2766y = this;
        Map map = Collections.EMPTY_MAP;
        Uri uri = c1584u.f17384a;
        AbstractC1709a.l(uri, "The uri must be set.");
        P0.o oVar = new P0.o(((z0.g) cVar.f2758q.f3604r).c(), new z0.k(uri, 1, null, map, 0L, -1L, 1), cVar.f2759r.u());
        AbstractC1709a.j(cVar.f2764w == null);
        P0.m mVar = new P0.m("DefaultHlsPlaylistTracker:MultivariantPlaylist");
        cVar.f2764w = mVar;
        mVar.d(oVar, cVar, cVar.f2760s.o(oVar.f5309c));
    }

    @Override // L0.AbstractC0146a
    public final void m(A a3) {
        k kVar = (k) a3;
        kVar.f2333r.f2762u.remove(kVar);
        for (q qVar : kVar.f2328J) {
            if (qVar.f2384T) {
                for (p pVar : qVar.f2376L) {
                    pVar.j();
                    K4.c cVar = pVar.f3776h;
                    if (cVar != null) {
                        cVar.J(pVar.f3773e);
                        pVar.f3776h = null;
                        pVar.f3775g = null;
                    }
                }
            }
            i iVar = qVar.f2407t;
            G0.b bVar = (G0.b) iVar.f2283g.f2761t.get(iVar.f2281e[iVar.f2292q.a()]);
            if (bVar != null) {
                bVar.f2742A = false;
            }
            iVar.f2289n = null;
            qVar.f2413z.c(qVar);
            qVar.H.removeCallbacksAndMessages(null);
            qVar.X = true;
            qVar.f2373I.clear();
        }
        kVar.f2326G = null;
    }

    @Override // L0.AbstractC0146a
    public final void o() {
        G0.c cVar = this.f2348o;
        cVar.f2755A = null;
        cVar.f2756B = null;
        cVar.f2767z = null;
        cVar.D = -9223372036854775807L;
        cVar.f2764w.c(null);
        cVar.f2764w = null;
        HashMap map = cVar.f2761t;
        Iterator it = map.values().iterator();
        while (it.hasNext()) {
            ((G0.b) it.next()).f2745r.c(null);
        }
        cVar.f2765x.removeCallbacksAndMessages(null);
        cVar.f2765x = null;
        map.clear();
        this.f2344k.a();
    }

    @Override // L0.AbstractC0146a
    public final synchronized void r(C1588y c1588y) {
        this.f2352s = c1588y;
    }

    /* JADX WARN: Removed duplicated region for block: B:79:0x0153  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x015c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void t(G0.k kVar) {
        long j8;
        g0 g0Var;
        boolean z8;
        long jL;
        long j9;
        long jL2;
        boolean z9 = kVar.f2819p;
        long j10 = kVar.f2812h;
        long jW = z9 ? v.W(j10) : -9223372036854775807L;
        int i = kVar.f2808d;
        long j11 = (i == 2 || i == 1) ? jW : -9223372036854775807L;
        G0.c cVar = this.f2348o;
        cVar.f2767z.getClass();
        C0253j c0253j = new C0253j(4);
        boolean z10 = cVar.f2757C;
        long j12 = kVar.f2824u;
        long j13 = 0;
        G g8 = kVar.f2821r;
        boolean z11 = kVar.f2811g;
        long j14 = kVar.f2809e;
        if (z10) {
            long j15 = j10 - cVar.D;
            boolean z12 = kVar.f2818o;
            long j16 = z12 ? j15 + j12 : -9223372036854775807L;
            if (kVar.f2819p) {
                int i5 = v.f18553a;
                z8 = z12;
                long j17 = this.f2349p;
                jL = v.L(j17 == -9223372036854775807L ? System.currentTimeMillis() : SystemClock.elapsedRealtime() + j17) - (j10 + j12);
            } else {
                z8 = z12;
                jL = 0;
            }
            long j18 = this.f2350q.f17379a;
            G0.j jVar = kVar.f2825v;
            if (j18 != -9223372036854775807L) {
                jL2 = v.L(j18);
            } else {
                if (j14 != -9223372036854775807L) {
                    j9 = j12 - j14;
                } else {
                    long j19 = jVar.f2806d;
                    if (j19 == -9223372036854775807L || kVar.f2817n == -9223372036854775807L) {
                        j9 = jVar.f2805c;
                        if (j9 == -9223372036854775807L) {
                            j9 = kVar.f2816m * 3;
                        }
                    } else {
                        j9 = j19;
                    }
                }
                jL2 = j9 + jL;
            }
            long j20 = j12 + jL;
            long j21 = v.j(jL2, jL, j20);
            C1583t c1583t = g().f17397c;
            boolean z13 = c1583t.f17382d == -3.4028235E38f && c1583t.f17383e == -3.4028235E38f && jVar.f2805c == -9223372036854775807L && jVar.f2806d == -9223372036854775807L;
            C1582s c1582s = new C1582s();
            c1582s.f17374a = v.W(j21);
            c1582s.f17377d = z13 ? 1.0f : this.f2350q.f17382d;
            c1582s.f17378e = z13 ? 1.0f : this.f2350q.f17383e;
            C1583t c1583t2 = new C1583t(c1582s);
            this.f2350q = c1583t2;
            long jL3 = j14 != -9223372036854775807L ? j14 : j20 - v.L(c1583t2.f17379a);
            if (z11) {
                j13 = jL3;
                if (i == 2) {
                }
            } else {
                G0.f fVarS = s(kVar.f2822s, jL3);
                if (fVarS != null) {
                    jL3 = fVarS.f2797u;
                } else {
                    if (!g8.isEmpty()) {
                        G0.h hVar = (G0.h) g8.get(v.c(g8, Long.valueOf(jL3), true));
                        G0.f fVarS2 = s(hVar.f2791C, jL3);
                        jL3 = fVarS2 != null ? fVarS2.f2797u : hVar.f2797u;
                    }
                    g0Var = new g0(j11, jW, j16, kVar.f2824u, j15, j13, true, !z8, i == 2 && kVar.f2810f, c0253j, g(), this.f2350q);
                }
                j13 = jL3;
                if (i == 2) {
                    g0Var = new g0(j11, jW, j16, kVar.f2824u, j15, j13, true, !z8, i == 2 && kVar.f2810f, c0253j, g(), this.f2350q);
                }
            }
        } else {
            if (j14 == -9223372036854775807L || g8.isEmpty()) {
                j8 = 0;
            } else {
                if (!z11 && j14 != j12) {
                    j14 = ((G0.h) g8.get(v.c(g8, Long.valueOf(j14), true))).f2797u;
                }
                j8 = j14;
            }
            C1588y c1588yG = g();
            long j22 = kVar.f2824u;
            g0Var = new g0(j11, jW, j22, j22, 0L, j8, true, false, true, c0253j, c1588yG, null);
        }
        l(g0Var);
    }
}
