Rabbit-R1/switch port/java/sources/com/google/android/exoplayer2/MediaPeriodQueue.java
2024-05-21 17:08:36 -04:00

533 lines
26 KiB
Java

package com.google.android.exoplayer2;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.common.collect.ImmutableList;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class MediaPeriodQueue {
public static final long INITIAL_RENDERER_POSITION_OFFSET_US = 1000000000000L;
private static final int MAXIMUM_BUFFER_AHEAD_PERIODS = 100;
private final AnalyticsCollector analyticsCollector;
private final HandlerWrapper analyticsCollectorHandler;
private int length;
private MediaPeriodHolder loading;
private long nextWindowSequenceNumber;
private Object oldFrontPeriodUid;
private long oldFrontPeriodWindowSequenceNumber;
private MediaPeriodHolder playing;
private MediaPeriodHolder reading;
private int repeatMode;
private boolean shuffleModeEnabled;
private final Timeline.Period period = new Timeline.Period();
private final Timeline.Window window = new Timeline.Window();
private boolean areDurationsCompatible(long j, long j2) {
return j == -9223372036854775807L || j == j2;
}
public MediaPeriodHolder getLoadingPeriod() {
return this.loading;
}
public MediaPeriodHolder getPlayingPeriod() {
return this.playing;
}
public MediaPeriodHolder getReadingPeriod() {
return this.reading;
}
public MediaPeriodQueue(AnalyticsCollector analyticsCollector, HandlerWrapper handlerWrapper) {
this.analyticsCollector = analyticsCollector;
this.analyticsCollectorHandler = handlerWrapper;
}
public boolean updateRepeatMode(Timeline timeline, int i) {
this.repeatMode = i;
return updateForPlaybackModeChange(timeline);
}
public boolean updateShuffleModeEnabled(Timeline timeline, boolean z) {
this.shuffleModeEnabled = z;
return updateForPlaybackModeChange(timeline);
}
public boolean isLoading(MediaPeriod mediaPeriod) {
MediaPeriodHolder mediaPeriodHolder = this.loading;
return mediaPeriodHolder != null && mediaPeriodHolder.mediaPeriod == mediaPeriod;
}
public void reevaluateBuffer(long j) {
MediaPeriodHolder mediaPeriodHolder = this.loading;
if (mediaPeriodHolder != null) {
mediaPeriodHolder.reevaluateBuffer(j);
}
}
public boolean shouldLoadNextMediaPeriod() {
MediaPeriodHolder mediaPeriodHolder = this.loading;
return mediaPeriodHolder == null || (!mediaPeriodHolder.info.isFinal && this.loading.isFullyBuffered() && this.loading.info.durationUs != -9223372036854775807L && this.length < 100);
}
public MediaPeriodInfo getNextMediaPeriodInfo(long j, PlaybackInfo playbackInfo) {
if (this.loading == null) {
return getFirstMediaPeriodInfo(playbackInfo);
}
return getFollowingMediaPeriodInfo(playbackInfo.timeline, this.loading, j);
}
public MediaPeriodHolder enqueueNextMediaPeriodHolder(RendererCapabilities[] rendererCapabilitiesArr, TrackSelector trackSelector, Allocator allocator, MediaSourceList mediaSourceList, MediaPeriodInfo mediaPeriodInfo, TrackSelectorResult trackSelectorResult) {
MediaPeriodHolder mediaPeriodHolder = this.loading;
MediaPeriodHolder mediaPeriodHolder2 = new MediaPeriodHolder(rendererCapabilitiesArr, mediaPeriodHolder == null ? 1000000000000L : (mediaPeriodHolder.getRendererOffset() + this.loading.info.durationUs) - mediaPeriodInfo.startPositionUs, trackSelector, allocator, mediaSourceList, mediaPeriodInfo, trackSelectorResult);
MediaPeriodHolder mediaPeriodHolder3 = this.loading;
if (mediaPeriodHolder3 != null) {
mediaPeriodHolder3.setNext(mediaPeriodHolder2);
} else {
this.playing = mediaPeriodHolder2;
this.reading = mediaPeriodHolder2;
}
this.oldFrontPeriodUid = null;
this.loading = mediaPeriodHolder2;
this.length++;
notifyQueueUpdate();
return mediaPeriodHolder2;
}
public MediaPeriodHolder advanceReadingPeriod() {
MediaPeriodHolder mediaPeriodHolder = this.reading;
Assertions.checkState((mediaPeriodHolder == null || mediaPeriodHolder.getNext() == null) ? false : true);
this.reading = this.reading.getNext();
notifyQueueUpdate();
return this.reading;
}
public MediaPeriodHolder advancePlayingPeriod() {
MediaPeriodHolder mediaPeriodHolder = this.playing;
if (mediaPeriodHolder == null) {
return null;
}
if (mediaPeriodHolder == this.reading) {
this.reading = mediaPeriodHolder.getNext();
}
this.playing.release();
int i = this.length - 1;
this.length = i;
if (i == 0) {
this.loading = null;
this.oldFrontPeriodUid = this.playing.uid;
this.oldFrontPeriodWindowSequenceNumber = this.playing.info.id.windowSequenceNumber;
}
this.playing = this.playing.getNext();
notifyQueueUpdate();
return this.playing;
}
public boolean removeAfter(MediaPeriodHolder mediaPeriodHolder) {
boolean z = false;
Assertions.checkState(mediaPeriodHolder != null);
if (mediaPeriodHolder.equals(this.loading)) {
return false;
}
this.loading = mediaPeriodHolder;
while (mediaPeriodHolder.getNext() != null) {
mediaPeriodHolder = mediaPeriodHolder.getNext();
if (mediaPeriodHolder == this.reading) {
this.reading = this.playing;
z = true;
}
mediaPeriodHolder.release();
this.length--;
}
this.loading.setNext(null);
notifyQueueUpdate();
return z;
}
public void clear() {
if (this.length == 0) {
return;
}
MediaPeriodHolder mediaPeriodHolder = (MediaPeriodHolder) Assertions.checkStateNotNull(this.playing);
this.oldFrontPeriodUid = mediaPeriodHolder.uid;
this.oldFrontPeriodWindowSequenceNumber = mediaPeriodHolder.info.id.windowSequenceNumber;
while (mediaPeriodHolder != null) {
mediaPeriodHolder.release();
mediaPeriodHolder = mediaPeriodHolder.getNext();
}
this.playing = null;
this.loading = null;
this.reading = null;
this.length = 0;
notifyQueueUpdate();
}
public boolean updateQueuedPeriods(Timeline timeline, long j, long j2) {
MediaPeriodInfo mediaPeriodInfo;
MediaPeriodHolder mediaPeriodHolder = this.playing;
MediaPeriodHolder mediaPeriodHolder2 = null;
while (mediaPeriodHolder != null) {
MediaPeriodInfo mediaPeriodInfo2 = mediaPeriodHolder.info;
if (mediaPeriodHolder2 == null) {
mediaPeriodInfo = getUpdatedMediaPeriodInfo(timeline, mediaPeriodInfo2);
} else {
MediaPeriodInfo followingMediaPeriodInfo = getFollowingMediaPeriodInfo(timeline, mediaPeriodHolder2, j);
if (followingMediaPeriodInfo == null) {
return !removeAfter(mediaPeriodHolder2);
}
if (!canKeepMediaPeriodHolder(mediaPeriodInfo2, followingMediaPeriodInfo)) {
return !removeAfter(mediaPeriodHolder2);
}
mediaPeriodInfo = followingMediaPeriodInfo;
}
mediaPeriodHolder.info = mediaPeriodInfo.copyWithRequestedContentPositionUs(mediaPeriodInfo2.requestedContentPositionUs);
if (!areDurationsCompatible(mediaPeriodInfo2.durationUs, mediaPeriodInfo.durationUs)) {
mediaPeriodHolder.updateClipping();
return (removeAfter(mediaPeriodHolder) || (mediaPeriodHolder == this.reading && !mediaPeriodHolder.info.isFollowedByTransitionToSameStream && ((j2 > Long.MIN_VALUE ? 1 : (j2 == Long.MIN_VALUE ? 0 : -1)) == 0 || (j2 > ((mediaPeriodInfo.durationUs > (-9223372036854775807L) ? 1 : (mediaPeriodInfo.durationUs == (-9223372036854775807L) ? 0 : -1)) == 0 ? Long.MAX_VALUE : mediaPeriodHolder.toRendererTime(mediaPeriodInfo.durationUs)) ? 1 : (j2 == ((mediaPeriodInfo.durationUs > (-9223372036854775807L) ? 1 : (mediaPeriodInfo.durationUs == (-9223372036854775807L) ? 0 : -1)) == 0 ? Long.MAX_VALUE : mediaPeriodHolder.toRendererTime(mediaPeriodInfo.durationUs)) ? 0 : -1)) >= 0))) ? false : true;
}
mediaPeriodHolder2 = mediaPeriodHolder;
mediaPeriodHolder = mediaPeriodHolder.getNext();
}
return true;
}
/* JADX WARN: Removed duplicated region for block: B:12:0x0064 */
/* JADX WARN: Removed duplicated region for block: B:17:0x006e */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public com.google.android.exoplayer2.MediaPeriodInfo getUpdatedMediaPeriodInfo(com.google.android.exoplayer2.Timeline r19, com.google.android.exoplayer2.MediaPeriodInfo r20) {
/*
r18 = this;
r0 = r18
r1 = r19
r2 = r20
com.google.android.exoplayer2.source.MediaSource$MediaPeriodId r3 = r2.id
boolean r11 = r0.isLastInPeriod(r3)
boolean r12 = r0.isLastInWindow(r1, r3)
boolean r13 = r0.isLastInTimeline(r1, r3, r11)
com.google.android.exoplayer2.source.MediaSource$MediaPeriodId r4 = r2.id
java.lang.Object r4 = r4.periodUid
com.google.android.exoplayer2.Timeline$Period r5 = r0.period
r1.getPeriodByUid(r4, r5)
boolean r1 = r3.isAd()
r4 = -1
r5 = -9223372036854775807(0x8000000000000001, double:-4.9E-324)
if (r1 != 0) goto L37
int r1 = r3.nextAdGroupIndex
if (r1 != r4) goto L2e
goto L37
L2e:
com.google.android.exoplayer2.Timeline$Period r1 = r0.period
int r7 = r3.nextAdGroupIndex
long r7 = r1.getAdGroupTimeUs(r7)
goto L38
L37:
r7 = r5
L38:
boolean r1 = r3.isAd()
if (r1 == 0) goto L4a
com.google.android.exoplayer2.Timeline$Period r1 = r0.period
int r5 = r3.adGroupIndex
int r6 = r3.adIndexInAdGroup
long r5 = r1.getAdDurationUs(r5, r6)
L48:
r9 = r5
goto L5e
L4a:
int r1 = (r7 > r5 ? 1 : (r7 == r5 ? 0 : -1))
if (r1 == 0) goto L57
r5 = -9223372036854775808
int r1 = (r7 > r5 ? 1 : (r7 == r5 ? 0 : -1))
if (r1 != 0) goto L55
goto L57
L55:
r9 = r7
goto L5e
L57:
com.google.android.exoplayer2.Timeline$Period r1 = r0.period
long r5 = r1.getDurationUs()
goto L48
L5e:
boolean r1 = r3.isAd()
if (r1 == 0) goto L6e
com.google.android.exoplayer2.Timeline$Period r0 = r0.period
int r1 = r3.adGroupIndex
boolean r0 = r0.isServerSideInsertedAdGroup(r1)
L6c:
r14 = r0
goto L80
L6e:
int r1 = r3.nextAdGroupIndex
if (r1 == r4) goto L7e
com.google.android.exoplayer2.Timeline$Period r0 = r0.period
int r1 = r3.nextAdGroupIndex
boolean r0 = r0.isServerSideInsertedAdGroup(r1)
if (r0 == 0) goto L7e
r0 = 1
goto L6c
L7e:
r0 = 0
goto L6c
L80:
com.google.android.exoplayer2.MediaPeriodInfo r15 = new com.google.android.exoplayer2.MediaPeriodInfo
long r4 = r2.startPositionUs
long r1 = r2.requestedContentPositionUs
r0 = r15
r16 = r1
r1 = r3
r2 = r4
r4 = r16
r6 = r7
r8 = r9
r10 = r14
r0.<init>(r1, r2, r4, r6, r8, r10, r11, r12, r13)
return r15
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.MediaPeriodQueue.getUpdatedMediaPeriodInfo(com.google.android.exoplayer2.Timeline, com.google.android.exoplayer2.MediaPeriodInfo):com.google.android.exoplayer2.MediaPeriodInfo");
}
public MediaSource.MediaPeriodId resolveMediaPeriodIdForAds(Timeline timeline, Object obj, long j) {
return resolveMediaPeriodIdForAds(timeline, obj, j, resolvePeriodIndexToWindowSequenceNumber(timeline, obj), this.window, this.period);
}
private static MediaSource.MediaPeriodId resolveMediaPeriodIdForAds(Timeline timeline, Object obj, long j, long j2, Timeline.Window window, Timeline.Period period) {
timeline.getPeriodByUid(obj, period);
timeline.getWindow(period.windowIndex, window);
int indexOfPeriod = timeline.getIndexOfPeriod(obj);
Object obj2 = obj;
while (period.durationUs == 0 && period.getAdGroupCount() > 0 && period.isServerSideInsertedAdGroup(period.getRemovedAdGroupCount()) && period.getAdGroupIndexForPositionUs(0L) == -1) {
int i = indexOfPeriod + 1;
if (indexOfPeriod >= window.lastPeriodIndex) {
break;
}
timeline.getPeriod(i, period, true);
obj2 = Assertions.checkNotNull(period.uid);
indexOfPeriod = i;
}
timeline.getPeriodByUid(obj2, period);
int adGroupIndexForPositionUs = period.getAdGroupIndexForPositionUs(j);
if (adGroupIndexForPositionUs == -1) {
return new MediaSource.MediaPeriodId(obj2, j2, period.getAdGroupIndexAfterPositionUs(j));
}
return new MediaSource.MediaPeriodId(obj2, adGroupIndexForPositionUs, period.getFirstAdIndexToPlay(adGroupIndexForPositionUs), j2);
}
public MediaSource.MediaPeriodId resolveMediaPeriodIdForAdsAfterPeriodPositionChange(Timeline timeline, Object obj, long j) {
long resolvePeriodIndexToWindowSequenceNumber = resolvePeriodIndexToWindowSequenceNumber(timeline, obj);
timeline.getPeriodByUid(obj, this.period);
timeline.getWindow(this.period.windowIndex, this.window);
boolean z = false;
for (int indexOfPeriod = timeline.getIndexOfPeriod(obj); indexOfPeriod >= this.window.firstPeriodIndex; indexOfPeriod--) {
timeline.getPeriod(indexOfPeriod, this.period, true);
boolean z2 = this.period.getAdGroupCount() > 0;
z |= z2;
Timeline.Period period = this.period;
if (period.getAdGroupIndexForPositionUs(period.durationUs) != -1) {
obj = Assertions.checkNotNull(this.period.uid);
}
if (z && (!z2 || this.period.durationUs != 0)) {
break;
}
}
return resolveMediaPeriodIdForAds(timeline, obj, j, resolvePeriodIndexToWindowSequenceNumber, this.window, this.period);
}
private void notifyQueueUpdate() {
final ImmutableList.Builder builder = ImmutableList.builder();
for (MediaPeriodHolder mediaPeriodHolder = this.playing; mediaPeriodHolder != null; mediaPeriodHolder = mediaPeriodHolder.getNext()) {
builder.add((ImmutableList.Builder) mediaPeriodHolder.info.id);
}
MediaPeriodHolder mediaPeriodHolder2 = this.reading;
final MediaSource.MediaPeriodId mediaPeriodId = mediaPeriodHolder2 == null ? null : mediaPeriodHolder2.info.id;
this.analyticsCollectorHandler.post(new Runnable() { // from class: com.google.android.exoplayer2.MediaPeriodQueue$$ExternalSyntheticLambda0
@Override // java.lang.Runnable
public final void run() {
MediaPeriodQueue.this.m5379xb2cc2342(builder, mediaPeriodId);
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$notifyQueueUpdate$0$com-google-android-exoplayer2-MediaPeriodQueue, reason: not valid java name */
public /* synthetic */ void m5379xb2cc2342(ImmutableList.Builder builder, MediaSource.MediaPeriodId mediaPeriodId) {
this.analyticsCollector.updateMediaPeriodQueueInfo(builder.build(), mediaPeriodId);
}
private long resolvePeriodIndexToWindowSequenceNumber(Timeline timeline, Object obj) {
int indexOfPeriod;
int i = timeline.getPeriodByUid(obj, this.period).windowIndex;
Object obj2 = this.oldFrontPeriodUid;
if (obj2 != null && (indexOfPeriod = timeline.getIndexOfPeriod(obj2)) != -1 && timeline.getPeriod(indexOfPeriod, this.period).windowIndex == i) {
return this.oldFrontPeriodWindowSequenceNumber;
}
for (MediaPeriodHolder mediaPeriodHolder = this.playing; mediaPeriodHolder != null; mediaPeriodHolder = mediaPeriodHolder.getNext()) {
if (mediaPeriodHolder.uid.equals(obj)) {
return mediaPeriodHolder.info.id.windowSequenceNumber;
}
}
for (MediaPeriodHolder mediaPeriodHolder2 = this.playing; mediaPeriodHolder2 != null; mediaPeriodHolder2 = mediaPeriodHolder2.getNext()) {
int indexOfPeriod2 = timeline.getIndexOfPeriod(mediaPeriodHolder2.uid);
if (indexOfPeriod2 != -1 && timeline.getPeriod(indexOfPeriod2, this.period).windowIndex == i) {
return mediaPeriodHolder2.info.id.windowSequenceNumber;
}
}
long j = this.nextWindowSequenceNumber;
this.nextWindowSequenceNumber = 1 + j;
if (this.playing == null) {
this.oldFrontPeriodUid = obj;
this.oldFrontPeriodWindowSequenceNumber = j;
}
return j;
}
private boolean canKeepMediaPeriodHolder(MediaPeriodInfo mediaPeriodInfo, MediaPeriodInfo mediaPeriodInfo2) {
return mediaPeriodInfo.startPositionUs == mediaPeriodInfo2.startPositionUs && mediaPeriodInfo.id.equals(mediaPeriodInfo2.id);
}
private boolean updateForPlaybackModeChange(Timeline timeline) {
MediaPeriodHolder mediaPeriodHolder = this.playing;
if (mediaPeriodHolder == null) {
return true;
}
int indexOfPeriod = timeline.getIndexOfPeriod(mediaPeriodHolder.uid);
while (true) {
indexOfPeriod = timeline.getNextPeriodIndex(indexOfPeriod, this.period, this.window, this.repeatMode, this.shuffleModeEnabled);
while (mediaPeriodHolder.getNext() != null && !mediaPeriodHolder.info.isLastInTimelinePeriod) {
mediaPeriodHolder = mediaPeriodHolder.getNext();
}
MediaPeriodHolder next = mediaPeriodHolder.getNext();
if (indexOfPeriod == -1 || next == null || timeline.getIndexOfPeriod(next.uid) != indexOfPeriod) {
break;
}
mediaPeriodHolder = next;
}
boolean removeAfter = removeAfter(mediaPeriodHolder);
mediaPeriodHolder.info = getUpdatedMediaPeriodInfo(timeline, mediaPeriodHolder.info);
return !removeAfter;
}
private MediaPeriodInfo getFirstMediaPeriodInfo(PlaybackInfo playbackInfo) {
return getMediaPeriodInfo(playbackInfo.timeline, playbackInfo.periodId, playbackInfo.requestedContentPositionUs, playbackInfo.positionUs);
}
/* JADX WARN: Code restructure failed: missing block: B:25:0x00cc, code lost:
if (r1.isServerSideInsertedAdGroup(r1.getRemovedAdGroupCount()) != false) goto L30;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private com.google.android.exoplayer2.MediaPeriodInfo getFollowingMediaPeriodInfo(com.google.android.exoplayer2.Timeline r20, com.google.android.exoplayer2.MediaPeriodHolder r21, long r22) {
/*
Method dump skipped, instructions count: 445
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.MediaPeriodQueue.getFollowingMediaPeriodInfo(com.google.android.exoplayer2.Timeline, com.google.android.exoplayer2.MediaPeriodHolder, long):com.google.android.exoplayer2.MediaPeriodInfo");
}
private MediaPeriodInfo getMediaPeriodInfo(Timeline timeline, MediaSource.MediaPeriodId mediaPeriodId, long j, long j2) {
timeline.getPeriodByUid(mediaPeriodId.periodUid, this.period);
if (mediaPeriodId.isAd()) {
return getMediaPeriodInfoForAd(timeline, mediaPeriodId.periodUid, mediaPeriodId.adGroupIndex, mediaPeriodId.adIndexInAdGroup, j, mediaPeriodId.windowSequenceNumber);
}
return getMediaPeriodInfoForContent(timeline, mediaPeriodId.periodUid, j2, j, mediaPeriodId.windowSequenceNumber);
}
private MediaPeriodInfo getMediaPeriodInfoForAd(Timeline timeline, Object obj, int i, int i2, long j, long j2) {
MediaSource.MediaPeriodId mediaPeriodId = new MediaSource.MediaPeriodId(obj, i, i2, j2);
long adDurationUs = timeline.getPeriodByUid(mediaPeriodId.periodUid, this.period).getAdDurationUs(mediaPeriodId.adGroupIndex, mediaPeriodId.adIndexInAdGroup);
long adResumePositionUs = i2 == this.period.getFirstAdIndexToPlay(i) ? this.period.getAdResumePositionUs() : 0L;
return new MediaPeriodInfo(mediaPeriodId, (adDurationUs == -9223372036854775807L || adResumePositionUs < adDurationUs) ? adResumePositionUs : Math.max(0L, adDurationUs - 1), j, -9223372036854775807L, adDurationUs, this.period.isServerSideInsertedAdGroup(mediaPeriodId.adGroupIndex), false, false, false);
}
private MediaPeriodInfo getMediaPeriodInfoForContent(Timeline timeline, Object obj, long j, long j2, long j3) {
boolean z;
long j4;
long j5;
long j6;
long j7;
timeline.getPeriodByUid(obj, this.period);
int adGroupIndexAfterPositionUs = this.period.getAdGroupIndexAfterPositionUs(j);
int i = 1;
if (adGroupIndexAfterPositionUs == -1) {
if (this.period.getAdGroupCount() > 0) {
Timeline.Period period = this.period;
if (period.isServerSideInsertedAdGroup(period.getRemovedAdGroupCount())) {
z = true;
}
}
z = false;
} else {
if (this.period.isServerSideInsertedAdGroup(adGroupIndexAfterPositionUs) && this.period.getAdGroupTimeUs(adGroupIndexAfterPositionUs) == this.period.durationUs && this.period.hasPlayedAdGroup(adGroupIndexAfterPositionUs)) {
z = true;
adGroupIndexAfterPositionUs = -1;
}
z = false;
}
MediaSource.MediaPeriodId mediaPeriodId = new MediaSource.MediaPeriodId(obj, j3, adGroupIndexAfterPositionUs);
boolean isLastInPeriod = isLastInPeriod(mediaPeriodId);
boolean isLastInWindow = isLastInWindow(timeline, mediaPeriodId);
boolean isLastInTimeline = isLastInTimeline(timeline, mediaPeriodId, isLastInPeriod);
boolean z2 = adGroupIndexAfterPositionUs != -1 && this.period.isServerSideInsertedAdGroup(adGroupIndexAfterPositionUs);
if (adGroupIndexAfterPositionUs != -1) {
j5 = this.period.getAdGroupTimeUs(adGroupIndexAfterPositionUs);
} else if (z) {
j5 = this.period.durationUs;
} else {
j4 = -9223372036854775807L;
j6 = (j4 != -9223372036854775807L || j4 == Long.MIN_VALUE) ? this.period.durationUs : j4;
if (j6 != -9223372036854775807L || j < j6) {
j7 = j;
} else {
if (!isLastInTimeline && z) {
i = 0;
}
j7 = Math.max(0L, j6 - i);
}
return new MediaPeriodInfo(mediaPeriodId, j7, j2, j4, j6, z2, isLastInPeriod, isLastInWindow, isLastInTimeline);
}
j4 = j5;
if (j4 != -9223372036854775807L) {
}
if (j6 != -9223372036854775807L) {
}
j7 = j;
return new MediaPeriodInfo(mediaPeriodId, j7, j2, j4, j6, z2, isLastInPeriod, isLastInWindow, isLastInTimeline);
}
private boolean isLastInPeriod(MediaSource.MediaPeriodId mediaPeriodId) {
return !mediaPeriodId.isAd() && mediaPeriodId.nextAdGroupIndex == -1;
}
private boolean isLastInWindow(Timeline timeline, MediaSource.MediaPeriodId mediaPeriodId) {
if (isLastInPeriod(mediaPeriodId)) {
return timeline.getWindow(timeline.getPeriodByUid(mediaPeriodId.periodUid, this.period).windowIndex, this.window).lastPeriodIndex == timeline.getIndexOfPeriod(mediaPeriodId.periodUid);
}
return false;
}
private boolean isLastInTimeline(Timeline timeline, MediaSource.MediaPeriodId mediaPeriodId, boolean z) {
int indexOfPeriod = timeline.getIndexOfPeriod(mediaPeriodId.periodUid);
return !timeline.getWindow(timeline.getPeriod(indexOfPeriod, this.period).windowIndex, this.window).isDynamic && timeline.isLastPeriod(indexOfPeriod, this.period, this.window, this.repeatMode, this.shuffleModeEnabled) && z;
}
private long getMinStartPositionAfterAdGroupUs(Timeline timeline, Object obj, int i) {
timeline.getPeriodByUid(obj, this.period);
long adGroupTimeUs = this.period.getAdGroupTimeUs(i);
if (adGroupTimeUs == Long.MIN_VALUE) {
return this.period.durationUs;
}
return adGroupTimeUs + this.period.getContentResumeOffsetUs(i);
}
}