Commit graph

132 commits

Author SHA1 Message Date
Seungha Yang
add1f17c57 systemclock: Restore default clock mode to monotonic for non-linux system
Before the MR https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829
Windows and macOS system clock used monotonic clock regardless of
selected clock mode. And because of clock resolution, we should prefer
monotonic over realtime unless realtime clock is selected explicitly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/855>
2021-07-26 09:20:42 +00:00
tyler-aicradle
ea33144147 systemclock: fall back to g_get_monotonic_time
This allows us to cover the case where we're on some unknown system that
doesn't have a known native precision monotonic time source. Sadly this
reintroduces some of the complexity removed in previous commits.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
2021-05-27 16:01:17 -05:00
tyler-aicradle
5328941632 systemclock: reorg real and mono time functions for macOS and win32
This simplifies the pre-processor checks a little to make it easier to
follow the code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
2021-05-27 09:44:29 -05:00
tyler-aicradle
d8237f150c systemclock: Use g_get_real_time on Windows and macOS for realtime clock
These targets previously were unable to produce wall clock times when
using GstSystemClock, this change makes it possible.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
2021-05-27 09:25:29 -05:00
tyler-aicradle
bb77f41abf systemclock: Reorganize defined checks for parts of GstSystemClock
The gst_system_clock_get_internal_time and
gst_system_clock_get_resolution functions had some nested defined checks
making this code somewhat harder to reason about and much harder to
change. The logical meaning of the checks has changed but the actual
code coming out of the pre-processor should not have changed
significantly. The main logical change was flattening the checks for
existence of posix timing functionality, from what I can tell these
functions aren't available on Windows where they were trying to be
included. I have checked the Linux and macOS output and they are
functionally unchanged.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/829>
2021-05-27 09:25:24 -05:00
Pieter Willem Jordaan
c899d0a52c systemclock: Fix deadlock on clock_nanosleep
Always use the monotonic clock's diff and end time for clock_nanosleep to have predictable behaviour even with other clock types.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/779>
2021-03-31 21:16:36 +02:00
Edward Hervey
17feeb1bd6 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>
2020-11-06 11:22:14 +01:00
Roman Shpuntov
fd280c0981 systemclock: Fix clock time conversion on Windows/xbox
The returned ratio can be bigger than GST_SECOND, in which case we would
forever return 0 for the system clock time. Even in other cases if it's
close to GST_SECOND it would result in accuracy loss.

Instead of doing the division by GST_CLOCK_TIME_NONE during
initialization once, do it every time the clock time is requested.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/575

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/534>
2020-06-18 17:41:25 +03:00
Sebastian Dröge
bf0672f00b systemclock: Only try initializing entries if they were not initialized before
And add assertions accordingly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/500>
2020-05-27 12:15:34 +00:00
Sebastian Dröge
d9bf0f1ec2 systemclock: Clarify comment that described a previous version of the code
Nowadays we are only waking up the head entry waiting if either the head
entry is unscheduled (which is handled some lines above already), or
when the head entry specifically is woken up because a new entry became
the new head entry.

We're not waking up *all* entries anymore whenever any entry in the last
was unscheduled.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/500>
2020-05-27 12:15:34 +00:00
Sebastian Dröge
c4a2d92718 systemclock: Get rid of atomic access to clock entry status and use the mutex instead
We already have a mutex in each clock entry anyway and need to make use
of that mutex in most cases when the status changes. Removal of the
atomic operations and usage of the mutex instead simplifies the code
considerably.

The only downside is that unscheduling a clock entry might block for the
time it needs for the waiting thread to go from checking the status of
the entry to actually waiting, which is not a lot of code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/500>
2020-05-27 12:15:34 +00:00
Sebastian Dröge
3e924f5df9 systemclock: Don't start waiting for a clock id if it was signalled before
Otherwise it can happen that unscheduling a clock id never takes place
and instead it is waiting until the normal timeout. This can happen if
the wait thread checks the status and sets it to busy, then the
unschedule thread sets it to unscheduled and signals the condition
variable, and then the waiting thread starts waiting. As condition
variables don't have a state (unlike Windows event objects), we have to
remember ourselves in a new boolean flag protected by the entry mutex
whether it is currently signalled, and reset this after waiting.

Previously this was not a problem because a file descriptor was written
to for waking up, and the token was left on the file descriptor until
the read from it for waiting.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/500>
2020-05-27 12:15:34 +00:00
Seungha Yang
684723d07c systemclock: Fix clock waiting on Windows
Add missing parentheses in macro for the divide operation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/444>
2020-04-22 20:59:02 +09:00
Sebastian Dröge
ed1022fa81 Use gst_object_unref() / gst_object_clear() instead of the GObject ones
To allow the refcounting tracer to work better. In childproxy/iterator
these might be plain GObjects but gst_object_unref() also works on them.
In other places where it is never GstObject, g_object_unref() is kept.
2020-04-20 16:28:52 +00:00
Matthew Waters
de0ec87ba1 systemclock: introduce a minimum wait time
There is not point waiting if the time to wait is less than this
platform specific value.  The worst case here is GCond usage on windows
where the granularity is 1ms.
2020-04-16 01:26:59 +00:00
Matthew Waters
6f9a63a10d gst/systemclock: wait on each entry individually
Problem:
multiple aggregator elements (audiomixer, compositor) in a live
pipeline use a lot of CPU waiting each other up.  This is because
of the previously unused clock entry unscheduling during regular
operation.

Clock entry unscheduling has the potential to wake up every clock entry
waiting using the system clock which may be a large number.

Solution:
Implement waiting per entry and only wakeup the unscheduled entry.

While this may be possible using GCond, theoretically GCond only gives
us microsecond accuracy and uses relative waits in a number of places.
We can unfortunately do better poking at the platform specifics
ourselves by using futexes on linux and pthread on other unix.  Windows
may have a possible implementation using Waitable timers but that is
not implemented here and instead falls back to the GCond implementation.
GCond waits on Windows is still as accurate as the previous GstPoll-based
implementation.
2020-04-16 01:26:59 +00:00
Matthew Waters
546bf6ec25 systemclock: log the object name with all debug logs
Simplifies correlating logs with clock instances
2020-04-16 01:26:59 +00:00
Matthew Waters
2c8a65745c systemclock: move to GCond waiting 2020-04-16 01:26:59 +00:00
Sebastian Dröge
b55d6c0b02 systemclock: Don't start the system clock at 0 on Windows
We kept the start time around and subtracted it everywhere for "easy of
debugging", but we don't do anything like this anywhere else and it
only complicates the code unnecessarily.
2020-03-09 15:17:08 +02:00
Sebastian Dröge
daf7df28dd systemclock: Don't divide by zero on Windows if high performance timers are not available 2020-03-09 15:16:00 +02:00
Olivier Crête
b4ba9ec089 systemclock: No need to check for CLOCK_TAI in the meson
POSIX defines CLOCK_MONOTONIC to always be a macro, so I think
it's safe to assume that CLOCK_TAI will also be.
2020-01-27 17:16:14 +00:00
Ederson de Souza
216d6dd0f0 GstSystemClock: Add GST_CLOCK_TYPE_TAI
GST_CLOCK_TYPE_TAI is GStreamer abstraction for CLOCK_TAI. Main
motivation for this patch is support for transmission offloading features
- when network packets are timestamped with the time they are deemed to
be actually transmitted. Linux API for that requires that time to be
in CLOCK_TAI coordinate.

With GST_CLOCK_TYPE_TAI, applications can use CLOCK_TAI directly on
their pipelines, avoiding the need to cross timestamp packet times. By
leveraging system's CLOCK_TAI, applications also don't need to keep track
of leap seconds - less burden for them. Just keep system's CLOCK_TAI
accurate and use it.
2020-01-27 17:16:14 +00:00
Olivier Crête
0a8d14acc9 Remove deprecated GTimeVal
GTimeVal won't work past 2038
2019-12-10 19:18:32 -05:00
Nirbheek Chauhan
f336fdd088 gstsystemclock: Mark the clock as MAY_BE_LEAKED
It is freed in gst_deinit(), but otherwise it is leaked.
2019-07-01 11:51:46 +00:00
Jordan Petridis
84512152c1
Run gst-indent through the files
This is required before we enabled an indent test in the CI.

https://gitlab.freedesktop.org/gstreamer/gstreamer-project/issues/33
2018-11-28 05:58:53 +02:00
Havard Graff
c6e5f59b2c systemclock: pre-calculate the ratio for multiplying the perf-count on win
Saves a lot of computations.
2018-11-06 10:39:05 +01:00
Tim-Philipp Müller
2db8e3705f Update for g_type_class_add_private() deprecation in recent GLib
https://gitlab.gnome.org/GNOME/glib/merge_requests/7
2018-06-24 12:49:14 +02:00
Sebastian Dröge
70104857b0 systemclock: set_default() clock parameter can be NULL 2017-12-20 18:56:23 +02:00
Sebastian Dröge
daa98fc02a gst: Don't ref_sink() GstObject subclasses in instance_init/constructor
This is something bindings can't handle and it causes leaks. Instead
move the ref_sink() to the explicit, new() constructors.

This means that abstract classes, and anything that can have subclasses,
will have to do ref_sink() in their new() function now. Specifically
this affects GstClock and GstControlSource.

https://bugzilla.gnome.org/show_bug.cgi?id=743062
2017-05-17 10:40:37 +03:00
Thibault Saunier
a87b4551a6 Port gtk-doc comments to their equivalent markdown syntax
Modernizing our documentation and preparing a possible move to hotdoc.
This commits also adds missing @title metadatas to all SECTIONs
2017-01-27 16:36:38 -03:00
Sebastian Dröge
149127b755 systemclock: Improve GstPoll handling and don't check for impossible errno values
Also just read/write control every time, GstPoll is optimized by itself
already to only do I/O if switching between empty and one byte.

https://bugzilla.gnome.org/show_bug.cgi?id=750397
2016-06-29 21:21:04 +02:00
Stian Selnes
2b0ff13d07 systemclock: Fix wait/unschedule race
Fixes a race where an entry is set to BUSY in
gst_system_clock_id_wait_jitter() and is UNSCHEDULED before
gst_system_clock_id_wait_jitter_unlocked() starts processing it. The
wakeup added by gst_system_clock_id_unschedule() must be cleaned up.

Two stress tests are added. One test that triggers the specific issue
described above. The second stresses the code path where a wait is
rescheduled because the poll returned early.

https://bugzilla.gnome.org/show_bug.cgi?id=761586
2016-02-10 08:59:33 -03:00
Thiago Santos
77a98d98cb systemclock: handle unschedule of late entries
If the clockentry is too late and is unscheduled before it gets
a change to detect its lateness the wakeup count and the poll are
used but never properly cleaned up. This leaves it in a dirty state
that is going to mess with the next clock entry waiting requests.

https://bugzilla.gnome.org/show_bug.cgi?id=761586
2016-02-10 08:59:33 -03:00
Florin Apostol
f0e94b4cdf systemclock: fixed race condition in handling alarms
When choosing the first entry from the list, gst_system_clock_async_thread
must set the entry state to busy before releasing the clock lock. Otherwise
a new entry could be added to the beginning of the list and
gst_system_clock_async_thread will be unaware and keep waiting on the entry
it has already chosen.

Also improved messages about expected state and bumped them to ERROR level
to detect unexpected state changes.

https://bugzilla.gnome.org/show_bug.cgi?id=760757
2016-01-20 13:47:20 +02:00
Heinrich Fink
d59022f508 systemclock: Use mach_time on Apple platforms
On iOS/OSX g_get_current_time was used by default. However, mach_time is
the preferred high-resolution monotonic clock to be used on Apple
platforms.

https://bugzilla.gnome.org/show_bug.cgi?id=758012
2015-11-13 09:23:44 +01:00
Sebastian Dröge
154eefecc9 Don't compare booleans for equality to TRUE and FALSE
TRUE is 1, but every other non-zero value is also considered true. Comparing
for equality with TRUE would only consider 1 but not the others.

Also normalize booleans in a few places.
2014-12-01 09:51:37 +01:00
Nicolas Huet
00bcd94723 systemclock: fix multi-thread entry status issue
Running two threads, one executing the timer and one unscheduling it, the
unscheduled status set by the second thread is sometimes overwritten by the
first one.

https://bugzilla.gnome.org/show_bug.cgi?id=737999
2014-10-06 15:58:42 +03:00
Evan Nemerson
5abc82e9f3 introspection: Assorted minor introspection and documentation fixes
https://bugzilla.gnome.org/show_bug.cgi?id=732534
2014-07-01 09:03:41 +02:00
Tim-Philipp Müller
6eb6d9ec38 docs: remove outdated and pointless 'Last reviewed' lines from docs
They are very confusing for people, and more often than not
also just not very accurate. Seeing 'last reviewed: 2005' in
your docs is not very confidence-inspiring. Let's just remove
those comments.
2014-04-26 21:21:51 +01:00
Tim-Philipp Müller
e30eab99a2 systemclock: add Since markers for new API 2013-11-11 16:47:06 +00:00
Wim Taymans
02b64ee03b systemclock: Add gst_system_clock_set_default
Used for setting the default system clock that is obtained through
gst_system_clock_obtain(), which is sometimes needed for unit
testing.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=711269
2013-11-11 12:25:14 +01:00
Руслан Ижбулатов
e745a2bcf0 clock: Do use HAVE_CLOCK_GETTIME
Fixes #697549
2013-04-09 20:33:27 +02:00
Tim-Philipp Müller
666c8c11c6 Fix FSF address
https://bugzilla.gnome.org/show_bug.cgi?id=687520
2012-11-03 20:44:48 +00:00
Tim-Philipp Müller
c0c79188ca bus, clock: make sure these never have a floating ref
Clear the initial floating ref in the init function for
busses and clocks. These objects can be set on multiple
elements, so there's no clear parent-child relationship
here. Ideally we'd just not make them derive from
GInitiallyUnowned at all, but since we want to keep
using GstObject features for debugging, we'll just do
it like this.

This should also fix some problems with bindings, which
seem to get confused when they get floating refs from
non-constructor functions (or functions annotated to
have a 'transfer full' return type). This works now:

from gi.repository import GObject, Gst

GObject.threads_init()
Gst.init(None)

pipeline=Gst.Pipeline()
bus = pipeline.get_bus()
pipeline.set_state(Gst.State.NULL)
del pipeline;

https://bugzilla.gnome.org/show_bug.cgi?id=679286
https://bugzilla.gnome.org/show_bug.cgi?id=657202
2012-07-09 13:09:45 +01:00
Raimo Järvi
63234a9dab gst: Fix compiler warnings on mingw-w64
https://bugzilla.gnome.org/show_bug.cgi?id=675525
2012-05-09 09:35:35 +02:00
Wim Taymans
eb84682e92 clock: make more stuff private
Expose methods to get and set the timeout because subclasses uses this.
2012-02-27 09:11:36 +01:00
Wim Taymans
8909205b85 systemclock: make more stuff private 2012-02-27 09:11:36 +01:00
Tim-Philipp Müller
2c8c44976f Replace deprecated GStaticMutex with GMutex
https://bugzilla.gnome.org/show_bug.cgi?id=662207
2012-01-22 22:44:59 +00:00
Tim-Philipp Müller
13d91d1f6c Use recent GLib API unconditionally now that we depend on the latest GLib 2012-01-22 01:25:22 +00:00
Tim-Philipp Müller
a1daf846f3 Merge remote-tracking branch 'origin/master' into 0.11
Conflicts:
	gst/gstobject.h
	libs/gst/check/gstcheck.h
	libs/gst/controller/gstcontroller.c
	plugins/elements/gstidentity.c
	tools/gst-xmlinspect.c
2011-12-04 15:38:09 +00:00