package A;

import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import b0.AbstractC0399d;
import b0.D;
import b0.s;
import b0.t;
import com.mstar.android.tv.TvLanguage;

/* JADX INFO: loaded from: classes.dex */
public final class p implements v.e {

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private static final long f147m = D.u("AC-3");

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private static final long f148n = D.u("EAC3");

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private static final long f149o = D.u("HEVC");

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private static final long f150p = D.u("DTSH");

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final /* synthetic */ int f151q = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final n f152b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final int f153c;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private v.g f159i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private boolean f160j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private int f161k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    j f162l;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final t f154d = new t(940);

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final s f155e = new s(new byte[3]);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    final SparseArray f157g = new SparseArray();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    final SparseBooleanArray f158h = new SparseBooleanArray();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final SparseIntArray f156f = new SparseIntArray();

    private class a extends d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final t f163a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final s f164b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private int f165c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private int f166d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private int f167e;

        public a() {
            super();
            this.f163a = new t();
            this.f164b = new s(new byte[4]);
        }

        @Override // A.p.d
        public void a(t tVar, boolean z2, v.g gVar) {
            if (z2) {
                tVar.C(tVar.q());
                tVar.f(this.f164b, 3);
                this.f164b.l(12);
                this.f165c = this.f164b.e(12);
                this.f166d = 0;
                this.f167e = D.j(this.f164b.f3088a, 0, 3, -1);
                this.f163a.y(this.f165c);
            }
            int iMin = Math.min(tVar.a(), this.f165c - this.f166d);
            tVar.e(this.f163a.f3092a, this.f166d, iMin);
            int i2 = this.f166d + iMin;
            this.f166d = i2;
            int i3 = this.f165c;
            if (i2 >= i3 && D.j(this.f163a.f3092a, 0, i3, this.f167e) == 0) {
                this.f163a.C(5);
                int i4 = (this.f165c - 9) / 4;
                for (int i5 = 0; i5 < i4; i5++) {
                    this.f163a.f(this.f164b, 4);
                    int iE = this.f164b.e(16);
                    this.f164b.l(3);
                    if (iE == 0) {
                        this.f164b.l(13);
                    } else {
                        int iE2 = this.f164b.e(13);
                        p pVar = p.this;
                        pVar.f157g.put(iE2, pVar.new c(iE2));
                    }
                }
            }
        }

        @Override // A.p.d
        public void b() {
        }
    }

    private static final class b extends d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final e f169a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final n f170b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private final s f171c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private int f172d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private int f173e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private boolean f174f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private boolean f175g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private boolean f176h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private int f177i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        private int f178j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        private boolean f179k;

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        private long f180l;

        public b(e eVar, n nVar) {
            super();
            this.f169a = eVar;
            this.f170b = nVar;
            this.f171c = new s(new byte[10]);
            this.f172d = 0;
        }

        private boolean c(t tVar, byte[] bArr, int i2) {
            int iMin = Math.min(tVar.a(), i2 - this.f173e);
            if (iMin <= 0) {
                return true;
            }
            if (bArr == null) {
                tVar.C(iMin);
            } else {
                tVar.e(bArr, this.f173e, iMin);
            }
            int i3 = this.f173e + iMin;
            this.f173e = i3;
            return i3 == i2;
        }

        private boolean d() {
            this.f171c.k(0);
            int iE = this.f171c.e(24);
            if (iE != 1) {
                Log.w("TsExtractor", "Unexpected start code prefix: " + iE);
                this.f178j = -1;
                return false;
            }
            this.f171c.l(8);
            int iE2 = this.f171c.e(16);
            this.f171c.l(5);
            this.f179k = this.f171c.d();
            this.f171c.l(2);
            this.f174f = this.f171c.d();
            this.f175g = this.f171c.d();
            this.f171c.l(6);
            int iE3 = this.f171c.e(8);
            this.f177i = iE3;
            if (iE2 == 0) {
                this.f178j = -1;
            } else {
                this.f178j = (iE2 - 3) - iE3;
            }
            return true;
        }

        private void e() {
            this.f171c.k(0);
            this.f180l = -1L;
            if (this.f174f) {
                this.f171c.l(4);
                long jE = ((long) this.f171c.e(3)) << 30;
                this.f171c.l(1);
                long jE2 = jE | (((long) this.f171c.e(15)) << 15);
                this.f171c.l(1);
                long jE3 = jE2 | ((long) this.f171c.e(15));
                this.f171c.l(1);
                if (!this.f176h && this.f175g) {
                    this.f171c.l(4);
                    long jE4 = ((long) this.f171c.e(3)) << 30;
                    this.f171c.l(1);
                    long jE5 = jE4 | (((long) this.f171c.e(15)) << 15);
                    this.f171c.l(1);
                    long jE6 = jE5 | ((long) this.f171c.e(15));
                    this.f171c.l(1);
                    this.f170b.a(jE6);
                    this.f176h = true;
                }
                this.f180l = this.f170b.a(jE3);
            }
        }

        private void f(int i2) {
            this.f172d = i2;
            this.f173e = 0;
        }

        @Override // A.p.d
        public void a(t tVar, boolean z2, v.g gVar) {
            if (z2) {
                int i2 = this.f172d;
                if (i2 == 2) {
                    Log.w("TsExtractor", "Unexpected start indicator reading extended header");
                } else if (i2 == 3) {
                    if (this.f178j != -1) {
                        Log.w("TsExtractor", "Unexpected start indicator: expected " + this.f178j + " more bytes");
                    }
                    this.f169a.b();
                }
                f(1);
            }
            while (tVar.a() > 0) {
                int i3 = this.f172d;
                if (i3 != 0) {
                    if (i3 != 1) {
                        if (i3 == 2) {
                            if (c(tVar, this.f171c.f3088a, Math.min(10, this.f177i)) && c(tVar, null, this.f177i)) {
                                e();
                                this.f169a.c(this.f180l, this.f179k);
                                f(3);
                            }
                        } else if (i3 == 3) {
                            int iA = tVar.a();
                            int i4 = this.f178j;
                            int i5 = i4 != -1 ? iA - i4 : 0;
                            if (i5 > 0) {
                                iA -= i5;
                                tVar.A(tVar.c() + iA);
                            }
                            this.f169a.a(tVar);
                            int i6 = this.f178j;
                            if (i6 != -1) {
                                int i7 = i6 - iA;
                                this.f178j = i7;
                                if (i7 == 0) {
                                    this.f169a.b();
                                    f(1);
                                }
                            }
                        }
                    } else if (c(tVar, this.f171c.f3088a, 9)) {
                        f(d() ? 2 : 0);
                    }
                } else {
                    tVar.C(tVar.a());
                }
            }
        }

        @Override // A.p.d
        public void b() {
            this.f172d = 0;
            this.f173e = 0;
            this.f176h = false;
            this.f169a.d();
        }
    }

    private class c extends d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final s f181a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final t f182b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private final int f183c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private int f184d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private int f185e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private int f186f;

        public c(int i2) {
            super();
            this.f181a = new s(new byte[5]);
            this.f182b = new t();
            this.f183c = i2;
        }

        private int c(t tVar, int i2) {
            int iC = tVar.c() + i2;
            int i3 = -1;
            while (true) {
                if (tVar.c() >= iC) {
                    break;
                }
                int iQ = tVar.q();
                int iQ2 = tVar.q();
                if (iQ == 5) {
                    long jS = tVar.s();
                    if (jS == p.f147m) {
                        i3 = 129;
                    } else if (jS == p.f148n) {
                        i3 = 135;
                    } else if (jS == p.f149o) {
                        i3 = 36;
                    }
                } else {
                    if (iQ == 106) {
                        i3 = 129;
                    } else if (iQ == 122) {
                        i3 = 135;
                    } else if (iQ == 123) {
                        i3 = 138;
                    }
                    tVar.C(iQ2);
                }
            }
            tVar.B(iC);
            return i3;
        }

        /* JADX WARN: Removed duplicated region for block: B:56:0x0177  */
        @Override // A.p.d
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void a(b0.t r17, boolean r18, v.g r19) {
            /*
                Method dump skipped, instruction units count: 661
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: A.p.c.a(b0.t, boolean, v.g):void");
        }

        @Override // A.p.d
        public void b() {
        }
    }

    private static abstract class d {
        private d() {
        }

        public abstract void a(t tVar, boolean z2, v.g gVar);

        public abstract void b();
    }

    public p(n nVar, int i2) {
        this.f152b = nVar;
        this.f153c = i2;
        n();
    }

    private void n() {
        this.f158h.clear();
        this.f157g.clear();
        this.f157g.put(0, new a());
        this.f162l = null;
        this.f161k = 8192;
    }

    @Override // v.e
    public int a(v.f fVar, v.j jVar) {
        boolean z2;
        d dVar;
        t tVar = this.f154d;
        byte[] bArr = tVar.f3092a;
        if (940 - tVar.c() < 188) {
            int iA = this.f154d.a();
            if (iA > 0) {
                System.arraycopy(bArr, this.f154d.c(), bArr, 0, iA);
            }
            this.f154d.z(bArr, iA);
        }
        while (this.f154d.a() < 188) {
            int iD = this.f154d.d();
            int i2 = fVar.read(bArr, iD, 940 - iD);
            if (i2 == -1) {
                return -1;
            }
            this.f154d.A(iD + i2);
        }
        int iD2 = this.f154d.d();
        int iC = this.f154d.c();
        while (iC < iD2 && bArr[iC] != 71) {
            iC++;
        }
        this.f154d.B(iC);
        int i3 = iC + TvLanguage.GEEZ;
        if (i3 > iD2) {
            return 0;
        }
        this.f154d.C(1);
        this.f154d.f(this.f155e, 3);
        if (this.f155e.d()) {
            this.f154d.B(i3);
            return 0;
        }
        boolean zD = this.f155e.d();
        this.f155e.l(1);
        int iE = this.f155e.e(13);
        this.f155e.l(2);
        boolean zD2 = this.f155e.d();
        boolean zD3 = this.f155e.d();
        int iE2 = this.f155e.e(4);
        if ((this.f153c & 16) == 0) {
            int i4 = this.f156f.get(iE, iE2 - 1);
            this.f156f.put(iE, iE2);
            if (i4 == iE2) {
                if (zD3) {
                    this.f154d.B(i3);
                    return 0;
                }
            } else if (iE2 != (i4 + 1) % 16) {
                z2 = true;
            }
            z2 = false;
        } else {
            z2 = false;
        }
        if (zD2) {
            this.f154d.C(this.f154d.q());
        }
        if (zD3 && (dVar = (d) this.f157g.get(iE)) != null) {
            if (z2) {
                dVar.b();
            }
            this.f154d.A(i3);
            dVar.a(this.f154d, zD, this.f159i);
            AbstractC0399d.e(this.f154d.c() <= i3);
            this.f154d.A(iD2);
        }
        this.f154d.B(i3);
        return 0;
    }

    @Override // v.e
    public void e(v.g gVar) {
        this.f159i = gVar;
        gVar.b(v.m.f6657a);
    }

    @Override // v.e
    public void f() {
        this.f152b.d();
        this.f154d.x();
        this.f156f.clear();
        n();
    }

    /* JADX WARN: Code restructure failed: missing block: B:12:0x0021, code lost:
    
        r1 = r1 + 1;
     */
    @Override // v.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean g(v.f r7) {
        /*
            r6 = this;
            b0.t r0 = r6.f154d
            byte[] r0 = r0.f3092a
            r1 = 940(0x3ac, float:1.317E-42)
            r2 = 0
            r7.i(r0, r2, r1)
            r1 = r2
        Lb:
            r3 = 188(0xbc, float:2.63E-43)
            if (r1 >= r3) goto L27
            r3 = r2
        L10:
            r4 = 5
            if (r3 != r4) goto L18
            r7.h(r1)
            r7 = 1
            return r7
        L18:
            int r4 = r3 * 188
            int r4 = r4 + r1
            r4 = r0[r4]
            r5 = 71
            if (r4 == r5) goto L24
            int r1 = r1 + 1
            goto Lb
        L24:
            int r3 = r3 + 1
            goto L10
        L27:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: A.p.g(v.f):boolean");
    }

    @Override // v.e
    public void release() {
    }
}
