package A;

import android.util.SparseArray;
import b0.r;
import b0.s;
import b0.t;
import java.util.ArrayList;
import java.util.Arrays;
import n.x;

/* JADX INFO: loaded from: classes.dex */
final class g extends e {

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final boolean[] f57d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final l f59f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final l f60g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final l f61h;

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

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

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

    private static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final v.o f65a;

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

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

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

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

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

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

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

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        private C0000a f77m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        private C0000a f78n;

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

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

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

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

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

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

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

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private byte[] f71g = new byte[128];

        /* JADX INFO: renamed from: A.g$a$a, reason: collision with other inner class name */
        private static final class C0000a {

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

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

            /* JADX INFO: renamed from: c, reason: collision with root package name */
            private r.b f85c;

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

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

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

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

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

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

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

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

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

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

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

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

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

            private C0000a() {
            }

            /* JADX INFO: Access modifiers changed from: private */
            public boolean c(C0000a c0000a) {
                boolean z2;
                boolean z3;
                if (this.f83a) {
                    if (!c0000a.f83a || this.f88f != c0000a.f88f || this.f89g != c0000a.f89g || this.f90h != c0000a.f90h) {
                        return true;
                    }
                    if (this.f91i && c0000a.f91i && this.f92j != c0000a.f92j) {
                        return true;
                    }
                    int i2 = this.f86d;
                    int i3 = c0000a.f86d;
                    if (i2 != i3 && (i2 == 0 || i3 == 0)) {
                        return true;
                    }
                    int i4 = this.f85c.f3085h;
                    if (i4 == 0 && c0000a.f85c.f3085h == 0 && (this.f95m != c0000a.f95m || this.f96n != c0000a.f96n)) {
                        return true;
                    }
                    if ((i4 == 1 && c0000a.f85c.f3085h == 1 && (this.f97o != c0000a.f97o || this.f98p != c0000a.f98p)) || (z2 = this.f93k) != (z3 = c0000a.f93k)) {
                        return true;
                    }
                    if (z2 && z3 && this.f94l != c0000a.f94l) {
                        return true;
                    }
                }
                return false;
            }

            public void b() {
                this.f84b = false;
                this.f83a = false;
            }

            public boolean d() {
                int i2;
                return this.f84b && ((i2 = this.f87e) == 7 || i2 == 2);
            }

            public void e(r.b bVar, int i2, int i3, int i4, int i5, boolean z2, boolean z3, boolean z4, boolean z5, int i6, int i7, int i8, int i9, int i10) {
                this.f85c = bVar;
                this.f86d = i2;
                this.f87e = i3;
                this.f88f = i4;
                this.f89g = i5;
                this.f90h = z2;
                this.f91i = z3;
                this.f92j = z4;
                this.f93k = z5;
                this.f94l = i6;
                this.f95m = i7;
                this.f96n = i8;
                this.f97o = i9;
                this.f98p = i10;
                this.f83a = true;
                this.f84b = true;
            }

            public void f(int i2) {
                this.f87e = i2;
                this.f84b = true;
            }
        }

        public a(v.o oVar, boolean z2, boolean z3) {
            this.f65a = oVar;
            this.f66b = z2;
            this.f67c = z3;
            this.f77m = new C0000a();
            this.f78n = new C0000a();
            g();
        }

        /* JADX WARN: Type inference fix 'apply assigned field type' failed
        java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
        	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
        	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
        	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
         */
        private void d(int i2) {
            boolean z2 = this.f82r;
            this.f65a.e(this.f81q, z2 ? 1 : 0, (int) (this.f74j - this.f80p), i2, null);
        }

        public void a(byte[] bArr, int i2, int i3) {
            boolean z2;
            boolean z3;
            boolean zD;
            int iH;
            int i4;
            int iG;
            int i5;
            int iG2;
            if (this.f75k) {
                int i6 = i3 - i2;
                byte[] bArr2 = this.f71g;
                int length = bArr2.length;
                int i7 = this.f72h;
                if (length < i7 + i6) {
                    this.f71g = Arrays.copyOf(bArr2, (i7 + i6) * 2);
                }
                System.arraycopy(bArr, i2, this.f71g, this.f72h, i6);
                int i8 = this.f72h + i6;
                this.f72h = i8;
                this.f68d.j(this.f71g, i8);
                if (this.f68d.b() < 8) {
                    return;
                }
                this.f68d.l(1);
                int iE = this.f68d.e(2);
                this.f68d.l(5);
                if (this.f68d.c()) {
                    this.f68d.h();
                    if (this.f68d.c()) {
                        int iH2 = this.f68d.h();
                        if (!this.f67c) {
                            this.f75k = false;
                            this.f78n.f(iH2);
                            return;
                        }
                        if (this.f68d.c()) {
                            int iH3 = this.f68d.h();
                            if (this.f70f.indexOfKey(iH3) < 0) {
                                this.f75k = false;
                                return;
                            }
                            r.a aVar = (r.a) this.f70f.get(iH3);
                            r.b bVar = (r.b) this.f69e.get(aVar.f3076b);
                            if (bVar.f3082e) {
                                if (this.f68d.b() < 2) {
                                    return;
                                } else {
                                    this.f68d.l(2);
                                }
                            }
                            int iB = this.f68d.b();
                            int i9 = bVar.f3084g;
                            if (iB < i9) {
                                return;
                            }
                            int iE2 = this.f68d.e(i9);
                            if (bVar.f3083f) {
                                z2 = false;
                                z3 = false;
                                zD = false;
                            } else {
                                if (this.f68d.b() < 1) {
                                    return;
                                }
                                boolean zD2 = this.f68d.d();
                                if (!zD2) {
                                    z3 = false;
                                    zD = false;
                                    z2 = zD2;
                                } else {
                                    if (this.f68d.b() < 1) {
                                        return;
                                    }
                                    z3 = true;
                                    z2 = zD2;
                                    zD = this.f68d.d();
                                }
                            }
                            boolean z4 = this.f73i == 5;
                            if (!z4) {
                                iH = 0;
                            } else if (!this.f68d.c()) {
                                return;
                            } else {
                                iH = this.f68d.h();
                            }
                            int i10 = bVar.f3085h;
                            if (i10 == 0) {
                                int iB2 = this.f68d.b();
                                int i11 = bVar.f3086i;
                                if (iB2 < i11) {
                                    return;
                                }
                                int iE3 = this.f68d.e(i11);
                                if (aVar.f3077c && !z2) {
                                    if (this.f68d.c()) {
                                        iG = this.f68d.g();
                                        i4 = iE3;
                                        i5 = 0;
                                        iG2 = i5;
                                        this.f78n.e(bVar, iE, iH2, iE2, iH3, z2, z3, zD, z4, iH, i4, iG, i5, iG2);
                                        this.f75k = false;
                                    }
                                    return;
                                }
                                i4 = iE3;
                                iG = 0;
                            } else {
                                if (i10 == 1 && !bVar.f3087j) {
                                    if (this.f68d.c()) {
                                        int iG3 = this.f68d.g();
                                        if (!aVar.f3077c || z2) {
                                            i5 = iG3;
                                            i4 = 0;
                                            iG = 0;
                                            iG2 = 0;
                                        } else {
                                            if (!this.f68d.c()) {
                                                return;
                                            }
                                            iG2 = this.f68d.g();
                                            i5 = iG3;
                                            i4 = 0;
                                            iG = 0;
                                        }
                                        this.f78n.e(bVar, iE, iH2, iE2, iH3, z2, z3, zD, z4, iH, i4, iG, i5, iG2);
                                        this.f75k = false;
                                    }
                                    return;
                                }
                                i4 = 0;
                                iG = 0;
                            }
                            i5 = iG;
                            iG2 = i5;
                            this.f78n.e(bVar, iE, iH2, iE2, iH3, z2, z3, zD, z4, iH, i4, iG, i5, iG2);
                            this.f75k = false;
                        }
                    }
                }
            }
        }

        public void b(long j2, int i2) {
            boolean z2 = false;
            if (this.f73i == 9 || (this.f67c && this.f78n.c(this.f77m))) {
                if (this.f79o) {
                    d(i2 + ((int) (j2 - this.f74j)));
                }
                this.f80p = this.f74j;
                this.f81q = this.f76l;
                this.f82r = false;
                this.f79o = true;
            }
            boolean z3 = this.f82r;
            int i3 = this.f73i;
            if (i3 == 5 || (this.f66b && i3 == 1 && this.f78n.d())) {
                z2 = true;
            }
            this.f82r = z3 | z2;
        }

        public boolean c() {
            return this.f67c;
        }

        public void e(r.a aVar) {
            this.f70f.append(aVar.f3075a, aVar);
        }

        public void f(r.b bVar) {
            this.f69e.append(bVar.f3078a, bVar);
        }

        public void g() {
            this.f75k = false;
            this.f79o = false;
            this.f78n.b();
        }

        public void h(long j2, int i2, long j3) {
            this.f73i = i2;
            this.f76l = j3;
            this.f74j = j2;
            if (!this.f66b || i2 != 1) {
                if (!this.f67c) {
                    return;
                }
                if (i2 != 5 && i2 != 1 && i2 != 2) {
                    return;
                }
            }
            C0000a c0000a = this.f77m;
            this.f77m = this.f78n;
            this.f78n = c0000a;
            c0000a.b();
            this.f72h = 0;
            this.f75k = true;
        }
    }

    public g(v.o oVar, o oVar2, boolean z2, boolean z3) {
        super(oVar);
        this.f56c = oVar2;
        this.f57d = new boolean[3];
        this.f58e = new a(oVar, z2, z3);
        this.f59f = new l(7, 128);
        this.f60g = new l(8, 128);
        this.f61h = new l(6, 128);
        this.f64k = new t();
    }

    private void e(long j2, int i2, int i3, long j3) {
        if (!this.f55b || this.f58e.c()) {
            this.f59f.b(i3);
            this.f60g.b(i3);
            if (this.f55b) {
                if (this.f59f.c()) {
                    this.f58e.f(r.i(h(this.f59f)));
                    this.f59f.d();
                } else if (this.f60g.c()) {
                    this.f58e.e(r.h(h(this.f60g)));
                    this.f60g.d();
                }
            } else if (this.f59f.c() && this.f60g.c()) {
                ArrayList arrayList = new ArrayList();
                l lVar = this.f59f;
                arrayList.add(Arrays.copyOf(lVar.f141d, lVar.f142e));
                l lVar2 = this.f60g;
                arrayList.add(Arrays.copyOf(lVar2.f141d, lVar2.f142e));
                r.b bVarI = r.i(h(this.f59f));
                r.a aVarH = r.h(h(this.f60g));
                this.f38a.c(x.p(null, "video/avc", -1, -1, -1L, bVarI.f3079b, bVarI.f3080c, arrayList, -1, bVarI.f3081d));
                this.f55b = true;
                this.f58e.f(bVarI);
                this.f58e.e(aVarH);
                this.f59f.d();
                this.f60g.d();
            }
        }
        if (this.f61h.b(i3)) {
            l lVar3 = this.f61h;
            this.f64k.z(this.f61h.f141d, r.k(lVar3.f141d, lVar3.f142e));
            this.f64k.B(4);
            this.f56c.a(j3, this.f64k);
        }
        this.f58e.b(j2, i2);
    }

    private void f(byte[] bArr, int i2, int i3) {
        if (!this.f55b || this.f58e.c()) {
            this.f59f.a(bArr, i2, i3);
            this.f60g.a(bArr, i2, i3);
        }
        this.f61h.a(bArr, i2, i3);
        this.f58e.a(bArr, i2, i3);
    }

    private void g(long j2, int i2, long j3) {
        if (!this.f55b || this.f58e.c()) {
            this.f59f.e(i2);
            this.f60g.e(i2);
        }
        this.f61h.e(i2);
        this.f58e.h(j2, i2, j3);
    }

    private static s h(l lVar) {
        s sVar = new s(lVar.f141d, r.k(lVar.f141d, lVar.f142e));
        sVar.l(32);
        return sVar;
    }

    @Override // A.e
    public void a(t tVar) {
        if (tVar.a() <= 0) {
            return;
        }
        int iC = tVar.c();
        int iD = tVar.d();
        byte[] bArr = tVar.f3092a;
        this.f62i += (long) tVar.a();
        this.f38a.a(tVar, tVar.a());
        while (true) {
            int iC2 = r.c(bArr, iC, iD, this.f57d);
            if (iC2 == iD) {
                f(bArr, iC, iD);
                return;
            }
            int iF = r.f(bArr, iC2);
            int i2 = iC2 - iC;
            if (i2 > 0) {
                f(bArr, iC, iC2);
            }
            int i3 = iD - iC2;
            long j2 = this.f62i - ((long) i3);
            e(j2, i3, i2 < 0 ? -i2 : 0, this.f63j);
            g(j2, iF, this.f63j);
            iC = iC2 + 3;
        }
    }

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

    @Override // A.e
    public void c(long j2, boolean z2) {
        this.f63j = j2;
    }

    @Override // A.e
    public void d() {
        r.a(this.f57d);
        this.f59f.d();
        this.f60g.d();
        this.f61h.d();
        this.f58e.g();
        this.f62i = 0L;
    }
}
