package u0;

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Pattern f17153b = Pattern.compile("^mp4a\\.([a-zA-Z0-9]{2})(?:\\.([0-9]{1,2}))?$");

    public static boolean a(String str, String str2) {
        A7.a aVarF;
        int iC;
        if (str == null) {
            return false;
        }
        switch (str) {
            case "audio/mp4a-latm":
                if (str2 != null && (aVarF = f(str2)) != null && (iC = aVarF.c()) != 0 && iC != 16) {
                }
                break;
        }
        return false;
    }

    public static String b(String str, String str2) {
        if (str != null && str2 != null) {
            String[] strArrV = x0.v.V(str);
            StringBuilder sb = new StringBuilder();
            for (String str3 : strArrV) {
                if (str2.equals(d(str3))) {
                    if (sb.length() > 0) {
                        sb.append(",");
                    }
                    sb.append(str3);
                }
            }
            if (sb.length() > 0) {
                return sb.toString();
            }
        }
        return null;
    }

    public static int c(String str, String str2) {
        A7.a aVarF;
        str.getClass();
        switch (str) {
            case "audio/eac3-joc":
                return 18;
            case "audio/vnd.dts.hd;profile=lbr":
                return 8;
            case "audio/vnd.dts":
                return 7;
            case "audio/mp4a-latm":
                if (str2 == null || (aVarF = f(str2)) == null) {
                    return 0;
                }
                return aVarF.c();
            case "audio/ac3":
                return 5;
            case "audio/ac4":
                return 17;
            case "audio/vnd.dts.uhd;profile=p2":
                return 30;
            case "audio/eac3":
                return 6;
            case "audio/mpeg":
                return 9;
            case "audio/opus":
                return 20;
            case "audio/vnd.dts.hd":
                return 8;
            case "audio/true-hd":
                return 14;
            default:
                return 0;
        }
    }

    public static String d(String str) {
        A7.a aVarF;
        String strE = null;
        if (str != null) {
            String strF = s7.d.F(str.trim());
            if (strF.startsWith("avc1") || strF.startsWith("avc3")) {
                return "video/avc";
            }
            if (strF.startsWith("hev1") || strF.startsWith("hvc1")) {
                return "video/hevc";
            }
            if (strF.startsWith("dvav") || strF.startsWith("dva1") || strF.startsWith("dvhe") || strF.startsWith("dvh1")) {
                return "video/dolby-vision";
            }
            if (strF.startsWith("av01")) {
                return "video/av01";
            }
            if (strF.startsWith("vp9") || strF.startsWith("vp09")) {
                return "video/x-vnd.on2.vp9";
            }
            if (strF.startsWith("vp8") || strF.startsWith("vp08")) {
                return "video/x-vnd.on2.vp8";
            }
            if (strF.startsWith("mp4a")) {
                if (strF.startsWith("mp4a.") && (aVarF = f(strF)) != null) {
                    strE = e(aVarF.f460a);
                }
                return strE == null ? "audio/mp4a-latm" : strE;
            }
            if (strF.startsWith("mha1")) {
                return "audio/mha1";
            }
            if (strF.startsWith("mhm1")) {
                return "audio/mhm1";
            }
            if (strF.startsWith("ac-3") || strF.startsWith("dac3")) {
                return "audio/ac3";
            }
            if (strF.startsWith("ec-3") || strF.startsWith("dec3")) {
                return "audio/eac3";
            }
            if (strF.startsWith("ec+3")) {
                return "audio/eac3-joc";
            }
            if (strF.startsWith("ac-4") || strF.startsWith("dac4")) {
                return "audio/ac4";
            }
            if (strF.startsWith("dtsc")) {
                return "audio/vnd.dts";
            }
            if (strF.startsWith("dtse")) {
                return "audio/vnd.dts.hd;profile=lbr";
            }
            if (strF.startsWith("dtsh") || strF.startsWith("dtsl")) {
                return "audio/vnd.dts.hd";
            }
            if (strF.startsWith("dtsx")) {
                return "audio/vnd.dts.uhd;profile=p2";
            }
            if (strF.startsWith("opus")) {
                return "audio/opus";
            }
            if (strF.startsWith("vorbis")) {
                return "audio/vorbis";
            }
            if (strF.startsWith("flac")) {
                return "audio/flac";
            }
            if (strF.startsWith("stpp")) {
                return "application/ttml+xml";
            }
            if (strF.startsWith("wvtt")) {
                return "text/vtt";
            }
            if (strF.contains("cea708")) {
                return "application/cea-708";
            }
            if (strF.contains("eia608") || strF.contains("cea608")) {
                return "application/cea-608";
            }
            ArrayList arrayList = f17152a;
            if (arrayList.size() > 0) {
                arrayList.get(0).getClass();
                throw new ClassCastException();
            }
        }
        return null;
    }

    public static String e(int i) {
        if (i == 32) {
            return "video/mp4v-es";
        }
        if (i == 33) {
            return "video/avc";
        }
        if (i == 35) {
            return "video/hevc";
        }
        if (i == 64) {
            return "audio/mp4a-latm";
        }
        if (i == 163) {
            return "video/wvc1";
        }
        if (i == 177) {
            return "video/x-vnd.on2.vp9";
        }
        if (i == 221) {
            return "audio/vorbis";
        }
        if (i == 165) {
            return "audio/ac3";
        }
        if (i == 166) {
            return "audio/eac3";
        }
        switch (i) {
            case 96:
            case 97:
            case 98:
            case 99:
            case 100:
            case 101:
                return "video/mpeg2";
            case 102:
            case 103:
            case 104:
                return "audio/mp4a-latm";
            case 105:
            case 107:
                return "audio/mpeg";
            case 106:
                return "video/mpeg";
            case 108:
                return "image/jpeg";
            default:
                switch (i) {
                    case 169:
                    case 172:
                        return "audio/vnd.dts";
                    case 170:
                    case 171:
                        return "audio/vnd.dts.hd";
                    case 173:
                        return "audio/opus";
                    case 174:
                        return "audio/ac4";
                    default:
                        return null;
                }
        }
    }

    public static A7.a f(String str) {
        Matcher matcher = f17153b.matcher(str);
        if (!matcher.matches()) {
            return null;
        }
        String strGroup = matcher.group(1);
        strGroup.getClass();
        String strGroup2 = matcher.group(2);
        try {
            return new A7.a(Integer.parseInt(strGroup, 16), strGroup2 != null ? Integer.parseInt(strGroup2) : 0, false);
        } catch (NumberFormatException unused) {
            return null;
        }
    }

    public static String g(String str) {
        int iIndexOf;
        if (str == null || (iIndexOf = str.indexOf(47)) == -1) {
            return null;
        }
        return str.substring(0, iIndexOf);
    }

    public static int h(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        if (i(str)) {
            return 1;
        }
        if (l(str)) {
            return 2;
        }
        if (k(str)) {
            return 3;
        }
        if (j(str)) {
            return 4;
        }
        if ("application/id3".equals(str) || "application/x-emsg".equals(str) || "application/x-scte35".equals(str) || "application/x-icy".equals(str) || "application/vnd.dvb.ait".equals(str)) {
            return 5;
        }
        if ("application/x-camera-motion".equals(str)) {
            return 6;
        }
        ArrayList arrayList = f17152a;
        if (arrayList.size() <= 0) {
            return -1;
        }
        arrayList.get(0).getClass();
        throw new ClassCastException();
    }

    public static boolean i(String str) {
        return "audio".equals(g(str));
    }

    public static boolean j(String str) {
        return "image".equals(g(str)) || "application/x-image-uri".equals(str);
    }

    public static boolean k(String str) {
        return "text".equals(g(str)) || "application/x-media3-cues".equals(str) || "application/cea-608".equals(str) || "application/cea-708".equals(str) || "application/x-mp4-cea-608".equals(str) || "application/x-subrip".equals(str) || "application/ttml+xml".equals(str) || "application/x-quicktime-tx3g".equals(str) || "application/x-mp4-vtt".equals(str) || "application/x-rawcc".equals(str) || "application/vobsub".equals(str) || "application/pgs".equals(str) || "application/dvbsubs".equals(str);
    }

    public static boolean l(String str) {
        return "video".equals(g(str));
    }

    public static String m(String str) {
        String strF;
        if (str == null) {
            return null;
        }
        strF = s7.d.F(str);
        strF.getClass();
        switch (strF) {
            case "video/x-mvhevc":
                return "video/mv-hevc";
            case "audio/x-flac":
                return "audio/flac";
            case "application/x-mpegurl":
                return "application/x-mpegURL";
            case "audio/x-wav":
                return "audio/wav";
            case "audio/mpeg-l1":
                return "audio/mpeg-L1";
            case "audio/mpeg-l2":
                return "audio/mpeg-L2";
            case "audio/mp3":
                return "audio/mpeg";
            default:
                return strF;
        }
    }
}
