mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
538445572d
commit
9f6ff55c0f
1 changed files with 79 additions and 70 deletions
|
|
@ -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,74 +1138,86 @@ 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(
|
||||||
|
Period period, long periodDurationUs, long nowUnixTimeUs) {
|
||||||
public static PeriodSeekInfo createPeriodSeekInfo(
|
long availableStartTimeUs = 0;
|
||||||
Period period, long periodDurationUs, long nowUnixTimeUs) {
|
boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
|
||||||
int adaptationSetCount = period.adaptationSets.size();
|
for (int i = 0; i < period.adaptationSets.size(); i++) {
|
||||||
long availableStartTimeUs = 0;
|
AdaptationSet adaptationSet = period.adaptationSets.get(i);
|
||||||
long availableEndTimeUs = Long.MAX_VALUE;
|
List<Representation> representations = adaptationSet.representations;
|
||||||
boolean isIndexExplicit = false;
|
// Exclude text adaptation sets from duration calculations, if we have at least one audio
|
||||||
boolean seenEmptyIndex = false;
|
// or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
|
||||||
|
if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
|
||||||
boolean haveAudioVideoAdaptationSets = false;
|
|| representations.isEmpty()) {
|
||||||
for (int i = 0; i < adaptationSetCount; i++) {
|
continue;
|
||||||
int type = period.adaptationSets.get(i).type;
|
|
||||||
if (type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO) {
|
|
||||||
haveAudioVideoAdaptationSets = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@Nullable DashSegmentIndex index = representations.get(0).getIndex();
|
||||||
for (int i = 0; i < adaptationSetCount; i++) {
|
if (index == null) {
|
||||||
AdaptationSet adaptationSet = period.adaptationSets.get(i);
|
return 0;
|
||||||
List<Representation> representations = adaptationSet.representations;
|
|
||||||
// Exclude text adaptation sets from duration calculations, if we have at least one audio
|
|
||||||
// or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
|
|
||||||
if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
|
|
||||||
|| representations.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable DashSegmentIndex index = representations.get(0).getIndex();
|
|
||||||
if (index == null) {
|
|
||||||
return new PeriodSeekInfo(
|
|
||||||
/* isIndexExplicit= */ true,
|
|
||||||
/* availableStartTimeUs= */ 0,
|
|
||||||
/* availableEndTimeUs= */ periodDurationUs);
|
|
||||||
}
|
|
||||||
isIndexExplicit |= index.isExplicit();
|
|
||||||
int availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs);
|
|
||||||
if (availableSegmentCount == 0) {
|
|
||||||
seenEmptyIndex = true;
|
|
||||||
availableStartTimeUs = 0;
|
|
||||||
availableEndTimeUs = 0;
|
|
||||||
} else if (!seenEmptyIndex) {
|
|
||||||
long firstAvailableSegmentNum =
|
|
||||||
index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs);
|
|
||||||
long adaptationSetAvailableStartTimeUs = index.getTimeUs(firstAvailableSegmentNum);
|
|
||||||
availableStartTimeUs = max(availableStartTimeUs, adaptationSetAvailableStartTimeUs);
|
|
||||||
long lastAvailableSegmentNum = firstAvailableSegmentNum + availableSegmentCount - 1;
|
|
||||||
long adaptationSetAvailableEndTimeUs =
|
|
||||||
index.getTimeUs(lastAvailableSegmentNum)
|
|
||||||
+ index.getDurationUs(lastAvailableSegmentNum, periodDurationUs);
|
|
||||||
availableEndTimeUs = min(availableEndTimeUs, adaptationSetAvailableEndTimeUs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new PeriodSeekInfo(isIndexExplicit, availableStartTimeUs, availableEndTimeUs);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean isIndexExplicit;
|
private static long getAvailableEndTimeUs(
|
||||||
public final long availableStartTimeUs;
|
Period period, long periodDurationUs, long nowUnixTimeUs) {
|
||||||
public final long availableEndTimeUs;
|
long availableEndTimeUs = Long.MAX_VALUE;
|
||||||
|
boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
|
||||||
private PeriodSeekInfo(boolean isIndexExplicit, long availableStartTimeUs,
|
for (int i = 0; i < period.adaptationSets.size(); i++) {
|
||||||
long availableEndTimeUs) {
|
AdaptationSet adaptationSet = period.adaptationSets.get(i);
|
||||||
this.isIndexExplicit = isIndexExplicit;
|
List<Representation> representations = adaptationSet.representations;
|
||||||
this.availableStartTimeUs = availableStartTimeUs;
|
// Exclude text adaptation sets from duration calculations, if we have at least one audio
|
||||||
this.availableEndTimeUs = availableEndTimeUs;
|
// or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
|
||||||
|
if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
|
||||||
|
|| representations.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
@Nullable DashSegmentIndex index = representations.get(0).getIndex();
|
||||||
|
if (index == null) {
|
||||||
|
return periodDurationUs;
|
||||||
|
}
|
||||||
|
int availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs);
|
||||||
|
if (availableSegmentCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long firstAvailableSegmentNum =
|
||||||
|
index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs);
|
||||||
|
long lastAvailableSegmentNum = firstAvailableSegmentNum + availableSegmentCount - 1;
|
||||||
|
long adaptationSetAvailableEndTimeUs =
|
||||||
|
index.getTimeUs(lastAvailableSegmentNum)
|
||||||
|
+ index.getDurationUs(lastAvailableSegmentNum, periodDurationUs);
|
||||||
|
availableEndTimeUs = min(availableEndTimeUs, adaptationSetAvailableEndTimeUs);
|
||||||
}
|
}
|
||||||
|
return availableEndTimeUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isIndexExplicit(Period period) {
|
||||||
|
for (int i = 0; i < period.adaptationSets.size(); i++) {
|
||||||
|
@Nullable
|
||||||
|
DashSegmentIndex index = period.adaptationSets.get(i).representations.get(0).getIndex();
|
||||||
|
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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue