Conversation
This commit addresses the issue of inaccurate live position measurement in HLS by introducing NTP time synchronization. Unlike DASH, HLS lacks origin time synchronization logic, resulting in potential discrepancies in wall-clock time when using `System.currentTimeMillis()`. The commit utilizes the `SntpClient` in ExoPlayer to determine the clock offset with the default NTP server (`time.android.com`) and applies this information to the `HlsMediaSource`. With the implementation of this change, multiple devices can now synchronize playback to a common time source, as long as the origin server also synchronizes to an NTP time source.
Enables testing the Live Offset settings with the main demo PlayerActivity. Using an intent like: ``` adb shell am start -n androidx.media3.demo.main/.PlayerActivity -a androidx.media3.demo.main.action.VIEW --ei live_offset_target 30 --ef live_offset_adjust_speed 35.0 ``` Will start playback synced to a 30 second offset with agressive speed adjustment to achive it, note this requires audio codec that supports speed changes (AAC for example)
|
When we initially implemented support for low-latency HLS, this clock sync wasn't technically needed because all available segments and parts are explicitly published in the HLS playlist without the need for an explicit clock source (unlike DASH where this part of the core logic). The current live offset is always simply measured against the current device time and the "program data time" tags in the playlist. And the target offset is adjusted according to the HLS playlist settings, making it independent of the current system time (=no clock sync needed). Having said that, it also means the streams don't use the exact same target offset across devices. And if you manually set a target offset, it will be fully dependent on the system time again (this is what I think you are doing in your use case?) More concretely:
|
This commit addresses the issue of inaccurate live position measurement in HLS by introducing NTP time synchronization. Unlike DASH, HLS lacks origin time synchronization logic, resulting in potential discrepancies in wall-clock time when using `System.currentTimeMillis()`. The commit utilizes the `SntpClient` in ExoPlayer to determine the clock offset with the default NTP server (`time.android.com`) and applies this information to the `HlsMediaSource`. With the implementation of this change, multiple devices can now synchronize playback to a common time source, as long as the origin server also synchronizes to an NTP time source. NOTE: we will revert this commit in favor of the final merged changes when the pull request [androidx#1752](androidx#1752) is merged in.
This commit addresses the issue of inaccurate live position measurement in HLS by introducing NTP time synchronization. Unlike DASH, HLS lacks origin time synchronization logic, resulting in potential discrepancies in wall-clock time when using `System.currentTimeMillis()`. The commit utilizes the `SntpClient` in ExoPlayer to determine the clock offset with the default NTP server (`time.android.com`) and applies this information to the `HlsMediaSource`. With the implementation of this change, multiple devices can now synchronize playback to a common time source, as long as the origin server also synchronizes to an NTP time source. NOTE: we will revert this commit in favor of the final merged changes when the pull request [androidx#1752](androidx#1752) is merged in.
This pull request satisfies the enhancement request #702. For playback longer than a few hours the fix for SntpClient is also required, see pull request #697