Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
* Remove `Renderer[]` parameter from `LoadControl.onTracksSelected()` as
`DefaultLoadControl` implementation can retrieve the stream types from
`ExoTrackSelection[]`.
* Add a setter to `SntpClient` to set the max elapsed time since the last
update after which the client is re-initialized
([#1794](https://github.com/androidx/media/pull/1794)).
* Deprecated `DefaultLoadControl.calculateTargetBufferBytes(Renderer[],
ExoTrackSelection[])` and marked method as final to prevent overrides.
The new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public interface InitializationCallback {
@GuardedBy("valueLock")
private static int timeoutMs = DEFAULT_TIMEOUT_MS;

@GuardedBy("valueLock")
private static long maxElapsedTimeUntilUpdateMs = C.TIME_UNSET;

@GuardedBy("valueLock")
private static long lastUpdateElapsedRealtime = C.TIME_UNSET;

private SntpClient() {}

/** Returns the NTP host address used to retrieve {@link #getElapsedRealtimeOffsetMs()}. */
Expand Down Expand Up @@ -148,6 +154,24 @@ public static void setTimeoutMs(int timeoutMs) {
}
}

/**
* Sets the maximum time to elapse until the client is re-initialized, in milliseconds.
*
* <p>The default is {@link C#TIME_UNSET} to never re-initialize.
*/
public static void setMaxElapsedTimeUntilUpdateMs(long maxElapsedTimeUntilUpdateMs) {
synchronized (valueLock) {
SntpClient.maxElapsedTimeUntilUpdateMs = maxElapsedTimeUntilUpdateMs;
}
}

/** Returns the maximum time to elapse until the client is re-initialized, in milliseconds. */
public static long getMaxElapsedTimeUntilUpdateMs() {
synchronized (valueLock) {
return maxElapsedTimeUntilUpdateMs;
}
}

/**
* Returns whether the device time offset has already been loaded.
*
Expand All @@ -156,6 +180,11 @@ public static void setTimeoutMs(int timeoutMs) {
*/
public static boolean isInitialized() {
synchronized (valueLock) {
if (lastUpdateElapsedRealtime != C.TIME_UNSET
&& maxElapsedTimeUntilUpdateMs != C.TIME_UNSET) {
long deltaLastUpdate = SystemClock.elapsedRealtime() - lastUpdateElapsedRealtime;
isInitialized = isInitialized && deltaLastUpdate < maxElapsedTimeUntilUpdateMs;
}
return isInitialized;
}
}
Expand Down Expand Up @@ -353,6 +382,7 @@ public void load() throws IOException {
}
long offsetMs = loadNtpTimeOffsetMs();
synchronized (valueLock) {
lastUpdateElapsedRealtime = SystemClock.elapsedRealtime();
elapsedRealtimeOffsetMs = offsetMs;
isInitialized = true;
}
Expand Down