From 4f5663632859e986077d5fcf2ac98314b19d7a4b Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 13 Mar 2018 02:45:33 -0700 Subject: [PATCH] Add window index and media period id to media source event listener events. This allows to distinguish between media source events of multi-window and multi-period media sources. In this change, only media sources currently reporting events are changed. Proper support in composite sources will be added in a later change. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=188847366 --- .../exoplayer2/source/BaseMediaSource.java | 41 ++++++++++- .../source/ExtractorMediaSource.java | 5 +- .../source/MediaSourceEventListener.java | 71 +++++++++++++++---- .../source/SingleSampleMediaSource.java | 4 +- .../source/dash/DashMediaSource.java | 52 ++++++++++---- .../exoplayer2/source/hls/HlsMediaSource.java | 4 +- .../source/smoothstreaming/SsMediaSource.java | 27 ++++--- .../testutil/FakeAdaptiveMediaSource.java | 3 +- 8 files changed, 159 insertions(+), 48 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/BaseMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/BaseMediaSource.java index cf703b8e4f..32526361f5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/BaseMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/BaseMediaSource.java @@ -76,10 +76,45 @@ public abstract class BaseMediaSource implements MediaSource { /** * Returns a {@link MediaSourceEventListener.EventDispatcher} which dispatches all events to the - * registered listeners. + * registered listeners with the specified media period id. + * + * @param mediaPeriodId The {@link MediaPeriodId} to be reported with the events. May be null, if + * the events do not belong to a specific media period. + * @return An event dispatcher with pre-configured media period id. */ - protected final MediaSourceEventListener.EventDispatcher getEventDispatcher() { - return eventDispatcher; + protected final MediaSourceEventListener.EventDispatcher createEventDispatcher( + @Nullable MediaPeriodId mediaPeriodId) { + return eventDispatcher.withParameters( + /* windowIndex= */ 0, mediaPeriodId, /* mediaTimeOffsetMs= */ 0); + } + + /** + * Returns a {@link MediaSourceEventListener.EventDispatcher} which dispatches all events to the + * registered listeners with the specified media period id and time offset. + * + * @param mediaPeriodId The {@link MediaPeriodId} to be reported with the events. + * @param mediaTimeOffsetMs The offset to be added to all media times, in milliseconds. + * @return An event dispatcher with pre-configured media period id and time offset. + */ + protected final MediaSourceEventListener.EventDispatcher createEventDispatcher( + MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) { + Assertions.checkArgument(mediaPeriodId != null); + return eventDispatcher.withParameters(/* windowIndex= */ 0, mediaPeriodId, mediaTimeOffsetMs); + } + + /** + * Returns a {@link MediaSourceEventListener.EventDispatcher} which dispatches all events to the + * registered listeners with the specified window index, media period id and time offset. + * + * @param windowIndex The timeline window index to be reported with the events. + * @param mediaPeriodId The {@link MediaPeriodId} to be reported with the events. May be null, if + * the events do not belong to a specific media period. + * @param mediaTimeOffsetMs The offset to be added to all media times, in milliseconds. + * @return An event dispatcher with pre-configured media period id and time offset. + */ + protected final MediaSourceEventListener.EventDispatcher createEventDispatcher( + int windowIndex, @Nullable MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) { + return eventDispatcher.withParameters(windowIndex, mediaPeriodId, mediaTimeOffsetMs); } @Override diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java index 5c1fec85fd..8f9b491fbc 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java @@ -24,7 +24,6 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.ExtractorsFactory; -import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher; import com.google.android.exoplayer2.source.ads.AdsMediaSource; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.DataSource; @@ -95,7 +94,6 @@ public final class ExtractorMediaSource extends BaseMediaSource private final DataSource.Factory dataSourceFactory; private final ExtractorsFactory extractorsFactory; private final int minLoadableRetryCount; - private final EventDispatcher eventDispatcher; private final String customCacheKey; private final int continueLoadingCheckIntervalBytes; @@ -319,7 +317,6 @@ public final class ExtractorMediaSource extends BaseMediaSource this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; - this.eventDispatcher = getEventDispatcher(); this.customCacheKey = customCacheKey; this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes; this.timelineDurationUs = C.TIME_UNSET; @@ -343,7 +340,7 @@ public final class ExtractorMediaSource extends BaseMediaSource dataSourceFactory.createDataSource(), extractorsFactory.createExtractors(), minLoadableRetryCount, - eventDispatcher, + createEventDispatcher(id), this, allocator, customCacheKey, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java index ed09e4143a..f24c047a0d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java @@ -22,6 +22,7 @@ import android.support.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.util.Assertions; import java.io.IOException; @@ -62,6 +63,14 @@ public interface MediaSourceEventListener { /** Descriptor for data being loaded or selected by a media source. */ final class MediaLoadData { + + /** The window index in the timeline of the media source this data belongs to. */ + public final int windowIndex; + /** + * The {@link MediaPeriodId} this data belongs to. Null if the data does not belong to a + * specific media period. + */ + public final @Nullable MediaPeriodId mediaPeriodId; /** One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data. */ public final int dataType; /** @@ -84,17 +93,23 @@ public interface MediaSourceEventListener { * the data does not belong to a track. */ public final @Nullable Object trackSelectionData; - /** The start time of the media, or {@link C#TIME_UNSET} if the data is not for media. */ + /** + * The start time of the media, or {@link C#TIME_UNSET} if the data does not belong to a + * specific media period. + */ public final long mediaStartTimeMs; /** - * The end time of the media, or {@link C#TIME_UNSET} if the data is not for media or the end - * time is unknown. + * The end time of the media, or {@link C#TIME_UNSET} if the data does not belong to a specific + * media period or the end time is unknown. */ public final long mediaEndTimeMs; /** * Creates media load data. * + * @param windowIndex The window index in the timeline of the media source this load belongs to. + * @param mediaPeriodId The {@link MediaPeriodId} this load belongs to. Null if the data does + * not belong to a specific media period. * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data. * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds * to media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. @@ -104,12 +119,14 @@ public interface MediaSourceEventListener { * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. * @param trackSelectionData Optional data associated with the selection of the track to which * the data belongs. Null if the data does not belong to a track. - * @param mediaStartTimeMs The start time of the media, or {@link C#TIME_UNSET} if the data is - * not for media. - * @param mediaEndTimeMs The end time of the media, or {@link C#TIME_UNSET} if the data is not - * for media or the end time is unknown. + * @param mediaStartTimeMs The start time of the media, or {@link C#TIME_UNSET} if the data does + * not belong to a specific media period. + * @param mediaEndTimeMs The end time of the media, or {@link C#TIME_UNSET} if the data does not + * belong to a specific media period or the end time is unknown. */ public MediaLoadData( + int windowIndex, + @Nullable MediaPeriodId mediaPeriodId, int dataType, int trackType, @Nullable Format trackFormat, @@ -117,6 +134,8 @@ public interface MediaSourceEventListener { @Nullable Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs) { + this.windowIndex = windowIndex; + this.mediaPeriodId = mediaPeriodId; this.dataType = dataType; this.trackType = trackType; this.trackFormat = trackFormat; @@ -196,30 +215,44 @@ public interface MediaSourceEventListener { final class EventDispatcher { private final CopyOnWriteArrayList listenerAndHandlers; + private final int windowIndex; + private final @Nullable MediaPeriodId mediaPeriodId; private final long mediaTimeOffsetMs; - /** Create event dispatcher. */ + /** Creates an event dispatcher. */ /* package */ EventDispatcher() { this( /* listenerAndHandlers= */ new CopyOnWriteArrayList(), + /* windowIndex= */ 0, + /* mediaPeriodId= */ null, /* mediaTimeOffsetMs= */ 0); } private EventDispatcher( - CopyOnWriteArrayList listenerAndHandlers, long mediaTimeOffsetMs) { + CopyOnWriteArrayList listenerAndHandlers, + int windowIndex, + @Nullable MediaPeriodId mediaPeriodId, + long mediaTimeOffsetMs) { this.listenerAndHandlers = listenerAndHandlers; + this.windowIndex = windowIndex; + this.mediaPeriodId = mediaPeriodId; this.mediaTimeOffsetMs = mediaTimeOffsetMs; } /** - * Creates a view of the event dispatcher with a media time offset. + * Creates a view of the event dispatcher with pre-configured window index, media period id, and + * media time offset. * + * @param windowIndex The timeline window index to be reported with the events. + * @param mediaPeriodId The {@link MediaPeriodId} to be reported with the events. * @param mediaTimeOffsetMs The offset to be added to all media times, in milliseconds. - * @return A view of the event dispatcher with the added media time offset. + * @return A view of the event dispatcher with the pre-configured parameters. */ @CheckResult - public EventDispatcher withMediaTimeOffsetMs(long mediaTimeOffsetMs) { - return new EventDispatcher(listenerAndHandlers, mediaTimeOffsetMs); + /* package */ EventDispatcher withParameters( + int windowIndex, @Nullable MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) { + return new EventDispatcher( + listenerAndHandlers, windowIndex, mediaPeriodId, mediaTimeOffsetMs); } /** @@ -280,6 +313,8 @@ public interface MediaSourceEventListener { new LoadEventInfo( dataSpec, elapsedRealtimeMs, /* loadDurationMs= */ 0, /* bytesLoaded= */ 0), new MediaLoadData( + windowIndex, + mediaPeriodId, dataType, trackType, trackFormat, @@ -334,6 +369,8 @@ public interface MediaSourceEventListener { listenerAndHandler.listener.onLoadCompleted( new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), new MediaLoadData( + windowIndex, + mediaPeriodId, dataType, trackType, trackFormat, @@ -388,6 +425,8 @@ public interface MediaSourceEventListener { listenerAndHandler.listener.onLoadCanceled( new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), new MediaLoadData( + windowIndex, + mediaPeriodId, dataType, trackType, trackFormat, @@ -448,6 +487,8 @@ public interface MediaSourceEventListener { listenerAndHandler.listener.onLoadError( new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), new MediaLoadData( + windowIndex, + mediaPeriodId, dataType, trackType, trackFormat, @@ -472,6 +513,8 @@ public interface MediaSourceEventListener { public void run() { listenerAndHandler.listener.onUpstreamDiscarded( new MediaLoadData( + windowIndex, + mediaPeriodId, C.DATA_TYPE_MEDIA, trackType, /* trackFormat= */ null, @@ -498,6 +541,8 @@ public interface MediaSourceEventListener { public void run() { listenerAndHandler.listener.onDownstreamFormatChanged( new MediaLoadData( + windowIndex, + mediaPeriodId, C.DATA_TYPE_MEDIA, trackType, trackFormat, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java index 15a91291ea..52aca9cc0d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java @@ -148,7 +148,6 @@ public final class SingleSampleMediaSource extends BaseMediaSource { private final DataSource.Factory dataSourceFactory; private final Format format; private final long durationUs; - private final MediaSourceEventListener.EventDispatcher eventDispatcher; private final int minLoadableRetryCount; private final boolean treatLoadErrorsAsEndOfStream; private final Timeline timeline; @@ -242,7 +241,6 @@ public final class SingleSampleMediaSource extends BaseMediaSource { this.durationUs = durationUs; this.minLoadableRetryCount = minLoadableRetryCount; this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream; - this.eventDispatcher = getEventDispatcher(); dataSpec = new DataSpec(uri); timeline = new SinglePeriodTimeline(durationUs, true, false); } @@ -268,7 +266,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource { format, durationUs, minLoadableRetryCount, - eventDispatcher, + createEventDispatcher(id), treatLoadErrorsAsEndOfStream); } diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java index 8356a3d269..8be4242bb2 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java @@ -281,7 +281,7 @@ public final class DashMediaSource extends BaseMediaSource { private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory; private final int minLoadableRetryCount; private final long livePresentationDelayMs; - private final EventDispatcher eventDispatcher; + private final EventDispatcher manifestEventDispatcher; private final ParsingLoadable.Parser manifestParser; private final ManifestCallback manifestCallback; private final Object manifestUriLock; @@ -476,7 +476,7 @@ public final class DashMediaSource extends BaseMediaSource { this.livePresentationDelayMs = livePresentationDelayMs; this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; sideloadedManifest = manifest != null; - eventDispatcher = getEventDispatcher(); + manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null); manifestUriLock = new Object(); periodsById = new SparseArray<>(); playerEmsgCallback = new DefaultPlayerEmsgCallback(); @@ -540,7 +540,7 @@ public final class DashMediaSource extends BaseMediaSource { public MediaPeriod createPeriod(MediaPeriodId periodId, Allocator allocator) { int periodIndex = periodId.periodIndex; EventDispatcher periodEventDispatcher = - eventDispatcher.withMediaTimeOffsetMs(manifest.getPeriod(periodIndex).startMs); + createEventDispatcher(periodId, manifest.getPeriod(periodIndex).startMs); DashMediaPeriod mediaPeriod = new DashMediaPeriod( firstPeriodId + periodIndex, @@ -612,8 +612,12 @@ public final class DashMediaSource extends BaseMediaSource { /* package */ void onManifestLoadCompleted(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) { - eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, elapsedRealtimeMs, - loadDurationMs, loadable.bytesLoaded()); + manifestEventDispatcher.loadCompleted( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded()); DashManifest newManifest = loadable.getResult(); int periodCount = manifest == null ? 0 : manifest.getPeriodCount(); @@ -691,30 +695,50 @@ public final class DashMediaSource extends BaseMediaSource { /* package */ int onManifestLoadError(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error) { boolean isFatal = error instanceof ParserException; - eventDispatcher.loadError(loadable.dataSpec, loadable.type, elapsedRealtimeMs, loadDurationMs, - loadable.bytesLoaded(), error, isFatal); + manifestEventDispatcher.loadError( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded(), + error, + isFatal); return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY; } /* package */ void onUtcTimestampLoadCompleted(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) { - eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, elapsedRealtimeMs, - loadDurationMs, loadable.bytesLoaded()); + manifestEventDispatcher.loadCompleted( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded()); onUtcTimestampResolved(loadable.getResult() - elapsedRealtimeMs); } /* package */ int onUtcTimestampLoadError(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error) { - eventDispatcher.loadError(loadable.dataSpec, loadable.type, elapsedRealtimeMs, loadDurationMs, - loadable.bytesLoaded(), error, true); + manifestEventDispatcher.loadError( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded(), + error, + true); onUtcTimestampResolutionError(error); return Loader.DONT_RETRY; } /* package */ void onLoadCanceled(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) { - eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, elapsedRealtimeMs, - loadDurationMs, loadable.bytesLoaded()); + manifestEventDispatcher.loadCanceled( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded()); } // Internal methods. @@ -889,7 +913,7 @@ public final class DashMediaSource extends BaseMediaSource { private void startLoading(ParsingLoadable loadable, Loader.Callback> callback, int minRetryCount) { long elapsedRealtimeMs = loader.startLoading(loadable, callback, minRetryCount); - eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); + manifestEventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); } private long getNowUnixTimeUs() { diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaSource.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaSource.java index 8aa84502d5..37d37575c2 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaSource.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaSource.java @@ -216,7 +216,6 @@ public final class HlsMediaSource extends BaseMediaSource private final HlsDataSourceFactory dataSourceFactory; private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory; private final int minLoadableRetryCount; - private final EventDispatcher eventDispatcher; private final ParsingLoadable.Parser playlistParser; private final boolean allowChunklessPreparation; @@ -314,11 +313,11 @@ public final class HlsMediaSource extends BaseMediaSource this.minLoadableRetryCount = minLoadableRetryCount; this.playlistParser = playlistParser; this.allowChunklessPreparation = allowChunklessPreparation; - eventDispatcher = getEventDispatcher(); } @Override public void prepareSourceInternal(ExoPlayer player, boolean isTopLevelSource) { + EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null); playlistTracker = new HlsPlaylistTracker(manifestUri, dataSourceFactory, eventDispatcher, minLoadableRetryCount, this, playlistParser); playlistTracker.start(); @@ -332,6 +331,7 @@ public final class HlsMediaSource extends BaseMediaSource @Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { Assertions.checkArgument(id.periodIndex == 0); + EventDispatcher eventDispatcher = createEventDispatcher(id); return new HlsMediaPeriod( extractorFactory, playlistTracker, diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java index 8efa7dc5fe..6b891361a1 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java @@ -258,7 +258,7 @@ public final class SsMediaSource extends BaseMediaSource private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory; private final int minLoadableRetryCount; private final long livePresentationDelayMs; - private final EventDispatcher eventDispatcher; + private final EventDispatcher manifestEventDispatcher; private final ParsingLoadable.Parser manifestParser; private final ArrayList mediaPeriods; @@ -431,7 +431,7 @@ public final class SsMediaSource extends BaseMediaSource this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.livePresentationDelayMs = livePresentationDelayMs; - this.eventDispatcher = getEventDispatcher(); + this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null); sideloadedManifest = manifest != null; mediaPeriods = new ArrayList<>(); } @@ -460,6 +460,7 @@ public final class SsMediaSource extends BaseMediaSource @Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { Assertions.checkArgument(id.periodIndex == 0); + EventDispatcher eventDispatcher = createEventDispatcher(id); SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, compositeSequenceableLoaderFactory, minLoadableRetryCount, eventDispatcher, manifestLoaderErrorThrower, allocator); @@ -493,8 +494,12 @@ public final class SsMediaSource extends BaseMediaSource @Override public void onLoadCompleted(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) { - eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, elapsedRealtimeMs, - loadDurationMs, loadable.bytesLoaded()); + manifestEventDispatcher.loadCompleted( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded()); manifest = loadable.getResult(); manifestLoadStartTimestamp = elapsedRealtimeMs - loadDurationMs; processManifest(); @@ -504,7 +509,7 @@ public final class SsMediaSource extends BaseMediaSource @Override public void onLoadCanceled(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released) { - eventDispatcher.loadCanceled( + manifestEventDispatcher.loadCanceled( loadable.dataSpec, loadable.type, elapsedRealtimeMs, @@ -516,8 +521,14 @@ public final class SsMediaSource extends BaseMediaSource public int onLoadError(ParsingLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error) { boolean isFatal = error instanceof ParserException; - eventDispatcher.loadError(loadable.dataSpec, loadable.type, elapsedRealtimeMs, loadDurationMs, - loadable.bytesLoaded(), error, isFatal); + manifestEventDispatcher.loadError( + loadable.dataSpec, + loadable.type, + elapsedRealtimeMs, + loadDurationMs, + loadable.bytesLoaded(), + error, + isFatal); return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY; } @@ -584,7 +595,7 @@ public final class SsMediaSource extends BaseMediaSource ParsingLoadable loadable = new ParsingLoadable<>(manifestDataSource, manifestUri, C.DATA_TYPE_MANIFEST, manifestParser); long elapsedRealtimeMs = manifestLoader.startLoading(loadable, this, minLoadableRetryCount); - eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); + manifestEventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); } } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java index 4ab012eb2d..3a4f4a0882 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java @@ -47,8 +47,9 @@ public class FakeAdaptiveMediaSource extends FakeMediaSource { protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator) { Period period = timeline.getPeriod(id.periodIndex, new Period()); + MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(id); return new FakeAdaptiveMediaPeriod( - trackGroupArray, getEventDispatcher(), allocator, chunkSourceFactory, period.durationUs); + trackGroupArray, eventDispatcher, allocator, chunkSourceFactory, period.durationUs); } }