package defpackage;

import androidx.media3.common.ParserException;
import java.math.RoundingMode;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: renamed from: ˌʥᵵ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1570 implements InterfaceC2750 {

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public int f6279;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final String f6280;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public int f6281;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public C5286 f6285;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public int f6287;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C4545 f6288;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public InterfaceC5226 f6289;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public long f6290;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final int f6291;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public int f6292;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public String f6293;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f6278 = 0;

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public long f6286 = -9223372036854775807L;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final AtomicInteger f6277 = new AtomicInteger();

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public int f6284 = -1;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public int f6282 = -1;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final String f6283 = "video/mp2t";

    public C1570(int i, int i2, String str) {
        this.f6288 = new C4545(new byte[i2]);
        this.f6280 = str;
        this.f6291 = i;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean m4410(C4545 c4545, byte[] bArr, int i) {
        int iMin = Math.min(c4545.m9623(), i - this.f6292);
        c4545.m9627(bArr, this.f6292, iMin);
        int i2 = this.f6292 + iMin;
        this.f6292 = i2;
        return i2 == i;
    }

    @Override // defpackage.InterfaceC2750
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final void mo2659() {
        this.f6278 = 0;
        this.f6292 = 0;
        this.f6287 = 0;
        this.f6286 = -9223372036854775807L;
        this.f6277.set(0);
    }

    @Override // defpackage.InterfaceC2750
    /* JADX INFO: renamed from: ᵨᵣ */
    public final void mo2660(long j, int i) {
        this.f6286 = j;
    }

    @Override // defpackage.InterfaceC2750
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo2661(C4545 c4545) throws ParserException {
        int i;
        byte b;
        int i2;
        byte b2;
        int i3;
        int i4;
        int iM7302;
        int iM73022;
        int iM73023;
        int i5;
        long jM3218;
        int i6;
        long jM32182;
        int i7;
        int i8;
        int i9;
        int i10;
        this.f6289.getClass();
        while (c4545.m9623() > 0) {
            int i11 = this.f6278;
            C4545 c45452 = this.f6288;
            switch (i11) {
                case 0:
                    while (true) {
                        if (c4545.m9623() > 0) {
                            int i12 = this.f6287 << 8;
                            this.f6287 = i12;
                            int iM9626 = i12 | c4545.m9626();
                            this.f6287 = iM9626;
                            int i13 = ᵸᵺᵜ.ᵱʡˏ(iM9626);
                            this.f6279 = i13;
                            if (i13 != 0) {
                                byte[] bArr = c45452.f17284;
                                int i14 = this.f6287;
                                bArr[0] = (byte) ((i14 >> 24) & 255);
                                bArr[1] = (byte) ((i14 >> 16) & 255);
                                bArr[2] = (byte) ((i14 >> 8) & 255);
                                bArr[3] = (byte) (i14 & 255);
                                this.f6292 = 4;
                                this.f6287 = 0;
                                if (i13 == 3 || i13 == 4) {
                                    this.f6278 = 4;
                                } else if (i13 == 1) {
                                    this.f6278 = 1;
                                } else {
                                    this.f6278 = 2;
                                }
                                break;
                            }
                        }
                    }
                    break;
                case 1:
                    if (m4410(c4545, c45452.f17284, 18)) {
                        byte[] bArr2 = c45452.f17284;
                        if (this.f6285 == null) {
                            String str = this.f6293;
                            C3180 c3180 = ᵸᵺᵜ.ˉᵲ(bArr2);
                            c3180.m7287(60);
                            int i15 = ᵸᵺᵜ.ᵲᵶᵳˈ[c3180.m7302(6)];
                            int i16 = ᵸᵺᵜ.ʽˈˋ[c3180.m7302(4)];
                            int iM73024 = c3180.m7302(5);
                            int i17 = iM73024 >= 29 ? -1 : (ᵸᵺᵜ.ːˏᵟᵯ[iM73024] * 1000) / 2;
                            c3180.m7287(10);
                            int i18 = i15 + (c3180.m7302(2) > 0 ? 1 : 0);
                            C4753 c4753 = new C4753();
                            c4753.f18121 = str;
                            c4753.f18111 = AbstractC4208.m9132(this.f6283);
                            c4753.f18101 = AbstractC4208.m9132("audio/vnd.dts");
                            c4753.f18099 = i17;
                            c4753.f18090 = i18;
                            c4753.f18113 = i16;
                            c4753.f18096 = null;
                            c4753.f18126 = this.f6280;
                            c4753.f18129 = this.f6291;
                            C5286 c5286 = new C5286(c4753);
                            this.f6285 = c5286;
                            this.f6289.mo1742(c5286);
                        }
                        this.f6281 = ᵸᵺᵜ.ᵪᵹᵥᵻ(bArr2);
                        byte b3 = bArr2[0];
                        if (b3 != -2) {
                            if (b3 == -1) {
                                i = (bArr2[4] & 7) << 4;
                                b2 = bArr2[7];
                            } else if (b3 != 31) {
                                i = (bArr2[4] & 1) << 6;
                                b = bArr2[5];
                            } else {
                                i = (bArr2[5] & 7) << 4;
                                b2 = bArr2[6];
                            }
                            i2 = b2 & 60;
                            this.f6290 = ᵝˉː.ᵷᵺʾᵖ(AbstractC0956.m3230((((i2 >> 2) | i) + 1) * 32, this.f6285.f19966));
                            c45452.m9624(0);
                            this.f6289.mo1740(18, c45452);
                            this.f6278 = 6;
                        } else {
                            i = (bArr2[5] & 1) << 6;
                            b = bArr2[4];
                        }
                        i2 = b & 252;
                        this.f6290 = ᵝˉː.ᵷᵺʾᵖ(AbstractC0956.m3230((((i2 >> 2) | i) + 1) * 32, this.f6285.f19966));
                        c45452.m9624(0);
                        this.f6289.mo1740(18, c45452);
                        this.f6278 = 6;
                        break;
                    }
                    break;
                case 2:
                    if (m4410(c4545, c45452.f17284, 7)) {
                        C3180 c31802 = ᵸᵺᵜ.ˉᵲ(c45452.f17284);
                        c31802.m7287(42);
                        this.f6284 = c31802.m7302(c31802.m7299() ? 12 : 8) + 1;
                        this.f6278 = 3;
                    }
                    break;
                case 3:
                    int i19 = 8;
                    if (m4410(c4545, c45452.f17284, this.f6284)) {
                        C3180 c31803 = ᵸᵺᵜ.ˉᵲ(c45452.f17284);
                        c31803.m7287(40);
                        int iM73025 = c31803.m7302(2);
                        if (c31803.m7299()) {
                            i3 = 20;
                            i4 = 12;
                        } else {
                            i3 = 16;
                            i4 = 8;
                        }
                        c31803.m7287(i4);
                        int iM73026 = c31803.m7302(i3) + 1;
                        boolean zM7299 = c31803.m7299();
                        if (zM7299) {
                            iM7302 = c31803.m7302(2);
                            iM73022 = (c31803.m7302(3) + 1) * 512;
                            if (c31803.m7299()) {
                                c31803.m7287(36);
                            }
                            int iM73027 = c31803.m7302(3) + 1;
                            int iM73028 = c31803.m7302(3) + 1;
                            if (iM73027 != 1 || iM73028 != 1) {
                                throw ParserException.m356("Multiple audio presentations or assets not supported");
                            }
                            int i20 = iM73025 + 1;
                            int iM73029 = c31803.m7302(i20);
                            int i21 = 0;
                            while (i21 < i20) {
                                if (((iM73029 >> i21) & 1) == 1) {
                                    c31803.m7287(i19);
                                }
                                i21++;
                                i19 = 8;
                            }
                            if (c31803.m7299()) {
                                c31803.m7287(2);
                                int iM730210 = (c31803.m7302(2) + 1) << 2;
                                int iM730211 = c31803.m7302(2) + 1;
                                for (int i22 = 0; i22 < iM730211; i22++) {
                                    c31803.m7287(iM730210);
                                }
                            }
                        } else {
                            iM7302 = -1;
                            iM73022 = 0;
                        }
                        c31803.m7287(i3);
                        c31803.m7287(12);
                        if (zM7299) {
                            if (c31803.m7299()) {
                                c31803.m7287(4);
                            }
                            if (c31803.m7299()) {
                                c31803.m7287(24);
                            }
                            if (c31803.m7299()) {
                                c31803.m7291(c31803.m7302(10) + 1);
                            }
                            c31803.m7287(5);
                            i5 = ᵸᵺᵜ.ᵷᵺʾᵖ[c31803.m7302(4)];
                            iM73023 = c31803.m7302(8) + 1;
                        } else {
                            iM73023 = -1;
                            i5 = -2147483647;
                        }
                        if (zM7299) {
                            if (iM7302 == 0) {
                                i6 = 32000;
                            } else if (iM7302 == 1) {
                                i6 = 44100;
                            } else {
                                if (iM7302 != 2) {
                                    throw ParserException.m357("Unsupported reference clock code in DTS HD header: " + iM7302, null);
                                }
                                i6 = 48000;
                            }
                            String str2 = AbstractC0956.f4222;
                            jM3218 = AbstractC0956.m3218(iM73022, 1000000L, i6, RoundingMode.DOWN);
                        } else {
                            jM3218 = -9223372036854775807L;
                        }
                        m4411(new C1260("audio/vnd.dts.hd;profile=lbr", iM73023, i5, iM73026, jM3218));
                        this.f6281 = iM73026;
                        this.f6290 = jM3218 == -9223372036854775807L ? 0L : jM3218;
                        c45452.m9624(0);
                        this.f6289.mo1740(this.f6284, c45452);
                        this.f6278 = 6;
                    } else {
                        continue;
                    }
                    break;
                case 4:
                    if (m4410(c4545, c45452.f17284, 6)) {
                        C3180 c31804 = ᵸᵺᵜ.ˉᵲ(c45452.f17284);
                        c31804.m7287(32);
                        int i23 = ᵸᵺᵜ.ᵸˆˁ(c31804, ᵸᵺᵜ.ᵻʽᵯ) + 1;
                        this.f6282 = i23;
                        int i24 = this.f6292;
                        if (i24 > i23) {
                            int i25 = i24 - i23;
                            this.f6292 = i24 - i25;
                            c4545.m9624(c4545.f17282 - i25);
                        }
                        this.f6278 = 5;
                    }
                    break;
                case 5:
                    if (m4410(c4545, c45452.f17284, this.f6282)) {
                        byte[] bArr3 = c45452.f17284;
                        C3180 c31805 = ᵸᵺᵜ.ˉᵲ(bArr3);
                        int i26 = c31805.m7302(32) == 1078008818 ? 1 : 0;
                        int i27 = ᵸᵺᵜ.ᵸˆˁ(c31805, ᵸᵺᵜ.ᵨᵣ);
                        int i28 = i27 + 1;
                        if (i26 == 0) {
                            jM32182 = -9223372036854775807L;
                            i7 = -2147483647;
                        } else {
                            if (!c31805.m7299()) {
                                throw ParserException.m356("Only supports full channel mask-based audio presentation");
                            }
                            int i29 = i27 - 1;
                            int i30 = ((bArr3[i29] << 8) & 65535) | (bArr3[i27] & 255);
                            String str3 = AbstractC0956.f4222;
                            int i31 = 65535;
                            for (int i32 = 0; i32 < i29; i32++) {
                                byte b4 = bArr3[i32];
                                int[] iArr = AbstractC0956.f4224;
                                int i33 = (iArr[(((b4 & 255) >> 4) ^ ((i31 >> 12) & 255)) & 255] ^ ((i31 << 4) & 65535)) & 65535;
                                i31 = (iArr[((b4 & 15) ^ ((i33 >> 12) & 255)) & 255] ^ ((i33 << 4) & 65535)) & 65535;
                            }
                            if (i30 != i31) {
                                throw ParserException.m357("CRC check failed", null);
                            }
                            int iM730212 = c31805.m7302(2);
                            if (iM730212 != 0) {
                                if (iM730212 == 1) {
                                    i9 = 480;
                                } else {
                                    if (iM730212 != 2) {
                                        throw ParserException.m357("Unsupported base duration index in DTS UHD header: " + iM730212, null);
                                    }
                                    i9 = 384;
                                }
                                i8 = 3;
                            } else {
                                i8 = 3;
                                i9 = 512;
                            }
                            int iM730213 = (c31805.m7302(i8) + 1) * i9;
                            int iM730214 = c31805.m7302(2);
                            if (iM730214 == 0) {
                                i10 = 32000;
                            } else if (iM730214 == 1) {
                                i10 = 44100;
                            } else {
                                if (iM730214 != 2) {
                                    throw ParserException.m357("Unsupported clock rate index in DTS UHD header: " + iM730214, null);
                                }
                                i10 = 48000;
                            }
                            if (c31805.m7299()) {
                                c31805.m7287(36);
                            }
                            int iM730215 = i10 * (1 << c31805.m7302(2));
                            jM32182 = AbstractC0956.m3218(iM730213, 1000000L, i10, RoundingMode.DOWN);
                            i7 = iM730215;
                        }
                        int i34 = 0;
                        for (int i35 = 0; i35 < i26; i35++) {
                            i34 += ᵸᵺᵜ.ᵸˆˁ(c31805, ᵸᵺᵜ.ᵻˈᵦʼ);
                        }
                        AtomicInteger atomicInteger = this.f6277;
                        if (i26 != 0) {
                            atomicInteger.set(ᵸᵺᵜ.ᵸˆˁ(c31805, ᵸᵺᵜ.ᵵᵽ));
                        }
                        int i36 = i34 + (atomicInteger.get() != 0 ? ᵸᵺᵜ.ᵸˆˁ(c31805, ᵸᵺᵜ.ˊᵫᵗ) : 0) + i28;
                        C1260 c1260 = new C1260("audio/vnd.dts.uhd;profile=p2", 2, i7, i36, jM32182);
                        if (this.f6279 == 3) {
                            m4411(c1260);
                        }
                        this.f6281 = i36;
                        this.f6290 = jM32182 == -9223372036854775807L ? 0L : jM32182;
                        c45452.m9624(0);
                        this.f6289.mo1740(this.f6282, c45452);
                        this.f6278 = 6;
                    } else {
                        continue;
                    }
                    break;
                case C5224.STRING_SET_FIELD_NUMBER /* 6 */:
                    int iMin = Math.min(c4545.m9623(), this.f6281 - this.f6292);
                    this.f6289.mo1740(iMin, c4545);
                    int i37 = this.f6292 + iMin;
                    this.f6292 = i37;
                    if (i37 == this.f6281) {
                        ᵻᵪ.ˌᴵ(this.f6286 != -9223372036854775807L);
                        this.f6289.mo1741(this.f6286, this.f6279 == 4 ? 0 : 1, this.f6281, 0, null);
                        this.f6286 += this.f6290;
                        this.f6278 = 0;
                    }
                    break;
                default:
                    ᵷᵝˎ.ᵱʡˏ();
                    return;
            }
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final void m4411(C1260 c1260) {
        int i = c1260.f5308;
        String str = c1260.f5307;
        int i2 = c1260.f5306;
        if (i == -2147483647 || i2 == -1) {
            return;
        }
        C5286 c5286 = this.f6285;
        if (c5286 != null && i2 == c5286.f19984 && i == c5286.f19966 && str.equals(c5286.f19987)) {
            return;
        }
        C5286 c52862 = this.f6285;
        C4753 c4753 = c52862 == null ? new C4753() : c52862.m10878();
        c4753.f18121 = this.f6293;
        c4753.f18111 = AbstractC4208.m9132(this.f6283);
        c4753.f18101 = AbstractC4208.m9132(str);
        c4753.f18090 = i2;
        c4753.f18113 = i;
        c4753.f18126 = this.f6280;
        c4753.f18129 = this.f6291;
        C5286 c52863 = new C5286(c4753);
        this.f6285 = c52863;
        this.f6289.mo1742(c52863);
    }

    @Override // defpackage.InterfaceC2750
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final void mo2662(boolean z) {
    }

    @Override // defpackage.InterfaceC2750
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final void mo2663(InterfaceC4550 interfaceC4550, C4173 c4173) {
        c4173.m9112();
        c4173.m9111();
        this.f6293 = c4173.f15926;
        c4173.m9111();
        this.f6289 = interfaceC4550.mo2743(c4173.f15928, 1);
    }
}
