Commit eb84b144 by tonihei Committed by Oliver Woodman

Move window index and media period id out of MediaLoadData again.

This gives the MediaSourceEventListener API a consistent look when new methods are
added which only have a window index and media period id.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190450270
parent dfe4bfba
...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.ExoPlayer; ...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSourceEventListener.MediaLoadData; import com.google.android.exoplayer2.source.MediaSourceEventListener.MediaLoadData;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
...@@ -176,8 +177,8 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource { ...@@ -176,8 +177,8 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
private final class ForwardingEventListener implements MediaSourceEventListener { private final class ForwardingEventListener implements MediaSourceEventListener {
private final EventDispatcher eventDispatcher;
private final @Nullable T id; private final @Nullable T id;
private EventDispatcher eventDispatcher;
public ForwardingEventListener(@Nullable T id) { public ForwardingEventListener(@Nullable T id) {
this.eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null); this.eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
...@@ -185,72 +186,96 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource { ...@@ -185,72 +186,96 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
} }
@Override @Override
public void onLoadStarted(LoadEventInfo loadEventData, MediaLoadData mediaLoadData) { public void onLoadStarted(
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); int windowIndex,
if (correctedMediaLoadData != null) { @Nullable MediaPeriodId mediaPeriodId,
eventDispatcher.loadStarted(loadEventData, correctedMediaLoadData); LoadEventInfo loadEventData,
MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
eventDispatcher.loadStarted(loadEventData, maybeUpdateMediaLoadData(mediaLoadData));
} }
} }
@Override @Override
public void onLoadCompleted(LoadEventInfo loadEventData, MediaLoadData mediaLoadData) { public void onLoadCompleted(
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); int windowIndex,
if (correctedMediaLoadData != null) { @Nullable MediaPeriodId mediaPeriodId,
eventDispatcher.loadCompleted(loadEventData, correctedMediaLoadData); LoadEventInfo loadEventData,
MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
eventDispatcher.loadCompleted(loadEventData, maybeUpdateMediaLoadData(mediaLoadData));
} }
} }
@Override @Override
public void onLoadCanceled(LoadEventInfo loadEventData, MediaLoadData mediaLoadData) { public void onLoadCanceled(
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); int windowIndex,
if (correctedMediaLoadData != null) { @Nullable MediaPeriodId mediaPeriodId,
eventDispatcher.loadCanceled(loadEventData, correctedMediaLoadData); LoadEventInfo loadEventData,
MediaLoadData mediaLoadData) {
if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
eventDispatcher.loadCanceled(loadEventData, maybeUpdateMediaLoadData(mediaLoadData));
} }
} }
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventData, LoadEventInfo loadEventData,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
boolean wasCanceled) { boolean wasCanceled) {
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
if (correctedMediaLoadData != null) { eventDispatcher.loadError(
eventDispatcher.loadError(loadEventData, correctedMediaLoadData, error, wasCanceled); loadEventData, maybeUpdateMediaLoadData(mediaLoadData), error, wasCanceled);
} }
} }
@Override @Override
public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { public void onUpstreamDiscarded(
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
if (correctedMediaLoadData != null) { if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
eventDispatcher.upstreamDiscarded(correctedMediaLoadData); eventDispatcher.upstreamDiscarded(maybeUpdateMediaLoadData(mediaLoadData));
} }
} }
@Override @Override
public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { public void onDownstreamFormatChanged(
MediaLoadData correctedMediaLoadData = correctMediaLoadData(mediaLoadData); int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
if (correctedMediaLoadData != null) { if (maybeUpdateEventDispatcher(windowIndex, mediaPeriodId)) {
eventDispatcher.downstreamFormatChanged(correctedMediaLoadData); eventDispatcher.downstreamFormatChanged(maybeUpdateMediaLoadData(mediaLoadData));
} }
} }
private @Nullable MediaLoadData correctMediaLoadData(MediaLoadData mediaLoadData) { /** Updates the event dispatcher and returns whether the event should be dispatched. */
private boolean maybeUpdateEventDispatcher(
int childWindowIndex, @Nullable MediaPeriodId childMediaPeriodId) {
MediaPeriodId mediaPeriodId = null; MediaPeriodId mediaPeriodId = null;
if (mediaLoadData.mediaPeriodId != null) { if (childMediaPeriodId != null) {
mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, mediaLoadData.mediaPeriodId); mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, childMediaPeriodId);
if (mediaPeriodId == null) { if (mediaPeriodId == null) {
// Media period not found. Ignore event. // Media period not found. Ignore event.
return null; return false;
} }
} }
int windowIndex = getWindowIndexForChildWindowIndex(id, mediaLoadData.windowIndex); int windowIndex = getWindowIndexForChildWindowIndex(id, childWindowIndex);
if (eventDispatcher.windowIndex != windowIndex
|| !Util.areEqual(eventDispatcher.mediaPeriodId, mediaPeriodId)) {
eventDispatcher =
createEventDispatcher(windowIndex, mediaPeriodId, /* mediaTimeOffsetMs= */ 0);
}
return true;
}
private MediaLoadData maybeUpdateMediaLoadData(MediaLoadData mediaLoadData) {
long mediaStartTimeMs = getMediaTimeForChildMediaTime(id, mediaLoadData.mediaStartTimeMs); long mediaStartTimeMs = getMediaTimeForChildMediaTime(id, mediaLoadData.mediaStartTimeMs);
long mediaEndTimeMs = getMediaTimeForChildMediaTime(id, mediaLoadData.mediaEndTimeMs); long mediaEndTimeMs = getMediaTimeForChildMediaTime(id, mediaLoadData.mediaEndTimeMs);
if (mediaStartTimeMs == mediaLoadData.mediaStartTimeMs
&& mediaEndTimeMs == mediaLoadData.mediaEndTimeMs) {
return mediaLoadData;
}
return new MediaLoadData( return new MediaLoadData(
windowIndex,
mediaPeriodId,
mediaLoadData.dataType, mediaLoadData.dataType,
mediaLoadData.trackType, mediaLoadData.trackType,
mediaLoadData.trackFormat, mediaLoadData.trackFormat,
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package com.google.android.exoplayer2.source; package com.google.android.exoplayer2.source;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import java.io.IOException; import java.io.IOException;
/** /**
...@@ -24,22 +26,36 @@ import java.io.IOException; ...@@ -24,22 +26,36 @@ import java.io.IOException;
public abstract class DefaultMediaSourceEventListener implements MediaSourceEventListener { public abstract class DefaultMediaSourceEventListener implements MediaSourceEventListener {
@Override @Override
public void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadStarted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCompleted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCanceled(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo, LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
...@@ -48,12 +64,14 @@ public abstract class DefaultMediaSourceEventListener implements MediaSourceEven ...@@ -48,12 +64,14 @@ public abstract class DefaultMediaSourceEventListener implements MediaSourceEven
} }
@Override @Override
public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { public void onUpstreamDiscarded(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { public void onDownstreamFormatChanged(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
} }
...@@ -394,6 +394,8 @@ public final class ExtractorMediaSource extends BaseMediaSource ...@@ -394,6 +394,8 @@ public final class ExtractorMediaSource extends BaseMediaSource
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo, LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
......
...@@ -296,6 +296,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource { ...@@ -296,6 +296,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo, LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.util; package com.google.android.exoplayer2.util;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -39,6 +40,7 @@ import com.google.android.exoplayer2.metadata.id3.PrivFrame; ...@@ -39,6 +40,7 @@ import com.google.android.exoplayer2.metadata.id3.PrivFrame;
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame; import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
import com.google.android.exoplayer2.metadata.id3.UrlLinkFrame; import com.google.android.exoplayer2.metadata.id3.UrlLinkFrame;
import com.google.android.exoplayer2.metadata.scte35.SpliceCommand; import com.google.android.exoplayer2.metadata.scte35.SpliceCommand;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSourceEventListener; import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
...@@ -361,12 +363,18 @@ public class EventLogger ...@@ -361,12 +363,18 @@ public class EventLogger
// MediaSourceEventListener // MediaSourceEventListener
@Override @Override
public void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadStarted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo, LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
...@@ -375,22 +383,32 @@ public class EventLogger ...@@ -375,22 +383,32 @@ public class EventLogger
} }
@Override @Override
public void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCanceled(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCompleted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { public void onUpstreamDiscarded(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { public void onDownstreamFormatChanged(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
// Do nothing. // Do nothing.
} }
......
...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
...@@ -271,8 +272,6 @@ public final class ClippingMediaSourceTest { ...@@ -271,8 +272,6 @@ public final class ClippingMediaSourceTest {
EventDispatcher eventDispatcher) { EventDispatcher eventDispatcher) {
eventDispatcher.downstreamFormatChanged( eventDispatcher.downstreamFormatChanged(
new MediaLoadData( new MediaLoadData(
/* windowIndex= */ 0,
id,
C.DATA_TYPE_MEDIA, C.DATA_TYPE_MEDIA,
C.TRACK_TYPE_UNKNOWN, C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null, /* trackFormat= */ null,
...@@ -297,7 +296,10 @@ public final class ClippingMediaSourceTest { ...@@ -297,7 +296,10 @@ public final class ClippingMediaSourceTest {
new Handler(), new Handler(),
new DefaultMediaSourceEventListener() { new DefaultMediaSourceEventListener() {
@Override @Override
public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { public void onDownstreamFormatChanged(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
MediaLoadData mediaLoadData) {
reportedMediaLoadData[0] = mediaLoadData; reportedMediaLoadData[0] = mediaLoadData;
} }
}); });
......
...@@ -200,8 +200,6 @@ public class FakeMediaSource extends BaseMediaSource { ...@@ -200,8 +200,6 @@ public class FakeMediaSource extends BaseMediaSource {
if (!timeline.isEmpty()) { if (!timeline.isEmpty()) {
MediaLoadData mediaLoadData = MediaLoadData mediaLoadData =
new MediaLoadData( new MediaLoadData(
/* windowIndex= */ 0,
/* mediaPeriodId= */ null,
C.DATA_TYPE_MANIFEST, C.DATA_TYPE_MANIFEST,
C.TRACK_TYPE_UNKNOWN, C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null, /* trackFormat= */ null,
......
...@@ -24,6 +24,8 @@ import android.os.Handler; ...@@ -24,6 +24,8 @@ import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.support.annotation.Nullable;
import android.util.Pair;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.PlayerMessage; import com.google.android.exoplayer2.PlayerMessage;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
...@@ -41,7 +43,7 @@ import java.util.ArrayList; ...@@ -41,7 +43,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -59,7 +61,7 @@ public class MediaSourceTestRunner { ...@@ -59,7 +61,7 @@ public class MediaSourceTestRunner {
private final Allocator allocator; private final Allocator allocator;
private final LinkedBlockingDeque<Timeline> timelines; private final LinkedBlockingDeque<Timeline> timelines;
private final CopyOnWriteArraySet<MediaLoadData> completedLoads; private final CopyOnWriteArrayList<Pair<Integer, MediaPeriodId>> completedLoads;
private Timeline timeline; private Timeline timeline;
/** /**
...@@ -76,7 +78,7 @@ public class MediaSourceTestRunner { ...@@ -76,7 +78,7 @@ public class MediaSourceTestRunner {
player = new EventHandlingExoPlayer(playbackLooper); player = new EventHandlingExoPlayer(playbackLooper);
mediaSourceListener = new MediaSourceListener(); mediaSourceListener = new MediaSourceListener();
timelines = new LinkedBlockingDeque<>(); timelines = new LinkedBlockingDeque<>();
completedLoads = new CopyOnWriteArraySet<>(); completedLoads = new CopyOnWriteArrayList<>();
mediaSource.addEventListener(playbackHandler, mediaSourceListener); mediaSource.addEventListener(playbackHandler, mediaSourceListener);
} }
...@@ -294,15 +296,15 @@ public class MediaSourceTestRunner { ...@@ -294,15 +296,15 @@ public class MediaSourceTestRunner {
/** /**
* Asserts that the media source reported completed loads via {@link * Asserts that the media source reported completed loads via {@link
* MediaSourceEventListener#onLoadCompleted(LoadEventInfo, MediaLoadData)} for each specified * MediaSourceEventListener#onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)} for
* window index and a null period id. Also asserts that no other loads with media period id null * each specified window index and a null period id. Also asserts that no other loads with media
* are reported. * period id null are reported.
*/ */
public void assertCompletedManifestLoads(Integer... windowIndices) { public void assertCompletedManifestLoads(Integer... windowIndices) {
List<Integer> expectedWindowIndices = new ArrayList<>(Arrays.asList(windowIndices)); List<Integer> expectedWindowIndices = new ArrayList<>(Arrays.asList(windowIndices));
for (MediaLoadData mediaLoadData : completedLoads) { for (Pair<Integer, MediaPeriodId> windowIndexAndMediaPeriodId : completedLoads) {
if (mediaLoadData.mediaPeriodId == null) { if (windowIndexAndMediaPeriodId.second == null) {
boolean loadExpected = expectedWindowIndices.remove((Integer) mediaLoadData.windowIndex); boolean loadExpected = expectedWindowIndices.remove(windowIndexAndMediaPeriodId.first);
assertThat(loadExpected).isTrue(); assertThat(loadExpected).isTrue();
} }
} }
...@@ -313,19 +315,20 @@ public class MediaSourceTestRunner { ...@@ -313,19 +315,20 @@ public class MediaSourceTestRunner {
/** /**
* Asserts that the media source reported completed loads via {@link * Asserts that the media source reported completed loads via {@link
* MediaSourceEventListener#onLoadCompleted(LoadEventInfo, MediaLoadData)} for each specified * MediaSourceEventListener#onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)} for
* media period id, and asserts that the associated window index matches the one in the last known * each specified media period id, and asserts that the associated window index matches the one in
* timeline returned from {@link #prepareSource()}, {@link #assertTimelineChange()} or {@link * the last known timeline returned from {@link #prepareSource()}, {@link #assertTimelineChange()}
* #assertTimelineChangeBlocking()}. * or {@link #assertTimelineChangeBlocking()}.
*/ */
public void assertCompletedMediaPeriodLoads(MediaPeriodId... mediaPeriodIds) { public void assertCompletedMediaPeriodLoads(MediaPeriodId... mediaPeriodIds) {
Timeline.Period period = new Timeline.Period(); Timeline.Period period = new Timeline.Period();
HashSet<MediaPeriodId> expectedLoads = new HashSet<>(Arrays.asList(mediaPeriodIds)); HashSet<MediaPeriodId> expectedLoads = new HashSet<>(Arrays.asList(mediaPeriodIds));
for (MediaLoadData mediaLoadData : completedLoads) { for (Pair<Integer, MediaPeriodId> windowIndexAndMediaPeriodId : completedLoads) {
if (expectedLoads.remove(mediaLoadData.mediaPeriodId)) { int windowIndex = windowIndexAndMediaPeriodId.first;
assertThat(mediaLoadData.windowIndex) MediaPeriodId mediaPeriodId = windowIndexAndMediaPeriodId.second;
.isEqualTo( if (expectedLoads.remove(mediaPeriodId)) {
timeline.getPeriod(mediaLoadData.mediaPeriodId.periodIndex, period).windowIndex); assertThat(windowIndex)
.isEqualTo(timeline.getPeriod(mediaPeriodId.periodIndex, period).windowIndex);
} }
} }
assertWithMessage("Not all expected media source loads have been completed.") assertWithMessage("Not all expected media source loads have been completed.")
...@@ -352,23 +355,37 @@ public class MediaSourceTestRunner { ...@@ -352,23 +355,37 @@ public class MediaSourceTestRunner {
// MediaSourceEventListener methods. // MediaSourceEventListener methods.
@Override @Override
public void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadStarted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); Assertions.checkState(Looper.myLooper() == playbackThread.getLooper());
} }
@Override @Override
public void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCompleted(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); Assertions.checkState(Looper.myLooper() == playbackThread.getLooper());
completedLoads.add(mediaLoadData); completedLoads.add(Pair.create(windowIndex, mediaPeriodId));
} }
@Override @Override
public void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { public void onLoadCanceled(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData) {
Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); Assertions.checkState(Looper.myLooper() == playbackThread.getLooper());
} }
@Override @Override
public void onLoadError( public void onLoadError(
int windowIndex,
@Nullable MediaPeriodId mediaPeriodId,
LoadEventInfo loadEventInfo, LoadEventInfo loadEventInfo,
MediaLoadData mediaLoadData, MediaLoadData mediaLoadData,
IOException error, IOException error,
...@@ -377,12 +394,14 @@ public class MediaSourceTestRunner { ...@@ -377,12 +394,14 @@ public class MediaSourceTestRunner {
} }
@Override @Override
public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { public void onUpstreamDiscarded(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); Assertions.checkState(Looper.myLooper() == playbackThread.getLooper());
} }
@Override @Override
public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { public void onDownstreamFormatChanged(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
Assertions.checkState(Looper.myLooper() == playbackThread.getLooper()); Assertions.checkState(Looper.myLooper() == playbackThread.getLooper());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment