mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Merge pull request #1794 from stevemayhew:p-fix-ntp-time-update-main
PiperOrigin-RevId: 689121191
(cherry picked from commit b5615d5e91)
This commit is contained in:
parent
a44079b516
commit
08e55d81ef
2 changed files with 34 additions and 0 deletions
|
|
@ -7,6 +7,10 @@
|
||||||
This release includes the following changes since the
|
This release includes the following changes since the
|
||||||
[1.5.0-beta01 release](#150-beta01-2024-10-30):
|
[1.5.0-beta01 release](#150-beta01-2024-10-30):
|
||||||
|
|
||||||
|
* ExoPlayer:
|
||||||
|
* 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)).
|
||||||
* Extractors:
|
* Extractors:
|
||||||
* Fix media duration parsing in `mdhd` box of MP4 files to handle `-1`
|
* Fix media duration parsing in `mdhd` box of MP4 files to handle `-1`
|
||||||
values ([#1819](https://github.com/androidx/media/issues/1819)).
|
values ([#1819](https://github.com/androidx/media/issues/1819)).
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,12 @@ public final class SntpClient {
|
||||||
@GuardedBy("valueLock")
|
@GuardedBy("valueLock")
|
||||||
private static int timeoutMs = DEFAULT_TIMEOUT_MS;
|
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() {}
|
private SntpClient() {}
|
||||||
|
|
||||||
/** Returns the NTP host address used to retrieve {@link #getElapsedRealtimeOffsetMs()}. */
|
/** Returns the NTP host address used to retrieve {@link #getElapsedRealtimeOffsetMs()}. */
|
||||||
|
|
@ -148,6 +154,24 @@ public final class SntpClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Returns whether the device time offset has already been loaded.
|
||||||
*
|
*
|
||||||
|
|
@ -156,6 +180,11 @@ public final class SntpClient {
|
||||||
*/
|
*/
|
||||||
public static boolean isInitialized() {
|
public static boolean isInitialized() {
|
||||||
synchronized (valueLock) {
|
synchronized (valueLock) {
|
||||||
|
if (lastUpdateElapsedRealtime != C.TIME_UNSET
|
||||||
|
&& maxElapsedTimeUntilUpdateMs != C.TIME_UNSET) {
|
||||||
|
long deltaLastUpdate = SystemClock.elapsedRealtime() - lastUpdateElapsedRealtime;
|
||||||
|
isInitialized = isInitialized && deltaLastUpdate < maxElapsedTimeUntilUpdateMs;
|
||||||
|
}
|
||||||
return isInitialized;
|
return isInitialized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -353,6 +382,7 @@ public final class SntpClient {
|
||||||
}
|
}
|
||||||
long offsetMs = loadNtpTimeOffsetMs();
|
long offsetMs = loadNtpTimeOffsetMs();
|
||||||
synchronized (valueLock) {
|
synchronized (valueLock) {
|
||||||
|
lastUpdateElapsedRealtime = SystemClock.elapsedRealtime();
|
||||||
elapsedRealtimeOffsetMs = offsetMs;
|
elapsedRealtimeOffsetMs = offsetMs;
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue