Skip to content

Commit

Permalink
Add url (after redirection) to LoadEventInfo.
Browse files Browse the repository at this point in the history
This url is readily available when creating media source events (from the
data source) but so far not published to external listeners. This change
adds a new field to LoadEventInfo which corresponds to DataSource.getUri().

Issue:#2054

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202459049
  • Loading branch information
tonihei authored and ojw28 committed Jun 28, 2018
1 parent 236eb5c commit dd14500
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 152 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
([#4403](https://github.com/google/ExoPlayer/issues/4413)).
* Add support for multiple audio and video tracks in MPEG-PS streams
([#4406](https://github.com/google/ExoPlayer/issues/4406)).
* Add uri field to `LoadEventInfo` in `MediaSourceEventListener` or
`AnalyticsListener` callbacks. This uri is the redirected uri if redirection
occurred ([#2054](https://github.com/google/ExoPlayer/issues/2054)).

### 2.8.2 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.Loader.LoadErrorAction;
import com.google.android.exoplayer2.upstream.Loader.Loadable;
import com.google.android.exoplayer2.upstream.StatsDataSource;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ConditionVariable;
import com.google.android.exoplayer2.util.MimeTypes;
Expand Down Expand Up @@ -491,6 +492,7 @@ public void onLoadCompleted(ExtractingLoadable loadable, long elapsedRealtimeMs,
}
eventDispatcher.loadCompleted(
loadable.dataSpec,
loadable.dataSource.getLastOpenedUri(),
C.DATA_TYPE_MEDIA,
C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null,
Expand All @@ -500,7 +502,7 @@ public void onLoadCompleted(ExtractingLoadable loadable, long elapsedRealtimeMs,
durationUs,
elapsedRealtimeMs,
loadDurationMs,
loadable.bytesLoaded);
loadable.dataSource.getBytesRead());
copyLengthFromLoader(loadable);
loadingFinished = true;
callback.onContinueLoadingRequested(this);
Expand All @@ -511,6 +513,7 @@ public void onLoadCanceled(ExtractingLoadable loadable, long elapsedRealtimeMs,
long loadDurationMs, boolean released) {
eventDispatcher.loadCanceled(
loadable.dataSpec,
loadable.dataSource.getLastOpenedUri(),
C.DATA_TYPE_MEDIA,
C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null,
Expand All @@ -520,7 +523,7 @@ public void onLoadCanceled(ExtractingLoadable loadable, long elapsedRealtimeMs,
durationUs,
elapsedRealtimeMs,
loadDurationMs,
loadable.bytesLoaded);
loadable.dataSource.getBytesRead());
if (!released) {
copyLengthFromLoader(loadable);
for (SampleQueue sampleQueue : sampleQueues) {
Expand All @@ -539,9 +542,23 @@ public LoadErrorAction onLoadError(
long loadDurationMs,
IOException error,
int errorCount) {
boolean isErrorFatal = isLoadableExceptionFatal(error);
copyLengthFromLoader(loadable);
LoadErrorAction retryAction;
if (isLoadableExceptionFatal(error)) {
retryAction = Loader.DONT_RETRY_FATAL;
} else {
int extractedSamplesCount = getExtractedSamplesCount();
boolean madeProgress = extractedSamplesCount > extractedSamplesCountAtStartOfLoad;
retryAction =
configureRetry(loadable, extractedSamplesCount)
? (madeProgress ? Loader.RETRY_RESET_ERROR_COUNT : Loader.RETRY)
: Loader.DONT_RETRY;
}
boolean wasCanceled =
retryAction == Loader.DONT_RETRY || retryAction == Loader.DONT_RETRY_FATAL;
eventDispatcher.loadError(
loadable.dataSpec,
loadable.dataSource.getLastOpenedUri(),
C.DATA_TYPE_MEDIA,
C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null,
Expand All @@ -551,18 +568,10 @@ public LoadErrorAction onLoadError(
durationUs,
elapsedRealtimeMs,
loadDurationMs,
loadable.bytesLoaded,
loadable.dataSource.getBytesRead(),
error,
/* wasCanceled= */ isErrorFatal);
copyLengthFromLoader(loadable);
if (isErrorFatal) {
return Loader.DONT_RETRY_FATAL;
}
int extractedSamplesCount = getExtractedSamplesCount();
boolean madeProgress = extractedSamplesCount > extractedSamplesCountAtStartOfLoad;
return configureRetry(loadable, extractedSamplesCount)
? (madeProgress ? Loader.RETRY_RESET_ERROR_COUNT : Loader.RETRY)
: Loader.DONT_RETRY;
wasCanceled);
return retryAction;
}

// ExtractorOutput implementation. Called by the loading thread.
Expand Down Expand Up @@ -663,6 +672,7 @@ private void startLoading() {
long elapsedRealtimeMs = loader.startLoading(loadable, this, actualMinLoadableRetryCount);
eventDispatcher.loadStarted(
loadable.dataSpec,
loadable.dataSpec.uri,
C.DATA_TYPE_MEDIA,
C.TRACK_TYPE_UNKNOWN,
/* trackFormat= */ null,
Expand Down Expand Up @@ -803,7 +813,7 @@ public int skipData(long positionUs) {
/* package */ final class ExtractingLoadable implements Loadable {

private final Uri uri;
private final DataSource dataSource;
private final StatsDataSource dataSource;
private final ExtractorHolder extractorHolder;
private final ConditionVariable loadCondition;
private final PositionHolder positionHolder;
Expand All @@ -814,17 +824,17 @@ public int skipData(long positionUs) {
private long seekTimeUs;
private DataSpec dataSpec;
private long length;
private long bytesLoaded;

public ExtractingLoadable(Uri uri, DataSource dataSource, ExtractorHolder extractorHolder,
ConditionVariable loadCondition) {
this.uri = Assertions.checkNotNull(uri);
this.dataSource = Assertions.checkNotNull(dataSource);
this.dataSource = new StatsDataSource(dataSource);
this.extractorHolder = Assertions.checkNotNull(extractorHolder);
this.loadCondition = loadCondition;
this.positionHolder = new PositionHolder();
this.pendingExtractorSeek = true;
this.length = C.LENGTH_UNSET;
dataSpec = new DataSpec(uri, positionHolder.position, C.LENGTH_UNSET, customCacheKey);
}

public void setLoadPosition(long position, long timeUs) {
Expand Down Expand Up @@ -870,7 +880,6 @@ public void load() throws IOException, InterruptedException {
result = Extractor.RESULT_CONTINUE;
} else if (input != null) {
positionHolder.position = input.getPosition();
bytesLoaded = positionHolder.position - dataSpec.absoluteStreamPosition;
}
Util.closeQuietly(dataSource);
}
Expand Down
Loading

0 comments on commit dd14500

Please sign in to comment.