package defpackage;

import android.media.ResourceBusyException;
import android.media.UnsupportedSchemeException;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import androidx.media3.exoplayer.drm.DefaultDrmSessionManager$MissingSchemeDataException;
import androidx.media3.exoplayer.drm.DrmSession$DrmSessionException;
import androidx.media3.exoplayer.drm.UnsupportedDrmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/* renamed from: ᵶˁᵣ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4788 implements InterfaceC0687 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final ᵪᵨ f17776;

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public C1669 f17777;

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public volatile HandlerC3737 f17778;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final long f17779;

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public C1545 f17780;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final C3718 f17781;

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public int f17782;

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public Looper f17783;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final C1899 f17784;

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public Handler f17785;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final boolean f17786;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C0910 f17787;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final int[] f17788;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public final Set f17789;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final UUID f17790;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public final ArrayList f17791;

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public InterfaceC3599 f17792;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public final Set f17793;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final HashMap f17794;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final InterfaceC3227 f17795;

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public C1669 f17796;

    public C4788(UUID uuid, InterfaceC3227 interfaceC3227, HashMap map, int[] iArr, boolean z, C1899 c1899) {
        uuid.getClass();
        ᵛᵾˏ.ˌᵜᵹᵩ("Use C.CLEARKEY_UUID instead", !AbstractC1360.f5607.equals(uuid));
        this.f17790 = uuid;
        this.f17787 = C0194.f1647;
        this.f17795 = interfaceC3227;
        this.f17794 = map;
        this.f17788 = iArr;
        this.f17786 = z;
        this.f17784 = c1899;
        this.f17776 = new ᵪᵨ(17);
        this.f17781 = new C3718(this);
        this.f17791 = new ArrayList();
        this.f17789 = Collections.newSetFromMap(new IdentityHashMap());
        this.f17793 = Collections.newSetFromMap(new IdentityHashMap());
        this.f17779 = 300000L;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public static ArrayList m10106(C2119 c2119, UUID uuid, boolean z) {
        ArrayList arrayList = new ArrayList(c2119.f8367);
        for (int i = 0; i < c2119.f8367; i++) {
            C1542 c1542 = c2119.f8366[i];
            if ((c1542.m4474(uuid) || (AbstractC1360.f5605.equals(uuid) && c1542.m4474(AbstractC1360.f5607))) && (c1542.f6162 != null || z)) {
                arrayList.add(c1542);
            }
        }
        return arrayList;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static boolean m10107(C1669 c1669) {
        c1669.m4792();
        if (c1669.f6638 != 1) {
            return false;
        }
        DrmSession$DrmSessionException drmSession$DrmSessionExceptionMo4740 = c1669.mo4740();
        drmSession$DrmSessionExceptionMo4740.getClass();
        Throwable cause = drmSession$DrmSessionExceptionMo4740.getCause();
        return (cause instanceof ResourceBusyException) || ᵯˉˋ.ᵢˇᵭ(cause);
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ˇʼʤˎ */
    public final InterfaceC1660 mo2669(C2221 c2221, C3446 c3446) {
        m10111(false);
        ᵛᵾˏ.ᵿʗᵝʽ(this.f17782 > 0);
        this.f17783.getClass();
        return m10109(this.f17783, c2221, c3446, true);
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final C1669 m10108(List list, boolean z, C2221 c2221, boolean z2) {
        C1669 c1669M10112 = m10112(list, z, c2221);
        boolean zM10107 = m10107(c1669M10112);
        long j = this.f17779;
        Set set = this.f17793;
        if (zM10107 && !set.isEmpty()) {
            AbstractC5447 it = AbstractC1559.m4529(set).iterator();
            while (it.hasNext()) {
                ((InterfaceC1660) it.next()).mo4742(null);
            }
            c1669M10112.mo4742(c2221);
            if (j != -9223372036854775807L) {
                c1669M10112.mo4742(null);
            }
            c1669M10112 = m10112(list, z, c2221);
        }
        if (m10107(c1669M10112) && z2) {
            Set set2 = this.f17789;
            if (!set2.isEmpty()) {
                AbstractC5447 it2 = AbstractC1559.m4529(set2).iterator();
                while (it2.hasNext()) {
                    ((C2014) it2.next()).mo1537();
                }
                if (!set.isEmpty()) {
                    AbstractC5447 it3 = AbstractC1559.m4529(set).iterator();
                    while (it3.hasNext()) {
                        ((InterfaceC1660) it3.next()).mo4742(null);
                    }
                }
                c1669M10112.mo4742(c2221);
                if (j != -9223372036854775807L) {
                    c1669M10112.mo4742(null);
                }
                return m10112(list, z, c2221);
            }
        }
        return c1669M10112;
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ᵝᵵᵺ */
    public final void mo2670() throws UnsupportedDrmException {
        C0194 c0194;
        m10111(true);
        int i = this.f17782;
        this.f17782 = i + 1;
        if (i != 0) {
            return;
        }
        if (this.f17792 == null) {
            UUID uuid = this.f17790;
            this.f17787.getClass();
            try {
                try {
                    try {
                        c0194 = new C0194(uuid);
                    } catch (Exception e) {
                        throw new UnsupportedDrmException(e);
                    }
                } catch (UnsupportedSchemeException e2) {
                    throw new UnsupportedDrmException(e2);
                }
            } catch (UnsupportedDrmException unused) {
                ᵳʿˉ.ᵶᵷᵕ("Failed to instantiate a FrameworkMediaDrm for uuid: " + uuid + ".");
                c0194 = new ˉːᵡ(20);
            }
            this.f17792 = c0194;
            c0194.mo1449(new C2931(this));
            return;
        }
        if (this.f17779 == -9223372036854775807L) {
            return;
        }
        int i2 = 0;
        while (true) {
            ArrayList arrayList = this.f17791;
            if (i2 >= arrayList.size()) {
                return;
            }
            ((C1669) arrayList.get(i2)).mo4746(null);
            i2++;
        }
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ᵡʠ */
    public final int mo2671(C3446 c3446) {
        m10111(false);
        InterfaceC3599 interfaceC3599 = this.f17792;
        interfaceC3599.getClass();
        int iMo1462 = interfaceC3599.mo1462();
        C2119 c2119 = c3446.f12915;
        if (c2119 == null) {
            int iM7106 = AbstractC2924.m7106(c3446.f12929);
            int i = 0;
            while (true) {
                int[] iArr = this.f17788;
                if (i >= iArr.length) {
                    i = -1;
                    break;
                }
                if (iArr[i] == iM7106) {
                    break;
                }
                i++;
            }
            if (i == -1) {
                return 0;
            }
        } else {
            UUID uuid = this.f17790;
            if (m10106(c2119, uuid, true).isEmpty()) {
                if (c2119.f8367 == 1 && c2119.f8366[0].m4474(AbstractC1360.f5607)) {
                    ᵳʿˉ.ᵶʔᵢˊ("DrmInitData only contains common PSSH SchemeData. Assuming support for: " + uuid);
                }
                return 1;
            }
            String str = c2119.f8368;
            if (str != null && !"cenc".equals(str) && (!"cbcs".equals(str) ? "cbc1".equals(str) || "cens".equals(str) : Build.VERSION.SDK_INT < 25)) {
                return 1;
            }
        }
        return iMo1462;
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ᵥᵯˎ */
    public final void mo2672() {
        m10111(true);
        int i = this.f17782 - 1;
        this.f17782 = i;
        if (i != 0) {
            return;
        }
        if (this.f17779 != -9223372036854775807L) {
            ArrayList arrayList = new ArrayList(this.f17791);
            for (int i2 = 0; i2 < arrayList.size(); i2++) {
                ((C1669) arrayList.get(i2)).mo4742(null);
            }
        }
        AbstractC5447 it = AbstractC1559.m4529(this.f17789).iterator();
        while (it.hasNext()) {
            ((C2014) it.next()).mo1537();
        }
        m10110();
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ᵳٴᵶ */
    public final void mo2673(Looper looper, C1545 c1545) {
        synchronized (this) {
            try {
                Looper looper2 = this.f17783;
                if (looper2 == null) {
                    this.f17783 = looper;
                    this.f17785 = new Handler(looper);
                } else {
                    ᵛᵾˏ.ᵿʗᵝʽ(looper2 == looper);
                    this.f17785.getClass();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f17780 = c1545;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final InterfaceC1660 m10109(Looper looper, C2221 c2221, C3446 c3446, boolean z) {
        if (this.f17778 == null) {
            this.f17778 = new HandlerC3737(this, looper, 3);
        }
        C2119 c2119 = c3446.f12915;
        int i = 0;
        if (c2119 != null) {
            ArrayList arrayListM10106 = m10106(c2119, this.f17790, false);
            if (arrayListM10106.isEmpty()) {
                DefaultDrmSessionManager$MissingSchemeDataException defaultDrmSessionManager$MissingSchemeDataException = new DefaultDrmSessionManager$MissingSchemeDataException("Media does not support uuid: " + this.f17790);
                ᵳʿˉ.ᵸˑ("DRM error", defaultDrmSessionManager$MissingSchemeDataException);
                if (c2221 != null) {
                    c2221.m5885(defaultDrmSessionManager$MissingSchemeDataException);
                }
                return new C2161(new DrmSession$DrmSessionException(6003, defaultDrmSessionManager$MissingSchemeDataException));
            }
            C1669 c1669 = this.f17796;
            if (c1669 != null) {
                c1669.mo4746(c2221);
                return c1669;
            }
            C1669 c1669M10108 = m10108(arrayListM10106, false, c2221, z);
            this.f17796 = c1669M10108;
            this.f17791.add(c1669M10108);
            return c1669M10108;
        }
        int iM7106 = AbstractC2924.m7106(c3446.f12929);
        InterfaceC3599 interfaceC3599 = this.f17792;
        interfaceC3599.getClass();
        if (interfaceC3599.mo1462() != 2 || !C4641.f17193) {
            int[] iArr = this.f17788;
            while (true) {
                if (i >= iArr.length) {
                    i = -1;
                    break;
                }
                if (iArr[i] == iM7106) {
                    break;
                }
                i++;
            }
            if (i != -1 && interfaceC3599.mo1462() != 1) {
                C1669 c16692 = this.f17777;
                if (c16692 == null) {
                    C4421 c4421 = AbstractC2692.f10429;
                    C1669 c1669M101082 = m10108(C4471.f16684, true, null, z);
                    this.f17791.add(c1669M101082);
                    this.f17777 = c1669M101082;
                } else {
                    c16692.mo4746(null);
                }
                return this.f17777;
            }
        }
        return null;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m10110() {
        if (this.f17792 != null && this.f17782 == 0 && this.f17791.isEmpty() && this.f17789.isEmpty()) {
            InterfaceC3599 interfaceC3599 = this.f17792;
            interfaceC3599.getClass();
            interfaceC3599.mo1456();
            this.f17792 = null;
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m10111(boolean z) {
        if (z && this.f17783 == null) {
            ᵳʿˉ.ˁˑᵰ("DefaultDrmSessionManager accessed before setPlayer(), possibly on the wrong thread.", new IllegalStateException());
            return;
        }
        Thread threadCurrentThread = Thread.currentThread();
        Looper looper = this.f17783;
        looper.getClass();
        if (threadCurrentThread != looper.getThread()) {
            ᵳʿˉ.ˁˑᵰ("DefaultDrmSessionManager accessed on the wrong thread.\nCurrent thread: " + Thread.currentThread().getName() + "\nExpected thread: " + this.f17783.getThread().getName(), new IllegalStateException());
        }
    }

    @Override // defpackage.InterfaceC0687
    /* renamed from: ᵹᵝᵶ */
    public final InterfaceC0235 mo2674(C2221 c2221, C3446 c3446) {
        ᵛᵾˏ.ᵿʗᵝʽ(this.f17782 > 0);
        this.f17783.getClass();
        C2014 c2014 = new C2014(this, c2221);
        Handler handler = this.f17785;
        handler.getClass();
        handler.post(new RunnableC0421(c2014, 18, c3446));
        return c2014;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C1669 m10112(List list, boolean z, C2221 c2221) {
        this.f17792.getClass();
        boolean z2 = this.f17786 | z;
        InterfaceC3599 interfaceC3599 = this.f17792;
        Looper looper = this.f17783;
        looper.getClass();
        C1545 c1545 = this.f17780;
        c1545.getClass();
        C1669 c1669 = new C1669(this.f17790, interfaceC3599, this.f17776, this.f17781, list, z2, z, null, this.f17794, this.f17795, looper, this.f17784, c1545);
        c1669.mo4746(c2221);
        if (this.f17779 != -9223372036854775807L) {
            c1669.mo4746(null);
        }
        return c1669;
    }
}
