package R0;

import O1.C0225a;
import android.os.SystemClock;
import androidx.datastore.preferences.protobuf.C0432j;
import java.util.NoSuchElementException;
import n4.u0;
import u0.C1578n;
import u0.C1579o;
import u0.E;
import u0.d0;

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final u f6021c = new u();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final S0.f f6022d = new S0.f();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final S0.f f6023e = new S0.f();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final C0432j f6024f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public d0 f6026h;
    public long i;

    public z(C0225a c0225a, v vVar) {
        this.f6019a = c0225a;
        this.f6020b = vVar;
        C0432j c0432j = new C0432j(4, (byte) 0);
        int iHighestOneBit = Integer.bitCount(16) != 1 ? Integer.highestOneBit(15) << 1 : 16;
        c0432j.f8096b = 0;
        c0432j.f8097c = 0;
        c0432j.f8099e = new long[iHighestOneBit];
        c0432j.f8098d = iHighestOneBit - 1;
        this.f6024f = c0432j;
        this.f6025g = -9223372036854775807L;
        this.f6026h = d0.f17268d;
    }

    public final void a(long j8, long j9) {
        int iA;
        do {
            C0432j c0432j = this.f6024f;
            int i = c0432j.f8097c;
            if (i == 0) {
                return;
            }
            if (i == 0) {
                throw new NoSuchElementException();
            }
            long j10 = ((long[]) c0432j.f8099e)[c0432j.f8096b];
            Long l8 = (Long) this.f6023e.f(j10);
            v vVar = this.f6020b;
            if (l8 != null && l8.longValue() != this.i) {
                this.i = l8.longValue();
                vVar.d(2);
            }
            iA = this.f6020b.a(j10, j8, j9, this.i, false, false, this.f6021c);
            final C0225a c0225a = this.f6019a;
            C0281c c0281c = (C0281c) c0225a.f5011s;
            if (iA == 0 || iA == 1) {
                long jS = c0432j.S();
                d0 d0Var = (d0) this.f6022d.f(jS);
                if (d0Var != null && !d0Var.equals(d0.f17268d) && !d0Var.equals(this.f6026h)) {
                    this.f6026h = d0Var;
                    C1578n c1578n = new C1578n();
                    c1578n.f17327t = d0Var.f17269a;
                    c1578n.f17328u = d0Var.f17270b;
                    c1578n.f17320m = E.m("video/raw");
                    c0225a.f5010r = new C1579o(c1578n);
                    c0281c.f5875h.execute(new B0.A(c0225a, 17, d0Var));
                }
                boolean z8 = vVar.f5987e != 3;
                vVar.f5987e = 3;
                vVar.f5993l.getClass();
                vVar.f5989g = x0.v.L(SystemClock.elapsedRealtime());
                if (z8) {
                    c0281c.getClass();
                }
                C1579o c1579o = (C1579o) c0225a.f5010r;
                C1579o c1579o2 = c1579o == null ? new C1579o(new C1578n()) : c1579o;
                t tVar = c0281c.i;
                c0281c.f5869b.getClass();
                tVar.c(jS, System.nanoTime(), c1579o2, null);
                c0281c.f5871d.remove().getClass();
                throw new ClassCastException();
            }
            if (iA == 2 || iA == 3) {
                c0432j.S();
                final int i5 = 1;
                c0281c.f5875h.execute(new Runnable() { // from class: R0.b
                    @Override // java.lang.Runnable
                    public final void run() {
                        switch (i5) {
                            case u0.f15495q /* 0 */:
                                ((C0281c) c0225a.f5011s).f5874g.getClass();
                                break;
                            default:
                                ((C0281c) c0225a.f5011s).f5874g.getClass();
                                break;
                        }
                    }
                });
                c0281c.f5871d.remove().getClass();
                throw new ClassCastException();
            }
        } while (iA == 4);
        if (iA != 5) {
            throw new IllegalStateException(String.valueOf(iA));
        }
    }
}
