package y;

import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import androidx.core.location.LocationRequestCompat;
import b0.AbstractC0399d;
import b0.D;
import b0.r;
import b0.t;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.util.UUID;
import n.z;
import u.InterfaceC0722a;
import v.C0725a;
import v.m;
import v.n;
import v.o;
import y.AbstractC0739a;

/* JADX INFO: renamed from: y.e, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0743e implements v.e, n {

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    private static final int f6965B = D.u("seig");

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    private static final byte[] f6966C = {-94, SDKKeyboardCode.FUNCTION_KEY_BOARD_CAPS_LOCK, SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT, SDKKeyboardCode.FUNCTION_KEY_BOARD_UP, 90, -101, SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT, SDKKeyboardCode.FUNCTION_KEY_BOARD_Q, -94, SDKKeyboardCode.FUNCTION_KEY_BOARD_F11, 108, SDKKeyboardCode.FUNCTION_KEY_BOARD_F9, 124, 100, -115, -12};

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

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    private String f6968A;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final SparseArray f6971d;

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

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private final byte[] f6976i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final Stack f6977j;

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private C0725a f6990w;

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

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

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

    /* JADX INFO: renamed from: y.e$a */
    private static final class a {

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

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public i f6996c;

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

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

        public a(o oVar) {
            this.f6995b = oVar;
        }

        public void a(i iVar, C0742d c0742d) {
            this.f6996c = (i) AbstractC0399d.d(iVar);
            this.f6997d = (C0742d) AbstractC0399d.d(c0742d);
            this.f6995b.c(iVar.f7014f);
            b();
        }

        public void b() {
            this.f6994a.f();
            this.f6998e = 0;
        }
    }

    public C0743e(int i2, i iVar) {
        this.f6970c = iVar;
        this.f6969b = i2 | (iVar != null ? 4 : 0);
        this.f6975h = new t(16);
        this.f6972e = new t(r.f3071a);
        this.f6973f = new t(4);
        this.f6974g = new t(1);
        this.f6976i = new byte[16];
        this.f6977j = new Stack();
        this.f6971d = new SparseArray();
        c();
    }

    private static void A(t tVar, k kVar, byte[] bArr) throws z {
        tVar.B(8);
        tVar.e(bArr, 0, 16);
        if (Arrays.equals(bArr, f6966C)) {
            r(tVar, 16, kVar);
        }
    }

    private void B(long j2) throws z {
        while (!this.f6977j.isEmpty() && ((AbstractC0739a.C0104a) this.f6977j.peek()).f6933d1 == j2) {
            i((AbstractC0739a.C0104a) this.f6977j.pop());
        }
        c();
    }

    private boolean C(v.f fVar) throws z {
        if (this.f6981n == 0) {
            if (!fVar.a(this.f6975h.f3092a, 0, 8, true)) {
                return false;
            }
            this.f6981n = 8;
            this.f6975h.B(0);
            this.f6980m = this.f6975h.s();
            this.f6979l = this.f6975h.h();
        }
        if (this.f6980m == 1) {
            fVar.readFully(this.f6975h.f3092a, 8, 8);
            this.f6981n += 8;
            this.f6980m = this.f6975h.v();
        }
        if (this.f6980m < this.f6981n) {
            throw new z("Atom size less than header length (unsupported).");
        }
        long j2 = fVar.j() - ((long) this.f6981n);
        if (this.f6979l == AbstractC0739a.f6848L) {
            int size = this.f6971d.size();
            for (int i2 = 0; i2 < size; i2++) {
                k kVar = ((a) this.f6971d.valueAt(i2)).f6994a;
                kVar.f7024c = j2;
                kVar.f7023b = j2;
                kVar.f7037p = false;
            }
        }
        int i3 = this.f6979l;
        if (i3 == AbstractC0739a.f6896i) {
            this.f6984q = null;
            this.f6983p = j2 + this.f6980m;
            if (!this.f6989v) {
                this.f6988u.b(m.f6657a);
                this.f6989v = true;
            }
            this.f6978k = 2;
            return true;
        }
        if (H(i3)) {
            long j3 = (fVar.j() + this.f6980m) - 8;
            this.f6977j.add(new AbstractC0739a.C0104a(this.f6979l, j3));
            if (this.f6980m == this.f6981n) {
                B(j3);
            } else {
                c();
            }
        } else if (I(this.f6979l)) {
            if (this.f6981n != 8) {
                throw new z("Leaf atom defines extended atom size (unsupported).");
            }
            long j4 = this.f6980m;
            if (j4 > 2147483647L) {
                throw new z("Leaf atom with length > 2147483647 (unsupported).");
            }
            t tVar = new t((int) j4);
            this.f6982o = tVar;
            System.arraycopy(this.f6975h.f3092a, 0, tVar.f3092a, 0, 8);
            this.f6978k = 1;
        } else {
            if (this.f6980m > 2147483647L) {
                throw new z("Skipping atom with length > 2147483647 (unsupported).");
            }
            this.f6982o = null;
            this.f6978k = 1;
        }
        return true;
    }

    private void D(v.f fVar) throws z {
        int i2 = ((int) this.f6980m) - this.f6981n;
        t tVar = this.f6982o;
        if (tVar != null) {
            fVar.readFully(tVar.f3092a, 8, i2);
            j(new AbstractC0739a.b(this.f6979l, this.f6982o), fVar.j());
        } else {
            try {
                fVar.h(i2);
            } catch (EOFException unused) {
                Log.e("FragmentedMp4Extractor", "catch EOFException, continue play from next atom");
            } catch (IOException unused2) {
                Log.e("FragmentedMp4Extractor", "catch IOException, continue play from next atom");
            }
        }
        B(fVar.j());
    }

    private void E(v.f fVar) throws z {
        int size = this.f6971d.size();
        a aVar = null;
        long j2 = LocationRequestCompat.PASSIVE_INTERVAL;
        for (int i2 = 0; i2 < size; i2++) {
            k kVar = ((a) this.f6971d.valueAt(i2)).f6994a;
            if (kVar.f7034m) {
                long j3 = kVar.f7024c;
                if (j3 < j2) {
                    aVar = (a) this.f6971d.valueAt(i2);
                    j2 = j3;
                }
            }
        }
        if (aVar == null) {
            this.f6978k = 3;
            return;
        }
        int iJ = (int) (j2 - fVar.j());
        if (iJ < 0) {
            throw new z("Offset to encryption data was negative.");
        }
        fVar.h(iJ);
        aVar.f6994a.b(fVar);
    }

    private boolean F(v.f fVar) throws z {
        byte[] bArr;
        int i2;
        if (this.f6978k == 3) {
            if (this.f6984q == null) {
                a aVarH = h(this.f6971d);
                this.f6984q = aVarH;
                if (aVarH == null) {
                    int iJ = (int) (this.f6983p - fVar.j());
                    if (iJ < 0) {
                        throw new z("Offset to end of mdat was negative.");
                    }
                    fVar.h(iJ);
                    c();
                    return false;
                }
                int iJ2 = (int) (aVarH.f6994a.f7023b - fVar.j());
                if (iJ2 < 0) {
                    Log.w("FragmentedMp4Extractor", "Ignoring negative offset to sample data.");
                    iJ2 = 0;
                }
                fVar.h(iJ2);
            }
            if (this.f6993z) {
                a aVar = this.f6984q;
                if (aVar.f6996c.f7010b == i.f7003k) {
                    int i3 = aVar.f6998e;
                    k kVar = aVar.f6994a;
                    int i4 = i3;
                    while (true) {
                        i2 = kVar.f7025d;
                        if (i4 >= i2 || kVar.f7029h[i4]) {
                            break;
                        }
                        i4++;
                    }
                    if (i4 >= i2) {
                        int iJ3 = (int) (this.f6983p - fVar.j());
                        if (iJ3 < 0) {
                            throw new z("Offset to end of mdat was negative.");
                        }
                        fVar.h(iJ3);
                        c();
                        return false;
                    }
                    int i5 = 0;
                    while (i3 < i4) {
                        i5 += kVar.f7026e[i3];
                        i3++;
                    }
                    if (i5 > 0) {
                        fVar.h(i5);
                    }
                }
            }
            a aVar2 = this.f6984q;
            k kVar2 = aVar2.f6994a;
            this.f6985r = kVar2.f7026e[aVar2.f6998e];
            if (kVar2.f7030i) {
                int iB = b(aVar2);
                this.f6986s = iB;
                this.f6985r += iB;
            } else {
                this.f6986s = 0;
            }
            this.f6978k = 4;
            this.f6987t = 0;
        }
        a aVar3 = this.f6984q;
        k kVar3 = aVar3.f6994a;
        i iVar = aVar3.f6996c;
        o oVar = aVar3.f6995b;
        int i6 = aVar3.f6998e;
        int i7 = iVar.f7018j;
        if (i7 == -1) {
            if (!iVar.f7014f.f5842g.equals("video/wvc1")) {
                while (true) {
                    int i8 = this.f6986s;
                    int i9 = this.f6985r;
                    if (i8 >= i9) {
                        break;
                    }
                    this.f6986s += oVar.d(fVar, i9 - i8, false);
                }
            } else {
                oVar.a(new t(f.f7000c), 4);
                this.f6986s += 4;
                this.f6985r += 4;
                while (true) {
                    int i10 = this.f6986s;
                    int i11 = this.f6985r;
                    if (i10 >= i11) {
                        break;
                    }
                    this.f6986s += oVar.d(fVar, i11 - i10, false);
                }
            }
        } else {
            byte[] bArr2 = this.f6973f.f3092a;
            bArr2[0] = 0;
            bArr2[1] = 0;
            bArr2[2] = 0;
            int i12 = 4 - i7;
            while (this.f6986s < this.f6985r) {
                int i13 = this.f6987t;
                if (i13 == 0) {
                    fVar.readFully(this.f6973f.f3092a, i12, i7);
                    this.f6973f.B(0);
                    this.f6987t = this.f6973f.u();
                    this.f6972e.B(0);
                    oVar.a(this.f6972e, 4);
                    this.f6986s += 4;
                    this.f6985r += i12;
                } else {
                    int iD = oVar.d(fVar, i13, false);
                    this.f6986s += iD;
                    this.f6987t -= iD;
                }
            }
        }
        long jC = kVar3.c(i6) * 1000;
        boolean z2 = kVar3.f7030i;
        int i14 = (z2 ? 2 : 0) | (kVar3.f7029h[i6] ? 1 : 0);
        int i15 = kVar3.f7022a.f6961a;
        if (z2) {
            j jVar = kVar3.f7035n;
            bArr = jVar != null ? jVar.f7021c : iVar.f7015g[i15].f7021c;
        } else {
            bArr = null;
        }
        oVar.e(jC, i14, this.f6985r, 0, bArr);
        a aVar4 = this.f6984q;
        int i16 = aVar4.f6998e + 1;
        aVar4.f6998e = i16;
        if (i16 == kVar3.f7025d) {
            this.f6984q = null;
        }
        this.f6978k = 3;
        return true;
    }

    private static boolean H(int i2) {
        return i2 == AbstractC0739a.f6830C || i2 == AbstractC0739a.f6834E || i2 == AbstractC0739a.f6836F || i2 == AbstractC0739a.f6838G || i2 == AbstractC0739a.f6840H || i2 == AbstractC0739a.f6848L || i2 == AbstractC0739a.f6850M || i2 == AbstractC0739a.f6852N || i2 == AbstractC0739a.f6858Q;
    }

    private static boolean I(int i2) {
        return i2 == AbstractC0739a.f6864T || i2 == AbstractC0739a.f6862S || i2 == AbstractC0739a.f6832D || i2 == AbstractC0739a.f6828B || i2 == AbstractC0739a.f6866U || i2 == AbstractC0739a.f6926x || i2 == AbstractC0739a.f6928y || i2 == AbstractC0739a.f6856P || i2 == AbstractC0739a.f6930z || i2 == AbstractC0739a.f6826A || i2 == AbstractC0739a.f6868V || i2 == AbstractC0739a.f6887d0 || i2 == AbstractC0739a.f6889e0 || i2 == AbstractC0739a.f6897i0 || i2 == AbstractC0739a.f6891f0 || i2 == AbstractC0739a.f6893g0 || i2 == AbstractC0739a.f6895h0 || i2 == AbstractC0739a.f6860R || i2 == AbstractC0739a.f6854O || i2 == AbstractC0739a.f6839G0;
    }

    private int b(a aVar) {
        k kVar = aVar.f6994a;
        t tVar = kVar.f7033l;
        int i2 = kVar.f7022a.f6961a;
        j jVar = kVar.f7035n;
        if (jVar == null) {
            jVar = aVar.f6996c.f7015g[i2];
        }
        int i3 = jVar.f7020b;
        boolean z2 = kVar.f7031j[aVar.f6998e];
        t tVar2 = this.f6974g;
        tVar2.f3092a[0] = (byte) ((z2 ? 128 : 0) | i3);
        tVar2.B(0);
        o oVar = aVar.f6995b;
        oVar.a(this.f6974g, 1);
        oVar.a(tVar, i3);
        if (!z2) {
            return i3 + 1;
        }
        int iW = tVar.w();
        tVar.C(-2);
        int i4 = (iW * 6) + 2;
        oVar.a(tVar, i4);
        return i3 + 1 + i4;
    }

    private void c() {
        this.f6978k = 0;
        this.f6981n = 0;
    }

    private static InterfaceC0722a.C0098a d(List list) {
        int size = list.size();
        InterfaceC0722a.C0098a c0098a = null;
        for (int i2 = 0; i2 < size; i2++) {
            AbstractC0739a.b bVar = (AbstractC0739a.b) list.get(i2);
            if (bVar.f6932a == AbstractC0739a.f6868V) {
                if (c0098a == null) {
                    c0098a = new InterfaceC0722a.C0098a();
                }
                byte[] bArr = bVar.f6936d1.f3092a;
                UUID uuidD = g.d(bArr);
                byte[] bArrC = g.c(bArr, uuidD);
                if (bArrC != null) {
                    AbstractC0740b.j(bArrC, bArrC.length);
                } else {
                    Log.e("FragmentedMp4Extractor", "SchemeSpecificData is null!");
                }
                if (uuidD == null) {
                    Log.w("FragmentedMp4Extractor", "Skipped pssh atom (failed to extract uuid)");
                } else {
                    c0098a.b(g.d(bArr), new InterfaceC0722a.b("video/mp4", bArr));
                }
            }
        }
        return c0098a;
    }

    private static a h(SparseArray sparseArray) {
        int size = sparseArray.size();
        a aVar = null;
        long j2 = LocationRequestCompat.PASSIVE_INTERVAL;
        for (int i2 = 0; i2 < size; i2++) {
            a aVar2 = (a) sparseArray.valueAt(i2);
            int i3 = aVar2.f6998e;
            k kVar = aVar2.f6994a;
            if (i3 != kVar.f7025d) {
                long j3 = kVar.f7023b;
                if (j3 < j2) {
                    aVar = aVar2;
                    j2 = j3;
                }
            }
        }
        return aVar;
    }

    private void i(AbstractC0739a.C0104a c0104a) throws z {
        int i2 = c0104a.f6932a;
        if (i2 == AbstractC0739a.f6830C) {
            l(c0104a);
            return;
        }
        if (i2 != AbstractC0739a.f6848L) {
            if (this.f6977j.isEmpty()) {
                return;
            }
            ((AbstractC0739a.C0104a) this.f6977j.peek()).d(c0104a);
        } else if (this.f6991x) {
            this.f6992y = true;
        } else {
            k(c0104a);
        }
    }

    private void j(AbstractC0739a.b bVar, long j2) {
        if (!this.f6977j.isEmpty()) {
            ((AbstractC0739a.C0104a) this.f6977j.peek()).e(bVar);
            return;
        }
        int i2 = bVar.f6932a;
        if (i2 != AbstractC0739a.f6828B) {
            if (i2 == AbstractC0739a.f6839G0) {
                m(bVar.f6936d1, j2);
                return;
            }
            return;
        }
        C0725a c0725aU = u(bVar.f6936d1, j2);
        if (c0725aU == null) {
            return;
        }
        C0725a c0725a = this.f6990w;
        if (c0725a == null) {
            this.f6990w = c0725aU;
            this.f6988u.b(c0725aU);
            this.f6989v = true;
            return;
        }
        int[] iArr = c0725a.f6560c;
        int[] iArr2 = new int[iArr.length + c0725aU.f6560c.length];
        System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
        int[] iArr3 = c0725aU.f6560c;
        System.arraycopy(iArr3, 0, iArr2, c0725a.f6560c.length, iArr3.length);
        long[] jArr = c0725a.f6561d;
        long[] jArr2 = new long[jArr.length + c0725aU.f6561d.length];
        System.arraycopy(jArr, 0, jArr2, 0, jArr.length);
        long[] jArr3 = c0725aU.f6561d;
        System.arraycopy(jArr3, 0, jArr2, c0725a.f6561d.length, jArr3.length);
        long[] jArr4 = c0725a.f6562e;
        long[] jArr5 = new long[jArr4.length + c0725aU.f6562e.length];
        System.arraycopy(jArr4, 0, jArr5, 0, jArr4.length);
        long[] jArr6 = c0725aU.f6562e;
        System.arraycopy(jArr6, 0, jArr5, c0725a.f6562e.length, jArr6.length);
        long[] jArr7 = c0725a.f6563f;
        long[] jArr8 = new long[jArr7.length + c0725aU.f6563f.length];
        System.arraycopy(jArr7, 0, jArr8, 0, jArr7.length);
        long[] jArr9 = c0725aU.f6563f;
        System.arraycopy(jArr9, 0, jArr8, c0725a.f6563f.length, jArr9.length);
        C0725a c0725a2 = new C0725a(iArr2, jArr2, jArr5, jArr8);
        this.f6990w = c0725a2;
        this.f6988u.b(c0725a2);
        this.f6989v = true;
    }

    private void k(AbstractC0739a.C0104a c0104a) throws z {
        o(c0104a, this.f6971d, this.f6969b, this.f6976i);
        InterfaceC0722a.C0098a c0098aD = d(c0104a.f6934e1);
        if (c0098aD != null) {
            this.f6988u.g(c0098aD);
        }
    }

    private void l(AbstractC0739a.C0104a c0104a) {
        AbstractC0399d.f(this.f6970c == null, "Unexpected moov box.");
        InterfaceC0722a.C0098a c0098aD = d(c0104a.f6934e1);
        if (c0098aD != null) {
            this.f6988u.g(c0098aD);
        }
        AbstractC0739a.C0104a c0104aG = c0104a.g(AbstractC0739a.f6852N);
        SparseArray sparseArray = new SparseArray();
        long jN = -1;
        if (c0104aG != null) {
            int size = c0104aG.f6934e1.size();
            for (int i2 = 0; i2 < size; i2++) {
                AbstractC0739a.b bVar = (AbstractC0739a.b) c0104aG.f6934e1.get(i2);
                int i3 = bVar.f6932a;
                if (i3 == AbstractC0739a.f6930z) {
                    Pair pairY = y(bVar.f6936d1);
                    sparseArray.put(((Integer) pairY.first).intValue(), (C0742d) pairY.second);
                } else if (i3 == AbstractC0739a.f6854O) {
                    jN = n(bVar.f6936d1);
                }
            }
        }
        SparseArray sparseArray2 = new SparseArray();
        int size2 = c0104a.f6935f1.size();
        for (int i4 = 0; i4 < size2; i4++) {
            AbstractC0739a.C0104a c0104a2 = (AbstractC0739a.C0104a) c0104a.f6935f1.get(i4);
            if (c0104a2 != null && c0104a2.f6932a == AbstractC0739a.f6834E) {
                int i5 = AbstractC0739a.f6832D;
                i iVarT = c0104a.h(i5) != null ? AbstractC0740b.t(c0104a2, c0104a.h(i5), jN, false) : null;
                if (iVarT != null) {
                    sparseArray2.put(iVarT.f7009a, iVarT);
                }
            }
        }
        int size3 = sparseArray2.size();
        if (this.f6971d.size() == 0) {
            for (int i6 = 0; i6 < size3; i6++) {
                this.f6971d.put(((i) sparseArray2.valueAt(i6)).f7009a, new a(this.f6988u.i(i6)));
            }
            this.f6988u.m();
        } else {
            AbstractC0399d.e(this.f6971d.size() == size3);
        }
        for (int i7 = 0; i7 < size3; i7++) {
            i iVar = (i) sparseArray2.valueAt(i7);
            ((a) this.f6971d.get(iVar.f7009a)).a(iVar, (C0742d) sparseArray.get(iVar.f7009a));
        }
    }

    private static long n(t tVar) {
        tVar.B(8);
        return AbstractC0739a.c(tVar.h()) == 0 ? tVar.s() : tVar.v();
    }

    private static void o(AbstractC0739a.C0104a c0104a, SparseArray sparseArray, int i2, byte[] bArr) throws z {
        int size = c0104a.f6935f1.size();
        for (int i3 = 0; i3 < size; i3++) {
            AbstractC0739a.C0104a c0104a2 = (AbstractC0739a.C0104a) c0104a.f6935f1.get(i3);
            if (c0104a2.f6932a == AbstractC0739a.f6850M) {
                x(c0104a2, sparseArray, i2, bArr);
            }
        }
    }

    private static void p(t tVar, k kVar) throws z {
        tVar.B(8);
        int iH = tVar.h();
        if ((AbstractC0739a.b(iH) & 1) == 1) {
            tVar.C(8);
        }
        int iU = tVar.u();
        if (iU == 1) {
            kVar.f7024c += AbstractC0739a.c(iH) == 0 ? tVar.s() : tVar.v();
        } else {
            throw new z("Unexpected saio entry count: " + iU);
        }
    }

    private static void q(j jVar, t tVar, k kVar) throws z {
        int i2;
        int i3 = jVar.f7020b;
        tVar.B(8);
        if ((AbstractC0739a.b(tVar.h()) & 1) == 1) {
            tVar.C(8);
        }
        int iQ = tVar.q();
        int iU = tVar.u();
        if (iU != kVar.f7025d) {
            throw new z("Length mismatch: " + iU + ", " + kVar.f7025d);
        }
        if (iQ == 0) {
            boolean[] zArr = kVar.f7031j;
            i2 = 0;
            for (int i4 = 0; i4 < iU; i4++) {
                int iQ2 = tVar.q();
                i2 += iQ2;
                zArr[i4] = iQ2 > i3;
            }
        } else {
            i2 = iQ * iU;
            Arrays.fill(kVar.f7031j, 0, iU, iQ > i3);
        }
        kVar.d(i2);
    }

    private static void r(t tVar, int i2, k kVar) throws z {
        tVar.B(i2 + 8);
        int iB = AbstractC0739a.b(tVar.h());
        if ((iB & 1) != 0) {
            throw new z("Overriding TrackEncryptionBox parameters is unsupported.");
        }
        boolean z2 = (iB & 2) != 0;
        int iU = tVar.u();
        if (iU == kVar.f7025d) {
            Arrays.fill(kVar.f7031j, 0, iU, z2);
            kVar.d(tVar.a());
            kVar.a(tVar);
        } else {
            throw new z("Length mismatch: " + iU + ", " + kVar.f7025d);
        }
    }

    private static void s(t tVar, k kVar) throws z {
        r(tVar, 0, kVar);
    }

    private static void t(t tVar, t tVar2, k kVar) throws z {
        tVar.B(8);
        int iH = tVar.h();
        int iH2 = tVar.h();
        int i2 = f6965B;
        if (iH2 != i2) {
            return;
        }
        if (AbstractC0739a.c(iH) == 1) {
            tVar.C(4);
        }
        if (tVar.h() != 1) {
            throw new z("Entry count in sbgp != 1 (unsupported).");
        }
        tVar2.B(8);
        int iH3 = tVar2.h();
        if (tVar2.h() != i2) {
            return;
        }
        int iC = AbstractC0739a.c(iH3);
        if (iC == 1) {
            if (tVar2.s() == 0) {
                throw new z("Variable length decription in sgpd found (unsupported)");
            }
        } else if (iC >= 2) {
            tVar2.C(4);
        }
        if (tVar2.s() != 1) {
            throw new z("Entry count in sgpd != 1 (unsupported).");
        }
        tVar2.C(2);
        boolean z2 = tVar2.q() == 1;
        if (z2) {
            int iQ = tVar2.q();
            byte[] bArr = new byte[16];
            tVar2.e(bArr, 0, 16);
            kVar.f7030i = true;
            kVar.f7035n = new j(z2, iQ, bArr);
        }
    }

    private static C0725a u(t tVar, long j2) {
        long jV;
        long jV2;
        tVar.B(8);
        int iC = AbstractC0739a.c(tVar.h());
        tVar.C(4);
        long jS = tVar.s();
        if (iC == 0) {
            jV = tVar.s();
            jV2 = tVar.s();
        } else {
            jV = tVar.v();
            jV2 = tVar.v();
        }
        long j3 = j2 + jV2;
        long j4 = jV;
        tVar.C(2);
        int iW = tVar.w();
        int[] iArr = new int[iW];
        long[] jArr = new long[iW];
        long[] jArr2 = new long[iW];
        long[] jArr3 = new long[iW];
        long jI = D.I(j4, 1000000L, jS);
        long j5 = j3;
        int i2 = 0;
        long j6 = j4;
        while (i2 < iW) {
            int iH = tVar.h();
            if ((Integer.MIN_VALUE & iH) != 0) {
                return null;
            }
            long jS2 = tVar.s();
            iArr[i2] = iH & Integer.MAX_VALUE;
            jArr[i2] = j5;
            jArr3[i2] = jI;
            long j7 = j6 + jS2;
            jI = D.I(j7, 1000000L, jS);
            jArr2[i2] = jI - jArr3[i2];
            tVar.C(4);
            j5 += (long) iArr[i2];
            i2++;
            j6 = j7;
        }
        return new C0725a(iArr, jArr, jArr2, jArr3);
    }

    private static long v(t tVar) {
        tVar.B(8);
        return AbstractC0739a.c(tVar.h()) == 1 ? tVar.v() : tVar.s();
    }

    private static a w(t tVar, SparseArray sparseArray, int i2) {
        tVar.B(8);
        int iB = AbstractC0739a.b(tVar.h());
        int iH = tVar.h();
        if ((i2 & 4) != 0) {
            iH = 0;
        }
        a aVar = (a) sparseArray.get(iH);
        if (aVar == null) {
            return null;
        }
        if ((iB & 1) != 0) {
            long jV = tVar.v();
            k kVar = aVar.f6994a;
            kVar.f7023b = jV;
            kVar.f7037p = true;
            kVar.f7024c = jV;
        }
        C0742d c0742d = aVar.f6997d;
        aVar.f6994a.f7022a = new C0742d((iB & 2) != 0 ? tVar.u() - 1 : c0742d.f6961a, (iB & 8) != 0 ? tVar.u() : c0742d.f6962b, (iB & 16) != 0 ? tVar.u() : c0742d.f6963c, (iB & 32) != 0 ? tVar.u() : c0742d.f6964d);
        return aVar;
    }

    private static void x(AbstractC0739a.C0104a c0104a, SparseArray sparseArray, int i2, byte[] bArr) throws z {
        int i3 = AbstractC0739a.f6826A;
        if (c0104a.f(i3) != 1) {
            throw new z("Trun count in traf != 1 (unsupported).");
        }
        AbstractC0739a.b bVarH = c0104a.h(AbstractC0739a.f6928y);
        a aVarW = bVarH != null ? w(bVarH.f6936d1, sparseArray, i2) : null;
        if (aVarW == null) {
            return;
        }
        k kVar = aVarW.f6994a;
        long jV = kVar.f7036o;
        aVarW.b();
        AbstractC0739a.b bVarH2 = c0104a.h(AbstractC0739a.f6926x);
        if (bVarH2 != null && (i2 & 2) == 0) {
            jV = v(bVarH2.f6936d1);
        }
        AbstractC0739a.b bVarH3 = c0104a.h(i3);
        if (bVarH3 != null) {
            z(aVarW, jV, i2, bVarH3.f6936d1);
        }
        AbstractC0739a.b bVarH4 = c0104a.h(AbstractC0739a.f6887d0);
        if (bVarH4 != null) {
            q(aVarW.f6996c.f7015g[kVar.f7022a.f6961a], bVarH4.f6936d1, kVar);
        }
        AbstractC0739a.b bVarH5 = c0104a.h(AbstractC0739a.f6889e0);
        if (bVarH5 != null) {
            p(bVarH5.f6936d1, kVar);
        }
        AbstractC0739a.b bVarH6 = c0104a.h(AbstractC0739a.f6897i0);
        if (bVarH6 != null) {
            s(bVarH6.f6936d1, kVar);
        }
        AbstractC0739a.b bVarH7 = c0104a.h(AbstractC0739a.f6891f0);
        AbstractC0739a.b bVarH8 = c0104a.h(AbstractC0739a.f6893g0);
        if (bVarH7 != null && bVarH8 != null) {
            t(bVarH7.f6936d1, bVarH8.f6936d1, kVar);
        }
        int size = c0104a.f6934e1.size();
        for (int i4 = 0; i4 < size; i4++) {
            AbstractC0739a.b bVar = (AbstractC0739a.b) c0104a.f6934e1.get(i4);
            if (bVar != null && bVar.f6932a == AbstractC0739a.f6895h0) {
                A(bVar.f6936d1, kVar, bArr);
            }
        }
    }

    private static Pair y(t tVar) {
        tVar.B(12);
        return Pair.create(Integer.valueOf(tVar.h()), new C0742d(tVar.u() - 1, tVar.u(), tVar.u(), tVar.h()));
    }

    private static void z(a aVar, long j2, int i2, t tVar) {
        boolean z2;
        int iU;
        boolean z3;
        int iU2;
        boolean z4;
        int iH;
        boolean z5;
        C0742d c0742d;
        int i3;
        boolean z6;
        tVar.B(8);
        int iB = AbstractC0739a.b(tVar.h());
        i iVar = aVar.f6996c;
        k kVar = aVar.f6994a;
        C0742d c0742d2 = kVar.f7022a;
        int iU3 = tVar.u();
        if ((iB & 1) != 0) {
            kVar.f7023b += (long) tVar.h();
            kVar.f7037p = true;
        }
        boolean z7 = (iB & 4) != 0;
        int iU4 = c0742d2.f6964d;
        if (z7) {
            iU4 = tVar.u();
        }
        boolean z8 = (iB & 256) != 0;
        boolean z9 = (iB & 512) != 0;
        boolean z10 = (iB & 1024) != 0;
        boolean z11 = (iB & 2048) != 0;
        long[] jArr = iVar.f7016h;
        long jI = (jArr != null && jArr.length == 1 && jArr[0] == 0) ? D.I(iVar.f7017i[0], 1000L, iVar.f7011c) : 0L;
        kVar.e(iU3);
        int[] iArr = kVar.f7026e;
        int[] iArr2 = kVar.f7027f;
        long[] jArr2 = kVar.f7028g;
        boolean[] zArr = kVar.f7029h;
        long j3 = jI;
        long j4 = iVar.f7011c;
        int i4 = iU4;
        boolean z12 = iVar.f7010b == i.f7003k && (i2 & 1) != 0;
        long j5 = j2;
        int i5 = 0;
        while (i5 < iU3) {
            if (z8) {
                z2 = z8;
                iU = tVar.u();
            } else {
                z2 = z8;
                iU = c0742d2.f6962b;
            }
            if (z9) {
                z3 = z9;
                iU2 = tVar.u();
            } else {
                z3 = z9;
                iU2 = c0742d2.f6963c;
            }
            if (i5 == 0 && z7) {
                z4 = z7;
                iH = i4;
            } else if (z10) {
                z4 = z7;
                iH = tVar.h();
            } else {
                z4 = z7;
                iH = c0742d2.f6964d;
            }
            if (z11) {
                z5 = z11;
                c0742d = c0742d2;
                i3 = iU3;
                iArr2[i5] = (int) (((long) (tVar.h() * 1000)) / j4);
                z6 = false;
            } else {
                z5 = z11;
                c0742d = c0742d2;
                i3 = iU3;
                z6 = false;
                iArr2[i5] = 0;
            }
            jArr2[i5] = D.I(j5, 1000L, j4) - j3;
            iArr[i5] = iU2;
            zArr[i5] = (((iH >> 16) & 1) != 0 || (z12 && i5 != 0)) ? z6 : true;
            if (iVar.f7010b == i.f7004l) {
                zArr[i5] = true;
            }
            j5 += (long) iU;
            i5++;
            z8 = z2;
            z9 = z3;
            z7 = z4;
            z11 = z5;
            c0742d2 = c0742d;
            iU3 = i3;
        }
        int i6 = iU3;
        long j6 = j5;
        long j7 = j4 > 0 ? (j6 - j2) / j4 : 0L;
        iVar.f7014f.f5851o0 = Long.valueOf(j7 > 0 ? ((long) i6) / j7 : 0L).intValue();
        kVar.f7036o = j6;
    }

    public void G(boolean z2) {
        this.f6991x = z2;
    }

    @Override // v.e
    public final int a(v.f fVar, v.j jVar) throws z {
        while (true) {
            if (this.f6991x && this.f6992y) {
                return -1;
            }
            int i2 = this.f6978k;
            if (i2 != 0) {
                if (i2 == 1) {
                    D(fVar);
                } else if (i2 == 2) {
                    E(fVar);
                } else if (F(fVar)) {
                    return 0;
                }
            } else if (!C(fVar)) {
                return -1;
            }
        }
    }

    @Override // v.e
    public final void e(v.g gVar) {
        this.f6988u = gVar;
        if (this.f6970c != null) {
            a aVar = new a(gVar.i(0));
            aVar.a(this.f6970c, new C0742d(0, 0, 0, 0));
            this.f6971d.put(0, aVar);
            this.f6988u.m();
        }
    }

    @Override // v.e
    public final void f() {
        int size = this.f6971d.size();
        for (int i2 = 0; i2 < size; i2++) {
            ((a) this.f6971d.valueAt(i2)).b();
        }
        this.f6977j.clear();
        c();
    }

    @Override // v.e
    public final boolean g(v.f fVar) {
        return h.b(fVar);
    }

    protected void m(t tVar, long j2) {
    }

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

    public C0743e(String str) {
        this(0, str);
    }

    public C0743e(int i2, String str) {
        this(i2, (i) null);
        this.f6968A = str.toLowerCase();
    }
}
