Make manifest loads on timeline refresh optional in FakeMediaSource.

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
This commit is contained in:
tonihei 2020-05-26 09:45:36 +01:00 committed by Oliver Woodman
parent f099f570e6
commit ee11d9d6fb
2 changed files with 24 additions and 15 deletions

View File

@ -849,7 +849,8 @@ public final class AnalyticsCollectorTest {
/* isSeekable= */ true, /* isSeekable= */ true,
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
adPlaybackState.get()))); adPlaybackState.get())),
/* sendManifestLoadEvents= */ false);
} }
} }
}); });
@ -956,25 +957,19 @@ public final class AnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_LOAD_STARTED)) assertThat(listener.getEvents(EVENT_LOAD_STARTED))
.containsExactly( .containsExactly(
WINDOW_0 /* content manifest */, WINDOW_0 /* content manifest */,
WINDOW_0 /* preroll manifest */,
prerollAd, prerollAd,
contentAfterPreroll, contentAfterPreroll,
WINDOW_0 /* midroll manifest */,
midrollAd, midrollAd,
contentAfterMidroll, contentAfterMidroll,
WINDOW_0 /* postroll manifest */,
postrollAd, postrollAd,
contentAfterPostroll); contentAfterPostroll);
assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)) assertThat(listener.getEvents(EVENT_LOAD_COMPLETED))
.containsExactly( .containsExactly(
WINDOW_0 /* content manifest */, WINDOW_0 /* content manifest */,
WINDOW_0 /* preroll manifest */,
prerollAd, prerollAd,
contentAfterPreroll, contentAfterPreroll,
WINDOW_0 /* midroll manifest */,
midrollAd, midrollAd,
contentAfterMidroll, contentAfterMidroll,
WINDOW_0 /* postroll manifest */,
postrollAd, postrollAd,
contentAfterPostroll); contentAfterPostroll);
assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)) assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED))

View File

@ -40,9 +40,9 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableMap;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -159,7 +159,7 @@ public class FakeMediaSource extends BaseMediaSource {
releasedSource = false; releasedSource = false;
sourceInfoRefreshHandler = Util.createHandler(); sourceInfoRefreshHandler = Util.createHandler();
if (timeline != null) { if (timeline != null) {
finishSourcePreparation(); finishSourcePreparation(/* sendManifestLoadEvents= */ true);
} }
} }
@ -209,15 +209,29 @@ public class FakeMediaSource extends BaseMediaSource {
/** /**
* Sets a new timeline. If the source is already prepared, this triggers a source info refresh * Sets a new timeline. If the source is already prepared, this triggers a source info refresh
* message being sent to the listener. * message being sent to the listener.
*
* @param newTimeline The new {@link Timeline}.
*/ */
public synchronized void setNewSourceInfo(final Timeline newTimeline) { 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(Timeline newTimeline, boolean sendManifestLoadEvents) {
if (sourceInfoRefreshHandler != null) { if (sourceInfoRefreshHandler != null) {
sourceInfoRefreshHandler.post( sourceInfoRefreshHandler.post(
() -> { () -> {
assertThat(releasedSource).isFalse(); assertThat(releasedSource).isFalse();
assertThat(preparedSource).isTrue(); assertThat(preparedSource).isTrue();
timeline = newTimeline; timeline = newTimeline;
finishSourcePreparation(); finishSourcePreparation(sendManifestLoadEvents);
}); });
} else { } else {
timeline = newTimeline; timeline = newTimeline;
@ -270,9 +284,9 @@ public class FakeMediaSource extends BaseMediaSource {
trackGroupArray, drmSessionManager, eventDispatcher, /* deferOnPrepared= */ false); trackGroupArray, drmSessionManager, eventDispatcher, /* deferOnPrepared= */ false);
} }
private void finishSourcePreparation() { private void finishSourcePreparation(boolean sendManifestLoadEvents) {
refreshSourceInfo(Assertions.checkStateNotNull(timeline)); refreshSourceInfo(Assertions.checkStateNotNull(timeline));
if (!timeline.isEmpty()) { if (!timeline.isEmpty() && sendManifestLoadEvents) {
MediaLoadData mediaLoadData = MediaLoadData mediaLoadData =
new MediaLoadData( new MediaLoadData(
C.DATA_TYPE_MANIFEST, C.DATA_TYPE_MANIFEST,
@ -290,7 +304,7 @@ public class FakeMediaSource extends BaseMediaSource {
loadTaskId, loadTaskId,
FAKE_DATA_SPEC, FAKE_DATA_SPEC,
FAKE_DATA_SPEC.uri, FAKE_DATA_SPEC.uri,
/* responseHeaders= */ Collections.emptyMap(), /* responseHeaders= */ ImmutableMap.of(),
elapsedRealTimeMs, elapsedRealTimeMs,
/* loadDurationMs= */ 0, /* loadDurationMs= */ 0,
/* bytesLoaded= */ 0), /* bytesLoaded= */ 0),
@ -300,7 +314,7 @@ public class FakeMediaSource extends BaseMediaSource {
loadTaskId, loadTaskId,
FAKE_DATA_SPEC, FAKE_DATA_SPEC,
FAKE_DATA_SPEC.uri, FAKE_DATA_SPEC.uri,
/* responseHeaders= */ Collections.emptyMap(), /* responseHeaders= */ ImmutableMap.of(),
elapsedRealTimeMs, elapsedRealTimeMs,
/* loadDurationMs= */ 0, /* loadDurationMs= */ 0,
/* bytesLoaded= */ MANIFEST_LOAD_BYTES), /* bytesLoaded= */ MANIFEST_LOAD_BYTES),