package defpackage;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* JADX INFO: renamed from: ᵾʿᵰˑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C5411 extends AbstractC3863 {

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public boolean f20528;

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public int f20529;

    /* JADX INFO: renamed from: ˊᵨᵧ, reason: contains not printable characters */
    public byte f20530;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public byte f20533;

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public boolean f20534;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public boolean f20535;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public List f20538;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public long f20539;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public List f20540;

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public int f20542;

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

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

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

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static final int[] f20525 = {11, 1, 3, 12, 14, 5, 7, 9};

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public static final int[] f20526 = {0, 4, 8, 12, 16, 20, 24, 28};

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public static final int[] f20521 = {-1, -16711936, -16776961, -16711681, -65536, -256, -65281};

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public static final int[] f20522 = {32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 225, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 233, 93, 237, 243, 250, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 231, 247, 209, 241, 9632};

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public static final int[] f20527 = {174, 176, 189, 191, 8482, 162, 163, 9834, 224, 32, 232, 226, 234, 238, 244, 251};

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public static final int[] f20523 = {193, 201, 211, 218, 220, 252, 8216, 161, 42, 39, 8212, 169, 8480, 8226, 8220, 8221, 192, 194, 199, 200, 202, 203, 235, 206, 207, 239, 212, 217, 249, 219, 171, 187};

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public static final int[] f20520 = {195, 227, 205, 204, 236, 210, 242, 213, 245, 123, 125, 92, 94, 95, 124, 126, 196, 228, 214, 246, 223, 165, 164, 9474, 197, 229, 216, 248, 9484, 9488, 9492, 9496};

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public static final boolean[] f20524 = {false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false};

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final C4545 f20531 = new C4545();

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final ArrayList f20537 = new ArrayList();

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public C0646 f20532 = new C0646(0, 4);

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public int f20536 = 0;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final long f20541 = 16000000;

    public C5411(int i, String str) {
        this.f20545 = "application/x-mp4-cea-608".equals(str) ? 2 : 3;
        if (i == 1) {
            this.f20544 = 0;
            this.f20543 = 0;
        } else if (i == 2) {
            this.f20544 = 1;
            this.f20543 = 0;
        } else if (i == 3) {
            this.f20544 = 0;
            this.f20543 = 1;
        } else if (i != 4) {
            ˋˀᵧ.ʿٴˇ("Invalid channel. Defaulting to CC1.");
            this.f20544 = 0;
            this.f20543 = 0;
        } else {
            this.f20544 = 1;
            this.f20543 = 1;
        }
        m11026(0);
        m11027();
        this.f20535 = true;
        this.f20539 = -9223372036854775807L;
    }

    @Override // defpackage.AbstractC3863, defpackage.InterfaceC0820
    public final void flush() {
        super.flush();
        this.f20540 = null;
        this.f20538 = null;
        m11026(0);
        this.f20529 = 4;
        this.f20532.f3026 = 4;
        m11027();
        this.f20528 = false;
        this.f20534 = false;
        this.f20530 = (byte) 0;
        this.f20533 = (byte) 0;
        this.f20536 = 0;
        this.f20535 = true;
        this.f20539 = -9223372036854775807L;
    }

    /* JADX WARN: Removed duplicated region for block: B:179:0x0085 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:181:0x007e A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0059  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00a6 A[FALL_THROUGH] */
    @Override // defpackage.AbstractC3863
    /* JADX INFO: renamed from: ˊᵫᵗ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void mo2229(C4641 c4641) {
        ByteBuffer byteBuffer = c4641.f11582;
        byteBuffer.getClass();
        byte[] bArrArray = byteBuffer.array();
        int iLimit = byteBuffer.limit();
        C4545 c4545 = this.f20531;
        c4545.m9600(iLimit, bArrArray);
        boolean z = false;
        while (true) {
            int iM9623 = c4545.m9623();
            int i = this.f20545;
            if (iM9623 < i) {
                if (z) {
                    int i2 = this.f20542;
                    if (i2 == 1 || i2 == 3) {
                        this.f20540 = m11028();
                        this.f20539 = this.f14762;
                        return;
                    }
                    return;
                }
                return;
            }
            int iM9626 = i == 2 ? -4 : c4545.m9626();
            int iM96262 = c4545.m9626();
            int iM96263 = c4545.m9626();
            if ((iM9626 & 2) == 0 && (iM9626 & 1) == this.f20543) {
                byte b = (byte) (iM96262 & 127);
                byte b2 = (byte) (iM96263 & 127);
                if (b != 0 || b2 != 0) {
                    boolean z2 = this.f20528;
                    if ((iM9626 & 4) == 4) {
                        boolean[] zArr = f20524;
                        boolean z3 = zArr[iM96262] && zArr[iM96263];
                        this.f20528 = z3;
                        if (!z3 || (b & 240) != 16) {
                            this.f20534 = false;
                            if (!z3) {
                                if (1 <= b && b <= 15) {
                                    this.f20535 = false;
                                } else if ((b & 246) == 20) {
                                    if (b2 != 32 && b2 != 47) {
                                        switch (b2) {
                                            default:
                                                switch (b2) {
                                                    case 42:
                                                    case 43:
                                                        this.f20535 = false;
                                                        break;
                                                }
                                            case 37:
                                            case 38:
                                            case 39:
                                                break;
                                        }
                                    } else {
                                        this.f20535 = true;
                                    }
                                }
                                if (this.f20535) {
                                    int i3 = b & 224;
                                    if (i3 == 0) {
                                        this.f20536 = (b >> 3) & 1;
                                    }
                                    if (this.f20536 == this.f20544) {
                                        if (i3 == 0) {
                                            int i4 = b & 247;
                                            if (i4 == 17 && (b2 & 240) == 48) {
                                                this.f20532.m2312((char) f20527[b2 & 15]);
                                            } else {
                                                int i5 = b & 246;
                                                if (i5 == 18 && (b2 & 224) == 32) {
                                                    this.f20532.m2309();
                                                    this.f20532.m2312((char) ((b & 1) == 0 ? f20523[b2 & 31] : f20520[b2 & 31]));
                                                } else if (i4 == 17 && (b2 & 240) == 32) {
                                                    this.f20532.m2312(' ');
                                                    boolean z4 = (b2 & 1) == 1;
                                                    C0646 c0646 = this.f20532;
                                                    c0646.f3029.add(new C3524((b2 >> 1) & 7, c0646.f3027.length(), z4));
                                                } else if ((b & 240) == 16 && (b2 & 192) == 64) {
                                                    int i6 = f20525[b & 7];
                                                    if ((b2 & 32) != 0) {
                                                        i6++;
                                                    }
                                                    C0646 c06462 = this.f20532;
                                                    if (i6 != c06462.f3031) {
                                                        if (this.f20542 != 1 && !c06462.m2311()) {
                                                            C0646 c06463 = new C0646(this.f20542, this.f20529);
                                                            this.f20532 = c06463;
                                                            this.f20537.add(c06463);
                                                        }
                                                        this.f20532.f3031 = i6;
                                                    }
                                                    boolean z5 = (b2 & 16) == 16;
                                                    boolean z6 = (b2 & 1) == 1;
                                                    int i7 = (b2 >> 1) & 7;
                                                    C0646 c06464 = this.f20532;
                                                    c06464.f3029.add(new C3524(z5 ? 8 : i7, c06464.f3027.length(), z6));
                                                    if (z5) {
                                                        this.f20532.f3028 = f20526[i7];
                                                    }
                                                } else if (i4 == 23 && b2 >= 33 && b2 <= 35) {
                                                    this.f20532.f3032 = b2 - 32;
                                                } else if (i5 == 20 && (b2 & 240) == 32) {
                                                    if (b2 == 32) {
                                                        m11026(2);
                                                    } else if (b2 != 41) {
                                                        switch (b2) {
                                                            case 37:
                                                                m11026(1);
                                                                this.f20529 = 2;
                                                                this.f20532.f3026 = 2;
                                                                break;
                                                            case 38:
                                                                m11026(1);
                                                                this.f20529 = 3;
                                                                this.f20532.f3026 = 3;
                                                                break;
                                                            case 39:
                                                                m11026(1);
                                                                this.f20529 = 4;
                                                                this.f20532.f3026 = 4;
                                                                break;
                                                            default:
                                                                int i8 = this.f20542;
                                                                if (i8 != 0) {
                                                                    if (b2 != 33) {
                                                                        switch (b2) {
                                                                            case 44:
                                                                                this.f20540 = Collections.EMPTY_LIST;
                                                                                if (i8 == 1 || i8 == 3) {
                                                                                    m11027();
                                                                                }
                                                                                break;
                                                                            case 45:
                                                                                if (i8 == 1 && !this.f20532.m2311()) {
                                                                                    C0646 c06465 = this.f20532;
                                                                                    ArrayList arrayList = c06465.f3025;
                                                                                    arrayList.add(c06465.m2313());
                                                                                    c06465.f3027.setLength(0);
                                                                                    c06465.f3029.clear();
                                                                                    int iMin = Math.min(c06465.f3026, c06465.f3031);
                                                                                    while (arrayList.size() >= iMin) {
                                                                                        arrayList.remove(0);
                                                                                    }
                                                                                }
                                                                                break;
                                                                            case 46:
                                                                                m11027();
                                                                                break;
                                                                            case 47:
                                                                                this.f20540 = m11028();
                                                                                m11027();
                                                                                break;
                                                                        }
                                                                    } else {
                                                                        this.f20532.m2309();
                                                                        break;
                                                                    }
                                                                }
                                                                break;
                                                        }
                                                    } else {
                                                        m11026(3);
                                                    }
                                                }
                                            }
                                        } else {
                                            C0646 c06466 = this.f20532;
                                            int[] iArr = f20522;
                                            c06466.m2312((char) iArr[(b & 127) - 32]);
                                            if ((b2 & 224) != 0) {
                                                this.f20532.m2312((char) iArr[(b2 & 127) - 32]);
                                            }
                                        }
                                        z = true;
                                    }
                                }
                            } else if (z2) {
                                m11027();
                                z = true;
                            }
                        } else if (this.f20534 && this.f20530 == b && this.f20533 == b2) {
                            this.f20534 = false;
                        } else {
                            this.f20534 = true;
                            this.f20530 = b;
                            this.f20533 = b2;
                            if (!z3) {
                            }
                        }
                    }
                }
            }
        }
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final void m11026(int i) {
        int i2 = this.f20542;
        if (i2 == i) {
            return;
        }
        this.f20542 = i;
        if (i != 3) {
            m11027();
            if (i2 == 3 || i == 1 || i == 0) {
                this.f20540 = Collections.EMPTY_LIST;
                return;
            }
            return;
        }
        int i3 = 0;
        while (true) {
            ArrayList arrayList = this.f20537;
            if (i3 >= arrayList.size()) {
                return;
            }
            ((C0646) arrayList.get(i3)).f3030 = i;
            i3++;
        }
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final void m11027() {
        C0646 c0646 = this.f20532;
        c0646.f3030 = this.f20542;
        c0646.f3029.clear();
        c0646.f3025.clear();
        c0646.f3027.setLength(0);
        c0646.f3031 = 15;
        c0646.f3028 = 0;
        c0646.f3032 = 0;
        ArrayList arrayList = this.f20537;
        arrayList.clear();
        arrayList.add(this.f20532);
    }

    @Override // defpackage.AbstractC3863
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final boolean mo2232() {
        return this.f20540 != this.f20538;
    }

    @Override // defpackage.AbstractC3863, defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo364() {
    }

    @Override // defpackage.AbstractC3863
    /* JADX INFO: renamed from: ᵵᵽ */
    public final C5401 mo2233() {
        List list = this.f20540;
        this.f20538 = list;
        list.getClass();
        return new C5401(list);
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final ArrayList m11028() {
        ArrayList arrayList = this.f20537;
        int size = arrayList.size();
        ArrayList arrayList2 = new ArrayList(size);
        int iMin = 2;
        for (int i = 0; i < size; i++) {
            C4847 c4847M2310 = ((C0646) arrayList.get(i)).m2310(Integer.MIN_VALUE);
            arrayList2.add(c4847M2310);
            if (c4847M2310 != null) {
                iMin = Math.min(iMin, c4847M2310.f18500);
            }
        }
        ArrayList arrayList3 = new ArrayList(size);
        for (int i2 = 0; i2 < size; i2++) {
            C4847 c4847M23102 = (C4847) arrayList2.get(i2);
            if (c4847M23102 != null) {
                if (c4847M23102.f18500 != iMin) {
                    c4847M23102 = ((C0646) arrayList.get(i2)).m2310(iMin);
                    c4847M23102.getClass();
                }
                arrayList3.add(c4847M23102);
            }
        }
        return arrayList3;
    }

    @Override // defpackage.AbstractC3863, defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ᵻʽᵯ */
    public final AbstractC3334 mo2937() {
        AbstractC3334 abstractC3334;
        AbstractC3334 abstractC3334Mo2937 = super.mo2937();
        if (abstractC3334Mo2937 != null) {
            return abstractC3334Mo2937;
        }
        long j = this.f20541;
        if (j == -9223372036854775807L) {
            return null;
        }
        long j2 = this.f20539;
        if (j2 == -9223372036854775807L || this.f14762 - j2 < j || (abstractC3334 = (AbstractC3334) this.f14760.pollFirst()) == null) {
            return null;
        }
        this.f20540 = Collections.EMPTY_LIST;
        this.f20539 = -9223372036854775807L;
        C5401 c5401Mo2233 = mo2233();
        long j3 = this.f14762;
        abstractC3334.f15983 = j3;
        abstractC3334.f12792 = c5401Mo2233;
        abstractC3334.f12791 = j3;
        return abstractC3334;
    }
}
