package com.google.android.gms.internal.ads;

import android.media.MediaCodecInfo;
import android.os.Build;
import android.util.Pair;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public abstract class do2 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final HashMap f10469a = new HashMap();

    /* JADX WARN: Removed duplicated region for block: B:104:0x01b1  */
    /* JADX WARN: Removed duplicated region for block: B:105:0x01ba  */
    /* JADX WARN: Removed duplicated region for block: B:15:0x004d  */
    /* JADX WARN: Removed duplicated region for block: B:161:0x0160 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0153  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x0155  */
    /* JADX WARN: Removed duplicated region for block: B:88:0x0173 A[Catch: Exception -> 0x0165, all -> 0x0277, TryCatch #2 {all -> 0x0277, blocks: (B:4:0x0009, B:8:0x001a, B:9:0x002f, B:11:0x003b, B:13:0x0047, B:19:0x0060, B:21:0x006a, B:23:0x0076, B:61:0x0106, B:63:0x0114, B:70:0x012f, B:72:0x0139, B:81:0x0158, B:84:0x0160, B:92:0x017c, B:94:0x0186, B:106:0x01e7, B:117:0x0218, B:118:0x024b, B:95:0x018c, B:97:0x019c, B:99:0x01a4, B:88:0x0173, B:26:0x0083, B:27:0x0088, B:29:0x0091, B:32:0x009c, B:34:0x00a4, B:37:0x00af, B:39:0x00b7, B:41:0x00bf, B:44:0x00ca, B:46:0x00d2, B:49:0x00dd, B:51:0x00e5, B:54:0x00f0, B:56:0x00f8, B:123:0x0273, B:126:0x027a, B:128:0x0282, B:130:0x0288, B:132:0x0292, B:134:0x0298, B:136:0x02a9, B:138:0x02be, B:140:0x02ca, B:142:0x02d0, B:144:0x02d6, B:146:0x02e6, B:147:0x02ef, B:150:0x02fa, B:151:0x0301), top: B:158:0x0009, inners: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:94:0x0186 A[Catch: Exception -> 0x0165, all -> 0x0277, TryCatch #2 {all -> 0x0277, blocks: (B:4:0x0009, B:8:0x001a, B:9:0x002f, B:11:0x003b, B:13:0x0047, B:19:0x0060, B:21:0x006a, B:23:0x0076, B:61:0x0106, B:63:0x0114, B:70:0x012f, B:72:0x0139, B:81:0x0158, B:84:0x0160, B:92:0x017c, B:94:0x0186, B:106:0x01e7, B:117:0x0218, B:118:0x024b, B:95:0x018c, B:97:0x019c, B:99:0x01a4, B:88:0x0173, B:26:0x0083, B:27:0x0088, B:29:0x0091, B:32:0x009c, B:34:0x00a4, B:37:0x00af, B:39:0x00b7, B:41:0x00bf, B:44:0x00ca, B:46:0x00d2, B:49:0x00dd, B:51:0x00e5, B:54:0x00f0, B:56:0x00f8, B:123:0x0273, B:126:0x027a, B:128:0x0282, B:130:0x0288, B:132:0x0292, B:134:0x0298, B:136:0x02a9, B:138:0x02be, B:140:0x02ca, B:142:0x02d0, B:144:0x02d6, B:146:0x02e6, B:147:0x02ef, B:150:0x02fa, B:151:0x0301), top: B:158:0x0009, inners: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x018c A[Catch: Exception -> 0x0165, all -> 0x0277, TryCatch #2 {all -> 0x0277, blocks: (B:4:0x0009, B:8:0x001a, B:9:0x002f, B:11:0x003b, B:13:0x0047, B:19:0x0060, B:21:0x006a, B:23:0x0076, B:61:0x0106, B:63:0x0114, B:70:0x012f, B:72:0x0139, B:81:0x0158, B:84:0x0160, B:92:0x017c, B:94:0x0186, B:106:0x01e7, B:117:0x0218, B:118:0x024b, B:95:0x018c, B:97:0x019c, B:99:0x01a4, B:88:0x0173, B:26:0x0083, B:27:0x0088, B:29:0x0091, B:32:0x009c, B:34:0x00a4, B:37:0x00af, B:39:0x00b7, B:41:0x00bf, B:44:0x00ca, B:46:0x00d2, B:49:0x00dd, B:51:0x00e5, B:54:0x00f0, B:56:0x00f8, B:123:0x0273, B:126:0x027a, B:128:0x0282, B:130:0x0288, B:132:0x0292, B:134:0x0298, B:136:0x02a9, B:138:0x02be, B:140:0x02ca, B:142:0x02d0, B:144:0x02d6, B:146:0x02e6, B:147:0x02ef, B:150:0x02fa, B:151:0x0301), top: B:158:0x0009, inners: #0 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static synchronized List a(String str, boolean z10, boolean z11) {
        int i10;
        String str2;
        String str3;
        String str4;
        String str5;
        String str6;
        String str7;
        int i11;
        String str8;
        String str9;
        yn2 yn2Var;
        int i12;
        String str10;
        ao2 ao2Var;
        String str11;
        ArrayList arrayList;
        boolean zIsFeatureSupported;
        boolean z12;
        int i13;
        boolean zIsHardwareAccelerated;
        boolean zIsVendor;
        try {
            yn2 yn2Var2 = new yn2(str, z10, z11);
            HashMap map = f10469a;
            List list = (List) map.get(yn2Var2);
            if (list != null) {
                return list;
            }
            ao2 ao2Var2 = new ao2(z10, z11, str.equals(MimeTypes.VIDEO_MV_HEVC));
            String str12 = "secure-playback";
            String str13 = "tunneled-playback";
            String str14 = ")";
            String str15 = " (";
            String str16 = "Failed to query codec ";
            try {
                ArrayList arrayList2 = new ArrayList();
                int iA = ao2Var2.a();
                int i14 = 0;
                while (i14 < iA) {
                    MediaCodecInfo mediaCodecInfoB = ao2Var2.b(i14);
                    int i15 = i14;
                    if (Build.VERSION.SDK_INT < 29 || !mediaCodecInfoB.isAlias()) {
                        String name = mediaCodecInfoB.getName();
                        if (mediaCodecInfoB.isEncoder()) {
                            i12 = iA;
                            str10 = str16;
                            str8 = str14;
                            str9 = str13;
                            yn2Var = yn2Var2;
                            ao2Var = ao2Var2;
                            str11 = str12;
                            arrayList = arrayList2;
                        } else {
                            String[] supportedTypes = mediaCodecInfoB.getSupportedTypes();
                            int i16 = iA;
                            int length = supportedTypes.length;
                            ArrayList arrayList3 = arrayList2;
                            int i17 = 0;
                            while (true) {
                                if (i17 < length) {
                                    int i18 = length;
                                    str2 = supportedTypes[i17];
                                    if (str2.equalsIgnoreCase(str)) {
                                        break;
                                    }
                                    i17++;
                                    length = i18;
                                } else {
                                    str2 = null;
                                    if (str.equals(MimeTypes.VIDEO_DOLBY_VISION)) {
                                        if ("OMX.MS.HEVCDV.Decoder".equals(name)) {
                                            str2 = "video/hevcdv";
                                        } else if ("OMX.RTK.video.decoder".equals(name) || "OMX.realtek.video.decoder.tunneled".equals(name)) {
                                            str2 = "video/dv_hevc";
                                        }
                                    } else if (str.equals(MimeTypes.VIDEO_MV_HEVC)) {
                                        if ("c2.qti.mvhevc.decoder".equals(name) || "c2.qti.mvhevc.decoder.secure".equals(name)) {
                                            str2 = "video/x-mvhevc";
                                        }
                                    } else if (str.equals(MimeTypes.AUDIO_ALAC) && "OMX.lge.alac.decoder".equals(name)) {
                                        str2 = "audio/x-lg-alac";
                                    } else if (str.equals(MimeTypes.AUDIO_FLAC) && "OMX.lge.flac.decoder".equals(name)) {
                                        str2 = "audio/x-lg-flac";
                                    } else if (str.equals(MimeTypes.AUDIO_AC3) && "OMX.lge.ac3.decoder".equals(name)) {
                                        str2 = "audio/lg-ac3";
                                    }
                                }
                            }
                            String str17 = str2;
                            if (str17 != null) {
                                try {
                                    MediaCodecInfo.CodecCapabilities capabilitiesForType = mediaCodecInfoB.getCapabilitiesForType(str17);
                                    boolean zIsFeatureSupported2 = capabilitiesForType.isFeatureSupported(str13);
                                    boolean zIsFeatureRequired = capabilitiesForType.isFeatureRequired(str13);
                                    String str18 = str16;
                                    try {
                                        if (yn2Var2.f18909c) {
                                            if (!zIsFeatureSupported2) {
                                                str8 = str14;
                                                str9 = str13;
                                                yn2Var = yn2Var2;
                                                i12 = i16;
                                                str10 = str18;
                                                ao2Var = ao2Var2;
                                                str11 = str12;
                                                arrayList = arrayList3;
                                            }
                                            zIsFeatureSupported = capabilitiesForType.isFeatureSupported(str12);
                                            boolean zIsFeatureRequired2 = capabilitiesForType.isFeatureRequired(str12);
                                            String str19 = str15;
                                            z12 = yn2Var2.f18908b;
                                            if (z12) {
                                                if (z12) {
                                                }
                                                i13 = Build.VERSION.SDK_INT;
                                                String str20 = str14;
                                                if (i13 < 29) {
                                                }
                                                boolean zC = c(mediaCodecInfoB, str);
                                                String str21 = str13;
                                                if (i13 < 29) {
                                                }
                                                if (z12 == zIsFeatureSupported) {
                                                }
                                            }
                                        } else {
                                            if (!zIsFeatureRequired) {
                                                zIsFeatureSupported = capabilitiesForType.isFeatureSupported(str12);
                                                boolean zIsFeatureRequired22 = capabilitiesForType.isFeatureRequired(str12);
                                                String str192 = str15;
                                                try {
                                                    z12 = yn2Var2.f18908b;
                                                    if (z12 && zIsFeatureRequired22) {
                                                        str8 = str14;
                                                        str9 = str13;
                                                        i12 = i16;
                                                        str10 = str18;
                                                        ao2Var = ao2Var2;
                                                        str11 = str12;
                                                        arrayList = arrayList3;
                                                        str6 = str192;
                                                        yn2Var = yn2Var2;
                                                    } else {
                                                        if (z12) {
                                                            if (zIsFeatureSupported) {
                                                                zIsFeatureSupported = true;
                                                            }
                                                            str8 = str14;
                                                            str9 = str13;
                                                            i12 = i16;
                                                            str10 = str18;
                                                            ao2Var = ao2Var2;
                                                            str11 = str12;
                                                            arrayList = arrayList3;
                                                            str6 = str192;
                                                            yn2Var = yn2Var2;
                                                        }
                                                        i13 = Build.VERSION.SDK_INT;
                                                        String str202 = str14;
                                                        if (i13 < 29) {
                                                            try {
                                                                zIsHardwareAccelerated = mediaCodecInfoB.isHardwareAccelerated();
                                                            } catch (Exception e10) {
                                                                e = e10;
                                                                str3 = name;
                                                                str4 = str17;
                                                                str6 = str192;
                                                                str5 = str18;
                                                                str7 = str202;
                                                                i11 = 1;
                                                            }
                                                        } else {
                                                            zIsHardwareAccelerated = !c(mediaCodecInfoB, str);
                                                        }
                                                        boolean zC2 = c(mediaCodecInfoB, str);
                                                        String str212 = str13;
                                                        if (i13 < 29) {
                                                            zIsVendor = mediaCodecInfoB.isVendor();
                                                        } else {
                                                            String strR = ih1.r(mediaCodecInfoB.getName());
                                                            zIsVendor = (strR.startsWith("omx.google.") || strR.startsWith("c2.android.") || strR.startsWith("c2.google.")) ? false : true;
                                                        }
                                                        if (z12 == zIsFeatureSupported) {
                                                            i12 = i16;
                                                            str10 = str18;
                                                            str8 = str202;
                                                            str9 = str212;
                                                            ao2Var = ao2Var2;
                                                            str11 = str12;
                                                            arrayList = arrayList3;
                                                            str6 = str192;
                                                            yn2Var = yn2Var2;
                                                        } else {
                                                            str3 = name;
                                                            i12 = i16;
                                                            ao2Var = ao2Var2;
                                                            arrayList = arrayList3;
                                                            str4 = str17;
                                                            str11 = str12;
                                                            str6 = str192;
                                                            yn2Var = yn2Var2;
                                                            i11 = 1;
                                                            str5 = str18;
                                                            str7 = str202;
                                                            str9 = str212;
                                                            try {
                                                                arrayList.add(tn2.zza(name, str, str17, capabilitiesForType, zIsHardwareAccelerated, zC2, zIsVendor, false, false));
                                                                str10 = str5;
                                                                str8 = str7;
                                                            } catch (Exception e11) {
                                                                e = e11;
                                                            }
                                                        }
                                                    }
                                                } catch (Exception e12) {
                                                    e = e12;
                                                    str3 = name;
                                                    str4 = str17;
                                                    str7 = str14;
                                                    str6 = str192;
                                                    str5 = str18;
                                                    i11 = 1;
                                                    StringBuilder sb = new StringBuilder(String.valueOf(str3).length() + 24 + str4.length() + i11);
                                                    sb.append(str5);
                                                    sb.append(str3);
                                                    sb.append(str6);
                                                    sb.append(str4);
                                                    sb.append(str7);
                                                    vt0.d(sb.toString());
                                                    throw e;
                                                }
                                            }
                                            str8 = str14;
                                            str9 = str13;
                                            yn2Var = yn2Var2;
                                            i12 = i16;
                                            str10 = str18;
                                            ao2Var = ao2Var2;
                                            str11 = str12;
                                            arrayList = arrayList3;
                                        }
                                    } catch (Exception e13) {
                                        e = e13;
                                        str3 = name;
                                        str4 = str17;
                                        str6 = str15;
                                        str7 = str14;
                                    }
                                } catch (Exception e14) {
                                    e = e14;
                                    str3 = name;
                                    str4 = str17;
                                    str5 = str16;
                                    str6 = str15;
                                    str7 = str14;
                                }
                                StringBuilder sb2 = new StringBuilder(String.valueOf(str3).length() + 24 + str4.length() + i11);
                                sb2.append(str5);
                                sb2.append(str3);
                                sb2.append(str6);
                                sb2.append(str4);
                                sb2.append(str7);
                                vt0.d(sb2.toString());
                                throw e;
                            }
                            str10 = str16;
                            str8 = str14;
                            str9 = str13;
                            yn2Var = yn2Var2;
                            str11 = str12;
                            i12 = i16;
                            str6 = str15;
                            ao2Var = ao2Var2;
                            arrayList = arrayList3;
                        }
                        str6 = str15;
                    }
                    i14 = i15 + 1;
                    str16 = str10;
                    str14 = str8;
                    arrayList2 = arrayList;
                    str15 = str6;
                    iA = i12;
                    str13 = str9;
                    ao2Var2 = ao2Var;
                    yn2Var2 = yn2Var;
                    str12 = str11;
                }
                ArrayList arrayList4 = arrayList2;
                yn2 yn2Var3 = yn2Var2;
                if (z10) {
                    arrayList4.isEmpty();
                }
                if (MimeTypes.AUDIO_RAW.equals(str)) {
                    if (Build.VERSION.SDK_INT < 26 && Build.DEVICE.equals("R9") && arrayList4.size() == 1) {
                        i10 = 0;
                        if (((tn2) arrayList4.get(0)).f16954a.equals("OMX.MTK.AUDIO.DECODER.RAW")) {
                            arrayList4.add(tn2.zza("OMX.google.raw.decoder", MimeTypes.AUDIO_RAW, MimeTypes.AUDIO_RAW, null, false, true, false, false, false));
                        }
                    } else {
                        i10 = 0;
                    }
                    Collections.sort(arrayList4, new bo2(xv1.f18602i));
                } else {
                    i10 = 0;
                }
                if (Build.VERSION.SDK_INT < 32 && arrayList4.size() > 1 && "OMX.qti.audio.decoder.flac".equals(((tn2) arrayList4.get(i10)).f16954a)) {
                    arrayList4.add((tn2) arrayList4.remove(i10));
                }
                zzguf zzgufVarS = zzguf.s(arrayList4);
                map.put(yn2Var3, zzgufVarS);
                return zzgufVarS;
            } catch (Exception e15) {
                throw new zzuy("Failed to query underlying media codecs", e15);
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public static List b(xn2 xn2Var, zn2 zn2Var, boolean z10, boolean z11) {
        Iterable iterableA;
        String str = zn2Var.zzo;
        xv1 xv1Var = (xv1) xn2Var;
        xv1Var.getClass();
        List listA = a(str, z10, z11);
        String strZzg = zzg(zn2Var);
        if (strZzg == null) {
            bs1 bs1Var = zzguf.f19771b;
            iterableA = zzgwa.f19786e;
        } else {
            xv1Var.getClass();
            iterableA = a(strZzg, z10, z11);
        }
        bs1 bs1Var2 = zzguf.f19771b;
        as1 as1Var = new as1(4);
        as1Var.b(listA);
        as1Var.b(iterableA);
        return as1Var.g();
    }

    public static boolean c(MediaCodecInfo mediaCodecInfo, String str) {
        if (Build.VERSION.SDK_INT >= 29) {
            return mediaCodecInfo.isSoftwareOnly();
        }
        if (hc.zza(str)) {
            return true;
        }
        String strR = ih1.r(mediaCodecInfo.getName());
        if (strR.startsWith("arc.")) {
            return false;
        }
        if (strR.startsWith("omx.google.") || strR.startsWith("omx.ffmpeg.")) {
            return true;
        }
        if ((strR.startsWith("omx.sec.") && strR.contains(".sw.")) || strR.equals("omx.qcom.video.decoder.hevcswvdec") || strR.startsWith("c2.android.") || strR.startsWith("c2.google.")) {
            return true;
        }
        return (strR.startsWith("omx.") || strR.startsWith("c2.")) ? false : true;
    }

    @Nullable
    public static tn2 zza() throws zzuy {
        List listA = a(MimeTypes.AUDIO_RAW, false, false);
        if (listA.isEmpty()) {
            return null;
        }
        return (tn2) listA.get(0);
    }

    @Nullable
    public static String zzg(zn2 zn2Var) {
        Pair pairZzd;
        String str = zn2Var.zzo;
        if (MimeTypes.AUDIO_E_AC3_JOC.equals(str)) {
            return MimeTypes.AUDIO_E_AC3;
        }
        if (MimeTypes.VIDEO_DOLBY_VISION.equals(str) && (pairZzd = km0.zzd(zn2Var)) != null) {
            int iIntValue = ((Integer) pairZzd.first).intValue();
            if (iIntValue == 16 || iIntValue == 256) {
                return MimeTypes.VIDEO_H265;
            }
            if (iIntValue == 512) {
                return MimeTypes.VIDEO_H264;
            }
            if (iIntValue == 1024) {
                return MimeTypes.VIDEO_AV1;
            }
        }
        if (MimeTypes.VIDEO_MV_HEVC.equals(str)) {
            return MimeTypes.VIDEO_H265;
        }
        return null;
    }
}
