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.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* renamed from: ˉˑ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1181 {

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public static final AbstractC0164 f5018 = new C0595(new C2360(7));

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final Context f5019;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public C4966 f5020;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final C1753 f5021;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public C1930 f5022;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public C1434 f5023;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public C0911 f5024;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public C3873 f5025;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public C1028 f5026;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public Boolean f5027;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public Thread f5028;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final Object f5029;

    public C1181(Context context, C1753 c1753) {
        C4966 c4966 = C4966.f18447;
        this.f5029 = new Object();
        this.f5019 = context != null ? context.getApplicationContext() : null;
        this.f5021 = c1753;
        if (c4966 != null) {
            this.f5020 = c4966;
        } else {
            c4966.getClass();
            C1754 c1754 = new C1754(c4966);
            c1754.m7099(c4966);
            this.f5020 = new C4966(c1754);
        }
        this.f5026 = C1028.f4492;
        if (this.f5020.f18451 && 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.");
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static void m3688(C0052 c0052, C1897 c1897, HashMap map) {
        for (int i = 0; i < c0052.f1231; i++) {
            C4904 c4904 = (C4904) c1897.f7650.get(c0052.m1103(i));
            if (c4904 != null) {
                C4010 c4010 = c4904.f18257;
                C4904 c49042 = (C4904) map.get(Integer.valueOf(c4010.f15076));
                if (c49042 == null || (c49042.f18258.isEmpty() && !c4904.f18258.isEmpty())) {
                    map.put(Integer.valueOf(c4010.f15076), c4904);
                }
            }
        }
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public static Pair m3689(C3943[] c3943Arr, int i) {
        for (int i2 = 0; i2 < c3943Arr.length; i2++) {
            C3943 c3943 = c3943Arr[i2];
            if (c3943 != null && c3943.f14887.f15076 == i) {
                return Pair.create(c3943, Integer.valueOf(i2));
            }
        }
        return null;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static void m3690(C1930 c1930, C4966 c4966, C3943[] c3943Arr) {
        for (int i = 0; i < c1930.f7752; i++) {
            int i2 = c1930.f7753[i];
            if (c4966.f18456.get(i) || c4966.f7663.contains(Integer.valueOf(i2))) {
                c3943Arr[i] = null;
            }
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static int m3691(C3446 c3446, AbstractC2692 abstractC2692) {
        for (int i = 0; i < abstractC2692.size(); i++) {
            for (int i2 = 0; i2 < c3446.f12908.size(); i2++) {
                if (((C4577) c3446.f12908.get(i2)).f17013.equals(abstractC2692.get(i))) {
                    return i;
                }
            }
        }
        return Integer.MAX_VALUE;
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0049  */
    /* renamed from: ᵪʩ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static defpackage.C3943 m3692(defpackage.C0052 r13, int[][] r14, defpackage.C4966 r15) {
        /*
            ᵣᵛˊ r0 = r15.f7649
            r0.getClass()
            r0 = 0
            r1 = 0
            r3 = r0
            r5 = r3
            r2 = r1
            r4 = r2
        Lb:
            int r6 = r13.f1231
            if (r2 >= r6) goto L52
            ᵬʢ r6 = r13.m1103(r2)
            r7 = r14[r2]
            r8 = r1
        L16:
            int r9 = r6.f15077
            if (r8 >= r9) goto L4f
            r9 = r7[r8]
            boolean r10 = r15.f18450
            boolean r9 = defpackage.AbstractC2990.m7315(r9, r10)
            if (r9 == 0) goto L4c
            ᵤᵛᵖ[] r9 = r6.f15079
            r9 = r9[r8]
            ˀᵧˇ r10 = new ˀᵧˇ
            r11 = r7[r8]
            r10.<init>(r9, r11)
            if (r5 == 0) goto L49
            boolean r9 = r10.f2971
            boolean r11 = r5.f2971
            ᵩﹳʽ r12 = defpackage.AbstractC3820.f14214
            ᵩᵡᵢ r9 = r12.mo2103(r9, r11)
            boolean r11 = r10.f2972
            boolean r12 = r5.f2972
            ᵩᵡᵢ r9 = r9.mo2103(r11, r12)
            int r9 = r9.mo2102()
            if (r9 <= 0) goto L4c
        L49:
            r3 = r6
            r4 = r8
            r5 = r10
        L4c:
            int r8 = r8 + 1
            goto L16
        L4f:
            int r2 = r2 + 1
            goto Lb
        L52:
            if (r3 != 0) goto L55
            return r0
        L55:
            ᵫˉᵱ r13 = new ᵫˉᵱ
            int[] r14 = new int[]{r4}
            r13.<init>(r1, r3, r14)
            return r13
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C1181.m3692(ʼˋ, int[][], ᵸˎʿ):ᵫˉᵱ");
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public static Pair m3693(int i, C1930 c1930, int[][][] iArr, InterfaceC5560 interfaceC5560, Comparator comparator) {
        int i2;
        Collection collectionM6702;
        C1930 c19302 = c1930;
        ArrayList arrayList = new ArrayList();
        int i3 = c19302.f7752;
        int i4 = 0;
        while (i4 < i3) {
            if (i == c19302.f7753[i4]) {
                C0052 c0052 = c19302.f7751[i4];
                for (int i5 = 0; i5 < c0052.f1231; i5++) {
                    C4010 c4010M1103 = c0052.m1103(i5);
                    C4471 c4471Mo2917 = interfaceC5560.mo2917(i4, c4010M1103, iArr[i4][i5]);
                    int i6 = c4010M1103.f15077;
                    boolean[] zArr = new boolean[i6];
                    int i7 = 0;
                    while (i7 < i6) {
                        AbstractC2812 abstractC2812 = (AbstractC2812) c4471Mo2917.get(i7);
                        int iMo2914 = abstractC2812.mo2914();
                        if (zArr[i7] || iMo2914 == 0) {
                            i2 = i3;
                        } else {
                            if (iMo2914 == 1) {
                                collectionM6702 = AbstractC2692.m6702(abstractC2812);
                            } else {
                                ArrayList arrayList2 = new ArrayList();
                                arrayList2.add(abstractC2812);
                                int i8 = i7 + 1;
                                while (i8 < i6) {
                                    AbstractC2812 abstractC28122 = (AbstractC2812) c4471Mo2917.get(i8);
                                    int i9 = i3;
                                    if (abstractC28122.mo2914() == 2 && abstractC2812.mo2915(abstractC28122)) {
                                        arrayList2.add(abstractC28122);
                                        zArr[i8] = true;
                                    }
                                    i8++;
                                    i3 = i9;
                                }
                                collectionM6702 = arrayList2;
                            }
                            i2 = i3;
                            arrayList.add(collectionM6702);
                        }
                        i7++;
                        i3 = i2;
                    }
                }
            }
            i4++;
            c19302 = c1930;
            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] = ((AbstractC2812) list.get(i10)).f10839;
        }
        AbstractC2812 abstractC28123 = (AbstractC2812) list.get(0);
        return Pair.create(new C3943(0, abstractC28123.f10836, iArr2), Integer.valueOf(abstractC28123.f10837));
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static void m3694(C1930 c1930, C4966 c4966, C3943[] c3943Arr) {
        int i = c1930.f7752;
        for (int i2 = 0; i2 < i; i2++) {
            C0052 c0052 = c1930.f7751[i2];
            Map map = (Map) c4966.f18454.get(i2);
            if (map != null && map.containsKey(c0052)) {
                Map map2 = (Map) c4966.f18454.get(i2);
                C3943 c3943 = null;
                C3946 c3946 = map2 != null ? (C3946) map2.get(c0052) : null;
                if (c3946 != null) {
                    int[] iArr = c3946.f14899;
                    if (iArr.length != 0) {
                        c3943 = new C3943(0, c0052.m1103(c3946.f14898), iArr);
                    }
                }
                c3943Arr[i2] = c3943;
            }
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public static String m3695(String str) {
        if (TextUtils.isEmpty(str) || TextUtils.equals(str, "und")) {
            return null;
        }
        return str;
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public static int m3696(C3446 c3446, String str, boolean z) {
        if (!TextUtils.isEmpty(str) && str.equals(c3446.f12937)) {
            return 4;
        }
        String strM3695 = m3695(str);
        String strM36952 = m3695(c3446.f12937);
        if (strM36952 == null || strM3695 == null) {
            return (z && strM36952 == null) ? 1 : 0;
        }
        if (strM36952.startsWith(strM3695) || strM3695.startsWith(strM36952)) {
            return 3;
        }
        String str2 = AbstractC3558.f13329;
        return strM36952.split("-", 2)[0].equals(strM3695.split("-", 2)[0]) ? 2 : 0;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public static void m3697(C1930 c1930, C4966 c4966, C3943[] c3943Arr) {
        int i = c1930.f7752;
        C0052[] c0052Arr = c1930.f7751;
        HashMap map = new HashMap();
        for (int i2 = 0; i2 < i; i2++) {
            m3688(c0052Arr[i2], c4966, map);
        }
        m3688(c1930.f7750, c4966, map);
        for (int i3 = 0; i3 < i; i3++) {
            C4904 c4904 = (C4904) map.get(Integer.valueOf(c1930.f7753[i3]));
            if (c4904 != null) {
                C4010 c4010 = c4904.f18257;
                AbstractC2692 abstractC2692 = c4904.f18258;
                c3943Arr[i3] = (abstractC2692.isEmpty() || c0052Arr[i3].m1104(c4010) == -1) ? null : new C3943(0, c4010, ˁˈᵸ.ᵙᵢᵨᵳ(abstractC2692));
            }
        }
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m3698(C1897 c1897) {
        if (c1897 instanceof C4966) {
            m3702((C4966) c1897);
        }
        C1754 c1754 = new C1754(m3701());
        c1754.m7099(c1897);
        m3702(new C4966(c1754));
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final void m3699() {
        synchronized (this.f5029) {
            this.f5020.getClass();
        }
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final C1930 m3700() {
        return this.f5022;
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final C4966 m3701() {
        C4966 c4966;
        synchronized (this.f5029) {
            c4966 = this.f5020;
        }
        return c4966;
    }

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final void m3702(C4966 c4966) {
        boolean zEquals;
        synchronized (this.f5029) {
            zEquals = this.f5020.equals(c4966);
            this.f5020 = c4966;
        }
        if (zEquals) {
            return;
        }
        if (c4966.f18451 && this.f5019 == 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.");
        }
        C0911 c0911 = this.f5024;
        if (c0911 != null) {
            c0911.f4140.m10536(10);
        }
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final void m3703() {
        C1434 c1434;
        synchronized (this.f5029) {
            try {
                Thread thread = this.f5028;
                if (thread != null) {
                    ᵛᵾˏ.ᵢˇᵭ("DefaultTrackSelector is accessed on the wrong thread.", thread == Thread.currentThread());
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (Build.VERSION.SDK_INT >= 32 && (c1434 = this.f5023) != null) {
            c1434.m4335();
            this.f5023 = null;
        }
        this.f5024 = null;
        this.f5025 = null;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m3704() {
        boolean z;
        C0911 c0911;
        C1434 c1434;
        synchronized (this.f5029) {
            try {
                z = this.f5020.f18451 && Build.VERSION.SDK_INT >= 32 && (c1434 = this.f5023) != null && c1434.f5833;
            } catch (Throwable th) {
                throw th;
            }
        }
        if (!z || (c0911 = this.f5024) == null) {
            return;
        }
        c0911.f4140.m10536(10);
    }
}
