systemclock: Use clock_nanosleep for higher accuracy
authorEdward Hervey <edward@centricular.com>
Fri, 30 Oct 2020 15:58:52 +0000 (16:58 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 6 Nov 2020 10:22:14 +0000 (11:22 +0100)
commit17feeb1bd6f4fa31d050054a6f3adb04816228d9
treec4dd54eb8d687cfe29f2944f332a5b831388cbac
parentb6df564251d7950196288a22e60e3111599d5629
systemclock: Use clock_nanosleep for higher accuracy

The various wait implementation have a latency ranging from 50 to 500+
microseconds. While this is not a major issue when dealing with a low number of
waits per second (for ex: video), it does introduce a non-negligeable jitter for
synchronization of higher packet rate systems.

The `clock_nanosleep` syscall does offer a lower-latency waiting system but is
unfortunately blocking, so we don't want to use it in all scenarios nor for too
long.

This patch makes GstSystemClock use clock_nanosleep (if available) as such:
* Any wait below 500us uses it
* Any wait below 2ms will first use the regular waiting system and then
  clock_nanosleep

  # modified:   gst/gstsystemclock.c

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/688>
gst/gstsystemclock.c
meson.build