Commit 525b3097 by Oliver Woodman

SmoothStreaming - Parse last chunk duration.

parent f52742b1
...@@ -173,11 +173,12 @@ public class SmoothStreamingManifest { ...@@ -173,11 +173,12 @@ public class SmoothStreamingManifest {
private final String chunkTemplate; private final String chunkTemplate;
private final List<Long> chunkStartTimes; private final List<Long> chunkStartTimes;
private final long lastChunkDuration;
public StreamElement(Uri baseUri, String chunkTemplate, int type, String subType, public StreamElement(Uri baseUri, String chunkTemplate, int type, String subType,
long timescale, String name, int qualityLevels, int maxWidth, int maxHeight, long timescale, String name, int qualityLevels, int maxWidth, int maxHeight,
int displayWidth, int displayHeight, String language, TrackElement[] tracks, int displayWidth, int displayHeight, String language, TrackElement[] tracks,
List<Long> chunkStartTimes) { List<Long> chunkStartTimes, long lastChunkDuration) {
this.baseUri = baseUri; this.baseUri = baseUri;
this.chunkTemplate = chunkTemplate; this.chunkTemplate = chunkTemplate;
this.type = type; this.type = type;
...@@ -193,6 +194,7 @@ public class SmoothStreamingManifest { ...@@ -193,6 +194,7 @@ public class SmoothStreamingManifest {
this.tracks = tracks; this.tracks = tracks;
this.chunkCount = chunkStartTimes.size(); this.chunkCount = chunkStartTimes.size();
this.chunkStartTimes = chunkStartTimes; this.chunkStartTimes = chunkStartTimes;
this.lastChunkDuration = lastChunkDuration;
} }
/** /**
...@@ -216,6 +218,18 @@ public class SmoothStreamingManifest { ...@@ -216,6 +218,18 @@ public class SmoothStreamingManifest {
} }
/** /**
* 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. * Builds a uri for requesting the specified chunk of the specified track.
* *
* @param track The index of the track for which to build the URL. * @param track The index of the track for which to build the URL.
......
...@@ -467,7 +467,7 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea ...@@ -467,7 +467,7 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
private String language; private String language;
private ArrayList<Long> startTimes; private ArrayList<Long> startTimes;
private long previousChunkDuration; private long lastChunkDuration;
public StreamElementParser(ElementParser parent, Uri baseUri) { public StreamElementParser(ElementParser parent, Uri baseUri) {
super(parent, baseUri, TAG); super(parent, baseUri, TAG);
...@@ -496,16 +496,16 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea ...@@ -496,16 +496,16 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
if (chunkIndex == 0) { if (chunkIndex == 0) {
// Assume the track starts at t = 0. // Assume the track starts at t = 0.
startTime = 0; startTime = 0;
} else if (previousChunkDuration != -1L) { } else if (lastChunkDuration != -1L) {
// Infer the start time from the previous chunk's start time and duration. // 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 { } else {
// We don't have the start time, and we're unable to infer it. // We don't have the start time, and we're unable to infer it.
throw new ParserException("Unable to infer start time"); throw new ParserException("Unable to infer start time");
} }
} }
startTimes.add(startTime); startTimes.add(startTime);
previousChunkDuration = parseLong(parser, KEY_FRAGMENT_DURATION, -1L); lastChunkDuration = parseLong(parser, KEY_FRAGMENT_DURATION, -1L);
chunkIndex++; chunkIndex++;
} }
...@@ -560,7 +560,8 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea ...@@ -560,7 +560,8 @@ public class SmoothStreamingManifestParser implements ManifestParser<SmoothStrea
TrackElement[] trackElements = new TrackElement[tracks.size()]; TrackElement[] trackElements = new TrackElement[tracks.size()];
tracks.toArray(trackElements); tracks.toArray(trackElements);
return new StreamElement(baseUri, url, type, subType, timescale, name, qualityLevels, 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);
} }
} }
......
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