mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Modified timing of manifest fetches to compensate for drift due to fetch time.
This commit is contained in:
parent
7ea199638e
commit
03305c92cf
4 changed files with 28 additions and 10 deletions
|
|
@ -134,7 +134,7 @@ public class DashRendererBuilder implements RendererBuilder,
|
|||
this.manifest = manifest;
|
||||
if (manifest.dynamic && manifest.utcTiming != null) {
|
||||
UtcTimingElementResolver.resolveTimingElement(manifestDataSource, manifest.utcTiming,
|
||||
manifestFetcher.getManifestLoadTimestamp(), this);
|
||||
manifestFetcher.getManifestLoadCompleteTimestamp(), this);
|
||||
} else {
|
||||
buildRenderers();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ public class DashChunkSource implements ChunkSource {
|
|||
}
|
||||
|
||||
if (finishedCurrentManifest && (android.os.SystemClock.elapsedRealtime()
|
||||
> manifestFetcher.getManifestLoadTimestamp() + minUpdatePeriod)) {
|
||||
> manifestFetcher.getManifestLoadStartTimestamp() + minUpdatePeriod)) {
|
||||
manifestFetcher.requestRefresh();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
|||
}
|
||||
|
||||
if (finishedCurrentManifest && (SystemClock.elapsedRealtime()
|
||||
> manifestFetcher.getManifestLoadTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) {
|
||||
> manifestFetcher.getManifestLoadStartTimestamp() + MINIMUM_MANIFEST_REFRESH_PERIOD_MS)) {
|
||||
manifestFetcher.requestRefresh();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,13 +108,15 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
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.
|
||||
|
|
@ -176,13 +178,23 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -235,6 +247,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
}
|
||||
if (!loader.isLoading()) {
|
||||
currentLoadable = new UriLoadable<>(manifestUri, uriDataSource, parser);
|
||||
currentLoadStartTimestamp = SystemClock.elapsedRealtime();
|
||||
loader.startLoading(currentLoadable, this);
|
||||
notifyManifestRefreshStarted();
|
||||
}
|
||||
|
|
@ -248,7 +261,8 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
}
|
||||
|
||||
manifest = currentLoadable.getResult();
|
||||
manifestLoadTimestamp = SystemClock.elapsedRealtime();
|
||||
manifestLoadStartTimestamp = currentLoadStartTimestamp;
|
||||
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
|
||||
loadExceptionCount = 0;
|
||||
loadException = null;
|
||||
|
||||
|
|
@ -282,9 +296,10 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
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) {
|
||||
|
|
@ -331,6 +346,8 @@ public class ManifestFetcher<T> 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;
|
||||
|
|
@ -340,6 +357,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
}
|
||||
|
||||
public void startLoading() {
|
||||
loadStartTimestamp = SystemClock.elapsedRealtime();
|
||||
singleUseLoader.startLoading(callbackLooper, singleUseLoadable, this);
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +365,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
|
|||
public void onLoadCompleted(Loadable loadable) {
|
||||
try {
|
||||
T result = singleUseLoadable.getResult();
|
||||
onSingleFetchCompleted(result);
|
||||
onSingleFetchCompleted(result, loadStartTimestamp);
|
||||
wrappedCallback.onSingleManifest(result);
|
||||
} finally {
|
||||
releaseLoader();
|
||||
|
|
|
|||
Loading…
Reference in a new issue