/** * Dequeues the playing period holder from the front of the queue and advances the playing period * holder to be the next item in the queue. If the playing period holder is unset, set it to the * item in the front of the queue. * * @return The updated playing period holder, or null if the queue is or becomes empty. */ public MediaPeriodHolder advancePlayingPeriod() { if (playing != null) { if (playing == reading) { reading = playing.next; } playing.release(); length--; if (length == 0) { loading = null; oldFrontPeriodUid = playing.uid; oldFrontPeriodWindowSequenceNumber = playing.info.id.windowSequenceNumber; } playing = playing.next; } else { playing = loading; reading = loading; } return playing; }
/** * Removes all period holders after the given period holder. This process may also remove the * currently reading period holder. If that is the case, the reading period holder is set to be * the same as the playing period holder at the front of the queue. * * @param mediaPeriodHolder The media period holder that shall be the new end of the queue. * @return Whether the reading period has been removed. */ public boolean removeAfter(MediaPeriodHolder mediaPeriodHolder) { Assertions.checkState(mediaPeriodHolder != null); boolean removedReading = false; loading = mediaPeriodHolder; while (mediaPeriodHolder.next != null) { mediaPeriodHolder = mediaPeriodHolder.next; if (mediaPeriodHolder == reading) { reading = playing; removedReading = true; } mediaPeriodHolder.release(); length--; } loading.next = null; return removedReading; }
/** * Clears the queue. * * @param keepFrontPeriodUid Whether the queue should keep the id of the media period in the front * of queue (typically the playing one) for later reuse. */ public void clear(boolean keepFrontPeriodUid) { MediaPeriodHolder front = getFrontPeriod(); if (front != null) { oldFrontPeriodUid = keepFrontPeriodUid ? front.uid : null; oldFrontPeriodWindowSequenceNumber = front.info.id.windowSequenceNumber; front.release(); removeAfter(front); } else if (!keepFrontPeriodUid) { oldFrontPeriodUid = null; } playing = null; loading = null; reading = null; length = 0; }