Commit graph

47 commits

Author SHA1 Message Date
Rui Matos
752de866ae spa: node-driver: Expose the clock id as param properties 2025-10-28 07:18:59 +00:00
Carlos Rafael Giani
14b242c737 node-driver: Make sure the discont clock flag does not remain set forever
If the timer was canceled, the discont flag needs to be set. But in the
next cycle, unless the timer was canceled again, that flag should not
remain set.
2025-07-18 10:52:13 +02:00
Carlos Rafael Giani
bb022c1b84 node-driver: Handle realtime clock modifications
If the user alters the realtime clock (for example by using the "date"
command in the shell), and the node driver uses the realtime clock as
the timerfd clock, then the scheduled graph cycle invocation may not
take place, or may take place much later than planned, because the
timestamp that was passed to spa_system_timerfd_settime() is now invalid.
Configure the timer to automatically be canceled if the realtime clock
is modified so that the graph cycle can be rescheduled with an updated
timestamp that is actually usable with the altered realtime clock.
2025-07-17 13:13:34 +00:00
Wim Taymans
f2452a6af7 spa: some more invoke -> locked calls 2025-05-29 10:17:16 +02:00
Wim Taymans
d4515378e7 node-driver: 5 seconds of freewheel timeout is enough
We retry to run the graph every 5 seconds in case it didn't complete. A
10 seconds timeout feels quite long.
2024-07-12 12:25:18 +02:00
Wim Taymans
42096de3cc node: add a clock XRUN_RECOVER flag
Make a new flag that is set when the process function is called because
of a recover from a graph xrun.

Use this flag in the freewheel driver to detect a recover and to avoid
scheduling a new timeout. We should schedule a new timeout only when the
process function was called after completion.

This fixes export in ardour some more when the initial driver timeout
didn't complete (when, for example, some nodes were still starting up).
2024-07-12 12:21:59 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Samuel Thibault
7ee8192ce9 spa plugins: Include Linux headers on Linux only 2024-03-25 14:53:14 +00:00
Pauli Virtanen
7d0ca2d103 spa: node-driver: always put CLOCK_MONOTONIC values to clock->nsec
When timer is not using monotonic clock, apply clock offset to translate
the time values to the monotonic clock when putting them to spa_io_clock
nsec fields.

Get appropriate clock offset by smoothed filtering.  The parameters here
keep the offset jitter < 10ns or so.

As monotonic/boottime/realtime all contain adjtime(), there generally is
no drift in the offset here, so just averaging should be fine.

Also fix using wrong timer clock when freewheeling.
2024-03-07 20:04:54 +02:00
Wim Taymans
532bc878f4 spa: use errno values in warnings
Propagate the errno values from syscalls and use them in the warning
messages to give info about what is going on.
2024-02-12 10:01:22 +01:00
Dmitry Sharshakov
bb2f793598 node-driver: suggest user to check clock device permissions 2024-02-12 08:14:10 +00:00
Barnabás Pőcze
a834da988c spa: support: add missing static 2024-02-05 20:01:21 +01:00
Arun Raghavan
3958bed5c3 node-driver: Log when we resync 2024-01-29 12:08:15 -05:00
Dmitry Sharshakov
ca25066874 node-driver: allow fractional resync-ms 2024-01-24 20:52:08 +03:00
Wim Taymans
e7888d4ccc support: add resync.ms option to node.driver
Move some of the tracking code for the DLL to where it is used.

Add resync.ms (default 10) option at which we give up rate adjusting
and instead do a hard resync. This results in a jump in the position
of the graph clock.
2024-01-24 17:53:15 +01:00
Wim Taymans
15908328d1 support: fix freewheel timeout in node-driver
When freewheeling we will immediately schedule a new graph cycle when we
get a process call because the graph completed.

When the process call is not done, because of some xrun or
because some node was removed that causes the graph to fail completion,
The next cycle will happen after a timeout.

This timeout was calculated as the ideal wakeup time (after a quantum of
time) and would accumulate for each timeout. The result is that the
timeout ended up far in the future and would stall the freewheel driver
for a long time.

Fix this by always setting the next timeout to wakeup time + freewheel.timeout
seconds. Also add a config property for the timeout (10 seconds, like
jack2 by default).
2024-01-10 11:59:10 +01:00
Dmitry Sharshakov
5edd3f240b node-driver: open PHC as readonly
RW access is usually denied to a user unit. RO might be as well but it's more safe to make /dev/ptpX just user-readable
2023-12-20 09:35:22 +00:00
Sebastian Jaeckel
be69f029ac node-driver: use interface name to get PHC index of PTP clock
The user may not know which is the active PHC index of a bonded
interface. We can now specify the interface name instead of a device
as the clock.interface property and query the interface about the
active PHC index.
2023-10-12 17:32:50 +00:00
Sebastian Jaeckel
f7fa7df3ee node-driver: warn if the specified clock can't be opened 2023-10-12 17:32:50 +00:00
Wim Taymans
2c5cdb57e5 Revert "node-driver: ensure position doesn't jump"
This reverts commit 8249fa3cbf.

See #3544
2023-10-05 15:22:30 +02:00
Samuel Thibault
f9559d2e83 node-driver: Cope with missing CLOCK_BOOTTIME 2023-09-24 15:11:52 +00:00
Wim Taymans
8249fa3cbf node-driver: ensure position doesn't jump
Make sure that the position only advances in the running state.

When we are not following a clock we can simply increment the position
with the duration every time we run.

If we are following a clock. Take the elapsed time of the clock into
account when aligning to the position.

Fixes #3189
2023-09-21 09:52:53 +02:00
Jonas Holmberg
00ca590ff6 node-driver, null-audio-sink: Fix EAGAIN check
spa_system_timerfd_read() returns -EAGAIN.
2023-09-04 13:24:30 +02:00
Dmitry Sharshakov
f257c3407d node-driver: allow specifying both PHC and ID 2023-06-20 06:51:30 +00:00
Wim Taymans
78b8e1af57 node-driver: fix position calculation
Set the driver node position based on the current time when we
start and keep incrementing it with the previous duration.
2023-03-24 17:34:14 +01:00
Wim Taymans
5ea3c10dca support: sync timers with data loop
Start and stop the timers in the data_loop. Otherwise we might be trying
to stop a timer while the data loop is starting it and we end up with
"ready non-active node" messages.
2023-03-24 17:24:56 +01:00
Wim Taymans
7b6680ba57 plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
2023-03-24 11:36:15 +01:00
Wim Taymans
6e8625cf96 node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and
rate with the new targets.
2023-03-23 18:39:27 +01:00
Gleb Popov
a83d3b0249 Fix node-driver.c build on FreeBSD. 2023-03-15 16:53:41 +00:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
206df03c27 support: Handle supported clocks with timerfd
We don't need to follow a clock when it is one of the supported clocks
for timerfd.
2023-02-01 16:19:14 +01:00
Wim Taymans
e3b358ac8b support: add support for other clocks
Add support for using other clocks.
clock.id can be used to set one of the system clocks.
clock.device can be used to open a clock device such as a PTP clock
device.
Use a dll to track the progress of non-monotonic clocks.
2023-02-01 15:54:54 +01:00
Wim Taymans
f44d55f6c2 handle read from timerfd correctly
When reading the timerfd gives an error, we should return right away
because the timeout did not happen.

If we change the timerfd timeout before reading it, we can get -EAGAIN.
Don't log an error in that case but wait for the new timeout.
2022-12-09 17:30:31 +01:00
Barnabás Pőcze
60b9d9081b spa: only remove embedded source from data loop from within the loop
Use `spa_loop_invoke()` to invoke a callback on the data loop
to remove an embedded `spa_source` from the data loop.

Embedded `spa_source` objects cannot be safely removed
while the loop is polling without risking potential
use-after-frees.
2022-03-06 18:40:43 +00:00
Wim Taymans
53352c0c81 support: add property to configure clock name
Add a clock.name property on the driver node. By default this is
clock.system.monotonic for the monotonic system clock.
2021-12-10 11:22:23 +01:00
Wim Taymans
f1f5cbc0a6 support: return completion from process
HAVE_DATA|NEED_DATA signals that the graph can continue processing.
OK means that the node will continue asynchronously later. This
is needed to make the dummy driver work as a follower.
2021-09-23 16:36:32 +02:00
Wim Taymans
35194d6de0 node-driver: remove timers when not a driver 2021-07-01 12:28:18 +02:00
George Kiagiadakis
5aa9c95390 node-driver: make the timerfd non-blocking
Relates to #1377
2021-07-01 11:52:28 +03:00
Wim Taymans
46ef88e520 spa: save the old change_mask and restore when emitting full
When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
2021-05-27 15:21:44 +02:00
Peter Hutterer
cdfd50e166 spa: add spa_atob() to convert a string to a boolean
This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
2021-05-18 22:18:56 +10:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Wim Taymans
a80ec36ad5 node-driver: run as fast as possible in freewheel mode 2021-05-07 11:50:55 +02:00
Wim Taymans
888612dc0f conf: add freewheel driver
Add freewheel driver and enable freewheel mode on it.
2021-05-07 09:03:34 +02:00
Wim Taymans
5c41131d6d node-driver: support node.freewheel property
To activate freewheeling when initializing
2021-05-07 09:03:34 +02:00
Wim Taymans
6eaf8d6921 spa: remove property, we don't implement a getter 2020-10-28 10:51:08 +01:00
Wim Taymans
1b7d052098 support: remove useless assignment 2020-10-16 13:11:27 +02:00
Wim Taymans
2220d5b9b6 support: add dummy driver
Add a dummy driver node with high priority. All nodes not linked
to a device node will be linked to this when they require a driver.
2020-04-27 20:21:31 +02:00