package n;

import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaFormat;
import android.text.TextUtils;
import android.util.Log;
import b0.AbstractC0399d;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public abstract class u {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final C0640f f5756a = new C0640f("OMX.google.raw.decoder", null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Map f5757b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static int f5758c = -1;

    private static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final String f5759a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final boolean f5760b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final boolean f5761c;

        public a(String str, boolean z2, boolean z3) {
            this.f5759a = str;
            this.f5760b = z2;
            this.f5761c = z3;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || obj.getClass() != a.class) {
                return false;
            }
            a aVar = (a) obj;
            return TextUtils.equals(this.f5759a, aVar.f5759a) && this.f5760b == aVar.f5760b && this.f5761c == aVar.f5761c;
        }

        public int hashCode() {
            String str = this.f5759a;
            return (((((str == null ? 0 : str.hashCode()) + 31) * 31) + (this.f5760b ? 1231 : 1237)) * 31) + (this.f5761c ? 1231 : 1237);
        }
    }

    public static class b extends IOException {
        private b(Throwable th) {
            super("Failed to query underlying media codecs", th);
        }
    }

    private interface c {
        MediaCodecInfo a(int i2);

        boolean b(String str, MediaCodecInfo.CodecCapabilities codecCapabilities);

        int c();

        boolean d();
    }

    private static final class d implements c {
        private d() {
        }

        @Override // n.u.c
        public MediaCodecInfo a(int i2) {
            return MediaCodecList.getCodecInfoAt(i2);
        }

        @Override // n.u.c
        public boolean b(String str, MediaCodecInfo.CodecCapabilities codecCapabilities) {
            return "video/avc".equals(str);
        }

        @Override // n.u.c
        public int c() {
            return MediaCodecList.getCodecCount();
        }

        @Override // n.u.c
        public boolean d() {
            return false;
        }
    }

    private static final class e implements c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final int f5762a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private MediaCodecInfo[] f5763b;

        public e(boolean z2) {
            this.f5762a = z2 ? 1 : 0;
        }

        private void e() {
            if (this.f5763b == null) {
                this.f5763b = new MediaCodecList(this.f5762a).getCodecInfos();
            }
        }

        @Override // n.u.c
        public MediaCodecInfo a(int i2) {
            e();
            return this.f5763b[i2];
        }

        @Override // n.u.c
        public boolean b(String str, MediaCodecInfo.CodecCapabilities codecCapabilities) {
            return codecCapabilities.isFeatureSupported("secure-playback");
        }

        @Override // n.u.c
        public int c() {
            e();
            return this.f5763b.length;
        }

        @Override // n.u.c
        public boolean d() {
            return true;
        }

        public String f(MediaFormat mediaFormat) {
            try {
                return new MediaCodecList(this.f5762a).findDecoderForFormat(mediaFormat);
            } catch (IllegalArgumentException | NullPointerException unused) {
                Log.e("MediaCodecUtil", "findDecoderForFormat with illegal format");
                return null;
            }
        }

        public String g(MediaFormat mediaFormat) {
            String string = mediaFormat.getString("mime");
            String str = null;
            try {
                MediaCodecInfo[] codecInfos = new MediaCodecList(this.f5762a).getCodecInfos();
                int length = codecInfos.length;
                String name = null;
                int i2 = 0;
                while (i2 < length) {
                    MediaCodecInfo mediaCodecInfo = codecInfos[i2];
                    if (!mediaCodecInfo.isEncoder()) {
                        try {
                            MediaCodecInfo.CodecCapabilities capabilitiesForType = mediaCodecInfo.getCapabilitiesForType(string);
                            if (capabilitiesForType == null) {
                                continue;
                            } else {
                                if (string != null && !capabilitiesForType.getMimeType().equalsIgnoreCase(string)) {
                                    return str;
                                }
                                if (mediaFormat.containsKey("profile")) {
                                    int integer = mediaFormat.getInteger("profile");
                                    for (MediaCodecInfo.CodecProfileLevel codecProfileLevel : capabilitiesForType.profileLevels) {
                                        if (codecProfileLevel.profile == integer) {
                                            name = mediaCodecInfo.getName();
                                            Log.i("MediaCodecUtil", "findDecoderForFormatWithoutLevel profile = " + integer + " decoderName = " + name);
                                        }
                                    }
                                }
                            }
                        } catch (IllegalArgumentException unused) {
                            continue;
                        }
                    }
                    i2++;
                    str = null;
                }
                return name;
            } catch (IllegalArgumentException | NullPointerException unused2) {
                Log.e("MediaCodecUtil", "findDecoderForFormatWithoutLevel with illegal format");
                return null;
            }
        }
    }

    private static int a(int i2) {
        if (i2 == 1 || i2 == 2) {
            return 25344;
        }
        switch (i2) {
            case 8:
            case 16:
            case 32:
                return 101376;
            case 64:
                return 202752;
            case 128:
            case 256:
                return 414720;
            case 512:
                return 921600;
            case 1024:
                return 1310720;
            case 2048:
            case 4096:
                return 2097152;
            case 8192:
                return 2228224;
            case 16384:
                return 5652480;
            case 32768:
                return 9437184;
            default:
                return -1;
        }
    }

    public static String b(MediaFormat mediaFormat, boolean z2) {
        if (b0.D.f2965a >= 24) {
            return new e(z2).f(mediaFormat);
        }
        return null;
    }

    public static String c(MediaFormat mediaFormat, boolean z2) {
        if (b0.D.f2965a >= 24) {
            return new e(z2).g(mediaFormat);
        }
        return null;
    }

    public static C0640f d(String str, boolean z2) {
        List listF = f(str, z2, false);
        if (listF.isEmpty()) {
            return null;
        }
        return (C0640f) listF.get(0);
    }

    public static C0640f e(String str, boolean z2, boolean z3) {
        List listF = f(str, z2, z3);
        if (listF.isEmpty()) {
            return null;
        }
        return (C0640f) listF.get(0);
    }

    public static synchronized List f(String str, boolean z2, boolean z3) {
        try {
            a aVar = new a(str, z2, z3);
            Map map = f5757b;
            List list = (List) map.get(aVar);
            if (list != null) {
                return list;
            }
            int i2 = b0.D.f2965a;
            List listG = g(aVar, i2 >= 21 ? new e(z2) : new d());
            if (z2 && listG.isEmpty() && 21 <= i2 && i2 <= 23) {
                listG = g(aVar, new d());
                if (!listG.isEmpty()) {
                    Log.w("MediaCodecUtil", "MediaCodecList API didn't list secure decoder for: " + str + ". Assuming: " + ((C0640f) listG.get(0)).f5519a);
                }
            }
            List listUnmodifiableList = Collections.unmodifiableList(listG);
            map.put(aVar, listUnmodifiableList);
            return listUnmodifiableList;
        } catch (Throwable th) {
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:47:0x00ba A[Catch: Exception -> 0x00b2, TryCatch #1 {Exception -> 0x00b2, blocks: (B:37:0x00a7, B:39:0x00ad, B:47:0x00ba, B:45:0x00b6, B:50:0x00c7), top: B:69:0x00a7 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static java.util.List g(n.u.a r18, n.u.c r19) throws n.u.b {
        /*
            Method dump skipped, instruction units count: 356
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: n.u.g(n.u$a, n.u$c):java.util.List");
    }

    public static C0640f h() {
        return f5756a;
    }

    private static MediaCodecInfo.VideoCapabilities i(String str, boolean z2) {
        C0640f c0640fD = d(str, z2);
        if (c0640fD == null) {
            return null;
        }
        return c0640fD.f5520b.getVideoCapabilities();
    }

    private static boolean j(MediaCodecInfo mediaCodecInfo, String str, boolean z2) {
        String str2;
        String str3;
        String str4;
        if (mediaCodecInfo.isEncoder() || (!z2 && str.endsWith(".secure"))) {
            return false;
        }
        int i2 = b0.D.f2965a;
        if (i2 < 21 && ("CIPAACDecoder".equals(str) || "CIPMP3Decoder".equals(str) || "CIPVorbisDecoder".equals(str) || "CIPAMRNBDecoder".equals(str) || "AACDecoder".equals(str) || "MP3Decoder".equals(str))) {
            return false;
        }
        if (i2 < 18 && "OMX.SEC.MP3.Decoder".equals(str)) {
            return false;
        }
        if (i2 < 18 && "OMX.MTK.AUDIO.DECODER.AAC".equals(str) && "a70".equals(b0.D.f2966b)) {
            return false;
        }
        if (i2 == 16 && (str4 = b0.D.f2966b) != null && "OMX.qcom.audio.decoder.mp3".equals(str) && ("dlxu".equals(str4) || "protou".equals(str4) || "ville".equals(str4) || "villeplus".equals(str4) || "villec2".equals(str4) || str4.startsWith("gee") || "C6602".equals(str4) || "C6603".equals(str4) || "C6606".equals(str4) || "C6616".equals(str4) || "L36h".equals(str4) || "SO-02E".equals(str4))) {
            return false;
        }
        if (i2 == 16 && "OMX.qcom.audio.decoder.aac".equals(str)) {
            String str5 = b0.D.f2966b;
            if ("C1504".equals(str5) || "C1505".equals(str5) || "C1604".equals(str5) || "C1605".equals(str5)) {
                return false;
            }
        }
        if (i2 > 19 || (str3 = b0.D.f2966b) == null || !((str3.startsWith("d2") || str3.startsWith("serrano") || str3.startsWith("jflte") || str3.startsWith("santos")) && "samsung".equals(b0.D.f2967c) && str.equals("OMX.SEC.vp8.dec"))) {
            return i2 > 19 || (str2 = b0.D.f2966b) == null || !str2.startsWith("jflte") || !"OMX.qcom.video.decoder.vp8".equals(str);
        }
        return false;
    }

    public static boolean k(String str, boolean z2, int i2, int i3, double d2) {
        AbstractC0399d.e(b0.D.f2965a >= 21);
        MediaCodecInfo.VideoCapabilities videoCapabilitiesI = i(str, z2);
        return videoCapabilitiesI != null && videoCapabilitiesI.areSizeAndRateSupported(i2, i3, d2);
    }

    public static boolean l(String str, boolean z2, int i2, int i3) {
        AbstractC0399d.e(b0.D.f2965a >= 21);
        MediaCodecInfo.VideoCapabilities videoCapabilitiesI = i(str, z2);
        return videoCapabilitiesI != null && videoCapabilitiesI.isSizeSupported(i2, i3);
    }

    public static int m() {
        if (f5758c == -1) {
            int iMax = 0;
            C0640f c0640fD = d("video/avc", false);
            if (c0640fD != null) {
                MediaCodecInfo.CodecProfileLevel[] codecProfileLevelArr = c0640fD.f5520b.profileLevels;
                int length = codecProfileLevelArr.length;
                int iMax2 = 0;
                while (iMax < length) {
                    iMax2 = Math.max(a(codecProfileLevelArr[iMax].level), iMax2);
                    iMax++;
                }
                iMax = Math.max(iMax2, 172800);
            }
            f5758c = iMax;
        }
        return f5758c;
    }
}
