package p138.p176.p177.p190.p198.p207;

import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.p198.C3558;
import p138.p176.p177.p190.p198.C3570;
import p138.p176.p177.p190.p198.InterfaceC3561;
import p138.p176.p177.p190.p198.InterfaceC3562;
import p138.p176.p177.p190.p198.InterfaceC3571;
import p138.p176.p177.p190.p198.p207.InterfaceC3690;
import p138.p176.p177.p190.p239.C4139;
import p138.p176.p177.p190.p239.C4140;
import p138.p176.p177.p190.p239.C4149;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޝ.ޙ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3687 implements InterfaceC3561 {

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

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final List<C4149> f11350;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C4140 f11351;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final SparseIntArray f11352;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final InterfaceC3690.InterfaceC3693 f11353;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final SparseArray<InterfaceC3690> f11354;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final SparseBooleanArray f11355;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final SparseBooleanArray f11356;

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

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public C3684 f11358;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public InterfaceC3562 f11359;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޝ.ޙ$֏, reason: contains not printable characters */
    public class C3688 implements InterfaceC3680 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C4139 f11367 = new C4139(new byte[4]);

        public C3688() {
        }

        @Override // p138.p176.p177.p190.p198.p207.InterfaceC3680
        /* JADX INFO: renamed from: ֏ */
        public void mo6031(C4140 c4140) {
            if (c4140.m6702() != 0) {
                return;
            }
            c4140.m6695(7);
            int iM6679 = c4140.m6679() / 4;
            for (int i = 0; i < iM6679; i++) {
                c4140.m6682(this.f11367, 4);
                int iM6667 = this.f11367.m6667(16);
                this.f11367.m6675(3);
                if (iM6667 == 0) {
                    this.f11367.m6675(13);
                } else {
                    int iM66672 = this.f11367.m6667(13);
                    C3687 c3687 = C3687.this;
                    c3687.f11354.put(iM66672, new C3681(c3687.new C3689(iM66672)));
                    C3687.this.f11360++;
                }
            }
            C3687 c36872 = C3687.this;
            if (c36872.f11349 != 2) {
                c36872.f11354.remove(0);
            }
        }

        @Override // p138.p176.p177.p190.p198.p207.InterfaceC3680
        /* JADX INFO: renamed from: ֏ */
        public void mo6032(C4149 c4149, InterfaceC3562 interfaceC3562, InterfaceC3690.C3694 c3694) {
        }
    }

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޝ.ޙ$ؠ, reason: contains not printable characters */
    public class C3689 implements InterfaceC3680 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C4139 f11369 = new C4139(new byte[5]);

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final SparseArray<InterfaceC3690> f11370 = new SparseArray<>();

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

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

        public C3689(int i) {
            this.f11372 = i;
        }

        /* JADX WARN: Removed duplicated region for block: B:39:0x011d  */
        /* JADX WARN: Removed duplicated region for block: B:42:0x0124  */
        /* JADX WARN: Removed duplicated region for block: B:47:0x0131  */
        @Override // p138.p176.p177.p190.p198.p207.InterfaceC3680
        /* JADX INFO: renamed from: ֏ */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public void mo6031(C4140 c4140) {
            C4149 c4149;
            C4149 c41492;
            int i;
            int i2;
            C4149 c41493;
            int i3;
            if (c4140.m6702() != 2) {
                return;
            }
            C3687 c3687 = C3687.this;
            int i4 = c3687.f11349;
            if (i4 == 1 || i4 == 2 || c3687.f11360 == 1) {
                c4149 = C3687.this.f11350.get(0);
            } else {
                c4149 = new C4149(c3687.f11350.get(0).f13256);
                C3687.this.f11350.add(c4149);
            }
            c4140.m6695(2);
            int iM6707 = c4140.m6707();
            int i5 = 3;
            c4140.m6695(3);
            c4140.m6682(this.f11369, 2);
            this.f11369.m6675(3);
            int i6 = 13;
            C3687.this.f11366 = this.f11369.m6667(13);
            c4140.m6682(this.f11369, 2);
            int i7 = 4;
            this.f11369.m6675(4);
            int i8 = 12;
            c4140.m6695(this.f11369.m6667(12));
            C3687 c36872 = C3687.this;
            int i9 = 21;
            if (c36872.f11349 == 2 && c36872.f11364 == null) {
                InterfaceC3690.C3692 c3692 = new InterfaceC3690.C3692(21, null, null, C4150.f13264);
                C3687 c36873 = C3687.this;
                c36873.f11364 = c36873.f11353.mo6009(21, c3692);
                C3687 c36874 = C3687.this;
                c36874.f11364.mo6025(c4149, c36874.f11359, new InterfaceC3690.C3694(iM6707, 21, 8192));
            }
            this.f11370.clear();
            this.f11371.clear();
            int iM6679 = c4140.m6679();
            while (iM6679 > 0) {
                int i10 = 5;
                c4140.m6682(this.f11369, 5);
                int iM6667 = this.f11369.m6667(8);
                this.f11369.m6675(i5);
                int iM66672 = this.f11369.m6667(i6);
                this.f11369.m6675(i7);
                int iM66673 = this.f11369.m6667(i8);
                int i11 = c4140.f13228;
                int i12 = iM66673 + i11;
                int i13 = -1;
                String strTrim = null;
                ArrayList arrayList = null;
                while (c4140.f13228 < i12) {
                    int iM6702 = c4140.m6702();
                    int iM67022 = c4140.f13228 + c4140.m6702();
                    if (iM6702 == i10) {
                        long jM6703 = c4140.m6703();
                        if (jM6703 == 1094921523) {
                            i13 = 129;
                        } else if (jM6703 == 1161904947) {
                            i13 = 135;
                        } else if (jM6703 == 1094921524) {
                            i13 = 172;
                        } else if (jM6703 == 1212503619) {
                            i13 = 36;
                        }
                        i2 = iM6707;
                        c41493 = c4149;
                        i3 = iM66672;
                    } else {
                        if (iM6702 != 106) {
                            if (iM6702 != 122) {
                                if (iM6702 == 127) {
                                    if (c4140.m6702() == i9) {
                                    }
                                } else if (iM6702 == 123) {
                                    i13 = 138;
                                } else if (iM6702 == 10) {
                                    strTrim = c4140.m6687(3).trim();
                                } else {
                                    int i14 = 3;
                                    if (iM6702 == 89) {
                                        ArrayList arrayList2 = new ArrayList();
                                        while (c4140.f13228 < iM67022) {
                                            String strTrim2 = c4140.m6687(i14).trim();
                                            int iM67023 = c4140.m6702();
                                            byte[] bArr = new byte[4];
                                            System.arraycopy(c4140.f13227, c4140.f13228, bArr, 0, 4);
                                            c4140.f13228 += 4;
                                            arrayList2.add(new InterfaceC3690.C3691(strTrim2, iM67023, bArr));
                                            c4149 = c4149;
                                            iM6707 = iM6707;
                                            iM66672 = iM66672;
                                            i14 = 3;
                                        }
                                        i2 = iM6707;
                                        c41493 = c4149;
                                        i3 = iM66672;
                                        arrayList = arrayList2;
                                        i13 = 89;
                                    }
                                }
                            }
                        }
                        i2 = iM6707;
                        c41493 = c4149;
                        i3 = iM66672;
                    }
                    c4140.m6695(iM67022 - c4140.f13228);
                    c4149 = c41493;
                    iM6707 = i2;
                    iM66672 = i3;
                    i10 = 5;
                    i9 = 21;
                }
                int i15 = iM6707;
                C4149 c41494 = c4149;
                int i16 = iM66672;
                c4140.m6693(i12);
                InterfaceC3690.C3692 c36922 = new InterfaceC3690.C3692(i13, strTrim, arrayList, Arrays.copyOfRange(c4140.f13227, i11, i12));
                if (iM6667 == 6) {
                    iM6667 = c36922.f11376;
                }
                iM6679 -= iM66673 + 5;
                if (!C3687.this.f11355.get(i16)) {
                    C3687 c36875 = C3687.this;
                    InterfaceC3690 interfaceC3690Mo6009 = (c36875.f11349 == 2 && iM6667 == 21) ? c36875.f11364 : C3687.this.f11353.mo6009(iM6667, c36922);
                    this.f11371.put(i16, i16);
                    this.f11370.put(i16, interfaceC3690Mo6009);
                }
                c4149 = c41494;
                iM6707 = i15;
                i5 = 3;
                i7 = 4;
                i6 = 13;
                i8 = 12;
                i9 = 21;
            }
            int i17 = iM6707;
            C4149 c41495 = c4149;
            int size = this.f11371.size();
            int i18 = 0;
            while (i18 < size) {
                int iKeyAt = this.f11371.keyAt(i18);
                int iValueAt = this.f11371.valueAt(i18);
                C3687.this.f11355.put(iKeyAt, true);
                C3687.this.f11356.put(iValueAt, true);
                InterfaceC3690 interfaceC3690ValueAt = this.f11370.valueAt(i18);
                if (interfaceC3690ValueAt != null) {
                    C3687 c36876 = C3687.this;
                    if (interfaceC3690ValueAt != c36876.f11364) {
                        InterfaceC3562 interfaceC3562 = c36876.f11359;
                        i = i17;
                        InterfaceC3690.C3694 c3694 = new InterfaceC3690.C3694(i, iKeyAt, 8192);
                        c41492 = c41495;
                        interfaceC3690ValueAt.mo6025(c41492, interfaceC3562, c3694);
                    } else {
                        c41492 = c41495;
                        i = i17;
                    }
                    C3687.this.f11354.put(iValueAt, interfaceC3690ValueAt);
                } else {
                    c41492 = c41495;
                    i = i17;
                }
                i18++;
                c41495 = c41492;
                i17 = i;
            }
            C3687 c36877 = C3687.this;
            if (c36877.f11349 == 2) {
                if (c36877.f11361) {
                    return;
                }
                c36877.f11359.mo5892();
                C3687 c36878 = C3687.this;
                c36878.f11360 = 0;
                c36878.f11361 = true;
                return;
            }
            c36877.f11354.remove(this.f11372);
            C3687 c36879 = C3687.this;
            c36879.f11360 = c36879.f11349 == 1 ? 0 : c36879.f11360 - 1;
            C3687 c368710 = C3687.this;
            if (c368710.f11360 == 0) {
                c368710.f11359.mo5892();
                C3687.this.f11361 = true;
            }
        }

        @Override // p138.p176.p177.p190.p198.p207.InterfaceC3680
        /* JADX INFO: renamed from: ֏ */
        public void mo6032(C4149 c4149, InterfaceC3562 interfaceC3562, InterfaceC3690.C3694 c3694) {
        }
    }

    public C3687(int i, C4149 c4149, InterfaceC3690.InterfaceC3693 interfaceC3693) {
        if (interfaceC3693 == null) {
            throw null;
        }
        this.f11353 = interfaceC3693;
        this.f11349 = i;
        if (i == 1 || i == 2) {
            this.f11350 = Collections.singletonList(c4149);
        } else {
            ArrayList arrayList = new ArrayList();
            this.f11350 = arrayList;
            arrayList.add(c4149);
        }
        this.f11351 = new C4140(new byte[9400], 0);
        this.f11355 = new SparseBooleanArray();
        this.f11356 = new SparseBooleanArray();
        this.f11354 = new SparseArray<>();
        this.f11352 = new SparseIntArray();
        this.f11357 = new C3686();
        this.f11366 = -1;
        this.f11355.clear();
        this.f11354.clear();
        SparseArray<InterfaceC3690> sparseArrayMo6007 = this.f11353.mo6007();
        int size = sparseArrayMo6007.size();
        for (int i2 = 0; i2 < size; i2++) {
            this.f11354.put(sparseArrayMo6007.keyAt(i2), sparseArrayMo6007.valueAt(i2));
        }
        this.f11354.put(0, new C3681(new C3688()));
        this.f11364 = null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r15v1 */
    /* JADX WARN: Type inference failed for: r15v2, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r15v7 */
    /* JADX WARN: Type inference failed for: r15v8 */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v19 */
    /* JADX WARN: Type inference failed for: r3v2, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r3v8 */
    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public int mo5886(C3558 c3558, C3570 c3570) throws InterruptedException, ParserException, EOFException {
        ?? r3;
        ?? r15;
        int i;
        boolean z;
        int i2;
        boolean z2;
        long j = c3558.f10562;
        if (this.f11361) {
            long j2 = -9223372036854775807L;
            if ((j == -1 || this.f11349 == 2) ? false : true) {
                C3686 c3686 = this.f11357;
                if (!c3686.f11343) {
                    int i3 = this.f11366;
                    if (i3 <= 0) {
                        c3686.m6034(c3558);
                        return 0;
                    }
                    if (!c3686.f11345) {
                        long j3 = c3558.f10562;
                        int iMin = (int) Math.min(1880000L, j3);
                        long j4 = j3 - ((long) iMin);
                        if (c3558.f10563 == j4) {
                            c3686.f11342.m6689(iMin);
                            c3558.f10565 = 0;
                            c3558.m5875(c3686.f11342.f13227, 0, iMin, false);
                            C4140 c4140 = c3686.f11342;
                            int i4 = c4140.f13228;
                            int i5 = c4140.f13229;
                            while (true) {
                                i5--;
                                if (i5 < i4) {
                                    break;
                                }
                                if (c4140.f13227[i5] == 71) {
                                    long jM1847 = C0567.m1847(c4140, i5, i3);
                                    if (jM1847 != -9223372036854775807L) {
                                        j2 = jM1847;
                                        break;
                                    }
                                }
                            }
                            c3686.f11347 = j2;
                            c3686.f11345 = true;
                            return 0;
                        }
                        c3570.f10591 = j4;
                    } else {
                        if (c3686.f11347 == -9223372036854775807L) {
                            c3686.m6034(c3558);
                            return 0;
                        }
                        if (c3686.f11344) {
                            long j5 = c3686.f11346;
                            if (j5 == -9223372036854775807L) {
                                c3686.m6034(c3558);
                                return 0;
                            }
                            c3686.f11348 = c3686.f11341.m6737(c3686.f11347) - c3686.f11341.m6737(j5);
                            c3686.m6034(c3558);
                            return 0;
                        }
                        int iMin2 = (int) Math.min(1880000L, c3558.f10562);
                        long j6 = 0;
                        if (c3558.f10563 == j6) {
                            c3686.f11342.m6689(iMin2);
                            c3558.f10565 = 0;
                            c3558.m5875(c3686.f11342.f13227, 0, iMin2, false);
                            C4140 c41402 = c3686.f11342;
                            int i6 = c41402.f13228;
                            int i7 = c41402.f13229;
                            while (true) {
                                if (i6 >= i7) {
                                    break;
                                }
                                if (c41402.f13227[i6] == 71) {
                                    long jM18472 = C0567.m1847(c41402, i6, i3);
                                    if (jM18472 != -9223372036854775807L) {
                                        j2 = jM18472;
                                        break;
                                    }
                                }
                                i6++;
                            }
                            c3686.f11346 = j2;
                            c3686.f11344 = true;
                            return 0;
                        }
                        c3570.f10591 = j6;
                    }
                    return 1;
                }
            }
            if (this.f11362) {
                z2 = false;
            } else {
                this.f11362 = true;
                C3686 c36862 = this.f11357;
                long j7 = c36862.f11348;
                if (j7 != -9223372036854775807L) {
                    z2 = false;
                    C3684 c3684 = new C3684(c36862.f11341, j7, j, this.f11366);
                    this.f11358 = c3684;
                    this.f11359.mo5893(c3684.f10525);
                } else {
                    z2 = false;
                    this.f11359.mo5893(new InterfaceC3571.C3573(j7, 0L));
                }
            }
            if (this.f11363) {
                this.f11363 = z2;
                mo5888(0L, 0L);
                if (c3558.f10563 != 0) {
                    c3570.f10591 = 0L;
                    return 1;
                }
            }
            r3 = 1;
            r3 = 1;
            C3684 c36842 = this.f11358;
            r15 = z2;
            if (c36842 != null) {
                r15 = z2;
                if (c36842.m5855()) {
                    return this.f11358.m5852(c3558, c3570);
                }
            }
        } else {
            r3 = 1;
            r15 = 0;
        }
        C4140 c41403 = this.f11351;
        byte[] bArr = c41403.f13227;
        if (9400 - c41403.f13228 < 188) {
            int iM6679 = c41403.m6679();
            if (iM6679 > 0) {
                System.arraycopy(bArr, this.f11351.f13228, bArr, r15, iM6679);
            }
            this.f11351.m6684(bArr, iM6679);
        }
        while (true) {
            if (this.f11351.m6679() >= 188) {
                i = -1;
                z = true;
                break;
            }
            int i8 = this.f11351.f13229;
            int iM5870 = c3558.m5870(bArr, i8, 9400 - i8);
            i = -1;
            if (iM5870 == -1) {
                z = false;
                break;
            }
            this.f11351.m6691(i8 + iM5870);
        }
        if (!z) {
            return i;
        }
        C4140 c41404 = this.f11351;
        int i9 = c41404.f13228;
        int i10 = c41404.f13229;
        byte[] bArr2 = c41404.f13227;
        int i11 = i9;
        while (i11 < i10 && bArr2[i11] != 71) {
            i11++;
        }
        this.f11351.m6693(i11);
        int i12 = i11 + 188;
        if (i12 > i10) {
            int i13 = (i11 - i9) + this.f11365;
            this.f11365 = i13;
            i2 = 2;
            if (this.f11349 == 2 && i13 > 376) {
                throw new ParserException("Cannot find sync byte. Most likely not a Transport Stream.");
            }
        } else {
            i2 = 2;
            this.f11365 = r15;
        }
        C4140 c41405 = this.f11351;
        int i14 = c41405.f13229;
        if (i12 > i14) {
            return r15;
        }
        int iM6688 = c41405.m6688();
        if ((8388608 & iM6688) != 0) {
            this.f11351.m6693(i12);
            return r15;
        }
        int i15 = ((4194304 & iM6688) != 0 ? 1 : 0) | 0;
        int i16 = (2096896 & iM6688) >> 8;
        boolean z3 = (iM6688 & 32) != 0;
        InterfaceC3690 interfaceC3690 = (iM6688 & 16) != 0 ? this.f11354.get(i16) : null;
        if (interfaceC3690 == null) {
            this.f11351.m6693(i12);
            return r15;
        }
        if (this.f11349 != i2) {
            int i17 = iM6688 & 15;
            int i18 = this.f11352.get(i16, i17 - 1);
            this.f11352.put(i16, i17);
            if (i18 == i17) {
                this.f11351.m6693(i12);
                return r15;
            }
            if (i17 != ((i18 + r3) & 15)) {
                interfaceC3690.mo6022();
            }
        }
        if (z3) {
            int iM6702 = this.f11351.m6702();
            i15 |= (this.f11351.m6702() & 64) != 0 ? 2 : 0;
            this.f11351.m6695(iM6702 - r3);
        }
        boolean z4 = this.f11361;
        if (this.f11349 == i2 || z4 || !this.f11356.get(i16, r15)) {
            this.f11351.m6691(i12);
            interfaceC3690.mo6024(this.f11351, i15);
            this.f11351.m6691(i14);
        }
        if (this.f11349 != i2 && !z4 && this.f11361 && j != -1) {
            this.f11363 = r3;
        }
        this.f11351.m6693(i12);
        return r15;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5887() {
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5888(long j, long j2) {
        C3684 c3684;
        C0567.m1932(this.f11349 != 2);
        int size = this.f11350.size();
        for (int i = 0; i < size; i++) {
            C4149 c4149 = this.f11350.get(i);
            if ((c4149.m6735() == -9223372036854775807L) || (c4149.m6735() != 0 && c4149.f13256 != j2)) {
                c4149.f13258 = -9223372036854775807L;
                c4149.m6739(j2);
            }
        }
        if (j2 != 0 && (c3684 = this.f11358) != null) {
            c3684.m5853(j2);
        }
        this.f11351.m6709();
        this.f11352.clear();
        for (int i2 = 0; i2 < this.f11354.size(); i2++) {
            this.f11354.valueAt(i2).mo6022();
        }
        this.f11365 = 0;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5889(InterfaceC3562 interfaceC3562) {
        this.f11359 = interfaceC3562;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public boolean mo5890(C3558 c3558) throws InterruptedException, EOFException {
        boolean z;
        byte[] bArr = this.f11351.f13227;
        c3558.m5875(bArr, 0, 940, false);
        for (int i = 0; i < 188; i++) {
            int i2 = 0;
            while (true) {
                if (i2 >= 5) {
                    z = true;
                    break;
                }
                if (bArr[(i2 * 188) + i] != 71) {
                    z = false;
                    break;
                }
                i2++;
            }
            if (z) {
                c3558.m5878(i);
                return true;
            }
        }
        return false;
    }
}
