Commit 03305c92 by Oliver Woodman

Modified timing of manifest fetches to compensate for drift due to fetch time.

parent 7ea19963
...@@ -134,7 +134,7 @@ public class DashRendererBuilder implements RendererBuilder, ...@@ -134,7 +134,7 @@ public class DashRendererBuilder implements RendererBuilder,
this.manifest = manifest; this.manifest = manifest;
if (manifest.dynamic && manifest.utcTiming != null) { if (manifest.dynamic && manifest.utcTiming != null) {
UtcTimingElementResolver.resolveTimingElement(manifestDataSource, manifest.utcTiming, UtcTimingElementResolver.resolveTimingElement(manifestDataSource, manifest.utcTiming,
manifestFetcher.getManifestLoadTimestamp(), this); manifestFetcher.getManifestLoadCompleteTimestamp(), this);
} else { } else {
buildRenderers(); buildRenderers();
} }
......
...@@ -386,7 +386,7 @@ public class DashChunkSource implements ChunkSource { ...@@ -386,7 +386,7 @@ public class DashChunkSource implements ChunkSource {
} }
if (finishedCurrentManifest && (android.os.SystemClock.elapsedRealtime() if (finishedCurrentManifest && (android.os.SystemClock.elapsedRealtime()
> manifestFetcher.getManifestLoadTimestamp() + minUpdatePeriod)) { > manifestFetcher.getManifestLoadStartTimestamp() + minUpdatePeriod)) {
manifestFetcher.requestRefresh(); manifestFetcher.requestRefresh();
} }
} }
......
...@@ -239,7 +239,7 @@ public class SmoothStreamingChunkSource implements ChunkSource { ...@@ -239,7 +239,7 @@ public class SmoothStreamingChunkSource implements ChunkSource {
} }
if (finishedCurrentManifest && (SystemClock.elapsedRealtime() if (finishedCurrentManifest && (SystemClock.elapsedRealtime()
> manifestFetcher.getManifestLoadTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) { > manifestFetcher.getManifestLoadStartTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) {
manifestFetcher.requestRefresh(); manifestFetcher.requestRefresh();
} }
} }
......
...@@ -108,13 +108,15 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -108,13 +108,15 @@ public class ManifestFetcher<T> implements Loader.Callback {
private int enabledCount; private int enabledCount;
private Loader loader; private Loader loader;
private UriLoadable<T> currentLoadable; private UriLoadable<T> currentLoadable;
private long currentLoadStartTimestamp;
private int loadExceptionCount; private int loadExceptionCount;
private long loadExceptionTimestamp; private long loadExceptionTimestamp;
private IOException loadException; private IOException loadException;
private volatile T manifest; private volatile T manifest;
private volatile long manifestLoadTimestamp; private volatile long manifestLoadStartTimestamp;
private volatile long manifestLoadCompleteTimestamp;
/** /**
* @param manifestUri The manifest location. * @param manifestUri The manifest location.
...@@ -177,12 +179,22 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -177,12 +179,22 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
/** /**
* 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. * Gets the value of {@link SystemClock#elapsedRealtime()} when the last load completed.
* *
* @return 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() { public long getManifestLoadCompleteTimestamp() {
return manifestLoadTimestamp; return manifestLoadCompleteTimestamp;
} }
/** /**
...@@ -235,6 +247,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -235,6 +247,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
if (!loader.isLoading()) { if (!loader.isLoading()) {
currentLoadable = new UriLoadable<>(manifestUri, uriDataSource, parser); currentLoadable = new UriLoadable<>(manifestUri, uriDataSource, parser);
currentLoadStartTimestamp = SystemClock.elapsedRealtime();
loader.startLoading(currentLoadable, this); loader.startLoading(currentLoadable, this);
notifyManifestRefreshStarted(); notifyManifestRefreshStarted();
} }
...@@ -248,7 +261,8 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -248,7 +261,8 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
manifest = currentLoadable.getResult(); manifest = currentLoadable.getResult();
manifestLoadTimestamp = SystemClock.elapsedRealtime(); manifestLoadStartTimestamp = currentLoadStartTimestamp;
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
loadExceptionCount = 0; loadExceptionCount = 0;
loadException = null; loadException = null;
...@@ -282,9 +296,10 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -282,9 +296,10 @@ public class ManifestFetcher<T> implements Loader.Callback {
notifyManifestError(loadException); notifyManifestError(loadException);
} }
/* package */ void onSingleFetchCompleted(T result) { /* package */ void onSingleFetchCompleted(T result, long loadStartTimestamp) {
manifest = result; manifest = result;
manifestLoadTimestamp = SystemClock.elapsedRealtime(); manifestLoadStartTimestamp = loadStartTimestamp;
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
} }
private long getRetryDelayMillis(long errorCount) { private long getRetryDelayMillis(long errorCount) {
...@@ -331,6 +346,8 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -331,6 +346,8 @@ public class ManifestFetcher<T> implements Loader.Callback {
private final ManifestCallback<T> wrappedCallback; private final ManifestCallback<T> wrappedCallback;
private final Loader singleUseLoader; private final Loader singleUseLoader;
private long loadStartTimestamp;
public SingleFetchHelper(UriLoadable<T> singleUseLoadable, Looper callbackLooper, public SingleFetchHelper(UriLoadable<T> singleUseLoadable, Looper callbackLooper,
ManifestCallback<T> wrappedCallback) { ManifestCallback<T> wrappedCallback) {
this.singleUseLoadable = singleUseLoadable; this.singleUseLoadable = singleUseLoadable;
...@@ -340,6 +357,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -340,6 +357,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
public void startLoading() { public void startLoading() {
loadStartTimestamp = SystemClock.elapsedRealtime();
singleUseLoader.startLoading(callbackLooper, singleUseLoadable, this); singleUseLoader.startLoading(callbackLooper, singleUseLoadable, this);
} }
...@@ -347,7 +365,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -347,7 +365,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
public void onLoadCompleted(Loadable loadable) { public void onLoadCompleted(Loadable loadable) {
try { try {
T result = singleUseLoadable.getResult(); T result = singleUseLoadable.getResult();
onSingleFetchCompleted(result); onSingleFetchCompleted(result, loadStartTimestamp);
wrappedCallback.onSingleManifest(result); wrappedCallback.onSingleManifest(result);
} finally { } finally {
releaseLoader(); releaseLoader();
......
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