Commit 9f6ff55c by tonihei Committed by Ian Baker

Replace PeriodSeekInfo by static methods.

The inner class was only used to obtain 3 distinct pieces of
information which is better handled by static methods.

#exofixit

PiperOrigin-RevId: 344767661
parent 53844557
...@@ -891,15 +891,12 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -891,15 +891,12 @@ public final class DashMediaSource extends BaseMediaSource {
Period lastPeriod = manifest.getPeriod(lastPeriodIndex); Period lastPeriod = manifest.getPeriod(lastPeriodIndex);
long lastPeriodDurationUs = manifest.getPeriodDurationUs(lastPeriodIndex); long lastPeriodDurationUs = manifest.getPeriodDurationUs(lastPeriodIndex);
long nowUnixTimeUs = C.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs)); long nowUnixTimeUs = C.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs));
PeriodSeekInfo firstPeriodSeekInfo =
PeriodSeekInfo.createPeriodSeekInfo(
manifest.getPeriod(0), manifest.getPeriodDurationUs(0), nowUnixTimeUs);
PeriodSeekInfo lastPeriodSeekInfo =
PeriodSeekInfo.createPeriodSeekInfo(lastPeriod, lastPeriodDurationUs, nowUnixTimeUs);
// Get the period-relative start/end times. // Get the period-relative start/end times.
long currentStartTimeUs = firstPeriodSeekInfo.availableStartTimeUs; long currentStartTimeUs =
long currentEndTimeUs = lastPeriodSeekInfo.availableEndTimeUs; getAvailableStartTimeUs(
if (manifest.dynamic && !lastPeriodSeekInfo.isIndexExplicit) { manifest.getPeriod(0), manifest.getPeriodDurationUs(0), nowUnixTimeUs);
long currentEndTimeUs = getAvailableEndTimeUs(lastPeriod, lastPeriodDurationUs, nowUnixTimeUs);
if (manifest.dynamic && !isIndexExplicit(lastPeriod)) {
// The manifest describes an incomplete live stream. Update the start/end times to reflect the // The manifest describes an incomplete live stream. Update the start/end times to reflect the
// live stream duration and the manifest's time shift buffer depth. // live stream duration and the manifest's time shift buffer depth.
long liveStreamEndPositionInLastPeriodUs = currentEndTimeUs - C.msToUs(lastPeriod.startMs); long liveStreamEndPositionInLastPeriodUs = currentEndTimeUs - C.msToUs(lastPeriod.startMs);
...@@ -1141,26 +1138,40 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1141,26 +1138,40 @@ public final class DashMediaSource extends BaseMediaSource {
return LongMath.divide(intervalUs, 1000, RoundingMode.CEILING); return LongMath.divide(intervalUs, 1000, RoundingMode.CEILING);
} }
private static final class PeriodSeekInfo { private static long getAvailableStartTimeUs(
public static PeriodSeekInfo createPeriodSeekInfo(
Period period, long periodDurationUs, long nowUnixTimeUs) { Period period, long periodDurationUs, long nowUnixTimeUs) {
int adaptationSetCount = period.adaptationSets.size();
long availableStartTimeUs = 0; long availableStartTimeUs = 0;
long availableEndTimeUs = Long.MAX_VALUE; boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
boolean isIndexExplicit = false; for (int i = 0; i < period.adaptationSets.size(); i++) {
boolean seenEmptyIndex = false; AdaptationSet adaptationSet = period.adaptationSets.get(i);
List<Representation> representations = adaptationSet.representations;
boolean haveAudioVideoAdaptationSets = false; // Exclude text adaptation sets from duration calculations, if we have at least one audio
for (int i = 0; i < adaptationSetCount; i++) { // or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
int type = period.adaptationSets.get(i).type; if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
if (type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO) { || representations.isEmpty()) {
haveAudioVideoAdaptationSets = true; continue;
break; }
@Nullable DashSegmentIndex index = representations.get(0).getIndex();
if (index == null) {
return 0;
}
int availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs);
if (availableSegmentCount == 0) {
return 0;
}
long firstAvailableSegmentNum =
index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs);
long adaptationSetAvailableStartTimeUs = index.getTimeUs(firstAvailableSegmentNum);
availableStartTimeUs = max(availableStartTimeUs, adaptationSetAvailableStartTimeUs);
} }
return availableStartTimeUs;
} }
for (int i = 0; i < adaptationSetCount; i++) { private static long getAvailableEndTimeUs(
Period period, long periodDurationUs, long nowUnixTimeUs) {
long availableEndTimeUs = Long.MAX_VALUE;
boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
for (int i = 0; i < period.adaptationSets.size(); i++) {
AdaptationSet adaptationSet = period.adaptationSets.get(i); AdaptationSet adaptationSet = period.adaptationSets.get(i);
List<Representation> representations = adaptationSet.representations; List<Representation> representations = adaptationSet.representations;
// Exclude text adaptation sets from duration calculations, if we have at least one audio // Exclude text adaptation sets from duration calculations, if we have at least one audio
...@@ -1169,46 +1180,44 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1169,46 +1180,44 @@ public final class DashMediaSource extends BaseMediaSource {
|| representations.isEmpty()) { || representations.isEmpty()) {
continue; continue;
} }
@Nullable DashSegmentIndex index = representations.get(0).getIndex(); @Nullable DashSegmentIndex index = representations.get(0).getIndex();
if (index == null) { if (index == null) {
return new PeriodSeekInfo( return periodDurationUs;
/* isIndexExplicit= */ true,
/* availableStartTimeUs= */ 0,
/* availableEndTimeUs= */ periodDurationUs);
} }
isIndexExplicit |= index.isExplicit();
int availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs); int availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs);
if (availableSegmentCount == 0) { if (availableSegmentCount == 0) {
seenEmptyIndex = true; return 0;
availableStartTimeUs = 0; }
availableEndTimeUs = 0;
} else if (!seenEmptyIndex) {
long firstAvailableSegmentNum = long firstAvailableSegmentNum =
index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs); index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs);
long adaptationSetAvailableStartTimeUs = index.getTimeUs(firstAvailableSegmentNum);
availableStartTimeUs = max(availableStartTimeUs, adaptationSetAvailableStartTimeUs);
long lastAvailableSegmentNum = firstAvailableSegmentNum + availableSegmentCount - 1; long lastAvailableSegmentNum = firstAvailableSegmentNum + availableSegmentCount - 1;
long adaptationSetAvailableEndTimeUs = long adaptationSetAvailableEndTimeUs =
index.getTimeUs(lastAvailableSegmentNum) index.getTimeUs(lastAvailableSegmentNum)
+ index.getDurationUs(lastAvailableSegmentNum, periodDurationUs); + index.getDurationUs(lastAvailableSegmentNum, periodDurationUs);
availableEndTimeUs = min(availableEndTimeUs, adaptationSetAvailableEndTimeUs); availableEndTimeUs = min(availableEndTimeUs, adaptationSetAvailableEndTimeUs);
} }
return availableEndTimeUs;
} }
return new PeriodSeekInfo(isIndexExplicit, availableStartTimeUs, availableEndTimeUs);
}
public final boolean isIndexExplicit;
public final long availableStartTimeUs;
public final long availableEndTimeUs;
private PeriodSeekInfo(boolean isIndexExplicit, long availableStartTimeUs, private static boolean isIndexExplicit(Period period) {
long availableEndTimeUs) { for (int i = 0; i < period.adaptationSets.size(); i++) {
this.isIndexExplicit = isIndexExplicit; @Nullable
this.availableStartTimeUs = availableStartTimeUs; DashSegmentIndex index = period.adaptationSets.get(i).representations.get(0).getIndex();
this.availableEndTimeUs = availableEndTimeUs; if (index == null || index.isExplicit()) {
return true;
}
}
return false;
} }
private static boolean hasVideoOrAudioAdaptationSets(Period period) {
for (int i = 0; i < period.adaptationSets.size(); i++) {
int type = period.adaptationSets.get(i).type;
if (type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO) {
return true;
}
}
return false;
} }
private static final class DashTimeline extends Timeline { private static final class DashTimeline extends Timeline {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment