SmoothStreaming - Parse last chunk duration.
This commit is contained in:
parent
f52742b100
commit
525b309764
@ -173,11 +173,12 @@ public class SmoothStreamingManifest {
|
||||
private final String chunkTemplate;
|
||||
|
||||
private final List<Long> chunkStartTimes;
|
||||
private final long lastChunkDuration;
|
||||
|
||||
public StreamElement(Uri baseUri, String chunkTemplate, int type, String subType,
|
||||
long timescale, String name, int qualityLevels, int maxWidth, int maxHeight,
|
||||
int displayWidth, int displayHeight, String language, TrackElement[] tracks,
|
||||
List<Long> chunkStartTimes) {
|
||||
List<Long> chunkStartTimes, long lastChunkDuration) {
|
||||
this.baseUri = baseUri;
|
||||
this.chunkTemplate = chunkTemplate;
|
||||
this.type = type;
|
||||
@ -193,6 +194,7 @@ public class SmoothStreamingManifest {
|
||||
this.tracks = tracks;
|
||||
this.chunkCount = chunkStartTimes.size();
|
||||
this.chunkStartTimes = chunkStartTimes;
|
||||
this.lastChunkDuration = lastChunkDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,6 +217,18 @@ public class SmoothStreamingManifest {
|
||||
return (chunkStartTimes.get(chunkIndex) * 1000000L) / timescale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the specified chunk.
|
||||
*
|
||||
* @param chunkIndex The index of the chunk.
|
||||
* @return The duration of the chunk, in microseconds.
|
||||
*/
|
||||
public long getChunkDurationUs(int chunkIndex) {
|
||||
long chunkDuration = (chunkIndex == chunkCount - 1) ? lastChunkDuration
|
||||
: chunkStartTimes.get(chunkIndex + 1) - chunkStartTimes.get(chunkIndex);
|
||||
return chunkDuration / timescale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a uri for requesting the specified chunk of the specified track.
|
||||
*
|
||||
|
@ -467,7 +467,7 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
|
||||
private String language;
|
||||
private ArrayList<Long> startTimes;
|
||||
|
||||
private long previousChunkDuration;
|
||||
private long lastChunkDuration;
|
||||
|
||||
public StreamElementParser(ElementParser parent, Uri baseUri) {
|
||||
super(parent, baseUri, TAG);
|
||||
@ -496,16 +496,16 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
|
||||
if (chunkIndex == 0) {
|
||||
// Assume the track starts at t = 0.
|
||||
startTime = 0;
|
||||
} else if (previousChunkDuration != -1L) {
|
||||
} else if (lastChunkDuration != -1L) {
|
||||
// Infer the start time from the previous chunk's start time and duration.
|
||||
startTime = startTimes.get(chunkIndex - 1) + previousChunkDuration;
|
||||
startTime = startTimes.get(chunkIndex - 1) + lastChunkDuration;
|
||||
} else {
|
||||
// We don't have the start time, and we're unable to infer it.
|
||||
throw new ParserException("Unable to infer start time");
|
||||
}
|
||||
}
|
||||
startTimes.add(startTime);
|
||||
previousChunkDuration = parseLong(parser, KEY_FRAGMENT_DURATION, -1L);
|
||||
lastChunkDuration = parseLong(parser, KEY_FRAGMENT_DURATION, -1L);
|
||||
chunkIndex++;
|
||||
}
|
||||
|
||||
@ -560,7 +560,8 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
|
||||
TrackElement[] trackElements = new TrackElement[tracks.size()];
|
||||
tracks.toArray(trackElements);
|
||||
return new StreamElement(baseUri, url, type, subType, timescale, name, qualityLevels,
|
||||
maxWidth, maxHeight, displayWidth, displayHeight, language, trackElements, startTimes);
|
||||
maxWidth, maxHeight, displayWidth, displayHeight, language, trackElements, startTimes,
|
||||
lastChunkDuration);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user