mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Deprecate setTag parameter in Timeline.getWindow.
There is no point in having this parameter as the tag should always be a single immutable object instantiated at the time the Timeline is created or earlier. So there is no preformance benefit and it's error-prone in case people forget to set setTag=true. PiperOrigin-RevId: 264117041
This commit is contained in:
parent
652c2f9c18
commit
20fd4e16d2
14 changed files with 43 additions and 66 deletions
|
|
@ -40,6 +40,7 @@
|
||||||
([#5619](https://github.com/google/ExoPlayer/issues/5619)).
|
([#5619](https://github.com/google/ExoPlayer/issues/5619)).
|
||||||
* Fix issue where player errors are thrown too early at playlist transitions
|
* Fix issue where player errors are thrown too early at playlist transitions
|
||||||
([#5407](https://github.com/google/ExoPlayer/issues/5407)).
|
([#5407](https://github.com/google/ExoPlayer/issues/5407)).
|
||||||
|
* Deprecate `setTag` parameter of `Timeline.getWindow`. Tags will always be set.
|
||||||
|
|
||||||
### 2.10.4 ###
|
### 2.10.4 ###
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,11 @@ import java.util.Arrays;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
long durationUs = durationsUs[windowIndex];
|
long durationUs = durationsUs[windowIndex];
|
||||||
boolean isDynamic = durationUs == C.TIME_UNSET;
|
boolean isDynamic = durationUs == C.TIME_UNSET;
|
||||||
Object tag = setTag ? ids[windowIndex] : null;
|
|
||||||
return window.set(
|
return window.set(
|
||||||
tag,
|
/* tag= */ ids[windowIndex],
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
/* presentationStartTimeMs= */ C.TIME_UNSET,
|
/* presentationStartTimeMs= */ C.TIME_UNSET,
|
||||||
/* windowStartTimeMs= */ C.TIME_UNSET,
|
/* windowStartTimeMs= */ C.TIME_UNSET,
|
||||||
|
|
|
||||||
|
|
@ -95,18 +95,14 @@ public abstract class BasePlayer implements Player {
|
||||||
@Nullable
|
@Nullable
|
||||||
public final Object getCurrentTag() {
|
public final Object getCurrentTag() {
|
||||||
Timeline timeline = getCurrentTimeline();
|
Timeline timeline = getCurrentTimeline();
|
||||||
return timeline.isEmpty()
|
return timeline.isEmpty() ? null : timeline.getWindow(getCurrentWindowIndex(), window).tag;
|
||||||
? null
|
|
||||||
: timeline.getWindow(getCurrentWindowIndex(), window, /* setTag= */ true).tag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public final Object getCurrentManifest() {
|
public final Object getCurrentManifest() {
|
||||||
Timeline timeline = getCurrentTimeline();
|
Timeline timeline = getCurrentTimeline();
|
||||||
return timeline.isEmpty()
|
return timeline.isEmpty() ? null : timeline.getWindow(getCurrentWindowIndex(), window).manifest;
|
||||||
? null
|
|
||||||
: timeline.getWindow(getCurrentWindowIndex(), window, /* setTag= */ false).manifest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -520,8 +520,7 @@ public abstract class Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -633,28 +632,20 @@ public abstract class Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates a {@link Window} with data for the window at the specified index. Does not populate
|
* Populates a {@link Window} with data for the window at the specified index.
|
||||||
* {@link Window#tag}.
|
|
||||||
*
|
*
|
||||||
* @param windowIndex The index of the window.
|
* @param windowIndex The index of the window.
|
||||||
* @param window The {@link Window} to populate. Must not be null.
|
* @param window The {@link Window} to populate. Must not be null.
|
||||||
* @return The populated {@link Window}, for convenience.
|
* @return The populated {@link Window}, for convenience.
|
||||||
*/
|
*/
|
||||||
public final Window getWindow(int windowIndex, Window window) {
|
public final Window getWindow(int windowIndex, Window window) {
|
||||||
return getWindow(windowIndex, window, false);
|
return getWindow(windowIndex, window, /* defaultPositionProjectionUs= */ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link #getWindow(int, Window)} instead. Tags will always be set. */
|
||||||
* Populates a {@link Window} with data for the window at the specified index.
|
@Deprecated
|
||||||
*
|
|
||||||
* @param windowIndex The index of the window.
|
|
||||||
* @param window The {@link Window} to populate. Must not be null.
|
|
||||||
* @param setTag Whether {@link Window#tag} should be populated. If false, the field will be set
|
|
||||||
* to null. The caller should pass false for efficiency reasons unless the field is required.
|
|
||||||
* @return The populated {@link Window}, for convenience.
|
|
||||||
*/
|
|
||||||
public final Window getWindow(int windowIndex, Window window, boolean setTag) {
|
public final Window getWindow(int windowIndex, Window window, boolean setTag) {
|
||||||
return getWindow(windowIndex, window, setTag, 0);
|
return getWindow(windowIndex, window, /* defaultPositionProjectionUs= */ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -662,14 +653,21 @@ public abstract class Timeline {
|
||||||
*
|
*
|
||||||
* @param windowIndex The index of the window.
|
* @param windowIndex The index of the window.
|
||||||
* @param window The {@link Window} to populate. Must not be null.
|
* @param window The {@link Window} to populate. Must not be null.
|
||||||
* @param setTag Whether {@link Window#tag} should be populated. If false, the field will be set
|
|
||||||
* to null. The caller should pass false for efficiency reasons unless the field is required.
|
|
||||||
* @param defaultPositionProjectionUs A duration into the future that the populated window's
|
* @param defaultPositionProjectionUs A duration into the future that the populated window's
|
||||||
* default start position should be projected.
|
* default start position should be projected.
|
||||||
* @return The populated {@link Window}, for convenience.
|
* @return The populated {@link Window}, for convenience.
|
||||||
*/
|
*/
|
||||||
public abstract Window getWindow(
|
@SuppressWarnings("deprecation")
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs);
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
|
return getWindow(windowIndex, window, /* setTag= */ true, defaultPositionProjectionUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated Implement {@link #getWindow(int, Window, long)} instead and always set the tag. */
|
||||||
|
@Deprecated
|
||||||
|
public Window getWindow(
|
||||||
|
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
||||||
|
return getWindow(windowIndex, window, defaultPositionProjectionUs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of periods in the timeline.
|
* Returns the number of periods in the timeline.
|
||||||
|
|
@ -750,7 +748,7 @@ public abstract class Timeline {
|
||||||
long windowPositionUs,
|
long windowPositionUs,
|
||||||
long defaultPositionProjectionUs) {
|
long defaultPositionProjectionUs) {
|
||||||
Assertions.checkIndex(windowIndex, 0, getWindowCount());
|
Assertions.checkIndex(windowIndex, 0, getWindowCount());
|
||||||
getWindow(windowIndex, window, false, defaultPositionProjectionUs);
|
getWindow(windowIndex, window, defaultPositionProjectionUs);
|
||||||
if (windowPositionUs == C.TIME_UNSET) {
|
if (windowPositionUs == C.TIME_UNSET) {
|
||||||
windowPositionUs = window.getDefaultPositionUs();
|
windowPositionUs = window.getDefaultPositionUs();
|
||||||
if (windowPositionUs == C.TIME_UNSET) {
|
if (windowPositionUs == C.TIME_UNSET) {
|
||||||
|
|
|
||||||
|
|
@ -189,14 +189,12 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Window getWindow(
|
public final Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
int childIndex = getChildIndexByWindowIndex(windowIndex);
|
int childIndex = getChildIndexByWindowIndex(windowIndex);
|
||||||
int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex);
|
int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex);
|
||||||
int firstPeriodIndexInChild = getFirstPeriodIndexByChildIndex(childIndex);
|
int firstPeriodIndexInChild = getFirstPeriodIndexByChildIndex(childIndex);
|
||||||
getTimelineByChildIndex(childIndex)
|
getTimelineByChildIndex(childIndex)
|
||||||
.getWindow(
|
.getWindow(windowIndex - firstWindowIndexInChild, window, defaultPositionProjectionUs);
|
||||||
windowIndex - firstWindowIndexInChild, window, setTag, defaultPositionProjectionUs);
|
|
||||||
window.firstPeriodIndex += firstPeriodIndexInChild;
|
window.firstPeriodIndex += firstPeriodIndexInChild;
|
||||||
window.lastPeriodIndex += firstPeriodIndexInChild;
|
window.lastPeriodIndex += firstPeriodIndexInChild;
|
||||||
return window;
|
return window;
|
||||||
|
|
|
||||||
|
|
@ -342,10 +342,8 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
timeline.getWindow(/* windowIndex= */ 0, window, /* defaultPositionProjectionUs= */ 0);
|
||||||
timeline.getWindow(
|
|
||||||
/* windowIndex= */ 0, window, setTag, /* defaultPositionProjectionUs= */ 0);
|
|
||||||
window.positionInFirstPeriodUs += startUs;
|
window.positionInFirstPeriodUs += startUs;
|
||||||
window.durationUs = durationUs;
|
window.durationUs = durationUs;
|
||||||
window.isDynamic = isDynamic;
|
window.isDynamic = isDynamic;
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,8 @@ public abstract class ForwardingTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
return timeline.getWindow(windowIndex, window, defaultPositionProjectionUs);
|
||||||
return timeline.getWindow(windowIndex, window, setTag, defaultPositionProjectionUs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -287,8 +287,7 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
return window.set(
|
return window.set(
|
||||||
tag,
|
tag,
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,8 @@ public final class SinglePeriodTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
Assertions.checkIndex(windowIndex, 0, 1);
|
Assertions.checkIndex(windowIndex, 0, 1);
|
||||||
Object tag = setTag ? this.tag : null;
|
|
||||||
long windowDefaultStartPositionUs = this.windowDefaultStartPositionUs;
|
long windowDefaultStartPositionUs = this.windowDefaultStartPositionUs;
|
||||||
if (isDynamic && defaultPositionProjectionUs != 0) {
|
if (isDynamic && defaultPositionProjectionUs != 0) {
|
||||||
if (windowDurationUs == C.TIME_UNSET) {
|
if (windowDurationUs == C.TIME_UNSET) {
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,8 @@ public final class SinglePeriodAdTimeline extends ForwardingTimeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
window = super.getWindow(windowIndex, window, defaultPositionProjectionUs);
|
||||||
window = super.getWindow(windowIndex, window, setTag, defaultPositionProjectionUs);
|
|
||||||
if (window.durationUs == C.TIME_UNSET) {
|
if (window.durationUs == C.TIME_UNSET) {
|
||||||
window.durationUs = adPlaybackState.contentDurationUs;
|
window.durationUs = adPlaybackState.contentDurationUs;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,7 @@ public final class SinglePeriodTimelineTest {
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
/* tag= */ null);
|
/* tag= */ null);
|
||||||
|
|
||||||
assertThat(timeline.getWindow(/* windowIndex= */ 0, window, /* setTag= */ false).tag).isNull();
|
assertThat(timeline.getWindow(/* windowIndex= */ 0, window).tag).isNull();
|
||||||
assertThat(timeline.getWindow(/* windowIndex= */ 0, window, /* setTag= */ true).tag).isNull();
|
|
||||||
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ false).id).isNull();
|
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ false).id).isNull();
|
||||||
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ true).id).isNull();
|
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ true).id).isNull();
|
||||||
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ false).uid).isNull();
|
assertThat(timeline.getPeriod(/* periodIndex= */ 0, period, /* setIds= */ false).uid).isNull();
|
||||||
|
|
@ -98,7 +97,7 @@ public final class SinglePeriodTimelineTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setTag_isUsedForWindowTag() {
|
public void getWindow_setsTag() {
|
||||||
Object tag = new Object();
|
Object tag = new Object();
|
||||||
SinglePeriodTimeline timeline =
|
SinglePeriodTimeline timeline =
|
||||||
new SinglePeriodTimeline(
|
new SinglePeriodTimeline(
|
||||||
|
|
@ -108,9 +107,7 @@ public final class SinglePeriodTimelineTest {
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
tag);
|
tag);
|
||||||
|
|
||||||
assertThat(timeline.getWindow(/* windowIndex= */ 0, window, /* setTag= */ false).tag).isNull();
|
assertThat(timeline.getWindow(/* windowIndex= */ 0, window).tag).isEqualTo(tag);
|
||||||
assertThat(timeline.getWindow(/* windowIndex= */ 0, window, /* setTag= */ true).tag)
|
|
||||||
.isEqualTo(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -1207,18 +1207,16 @@ public final class DashMediaSource extends BaseMediaSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
Assertions.checkIndex(windowIndex, 0, 1);
|
Assertions.checkIndex(windowIndex, 0, 1);
|
||||||
long windowDefaultStartPositionUs = getAdjustedWindowDefaultStartPositionUs(
|
long windowDefaultStartPositionUs = getAdjustedWindowDefaultStartPositionUs(
|
||||||
defaultPositionProjectionUs);
|
defaultPositionProjectionUs);
|
||||||
Object tag = setTag ? windowTag : null;
|
|
||||||
boolean isDynamic =
|
boolean isDynamic =
|
||||||
manifest.dynamic
|
manifest.dynamic
|
||||||
&& manifest.minUpdatePeriodMs != C.TIME_UNSET
|
&& manifest.minUpdatePeriodMs != C.TIME_UNSET
|
||||||
&& manifest.durationMs == C.TIME_UNSET;
|
&& manifest.durationMs == C.TIME_UNSET;
|
||||||
return window.set(
|
return window.set(
|
||||||
tag,
|
windowTag,
|
||||||
manifest,
|
manifest,
|
||||||
presentationStartTimeMs,
|
presentationStartTimeMs,
|
||||||
windowStartTimeMs,
|
windowStartTimeMs,
|
||||||
|
|
|
||||||
|
|
@ -179,12 +179,10 @@ public final class FakeTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window getWindow(
|
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
|
||||||
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
|
|
||||||
TimelineWindowDefinition windowDefinition = windowDefinitions[windowIndex];
|
TimelineWindowDefinition windowDefinition = windowDefinitions[windowIndex];
|
||||||
Object tag = setTag ? windowDefinition.id : null;
|
|
||||||
return window.set(
|
return window.set(
|
||||||
tag,
|
/* tag= */ windowDefinition.id,
|
||||||
manifests[windowIndex],
|
manifests[windowIndex],
|
||||||
/* presentationStartTimeMs= */ C.TIME_UNSET,
|
/* presentationStartTimeMs= */ C.TIME_UNSET,
|
||||||
/* windowStartTimeMs= */ C.TIME_UNSET,
|
/* windowStartTimeMs= */ C.TIME_UNSET,
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public final class TimelineAsserts {
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
assertThat(timeline.getWindowCount()).isEqualTo(expectedWindowTags.length);
|
assertThat(timeline.getWindowCount()).isEqualTo(expectedWindowTags.length);
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
timeline.getWindow(i, window, true);
|
timeline.getWindow(i, window);
|
||||||
if (expectedWindowTags[i] != null) {
|
if (expectedWindowTags[i] != null) {
|
||||||
assertThat(window.tag).isEqualTo(expectedWindowTags[i]);
|
assertThat(window.tag).isEqualTo(expectedWindowTags[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ public final class TimelineAsserts {
|
||||||
public static void assertWindowIsDynamic(Timeline timeline, boolean... windowIsDynamic) {
|
public static void assertWindowIsDynamic(Timeline timeline, boolean... windowIsDynamic) {
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
timeline.getWindow(i, window, true);
|
timeline.getWindow(i, window);
|
||||||
assertThat(window.isDynamic).isEqualTo(windowIsDynamic[i]);
|
assertThat(window.isDynamic).isEqualTo(windowIsDynamic[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +129,7 @@ public final class TimelineAsserts {
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
Period period = new Period();
|
Period period = new Period();
|
||||||
for (int i = 0; i < windowCount; i++) {
|
for (int i = 0; i < windowCount; i++) {
|
||||||
timeline.getWindow(i, window, true);
|
timeline.getWindow(i, window);
|
||||||
assertThat(window.firstPeriodIndex).isEqualTo(accumulatedPeriodCounts[i]);
|
assertThat(window.firstPeriodIndex).isEqualTo(accumulatedPeriodCounts[i]);
|
||||||
assertThat(window.lastPeriodIndex).isEqualTo(accumulatedPeriodCounts[i + 1] - 1);
|
assertThat(window.lastPeriodIndex).isEqualTo(accumulatedPeriodCounts[i + 1] - 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue