Commit cf27bc84 by olly Committed by Oliver Woodman

DashMediaSource cleanup

- Get handling of "stale" and "out of sync" manifests so
  they're right next to each other (to be merged)
- Move startLoadingManifest to be next to the methods that
  schedule it, and actually start loading stuff.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182530683
parent 9de0123e
...@@ -597,21 +597,36 @@ public final class DashMediaSource implements MediaSource { ...@@ -597,21 +597,36 @@ public final class DashMediaSource implements MediaSource {
// this condition occurs, assume that we are hitting a manifest server that is out of sync and // this condition occurs, assume that we are hitting a manifest server that is out of sync and
// behind, discard this manifest, and try again later. // behind, discard this manifest, and try again later.
if (periodCount - removedPeriodCount > newManifest.getPeriodCount()) { if (periodCount - removedPeriodCount > newManifest.getPeriodCount()) {
Log.w(TAG, "Out of sync manifest"); Log.w(TAG, "Loaded out of sync manifest");
scheduleManifestRefresh(); scheduleManifestRefresh();
return; return;
} }
if (maybeReloadStaleDynamicManifest(newManifest)) { // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
return; // expired, or it's dynamic and we know the presentation has ended), then ignore it and load
// again up to a specified number of times.
if (manifest.dynamic
&& (dynamicMediaPresentationEnded
|| manifest.publishTimeMs <= expiredManifestPublishTimeUs)) {
Log.w(
TAG,
"Loaded stale dynamic manifest: "
+ manifest.publishTimeMs
+ ", "
+ dynamicMediaPresentationEnded
+ ", "
+ expiredManifestPublishTimeUs);
if (staleManifestReloadAttempt++ < minLoadableRetryCount) {
startLoadingManifest();
return;
}
} }
staleManifestReloadAttempt = 0;
manifest = newManifest; manifest = newManifest;
manifestLoadPending &= manifest.dynamic;
manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs; manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
manifestLoadEndTimestampMs = elapsedRealtimeMs; manifestLoadEndTimestampMs = elapsedRealtimeMs;
staleManifestReloadAttempt = 0;
if (!manifest.dynamic) {
manifestLoadPending = false;
}
if (manifest.location != null) { if (manifest.location != null) {
synchronized (manifestUriLock) { synchronized (manifestUriLock) {
// This condition checks that replaceManifestUri wasn't called between the start and end of // This condition checks that replaceManifestUri wasn't called between the start and end of
...@@ -665,45 +680,6 @@ public final class DashMediaSource implements MediaSource { ...@@ -665,45 +680,6 @@ public final class DashMediaSource implements MediaSource {
// Internal methods. // Internal methods.
/**
* Reloads a stale dynamic manifest to get a more recent version if possible.
*
* @return True if the reload is scheduled. False if we have already retried too many times.
*/
private boolean maybeReloadStaleDynamicManifest(DashManifest manifest) {
if (!isManifestStale(manifest)) {
return false;
}
String warning =
"Loaded a stale dynamic manifest "
+ manifest.publishTimeMs
+ " "
+ dynamicMediaPresentationEnded
+ " "
+ expiredManifestPublishTimeUs;
Log.w(TAG, warning);
if (staleManifestReloadAttempt++ < minLoadableRetryCount) {
startLoadingManifest();
return true;
}
return false;
}
private void startLoadingManifest() {
handler.removeCallbacks(refreshManifestRunnable);
if (loader.isLoading()) {
manifestLoadPending = true;
return;
}
Uri manifestUri;
synchronized (manifestUriLock) {
manifestUri = this.manifestUri;
}
manifestLoadPending = false;
startLoading(new ParsingLoadable<>(dataSource, manifestUri, C.DATA_TYPE_MANIFEST,
manifestParser), manifestCallback, minLoadableRetryCount);
}
private void resolveUtcTimingElement(UtcTimingElement timingElement) { private void resolveUtcTimingElement(UtcTimingElement timingElement) {
String scheme = timingElement.schemeIdUri; String scheme = timingElement.schemeIdUri;
if (Util.areEqual(scheme, "urn:mpeg:dash:utc:direct:2014") if (Util.areEqual(scheme, "urn:mpeg:dash:utc:direct:2014")
...@@ -835,12 +811,6 @@ public final class DashMediaSource implements MediaSource { ...@@ -835,12 +811,6 @@ public final class DashMediaSource implements MediaSource {
} }
} }
private boolean isManifestStale(DashManifest manifest) {
return manifest.dynamic
&& (dynamicMediaPresentationEnded
|| manifest.publishTimeMs <= expiredManifestPublishTimeUs);
}
private void scheduleManifestRefresh() { private void scheduleManifestRefresh() {
if (!manifest.dynamic) { if (!manifest.dynamic) {
return; return;
...@@ -858,6 +828,23 @@ public final class DashMediaSource implements MediaSource { ...@@ -858,6 +828,23 @@ public final class DashMediaSource implements MediaSource {
handler.postDelayed(refreshManifestRunnable, delayUntilNextLoad); handler.postDelayed(refreshManifestRunnable, delayUntilNextLoad);
} }
private void startLoadingManifest() {
handler.removeCallbacks(refreshManifestRunnable);
if (loader.isLoading()) {
manifestLoadPending = true;
return;
}
Uri manifestUri;
synchronized (manifestUriLock) {
manifestUri = this.manifestUri;
}
manifestLoadPending = false;
startLoading(
new ParsingLoadable<>(dataSource, manifestUri, C.DATA_TYPE_MANIFEST, manifestParser),
manifestCallback,
minLoadableRetryCount);
}
private <T> void startLoading(ParsingLoadable<T> loadable, private <T> void startLoading(ParsingLoadable<T> loadable,
Loader.Callback<ParsingLoadable<T>> callback, int minRetryCount) { Loader.Callback<ParsingLoadable<T>> callback, int minRetryCount) {
long elapsedRealtimeMs = loader.startLoading(loadable, callback, minRetryCount); long elapsedRealtimeMs = loader.startLoading(loadable, callback, minRetryCount);
......
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