package A1;

import N1.C0198b;
import java.util.Collections;
import u0.C1570f;
import u0.C1578n;
import u0.C1579o;
import x0.AbstractC1709a;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public String f287b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public r f289d;

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final x f292g = new x(32);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final x f293h = new x(33);
    public final x i = new x(34);

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final x f294j = new x(39);

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final x f295k = new x(40);

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

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

    public s(y yVar) {
        this.f286a = yVar;
    }

    @Override // A1.InterfaceC0008i
    public final void a() {
        this.f296l = 0L;
        this.f297m = -9223372036854775807L;
        y0.o.b(this.f291f);
        this.f292g.g();
        this.f293h.g();
        this.i.g();
        this.f294j.g();
        this.f295k.g();
        ((C0198b) this.f286a.f365t).j(0);
        r rVar = this.f289d;
        if (rVar != null) {
            rVar.f279f = false;
            rVar.f280g = false;
            rVar.f281h = false;
            rVar.i = false;
            rVar.f282j = false;
        }
    }

    public final void b(int i, int i5, long j8, long j9) {
        r rVar = this.f289d;
        boolean z8 = this.f290e;
        if (rVar.f282j && rVar.f280g) {
            rVar.f285m = rVar.f276c;
            rVar.f282j = false;
        } else if (rVar.f281h || rVar.f280g) {
            if (z8 && rVar.i) {
                rVar.a(i + ((int) (j8 - rVar.f275b)));
            }
            rVar.f283k = rVar.f275b;
            rVar.f284l = rVar.f278e;
            rVar.f285m = rVar.f276c;
            rVar.i = true;
        }
        boolean z9 = this.f290e;
        C0198b c0198b = (C0198b) this.f286a.f365t;
        if (!z9) {
            x xVar = this.f292g;
            xVar.e(i5);
            x xVar2 = this.f293h;
            xVar2.e(i5);
            x xVar3 = this.i;
            xVar3.e(i5);
            if (xVar.f359d && xVar2.f359d && xVar3.f359d) {
                String str = this.f287b;
                int i8 = xVar.f360e;
                byte[] bArr = new byte[xVar2.f360e + i8 + xVar3.f360e];
                System.arraycopy((byte[]) xVar.f361f, 0, bArr, 0, i8);
                System.arraycopy((byte[]) xVar2.f361f, 0, bArr, xVar.f360e, xVar2.f360e);
                System.arraycopy((byte[]) xVar3.f361f, 0, bArr, xVar.f360e + xVar2.f360e, xVar3.f360e);
                y0.k kVarI = y0.o.i((byte[]) xVar2.f361f, 3, xVar2.f360e, null);
                y0.h hVar = kVarI.f18838b;
                String strA = hVar != null ? x0.b.a(hVar.f18824a, hVar.f18825b, hVar.f18826c, hVar.f18827d, hVar.f18828e, hVar.f18829f) : null;
                C1578n c1578n = new C1578n();
                c1578n.f17309a = str;
                c1578n.f17319l = u0.E.m("video/mp2t");
                c1578n.f17320m = u0.E.m("video/hevc");
                c1578n.f17317j = strA;
                c1578n.f17327t = kVarI.f18841e;
                c1578n.f17328u = kVarI.f18842f;
                c1578n.f17299A = new C1570f(kVarI.i, kVarI.f18845j, kVarI.f18846k, kVarI.f18839c + 8, kVarI.f18840d + 8, null);
                c1578n.f17331x = kVarI.f18843g;
                c1578n.f17322o = kVarI.f18844h;
                c1578n.f17300B = kVarI.f18837a + 1;
                c1578n.f17323p = Collections.singletonList(bArr);
                C1579o c1579o = new C1579o(c1578n);
                this.f288c.e(c1579o);
                int i9 = c1579o.f17360p;
                if (i9 == -1) {
                    throw new IllegalStateException();
                }
                c0198b.getClass();
                AbstractC1709a.j(i9 >= 0);
                c0198b.f4504a = i9;
                c0198b.j(i9);
                this.f290e = true;
            }
        }
        x xVar4 = this.f294j;
        boolean zE = xVar4.e(i5);
        x0.o oVar = this.f298n;
        if (zE) {
            oVar.D(y0.o.n(xVar4.f360e, (byte[]) xVar4.f361f), (byte[]) xVar4.f361f);
            oVar.G(5);
            c0198b.a(j9, oVar);
        }
        x xVar5 = this.f295k;
        if (xVar5.e(i5)) {
            oVar.D(y0.o.n(xVar5.f360e, (byte[]) xVar5.f361f), (byte[]) xVar5.f361f);
            oVar.G(5);
            c0198b.a(j9, oVar);
        }
    }

    public final void c(byte[] bArr, int i, int i5) {
        r rVar = this.f289d;
        if (rVar.f279f) {
            int i8 = rVar.f277d;
            int i9 = (i + 2) - i8;
            if (i9 < i5) {
                rVar.f280g = (bArr[i9] & 128) != 0;
                rVar.f279f = false;
            } else {
                rVar.f277d = (i5 - i) + i8;
            }
        }
        if (!this.f290e) {
            this.f292g.a(bArr, i, i5);
            this.f293h.a(bArr, i, i5);
            this.i.a(bArr, i, i5);
        }
        this.f294j.a(bArr, i, i5);
        this.f295k.a(bArr, i, i5);
    }

    public final void d(int i, int i5, long j8, long j9) {
        r rVar = this.f289d;
        boolean z8 = this.f290e;
        rVar.f280g = false;
        rVar.f281h = false;
        rVar.f278e = j9;
        rVar.f277d = 0;
        rVar.f275b = j8;
        if (i5 >= 32 && i5 != 40) {
            if (rVar.i && !rVar.f282j) {
                if (z8) {
                    rVar.a(i);
                }
                rVar.i = false;
            }
            if ((32 <= i5 && i5 <= 35) || i5 == 39) {
                rVar.f281h = !rVar.f282j;
                rVar.f282j = true;
            }
        }
        boolean z9 = i5 >= 16 && i5 <= 21;
        rVar.f276c = z9;
        rVar.f279f = z9 || i5 <= 9;
        if (!this.f290e) {
            this.f292g.h(i5);
            this.f293h.h(i5);
            this.i.h(i5);
        }
        this.f294j.h(i5);
        this.f295k.h(i5);
    }

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

    @Override // A1.InterfaceC0008i
    public final void f(boolean z8) {
        AbstractC1709a.k(this.f288c);
        int i = x0.v.f18553a;
        if (z8) {
            ((C0198b) this.f286a.f365t).j(0);
            b(0, 0, this.f296l, this.f297m);
            d(0, 48, this.f296l, this.f297m);
        }
    }

    @Override // A1.InterfaceC0008i
    public final void g(T0.o oVar, M m8) {
        m8.a();
        m8.b();
        this.f287b = m8.f103e;
        m8.b();
        T0.F fJ = oVar.j(m8.f102d, 2);
        this.f288c = fJ;
        this.f289d = new r(fJ);
        this.f286a.o(oVar, m8);
    }

    @Override // A1.InterfaceC0008i
    public final void h(long j8, int i) {
        this.f297m = j8;
    }
}
