Commit a58bffbe by andrewlewis Committed by Oliver Woodman

Fix clipping to end of source

Issue: #3966

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188465096
parent 8f952162
......@@ -226,7 +226,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> {
}
this.startUs = startUs;
this.endUs = resolvedEndUs;
durationUs = endUs == C.TIME_UNSET ? C.TIME_UNSET : endUs - startUs;
durationUs = resolvedEndUs == C.TIME_UNSET ? C.TIME_UNSET : (resolvedEndUs - startUs);
}
@Override
......
......@@ -125,6 +125,36 @@ public final class ClippingMediaSourceTest {
}
@Test
public void testClippingToEndOfSourceWithDurationSetsDuration() throws IOException {
// Create a child timeline that has a known duration.
Timeline timeline =
new SinglePeriodTimeline(
/* durationUs= */ TEST_PERIOD_DURATION_US,
/* isSeekable= */ true,
/* isDynamic= */ false);
// When clipping to the end, the clipped timeline should also have a duration.
Timeline clippedTimeline =
getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, C.TIME_END_OF_SOURCE);
assertThat(clippedTimeline.getWindow(/* windowIndex= */ 0, window).getDurationUs())
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
}
@Test
public void testClippingToEndOfSourceWithUnsetDurationDoesNotSetDuration() throws IOException {
// Create a child timeline that has an unknown duration.
Timeline timeline =
new SinglePeriodTimeline(
/* durationUs= */ C.TIME_UNSET, /* isSeekable= */ true, /* isDynamic= */ false);
// When clipping to the end, the clipped timeline should also have an unset duration.
Timeline clippedTimeline =
getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, C.TIME_END_OF_SOURCE);
assertThat(clippedTimeline.getWindow(/* windowIndex= */ 0, window).getDurationUs())
.isEqualTo(C.TIME_UNSET);
}
@Test
public void testClippingStartAndEnd() throws IOException {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true, false);
......
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