Commit 67cb7d8d by olly Committed by Oliver Woodman

Fix SmoothStreaming Timeline

There were a few things wrong. Specifically the case in
the ref'd issue. Also, the timeline was being marked as
non-dynamic in the empty-but-live case (it should be
marked dynamic as segments may be added later).

Issue: #2760

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157103727
parent 22137f62
...@@ -287,39 +287,41 @@ public final class SsMediaSource implements MediaSource, ...@@ -287,39 +287,41 @@ public final class SsMediaSource implements MediaSource,
for (int i = 0; i < mediaPeriods.size(); i++) { for (int i = 0; i < mediaPeriods.size(); i++) {
mediaPeriods.get(i).updateManifest(manifest); mediaPeriods.get(i).updateManifest(manifest);
} }
long startTimeUs = Long.MAX_VALUE;
long endTimeUs = Long.MIN_VALUE;
for (StreamElement element : manifest.streamElements) {
if (element.chunkCount > 0) {
startTimeUs = Math.min(startTimeUs, element.getStartTimeUs(0));
endTimeUs = Math.max(endTimeUs, element.getStartTimeUs(element.chunkCount - 1)
+ element.getChunkDurationUs(element.chunkCount - 1));
}
}
Timeline timeline; Timeline timeline;
if (manifest.isLive) { if (startTimeUs == Long.MAX_VALUE) {
long startTimeUs = Long.MAX_VALUE; long periodDurationUs = manifest.isLive ? C.TIME_UNSET : 0;
long endTimeUs = Long.MIN_VALUE; timeline = new SinglePeriodTimeline(periodDurationUs, 0, 0, 0, true /* isSeekable */,
for (int i = 0; i < manifest.streamElements.length; i++) { manifest.isLive /* isDynamic */);
StreamElement element = manifest.streamElements[i]; } else if (manifest.isLive) {
if (element.chunkCount > 0) { if (manifest.dvrWindowLengthUs != C.TIME_UNSET && manifest.dvrWindowLengthUs > 0) {
startTimeUs = Math.min(startTimeUs, element.getStartTimeUs(0)); startTimeUs = Math.max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs);
endTimeUs = Math.max(endTimeUs, element.getStartTimeUs(element.chunkCount - 1)
+ element.getChunkDurationUs(element.chunkCount - 1));
}
} }
if (startTimeUs == Long.MAX_VALUE) { long durationUs = endTimeUs - startTimeUs;
timeline = new SinglePeriodTimeline(C.TIME_UNSET, false); long defaultStartPositionUs = durationUs - C.msToUs(livePresentationDelayMs);
} else { if (defaultStartPositionUs < MIN_LIVE_DEFAULT_START_POSITION_US) {
if (manifest.dvrWindowLengthUs != C.TIME_UNSET // The default start position is too close to the start of the live window. Set it to the
&& manifest.dvrWindowLengthUs > 0) { // minimum default start position provided the window is at least twice as big. Else set
startTimeUs = Math.max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs); // it to the middle of the window.
} defaultStartPositionUs = Math.min(MIN_LIVE_DEFAULT_START_POSITION_US, durationUs / 2);
long durationUs = endTimeUs - startTimeUs;
long defaultStartPositionUs = durationUs - C.msToUs(livePresentationDelayMs);
if (defaultStartPositionUs < MIN_LIVE_DEFAULT_START_POSITION_US) {
// The default start position is too close to the start of the live window. Set it to the
// minimum default start position provided the window is at least twice as big. Else set
// it to the middle of the window.
defaultStartPositionUs = Math.min(MIN_LIVE_DEFAULT_START_POSITION_US, durationUs / 2);
}
timeline = new SinglePeriodTimeline(C.TIME_UNSET, durationUs, startTimeUs,
defaultStartPositionUs, true /* isSeekable */, true /* isDynamic */);
} }
timeline = new SinglePeriodTimeline(C.TIME_UNSET, durationUs, startTimeUs,
defaultStartPositionUs, true /* isSeekable */, true /* isDynamic */);
} else { } else {
boolean isSeekable = manifest.durationUs != C.TIME_UNSET; long durationUs = manifest.durationUs != C.TIME_UNSET ? manifest.durationUs
timeline = new SinglePeriodTimeline(manifest.durationUs, isSeekable); : endTimeUs - startTimeUs;
timeline = new SinglePeriodTimeline(startTimeUs + durationUs, durationUs, startTimeUs, 0,
true /* isSeekable */, false /* isDynamic */);
} }
sourceListener.onSourceInfoRefreshed(timeline, manifest); sourceListener.onSourceInfoRefreshed(timeline, manifest);
} }
......
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