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
This commit is contained in:
parent
dfe4bfba03
commit
eb84b144bf
@ -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 {
|
|||||||
|
|
||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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 @@
|
|||||||
*/
|
*/
|
||||||
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;
|
|||||||
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
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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
|
|||||||
|
|
||||||
@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,
|
||||||
|
@ -65,13 +65,6 @@ public interface MediaSourceEventListener {
|
|||||||
/** Descriptor for data being loaded or selected by a media source. */
|
/** Descriptor for data being loaded or selected by a media source. */
|
||||||
final class MediaLoadData {
|
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. */
|
/** One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data. */
|
||||||
public final int dataType;
|
public final int dataType;
|
||||||
/**
|
/**
|
||||||
@ -108,9 +101,6 @@ public interface MediaSourceEventListener {
|
|||||||
/**
|
/**
|
||||||
* Creates media load data.
|
* 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 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
|
* @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.
|
* to media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise.
|
||||||
@ -126,8 +116,6 @@ public interface MediaSourceEventListener {
|
|||||||
* belong to a specific media period or the end time is unknown.
|
* belong to a specific media period or the end time is unknown.
|
||||||
*/
|
*/
|
||||||
public MediaLoadData(
|
public MediaLoadData(
|
||||||
int windowIndex,
|
|
||||||
@Nullable MediaPeriodId mediaPeriodId,
|
|
||||||
int dataType,
|
int dataType,
|
||||||
int trackType,
|
int trackType,
|
||||||
@Nullable Format trackFormat,
|
@Nullable Format trackFormat,
|
||||||
@ -135,8 +123,6 @@ public interface MediaSourceEventListener {
|
|||||||
@Nullable Object trackSelectionData,
|
@Nullable Object trackSelectionData,
|
||||||
long mediaStartTimeMs,
|
long mediaStartTimeMs,
|
||||||
long mediaEndTimeMs) {
|
long mediaEndTimeMs) {
|
||||||
this.windowIndex = windowIndex;
|
|
||||||
this.mediaPeriodId = mediaPeriodId;
|
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
this.trackType = trackType;
|
this.trackType = trackType;
|
||||||
this.trackFormat = trackFormat;
|
this.trackFormat = trackFormat;
|
||||||
@ -150,26 +136,47 @@ public interface MediaSourceEventListener {
|
|||||||
/**
|
/**
|
||||||
* Called when a load begins.
|
* Called when a load begins.
|
||||||
*
|
*
|
||||||
|
* @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 load does not
|
||||||
|
* belong to a specific media period.
|
||||||
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
||||||
*/
|
*/
|
||||||
void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData);
|
void onLoadStarted(
|
||||||
|
int windowIndex,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
|
LoadEventInfo loadEventInfo,
|
||||||
|
MediaLoadData mediaLoadData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a load ends.
|
* Called when a load ends.
|
||||||
*
|
*
|
||||||
|
* @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 load does not
|
||||||
|
* belong to a specific media period.
|
||||||
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
||||||
*/
|
*/
|
||||||
void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData);
|
void onLoadCompleted(
|
||||||
|
int windowIndex,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
|
LoadEventInfo loadEventInfo,
|
||||||
|
MediaLoadData mediaLoadData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a load is canceled.
|
* Called when a load is canceled.
|
||||||
*
|
*
|
||||||
|
* @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 load does not
|
||||||
|
* belong to a specific media period.
|
||||||
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
||||||
*/
|
*/
|
||||||
void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData);
|
void onLoadCanceled(
|
||||||
|
int windowIndex,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
|
LoadEventInfo loadEventInfo,
|
||||||
|
MediaLoadData mediaLoadData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a load error occurs.
|
* Called when a load error occurs.
|
||||||
@ -185,12 +192,17 @@ public interface MediaSourceEventListener {
|
|||||||
* such behavior). This method is called to provide the application with an opportunity to log the
|
* such behavior). This method is called to provide the application with an opportunity to log the
|
||||||
* error if it wishes to do so.
|
* error if it wishes to do so.
|
||||||
*
|
*
|
||||||
|
* @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 load does not
|
||||||
|
* belong to a specific media period.
|
||||||
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
* @param loadEventInfo The {@link LoadEventInfo} defining the load event.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
* @param mediaLoadData The {@link MediaLoadData} defining the data being loaded.
|
||||||
* @param error The load error.
|
* @param error The load error.
|
||||||
* @param wasCanceled Whether the load was canceled as a result of the error.
|
* @param wasCanceled Whether the load was canceled as a result of the error.
|
||||||
*/
|
*/
|
||||||
void onLoadError(
|
void onLoadError(
|
||||||
|
int windowIndex,
|
||||||
|
@Nullable MediaPeriodId mediaPeriodId,
|
||||||
LoadEventInfo loadEventInfo,
|
LoadEventInfo loadEventInfo,
|
||||||
MediaLoadData mediaLoadData,
|
MediaLoadData mediaLoadData,
|
||||||
IOException error,
|
IOException error,
|
||||||
@ -200,24 +212,33 @@ public interface MediaSourceEventListener {
|
|||||||
* Called when data is removed from the back of a media buffer, typically so that it can be
|
* Called when data is removed from the back of a media buffer, typically so that it can be
|
||||||
* re-buffered in a different format.
|
* re-buffered in a different format.
|
||||||
*
|
*
|
||||||
|
* @param windowIndex The window index in the timeline of the media source this load belongs to.
|
||||||
|
* @param mediaPeriodId The {@link MediaPeriodId} the media belongs to.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the media being discarded.
|
* @param mediaLoadData The {@link MediaLoadData} defining the media being discarded.
|
||||||
*/
|
*/
|
||||||
void onUpstreamDiscarded(MediaLoadData mediaLoadData);
|
void onUpstreamDiscarded(
|
||||||
|
int windowIndex, MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a downstream format change occurs (i.e. when the format of the media being read
|
* Called when a downstream format change occurs (i.e. when the format of the media being read
|
||||||
* from one or more {@link SampleStream}s provided by the source changes).
|
* from one or more {@link SampleStream}s provided by the source changes).
|
||||||
*
|
*
|
||||||
|
* @param windowIndex The window index in the timeline of the media source this load belongs to.
|
||||||
|
* @param mediaPeriodId The {@link MediaPeriodId} the media belongs to.
|
||||||
* @param mediaLoadData The {@link MediaLoadData} defining the newly selected downstream data.
|
* @param mediaLoadData The {@link MediaLoadData} defining the newly selected downstream data.
|
||||||
*/
|
*/
|
||||||
void onDownstreamFormatChanged(MediaLoadData mediaLoadData);
|
void onDownstreamFormatChanged(
|
||||||
|
int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData);
|
||||||
|
|
||||||
/** Dispatches events to {@link MediaSourceEventListener}s. */
|
/** Dispatches events to {@link MediaSourceEventListener}s. */
|
||||||
final class EventDispatcher {
|
final class EventDispatcher {
|
||||||
|
|
||||||
|
/** The timeline window index reported with the events. */
|
||||||
|
public final int windowIndex;
|
||||||
|
/** The {@link MediaPeriodId} reported with the events. */
|
||||||
|
public final @Nullable MediaPeriodId mediaPeriodId;
|
||||||
|
|
||||||
private final CopyOnWriteArrayList<ListenerAndHandler> listenerAndHandlers;
|
private final CopyOnWriteArrayList<ListenerAndHandler> listenerAndHandlers;
|
||||||
private final int windowIndex;
|
|
||||||
private final @Nullable MediaPeriodId mediaPeriodId;
|
|
||||||
private final long mediaTimeOffsetMs;
|
private final long mediaTimeOffsetMs;
|
||||||
|
|
||||||
/** Creates an event dispatcher. */
|
/** Creates an event dispatcher. */
|
||||||
@ -280,7 +301,7 @@ public interface MediaSourceEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadStarted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadStarted(DataSpec dataSpec, int dataType, long elapsedRealtimeMs) {
|
public void loadStarted(DataSpec dataSpec, int dataType, long elapsedRealtimeMs) {
|
||||||
loadStarted(
|
loadStarted(
|
||||||
dataSpec,
|
dataSpec,
|
||||||
@ -294,7 +315,7 @@ public interface MediaSourceEventListener {
|
|||||||
elapsedRealtimeMs);
|
elapsedRealtimeMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadStarted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadStarted(
|
public void loadStarted(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -309,8 +330,6 @@ public interface MediaSourceEventListener {
|
|||||||
new LoadEventInfo(
|
new LoadEventInfo(
|
||||||
dataSpec, elapsedRealtimeMs, /* loadDurationMs= */ 0, /* bytesLoaded= */ 0),
|
dataSpec, elapsedRealtimeMs, /* loadDurationMs= */ 0, /* bytesLoaded= */ 0),
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
dataType,
|
dataType,
|
||||||
trackType,
|
trackType,
|
||||||
trackFormat,
|
trackFormat,
|
||||||
@ -320,7 +339,7 @@ public interface MediaSourceEventListener {
|
|||||||
adjustMediaTime(mediaEndTimeUs)));
|
adjustMediaTime(mediaEndTimeUs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadStarted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadStarted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadStarted(final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
public void loadStarted(final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
||||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||||
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
||||||
@ -329,13 +348,13 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onLoadStarted(loadEventInfo, mediaLoadData);
|
listener.onLoadStarted(windowIndex, mediaPeriodId, loadEventInfo, mediaLoadData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCompleted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCompleted(
|
public void loadCompleted(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -356,7 +375,7 @@ public interface MediaSourceEventListener {
|
|||||||
bytesLoaded);
|
bytesLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCompleted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCompleted(
|
public void loadCompleted(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -372,8 +391,6 @@ public interface MediaSourceEventListener {
|
|||||||
loadCompleted(
|
loadCompleted(
|
||||||
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
dataType,
|
dataType,
|
||||||
trackType,
|
trackType,
|
||||||
trackFormat,
|
trackFormat,
|
||||||
@ -383,7 +400,7 @@ public interface MediaSourceEventListener {
|
|||||||
adjustMediaTime(mediaEndTimeUs)));
|
adjustMediaTime(mediaEndTimeUs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCompleted(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCompleted(
|
public void loadCompleted(
|
||||||
final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
||||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||||
@ -393,13 +410,13 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onLoadCompleted(loadEventInfo, mediaLoadData);
|
listener.onLoadCompleted(windowIndex, mediaPeriodId, loadEventInfo, mediaLoadData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCanceled(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCanceled(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCanceled(
|
public void loadCanceled(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -420,7 +437,7 @@ public interface MediaSourceEventListener {
|
|||||||
bytesLoaded);
|
bytesLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCanceled(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCanceled(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCanceled(
|
public void loadCanceled(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -436,8 +453,6 @@ public interface MediaSourceEventListener {
|
|||||||
loadCanceled(
|
loadCanceled(
|
||||||
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
dataType,
|
dataType,
|
||||||
trackType,
|
trackType,
|
||||||
trackFormat,
|
trackFormat,
|
||||||
@ -447,7 +462,7 @@ public interface MediaSourceEventListener {
|
|||||||
adjustMediaTime(mediaEndTimeUs)));
|
adjustMediaTime(mediaEndTimeUs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadCanceled(LoadEventInfo, MediaLoadData)}. */
|
/** Dispatches {@link #onLoadCanceled(int, MediaPeriodId, LoadEventInfo, MediaLoadData)}. */
|
||||||
public void loadCanceled(final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
public void loadCanceled(final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
|
||||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||||
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
||||||
@ -456,13 +471,16 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onLoadCanceled(loadEventInfo, mediaLoadData);
|
listener.onLoadCanceled(windowIndex, mediaPeriodId, loadEventInfo, mediaLoadData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadError(LoadEventInfo, MediaLoadData, IOException, boolean)}. */
|
/**
|
||||||
|
* Dispatches {@link #onLoadError(int, MediaPeriodId, LoadEventInfo, MediaLoadData, IOException,
|
||||||
|
* boolean)}.
|
||||||
|
*/
|
||||||
public void loadError(
|
public void loadError(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -487,7 +505,10 @@ public interface MediaSourceEventListener {
|
|||||||
wasCanceled);
|
wasCanceled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadError(LoadEventInfo, MediaLoadData, IOException, boolean)}. */
|
/**
|
||||||
|
* Dispatches {@link #onLoadError(int, MediaPeriodId, LoadEventInfo, MediaLoadData, IOException,
|
||||||
|
* boolean)}.
|
||||||
|
*/
|
||||||
public void loadError(
|
public void loadError(
|
||||||
DataSpec dataSpec,
|
DataSpec dataSpec,
|
||||||
int dataType,
|
int dataType,
|
||||||
@ -505,8 +526,6 @@ public interface MediaSourceEventListener {
|
|||||||
loadError(
|
loadError(
|
||||||
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded),
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
dataType,
|
dataType,
|
||||||
trackType,
|
trackType,
|
||||||
trackFormat,
|
trackFormat,
|
||||||
@ -518,7 +537,10 @@ public interface MediaSourceEventListener {
|
|||||||
wasCanceled);
|
wasCanceled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onLoadError(LoadEventInfo, MediaLoadData, IOException, boolean)}. */
|
/**
|
||||||
|
* Dispatches {@link #onLoadError(int, MediaPeriodId, LoadEventInfo, MediaLoadData, IOException,
|
||||||
|
* boolean)}.
|
||||||
|
*/
|
||||||
public void loadError(
|
public void loadError(
|
||||||
final LoadEventInfo loadEventInfo,
|
final LoadEventInfo loadEventInfo,
|
||||||
final MediaLoadData mediaLoadData,
|
final MediaLoadData mediaLoadData,
|
||||||
@ -531,18 +553,17 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onLoadError(loadEventInfo, mediaLoadData, error, wasCanceled);
|
listener.onLoadError(
|
||||||
|
windowIndex, mediaPeriodId, loadEventInfo, mediaLoadData, error, wasCanceled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onUpstreamDiscarded(MediaLoadData)}. */
|
/** Dispatches {@link #onUpstreamDiscarded(int, MediaPeriodId, MediaLoadData)}. */
|
||||||
public void upstreamDiscarded(int trackType, long mediaStartTimeUs, long mediaEndTimeUs) {
|
public void upstreamDiscarded(int trackType, long mediaStartTimeUs, long mediaEndTimeUs) {
|
||||||
upstreamDiscarded(
|
upstreamDiscarded(
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
C.DATA_TYPE_MEDIA,
|
C.DATA_TYPE_MEDIA,
|
||||||
trackType,
|
trackType,
|
||||||
/* trackFormat= */ null,
|
/* trackFormat= */ null,
|
||||||
@ -552,7 +573,7 @@ public interface MediaSourceEventListener {
|
|||||||
adjustMediaTime(mediaEndTimeUs)));
|
adjustMediaTime(mediaEndTimeUs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onUpstreamDiscarded(MediaLoadData)}. */
|
/** Dispatches {@link #onUpstreamDiscarded(int, MediaPeriodId, MediaLoadData)}. */
|
||||||
public void upstreamDiscarded(final MediaLoadData mediaLoadData) {
|
public void upstreamDiscarded(final MediaLoadData mediaLoadData) {
|
||||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||||
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
||||||
@ -561,13 +582,13 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onUpstreamDiscarded(mediaLoadData);
|
listener.onUpstreamDiscarded(windowIndex, mediaPeriodId, mediaLoadData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onDownstreamFormatChanged(MediaLoadData)}. */
|
/** Dispatches {@link #onDownstreamFormatChanged(int, MediaPeriodId, MediaLoadData)}. */
|
||||||
public void downstreamFormatChanged(
|
public void downstreamFormatChanged(
|
||||||
int trackType,
|
int trackType,
|
||||||
@Nullable Format trackFormat,
|
@Nullable Format trackFormat,
|
||||||
@ -576,8 +597,6 @@ public interface MediaSourceEventListener {
|
|||||||
long mediaTimeUs) {
|
long mediaTimeUs) {
|
||||||
downstreamFormatChanged(
|
downstreamFormatChanged(
|
||||||
new MediaLoadData(
|
new MediaLoadData(
|
||||||
windowIndex,
|
|
||||||
mediaPeriodId,
|
|
||||||
C.DATA_TYPE_MEDIA,
|
C.DATA_TYPE_MEDIA,
|
||||||
trackType,
|
trackType,
|
||||||
trackFormat,
|
trackFormat,
|
||||||
@ -587,7 +606,7 @@ public interface MediaSourceEventListener {
|
|||||||
/* mediaEndTimeMs= */ C.TIME_UNSET));
|
/* mediaEndTimeMs= */ C.TIME_UNSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dispatches {@link #onDownstreamFormatChanged(MediaLoadData)}. */
|
/** Dispatches {@link #onDownstreamFormatChanged(int, MediaPeriodId, MediaLoadData)}. */
|
||||||
public void downstreamFormatChanged(final MediaLoadData mediaLoadData) {
|
public void downstreamFormatChanged(final MediaLoadData mediaLoadData) {
|
||||||
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
for (ListenerAndHandler listenerAndHandler : listenerAndHandlers) {
|
||||||
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
final MediaSourceEventListener listener = listenerAndHandler.listener;
|
||||||
@ -596,7 +615,7 @@ public interface MediaSourceEventListener {
|
|||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onDownstreamFormatChanged(mediaLoadData);
|
listener.onDownstreamFormatChanged(windowIndex, mediaPeriodId, mediaLoadData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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 @@
|
|||||||
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;
|
|||||||
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
|
|||||||
// 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
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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;
|
|||||||
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;
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
|||||||
// 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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user