package x0;

import java.math.RoundingMode;

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

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

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

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

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

    public t(long j8) {
        g(j8);
    }

    public final synchronized long a(long j8) {
        if (j8 == -9223372036854775807L) {
            return -9223372036854775807L;
        }
        try {
            if (!f()) {
                long jLongValue = this.f18549a;
                if (jLongValue == 9223372036854775806L) {
                    Long l8 = (Long) this.f18552d.get();
                    l8.getClass();
                    jLongValue = l8.longValue();
                }
                this.f18550b = jLongValue - j8;
                notifyAll();
            }
            this.f18551c = j8;
            return j8 + this.f18550b;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized long b(long j8) {
        if (j8 == -9223372036854775807L) {
            return -9223372036854775807L;
        }
        try {
            long j9 = this.f18551c;
            if (j9 != -9223372036854775807L) {
                int i = v.f18553a;
                long jS = v.S(j9, 90000L, 1000000L, RoundingMode.DOWN);
                long j10 = (4294967296L + jS) / 8589934592L;
                long j11 = ((j10 - 1) * 8589934592L) + j8;
                long j12 = (j10 * 8589934592L) + j8;
                j8 = Math.abs(j11 - jS) < Math.abs(j12 - jS) ? j11 : j12;
            }
            long j13 = j8;
            int i5 = v.f18553a;
            return a(v.S(j13, 1000000L, 90000L, RoundingMode.DOWN));
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized long c(long j8) {
        if (j8 == -9223372036854775807L) {
            return -9223372036854775807L;
        }
        long j9 = this.f18551c;
        if (j9 != -9223372036854775807L) {
            int i = v.f18553a;
            long jS = v.S(j9, 90000L, 1000000L, RoundingMode.DOWN);
            long j10 = jS / 8589934592L;
            Long.signum(j10);
            long j11 = (j10 * 8589934592L) + j8;
            j8 = j11 >= jS ? j11 : ((j10 + 1) * 8589934592L) + j8;
        }
        long j12 = j8;
        int i5 = v.f18553a;
        return a(v.S(j12, 1000000L, 90000L, RoundingMode.DOWN));
    }

    public final synchronized long d() {
        long j8;
        j8 = this.f18549a;
        if (j8 == Long.MAX_VALUE || j8 == 9223372036854775806L) {
            j8 = -9223372036854775807L;
        }
        return j8;
    }

    public final synchronized long e() {
        return this.f18550b;
    }

    public final synchronized boolean f() {
        return this.f18550b != -9223372036854775807L;
    }

    public final synchronized void g(long j8) {
        this.f18549a = j8;
        this.f18550b = j8 == Long.MAX_VALUE ? 0L : -9223372036854775807L;
        this.f18551c = -9223372036854775807L;
    }

    public final synchronized void h(long j8, boolean z8) {
        try {
            AbstractC1709a.j(this.f18549a == 9223372036854775806L);
            if (f()) {
                return;
            }
            if (z8) {
                this.f18552d.set(Long.valueOf(j8));
            } else {
                while (!f()) {
                    wait();
                }
            }
        } catch (Throwable th) {
            throw th;
        }
    }
}
