Skip to content

Commit

Permalink
Make manifest loads on timeline refresh optional in FakeMediaSource.
Browse files Browse the repository at this point in the history
Every timeline refresh currently assumes that it corresponds to a manifest
refresh and issues the respective load events. However, there are other
timeline updates that don't have a manifest refresh (e.g. ad state updates)and thus shouldn't issue these events.

PiperOrigin-RevId: 313150489
  • Loading branch information
tonihei authored and ojw28 committed May 27, 2020
1 parent f099f57 commit ee11d9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ public void onPositionDiscontinuity(
/* isSeekable= */ true,
/* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND,
adPlaybackState.get())));
adPlaybackState.get())),
/* sendManifestLoadEvents= */ false);
}
}
});
Expand Down Expand Up @@ -956,25 +957,19 @@ public void onPositionDiscontinuity(
assertThat(listener.getEvents(EVENT_LOAD_STARTED))
.containsExactly(
WINDOW_0 /* content manifest */,
WINDOW_0 /* preroll manifest */,
prerollAd,
contentAfterPreroll,
WINDOW_0 /* midroll manifest */,
midrollAd,
contentAfterMidroll,
WINDOW_0 /* postroll manifest */,
postrollAd,
contentAfterPostroll);
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED))
.containsExactly(
WINDOW_0 /* content manifest */,
WINDOW_0 /* preroll manifest */,
prerollAd,
contentAfterPreroll,
WINDOW_0 /* midroll manifest */,
midrollAd,
contentAfterMidroll,
WINDOW_0 /* postroll manifest */,
postrollAd,
contentAfterPostroll);
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

Expand Down Expand Up @@ -159,7 +159,7 @@ public synchronized void prepareSourceInternal(@Nullable TransferListener mediaT
releasedSource = false;
sourceInfoRefreshHandler = Util.createHandler();
if (timeline != null) {
finishSourcePreparation();
finishSourcePreparation(/* sendManifestLoadEvents= */ true);
}
}

Expand Down Expand Up @@ -209,15 +209,29 @@ protected void releaseSourceInternal() {
/**
* Sets a new timeline. If the source is already prepared, this triggers a source info refresh
* message being sent to the listener.
*
* @param newTimeline The new {@link Timeline}.
*/
public void setNewSourceInfo(Timeline newTimeline) {
setNewSourceInfo(newTimeline, /* sendManifestLoadEvents= */ true);
}

/**
* Sets a new timeline. If the source is already prepared, this triggers a source info refresh
* message being sent to the listener.
*
* @param newTimeline The new {@link Timeline}.
* @param sendManifestLoadEvents Whether to treat this as a manifest refresh and send manifest
* load events to listeners.
*/
public synchronized void setNewSourceInfo(final Timeline newTimeline) {
public synchronized void setNewSourceInfo(Timeline newTimeline, boolean sendManifestLoadEvents) {
if (sourceInfoRefreshHandler != null) {
sourceInfoRefreshHandler.post(
() -> {
assertThat(releasedSource).isFalse();
assertThat(preparedSource).isTrue();
timeline = newTimeline;
finishSourcePreparation();
finishSourcePreparation(sendManifestLoadEvents);
});
} else {
timeline = newTimeline;
Expand Down Expand Up @@ -270,9 +284,9 @@ protected FakeMediaPeriod createFakeMediaPeriod(
trackGroupArray, drmSessionManager, eventDispatcher, /* deferOnPrepared= */ false);
}

private void finishSourcePreparation() {
private void finishSourcePreparation(boolean sendManifestLoadEvents) {
refreshSourceInfo(Assertions.checkStateNotNull(timeline));
if (!timeline.isEmpty()) {
if (!timeline.isEmpty() && sendManifestLoadEvents) {
MediaLoadData mediaLoadData =
new MediaLoadData(
C.DATA_TYPE_MANIFEST,
Expand All @@ -290,7 +304,7 @@ private void finishSourcePreparation() {
loadTaskId,
FAKE_DATA_SPEC,
FAKE_DATA_SPEC.uri,
/* responseHeaders= */ Collections.emptyMap(),
/* responseHeaders= */ ImmutableMap.of(),
elapsedRealTimeMs,
/* loadDurationMs= */ 0,
/* bytesLoaded= */ 0),
Expand All @@ -300,7 +314,7 @@ private void finishSourcePreparation() {
loadTaskId,
FAKE_DATA_SPEC,
FAKE_DATA_SPEC.uri,
/* responseHeaders= */ Collections.emptyMap(),
/* responseHeaders= */ ImmutableMap.of(),
elapsedRealTimeMs,
/* loadDurationMs= */ 0,
/* bytesLoaded= */ MANIFEST_LOAD_BYTES),
Expand Down

0 comments on commit ee11d9d

Please sign in to comment.