package I0;

import B0.C0022i;
import C3.D;
import C3.G;
import C3.W;
import D0.AbstractC0064a;
import T0.H;
import a.AbstractC0386a;
import android.graphics.Point;
import android.media.MediaCodecInfo;
import android.os.Build;
import android.util.Pair;
import d5.AbstractC0844a;
import java.util.List;
import java.util.Objects;
import u0.C1570f;
import u0.C1579o;
import u0.E;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class q {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final MediaCodecInfo.CodecCapabilities f3237d;

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean f3241h;
    public final boolean i;

    public q(String str, String str2, String str3, MediaCodecInfo.CodecCapabilities codecCapabilities, boolean z8, boolean z9, boolean z10, boolean z11, boolean z12, boolean z13) {
        str.getClass();
        this.f3234a = str;
        this.f3235b = str2;
        this.f3236c = str3;
        this.f3237d = codecCapabilities;
        this.f3240g = z8;
        this.f3238e = z11;
        this.f3239f = z12;
        this.f3241h = z13;
        this.i = E.l(str2);
    }

    public static boolean a(MediaCodecInfo.VideoCapabilities videoCapabilities, int i, int i5, double d8) {
        int widthAlignment = videoCapabilities.getWidthAlignment();
        int heightAlignment = videoCapabilities.getHeightAlignment();
        Point point = new Point(x0.v.f(i, widthAlignment) * widthAlignment, x0.v.f(i5, heightAlignment) * heightAlignment);
        int i8 = point.x;
        int i9 = point.y;
        return (d8 == -1.0d || d8 < 1.0d) ? videoCapabilities.isSizeSupported(i8, i9) : videoCapabilities.areSizeAndRateSupported(i8, i9, Math.floor(d8));
    }

    /* JADX WARN: Removed duplicated region for block: B:18:0x0039  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x0080  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static q i(String str, String str2, String str3, MediaCodecInfo.CodecCapabilities codecCapabilities, boolean z8, boolean z9, boolean z10, boolean z11) {
        boolean z12;
        boolean z13;
        String str4;
        String str5;
        MediaCodecInfo.CodecCapabilities codecCapabilities2;
        boolean z14;
        boolean z15;
        boolean z16;
        String str6;
        if (codecCapabilities == null || !codecCapabilities.isFeatureSupported("adaptive-playback")) {
            z12 = false;
        } else {
            if (x0.v.f18553a <= 22) {
                String str7 = Build.MODEL;
                if (("ODROID-XU3".equals(str7) || "Nexus 10".equals(str7)) && ("OMX.Exynos.AVC.Decoder".equals(str) || "OMX.Exynos.AVC.Decoder.secure".equals(str))) {
                }
            }
            z12 = true;
        }
        if (codecCapabilities != null) {
            codecCapabilities.isFeatureSupported("tunneled-playback");
        }
        boolean z17 = z11 || (codecCapabilities != null && codecCapabilities.isFeatureSupported("secure-playback"));
        if (x0.v.f18553a < 35 || codecCapabilities == null || !codecCapabilities.isFeatureSupported("detached-surface")) {
            z13 = false;
            str4 = str2;
            str5 = str3;
            codecCapabilities2 = codecCapabilities;
            z14 = z8;
            z15 = z9;
            z16 = z10;
            str6 = str;
        } else {
            String str8 = Build.MANUFACTURER;
            if (!str8.equals("Xiaomi") && !str8.equals("OPPO")) {
                z13 = true;
                str6 = str;
                str5 = str3;
                codecCapabilities2 = codecCapabilities;
                z14 = z8;
                z15 = z9;
                z16 = z10;
                str4 = str2;
            }
        }
        return new q(str6, str4, str5, codecCapabilities2, z14, z15, z16, z12, z17, z13);
    }

    public final C0022i b(C1579o c1579o, C1579o c1579o2) {
        C1579o c1579o3;
        C1579o c1579o4;
        int i = !Objects.equals(c1579o.f17358n, c1579o2.f17358n) ? 8 : 0;
        if (this.i) {
            if (c1579o.f17368x != c1579o2.f17368x) {
                i |= 1024;
            }
            if (!this.f3238e && (c1579o.f17365u != c1579o2.f17365u || c1579o.f17366v != c1579o2.f17366v)) {
                i |= 512;
            }
            C1570f c1570f = c1579o.f17335B;
            boolean zE = C1570f.e(c1570f);
            C1570f c1570f2 = c1579o2.f17335B;
            if ((!zE || !C1570f.e(c1570f2)) && !Objects.equals(c1570f, c1570f2)) {
                i |= 2048;
            }
            if (Build.MODEL.startsWith("SM-T230") && "OMX.MARVELL.VIDEO.HW.CODA7542DECODER".equals(this.f3234a) && !c1579o.b(c1579o2)) {
                i |= 2;
            }
            if (i == 0) {
                return new C0022i(this.f3234a, c1579o, c1579o2, c1579o.b(c1579o2) ? 3 : 2, 0);
            }
            c1579o3 = c1579o;
            c1579o4 = c1579o2;
        } else {
            c1579o3 = c1579o;
            c1579o4 = c1579o2;
            if (c1579o3.D != c1579o4.D) {
                i |= 4096;
            }
            if (c1579o3.f17337E != c1579o4.f17337E) {
                i |= 8192;
            }
            if (c1579o3.f17338F != c1579o4.f17338F) {
                i |= 16384;
            }
            String str = this.f3235b;
            if (i == 0 && "audio/mp4a-latm".equals(str)) {
                Pair pairD = z.d(c1579o3);
                Pair pairD2 = z.d(c1579o4);
                if (pairD != null && pairD2 != null) {
                    int iIntValue = ((Integer) pairD.first).intValue();
                    int iIntValue2 = ((Integer) pairD2.first).intValue();
                    if (iIntValue == 42 && iIntValue2 == 42) {
                        return new C0022i(this.f3234a, c1579o3, c1579o4, 3, 0);
                    }
                }
            }
            if (!c1579o3.b(c1579o4)) {
                i |= 32;
            }
            if ("audio/opus".equals(str)) {
                i |= 2;
            }
            if (i == 0) {
                return new C0022i(this.f3234a, c1579o3, c1579o4, 1, 0);
            }
        }
        return new C0022i(this.f3234a, c1579o3, c1579o4, 0, i);
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x00e7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean c(C1579o c1579o, boolean z8) {
        MediaCodecInfo.CodecProfileLevel[] codecProfileLevelArr;
        MediaCodecInfo.VideoCapabilities videoCapabilities;
        Pair pair;
        String strA;
        Pair pairB;
        int i = 4;
        int i5 = 3;
        Pair pairD = z.d(c1579o);
        String str = this.f3236c;
        String str2 = c1579o.f17358n;
        if (str2 != null && str2.equals("video/mv-hevc")) {
            String strM = E.m(str);
            if (strM.equals("video/mv-hevc")) {
                return true;
            }
            if (strM.equals("video/hevc")) {
                List list = c1579o.f17361q;
                int i8 = 0;
                loop0: while (true) {
                    if (i8 >= list.size()) {
                        pair = null;
                        strA = null;
                        break;
                    }
                    byte[] bArr = (byte[]) list.get(i8);
                    int length = bArr.length;
                    if (length > i5) {
                        boolean[] zArr = new boolean[i5];
                        D dJ = G.j();
                        int i9 = 0;
                        while (i9 < bArr.length) {
                            int iC = y0.o.c(bArr, i9, bArr.length, zArr);
                            if (iC != bArr.length) {
                                dJ.a(Integer.valueOf(iC));
                            }
                            i9 = iC + i5;
                        }
                        W wG = dJ.g();
                        for (int i10 = 0; i10 < wG.f1227t; i10++) {
                            if (((Integer) wG.get(i10)).intValue() + i5 < length) {
                                H h8 = new H(bArr, ((Integer) wG.get(i10)).intValue() + i5, length);
                                R0.h hVarF = y0.o.f(h8);
                                if (hVarF.f5896a == 33 && hVarF.f5897b == 0) {
                                    h8.t(4);
                                    int i11 = h8.i(3);
                                    h8.s();
                                    pair = null;
                                    y0.h hVarG = y0.o.g(h8, true, i11, null);
                                    strA = x0.b.a(hVarG.f18824a, hVarG.f18825b, hVarG.f18826c, hVarG.f18827d, hVarG.f18828e, hVarG.f18829f);
                                    break loop0;
                                }
                                i5 = 3;
                            }
                        }
                    }
                    i8++;
                }
                if (strA == null) {
                    pairB = pair;
                } else {
                    String strTrim = strA.trim();
                    int i12 = x0.v.f18553a;
                    pairB = x0.b.b(strA, strTrim.split("\\.", -1), c1579o.f17335B);
                }
                pairD = pairB;
            }
        }
        if (pairD == null) {
            return true;
        }
        int iIntValue = ((Integer) pairD.first).intValue();
        int iIntValue2 = ((Integer) pairD.second).intValue();
        boolean zEquals = "video/dolby-vision".equals(str2);
        String str3 = this.f3235b;
        if (zEquals) {
            str3.getClass();
            switch (str3) {
                case "video/av01":
                case "video/hevc":
                    iIntValue = 2;
                    break;
                case "video/avc":
                    iIntValue = 8;
                    break;
            }
            iIntValue2 = 0;
        }
        if (!this.i && iIntValue != 42) {
            return true;
        }
        MediaCodecInfo.CodecCapabilities codecCapabilities = this.f3237d;
        if (codecCapabilities == null || (codecProfileLevelArr = codecCapabilities.profileLevels) == null) {
            codecProfileLevelArr = new MediaCodecInfo.CodecProfileLevel[0];
        }
        if (x0.v.f18553a <= 23 && "video/x-vnd.on2.vp9".equals(str3) && codecProfileLevelArr.length == 0) {
            int iIntValue3 = (codecCapabilities == null || (videoCapabilities = codecCapabilities.getVideoCapabilities()) == null) ? 0 : ((Integer) videoCapabilities.getBitrateRange().getUpper()).intValue();
            if (iIntValue3 >= 180000000) {
                i = 1024;
            } else if (iIntValue3 >= 120000000) {
                i = 512;
            } else if (iIntValue3 >= 60000000) {
                i = 256;
            } else if (iIntValue3 >= 30000000) {
                i = 128;
            } else if (iIntValue3 >= 18000000) {
                i = 64;
            } else if (iIntValue3 >= 12000000) {
                i = 32;
            } else if (iIntValue3 >= 7200000) {
                i = 16;
            } else if (iIntValue3 >= 3600000) {
                i = 8;
            } else if (iIntValue3 < 1800000) {
                i = iIntValue3 >= 800000 ? 2 : 1;
            }
            MediaCodecInfo.CodecProfileLevel codecProfileLevel = new MediaCodecInfo.CodecProfileLevel();
            codecProfileLevel.profile = 1;
            codecProfileLevel.level = i;
            codecProfileLevelArr = new MediaCodecInfo.CodecProfileLevel[]{codecProfileLevel};
        }
        for (MediaCodecInfo.CodecProfileLevel codecProfileLevel2 : codecProfileLevelArr) {
            if (codecProfileLevel2.profile == iIntValue && (codecProfileLevel2.level >= iIntValue2 || !z8)) {
                if (!"video/hevc".equals(str3) || 2 != iIntValue) {
                    return true;
                }
                String str4 = Build.DEVICE;
                if (!"sailfish".equals(str4) && !"marlin".equals(str4)) {
                    return true;
                }
            }
        }
        h("codec.profileLevel, " + c1579o.f17355k + ", " + str);
        return false;
    }

    public final boolean d(C1579o c1579o) {
        return (Objects.equals(c1579o.f17358n, "audio/flac") && c1579o.f17338F == 22 && x0.v.f18553a < 34 && this.f3234a.equals("c2.android.flac.decoder")) ? false : true;
    }

    public final boolean e(C1579o c1579o) {
        int i;
        String str = c1579o.f17358n;
        String str2 = this.f3235b;
        if (!(str2.equals(str) || str2.equals(z.b(c1579o))) || !c(c1579o, true) || !d(c1579o)) {
            return false;
        }
        if (this.i) {
            int i5 = c1579o.f17365u;
            if (i5 > 0 && (i = c1579o.f17366v) > 0) {
                return g(i5, i, c1579o.f17367w);
            }
        } else {
            MediaCodecInfo.CodecCapabilities codecCapabilities = this.f3237d;
            int i8 = c1579o.f17337E;
            if (i8 != -1) {
                if (codecCapabilities == null) {
                    h("sampleRate.caps");
                    return false;
                }
                MediaCodecInfo.AudioCapabilities audioCapabilities = codecCapabilities.getAudioCapabilities();
                if (audioCapabilities == null) {
                    h("sampleRate.aCaps");
                    return false;
                }
                if (!audioCapabilities.isSampleRateSupported(i8)) {
                    h("sampleRate.support, " + i8);
                    return false;
                }
            }
            int i9 = c1579o.D;
            if (i9 != -1) {
                if (codecCapabilities == null) {
                    h("channelCount.caps");
                    return false;
                }
                MediaCodecInfo.AudioCapabilities audioCapabilities2 = codecCapabilities.getAudioCapabilities();
                if (audioCapabilities2 == null) {
                    h("channelCount.aCaps");
                    return false;
                }
                int maxInputChannelCount = audioCapabilities2.getMaxInputChannelCount();
                if (maxInputChannelCount <= 1 && ((x0.v.f18553a < 26 || maxInputChannelCount <= 0) && !"audio/mpeg".equals(str2) && !"audio/3gpp".equals(str2) && !"audio/amr-wb".equals(str2) && !"audio/mp4a-latm".equals(str2) && !"audio/vorbis".equals(str2) && !"audio/opus".equals(str2) && !"audio/raw".equals(str2) && !"audio/flac".equals(str2) && !"audio/g711-alaw".equals(str2) && !"audio/g711-mlaw".equals(str2) && !"audio/gsm".equals(str2))) {
                    int i10 = "audio/ac3".equals(str2) ? 6 : "audio/eac3".equals(str2) ? 16 : 30;
                    AbstractC1709a.B("MediaCodecInfo", "AssumedMaxChannelAdjustment: " + this.f3234a + ", [" + maxInputChannelCount + " to " + i10 + "]");
                    maxInputChannelCount = i10;
                }
                if (maxInputChannelCount < i9) {
                    h("channelCount.support, " + i9);
                    return false;
                }
            }
        }
        return true;
    }

    public final boolean f(C1579o c1579o) {
        if (this.i) {
            return this.f3238e;
        }
        Pair pairD = z.d(c1579o);
        return pairD != null && ((Integer) pairD.first).intValue() == 42;
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x006b  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x008b  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0090  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00b6  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean g(int i, int i5, double d8) {
        char c3;
        Boolean bool;
        List supportedPerformancePoints;
        boolean z8;
        MediaCodecInfo.CodecCapabilities codecCapabilities = this.f3237d;
        if (codecCapabilities == null) {
            h("sizeAndRate.caps");
            return false;
        }
        MediaCodecInfo.VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
        if (videoCapabilities == null) {
            h("sizeAndRate.vCaps");
            return false;
        }
        int i8 = x0.v.f18553a;
        if (i8 < 29) {
            if (!a(videoCapabilities, i, i5, d8)) {
                if (i < i5) {
                    String str = this.f3234a;
                    if ((!"OMX.MTK.VIDEO.DECODER.HEVC".equals(str) || !"mcv5a".equals(Build.DEVICE)) && a(videoCapabilities, i5, i, d8)) {
                        AbstractC1709a.n("MediaCodecInfo", "AssumedSupport [" + ("sizeAndRate.rotated, " + i + "x" + i5 + "@" + d8) + "] [" + str + ", " + this.f3235b + "] [" + x0.v.f18554b + "]");
                        return true;
                    }
                }
                h("sizeAndRate.support, " + i + "x" + i5 + "@" + d8);
                return false;
            }
        } else if (i8 < 29 || (((bool = android.support.v4.media.session.a.f7712b) != null && bool.booleanValue()) || (supportedPerformancePoints = videoCapabilities.getSupportedPerformancePoints()) == null || supportedPerformancePoints.isEmpty())) {
            c3 = 0;
            if (c3 != 2) {
                if (c3 == 1) {
                    h("sizeAndRate.cover, " + i + "x" + i5 + "@" + d8);
                    return false;
                }
                if (!a(videoCapabilities, i, i5, d8)) {
                }
            }
        } else {
            AbstractC0064a.k();
            MediaCodecInfo.VideoCapabilities.PerformancePoint performancePointC = AbstractC0064a.c(i, i5, (int) d8);
            int i9 = 0;
            while (true) {
                if (i9 >= supportedPerformancePoints.size()) {
                    c3 = 1;
                    break;
                }
                if (AbstractC0064a.d(supportedPerformancePoints.get(i9)).covers(performancePointC)) {
                    c3 = 2;
                    break;
                }
                i9++;
            }
            if (c3 == 1 && android.support.v4.media.session.a.f7712b == null) {
                if (i8 >= 35) {
                    z8 = false;
                    android.support.v4.media.session.a.f7712b = Boolean.valueOf(z8);
                    if (z8) {
                    }
                } else {
                    int iL = AbstractC0386a.l(false);
                    int iL2 = AbstractC0386a.l(true);
                    if (iL == 0 || (iL2 != 0 ? iL != 2 || iL2 != 2 : iL != 2)) {
                        z8 = true;
                    }
                    android.support.v4.media.session.a.f7712b = Boolean.valueOf(z8);
                    if (z8) {
                    }
                }
            }
            if (c3 != 2) {
            }
        }
        return true;
    }

    public final void h(String str) {
        StringBuilder sbP = AbstractC0844a.p("NoSupport [", str, "] [");
        sbP.append(this.f3234a);
        sbP.append(", ");
        sbP.append(this.f3235b);
        sbP.append("] [");
        sbP.append(x0.v.f18554b);
        sbP.append("]");
        AbstractC1709a.n("MediaCodecInfo", sbP.toString());
    }

    public final String toString() {
        return this.f3234a;
    }
}
