package b0;

import android.util.SparseArray;
import c0.C0333a;
import java.nio.ByteBuffer;

/* JADX INFO: loaded from: classes.dex */
public final class n {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f4651a = 1;

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

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

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

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

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

    public n(q qVar) {
        this.f4652b = qVar;
        this.f4653c = qVar;
    }

    public final int a(int i) {
        SparseArray sparseArray = this.f4653c.f4664a;
        q qVar = sparseArray == null ? null : (q) sparseArray.get(i);
        int i5 = 1;
        int i6 = 2;
        if (this.f4651a == 2) {
            if (qVar != null) {
                this.f4653c = qVar;
                this.f4656f++;
            } else if (i == 65038) {
                b();
            } else if (i != 65039) {
                q qVar2 = this.f4653c;
                if (qVar2.f4665b != null) {
                    i6 = 3;
                    if (this.f4656f != 1) {
                        this.f4654d = qVar2;
                        b();
                    } else if (c()) {
                        this.f4654d = this.f4653c;
                        b();
                    } else {
                        b();
                    }
                } else {
                    b();
                }
            }
            i5 = i6;
        } else if (qVar == null) {
            b();
        } else {
            this.f4651a = 2;
            this.f4653c = qVar;
            this.f4656f = 1;
            i5 = i6;
        }
        this.f4655e = i;
        return i5;
    }

    public final void b() {
        this.f4651a = 1;
        this.f4653c = this.f4652b;
        this.f4656f = 0;
    }

    public final boolean c() {
        C0333a c0333aB = this.f4653c.f4665b.b();
        int iA = c0333aB.a(6);
        return !(iA == 0 || ((ByteBuffer) c0333aB.f2384d).get(iA + c0333aB.f2381a) == 0) || this.f4655e == 65039;
    }
}
