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
This commit is contained in:
parent
00a7306fd8
commit
4f56636328
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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<ListenerAndHandler> 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<ListenerAndHandler>(),
|
||||
/* windowIndex= */ 0,
|
||||
/* mediaPeriodId= */ null,
|
||||
/* mediaTimeOffsetMs= */ 0);
|
||||
}
|
||||
|
||||
private EventDispatcher(
|
||||
CopyOnWriteArrayList<ListenerAndHandler> listenerAndHandlers, long mediaTimeOffsetMs) {
|
||||
CopyOnWriteArrayList<ListenerAndHandler> 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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<? extends DashManifest> 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<DashManifest> 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<DashManifest> 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<Long> 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<Long> 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 <T> void startLoading(ParsingLoadable<T> loadable,
|
||||
Loader.Callback<ParsingLoadable<T>> 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() {
|
||||
|
@ -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<HlsPlaylist> 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,
|
||||
|
@ -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<? extends SsManifest> manifestParser;
|
||||
private final ArrayList<SsMediaPeriod> 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<SsManifest> 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<SsManifest> 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<SsManifest> 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<SsManifest> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user