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:
parent
f099f570e6
commit
ee11d9d6fb
@ -849,7 +849,8 @@ public final class AnalyticsCollectorTest {
|
||||
/* isSeekable= */ true,
|
||||
/* isDynamic= */ false,
|
||||
/* 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))
|
||||
.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))
|
||||
|
@ -40,9 +40,9 @@ import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
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;
|
||||
|
||||
@ -159,7 +159,7 @@ public class FakeMediaSource extends BaseMediaSource {
|
||||
releasedSource = false;
|
||||
sourceInfoRefreshHandler = Util.createHandler();
|
||||
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
|
||||
* 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) {
|
||||
sourceInfoRefreshHandler.post(
|
||||
() -> {
|
||||
assertThat(releasedSource).isFalse();
|
||||
assertThat(preparedSource).isTrue();
|
||||
timeline = newTimeline;
|
||||
finishSourcePreparation();
|
||||
finishSourcePreparation(sendManifestLoadEvents);
|
||||
});
|
||||
} else {
|
||||
timeline = newTimeline;
|
||||
@ -270,9 +284,9 @@ public class FakeMediaSource extends BaseMediaSource {
|
||||
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,
|
||||
@ -290,7 +304,7 @@ public class FakeMediaSource extends BaseMediaSource {
|
||||
loadTaskId,
|
||||
FAKE_DATA_SPEC,
|
||||
FAKE_DATA_SPEC.uri,
|
||||
/* responseHeaders= */ Collections.emptyMap(),
|
||||
/* responseHeaders= */ ImmutableMap.of(),
|
||||
elapsedRealTimeMs,
|
||||
/* loadDurationMs= */ 0,
|
||||
/* bytesLoaded= */ 0),
|
||||
@ -300,7 +314,7 @@ public class FakeMediaSource extends BaseMediaSource {
|
||||
loadTaskId,
|
||||
FAKE_DATA_SPEC,
|
||||
FAKE_DATA_SPEC.uri,
|
||||
/* responseHeaders= */ Collections.emptyMap(),
|
||||
/* responseHeaders= */ ImmutableMap.of(),
|
||||
elapsedRealTimeMs,
|
||||
/* loadDurationMs= */ 0,
|
||||
/* bytesLoaded= */ MANIFEST_LOAD_BYTES),
|
||||
|
Loading…
x
Reference in New Issue
Block a user