package L0;

import android.content.Context;
import android.net.Uri;
import e0.C0853a;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import u0.C1578n;
import u0.C1579o;
import u0.C1582s;
import u0.C1583t;
import u0.C1584u;
import u0.C1585v;
import u0.C1587x;
import u0.C1588y;
import x0.AbstractC1709a;

/* JADX INFO: renamed from: L0.q, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0162q implements B {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final D0.y f3892a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public d3.C f3894c;

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final float f3899h;
    public boolean i;

    public C0162q(Context context, T0.k kVar) {
        C0853a c0853a = new C0853a(context);
        this.f3893b = c0853a;
        d3.C c3 = new d3.C(13);
        this.f3894c = c3;
        D0.y yVar = new D0.y(kVar, c3);
        this.f3892a = yVar;
        if (c0853a != ((C0853a) yVar.f1638u)) {
            yVar.f1638u = c0853a;
            ((HashMap) yVar.f1636s).clear();
            ((HashMap) yVar.f1637t).clear();
        }
        this.f3895d = -9223372036854775807L;
        this.f3896e = -9223372036854775807L;
        this.f3897f = -9223372036854775807L;
        this.f3898g = -3.4028235E38f;
        this.f3899h = -3.4028235E38f;
        this.i = true;
    }

    public static B e(Class cls, C0853a c0853a) {
        try {
            return (B) cls.getConstructor(z0.g.class).newInstance(c0853a);
        } catch (Exception e8) {
            throw new IllegalStateException(e8);
        }
    }

    @Override // L0.B
    public final B a(boolean z8) {
        this.i = z8;
        D0.y yVar = this.f3892a;
        yVar.f1634q = z8;
        T0.k kVar = (T0.k) yVar.f1635r;
        synchronized (kVar) {
            kVar.f6436r = z8;
        }
        Iterator it = ((HashMap) yVar.f1637t).values().iterator();
        while (it.hasNext()) {
            ((B) it.next()).a(z8);
        }
        return this;
    }

    @Override // L0.B
    public final B b() {
        D0.y yVar = this.f3892a;
        yVar.getClass();
        synchronized (((T0.k) yVar.f1635r)) {
        }
        return this;
    }

    @Override // L0.B
    public final B c(d3.C c3) {
        this.f3894c = c3;
        D0.y yVar = this.f3892a;
        yVar.f1639v = c3;
        T0.k kVar = (T0.k) yVar.f1635r;
        synchronized (kVar) {
            kVar.f6437s = c3;
        }
        Iterator it = ((HashMap) yVar.f1637t).values().iterator();
        while (it.hasNext()) {
            ((B) it.next()).c(c3);
        }
        return this;
    }

    @Override // L0.B
    public final AbstractC0146a d(C1588y c1588y) {
        boolean z8;
        int i;
        E0.b bVar;
        C0853a c0853a;
        A1.G g8;
        L4.h hVar;
        C1582s c1582s;
        C1584u c1584u;
        List list;
        C3.G g9;
        Uri uri;
        String str;
        long j8;
        C1588y c1588y2 = c1588y;
        int i5 = 12;
        int i8 = 0;
        c1588y2.f17396b.getClass();
        String scheme = c1588y2.f17396b.f17384a.getScheme();
        if (scheme != null && scheme.equals("ssai")) {
            throw null;
        }
        if (Objects.equals(c1588y2.f17396b.f17385b, "application/x-image-uri")) {
            long j9 = c1588y2.f17396b.f17388e;
            int i9 = x0.v.f18553a;
            throw null;
        }
        C1584u c1584u2 = c1588y2.f17396b;
        int iE = x0.v.E(c1584u2.f17384a, c1584u2.f17385b);
        if (c1588y2.f17396b.f17388e != -9223372036854775807L) {
            T0.k kVar = (T0.k) this.f3892a.f1635r;
            synchronized (kVar) {
                kVar.f6438t = 1;
            }
        }
        try {
            D0.y yVar = this.f3892a;
            HashMap map = (HashMap) yVar.f1637t;
            B b8 = (B) map.get(Integer.valueOf(iE));
            if (b8 == null) {
                b8 = (B) yVar.b(iE).get();
                b8.c((d3.C) yVar.f1639v);
                b8.a(yVar.f1634q);
                b8.b();
                map.put(Integer.valueOf(iE), b8);
            }
            C1582s c1582sA = c1588y2.f17397c.a();
            C1583t c1583t = c1588y2.f17397c;
            if (c1583t.f17379a == -9223372036854775807L) {
                c1582sA.f17374a = this.f3895d;
            }
            if (c1583t.f17382d == -3.4028235E38f) {
                c1582sA.f17377d = this.f3898g;
            }
            if (c1583t.f17383e == -3.4028235E38f) {
                c1582sA.f17378e = this.f3899h;
            }
            if (c1583t.f17380b == -9223372036854775807L) {
                c1582sA.f17375b = this.f3896e;
            }
            if (c1583t.f17381c == -9223372036854775807L) {
                c1582sA.f17376c = this.f3897f;
            }
            C1583t c1583t2 = new C1583t(c1582sA);
            String str2 = null;
            if (c1583t2.equals(c1588y2.f17397c)) {
                z8 = true;
            } else {
                C3.E e8 = C3.G.f1197r;
                C3.W w4 = C3.W.f1225u;
                List list2 = Collections.EMPTY_LIST;
                C3.W w6 = C3.W.f1225u;
                C1585v c1585v = C1585v.f17389a;
                u0.r rVar = c1588y2.f17399e;
                L4.h hVar2 = new L4.h();
                hVar2.f4006a = rVar.f17373a;
                String str3 = c1588y2.f17395a;
                u0.B b9 = c1588y2.f17398d;
                c1588y2.f17397c.a();
                C1585v c1585v2 = c1588y2.f17400f;
                C1584u c1584u3 = c1588y2.f17396b;
                if (c1584u3 != null) {
                    String str4 = c1584u3.f17385b;
                    Uri uri2 = c1584u3.f17384a;
                    List list3 = c1584u3.f17386c;
                    C3.G g10 = c1584u3.f17387d;
                    C3.E e9 = C3.G.f1197r;
                    C3.W w8 = C3.W.f1225u;
                    z8 = true;
                    j8 = c1584u3.f17388e;
                    uri = uri2;
                    list = list3;
                    g9 = g10;
                    str = str4;
                } else {
                    z8 = true;
                    list = list2;
                    g9 = w6;
                    uri = null;
                    str = null;
                    j8 = -9223372036854775807L;
                }
                C1582s c1582sA2 = c1583t2.a();
                C1584u c1584u4 = uri != null ? new C1584u(uri, str, null, list, g9, j8) : null;
                if (str3 == null) {
                    str3 = "";
                }
                String str5 = str3;
                u0.r rVar2 = new u0.r(hVar2);
                C1583t c1583t3 = new C1583t(c1582sA2);
                if (b9 == null) {
                    b9 = u0.B.f17123B;
                }
                c1588y2 = new C1588y(str5, rVar2, c1584u4, c1583t3, b9, c1585v2);
            }
            AbstractC0146a abstractC0146aD = b8.d(c1588y2);
            C3.G g11 = c1588y2.f17396b.f17387d;
            if (!g11.isEmpty()) {
                AbstractC0146a[] abstractC0146aArr = new AbstractC0146a[g11.size() + 1];
                abstractC0146aArr[0] = abstractC0146aD;
                int i10 = 0;
                while (i10 < g11.size()) {
                    if (this.i) {
                        C1578n c1578n = new C1578n();
                        c1578n.f17320m = u0.E.m(((C1587x) g11.get(i10)).f17391b);
                        ((C1587x) g11.get(i10)).getClass();
                        c1578n.f17312d = str2;
                        c1578n.f17313e = ((C1587x) g11.get(i10)).f17392c;
                        ((C1587x) g11.get(i10)).getClass();
                        c1578n.f17314f = i8;
                        c1578n.f17310b = ((C1587x) g11.get(i10)).f17393d;
                        c1578n.f17309a = ((C1587x) g11.get(i10)).f17394e;
                        C1579o c1579o = new C1579o(c1578n);
                        C0.b bVar2 = new C0.b(this, 6, c1579o);
                        C0853a c0853a2 = this.f3893b;
                        A1.G g12 = new A1.G(17, bVar2);
                        E0.b bVar3 = new E0.b(i8);
                        C4.f fVar = new C4.f(i5);
                        if (this.f3894c.l(c1579o)) {
                            C1578n c1578nA = c1579o.a();
                            c1578nA.f17320m = u0.E.m("application/x-media3-cues");
                            c1578nA.f17317j = c1579o.f17358n;
                            c1578nA.f17305I = this.f3894c.i(c1579o);
                            c1579o = new C1579o(c1578nA);
                        }
                        C1579o c1579o2 = c1579o;
                        int i11 = i10 + 1;
                        String string = ((C1587x) g11.get(i10)).f17390a.toString();
                        L4.h hVar3 = new L4.h();
                        C3.E e10 = C3.G.f1197r;
                        C3.W w9 = C3.W.f1225u;
                        List list4 = Collections.EMPTY_LIST;
                        C3.W w10 = C3.W.f1225u;
                        C1582s c1582s2 = new C1582s();
                        C1585v c1585v3 = C1585v.f17389a;
                        Uri uri3 = string == null ? null : Uri.parse(string);
                        if (uri3 != null) {
                            bVar = bVar3;
                            hVar = hVar3;
                            c1582s = c1582s2;
                            c0853a = c0853a2;
                            g8 = g12;
                            c1584u = new C1584u(uri3, null, null, list4, w10, -9223372036854775807L);
                        } else {
                            bVar = bVar3;
                            c0853a = c0853a2;
                            g8 = g12;
                            hVar = hVar3;
                            c1582s = c1582s2;
                            c1584u = null;
                        }
                        C1588y c1588y3 = new C1588y("", new u0.r(hVar), c1584u, new C1583t(c1582s), u0.B.f17123B, c1585v3);
                        c1584u.getClass();
                        abstractC0146aArr[i11] = new W(c1588y3, c0853a, g8, bVar.b(c1588y3), fVar, 1048576, c1579o2);
                        i = 12;
                    } else {
                        C0853a c0853a3 = this.f3893b;
                        c0853a3.getClass();
                        i = 12;
                        abstractC0146aArr[i10 + 1] = new k0((C1587x) g11.get(i10), c0853a3, new C4.f(12));
                    }
                    i10++;
                    i5 = i;
                    i8 = 0;
                    str2 = null;
                }
                abstractC0146aD = new M(abstractC0146aArr);
            }
            if (c1588y2.f17399e.f17373a != Long.MIN_VALUE) {
                C0150e c0150e = new C0150e(abstractC0146aD);
                u0.r rVar3 = c1588y2.f17399e;
                AbstractC1709a.j(!c0150e.f3807d);
                long j10 = rVar3.f17373a;
                AbstractC1709a.j(!c0150e.f3807d);
                c0150e.f3805b = j10;
                AbstractC1709a.j(!c0150e.f3807d);
                boolean z9 = z8;
                c0150e.f3806c = z9;
                AbstractC1709a.j(c0150e.f3807d ^ z9);
                AbstractC1709a.j(c0150e.f3807d ^ z9);
                c0150e.f3807d = z9;
                abstractC0146aD = new C0153h(c0150e);
            }
            c1588y2.f17396b.getClass();
            c1588y2.f17396b.getClass();
            return abstractC0146aD;
        } catch (ClassNotFoundException e11) {
            throw new IllegalStateException(e11);
        }
    }
}
