package defpackage;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.RandomAccess;

/* JADX INFO: renamed from: ᵕᵕᵎᵎ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2330 {

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static final AbstractC4498 f9157 = new C1957(new C2262(7));

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public C4216 f9158;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public Thread f9159;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public C4997 f9160;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final Context f9161;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public C4683 f9162;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public C1760 f9163;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public C2600 f9164;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public Boolean f9165;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final Object f9166;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public C5304 f9167;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final C2516 f9168;

    public C2330(Context context, C2516 c2516) {
        C2600 c2600 = C2600.f10056;
        this.f9166 = new Object();
        this.f9161 = context != null ? context.getApplicationContext() : null;
        this.f9168 = c2516;
        if (c2600 != null) {
            this.f9164 = c2600;
        } else {
            c2600.getClass();
            C1718 c1718 = new C1718(c2600);
            c1718.m3305(c2600);
            this.f9164 = new C2600(c1718);
        }
        this.f9162 = C4683.f17774;
        if (this.f9164.f10060 && context == null) {
            ˋˀᵧ.ʿٴˇ("Audio channel count constraints cannot be applied without reference to Context. Build the track selector instance with one of the non-deprecated constructors that take a Context argument.");
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static void m5973(C4997 c4997, C2600 c2600, C3159[] c3159Arr) {
        int i = c4997.f18946;
        for (int i2 = 0; i2 < i; i2++) {
            C5502 c5502 = c4997.f18944[i2];
            Map map = (Map) c2600.f10062.get(i2);
            if (map != null && map.containsKey(c5502)) {
                Map map2 = (Map) c2600.f10062.get(i2);
                C3159 c3159 = null;
                C5385 c5385 = map2 != null ? (C5385) map2.get(c5502) : null;
                if (c5385 != null) {
                    int[] iArr = c5385.f20401;
                    if (iArr.length != 0) {
                        c3159 = new C3159(0, c5502.m11142(c5385.f20402), iArr);
                    }
                }
                c3159Arr[i2] = c3159;
            }
        }
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static int m5974(C5286 c5286, String str, boolean z) {
        if (!TextUtils.isEmpty(str) && str.equals(c5286.f19997)) {
            return 4;
        }
        String strM5980 = m5980(str);
        String strM59802 = m5980(c5286.f19997);
        if (strM59802 == null || strM5980 == null) {
            return (z && strM59802 == null) ? 1 : 0;
        }
        if (strM59802.startsWith(strM5980) || strM5980.startsWith(strM59802)) {
            return 3;
        }
        String str2 = AbstractC0956.f4222;
        return strM59802.split("-", 2)[0].equals(strM5980.split("-", 2)[0]) ? 2 : 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0049  */
    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static C3159 m5975(C5502 c5502, int[][] iArr, C2600 c2600) {
        c2600.f8111.getClass();
        C1882 c1882 = null;
        C0971 c0971 = null;
        int i = 0;
        for (int i2 = 0; i2 < c5502.f20789; i2++) {
            C1882 c1882M11142 = c5502.m11142(i2);
            int[] iArr2 = iArr[i2];
            for (int i3 = 0; i3 < c1882M11142.f7462; i3++) {
                if (AbstractC2704.m6515(iArr2[i3], c2600.f10066)) {
                    C0971 c09712 = new C0971(c1882M11142.f7463[i3], iArr2[i3]);
                    if (c0971 != null) {
                        if (AbstractC3146.f11991.mo1117(c09712.f4258, c0971.f4258).mo1117(c09712.f4257, c0971.f4257).mo1118() > 0) {
                            c1882 = c1882M11142;
                            i = i3;
                            c0971 = c09712;
                        }
                    }
                }
            }
        }
        if (c1882 == null) {
            return null;
        }
        return new C3159(0, c1882, new int[]{i});
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static void m5976(C4997 c4997, C2600 c2600, C3159[] c3159Arr) {
        for (int i = 0; i < c4997.f18946; i++) {
            int i2 = c4997.f18943[i];
            if (c2600.f10059.get(i) || c2600.f8104.contains(Integer.valueOf(i2))) {
                c3159Arr[i] = null;
            }
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static void m5977(C5502 c5502, C2039 c2039, HashMap map) {
        for (int i = 0; i < c5502.f20789; i++) {
            C2549 c2549 = (C2549) c2039.f8105.get(c5502.m11142(i));
            if (c2549 != null) {
                C1882 c1882 = c2549.f9854;
                C2549 c25492 = (C2549) map.get(Integer.valueOf(c1882.f7460));
                if (c25492 == null || (c25492.f9853.isEmpty() && !c2549.f9853.isEmpty())) {
                    map.put(Integer.valueOf(c1882.f7460), c2549);
                }
            }
        }
    }

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public static Pair m5978(int i, C4997 c4997, int[][][] iArr, InterfaceC2902 interfaceC2902, Comparator comparator) {
        int i2;
        RandomAccess randomAccessM9553;
        C4997 c49972 = c4997;
        ArrayList arrayList = new ArrayList();
        int i3 = c49972.f18946;
        int i4 = 0;
        while (i4 < i3) {
            if (i == c49972.f18943[i4]) {
                C5502 c5502 = c49972.f18944[i4];
                for (int i5 = 0; i5 < c5502.f20789; i5++) {
                    C1882 c1882M11142 = c5502.m11142(i5);
                    C2598 c2598Mo6785 = interfaceC2902.mo6785(i4, c1882M11142, iArr[i4][i5]);
                    int i6 = c1882M11142.f7462;
                    boolean[] zArr = new boolean[i6];
                    int i7 = 0;
                    while (i7 < i6) {
                        AbstractC4746 abstractC4746 = (AbstractC4746) c2598Mo6785.get(i7);
                        int iMo4023 = abstractC4746.mo4023();
                        if (zArr[i7] || iMo4023 == 0) {
                            i2 = i3;
                        } else {
                            if (iMo4023 == 1) {
                                randomAccessM9553 = AbstractC4509.m9553(abstractC4746);
                            } else {
                                ArrayList arrayList2 = new ArrayList();
                                arrayList2.add(abstractC4746);
                                int i8 = i7 + 1;
                                while (i8 < i6) {
                                    AbstractC4746 abstractC47462 = (AbstractC4746) c2598Mo6785.get(i8);
                                    int i9 = i3;
                                    if (abstractC47462.mo4023() == 2 && abstractC4746.mo4021(abstractC47462)) {
                                        arrayList2.add(abstractC47462);
                                        zArr[i8] = true;
                                    }
                                    i8++;
                                    i3 = i9;
                                }
                                randomAccessM9553 = arrayList2;
                            }
                            i2 = i3;
                            arrayList.add(randomAccessM9553);
                        }
                        i7++;
                        i3 = i2;
                    }
                }
            }
            i4++;
            c49972 = c4997;
            i3 = i3;
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        List list = (List) Collections.max(arrayList, comparator);
        int[] iArr2 = new int[list.size()];
        for (int i10 = 0; i10 < list.size(); i10++) {
            iArr2[i10] = ((AbstractC4746) list.get(i10)).f18049;
        }
        AbstractC4746 abstractC47463 = (AbstractC4746) list.get(0);
        return Pair.create(new C3159(0, abstractC47463.f18050, iArr2), Integer.valueOf(abstractC47463.f18048));
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static int m5979(C5286 c5286, AbstractC4509 abstractC4509) {
        for (int i = 0; i < abstractC4509.size(); i++) {
            for (int i2 = 0; i2 < c5286.f19976.size(); i2++) {
                if (((C2700) c5286.f19976.get(i2)).f10389.equals(abstractC4509.get(i))) {
                    return i;
                }
            }
        }
        return Integer.MAX_VALUE;
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public static String m5980(String str) {
        if (TextUtils.isEmpty(str) || TextUtils.equals(str, "und")) {
            return null;
        }
        return str;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static void m5981(C4997 c4997, C2600 c2600, C3159[] c3159Arr) {
        int i = c4997.f18946;
        C5502[] c5502Arr = c4997.f18944;
        HashMap map = new HashMap();
        for (int i2 = 0; i2 < i; i2++) {
            m5977(c5502Arr[i2], c2600, map);
        }
        m5977(c4997.f18948, c2600, map);
        for (int i3 = 0; i3 < i; i3++) {
            C2549 c2549 = (C2549) map.get(Integer.valueOf(c4997.f18943[i3]));
            if (c2549 != null) {
                C1882 c1882 = c2549.f9854;
                AbstractC4509 abstractC4509 = c2549.f9853;
                c3159Arr[i3] = (abstractC4509.isEmpty() || c5502Arr[i3].m11141(c1882) == -1) ? null : new C3159(0, c1882, ᵝˉː.ᵛˑﹳ(abstractC4509));
            }
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static Pair m5982(C3159[] c3159Arr, int i) {
        for (int i2 = 0; i2 < c3159Arr.length; i2++) {
            C3159 c3159 = c3159Arr[i2];
            if (c3159 != null && c3159.f12019.f7460 == i) {
                return Pair.create(c3159, Integer.valueOf(i2));
            }
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final void m5983() {
        C5304 c5304;
        synchronized (this.f9166) {
            try {
                Thread thread = this.f9159;
                if (thread != null) {
                    ᵻᵪ.ˊᵨᵧ("DefaultTrackSelector is accessed on the wrong thread.", thread == Thread.currentThread());
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (Build.VERSION.SDK_INT >= 32 && (c5304 = this.f9167) != null) {
            c5304.m10891();
            this.f9167 = null;
        }
        this.f9163 = null;
        this.f9158 = null;
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final void m5984(C2039 c2039) {
        if (c2039 instanceof C2600) {
            m5986((C2600) c2039);
        }
        C1718 c1718 = new C1718(m5989());
        c1718.m3305(c2039);
        m5986(new C2600(c1718));
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final void m5985() {
        synchronized (this.f9166) {
            this.f9164.getClass();
        }
    }

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public final void m5986(C2600 c2600) {
        boolean zEquals;
        synchronized (this.f9166) {
            zEquals = this.f9164.equals(c2600);
            this.f9164 = c2600;
        }
        if (zEquals) {
            return;
        }
        if (c2600.f10060 && this.f9161 == null) {
            ˋˀᵧ.ʿٴˇ("Audio channel count constraints cannot be applied without reference to Context. Build the track selector instance with one of the non-deprecated constructors that take a Context argument.");
        }
        C1760 c1760 = this.f9163;
        if (c1760 != null) {
            c1760.f7032.m7176(10);
        }
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void m5987() {
        boolean z;
        C1760 c1760;
        C5304 c5304;
        synchronized (this.f9166) {
            try {
                z = this.f9164.f10060 && Build.VERSION.SDK_INT >= 32 && (c5304 = this.f9167) != null && c5304.f20025;
            } catch (Throwable th) {
                throw th;
            }
        }
        if (!z || (c1760 = this.f9163) == null) {
            return;
        }
        c1760.f7032.m7176(10);
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final C4997 m5988() {
        return this.f9160;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final C2600 m5989() {
        C2600 c2600;
        synchronized (this.f9166) {
            c2600 = this.f9164;
        }
        return c2600;
    }
}
