-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ExtractorMediaSource timeline dynamic until duration is set
We (eventually - albeit possibly infinitely far in the future) expect a timeline update with a window of known duration. This also stops live radio stream playbacks transitioning to ended state when their tracks are disabled. As part of this fix, I found an issue where getPeriodPosition could return null even when defaultPositionProjectionUs is 0, which is not as documented. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176492024
- Loading branch information
Showing
5 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ary/core/src/test/java/com/google/android/exoplayer2/source/SinglePeriodTimelineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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); | ||
} | ||
|
||
} |