package defpackage;

import android.media.MediaCodecInfo;
import android.os.Build;
import android.util.Pair;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil$DecoderQueryException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/* JADX INFO: renamed from: ˑᵮ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC2124 {

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final HashMap f8440 = new HashMap();

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static MediaCodecInfo.CodecProfileLevel m5628(int i, int i2) {
        MediaCodecInfo.CodecProfileLevel codecProfileLevel = new MediaCodecInfo.CodecProfileLevel();
        codecProfileLevel.profile = i;
        codecProfileLevel.level = i2;
        return codecProfileLevel;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static boolean m5629(MediaCodecInfo mediaCodecInfo, String str, boolean z, String str2) {
        if (mediaCodecInfo.isEncoder()) {
            return false;
        }
        if (!z && str.endsWith(".secure")) {
            return false;
        }
        int i = Build.VERSION.SDK_INT;
        if (i < 24 && (("OMX.SEC.aac.dec".equals(str) || "OMX.Exynos.AAC.Decoder".equals(str)) && "samsung".equals(Build.MANUFACTURER))) {
            String str3 = Build.DEVICE;
            if (str3.startsWith("zeroflte") || str3.startsWith("zerolte") || str3.startsWith("zenlte") || "SC-05G".equals(str3) || "marinelteatt".equals(str3) || "404SC".equals(str3) || "SC-04G".equals(str3) || "SCV31".equals(str3)) {
                return false;
            }
        }
        return (i == 23 && "audio/eac3-joc".equals(str2) && "OMX.MTK.AUDIO.DECODER.DSPAC3".equals(str)) ? false : true;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static String m5630(C5286 c5286) {
        Pair pairM5109;
        String str = c5286.f19987;
        String str2 = c5286.f19987;
        if ("audio/eac3-joc".equals(str)) {
            return "audio/eac3";
        }
        if ("video/dolby-vision".equals(str2) && (pairM5109 = AbstractC1879.m5109(c5286)) != null) {
            int iIntValue = ((Integer) pairM5109.first).intValue();
            if (iIntValue == 16 || iIntValue == 256) {
                return "video/hevc";
            }
            if (iIntValue == 512) {
                return "video/avc";
            }
            if (iIntValue == 1024) {
                C3281 c3281 = c5286.f19978;
                if (c3281 != null && c3281.f12575 == 6 && c3281.f12574 == 1) {
                    return null;
                }
                return "video/av01";
            }
        }
        if ("video/mv-hevc".equals(str2)) {
            return "video/hevc";
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static synchronized List m5631(String str, boolean z, boolean z2) {
        try {
            C1512 c1512 = new C1512(str, z, z2);
            HashMap map = f8440;
            List list = (List) map.get(c1512);
            if (list != null) {
                return list;
            }
            ArrayList arrayListM5636 = m5636(c1512, new C1785(z, z2, str.equals("video/mv-hevc")));
            if (z && arrayListM5636.isEmpty() && Build.VERSION.SDK_INT == 23) {
                ArrayList arrayListM56362 = m5636(c1512, new ᵻᵧˁ(0));
                if (!arrayListM56362.isEmpty()) {
                    ˋˀᵧ.ʿٴˇ("MediaCodecList API didn't list secure decoder for: " + str + ". Assuming: " + ((C1354) arrayListM56362.get(0)).f5600);
                }
                arrayListM5636 = arrayListM56362;
            }
            m5632(str, arrayListM5636);
            AbstractC4509 abstractC4509M9559 = AbstractC4509.m9559(arrayListM5636);
            map.put(c1512, abstractC4509M9559);
            return abstractC4509M9559;
        } catch (Throwable th) {
            throw th;
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static void m5632(String str, ArrayList arrayList) {
        if ("audio/raw".equals(str)) {
            if (Build.VERSION.SDK_INT < 26 && Build.DEVICE.equals("R9") && arrayList.size() == 1 && ((C1354) arrayList.get(0)).f5600.equals("OMX.MTK.AUDIO.DECODER.RAW")) {
                arrayList.add(C1354.m3875("OMX.google.raw.decoder", "audio/raw", "audio/raw", null, false, true, false, false));
            }
            Collections.sort(arrayList, new ᵛˎ(7, new C4935(14)));
        }
        if (Build.VERSION.SDK_INT >= 32 || arrayList.size() <= 1 || !"OMX.qti.audio.decoder.flac".equals(((C1354) arrayList.get(0)).f5600)) {
            return;
        }
        arrayList.add((C1354) arrayList.remove(0));
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static C2598 m5633(InterfaceC2978 interfaceC2978, C5286 c5286, boolean z, boolean z2) {
        List listMo7059 = interfaceC2978.mo7059(c5286.f19987, z, z2);
        String strM5630 = m5630(c5286);
        List listMo70592 = strM5630 == null ? C2598.f10048 : interfaceC2978.mo7059(strM5630, z, z2);
        C3975 c3975M9561 = AbstractC4509.m9561();
        c3975M9561.m7408(listMo7059);
        c3975M9561.m7408(listMo70592);
        return c3975M9561.m8718();
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static String m5634(MediaCodecInfo mediaCodecInfo, String str, String str2) {
        for (String str3 : mediaCodecInfo.getSupportedTypes()) {
            if (str3.equalsIgnoreCase(str2)) {
                return str3;
            }
        }
        if (str2.equals("video/dolby-vision")) {
            if ("OMX.MS.HEVCDV.Decoder".equals(str)) {
                return "video/hevcdv";
            }
            if ("OMX.RTK.video.decoder".equals(str) || "OMX.realtek.video.decoder.tunneled".equals(str)) {
                return "video/dv_hevc";
            }
            return null;
        }
        if (str2.equals("video/mv-hevc")) {
            if ("c2.qti.mvhevc.decoder".equals(str) || "c2.qti.mvhevc.decoder.secure".equals(str)) {
                return "video/x-mvhevc";
            }
            return null;
        }
        if (str2.equals("audio/alac") && "OMX.lge.alac.decoder".equals(str)) {
            return "audio/x-lg-alac";
        }
        if (str2.equals("audio/flac") && "OMX.lge.flac.decoder".equals(str)) {
            return "audio/x-lg-flac";
        }
        if (str2.equals("audio/ac3") && "OMX.lge.ac3.decoder".equals(str)) {
            return "audio/lg-ac3";
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public static boolean m5635(MediaCodecInfo mediaCodecInfo, String str) {
        if (Build.VERSION.SDK_INT >= 29) {
            return mediaCodecInfo.isSoftwareOnly();
        }
        if (AbstractC4208.m9139(str)) {
            return true;
        }
        String str2 = ᵻᵕᵭ.ʽᵡᵢᵾ(mediaCodecInfo.getName());
        if (str2.startsWith("arc.")) {
            return false;
        }
        if (str2.startsWith("omx.google.") || str2.startsWith("omx.ffmpeg.")) {
            return true;
        }
        if ((str2.startsWith("omx.sec.") && str2.contains(".sw.")) || str2.equals("omx.qcom.video.decoder.hevcswvdec") || str2.startsWith("c2.android.") || str2.startsWith("c2.google.")) {
            return true;
        }
        return (str2.startsWith("omx.") || str2.startsWith("c2.")) ? false : true;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0047  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0117 A[Catch: Exception -> 0x0161, TryCatch #4 {Exception -> 0x0161, blocks: (B:3:0x000a, B:5:0x001f, B:7:0x0029, B:76:0x0136, B:10:0x0035, B:13:0x0040, B:71:0x0111, B:73:0x0117, B:75:0x011d, B:77:0x013e, B:78:0x015f), top: B:91:0x000a }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x013e A[ADDED_TO_REGION, REMOVE, SYNTHETIC] */
    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static ArrayList m5636(C1512 c1512, InterfaceC3750 interfaceC3750) throws MediaCodecUtil$DecoderQueryException {
        boolean z;
        String str;
        int i;
        int i2;
        C1512 c15122 = c1512;
        boolean z2 = c15122.f6128;
        try {
            ArrayList arrayList = new ArrayList();
            String str2 = c15122.f6130;
            int iMo4938 = interfaceC3750.mo4938();
            boolean zMo4935 = interfaceC3750.mo4935();
            int i3 = 0;
            while (i3 < iMo4938) {
                MediaCodecInfo mediaCodecInfoMo4929 = interfaceC3750.mo4929(i3);
                int i4 = Build.VERSION.SDK_INT;
                if (i4 < 29 || !mediaCodecInfoMo4929.isAlias()) {
                    String name = mediaCodecInfoMo4929.getName();
                    if (m5629(mediaCodecInfoMo4929, name, zMo4935, str2)) {
                        int i5 = i3;
                        String strM5634 = m5634(mediaCodecInfoMo4929, name, str2);
                        if (strM5634 == null) {
                            z = zMo4935;
                            i = i5;
                        } else {
                            try {
                                MediaCodecInfo.CodecCapabilities capabilitiesForType = mediaCodecInfoMo4929.getCapabilitiesForType(strM5634);
                                boolean zMo4939 = interfaceC3750.mo4939("tunneled-playback", strM5634, capabilitiesForType);
                                boolean zMo4925 = interfaceC3750.mo4925("tunneled-playback", capabilitiesForType);
                                boolean z3 = c15122.f6129;
                                if (z3 || !zMo4925) {
                                    if (!z3 || zMo4939) {
                                        boolean zMo49392 = interfaceC3750.mo4939("secure-playback", strM5634, capabilitiesForType);
                                        boolean zMo49252 = interfaceC3750.mo4925("secure-playback", capabilitiesForType);
                                        if (z2 || !zMo49252) {
                                            if (!z2 || zMo49392) {
                                                boolean zIsVendor = true;
                                                boolean zIsHardwareAccelerated = i4 >= 29 ? mediaCodecInfoMo4929.isHardwareAccelerated() : !m5635(mediaCodecInfoMo4929, str2);
                                                z = zMo4935;
                                                try {
                                                    boolean zM5635 = m5635(mediaCodecInfoMo4929, str2);
                                                    if (i4 >= 29) {
                                                        zIsVendor = mediaCodecInfoMo4929.isVendor();
                                                    } else {
                                                        String str3 = ᵻᵕᵭ.ʽᵡᵢᵾ(mediaCodecInfoMo4929.getName());
                                                        if (str3.startsWith("omx.google.") || str3.startsWith("c2.android.") || str3.startsWith("c2.google.")) {
                                                            zIsVendor = false;
                                                        }
                                                    }
                                                    if (!(z && z2 == zMo49392) && (z || z2)) {
                                                        boolean z4 = zIsHardwareAccelerated;
                                                        i2 = i5;
                                                        boolean z5 = zIsVendor;
                                                        if (!z && zMo49392) {
                                                            i = i2;
                                                            str = name;
                                                            try {
                                                                arrayList.add(C1354.m3875(name + ".secure", str2, strM5634, capabilitiesForType, z4, zM5635, z5, true));
                                                                break;
                                                            } catch (Exception e) {
                                                                e = e;
                                                                if (Build.VERSION.SDK_INT != 23) {
                                                                }
                                                                ˋˀᵧ.ᵝᵶ("Failed to query codec " + str + " (" + strM5634 + ")");
                                                                throw e;
                                                            }
                                                        }
                                                    } else {
                                                        boolean z6 = zIsHardwareAccelerated;
                                                        i2 = i5;
                                                        try {
                                                            arrayList.add(C1354.m3875(name, str2, strM5634, capabilitiesForType, z6, zM5635, zIsVendor, false));
                                                        } catch (Exception e2) {
                                                            e = e2;
                                                            i = i2;
                                                            str = name;
                                                            if (Build.VERSION.SDK_INT != 23 || arrayList.isEmpty()) {
                                                                ˋˀᵧ.ᵝᵶ("Failed to query codec " + str + " (" + strM5634 + ")");
                                                                throw e;
                                                            }
                                                            ˋˀᵧ.ᵝᵶ("Skipping codec " + str + " (failed to query capabilities)");
                                                        }
                                                    }
                                                    i = i2;
                                                } catch (Exception e3) {
                                                    e = e3;
                                                    str = name;
                                                    i = i5;
                                                    if (Build.VERSION.SDK_INT != 23) {
                                                    }
                                                    ˋˀᵧ.ᵝᵶ("Failed to query codec " + str + " (" + strM5634 + ")");
                                                    throw e;
                                                }
                                            } else {
                                                z = zMo4935;
                                                i = i5;
                                            }
                                        }
                                    } else {
                                        z = zMo4935;
                                        i = i5;
                                    }
                                }
                            } catch (Exception e4) {
                                e = e4;
                                z = zMo4935;
                                str = name;
                            }
                        }
                    } else {
                        z = zMo4935;
                        i = i3;
                    }
                } else {
                    z = zMo4935;
                    i = i3;
                }
                i3 = i + 1;
                c15122 = c1512;
                zMo4935 = z;
            }
            return arrayList;
        } catch (Exception e5) {
            throw new MediaCodecUtil$DecoderQueryException("Failed to query underlying media codecs", e5);
        }
    }
}
