package com.google.android.exoplayer2.util; /* loaded from: classes2.dex */ public final class TimedValueQueue { public int first; public int size; public long[] timestamps; public Object[] values; public TimedValueQueue() { this(10); } public TimedValueQueue(int i) { this.timestamps = new long[i]; this.values = newArray(i); } public synchronized Object pollFloor(long j) { return poll(j, true); } public synchronized Object poll(long j) { return poll(j, false); } public final Object poll(long j, boolean z) { Object obj = null; long j2 = Long.MAX_VALUE; while (this.size > 0) { long j3 = j - this.timestamps[this.first]; if (j3 < 0 && (z || (-j3) >= j2)) { break; } obj = popFirst(); j2 = j3; } return obj; } public final Object popFirst() { Assertions.checkState(this.size > 0); Object[] objArr = this.values; int i = this.first; Object obj = objArr[i]; objArr[i] = null; this.first = (i + 1) % objArr.length; this.size--; return obj; } public static Object[] newArray(int i) { return new Object[i]; } }