Commit a626a5e5 by Oliver Woodman

Take period start time into account when calculating segment times.

parent 2b27137e
......@@ -531,7 +531,8 @@ public class DashChunkSource implements ChunkSource {
if (initializationChunk.hasSeekMap()) {
representationHolder.segmentIndex = new DashWrappingSegmentIndex(
(ChunkIndex) initializationChunk.getSeekMap(),
initializationChunk.dataSpec.uri.toString());
initializationChunk.dataSpec.uri.toString(),
representationHolder.representation.periodStartMs * 1000);
}
// The null check avoids overwriting drmInitData obtained from the manifest with drmInitData
// obtained from the stream, as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
......@@ -638,7 +639,8 @@ public class DashChunkSource implements ChunkSource {
DataSpec dataSpec = new DataSpec(segmentUri.getUri(), segmentUri.start, segmentUri.length,
representation.getCacheKey());
long sampleOffsetUs = -1 * representation.presentationTimeOffsetUs;
long sampleOffsetUs = representation.periodStartMs * 1000
- representation.presentationTimeOffsetUs;
if (representation.format.mimeType.equals(MimeTypes.TEXT_VTT)) {
if (representationHolder.vttHeaderOffsetUs != sampleOffsetUs) {
// Update the VTT header.
......
......@@ -26,14 +26,17 @@ public class DashWrappingSegmentIndex implements DashSegmentIndex {
private final ChunkIndex chunkIndex;
private final String uri;
private final long startTimeUs;
/**
* @param chunkIndex The {@link ChunkIndex} to wrap.
* @param uri The URI where the data is located.
* @param startTimeUs The start time of the index, in microseconds.
*/
public DashWrappingSegmentIndex(ChunkIndex chunkIndex, String uri) {
public DashWrappingSegmentIndex(ChunkIndex chunkIndex, String uri, long startTimeUs) {
this.chunkIndex = chunkIndex;
this.uri = uri;
this.startTimeUs = startTimeUs;
}
@Override
......@@ -48,7 +51,7 @@ public class DashWrappingSegmentIndex implements DashSegmentIndex {
@Override
public long getTimeUs(int segmentNum) {
return chunkIndex.timesUs[segmentNum];
return chunkIndex.timesUs[segmentNum] + startTimeUs;
}
@Override
......@@ -63,7 +66,7 @@ public class DashWrappingSegmentIndex implements DashSegmentIndex {
@Override
public int getSegmentNum(long timeUs) {
return chunkIndex.getChunkIndex(timeUs);
return chunkIndex.getChunkIndex(timeUs - startTimeUs);
}
@Override
......
......@@ -266,12 +266,12 @@ public abstract class Representation implements FormatWrapper {
@Override
public int getSegmentNum(long timeUs) {
return segmentBase.getSegmentNum(timeUs);
return segmentBase.getSegmentNum(timeUs - periodStartMs * 1000);
}
@Override
public long getTimeUs(int segmentIndex) {
return segmentBase.getSegmentTimeUs(segmentIndex);
return segmentBase.getSegmentTimeUs(segmentIndex) + periodStartMs * 1000;
}
@Override
......
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