Skip to content

Commit

Permalink
Modified timing of manifest fetches to compensate for drift due to fe…
Browse files Browse the repository at this point in the history
…tch time.
  • Loading branch information
ojw28 committed Jul 23, 2015
1 parent 7ea1996 commit 03305c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onSingleManifest(MediaPresentationDescription manifest) {
this.manifest = manifest;
if (manifest.dynamic && manifest.utcTiming != null) {
UtcTimingElementResolver.resolveTimingElement(manifestDataSource, manifest.utcTiming,
manifestFetcher.getManifestLoadTimestamp(), this);
manifestFetcher.getManifestLoadCompleteTimestamp(), this);
} else {
buildRenderers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void continueBuffering(long playbackPositionUs) {
}

if (finishedCurrentManifest && (android.os.SystemClock.elapsedRealtime()
> manifestFetcher.getManifestLoadTimestamp() + minUpdatePeriod)) {
> manifestFetcher.getManifestLoadStartTimestamp() + minUpdatePeriod)) {
manifestFetcher.requestRefresh();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void continueBuffering(long playbackPositionUs) {
}

if (finishedCurrentManifest && (SystemClock.elapsedRealtime()
> manifestFetcher.getManifestLoadTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) {
> manifestFetcher.getManifestLoadStartTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) {
manifestFetcher.requestRefresh();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ public interface RedirectingManifest {
private int enabledCount;
private Loader loader;
private UriLoadable<T> currentLoadable;
private long currentLoadStartTimestamp;

private int loadExceptionCount;
private long loadExceptionTimestamp;
private IOException loadException;

private volatile T manifest;
private volatile long manifestLoadTimestamp;
private volatile long manifestLoadStartTimestamp;
private volatile long manifestLoadCompleteTimestamp;

/**
* @param manifestUri The manifest location.
Expand Down Expand Up @@ -176,13 +178,23 @@ public T getManifest() {
return manifest;
}

/**
* Gets the value of {@link SystemClock#elapsedRealtime()} when the last completed load started.
*
* @return The value of {@link SystemClock#elapsedRealtime()} when the last completed load
* started.
*/
public long getManifestLoadStartTimestamp() {
return manifestLoadStartTimestamp;
}

/**
* Gets the value of {@link SystemClock#elapsedRealtime()} when the last load completed.
*
* @return The value of {@link SystemClock#elapsedRealtime()} when the last load completed.
*/
public long getManifestLoadTimestamp() {
return manifestLoadTimestamp;
public long getManifestLoadCompleteTimestamp() {
return manifestLoadCompleteTimestamp;
}

/**
Expand Down Expand Up @@ -235,6 +247,7 @@ public void requestRefresh() {
}
if (!loader.isLoading()) {
currentLoadable = new UriLoadable<>(manifestUri, uriDataSource, parser);
currentLoadStartTimestamp = SystemClock.elapsedRealtime();
loader.startLoading(currentLoadable, this);
notifyManifestRefreshStarted();
}
Expand All @@ -248,7 +261,8 @@ public void onLoadCompleted(Loadable loadable) {
}

manifest = currentLoadable.getResult();
manifestLoadTimestamp = SystemClock.elapsedRealtime();
manifestLoadStartTimestamp = currentLoadStartTimestamp;
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
loadExceptionCount = 0;
loadException = null;

Expand Down Expand Up @@ -282,9 +296,10 @@ public void onLoadError(Loadable loadable, IOException exception) {
notifyManifestError(loadException);
}

/* package */ void onSingleFetchCompleted(T result) {
/* package */ void onSingleFetchCompleted(T result, long loadStartTimestamp) {
manifest = result;
manifestLoadTimestamp = SystemClock.elapsedRealtime();
manifestLoadStartTimestamp = loadStartTimestamp;
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
}

private long getRetryDelayMillis(long errorCount) {
Expand Down Expand Up @@ -331,6 +346,8 @@ private class SingleFetchHelper implements Loader.Callback {
private final ManifestCallback<T> wrappedCallback;
private final Loader singleUseLoader;

private long loadStartTimestamp;

public SingleFetchHelper(UriLoadable<T> singleUseLoadable, Looper callbackLooper,
ManifestCallback<T> wrappedCallback) {
this.singleUseLoadable = singleUseLoadable;
Expand All @@ -340,14 +357,15 @@ public SingleFetchHelper(UriLoadable<T> singleUseLoadable, Looper callbackLooper
}

public void startLoading() {
loadStartTimestamp = SystemClock.elapsedRealtime();
singleUseLoader.startLoading(callbackLooper, singleUseLoadable, this);
}

@Override
public void onLoadCompleted(Loadable loadable) {
try {
T result = singleUseLoadable.getResult();
onSingleFetchCompleted(result);
onSingleFetchCompleted(result, loadStartTimestamp);
wrappedCallback.onSingleManifest(result);
} finally {
releaseLoader();
Expand Down

0 comments on commit 03305c9

Please sign in to comment.