package A1;

import N1.C0198b;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.Arrays;
import u0.C1570f;
import u0.C1578n;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class q implements InterfaceC0008i {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final y f260a;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public long f266g;
    public String i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public T0.F f268j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public p f269k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public boolean f270l;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f272n;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean[] f267h = new boolean[3];

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final x f263d = new x(7);

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final x f264e = new x(8);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final x f265f = new x(6);

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public long f271m = -9223372036854775807L;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final x0.o f273o = new x0.o();

    public q(y yVar, boolean z8, boolean z9) {
        this.f260a = yVar;
        this.f261b = z8;
        this.f262c = z9;
    }

    @Override // A1.InterfaceC0008i
    public final void a() {
        this.f266g = 0L;
        this.f272n = false;
        this.f271m = -9223372036854775807L;
        y0.o.b(this.f267h);
        this.f263d.g();
        this.f264e.g();
        this.f265f.g();
        ((C0198b) this.f260a.f365t).j(0);
        p pVar = this.f269k;
        if (pVar != null) {
            pVar.f251k = false;
            pVar.f255o = false;
            o oVar = pVar.f254n;
            oVar.f228b = false;
            oVar.f227a = false;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:76:0x021b  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0019  */
    /* 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)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b(int i, int i5, long j8, long j9) {
        int i8;
        boolean z8;
        int i9;
        int i10;
        int i11;
        boolean z9;
        boolean z10 = this.f270l;
        boolean z11 = true;
        C0198b c0198b = (C0198b) this.f260a.f365t;
        if (!z10 || this.f269k.f244c) {
            x xVar = this.f263d;
            xVar.e(i5);
            x xVar2 = this.f264e;
            xVar2.e(i5);
            if (this.f270l) {
                i8 = 2;
                if (xVar.f359d) {
                    y0.n nVarK = y0.o.k((byte[]) xVar.f361f, 3, xVar.f360e);
                    c0198b.getClass();
                    int i12 = nVarK.f18869s;
                    AbstractC1709a.j(i12 >= 0);
                    c0198b.f4504a = i12;
                    c0198b.j(i12);
                    this.f269k.f245d.append(nVarK.f18855d, nVarK);
                    xVar.g();
                } else if (xVar2.f359d) {
                    T0.H h8 = new T0.H((byte[]) xVar2.f361f, 4, xVar2.f360e);
                    int iM = h8.m();
                    int iM2 = h8.m();
                    h8.s();
                    this.f269k.f246e.append(iM, new y0.m(iM, iM2, h8.h()));
                    xVar2.g();
                }
            } else if (xVar.f359d && xVar2.f359d) {
                ArrayList arrayList = new ArrayList();
                arrayList.add(Arrays.copyOf((byte[]) xVar.f361f, xVar.f360e));
                arrayList.add(Arrays.copyOf((byte[]) xVar2.f361f, xVar2.f360e));
                y0.n nVarK2 = y0.o.k((byte[]) xVar.f361f, 3, xVar.f360e);
                T0.H h9 = new T0.H((byte[]) xVar2.f361f, 4, xVar2.f360e);
                int iM3 = h9.m();
                int iM4 = h9.m();
                h9.s();
                y0.m mVar = new y0.m(iM3, iM4, h9.h());
                byte[] bArr = x0.b.f18499a;
                i8 = 2;
                String str = String.format("avc1.%02X%02X%02X", Integer.valueOf(nVarK2.f18852a), Integer.valueOf(nVarK2.f18853b), Integer.valueOf(nVarK2.f18854c));
                T0.F f3 = this.f268j;
                C1578n c1578n = new C1578n();
                c1578n.f17309a = this.i;
                c1578n.f17319l = u0.E.m("video/mp2t");
                c1578n.f17320m = u0.E.m("video/avc");
                c1578n.f17317j = str;
                c1578n.f17327t = nVarK2.f18856e;
                c1578n.f17328u = nVarK2.f18857f;
                c1578n.f17299A = new C1570f(nVarK2.f18866p, nVarK2.f18867q, nVarK2.f18868r, nVarK2.f18859h + 8, nVarK2.i + 8, null);
                c1578n.f17331x = nVarK2.f18858g;
                c1578n.f17323p = arrayList;
                int i13 = nVarK2.f18869s;
                c1578n.f17322o = i13;
                I1.a.w(c1578n, f3);
                this.f270l = true;
                c0198b.getClass();
                AbstractC1709a.j(i13 >= 0);
                c0198b.f4504a = i13;
                c0198b.j(i13);
                this.f269k.f245d.append(nVarK2.f18855d, nVarK2);
                this.f269k.f246e.append(iM3, mVar);
                xVar.g();
                xVar2.g();
            } else {
                i8 = 2;
            }
        }
        x xVar3 = this.f265f;
        if (xVar3.e(i5)) {
            int iN = y0.o.n(xVar3.f360e, (byte[]) xVar3.f361f);
            byte[] bArr2 = (byte[]) xVar3.f361f;
            x0.o oVar = this.f273o;
            oVar.D(iN, bArr2);
            oVar.F(4);
            c0198b.a(j9, oVar);
        }
        p pVar = this.f269k;
        boolean z12 = this.f270l;
        if (pVar.i == 9) {
            if (z12 && pVar.f255o) {
                long j10 = pVar.f250j;
                int i14 = i + ((int) (j8 - j10));
                long j11 = pVar.f257q;
                if (j11 != -9223372036854775807L) {
                    long j12 = pVar.f256p;
                    if (j10 != j12) {
                        pVar.f242a.a(j11, pVar.f258r ? 1 : 0, (int) (j10 - j12), i14, null);
                    }
                }
            }
            pVar.f256p = pVar.f250j;
            pVar.f257q = pVar.f252l;
            pVar.f258r = false;
            pVar.f255o = true;
        } else if (pVar.f244c) {
            o oVar2 = pVar.f254n;
            o oVar3 = pVar.f253m;
            if (oVar2.f227a) {
                if (oVar3.f227a) {
                    y0.n nVar = oVar2.f229c;
                    AbstractC1709a.k(nVar);
                    y0.n nVar2 = oVar3.f229c;
                    AbstractC1709a.k(nVar2);
                    if (oVar2.f232f == oVar3.f232f && oVar2.f233g == oVar3.f233g && oVar2.f234h == oVar3.f234h && ((!oVar2.i || !oVar3.i || oVar2.f235j == oVar3.f235j) && ((i10 = oVar2.f230d) == (i11 = oVar3.f230d) || (i10 != 0 && i11 != 0)))) {
                        int i15 = nVar2.f18863m;
                        int i16 = nVar.f18863m;
                        if ((i16 == 0 && i15 == 0 && (oVar2.f238m != oVar3.f238m || oVar2.f239n != oVar3.f239n)) || ((i16 == 1 && i15 == 1 && (oVar2.f240o != oVar3.f240o || oVar2.f241p != oVar3.f241p)) || (z9 = oVar2.f236k) != oVar3.f236k || (z9 && oVar2.f237l != oVar3.f237l))) {
                        }
                    }
                }
            }
        }
        if (pVar.f243b) {
            o oVar4 = pVar.f254n;
            z8 = oVar4.f228b && ((i9 = oVar4.f231e) == 7 || i9 == i8);
        } else {
            z8 = pVar.f259s;
        }
        boolean z13 = pVar.f258r;
        int i17 = pVar.i;
        if (i17 != 5 && (!z8 || i17 != 1)) {
            z11 = false;
        }
        boolean z14 = z13 | z11;
        pVar.f258r = z14;
        pVar.i = 24;
        if (z14) {
            this.f272n = false;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:58:0x00fe  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0100  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0103  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x010f  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0116  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x013a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void c(byte[] bArr, int i, int i5) {
        boolean zH;
        boolean zH2;
        boolean z8;
        boolean z9;
        int iM;
        int i8;
        int i9;
        int i10;
        int iN;
        int iN2;
        if (!this.f270l || this.f269k.f244c) {
            this.f263d.a(bArr, i, i5);
            this.f264e.a(bArr, i, i5);
        }
        this.f265f.a(bArr, i, i5);
        p pVar = this.f269k;
        if (pVar.f251k) {
            int i11 = i5 - i;
            byte[] bArr2 = pVar.f248g;
            int length = bArr2.length;
            int i12 = pVar.f249h + i11;
            if (length < i12) {
                pVar.f248g = Arrays.copyOf(bArr2, i12 * 2);
            }
            System.arraycopy(bArr, i, pVar.f248g, pVar.f249h, i11);
            int i13 = pVar.f249h + i11;
            pVar.f249h = i13;
            byte[] bArr3 = pVar.f248g;
            T0.H h8 = pVar.f247f;
            h8.f6361d = bArr3;
            h8.f6360c = 0;
            h8.f6359b = i13;
            h8.f6362e = 0;
            h8.a();
            if (h8.d(8)) {
                h8.s();
                int i14 = h8.i(2);
                h8.t(5);
                if (h8.e()) {
                    h8.m();
                    if (h8.e()) {
                        int iM2 = h8.m();
                        if (!pVar.f244c) {
                            pVar.f251k = false;
                            o oVar = pVar.f254n;
                            oVar.f231e = iM2;
                            oVar.f228b = true;
                            return;
                        }
                        if (h8.e()) {
                            int iM3 = h8.m();
                            SparseArray sparseArray = pVar.f246e;
                            if (sparseArray.indexOfKey(iM3) < 0) {
                                pVar.f251k = false;
                                return;
                            }
                            y0.m mVar = (y0.m) sparseArray.get(iM3);
                            y0.n nVar = (y0.n) pVar.f245d.get(mVar.f18850a);
                            if (nVar.f18860j) {
                                if (!h8.d(2)) {
                                    return;
                                } else {
                                    h8.t(2);
                                }
                            }
                            int i15 = nVar.f18862l;
                            if (h8.d(i15)) {
                                int i16 = h8.i(i15);
                                if (nVar.f18861k) {
                                    zH = false;
                                    zH2 = false;
                                } else {
                                    if (!h8.d(1)) {
                                        return;
                                    }
                                    zH = h8.h();
                                    if (zH) {
                                        if (h8.d(1)) {
                                            zH2 = h8.h();
                                            z8 = true;
                                            z9 = pVar.i != 5;
                                            if (z9) {
                                                iM = 0;
                                            } else if (!h8.e()) {
                                                return;
                                            } else {
                                                iM = h8.m();
                                            }
                                            boolean z10 = mVar.f18851b;
                                            i8 = nVar.f18863m;
                                            if (i8 != 0) {
                                                int i17 = nVar.f18864n;
                                                if (!h8.d(i17)) {
                                                    return;
                                                }
                                                i9 = h8.i(i17);
                                                if (z10 && !zH) {
                                                    if (h8.e()) {
                                                        iN2 = h8.n();
                                                        i10 = 0;
                                                        iN = 0;
                                                        o oVar2 = pVar.f254n;
                                                        oVar2.f229c = nVar;
                                                        oVar2.f230d = i14;
                                                        oVar2.f231e = iM2;
                                                        oVar2.f232f = i16;
                                                        oVar2.f233g = iM3;
                                                        oVar2.f234h = zH;
                                                        oVar2.i = z8;
                                                        oVar2.f235j = zH2;
                                                        oVar2.f236k = z9;
                                                        oVar2.f237l = iM;
                                                        oVar2.f238m = i9;
                                                        oVar2.f239n = iN2;
                                                        oVar2.f240o = i10;
                                                        oVar2.f241p = iN;
                                                        oVar2.f227a = true;
                                                        oVar2.f228b = true;
                                                        pVar.f251k = false;
                                                    }
                                                    return;
                                                }
                                                i10 = 0;
                                            } else if (i8 != 1 || nVar.f18865o) {
                                                i9 = 0;
                                                i10 = 0;
                                            } else {
                                                if (!h8.e()) {
                                                    return;
                                                }
                                                int iN3 = h8.n();
                                                if (z10 && !zH) {
                                                    if (h8.e()) {
                                                        iN = h8.n();
                                                        iN2 = 0;
                                                        i10 = iN3;
                                                        i9 = 0;
                                                        o oVar22 = pVar.f254n;
                                                        oVar22.f229c = nVar;
                                                        oVar22.f230d = i14;
                                                        oVar22.f231e = iM2;
                                                        oVar22.f232f = i16;
                                                        oVar22.f233g = iM3;
                                                        oVar22.f234h = zH;
                                                        oVar22.i = z8;
                                                        oVar22.f235j = zH2;
                                                        oVar22.f236k = z9;
                                                        oVar22.f237l = iM;
                                                        oVar22.f238m = i9;
                                                        oVar22.f239n = iN2;
                                                        oVar22.f240o = i10;
                                                        oVar22.f241p = iN;
                                                        oVar22.f227a = true;
                                                        oVar22.f228b = true;
                                                        pVar.f251k = false;
                                                    }
                                                    return;
                                                }
                                                i10 = iN3;
                                                i9 = 0;
                                            }
                                            iN = 0;
                                            iN2 = 0;
                                            o oVar222 = pVar.f254n;
                                            oVar222.f229c = nVar;
                                            oVar222.f230d = i14;
                                            oVar222.f231e = iM2;
                                            oVar222.f232f = i16;
                                            oVar222.f233g = iM3;
                                            oVar222.f234h = zH;
                                            oVar222.i = z8;
                                            oVar222.f235j = zH2;
                                            oVar222.f236k = z9;
                                            oVar222.f237l = iM;
                                            oVar222.f238m = i9;
                                            oVar222.f239n = iN2;
                                            oVar222.f240o = i10;
                                            oVar222.f241p = iN;
                                            oVar222.f227a = true;
                                            oVar222.f228b = true;
                                            pVar.f251k = false;
                                        }
                                        return;
                                    }
                                    zH2 = false;
                                }
                                z8 = zH2;
                                if (pVar.i != 5) {
                                }
                                if (z9) {
                                }
                                boolean z102 = mVar.f18851b;
                                i8 = nVar.f18863m;
                                if (i8 != 0) {
                                }
                                iN = 0;
                                iN2 = 0;
                                o oVar2222 = pVar.f254n;
                                oVar2222.f229c = nVar;
                                oVar2222.f230d = i14;
                                oVar2222.f231e = iM2;
                                oVar2222.f232f = i16;
                                oVar2222.f233g = iM3;
                                oVar2222.f234h = zH;
                                oVar2222.i = z8;
                                oVar2222.f235j = zH2;
                                oVar2222.f236k = z9;
                                oVar2222.f237l = iM;
                                oVar2222.f238m = i9;
                                oVar2222.f239n = iN2;
                                oVar2222.f240o = i10;
                                oVar2222.f241p = iN;
                                oVar2222.f227a = true;
                                oVar2222.f228b = true;
                                pVar.f251k = false;
                            }
                        }
                    }
                }
            }
        }
    }

    public final void d(int i, long j8, long j9) {
        if (!this.f270l || this.f269k.f244c) {
            this.f263d.h(i);
            this.f264e.h(i);
        }
        this.f265f.h(i);
        p pVar = this.f269k;
        boolean z8 = this.f272n;
        pVar.i = i;
        pVar.f252l = j9;
        pVar.f250j = j8;
        pVar.f259s = z8;
        if (!pVar.f243b || i != 1) {
            if (!pVar.f244c) {
                return;
            }
            if (i != 5 && i != 1 && i != 2) {
                return;
            }
        }
        o oVar = pVar.f253m;
        pVar.f253m = pVar.f254n;
        pVar.f254n = oVar;
        oVar.f228b = false;
        oVar.f227a = false;
        pVar.f249h = 0;
        pVar.f251k = true;
    }

    @Override // A1.InterfaceC0008i
    public final void e(x0.o oVar) {
        int i;
        AbstractC1709a.k(this.f268j);
        int i5 = x0.v.f18553a;
        int i8 = oVar.f18540b;
        int i9 = oVar.f18541c;
        byte[] bArr = oVar.f18539a;
        this.f266g += (long) oVar.a();
        this.f268j.c(oVar.a(), oVar);
        while (true) {
            int iC = y0.o.c(bArr, i8, i9, this.f267h);
            if (iC == i9) {
                c(bArr, i8, i9);
                return;
            }
            int i10 = bArr[iC + 3] & 31;
            if (iC <= 0 || bArr[iC - 1] != 0) {
                i = 3;
            } else {
                iC--;
                i = 4;
            }
            int i11 = iC - i8;
            if (i11 > 0) {
                c(bArr, i8, iC);
            }
            int i12 = i9 - iC;
            long j8 = this.f266g - ((long) i12);
            b(i12, i11 < 0 ? -i11 : 0, j8, this.f271m);
            d(i10, j8, this.f271m);
            i8 = iC + i;
        }
    }

    @Override // A1.InterfaceC0008i
    public final void f(boolean z8) {
        AbstractC1709a.k(this.f268j);
        int i = x0.v.f18553a;
        if (z8) {
            ((C0198b) this.f260a.f365t).j(0);
            b(0, 0, this.f266g, this.f271m);
            d(9, this.f266g, this.f271m);
            b(0, 0, this.f266g, this.f271m);
        }
    }

    @Override // A1.InterfaceC0008i
    public final void g(T0.o oVar, M m8) {
        m8.a();
        m8.b();
        this.i = m8.f103e;
        m8.b();
        T0.F fJ = oVar.j(m8.f102d, 2);
        this.f268j = fJ;
        this.f269k = new p(fJ, this.f261b, this.f262c);
        this.f260a.o(oVar, m8);
    }

    @Override // A1.InterfaceC0008i
    public final void h(long j8, int i) {
        this.f271m = j8;
        this.f272n |= (i & 2) != 0;
    }
}
