Commit c5aa376b by olly Committed by Oliver Woodman

Rename only part of FormatEvaluator/TrackSelection merge

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128471102
parent bf0bdd8d
Showing with 193 additions and 182 deletions
...@@ -236,30 +236,30 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb ...@@ -236,30 +236,30 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb
// AdaptiveMediaSourceEventListener // AdaptiveMediaSourceEventListener
@Override @Override
public void onLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format format, public void onLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long mediaStartTimeMs, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs) { long mediaEndTimeMs, long elapsedRealtimeMs) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format format, public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long mediaStartTimeMs, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded,
IOException error, boolean wasCanceled) { IOException error, boolean wasCanceled) {
printInternalError("loadError", error); printInternalError("loadError", error);
} }
@Override @Override
public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format format, public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long mediaStartTimeMs, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) { long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {
// Do nothing. // Do nothing.
} }
@Override @Override
public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format format, public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long mediaStartTimeMs, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) { long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {
// Do nothing. // Do nothing.
} }
...@@ -270,8 +270,8 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb ...@@ -270,8 +270,8 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb
} }
@Override @Override
public void onDownstreamFormatChanged(int trackType, Format format, int formatEvaluatorTrigger, public void onDownstreamFormatChanged(int trackType, Format trackFormat, int trackSelectionReason,
Object formatEvaluatorData, long mediaTimeMs) { Object trackSelectionData, long mediaTimeMs) {
// Do nothing. // Do nothing.
} }
......
...@@ -234,6 +234,43 @@ public interface C { ...@@ -234,6 +234,43 @@ public interface C {
int TRACK_TYPE_METADATA = 4; int TRACK_TYPE_METADATA = 4;
/** /**
* Applications or extensions may define custom {@code TRACK_TYPE_*} constants greater than or
* equal to this value.
*/
int TRACK_TYPE_CUSTOM_BASE = 10000;
/**
* A selection reason constant for selections whose reasons are unknown or unspecified.
*/
int SELECTION_REASON_UNKNOWN = 0;
/**
* A selection reason constant for an initial track selection.
*/
int SELECTION_REASON_INITIAL = 1;
/**
* A selection reason constant for an manual (i.e. user initiated) track selection.
*/
int SELECTION_REASON_MANUAL = 2;
/**
* A selection reason constant for an adaptive track selection.
*/
int SELECTION_REASON_ADAPTIVE = 3;
/**
* A selection reason constant for a trick play track selection.
*/
int SELECTION_REASON_TRICK_PLAY = 4;
/**
* Applications or extensions may define custom {@code SELECTION_REASON_*} constants greater than
* or equal to this value.
*/
int SELECTION_REASON_CUSTOM_BASE = 10000;
/**
* A default size in bytes for an individual allocation that forms part of a larger buffer. * A default size in bytes for an individual allocation that forms part of a larger buffer.
*/ */
int DEFAULT_BUFFER_SEGMENT_SIZE = 64 * 1024; int DEFAULT_BUFFER_SEGMENT_SIZE = 64 * 1024;
......
...@@ -33,17 +33,17 @@ public abstract class BaseMediaChunk extends MediaChunk { ...@@ -33,17 +33,17 @@ public abstract class BaseMediaChunk extends MediaChunk {
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs The start time of the media contained by the chunk, in microseconds. * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The index of the chunk. * @param chunkIndex The index of the chunk.
*/ */
public BaseMediaChunk(DataSource dataSource, DataSpec dataSpec, Format format, public BaseMediaChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs,
int chunkIndex) { int chunkIndex) {
super(dataSource, dataSpec, format, formatEvaluatorTrigger, formatEvaluatorData, startTimeUs, super(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, startTimeUs,
endTimeUs, chunkIndex); endTimeUs, chunkIndex);
} }
......
...@@ -38,21 +38,20 @@ public abstract class Chunk implements Loadable { ...@@ -38,21 +38,20 @@ public abstract class Chunk implements Loadable {
*/ */
public final int type; public final int type;
/** /**
* One of the {@link FormatEvaluator} {@code TRIGGER_*} constants if a format evaluation was * The format of the track to which this chunk belongs, or null if the chunk does not belong to
* performed to determine that this chunk should be loaded. * a track.
* {@link FormatEvaluator#TRIGGER_UNKNOWN} otherwise.
*/ */
public final int formatEvaluatorTrigger; public final Format trackFormat;
/** /**
* Optional data set by a {@link FormatEvaluator} if a format evaluation was performed to * One of the {@link C} {@code SELECTION_REASON_*} constants if the chunk belongs to a track.
* determine that this chunk should be loaded. Null otherwise. * {@link C#SELECTION_REASON_UNKNOWN} if the chunk does not belong to a track.
*/ */
public final Object formatEvaluatorData; public final int trackSelectionReason;
/** /**
* The format associated with the data being loaded, or null if the data being loaded is not * Optional data associated with the selection of the track to which this chunk belongs. Null if
* associated with a specific format. * the chunk does not belong to a track.
*/ */
public final Format format; public final Object trackSelectionData;
/** /**
* The start time of the media contained by the chunk, or {@link C#UNSET_TIME_US} if the data * The start time of the media contained by the chunk, or {@link C#UNSET_TIME_US} if the data
* being loaded does not contain media samples. * being loaded does not contain media samples.
...@@ -70,20 +69,20 @@ public abstract class Chunk implements Loadable { ...@@ -70,20 +69,20 @@ public abstract class Chunk implements Loadable {
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param type See {@link #type}. * @param type See {@link #type}.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs See {@link #startTimeUs}. * @param startTimeUs See {@link #startTimeUs}.
* @param endTimeUs See {@link #endTimeUs}. * @param endTimeUs See {@link #endTimeUs}.
*/ */
public Chunk(DataSource dataSource, DataSpec dataSpec, int type, Format format, public Chunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs) { int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs) {
this.dataSource = Assertions.checkNotNull(dataSource); this.dataSource = Assertions.checkNotNull(dataSource);
this.dataSpec = Assertions.checkNotNull(dataSpec); this.dataSpec = Assertions.checkNotNull(dataSpec);
this.type = type; this.type = type;
this.format = format; this.trackFormat = trackFormat;
this.formatEvaluatorTrigger = formatEvaluatorTrigger; this.trackSelectionReason = trackSelectionReason;
this.formatEvaluatorData = formatEvaluatorData; this.trackSelectionData = trackSelectionData;
this.startTimeUs = startTimeUs; this.startTimeUs = startTimeUs;
this.endTimeUs = endTimeUs; this.endTimeUs = endTimeUs;
} }
......
...@@ -49,7 +49,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -49,7 +49,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
private final ChunkHolder nextChunkHolder; private final ChunkHolder nextChunkHolder;
private final Loader loader; private final Loader loader;
private Format downstreamFormat; private Format downstreamTrackFormat;
private long lastSeekPositionUs; private long lastSeekPositionUs;
private long pendingResetPositionUs; private long pendingResetPositionUs;
...@@ -182,13 +182,13 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -182,13 +182,13 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
} }
BaseMediaChunk currentChunk = mediaChunks.getFirst(); BaseMediaChunk currentChunk = mediaChunks.getFirst();
Format format = currentChunk.format; Format trackFormat = currentChunk.trackFormat;
if (!format.equals(downstreamFormat)) { if (!trackFormat.equals(downstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(trackType, format, eventDispatcher.downstreamFormatChanged(trackType, trackFormat,
currentChunk.formatEvaluatorTrigger, currentChunk.formatEvaluatorData, currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs); currentChunk.startTimeUs);
} }
downstreamFormat = format; downstreamTrackFormat = trackFormat;
return sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs); return sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
} }
...@@ -202,8 +202,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -202,8 +202,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
@Override @Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) { public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
chunkSource.onChunkLoadCompleted(loadable); chunkSource.onChunkLoadCompleted(loadable);
eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
callback.onContinueLoadingRequested(this); callback.onContinueLoadingRequested(this);
} }
...@@ -211,8 +211,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -211,8 +211,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
@Override @Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
boolean released) { boolean released) {
eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
if (!released) { if (!released) {
sampleQueue.reset(true); sampleQueue.reset(true);
...@@ -238,8 +238,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -238,8 +238,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
} }
} }
} }
eventDispatcher.loadError(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadError(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, bytesLoaded, error, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, bytesLoaded, error,
canceled); canceled);
if (canceled) { if (canceled) {
...@@ -281,8 +281,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -281,8 +281,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
mediaChunks.add(mediaChunk); mediaChunks.add(mediaChunk);
} }
long elapsedRealtimeMs = loader.startLoading(loadable, this, minLoadableRetryCount); long elapsedRealtimeMs = loader.startLoading(loadable, this, minLoadableRetryCount);
eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs); loadable.endTimeUs, elapsedRealtimeMs);
return true; return true;
} }
......
...@@ -44,9 +44,9 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackMe ...@@ -44,9 +44,9 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackMe
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs The start time of the media contained by the chunk, in microseconds. * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The index of the chunk. * @param chunkIndex The index of the chunk.
...@@ -55,11 +55,11 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackMe ...@@ -55,11 +55,11 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackMe
* @param sampleFormat The {@link Format} of the samples in the chunk, if known. May be null if * @param sampleFormat The {@link Format} of the samples in the chunk, if known. May be null if
* the data is known to define its own sample format. * the data is known to define its own sample format.
*/ */
public ContainerMediaChunk(DataSource dataSource, DataSpec dataSpec, Format format, public ContainerMediaChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs,
int chunkIndex, long sampleOffsetUs, ChunkExtractorWrapper extractorWrapper, int chunkIndex, long sampleOffsetUs, ChunkExtractorWrapper extractorWrapper,
Format sampleFormat) { Format sampleFormat) {
super(dataSource, dataSpec, format, formatEvaluatorTrigger, formatEvaluatorData, startTimeUs, super(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, startTimeUs,
endTimeUs, chunkIndex); endTimeUs, chunkIndex);
this.extractorWrapper = extractorWrapper; this.extractorWrapper = extractorWrapper;
this.sampleOffsetUs = sampleOffsetUs; this.sampleOffsetUs = sampleOffsetUs;
......
...@@ -40,14 +40,14 @@ public abstract class DataChunk extends Chunk { ...@@ -40,14 +40,14 @@ public abstract class DataChunk extends Chunk {
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param type See {@link #type}. * @param type See {@link #type}.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param data An optional recycled array that can be used as a holder for the data. * @param data An optional recycled array that can be used as a holder for the data.
*/ */
public DataChunk(DataSource dataSource, DataSpec dataSpec, int type, Format format, public DataChunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, byte[] data) { int trackSelectionReason, Object trackSelectionData, byte[] data) {
super(dataSource, dataSpec, type, format, formatEvaluatorTrigger, formatEvaluatorData, super(dataSource, dataSpec, type, trackFormat, trackSelectionReason, trackSelectionData,
C.UNSET_TIME_US, C.UNSET_TIME_US); C.UNSET_TIME_US, C.UNSET_TIME_US);
this.data = data; this.data = data;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.source.chunk; package com.google.android.exoplayer2.source.chunk;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
...@@ -39,32 +40,6 @@ public interface FormatEvaluator { ...@@ -39,32 +40,6 @@ public interface FormatEvaluator {
} }
/** /**
* A trigger for a load whose reason is unknown or unspecified.
*/
int TRIGGER_UNKNOWN = 0;
/**
* A trigger for a load triggered by an initial format selection.
*/
int TRIGGER_INITIAL = 1;
/**
* A trigger for a load triggered by a user initiated format selection.
*/
int TRIGGER_MANUAL = 2;
/**
* A trigger for a load triggered by an adaptive format selection.
*/
int TRIGGER_ADAPTIVE = 3;
/**
* A trigger for a load triggered whilst in a trick play mode.
*/
int TRIGGER_TRICK_PLAY = 4;
/**
* Applications or extensions may define custom {@code TRIGGER_*} constants greater than or equal
* to this value.
*/
int TRIGGER_CUSTOM_BASE = 10000;
/**
* Enables the evaluator. * Enables the evaluator.
* *
* @param formats The formats from which to select, ordered by decreasing bandwidth. * @param formats The formats from which to select, ordered by decreasing bandwidth.
...@@ -80,8 +55,8 @@ public interface FormatEvaluator { ...@@ -80,8 +55,8 @@ public interface FormatEvaluator {
* Update the supplied evaluation. * Update the supplied evaluation.
* <p> * <p>
* When invoked, {@code evaluation} must contain the currently selected format (null for an * When invoked, {@code evaluation} must contain the currently selected format (null for an
* initial evaluation), the most recent trigger {@link #TRIGGER_INITIAL} for an initial * initial evaluation), the most recent reason ({@link C#SELECTION_REASON_INITIAL} for an
* evaluation) and the most recent evaluation data (null for an initial evaluation). * initial evaluation) and the most recent evaluation data (null for an initial evaluation).
* *
* @param bufferedDurationUs The duration of media currently buffered in microseconds. * @param bufferedDurationUs The duration of media currently buffered in microseconds.
* @param blacklistFlags An array whose length is equal to the number of available formats. A * @param blacklistFlags An array whose length is equal to the number of available formats. A
...@@ -118,7 +93,7 @@ public interface FormatEvaluator { ...@@ -118,7 +93,7 @@ public interface FormatEvaluator {
/** /**
* The sticky reason for the format selection. * The sticky reason for the format selection.
*/ */
public int trigger; public int reason;
/** /**
* Sticky optional data relating to the evaluation. * Sticky optional data relating to the evaluation.
...@@ -126,7 +101,7 @@ public interface FormatEvaluator { ...@@ -126,7 +101,7 @@ public interface FormatEvaluator {
public Object data; public Object data;
public Evaluation() { public Evaluation() {
trigger = TRIGGER_INITIAL; reason = C.SELECTION_REASON_INITIAL;
} }
} }
...@@ -207,7 +182,7 @@ public interface FormatEvaluator { ...@@ -207,7 +182,7 @@ public interface FormatEvaluator {
} }
Format newFormat = formats[formatIndex]; Format newFormat = formats[formatIndex];
if (evaluation.format != null && evaluation.format != newFormat) { if (evaluation.format != null && evaluation.format != newFormat) {
evaluation.trigger = TRIGGER_ADAPTIVE; evaluation.reason = C.SELECTION_REASON_ADAPTIVE;
} }
evaluation.format = newFormat; evaluation.format = newFormat;
} }
...@@ -331,7 +306,7 @@ public interface FormatEvaluator { ...@@ -331,7 +306,7 @@ public interface FormatEvaluator {
} }
} }
if (current != null && selected != current) { if (current != null && selected != current) {
evaluation.trigger = TRIGGER_ADAPTIVE; evaluation.reason = C.SELECTION_REASON_ADAPTIVE;
} }
evaluation.format = selected; evaluation.format = selected;
} }
...@@ -347,7 +322,7 @@ public interface FormatEvaluator { ...@@ -347,7 +322,7 @@ public interface FormatEvaluator {
if (bufferedDurationUs < minDurationToRetainAfterDiscardUs) { if (bufferedDurationUs < minDurationToRetainAfterDiscardUs) {
return queueSize; return queueSize;
} }
Format current = queue.get(queueSize - 1).format; Format current = queue.get(queueSize - 1).trackFormat;
Format ideal = determineIdealFormat(formats, blacklistFlags, Format ideal = determineIdealFormat(formats, blacklistFlags,
bandwidthMeter.getBitrateEstimate()); bandwidthMeter.getBitrateEstimate());
if (ideal.bitrate <= current.bitrate) { if (ideal.bitrate <= current.bitrate) {
...@@ -359,10 +334,10 @@ public interface FormatEvaluator { ...@@ -359,10 +334,10 @@ public interface FormatEvaluator {
MediaChunk thisChunk = queue.get(i); MediaChunk thisChunk = queue.get(i);
long durationBeforeThisSegmentUs = thisChunk.startTimeUs - playbackPositionUs; long durationBeforeThisSegmentUs = thisChunk.startTimeUs - playbackPositionUs;
if (durationBeforeThisSegmentUs >= minDurationToRetainAfterDiscardUs if (durationBeforeThisSegmentUs >= minDurationToRetainAfterDiscardUs
&& thisChunk.format.bitrate < ideal.bitrate && thisChunk.trackFormat.bitrate < ideal.bitrate
&& thisChunk.format.height < ideal.height && thisChunk.trackFormat.height < ideal.height
&& thisChunk.format.height < 720 && thisChunk.trackFormat.height < 720
&& thisChunk.format.width < 1280) { && thisChunk.trackFormat.width < 1280) {
// Discard chunks from this one onwards. // Discard chunks from this one onwards.
return i; return i;
} }
......
...@@ -50,16 +50,16 @@ public final class InitializationChunk extends Chunk implements SingleTrackMetad ...@@ -50,16 +50,16 @@ public final class InitializationChunk extends Chunk implements SingleTrackMetad
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param extractorWrapper A wrapped extractor to use for parsing the initialization data. * @param extractorWrapper A wrapped extractor to use for parsing the initialization data.
*/ */
public InitializationChunk(DataSource dataSource, DataSpec dataSpec, Format format, public InitializationChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, int trackSelectionReason, Object trackSelectionData,
ChunkExtractorWrapper extractorWrapper) { ChunkExtractorWrapper extractorWrapper) {
super(dataSource, dataSpec, C.DATA_TYPE_MEDIA_INITIALIZATION, format, formatEvaluatorTrigger, super(dataSource, dataSpec, C.DATA_TYPE_MEDIA_INITIALIZATION, trackFormat, trackSelectionReason,
formatEvaluatorData, C.UNSET_TIME_US, C.UNSET_TIME_US); trackSelectionData, C.UNSET_TIME_US, C.UNSET_TIME_US);
this.extractorWrapper = extractorWrapper; this.extractorWrapper = extractorWrapper;
} }
......
...@@ -34,19 +34,19 @@ public abstract class MediaChunk extends Chunk { ...@@ -34,19 +34,19 @@ public abstract class MediaChunk extends Chunk {
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs The start time of the media contained by the chunk, in microseconds. * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The index of the chunk. * @param chunkIndex The index of the chunk.
*/ */
public MediaChunk(DataSource dataSource, DataSpec dataSpec, Format format, public MediaChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs,
int chunkIndex) { int chunkIndex) {
super(dataSource, dataSpec, C.DATA_TYPE_MEDIA, format, formatEvaluatorTrigger, super(dataSource, dataSpec, C.DATA_TYPE_MEDIA, trackFormat, trackSelectionReason,
formatEvaluatorData, startTimeUs, endTimeUs); trackSelectionData, startTimeUs, endTimeUs);
Assertions.checkNotNull(format); Assertions.checkNotNull(trackFormat);
this.chunkIndex = chunkIndex; this.chunkIndex = chunkIndex;
} }
......
...@@ -40,17 +40,17 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk { ...@@ -40,17 +40,17 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs The start time of the media contained by the chunk, in microseconds. * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The index of the chunk. * @param chunkIndex The index of the chunk.
*/ */
public SingleSampleMediaChunk(DataSource dataSource, DataSpec dataSpec, Format format, public SingleSampleMediaChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs,
int chunkIndex, Format sampleFormat) { int chunkIndex, Format sampleFormat) {
super(dataSource, dataSpec, format, formatEvaluatorTrigger, formatEvaluatorData, startTimeUs, super(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, startTimeUs,
endTimeUs, chunkIndex); endTimeUs, chunkIndex);
this.sampleFormat = sampleFormat; this.sampleFormat = sampleFormat;
} }
......
...@@ -177,7 +177,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -177,7 +177,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
evaluation); evaluation);
} else { } else {
evaluation.format = trackSelection.getFormat(0); evaluation.format = trackSelection.getFormat(0);
evaluation.trigger = FormatEvaluator.TRIGGER_UNKNOWN; evaluation.reason = C.SELECTION_REASON_UNKNOWN;
evaluation.data = null; evaluation.data = null;
} }
} }
...@@ -204,8 +204,8 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -204,8 +204,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
if (pendingInitializationUri != null || pendingIndexUri != null) { if (pendingInitializationUri != null || pendingIndexUri != null) {
// We have initialization and/or index requests to make. // We have initialization and/or index requests to make.
Chunk initializationChunk = newInitializationChunk(representationHolder, dataSource, Chunk initializationChunk = newInitializationChunk(representationHolder, dataSource,
selectedFormat, pendingInitializationUri, pendingIndexUri, evaluation.trigger, selectedFormat, evaluation.reason, evaluation.data, pendingInitializationUri,
evaluation.data); pendingIndexUri);
lastChunkWasInitialization = true; lastChunkWasInitialization = true;
out.chunk = initializationChunk; out.chunk = initializationChunk;
return; return;
...@@ -250,7 +250,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -250,7 +250,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
} }
Chunk nextMediaChunk = newMediaChunk(representationHolder, dataSource, selectedFormat, Chunk nextMediaChunk = newMediaChunk(representationHolder, dataSource, selectedFormat,
sampleFormat, segmentNum, evaluation.trigger, evaluation.data); evaluation.reason, evaluation.data, sampleFormat, segmentNum);
lastChunkWasInitialization = false; lastChunkWasInitialization = false;
out.chunk = nextMediaChunk; out.chunk = nextMediaChunk;
} }
...@@ -260,7 +260,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -260,7 +260,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
if (chunk instanceof InitializationChunk) { if (chunk instanceof InitializationChunk) {
InitializationChunk initializationChunk = (InitializationChunk) chunk; InitializationChunk initializationChunk = (InitializationChunk) chunk;
RepresentationHolder representationHolder = RepresentationHolder representationHolder =
representationHolders[trackSelection.indexOf(initializationChunk.format)]; representationHolders[trackSelection.indexOf(initializationChunk.trackFormat)];
Format sampleFormat = initializationChunk.getSampleFormat(); Format sampleFormat = initializationChunk.getSampleFormat();
if (sampleFormat != null) { if (sampleFormat != null) {
representationHolder.setSampleFormat(sampleFormat); representationHolder.setSampleFormat(sampleFormat);
...@@ -285,7 +285,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -285,7 +285,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
&& e instanceof InvalidResponseCodeException && e instanceof InvalidResponseCodeException
&& ((InvalidResponseCodeException) e).responseCode == 404) { && ((InvalidResponseCodeException) e).responseCode == 404) {
RepresentationHolder representationHolder = RepresentationHolder representationHolder =
representationHolders[trackSelection.indexOf(chunk.format)]; representationHolders[trackSelection.indexOf(chunk.trackFormat)];
int lastAvailableSegmentNum = representationHolder.getLastSegmentNum(); int lastAvailableSegmentNum = representationHolder.getLastSegmentNum();
if (((MediaChunk) chunk).chunkIndex >= lastAvailableSegmentNum) { if (((MediaChunk) chunk).chunkIndex >= lastAvailableSegmentNum) {
missingLastSegment = true; missingLastSegment = true;
...@@ -318,8 +318,8 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -318,8 +318,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
} }
private Chunk newInitializationChunk(RepresentationHolder representationHolder, private Chunk newInitializationChunk(RepresentationHolder representationHolder,
DataSource dataSource, Format trackFormat, RangedUri initializationUri, RangedUri indexUri, DataSource dataSource, Format trackFormat, int trackSelectionReason,
int formatEvaluatorTrigger, Object formatEvaluatorData) { Object trackSelectionData, RangedUri initializationUri, RangedUri indexUri) {
RangedUri requestUri; RangedUri requestUri;
if (initializationUri != null) { if (initializationUri != null) {
// It's common for initialization and index data to be stored adjacently. Attempt to merge // It's common for initialization and index data to be stored adjacently. Attempt to merge
...@@ -334,12 +334,12 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -334,12 +334,12 @@ public class DefaultDashChunkSource implements DashChunkSource {
DataSpec dataSpec = new DataSpec(requestUri.getUri(), requestUri.start, requestUri.length, DataSpec dataSpec = new DataSpec(requestUri.getUri(), requestUri.start, requestUri.length,
representationHolder.representation.getCacheKey()); representationHolder.representation.getCacheKey());
return new InitializationChunk(dataSource, dataSpec, trackFormat, return new InitializationChunk(dataSource, dataSpec, trackFormat,
formatEvaluatorTrigger, formatEvaluatorData, representationHolder.extractorWrapper); trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
} }
private Chunk newMediaChunk(RepresentationHolder representationHolder, DataSource dataSource, private Chunk newMediaChunk(RepresentationHolder representationHolder, DataSource dataSource,
Format trackFormat, Format sampleFormat, int segmentNum, int formatEvaluatorTrigger, Format trackFormat, int trackSelectionReason,
Object formatEvaluatorData) { Object trackSelectionData, Format sampleFormat, int segmentNum) {
Representation representation = representationHolder.representation; Representation representation = representationHolder.representation;
long startTimeUs = representationHolder.getSegmentStartTimeUs(segmentNum); long startTimeUs = representationHolder.getSegmentStartTimeUs(segmentNum);
long endTimeUs = representationHolder.getSegmentEndTimeUs(segmentNum); long endTimeUs = representationHolder.getSegmentEndTimeUs(segmentNum);
...@@ -348,12 +348,12 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -348,12 +348,12 @@ public class DefaultDashChunkSource implements DashChunkSource {
representation.getCacheKey()); representation.getCacheKey());
if (representationHolder.extractorWrapper == null) { if (representationHolder.extractorWrapper == null) {
return new SingleSampleMediaChunk(dataSource, dataSpec, trackFormat, formatEvaluatorTrigger, return new SingleSampleMediaChunk(dataSource, dataSpec, trackFormat, trackSelectionReason,
formatEvaluatorData, startTimeUs, endTimeUs, segmentNum, trackFormat); trackSelectionData, startTimeUs, endTimeUs, segmentNum, trackFormat);
} else { } else {
long sampleOffsetUs = -representation.presentationTimeOffsetUs; long sampleOffsetUs = -representation.presentationTimeOffsetUs;
return new ContainerMediaChunk(dataSource, dataSpec, trackFormat, formatEvaluatorTrigger, return new ContainerMediaChunk(dataSource, dataSpec, trackFormat, trackSelectionReason,
formatEvaluatorData, startTimeUs, endTimeUs, segmentNum, sampleOffsetUs, trackSelectionData, startTimeUs, endTimeUs, segmentNum, sampleOffsetUs,
representationHolder.extractorWrapper, sampleFormat); representationHolder.extractorWrapper, sampleFormat);
} }
} }
......
...@@ -199,14 +199,15 @@ public class HlsChunkSource { ...@@ -199,14 +199,15 @@ public class HlsChunkSource {
* @param out A holder to populate. * @param out A holder to populate.
*/ */
public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, ChunkHolder out) { public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, ChunkHolder out) {
int previousChunkVariantIndex = previous != null ? trackGroup.indexOf(previous.format) : -1; int previousChunkVariantIndex = previous != null ? trackGroup.indexOf(previous.trackFormat)
: -1;
updateFormatEvaluation(previous, playbackPositionUs); updateFormatEvaluation(previous, playbackPositionUs);
int newVariantIndex = trackGroup.indexOf(evaluation.format); int newVariantIndex = trackGroup.indexOf(evaluation.format);
boolean switchingVariant = previousChunkVariantIndex != newVariantIndex; boolean switchingVariant = previousChunkVariantIndex != newVariantIndex;
HlsMediaPlaylist mediaPlaylist = variantPlaylists[newVariantIndex]; HlsMediaPlaylist mediaPlaylist = variantPlaylists[newVariantIndex];
if (mediaPlaylist == null) { if (mediaPlaylist == null) {
// We don't have the media playlist for the next variant. Request it now. // We don't have the media playlist for the next variant. Request it now.
out.chunk = newMediaPlaylistChunk(newVariantIndex, evaluation.trigger, evaluation.data); out.chunk = newMediaPlaylistChunk(newVariantIndex, evaluation.reason, evaluation.data);
return; return;
} }
...@@ -241,7 +242,7 @@ public class HlsChunkSource { ...@@ -241,7 +242,7 @@ public class HlsChunkSource {
if (!mediaPlaylist.live) { if (!mediaPlaylist.live) {
out.endOfStream = true; out.endOfStream = true;
} else if (shouldRerequestLiveMediaPlaylist(newVariantIndex)) { } else if (shouldRerequestLiveMediaPlaylist(newVariantIndex)) {
out.chunk = newMediaPlaylistChunk(newVariantIndex, evaluation.trigger, evaluation.data); out.chunk = newMediaPlaylistChunk(newVariantIndex, evaluation.reason, evaluation.data);
} }
return; return;
} }
...@@ -255,7 +256,7 @@ public class HlsChunkSource { ...@@ -255,7 +256,7 @@ public class HlsChunkSource {
if (!keyUri.equals(encryptionKeyUri)) { if (!keyUri.equals(encryptionKeyUri)) {
// Encryption is specified and the key has changed. // Encryption is specified and the key has changed.
out.chunk = newEncryptionKeyChunk(keyUri, segment.encryptionIV, newVariantIndex, out.chunk = newEncryptionKeyChunk(keyUri, segment.encryptionIV, newVariantIndex,
evaluation.trigger, evaluation.data); evaluation.reason, evaluation.data);
return; return;
} }
if (!Util.areEqual(segment.encryptionIV, encryptionIvString)) { if (!Util.areEqual(segment.encryptionIV, encryptionIvString)) {
...@@ -309,7 +310,7 @@ public class HlsChunkSource { ...@@ -309,7 +310,7 @@ public class HlsChunkSource {
extractor = new WebvttExtractor(format.language, timestampAdjuster); extractor = new WebvttExtractor(format.language, timestampAdjuster);
} else if (previous == null } else if (previous == null
|| previous.discontinuitySequenceNumber != segment.discontinuitySequenceNumber || previous.discontinuitySequenceNumber != segment.discontinuitySequenceNumber
|| format != previous.format) { || format != previous.trackFormat) {
// MPEG-2 TS segments, but we need a new extractor. // MPEG-2 TS segments, but we need a new extractor.
PtsTimestampAdjuster timestampAdjuster = timestampAdjusterProvider.getAdjuster(true, PtsTimestampAdjuster timestampAdjuster = timestampAdjusterProvider.getAdjuster(true,
segment.discontinuitySequenceNumber, startTimeUs); segment.discontinuitySequenceNumber, startTimeUs);
...@@ -337,7 +338,7 @@ public class HlsChunkSource { ...@@ -337,7 +338,7 @@ public class HlsChunkSource {
extractorNeedsInit = false; extractorNeedsInit = false;
} }
out.chunk = new HlsMediaChunk(dataSource, dataSpec, format, evaluation.trigger, evaluation.data, out.chunk = new HlsMediaChunk(dataSource, dataSpec, format, evaluation.reason, evaluation.data,
startTimeUs, endTimeUs, chunkMediaSequence, segment.discontinuitySequenceNumber, extractor, startTimeUs, endTimeUs, chunkMediaSequence, segment.discontinuitySequenceNumber, extractor,
extractorNeedsInit, switchingVariant, encryptionKey, encryptionIv); extractorNeedsInit, switchingVariant, encryptionKey, encryptionIv);
} }
...@@ -417,7 +418,7 @@ public class HlsChunkSource { ...@@ -417,7 +418,7 @@ public class HlsChunkSource {
InvalidResponseCodeException responseCodeException = (InvalidResponseCodeException) e; InvalidResponseCodeException responseCodeException = (InvalidResponseCodeException) e;
int responseCode = responseCodeException.responseCode; int responseCode = responseCodeException.responseCode;
if (responseCode == 404 || responseCode == 410) { if (responseCode == 404 || responseCode == 410) {
int enabledVariantIndex = trackSelection.indexOf(chunk.format); int enabledVariantIndex = trackSelection.indexOf(chunk.trackFormat);
boolean alreadyBlacklisted = enabledVariantBlacklistFlags[enabledVariantIndex]; boolean alreadyBlacklisted = enabledVariantBlacklistFlags[enabledVariantIndex];
enabledVariantBlacklistFlags[enabledVariantIndex] = true; enabledVariantBlacklistFlags[enabledVariantIndex] = true;
enabledVariantBlacklistTimes[enabledVariantIndex] = SystemClock.elapsedRealtime(); enabledVariantBlacklistTimes[enabledVariantIndex] = SystemClock.elapsedRealtime();
...@@ -470,7 +471,7 @@ public class HlsChunkSource { ...@@ -470,7 +471,7 @@ public class HlsChunkSource {
evaluation.format = null; evaluation.format = null;
} }
} else { } else {
evaluation.trigger = FormatEvaluator.TRIGGER_UNKNOWN; evaluation.reason = C.SELECTION_REASON_UNKNOWN;
evaluation.data = null; evaluation.data = null;
} }
} }
...@@ -516,21 +517,21 @@ public class HlsChunkSource { ...@@ -516,21 +517,21 @@ public class HlsChunkSource {
return timeSinceLastMediaPlaylistLoadMs >= (mediaPlaylist.targetDurationSecs * 1000) / 2; return timeSinceLastMediaPlaylistLoadMs >= (mediaPlaylist.targetDurationSecs * 1000) / 2;
} }
private MediaPlaylistChunk newMediaPlaylistChunk(int variantIndex, int formatEvaluatorTrigger, private MediaPlaylistChunk newMediaPlaylistChunk(int variantIndex, int trackSelectionReason,
Object formatEvaluatorData) { Object trackSelectionData) {
Uri mediaPlaylistUri = UriUtil.resolveToUri(baseUri, variants[variantIndex].url); Uri mediaPlaylistUri = UriUtil.resolveToUri(baseUri, variants[variantIndex].url);
DataSpec dataSpec = new DataSpec(mediaPlaylistUri, 0, C.LENGTH_UNBOUNDED, null, DataSpec dataSpec = new DataSpec(mediaPlaylistUri, 0, C.LENGTH_UNBOUNDED, null,
DataSpec.FLAG_ALLOW_GZIP); DataSpec.FLAG_ALLOW_GZIP);
return new MediaPlaylistChunk(dataSource, dataSpec, variants[variantIndex].format, return new MediaPlaylistChunk(dataSource, dataSpec, variants[variantIndex].format,
formatEvaluatorTrigger, formatEvaluatorData, scratchSpace, playlistParser, variantIndex, trackSelectionReason, trackSelectionData, scratchSpace, playlistParser, variantIndex,
mediaPlaylistUri); mediaPlaylistUri);
} }
private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex, private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex,
int formatEvaluatorTrigger, Object formatEvaluatorData) { int trackSelectionReason, Object trackSelectionData) {
DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNBOUNDED, null, DataSpec.FLAG_ALLOW_GZIP); DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNBOUNDED, null, DataSpec.FLAG_ALLOW_GZIP);
return new EncryptionKeyChunk(dataSource, dataSpec, variants[variantIndex].format, return new EncryptionKeyChunk(dataSource, dataSpec, variants[variantIndex].format,
formatEvaluatorTrigger, formatEvaluatorData, scratchSpace, iv); trackSelectionReason, trackSelectionData, scratchSpace, iv);
} }
private void setEncryptionData(Uri keyUri, String iv, byte[] secretKey) { private void setEncryptionData(Uri keyUri, String iv, byte[] secretKey) {
...@@ -604,12 +605,12 @@ public class HlsChunkSource { ...@@ -604,12 +605,12 @@ public class HlsChunkSource {
private HlsMediaPlaylist result; private HlsMediaPlaylist result;
public MediaPlaylistChunk(DataSource dataSource, DataSpec dataSpec, Format format, public MediaPlaylistChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, byte[] scratchSpace, int trackSelectionReason, Object trackSelectionData, byte[] scratchSpace,
HlsPlaylistParser playlistParser, int variantIndex, HlsPlaylistParser playlistParser, int variantIndex,
Uri playlistUri) { Uri playlistUri) {
super(dataSource, dataSpec, C.DATA_TYPE_MANIFEST, format, formatEvaluatorTrigger, super(dataSource, dataSpec, C.DATA_TYPE_MANIFEST, trackFormat, trackSelectionReason,
formatEvaluatorData, scratchSpace); trackSelectionData, scratchSpace);
this.variantIndex = variantIndex; this.variantIndex = variantIndex;
this.playlistParser = playlistParser; this.playlistParser = playlistParser;
this.playlistUri = playlistUri; this.playlistUri = playlistUri;
...@@ -633,10 +634,10 @@ public class HlsChunkSource { ...@@ -633,10 +634,10 @@ public class HlsChunkSource {
private byte[] result; private byte[] result;
public EncryptionKeyChunk(DataSource dataSource, DataSpec dataSpec, Format format, public EncryptionKeyChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, byte[] scratchSpace, String iv) { int trackSelectionReason, Object trackSelectionData, byte[] scratchSpace, String iv) {
super(dataSource, dataSpec, C.DATA_TYPE_DRM, format, formatEvaluatorTrigger, super(dataSource, dataSpec, C.DATA_TYPE_DRM, trackFormat, trackSelectionReason,
formatEvaluatorData, scratchSpace); trackSelectionData, scratchSpace);
this.iv = iv; this.iv = iv;
} }
......
...@@ -62,9 +62,9 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -62,9 +62,9 @@ import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @param dataSource The source from which the data should be loaded. * @param dataSource The source from which the data should be loaded.
* @param dataSpec Defines the data to be loaded. * @param dataSpec Defines the data to be loaded.
* @param format See {@link #format}. * @param trackFormat See {@link #trackFormat}.
* @param formatEvaluatorTrigger See {@link #formatEvaluatorTrigger}. * @param trackSelectionReason See {@link #trackSelectionReason}.
* @param formatEvaluatorData See {@link #formatEvaluatorData}. * @param trackSelectionData See {@link #trackSelectionData}.
* @param startTimeUs The start time of the media contained by the chunk, in microseconds. * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The media sequence number of the chunk. * @param chunkIndex The media sequence number of the chunk.
...@@ -77,13 +77,13 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -77,13 +77,13 @@ import java.util.concurrent.atomic.AtomicInteger;
* @param encryptionKey For AES encryption chunks, the encryption key. * @param encryptionKey For AES encryption chunks, the encryption key.
* @param encryptionIv For AES encryption chunks, the encryption initialization vector. * @param encryptionIv For AES encryption chunks, the encryption initialization vector.
*/ */
public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, Format format, public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, Format trackFormat,
int formatEvaluatorTrigger, Object formatEvaluatorData, long startTimeUs, long endTimeUs, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs,
int chunkIndex, int discontinuitySequenceNumber, Extractor extractor, int chunkIndex, int discontinuitySequenceNumber, Extractor extractor,
boolean extractorNeedsInit, boolean shouldSpliceIn, byte[] encryptionKey, boolean extractorNeedsInit, boolean shouldSpliceIn, byte[] encryptionKey,
byte[] encryptionIv) { byte[] encryptionIv) {
super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, format, super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, trackFormat,
formatEvaluatorTrigger, formatEvaluatorData, startTimeUs, endTimeUs, chunkIndex); trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkIndex);
this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.discontinuitySequenceNumber = discontinuitySequenceNumber;
this.extractor = extractor; this.extractor = extractor;
this.extractorNeedsInit = extractorNeedsInit; this.extractorNeedsInit = extractorNeedsInit;
......
...@@ -83,7 +83,7 @@ import java.util.List; ...@@ -83,7 +83,7 @@ import java.util.List;
private boolean prepared; private boolean prepared;
private int enabledTrackCount; private int enabledTrackCount;
private Format downstreamFormat; private Format downstreamTrackFormat;
private int upstreamChunkUid; private int upstreamChunkUid;
// Tracks are complicated in HLS. See documentation of buildTracks for details. // Tracks are complicated in HLS. See documentation of buildTracks for details.
...@@ -189,7 +189,7 @@ import java.util.List; ...@@ -189,7 +189,7 @@ import java.util.List;
// Cancel requests if necessary. // Cancel requests if necessary.
if (enabledTrackCount == 0) { if (enabledTrackCount == 0) {
chunkSource.reset(); chunkSource.reset();
downstreamFormat = null; downstreamTrackFormat = null;
mediaChunks.clear(); mediaChunks.clear();
if (loader.isLoading()) { if (loader.isLoading()) {
loader.cancelLoading(); loader.cancelLoading();
...@@ -273,13 +273,13 @@ import java.util.List; ...@@ -273,13 +273,13 @@ import java.util.List;
mediaChunks.removeFirst(); mediaChunks.removeFirst();
} }
HlsMediaChunk currentChunk = mediaChunks.getFirst(); HlsMediaChunk currentChunk = mediaChunks.getFirst();
Format format = currentChunk.format; Format trackFormat = currentChunk.trackFormat;
if (!format.equals(downstreamFormat)) { if (!trackFormat.equals(downstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(trackType, format, eventDispatcher.downstreamFormatChanged(trackType, trackFormat,
currentChunk.formatEvaluatorTrigger, currentChunk.formatEvaluatorData, currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs); currentChunk.startTimeUs);
} }
downstreamFormat = format; downstreamTrackFormat = trackFormat;
return sampleQueues.valueAt(group).readData(formatHolder, buffer, loadingFinished, return sampleQueues.valueAt(group).readData(formatHolder, buffer, loadingFinished,
lastSeekPositionUs); lastSeekPositionUs);
...@@ -326,8 +326,8 @@ import java.util.List; ...@@ -326,8 +326,8 @@ import java.util.List;
mediaChunks.add(mediaChunk); mediaChunks.add(mediaChunk);
} }
long elapsedRealtimeMs = loader.startLoading(loadable, this, minLoadableRetryCount); long elapsedRealtimeMs = loader.startLoading(loadable, this, minLoadableRetryCount);
eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs); loadable.endTimeUs, elapsedRealtimeMs);
return true; return true;
} }
...@@ -346,8 +346,8 @@ import java.util.List; ...@@ -346,8 +346,8 @@ import java.util.List;
@Override @Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) { public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
chunkSource.onChunkLoadCompleted(loadable); chunkSource.onChunkLoadCompleted(loadable);
eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
if (!prepared) { if (!prepared) {
continueLoading(lastSeekPositionUs); continueLoading(lastSeekPositionUs);
...@@ -359,8 +359,8 @@ import java.util.List; ...@@ -359,8 +359,8 @@ import java.util.List;
@Override @Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
boolean released) { boolean released) {
eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
if (!released) { if (!released) {
int sampleQueueCount = sampleQueues.size(); int sampleQueueCount = sampleQueues.size();
...@@ -388,8 +388,8 @@ import java.util.List; ...@@ -388,8 +388,8 @@ import java.util.List;
} }
canceled = true; canceled = true;
} }
eventDispatcher.loadError(loadable.dataSpec, loadable.type, trackType, loadable.format, eventDispatcher.loadError(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
loadable.formatEvaluatorTrigger, loadable.formatEvaluatorData, loadable.startTimeUs, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded(), error, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded(), error,
canceled); canceled);
if (canceled) { if (canceled) {
......
...@@ -181,7 +181,7 @@ public class DefaultSsChunkSource implements SsChunkSource { ...@@ -181,7 +181,7 @@ public class DefaultSsChunkSource implements SsChunkSource {
evaluation); evaluation);
} else { } else {
evaluation.format = trackSelection.getFormat(0); evaluation.format = trackSelection.getFormat(0);
evaluation.trigger = FormatEvaluator.TRIGGER_UNKNOWN; evaluation.reason = C.SELECTION_REASON_UNKNOWN;
evaluation.data = null; evaluation.data = null;
} }
...@@ -226,7 +226,7 @@ public class DefaultSsChunkSource implements SsChunkSource { ...@@ -226,7 +226,7 @@ public class DefaultSsChunkSource implements SsChunkSource {
Uri uri = streamElement.buildRequestUri(manifestTrackIndex, chunkIndex); Uri uri = streamElement.buildRequestUri(manifestTrackIndex, chunkIndex);
out.chunk = newMediaChunk(selectedFormat, dataSource, uri, null, currentAbsoluteChunkIndex, out.chunk = newMediaChunk(selectedFormat, dataSource, uri, null, currentAbsoluteChunkIndex,
chunkStartTimeUs, chunkEndTimeUs, evaluation.trigger, evaluation.data, extractorWrapper); chunkStartTimeUs, chunkEndTimeUs, evaluation.reason, evaluation.data, extractorWrapper);
} }
@Override @Override
...@@ -251,14 +251,13 @@ public class DefaultSsChunkSource implements SsChunkSource { ...@@ -251,14 +251,13 @@ public class DefaultSsChunkSource implements SsChunkSource {
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri, private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri,
String cacheKey, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs, String cacheKey, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs,
int formatEvaluatorTrigger, Object formatEvaluatorData, int trackSelectionReason, Object trackSelectionData, ChunkExtractorWrapper extractorWrapper) {
ChunkExtractorWrapper extractorWrapper) {
DataSpec dataSpec = new DataSpec(uri, 0, -1, cacheKey); DataSpec dataSpec = new DataSpec(uri, 0, -1, cacheKey);
// In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk. // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
// To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs. // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
long sampleOffsetUs = chunkStartTimeUs; long sampleOffsetUs = chunkStartTimeUs;
return new ContainerMediaChunk(dataSource, dataSpec, format, formatEvaluatorTrigger, return new ContainerMediaChunk(dataSource, dataSpec, format, trackSelectionReason,
formatEvaluatorData, chunkStartTimeUs, chunkEndTimeUs, chunkIndex, sampleOffsetUs, trackSelectionData, chunkStartTimeUs, chunkEndTimeUs, chunkIndex, sampleOffsetUs,
extractorWrapper, format); extractorWrapper, format);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment