Skip to content

Commit

Permalink
Use media source tag in dummy timeline.
Browse files Browse the repository at this point in the history
This is now possible as it's directly accessible from the media source.

Issue:#5177
Issue:#5155
PiperOrigin-RevId: 224321917
  • Loading branch information
tonihei authored and ojw28 committed Dec 19, 2018
1 parent ee1ec8d commit 0e139e9
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ private static Object getPeriodUid(MediaSourceHolder holder, Object childPeriodU

public MediaSourceHolder(MediaSource mediaSource) {
this.mediaSource = mediaSource;
this.timeline = new DeferredTimeline();
this.timeline = DeferredTimeline.createWithDummyTimeline(mediaSource.getTag());
this.activeMediaPeriods = new ArrayList<>();
this.uid = new Object();
}
Expand Down Expand Up @@ -951,10 +951,18 @@ public int getPeriodCount() {
private static final class DeferredTimeline extends ForwardingTimeline {

private static final Object DUMMY_ID = new Object();
private static final DummyTimeline DUMMY_TIMELINE = new DummyTimeline();

private final Object replacedId;

/**
* Returns an instance with a dummy timeline using the provided window tag.
*
* @param windowTag A window tag.
*/
public static DeferredTimeline createWithDummyTimeline(@Nullable Object windowTag) {
return new DeferredTimeline(new DummyTimeline(windowTag), DUMMY_ID);
}

/**
* Returns an instance with a real timeline, replacing the provided period ID with the already
* assigned dummy period ID.
Expand All @@ -968,11 +976,6 @@ public static DeferredTimeline createWithRealTimeline(
return new DeferredTimeline(timeline, firstPeriodUid);
}

/** Creates deferred timeline exposing a {@link DummyTimeline}. */
public DeferredTimeline() {
this(DUMMY_TIMELINE, DUMMY_ID);
}

private DeferredTimeline(Timeline timeline, Object replacedId) {
super(timeline);
this.replacedId = replacedId;
Expand Down Expand Up @@ -1016,6 +1019,12 @@ public Object getUidOfPeriod(int periodIndex) {
/** Dummy placeholder timeline with one dynamic window with a period of indeterminate duration. */
private static final class DummyTimeline extends Timeline {

@Nullable private final Object tag;

public DummyTimeline(@Nullable Object tag) {
this.tag = tag;
}

@Override
public int getWindowCount() {
return 1;
Expand All @@ -1025,7 +1034,7 @@ public int getWindowCount() {
public Window getWindow(
int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
return window.set(
/* tag= */ null,
tag,
/* presentationStartTimeMs= */ C.TIME_UNSET,
/* windowStartTimeMs= */ C.TIME_UNSET,
/* isSeekable= */ false,
Expand Down

0 comments on commit 0e139e9

Please sign in to comment.