Skip to content

Commit

Permalink
Offset SIDX timestamps by presentationTimeOffset
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199856613
  • Loading branch information
ojw28 committed Jun 18, 2018
1 parent 799d281 commit 9ecf959
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* IMA: Don't advertise support for video/mpeg ad media, as we don't have an
extractor for this ([#4297](https://github.com/google/ExoPlayer/issues/4297)).
* DASH: Fix playback getting stuck when playing representations that have both
sidx atoms and non-zero presentationTimeOffset values.
* Mitigate memory leaks when `MediaSource` loads are slow to cancel
([#4249](https://github.com/google/ExoPlayer/issues/4249)).
* Fix inconsistent `Player.EventListener` invocations for recursive player state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
public final class DashWrappingSegmentIndex implements DashSegmentIndex {

private final ChunkIndex chunkIndex;
private final long timeOffsetUs;

/**
* @param chunkIndex The {@link ChunkIndex} to wrap.
* @param timeOffsetUs An offset to subtract from the times in the wrapped index, in microseconds.
*/
public DashWrappingSegmentIndex(ChunkIndex chunkIndex) {
public DashWrappingSegmentIndex(ChunkIndex chunkIndex, long timeOffsetUs) {
this.chunkIndex = chunkIndex;
this.timeOffsetUs = timeOffsetUs;
}

@Override
Expand All @@ -45,7 +48,7 @@ public int getSegmentCount(long periodDurationUs) {

@Override
public long getTimeUs(long segmentNum) {
return chunkIndex.timesUs[(int) segmentNum];
return chunkIndex.timesUs[(int) segmentNum] - timeOffsetUs;
}

@Override
Expand All @@ -61,7 +64,7 @@ public RangedUri getSegmentUrl(long segmentNum) {

@Override
public long getSegmentNum(long timeUs, long periodDurationUs) {
return chunkIndex.getChunkIndex(timeUs);
return chunkIndex.getChunkIndex(timeUs + timeOffsetUs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ public void onChunkLoadCompleted(Chunk chunk) {
if (representationHolder.segmentIndex == null) {
SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
if (seekMap != null) {
representationHolder.segmentIndex = new DashWrappingSegmentIndex((ChunkIndex) seekMap);
representationHolder.segmentIndex =
new DashWrappingSegmentIndex(
(ChunkIndex) seekMap,
representationHolder.representation.presentationTimeOffsetUs);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private static void addSegment(
return index;
}
ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap);
return seekMap == null
? null
: new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}

}

0 comments on commit 9ecf959

Please sign in to comment.