package defpackage;

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

/* renamed from: ᵯˏᵽ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4271 implements InterfaceC4315 {

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public C3446 f16022;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public InterfaceC2154 f16023;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public String f16024;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final String f16025;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public int f16026;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C3493 f16028;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public int f16029;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public int f16030;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public int f16033;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public long f16034;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final int f16036;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int f16035 = 0;

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public long f16027 = -9223372036854775807L;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final AtomicInteger f16032 = new AtomicInteger();

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public int f16031 = -1;

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public int f16021 = -1;

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final String f16020 = "video/mp2t";

    public C4271(int i, int i2, String str) {
        this.f16028 = new C3493(new byte[i2]);
        this.f16025 = str;
        this.f16036 = i;
    }

    @Override // defpackage.InterfaceC4315
    /* renamed from: ˇʼʤˎ */
    public final void mo1771(long j, int i) {
        this.f16027 = j;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final void m9244(C5092 c5092) {
        int i = c5092.f19027;
        String str = c5092.f19026;
        int i2 = c5092.f19028;
        if (i == -2147483647 || i2 == -1) {
            return;
        }
        C3446 c3446 = this.f16022;
        if (c3446 != null && i2 == c3446.f12923 && i == c3446.f12936 && str.equals(c3446.f12929)) {
            return;
        }
        C3446 c34462 = this.f16022;
        C2153 c2153 = c34462 == null ? new C2153() : c34462.m7829();
        c2153.f8512 = this.f16024;
        c2153.f8518 = AbstractC2924.m7101(this.f16020);
        c2153.f8516 = AbstractC2924.m7101(str);
        c2153.f8517 = i2;
        c2153.f8513 = i;
        c2153.f8527 = this.f16025;
        c2153.f8497 = this.f16036;
        C3446 c34463 = new C3446(c2153);
        this.f16022 = c34463;
        this.f16023.mo4407(c34463);
    }

    @Override // defpackage.InterfaceC4315
    /* renamed from: ˏˋٴ */
    public final void mo1772(InterfaceC1982 interfaceC1982, C4996 c4996) {
        c4996.m10451();
        c4996.m10452();
        this.f16024 = c4996.f18544;
        c4996.m10452();
        this.f16023 = interfaceC1982.mo4996(c4996.f18548, 1);
    }

    @Override // defpackage.InterfaceC4315
    /* renamed from: ˏᵙ */
    public final void mo1773() {
        this.f16035 = 0;
        this.f16026 = 0;
        this.f16033 = 0;
        this.f16027 = -9223372036854775807L;
        this.f16032.set(0);
    }

    @Override // defpackage.InterfaceC4315
    /* renamed from: ᵥᵯˎ */
    public final void mo1774(C3493 c3493) throws ParserException {
        int i;
        byte b;
        int i2;
        byte b2;
        int i3;
        int i4;
        int iM8966;
        int iM89662;
        int iM89663;
        int i5;
        long jM8115;
        int i6;
        long jM81152;
        int i7;
        int i8;
        int i9;
        int i10;
        this.f16023.getClass();
        while (c3493.m7959() > 0) {
            int i11 = this.f16035;
            C3493 c34932 = this.f16028;
            switch (i11) {
                case 0:
                    while (true) {
                        if (c3493.m7959() > 0) {
                            int i12 = this.f16033 << 8;
                            this.f16033 = i12;
                            int iM7956 = i12 | c3493.m7956();
                            this.f16033 = iM7956;
                            int i13 = ᵯˉˋ.ᵡʠ(iM7956);
                            this.f16029 = i13;
                            if (i13 != 0) {
                                byte[] bArr = c34932.f13082;
                                int i14 = this.f16033;
                                bArr[0] = (byte) ((i14 >> 24) & 255);
                                bArr[1] = (byte) ((i14 >> 16) & 255);
                                bArr[2] = (byte) ((i14 >> 8) & 255);
                                bArr[3] = (byte) (i14 & 255);
                                this.f16026 = 4;
                                this.f16033 = 0;
                                if (i13 != 3 && i13 != 4) {
                                    if (i13 == 1) {
                                        this.f16035 = 1;
                                        break;
                                    } else {
                                        this.f16035 = 2;
                                        break;
                                    }
                                } else {
                                    this.f16035 = 4;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case 1:
                    if (!m9245(c3493, c34932.f13082, 18)) {
                        break;
                    } else {
                        byte[] bArr2 = c34932.f13082;
                        if (this.f16022 == null) {
                            String str = this.f16024;
                            C4089 c4089 = ᵯˉˋ.ˑᵱ(bArr2);
                            c4089.m8956(60);
                            int i15 = ᵯˉˋ.ᵥᵯˎ[c4089.m8966(6)];
                            int i16 = ᵯˉˋ.ᵴᵳ[c4089.m8966(4)];
                            int iM89664 = c4089.m8966(5);
                            int i17 = iM89664 >= 29 ? -1 : (ᵯˉˋ.ˏᵙ[iM89664] * 1000) / 2;
                            c4089.m8956(10);
                            int i18 = i15 + (c4089.m8966(2) > 0 ? 1 : 0);
                            C2153 c2153 = new C2153();
                            c2153.f8512 = str;
                            c2153.f8518 = AbstractC2924.m7101(this.f16020);
                            c2153.f8516 = AbstractC2924.m7101("audio/vnd.dts");
                            c2153.f8525 = i17;
                            c2153.f8517 = i18;
                            c2153.f8513 = i16;
                            c2153.f8523 = null;
                            c2153.f8527 = this.f16025;
                            c2153.f8497 = this.f16036;
                            C3446 c3446 = new C3446(c2153);
                            this.f16022 = c3446;
                            this.f16023.mo4407(c3446);
                        }
                        this.f16030 = ᵯˉˋ.ᵳٴᵶ(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.f16034 = ˁˈᵸ.ˎˏʜʾ(AbstractC3558.m8110((((i2 >> 2) | i) + 1) * 32, this.f16022.f12936));
                            c34932.m7955(0);
                            this.f16023.mo4406(18, c34932);
                            this.f16035 = 6;
                            break;
                        } else {
                            i = (bArr2[5] & 1) << 6;
                            b = bArr2[4];
                        }
                        i2 = b & 252;
                        this.f16034 = ˁˈᵸ.ˎˏʜʾ(AbstractC3558.m8110((((i2 >> 2) | i) + 1) * 32, this.f16022.f12936));
                        c34932.m7955(0);
                        this.f16023.mo4406(18, c34932);
                        this.f16035 = 6;
                    }
                case 2:
                    if (m9245(c3493, c34932.f13082, 7)) {
                        C4089 c40892 = ᵯˉˋ.ˑᵱ(c34932.f13082);
                        c40892.m8956(42);
                        this.f16031 = c40892.m8966(c40892.m8964() ? 12 : 8) + 1;
                        this.f16035 = 3;
                        break;
                    } else {
                        break;
                    }
                case 3:
                    int i19 = 8;
                    if (m9245(c3493, c34932.f13082, this.f16031)) {
                        C4089 c40893 = ᵯˉˋ.ˑᵱ(c34932.f13082);
                        c40893.m8956(40);
                        int iM89665 = c40893.m8966(2);
                        if (c40893.m8964()) {
                            i3 = 20;
                            i4 = 12;
                        } else {
                            i3 = 16;
                            i4 = 8;
                        }
                        c40893.m8956(i4);
                        int iM89666 = c40893.m8966(i3) + 1;
                        boolean zM8964 = c40893.m8964();
                        if (zM8964) {
                            iM8966 = c40893.m8966(2);
                            iM89662 = (c40893.m8966(3) + 1) * 512;
                            if (c40893.m8964()) {
                                c40893.m8956(36);
                            }
                            int iM89667 = c40893.m8966(3) + 1;
                            int iM89668 = c40893.m8966(3) + 1;
                            if (iM89667 != 1 || iM89668 != 1) {
                                throw ParserException.m355("Multiple audio presentations or assets not supported");
                            }
                            int i20 = iM89665 + 1;
                            int iM89669 = c40893.m8966(i20);
                            int i21 = 0;
                            while (i21 < i20) {
                                if (((iM89669 >> i21) & 1) == 1) {
                                    c40893.m8956(i19);
                                }
                                i21++;
                                i19 = 8;
                            }
                            if (c40893.m8964()) {
                                c40893.m8956(2);
                                int iM896610 = (c40893.m8966(2) + 1) << 2;
                                int iM896611 = c40893.m8966(2) + 1;
                                for (int i22 = 0; i22 < iM896611; i22++) {
                                    c40893.m8956(iM896610);
                                }
                            }
                        } else {
                            iM8966 = -1;
                            iM89662 = 0;
                        }
                        c40893.m8956(i3);
                        c40893.m8956(12);
                        if (zM8964) {
                            if (c40893.m8964()) {
                                c40893.m8956(4);
                            }
                            if (c40893.m8964()) {
                                c40893.m8956(24);
                            }
                            if (c40893.m8964()) {
                                c40893.m8959(c40893.m8966(10) + 1);
                            }
                            c40893.m8956(5);
                            i5 = ᵯˉˋ.ᵻᵢﹳᵰ[c40893.m8966(4)];
                            iM89663 = c40893.m8966(8) + 1;
                        } else {
                            iM89663 = -1;
                            i5 = -2147483647;
                        }
                        if (zM8964) {
                            if (iM8966 == 0) {
                                i6 = 32000;
                            } else if (iM8966 == 1) {
                                i6 = 44100;
                            } else {
                                if (iM8966 != 2) {
                                    throw ParserException.m356("Unsupported reference clock code in DTS HD header: " + iM8966, null);
                                }
                                i6 = 48000;
                            }
                            String str2 = AbstractC3558.f13329;
                            jM8115 = AbstractC3558.m8115(iM89662, 1000000L, i6, RoundingMode.DOWN);
                        } else {
                            jM8115 = -9223372036854775807L;
                        }
                        m9244(new C5092("audio/vnd.dts.hd;profile=lbr", iM89663, i5, iM89666, jM8115));
                        this.f16030 = iM89666;
                        this.f16034 = jM8115 == -9223372036854775807L ? 0L : jM8115;
                        c34932.m7955(0);
                        this.f16023.mo4406(this.f16031, c34932);
                        this.f16035 = 6;
                        break;
                    } else {
                        continue;
                    }
                    break;
                case 4:
                    if (m9245(c3493, c34932.f13082, 6)) {
                        C4089 c40894 = ᵯˉˋ.ˑᵱ(c34932.f13082);
                        c40894.m8956(32);
                        int i23 = ᵯˉˋ.ˑᵥˁ(c40894, ᵯˉˋ.ᵝᵵᵺ) + 1;
                        this.f16021 = i23;
                        int i24 = this.f16026;
                        if (i24 > i23) {
                            int i25 = i24 - i23;
                            this.f16026 = i24 - i25;
                            c3493.m7955(c3493.f13083 - i25);
                        }
                        this.f16035 = 5;
                        break;
                    } else {
                        break;
                    }
                case 5:
                    if (m9245(c3493, c34932.f13082, this.f16021)) {
                        byte[] bArr3 = c34932.f13082;
                        C4089 c40895 = ᵯˉˋ.ˑᵱ(bArr3);
                        int i26 = c40895.m8966(32) == 1078008818 ? 1 : 0;
                        int i27 = ᵯˉˋ.ˑᵥˁ(c40895, ᵯˉˋ.ˇʼʤˎ);
                        int i28 = i27 + 1;
                        if (i26 == 0) {
                            jM81152 = -9223372036854775807L;
                            i7 = -2147483647;
                        } else {
                            if (!c40895.m8964()) {
                                throw ParserException.m355("Only supports full channel mask-based audio presentation");
                            }
                            int i29 = i27 - 1;
                            int i30 = ((bArr3[i29] << 8) & 65535) | (bArr3[i27] & 255);
                            String str3 = AbstractC3558.f13329;
                            int i31 = 65535;
                            for (int i32 = 0; i32 < i29; i32++) {
                                byte b4 = bArr3[i32];
                                int[] iArr = AbstractC3558.f13332;
                                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.m356("CRC check failed", null);
                            }
                            int iM896612 = c40895.m8966(2);
                            if (iM896612 != 0) {
                                if (iM896612 == 1) {
                                    i9 = 480;
                                } else {
                                    if (iM896612 != 2) {
                                        throw ParserException.m356("Unsupported base duration index in DTS UHD header: " + iM896612, null);
                                    }
                                    i9 = 384;
                                }
                                i8 = 3;
                            } else {
                                i8 = 3;
                                i9 = 512;
                            }
                            int iM896613 = (c40895.m8966(i8) + 1) * i9;
                            int iM896614 = c40895.m8966(2);
                            if (iM896614 == 0) {
                                i10 = 32000;
                            } else if (iM896614 == 1) {
                                i10 = 44100;
                            } else {
                                if (iM896614 != 2) {
                                    throw ParserException.m356("Unsupported clock rate index in DTS UHD header: " + iM896614, null);
                                }
                                i10 = 48000;
                            }
                            if (c40895.m8964()) {
                                c40895.m8956(36);
                            }
                            int iM896615 = i10 * (1 << c40895.m8966(2));
                            jM81152 = AbstractC3558.m8115(iM896613, 1000000L, i10, RoundingMode.DOWN);
                            i7 = iM896615;
                        }
                        int i34 = 0;
                        for (int i35 = 0; i35 < i26; i35++) {
                            i34 += ᵯˉˋ.ˑᵥˁ(c40895, ᵯˉˋ.ˏˋٴ);
                        }
                        AtomicInteger atomicInteger = this.f16032;
                        if (i26 != 0) {
                            atomicInteger.set(ᵯˉˋ.ˑᵥˁ(c40895, ᵯˉˋ.ˎˏʜʾ));
                        }
                        int i36 = i34 + (atomicInteger.get() != 0 ? ᵯˉˋ.ˑᵥˁ(c40895, ᵯˉˋ.ᵹᵝᵶ) : 0) + i28;
                        C5092 c5092 = new C5092("audio/vnd.dts.uhd;profile=p2", 2, i7, i36, jM81152);
                        if (this.f16029 == 3) {
                            m9244(c5092);
                        }
                        this.f16030 = i36;
                        this.f16034 = jM81152 == -9223372036854775807L ? 0L : jM81152;
                        c34932.m7955(0);
                        this.f16023.mo4406(this.f16021, c34932);
                        this.f16035 = 6;
                        break;
                    } else {
                        continue;
                    }
                case C1339.STRING_SET_FIELD_NUMBER /* 6 */:
                    int iMin = Math.min(c3493.m7959(), this.f16030 - this.f16026);
                    this.f16023.mo4406(iMin, c3493);
                    int i37 = this.f16026 + iMin;
                    this.f16026 = i37;
                    if (i37 != this.f16030) {
                        break;
                    } else {
                        ᵛᵾˏ.ᵿʗᵝʽ(this.f16027 != -9223372036854775807L);
                        this.f16023.mo4410(this.f16027, this.f16029 == 4 ? 0 : 1, this.f16030, 0, null);
                        this.f16027 += this.f16034;
                        this.f16035 = 0;
                        break;
                    }
                default:
                    ᵨᴵᵺ.ˌʾˀ();
                    return;
            }
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final boolean m9245(C3493 c3493, byte[] bArr, int i) {
        int iMin = Math.min(c3493.m7959(), i - this.f16026);
        c3493.m7970(bArr, this.f16026, iMin);
        int i2 = this.f16026 + iMin;
        this.f16026 = i2;
        return i2 == i;
    }

    @Override // defpackage.InterfaceC4315
    /* renamed from: ᵻᵢﹳᵰ */
    public final void mo1775(boolean z) {
    }
}
