Commit 56c1c3f6 by Oliver Woodman

Revert "Make ExtractorMediaSource timeline dynamic until duration is set"

This reverts commit b688a562.
parent 74569bba
...@@ -45,7 +45,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase { ...@@ -45,7 +45,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
} }
public void testNoClipping() { public void testNoClipping() {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true, false); Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true);
Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US); Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
...@@ -56,7 +56,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase { ...@@ -56,7 +56,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
} }
public void testClippingUnseekableWindowThrows() { public void testClippingUnseekableWindowThrows() {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), false, false); Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), false);
// If the unseekable window isn't clipped, clipping succeeds. // If the unseekable window isn't clipped, clipping succeeds.
getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US); getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
...@@ -70,7 +70,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase { ...@@ -70,7 +70,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
} }
public void testClippingStart() { public void testClippingStart() {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true, false); Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true);
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
TEST_PERIOD_DURATION_US); TEST_PERIOD_DURATION_US);
...@@ -81,7 +81,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase { ...@@ -81,7 +81,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
} }
public void testClippingEnd() { public void testClippingEnd() {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true, false); Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true);
Timeline clippedTimeline = getClippedTimeline(timeline, 0, Timeline clippedTimeline = getClippedTimeline(timeline, 0,
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US); TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
...@@ -92,7 +92,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase { ...@@ -92,7 +92,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
} }
public void testClippingStartAndEnd() { public void testClippingStartAndEnd() {
Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true, false); Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true);
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2); TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
......
...@@ -204,11 +204,8 @@ public final class ExtractorMediaSource implements MediaSource, ExtractorMediaPe ...@@ -204,11 +204,8 @@ public final class ExtractorMediaSource implements MediaSource, ExtractorMediaPe
private void notifySourceInfoRefreshed(long durationUs, boolean isSeekable) { private void notifySourceInfoRefreshed(long durationUs, boolean isSeekable) {
timelineDurationUs = durationUs; timelineDurationUs = durationUs;
timelineIsSeekable = isSeekable; timelineIsSeekable = isSeekable;
// If the duration is currently unset, we expect to be able to update the window when its sourceListener.onSourceInfoRefreshed(
// duration eventually becomes known. this, new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable), null);
boolean isDynamic = timelineDurationUs == C.TIME_UNSET;
sourceListener.onSourceInfoRefreshed(this,
new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable, isDynamic), null);
} }
} }
...@@ -36,14 +36,14 @@ public final class SinglePeriodTimeline extends Timeline { ...@@ -36,14 +36,14 @@ public final class SinglePeriodTimeline extends Timeline {
private final boolean isDynamic; private final boolean isDynamic;
/** /**
* Creates a timeline containing a single period and a window that spans it. * Creates a timeline of one period of known duration, and a static window starting at zero and
* extending to that duration.
* *
* @param durationUs The duration of the period, in microseconds. * @param durationUs The duration of the period, in microseconds.
* @param isSeekable Whether seeking is supported within the period. * @param isSeekable Whether seeking is supported within the period.
* @param isDynamic Whether the window may change when the timeline is updated.
*/ */
public SinglePeriodTimeline(long durationUs, boolean isSeekable, boolean isDynamic) { public SinglePeriodTimeline(long durationUs, boolean isSeekable) {
this(durationUs, durationUs, 0, 0, isSeekable, isDynamic); this(durationUs, durationUs, 0, 0, isSeekable, false);
} }
/** /**
...@@ -63,7 +63,7 @@ public final class SinglePeriodTimeline extends Timeline { ...@@ -63,7 +63,7 @@ public final class SinglePeriodTimeline extends Timeline {
long windowPositionInPeriodUs, long windowDefaultStartPositionUs, boolean isSeekable, long windowPositionInPeriodUs, long windowDefaultStartPositionUs, boolean isSeekable,
boolean isDynamic) { boolean isDynamic) {
this(C.TIME_UNSET, C.TIME_UNSET, periodDurationUs, windowDurationUs, windowPositionInPeriodUs, this(C.TIME_UNSET, C.TIME_UNSET, periodDurationUs, windowDurationUs, windowPositionInPeriodUs,
windowDefaultStartPositionUs, isSeekable, isDynamic); windowDefaultStartPositionUs, isSeekable, isDynamic);
} }
/** /**
...@@ -106,16 +106,11 @@ public final class SinglePeriodTimeline extends Timeline { ...@@ -106,16 +106,11 @@ public final class SinglePeriodTimeline extends Timeline {
Assertions.checkIndex(windowIndex, 0, 1); Assertions.checkIndex(windowIndex, 0, 1);
Object id = setIds ? ID : null; Object id = setIds ? ID : null;
long windowDefaultStartPositionUs = this.windowDefaultStartPositionUs; long windowDefaultStartPositionUs = this.windowDefaultStartPositionUs;
if (isDynamic && defaultPositionProjectionUs != 0) { if (isDynamic) {
if (windowDurationUs == C.TIME_UNSET) { windowDefaultStartPositionUs += defaultPositionProjectionUs;
// Don't allow projection into a window that has an unknown duration. if (windowDefaultStartPositionUs > windowDurationUs) {
// The projection takes us beyond the end of the live window.
windowDefaultStartPositionUs = C.TIME_UNSET; windowDefaultStartPositionUs = C.TIME_UNSET;
} else {
windowDefaultStartPositionUs += defaultPositionProjectionUs;
if (windowDefaultStartPositionUs > windowDurationUs) {
// The projection takes us beyond the end of the window.
windowDefaultStartPositionUs = C.TIME_UNSET;
}
} }
} }
return window.set(id, presentationStartTimeMs, windowStartTimeMs, isSeekable, isDynamic, return window.set(id, presentationStartTimeMs, windowStartTimeMs, isSeekable, isDynamic,
......
...@@ -110,7 +110,7 @@ public final class SingleSampleMediaSource implements MediaSource { ...@@ -110,7 +110,7 @@ public final class SingleSampleMediaSource implements MediaSource {
this.eventListener = eventListener; this.eventListener = eventListener;
this.eventSourceId = eventSourceId; this.eventSourceId = eventSourceId;
this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream; this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
timeline = new SinglePeriodTimeline(durationUs, true, false); timeline = new SinglePeriodTimeline(durationUs, true);
} }
// MediaSource implementation. // MediaSource implementation.
......
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Timeline.Period;
import com.google.android.exoplayer2.Timeline.Window;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/**
* Unit test for {@link SinglePeriodTimeline}.
*/
@RunWith(RobolectricTestRunner.class)
@Config(sdk = Config.TARGET_SDK, manifest = Config.NONE)
public final class SinglePeriodTimelineTest {
private Window window;
private Period period;
@Before
public void setUp() throws Exception {
window = new Window();
period = new Period();
}
@Test
public void testGetPeriodPositionDynamicWindowUnknownDuration() {
SinglePeriodTimeline timeline = new SinglePeriodTimeline(C.TIME_UNSET, false, true);
// Should return null with any positive position projection.
Pair<Integer, Long> position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 1);
assertThat(position).isNull();
// Should return (0, 0) without a position projection.
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 0);
assertThat(position.first).isEqualTo(0);
assertThat(position.second).isEqualTo(0);
}
@Test
public void testGetPeriodPositionDynamicWindowKnownDuration() {
long windowDurationUs = 1000;
SinglePeriodTimeline timeline = new SinglePeriodTimeline(windowDurationUs, windowDurationUs, 0,
0, false, true);
// Should return null with a positive position projection beyond window duration.
Pair<Integer, Long> position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET,
windowDurationUs + 1);
assertThat(position).isNull();
// Should return (0, duration) with a projection equal to window duration.
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, windowDurationUs);
assertThat(position.first).isEqualTo(0);
assertThat(position.second).isEqualTo(windowDurationUs);
// Should return (0, 0) without a position projection.
position = timeline.getPeriodPosition(window, period, 0, C.TIME_UNSET, 0);
assertThat(position.first).isEqualTo(0);
assertThat(position.second).isEqualTo(0);
}
}
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