package p138.p176.p177.p190.p226.p227;

import android.text.Layout;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import p138.p176.p177.p190.p226.C3946;
import p138.p176.p177.p190.p226.C3953;
import p138.p176.p177.p190.p226.InterfaceC3949;
import p138.p176.p177.p190.p239.C4140;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.މ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3957 extends AbstractC3964 {

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

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

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

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public static final int[] f12411 = {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[] f12412 = {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[] f12413 = {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[] f12414 = {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[] f12415 = {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 int f12417;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final int f12418;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final int f12419;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public List<C3946> f12422;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public List<C3946> f12423;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public int f12424;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public int f12425;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public boolean f12426;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public boolean f12427;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public byte f12428;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public byte f12429;

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public boolean f12431;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C4140 f12416 = new C4140();

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final ArrayList<C3958> f12420 = new ArrayList<>();

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public C3958 f12421 = new C3958(0, 4);

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public int f12430 = 0;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.މ.֏$֏, reason: contains not printable characters */
    public static class C3958 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final List<C3959> f12432 = new ArrayList();

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final List<SpannableString> f12433 = new ArrayList();

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final StringBuilder f12434 = new StringBuilder();

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public int f12435;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public int f12436;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public int f12437;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public int f12438;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public int f12439;

        /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.މ.֏$֏$֏, reason: contains not printable characters */
        public static class C3959 {

            /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
            public final int f12440;

            /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
            public final boolean f12441;

            /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
            public int f12442;

            public C3959(int i, boolean z, int i2) {
                this.f12440 = i;
                this.f12441 = z;
                this.f12442 = i2;
            }
        }

        public C3958(int i, int i2) {
            m6395(i);
            this.f12439 = i2;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public C3946 m6392(int i) {
            float f;
            int i2;
            int i3;
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
            for (int i4 = 0; i4 < this.f12433.size(); i4++) {
                spannableStringBuilder.append((CharSequence) this.f12433.get(i4));
                spannableStringBuilder.append('\n');
            }
            spannableStringBuilder.append((CharSequence) m6394());
            if (spannableStringBuilder.length() == 0) {
                return null;
            }
            int i5 = this.f12436 + this.f12437;
            int length = (32 - i5) - spannableStringBuilder.length();
            int i6 = i5 - length;
            if (i == Integer.MIN_VALUE) {
                i = (this.f12438 != 2 || (Math.abs(i6) >= 3 && length >= 0)) ? (this.f12438 != 2 || i6 <= 0) ? 0 : 2 : 1;
            }
            if (i != 1) {
                if (i == 2) {
                    i5 = 32 - length;
                }
                f = ((i5 / 32.0f) * 0.8f) + 0.1f;
            } else {
                f = 0.5f;
            }
            if (this.f12438 == 1 || (i2 = this.f12435) > 7) {
                i2 = (this.f12435 - 15) - 2;
                i3 = 2;
            } else {
                i3 = 0;
            }
            return new C3946(spannableStringBuilder, Layout.Alignment.ALIGN_NORMAL, i2, 1, i3, f, i, -3.4028235E38f);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void m6393() {
            int length = this.f12434.length();
            if (length > 0) {
                this.f12434.delete(length - 1, length);
                for (int size = this.f12432.size() - 1; size >= 0; size--) {
                    C3959 c3959 = this.f12432.get(size);
                    int i = c3959.f12442;
                    if (i != length) {
                        return;
                    }
                    c3959.f12442 = i - 1;
                }
            }
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final SpannableString m6394() {
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(this.f12434);
            int length = spannableStringBuilder.length();
            int i = 0;
            int i2 = -1;
            int i3 = -1;
            int i4 = 0;
            int i5 = -1;
            boolean z = false;
            int i6 = -1;
            while (i < this.f12432.size()) {
                C3959 c3959 = this.f12432.get(i);
                boolean z2 = c3959.f12441;
                int i7 = c3959.f12440;
                if (i7 != 8) {
                    boolean z3 = i7 == 7;
                    if (i7 != 7) {
                        i6 = C3957.f12410[i7];
                    }
                    z = z3;
                }
                int i8 = c3959.f12442;
                i++;
                if (i8 != (i < this.f12432.size() ? this.f12432.get(i).f12442 : length)) {
                    if (i2 != -1 && !z2) {
                        spannableStringBuilder.setSpan(new UnderlineSpan(), i2, i8, 33);
                        i2 = -1;
                    } else if (i2 == -1 && z2) {
                        i2 = i8;
                    }
                    if (i3 != -1 && !z) {
                        spannableStringBuilder.setSpan(new StyleSpan(2), i3, i8, 33);
                        i3 = -1;
                    } else if (i3 == -1 && z) {
                        i3 = i8;
                    }
                    if (i6 != i5) {
                        if (i5 != -1) {
                            spannableStringBuilder.setSpan(new ForegroundColorSpan(i5), i4, i8, 33);
                        }
                        i4 = i8;
                        i5 = i6;
                    }
                }
            }
            if (i2 != -1 && i2 != length) {
                spannableStringBuilder.setSpan(new UnderlineSpan(), i2, length, 33);
            }
            if (i3 != -1 && i3 != length) {
                spannableStringBuilder.setSpan(new StyleSpan(2), i3, length, 33);
            }
            if (i4 != length && i5 != -1) {
                spannableStringBuilder.setSpan(new ForegroundColorSpan(i5), i4, length, 33);
            }
            return new SpannableString(spannableStringBuilder);
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public void m6395(int i) {
            this.f12438 = i;
            this.f12432.clear();
            this.f12433.clear();
            this.f12434.setLength(0);
            this.f12435 = 15;
            this.f12436 = 0;
            this.f12437 = 0;
        }

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public boolean m6396() {
            return this.f12432.isEmpty() && this.f12433.isEmpty() && this.f12434.length() == 0;
        }
    }

    public C3957(String str, int i) {
        this.f12417 = "application/x-mp4-cea-608".equals(str) ? 2 : 3;
        if (i == 1) {
            this.f12419 = 0;
            this.f12418 = 0;
        } else if (i == 2) {
            this.f12419 = 1;
            this.f12418 = 0;
        } else if (i == 3) {
            this.f12419 = 0;
            this.f12418 = 1;
        } else if (i != 4) {
            Log.w("Cea608Decoder", "Invalid channel. Defaulting to CC1.");
            this.f12419 = 0;
            this.f12418 = 0;
        } else {
            this.f12419 = 1;
            this.f12418 = 1;
        }
        m6385(0);
        m6391();
        this.f12431 = true;
    }

    @Override // p138.p176.p177.p190.p226.p227.AbstractC3964, p138.p176.p177.p190.p193.InterfaceC3509
    public void flush() {
        super.flush();
        this.f12422 = null;
        this.f12423 = null;
        m6385(0);
        m6387(4);
        m6391();
        this.f12426 = false;
        this.f12427 = false;
        this.f12428 = (byte) 0;
        this.f12429 = (byte) 0;
        this.f12430 = 0;
        this.f12431 = true;
    }

    @Override // p138.p176.p177.p190.p226.p227.AbstractC3964, p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ֏ */
    public void mo1134() {
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m6385(int i) {
        int i2 = this.f12424;
        if (i2 == i) {
            return;
        }
        this.f12424 = i;
        if (i == 3) {
            for (int i3 = 0; i3 < this.f12420.size(); i3++) {
                this.f12420.get(i3).f12438 = i;
            }
            return;
        }
        m6391();
        if (i2 == 3 || i == 1 || i == 0) {
            this.f12422 = Collections.emptyList();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:216:0x008e A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:226:0x0014 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0061  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x0088  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x00c4 A[FALL_THROUGH] */
    @Override // p138.p176.p177.p190.p226.p227.AbstractC3964
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void mo6386(C3953 c3953) {
        boolean z;
        this.f12416.m6684(c3953.f10461.array(), c3953.f10461.limit());
        boolean z2 = false;
        while (true) {
            int iM6679 = this.f12416.m6679();
            int i = this.f12417;
            if (iM6679 < i) {
                if (z2) {
                    int i2 = this.f12424;
                    if (i2 == 1 || i2 == 3) {
                        this.f12422 = m6390();
                        return;
                    }
                    return;
                }
                return;
            }
            byte bM6702 = i == 2 ? (byte) -4 : (byte) this.f12416.m6702();
            int iM6702 = this.f12416.m6702();
            int iM67022 = this.f12416.m6702();
            if ((bM6702 & 2) == 0 && (bM6702 & 1) == this.f12418) {
                byte b = (byte) (iM6702 & 127);
                byte b2 = (byte) (iM67022 & 127);
                if (b != 0 || b2 != 0) {
                    boolean z3 = this.f12426;
                    if ((bM6702 & 4) == 4) {
                        boolean[] zArr = f12415;
                        boolean z4 = zArr[iM6702] && zArr[iM67022];
                        this.f12426 = z4;
                        if (z4) {
                            if ((b & 240) == 16) {
                                if (this.f12427 && this.f12428 == b && this.f12429 == b2) {
                                    this.f12427 = false;
                                    z = true;
                                    if (!z) {
                                    }
                                } else {
                                    this.f12427 = true;
                                    this.f12428 = b;
                                    this.f12429 = b2;
                                }
                            }
                            z = false;
                            if (!z) {
                            }
                        } else {
                            this.f12427 = false;
                            z = false;
                            if (!z) {
                                if (this.f12426) {
                                    if (1 <= b && b <= 15) {
                                        this.f12431 = false;
                                    } else if ((b & 247) == 20) {
                                        if (b2 != 32 && b2 != 47) {
                                            switch (b2) {
                                                default:
                                                    switch (b2) {
                                                        case 42:
                                                        case 43:
                                                            this.f12431 = false;
                                                            break;
                                                    }
                                                case 37:
                                                case 38:
                                                case 39:
                                                    break;
                                            }
                                        } else {
                                            this.f12431 = true;
                                        }
                                    }
                                    if (this.f12431) {
                                        int i3 = b & 224;
                                        if (i3 == 0) {
                                            this.f12430 = (b >> 3) & 1;
                                        }
                                        if (this.f12430 == this.f12419) {
                                            if (i3 == 0) {
                                                int i4 = b & 247;
                                                if (i4 == 17 && (b2 & 240) == 48) {
                                                    this.f12421.f12434.append((char) f12412[b2 & 15]);
                                                } else {
                                                    int i5 = b & 246;
                                                    if (i5 == 18 && (b2 & 224) == 32) {
                                                        this.f12421.m6393();
                                                        this.f12421.f12434.append((char) ((b & 1) == 0 ? f12413[b2 & 31] : f12414[b2 & 31]));
                                                    } else if (i4 == 17 && (b2 & 240) == 32) {
                                                        this.f12421.f12434.append(' ');
                                                        boolean z5 = (b2 & 1) == 1;
                                                        C3958 c3958 = this.f12421;
                                                        c3958.f12432.add(new C3958.C3959((b2 >> 1) & 7, z5, c3958.f12434.length()));
                                                    } else if ((b & 240) == 16 && (b2 & 192) == 64) {
                                                        int i6 = f12408[b & 7];
                                                        if ((b2 & 32) != 0) {
                                                            i6++;
                                                        }
                                                        C3958 c39582 = this.f12421;
                                                        if (i6 != c39582.f12435) {
                                                            if (this.f12424 != 1 && !c39582.m6396()) {
                                                                C3958 c39583 = new C3958(this.f12424, this.f12425);
                                                                this.f12421 = c39583;
                                                                this.f12420.add(c39583);
                                                            }
                                                            this.f12421.f12435 = i6;
                                                        }
                                                        boolean z6 = (b2 & 16) == 16;
                                                        boolean z7 = (b2 & 1) == 1;
                                                        int i7 = (b2 >> 1) & 7;
                                                        C3958 c39584 = this.f12421;
                                                        c39584.f12432.add(new C3958.C3959(z6 ? 8 : i7, z7, c39584.f12434.length()));
                                                        if (z6) {
                                                            this.f12421.f12436 = f12409[i7];
                                                        }
                                                    } else if (i4 == 23 && b2 >= 33 && b2 <= 35) {
                                                        this.f12421.f12437 = b2 - 32;
                                                    } else if (i5 == 20 && (b2 & 240) == 32) {
                                                        if (b2 == 32) {
                                                            m6385(2);
                                                        } else if (b2 != 41) {
                                                            switch (b2) {
                                                                case 37:
                                                                    m6385(1);
                                                                    m6387(2);
                                                                    break;
                                                                case 38:
                                                                    m6385(1);
                                                                    m6387(3);
                                                                    break;
                                                                case 39:
                                                                    m6385(1);
                                                                    m6387(4);
                                                                    break;
                                                                default:
                                                                    int i8 = this.f12424;
                                                                    if (i8 != 0) {
                                                                        if (b2 != 33) {
                                                                            switch (b2) {
                                                                                case 44:
                                                                                    this.f12422 = Collections.emptyList();
                                                                                    int i9 = this.f12424;
                                                                                    if (i9 == 1 || i9 == 3) {
                                                                                        m6391();
                                                                                    }
                                                                                    break;
                                                                                case 45:
                                                                                    if (i8 == 1 && !this.f12421.m6396()) {
                                                                                        C3958 c39585 = this.f12421;
                                                                                        c39585.f12433.add(c39585.m6394());
                                                                                        c39585.f12434.setLength(0);
                                                                                        c39585.f12432.clear();
                                                                                        int iMin = Math.min(c39585.f12439, c39585.f12435);
                                                                                        while (c39585.f12433.size() >= iMin) {
                                                                                            c39585.f12433.remove(0);
                                                                                        }
                                                                                    }
                                                                                    break;
                                                                                case 46:
                                                                                    m6391();
                                                                                    break;
                                                                                case 47:
                                                                                    this.f12422 = m6390();
                                                                                    m6391();
                                                                                    break;
                                                                            }
                                                                        } else {
                                                                            this.f12421.m6393();
                                                                            break;
                                                                        }
                                                                    }
                                                                    break;
                                                            }
                                                        } else {
                                                            m6385(3);
                                                        }
                                                    }
                                                }
                                            } else {
                                                this.f12421.f12434.append((char) f12411[(b & 127) - 32]);
                                                if ((b2 & 224) != 0) {
                                                    this.f12421.f12434.append((char) f12411[(b2 & 127) - 32]);
                                                }
                                            }
                                            z2 = true;
                                        }
                                    }
                                } else if (z3) {
                                    m6391();
                                    z2 = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override // p138.p176.p177.p190.p193.InterfaceC3509
    /* JADX INFO: renamed from: ؠ */
    public String mo1135() {
        return "Cea608Decoder";
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m6387(int i) {
        this.f12425 = i;
        this.f12421.f12439 = i;
    }

    @Override // p138.p176.p177.p190.p226.p227.AbstractC3964
    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public InterfaceC3949 mo6388() {
        List<C3946> list = this.f12422;
        this.f12423 = list;
        return new C3968(list);
    }

    @Override // p138.p176.p177.p190.p226.p227.AbstractC3964
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean mo6389() {
        return this.f12422 != this.f12423;
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final List<C3946> m6390() {
        int size = this.f12420.size();
        ArrayList arrayList = new ArrayList(size);
        int iMin = 2;
        for (int i = 0; i < size; i++) {
            C3946 c3946M6392 = this.f12420.get(i).m6392(Integer.MIN_VALUE);
            arrayList.add(c3946M6392);
            if (c3946M6392 != null) {
                iMin = Math.min(iMin, c3946M6392.f12382);
            }
        }
        ArrayList arrayList2 = new ArrayList(size);
        for (int i2 = 0; i2 < size; i2++) {
            C3946 c3946M63922 = (C3946) arrayList.get(i2);
            if (c3946M63922 != null) {
                if (c3946M63922.f12382 != iMin) {
                    c3946M63922 = this.f12420.get(i2).m6392(iMin);
                }
                arrayList2.add(c3946M63922);
            }
        }
        return arrayList2;
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final void m6391() {
        this.f12421.m6395(this.f12424);
        this.f12420.clear();
        this.f12420.add(this.f12421);
    }
}
