Commit graph

583 commits

Author SHA1 Message Date
Wim Taymans 7a9dfc188a jack: improve midi buffer handling
nframes in the midi buffer should be set to the current cycle
buffer_size and it should restrict the timestamps that can be set on the
midi events.

Keep the last max_frames around in a globals so that we can use it to
set the midi buffer to the default size.

Return NULL when we do jack_port_get_buffer() with larger nframes than
the current cycle buffer_size, just like JACK. Otherwise this could
result in a crash when we try to mix more than the available buffer
space.

Check and reset the midi buffer better. Check if the MAGIC is still ok.
jack_midi_reset_buffer() should restore the MAGIC and other values.
2024-03-12 16:41:59 +01:00
Wim Taymans ca4f9d4989 jack: set the output buffer size correctly
The output buffer size is always the current cycle buffer_size.
The size that is give by the JACK API is only used to restrict the
number of mixdown samples or midi offsets.

Fixes #3892
2024-03-12 15:53:02 +01:00
Wim Taymans 1e92ecea53 jack: fix multiple midi input ports
On the midi input ports, do the same trick as on the output ports:
first convert the midi to JACK and then copy the whole buffer to the
port specific storage.

This makes it possible to have a different midi buffer per port and
allow multiple threads to get the buffer concurrently.

Fixes #3901
2024-03-08 16:31:00 +01:00
Wim Taymans 06f63f489a node: add node.sync-group and node.sync
node.sync-group can contain a list of strings. When a node in the graph
sets node.sync = true, it will be scheduled with all of the other nodes with
common node.sync-group strings. By default all nodes are placed in
group.sync.0 except the freewheel and dummy driver.

Use this to ensure that all nodes are grouped under the same driver
(that is not the freewheel and dummy driver) as soon as the transport is
started so that the transport is visible to all nodes from the same
sync-groups. We also don't deactive the sync-group anymore for the node,
even if the transport is stopped, to avoid driver changes and transport
jumps.

When the node that activated the sync/transport is destroyed, things are
restored to their original state. Note that this is different from JACK
where starting the transport outlives the application and always needs
to be explicitly stopped again. We can't really do this (by default) because
it leaves the graph in an unnatural state with all devices in sync.

The reason for the node.sync-group is that it is possible to still have N
different subgraphs with a separate transports by manually specifying
the node.sync-group.

It's also slightly different from the node.group, that is always active.
The sync-group is something you only want to enable in specific cases
because it groups drivers together and enables adaptive resampling etc.

It's also possible to place this option in the jack.conf file to
automatically sync all devices and apps as soon as a jack app is started.

Fixes #3850
2024-02-29 18:04:05 +01:00
Wim Taymans d063ab7322 node: use new node.transport property to start/stop transport
Instead of modifying the driver activation to start/stop the transport,
use a property on the node and let the server handle the change.
2024-02-29 17:45:28 +01:00
Wim Taymans 94d19f2673 jack: when leaving freewheel, set property to empty string
Setting it to NULL will remove it from the properties and will not
send the updated property to the server, keeping things freewheeling
forever.
2024-02-28 18:53:52 +01:00
Wim Taymans 66792c1e77 jack: handle freewheel property a little better
Don't just overwite the node.group property when changing the freewheel
thate but append the frewheel group and remove it again to preserve
the original node.group.
2024-02-28 16:39:03 +01:00
Wim Taymans 1b407d1c6d jack: FORCE_RATE should just contain the rate 2024-02-26 17:04:21 +01:00
Wim Taymans bb887cd5c5 jack: set global_mix safely
Keep track of the active number of mixer ports and update the global mix
io in sync with the data thread because that is where we will check the
state of the global mix io.

This is mostly important for output ports. When removing all links from
an output port, we first will clear all the mixer io and then remove the
global mixer with client_node_port_set_mix_info(). If we don't clear the
io before that, the data thread will be using that buffers as they are
cleared.

See !1915
2024-02-21 12:40:00 +01:00
Wim Taymans c58e187590 jack: sync threads by pausing the core
When we clear the port io, pause the core until the invoke call
completed. This way we don't start processing other messages until we
have safely removed the port io.

Normally, when clearing a link on a port, first the mix io will be set
to NULL and then the format will be cleared, which clears the buffers
as well. By delaying the processing of the format clear until the io
is removed from the data thread we avoid taking away the buffer memory
from the processing thread prematurely.

When creating a link, first the format and buffers are configured and
then the io is set, which should be safe in all cases.

See !1915
2024-02-21 10:39:12 +01:00
Wim Taymans f1a6fabb6c meson: add options to set server and client RT priority
Make a rtprio-server and rtprio-client option. Leave the server
priority by default to 88 but lower client priority to 83. JACK
does something similar by setting clients to rtprio-server - 5.

Make module-rt use the client priority by default and bump the server
priority explicitly in the config file.

Leave the pulse-server to the default rtprio-client, there is no reason
to lower this any further because it is really just a regular client.

Bump the ffado packetizer thread to rtprio-server + 5 because that is
also what JACK does.

88 is still much higher than the value of 60 that JACK uses in
Fedora but now this is at least configurable.
2024-02-15 11:53:32 +01:00
Wim Taymans a9c0eb993e jack: add jack.other-connect-mode property
Add a new property that controls how connections between other ports are
handled. This can be used to block jack apps from connecting or
disconnecting port they don't own.
2024-02-14 15:09:55 +01:00
Dimitrios Katsaros e84184f28f Jack: Added missing lock to jack API call 2024-02-08 10:20:12 +01:00
Dimitrios Katsaros 44b8a03c40 Jack: Fix jack_remove_property(ies) to use proxy id
These functions were using the object serial as the object id
2024-02-07 14:46:48 +01:00
Wim Taymans 07f7bda1fe jack: fix version check 2024-01-31 10:36:05 +01:00
Wim Taymans f0304f45a9 jack: make sure jack clients are ALWAYS_PROCESS
We need this flag to be true otherwise, we will try to hide ports from
JACK clients that suspend (while still active).

See #3416
2024-01-24 12:47:32 +01:00
Wim Taymans 1ad0ea3e56 jack: improve running check
We already checked if a node is_jack when it appeared in the registry
with the client.api property, so don't check again with ALWAYS_PROCESS
when the node properties changed.

When we get a node info about our own state, we can use the active state
of the node to decide if we are running or not.

See #3794
2024-01-24 12:32:44 +01:00
Daniel Struebig 281451db85 pipewire-jack: remove unused field graph_callback_pending
* The field `graph_callback_pending` in the struct `client` in pipewire
  jack seems to be unused and referenced nowhere else in the repository.
2024-01-24 09:34:37 +01:00
Wim Taymans fee0f95737 jack: handle -ENOENT from the core
This means that we tried to do something on a proxy that was destroyed
on the server and we should just ignore the error.
2023-12-14 11:10:52 +01:00
Wim Taymans 74f48a2bec jack: improve current_usec calculation
We should not use nsec from the clock as the current_usec because
current_usec is supposed to be an idealized time when the wakeup would
have happened and nsec is when it actually happened.

Instead use next_nsec and subtract the rate corrected period from it to
get the idealized current_usec.

We can still use nsec to calculate the elapsed time since the wakeup and
be sure that it is always in the past.
2023-12-12 13:08:11 +01:00
Wim Taymans 9daca346a7 jack: allow OSC messages inside JACK MIDI
Some JACK clients place OSC messages in MIDI buffers. Try to detect the
OSC messages and mark the control as OSC.

Also allow OSC control to be converted to JACK MIDI.

This should make things work better with native PipeWire clients that
handle MIDI and OSC.
2023-11-27 17:00:39 +01:00
Wim Taymans 3376b96f2a jack: handle concurrent jack_port_get_buffer()
Ardour calls jack_port_get_buffer() from multiple threads. For audio
buffers this will result in mixing the input samples into the target
buffer and there is no window for having a corrupt buffer.

For MIDI, there is a problem because we need to convert from and to
PipeWire MIDI and while we do that from multiple threads, the midi
buffer can be incomplete or corrupt.

Fix this by building the intermediate POD to a thread-local scratch area
and then copy it to the target buffer. If this is done from multiple
threads there is no moment where incomplete data can be seen in the
target buffer.

Make the complete midi-scratch buffer thread_local so that we also avoid
a race when converting midi data from a foreign port.

When we write into the scratch buffer when mixing and converting input
midi data, we also avoid a race there.

Fixes #3632
2023-11-22 16:16:30 +01:00
Wim Taymans f324f0e8e1 jack: optimize one buffer case
The normal case is using 1 buffer port port so we can avoid a
queue/dequeue pair of operations.
2023-11-22 13:20:52 +01:00
Wim Taymans e8c6c78982 jack: fix crash with fastpath debug
Don't deref p in the trace log because it can be NULL.
Don't try to dequeue a buffer when there are none. Improve some debug.

See #3632
2023-11-21 17:09:08 +01:00
Wim Taymans b3ee9942f6 jack: enunerate Latency only for DSP ports
We don't really include the other ports in the API.
2023-11-20 18:17:31 +01:00
Wim Taymans 0fe7bd2780 jack: improve transport and times handling
Avoid reading from the activation directly to get cycle times but copy
the relevant fields of the clock when the cycle starts. Use the unique id
to get a consistent copy of the data.

This avoids some stay frames and values in jack_showtime.
2023-11-20 17:20:39 +01:00
Wim Taymans 935093e4a2 jack: fix compilation with -UFASTPATH 2023-11-15 09:28:08 +01:00
Wim Taymans e2598b3242 jack: Add jack_port_t* <-> object helpers
Improve get_buffer debug.
Add some extra checks for the type before we try to use the object as a
port.
Set latency range to 0 when called with wrong port. Ardour seems to call
into us with ports from a previous jack_client..
2023-11-10 12:07:52 +01:00
Wim Taymans ee811307cd jack: make 0 an invalid object type
So that we don't accidentally think uninitialized objects are ports.
2023-11-10 11:26:06 +01:00
Wim Taymans ea412a5628 jack: fix midi events from peer port
When we get a midi buffer directly from one of our peer ports, we need
to convert it to a jack midi buffer.

Note that this previously returned NULL because of the size check of the
midi buffer, which was likely much smaller than the frames argument.

This fixes midi event recording preview in ardour.
2023-11-08 12:59:33 +01:00
Théo Lebrun 0e44f5ef97 jack: fix PW_VERSION_* constant used with pw_*_events structs
PW_VERSION_NODE is 3 while PW_VERSION_NODE_EVENTS is 0, I am unsure if
it could have caused issues. Same thing with PW_VERSION_PORT &
PW_VERSION_PORT_EVENTS.

I have not seen code checking this version number.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2023-11-02 12:42:30 +01:00
Wim Taymans b8a8e00a80 jack: do sync when starting client
do a sync when starting up client and sync when creating a new proxy so
that we get all the proxy updates before the client is opened.

This ensures all ports are enumerated correctly.

Fixes #3618
2023-11-01 18:42:12 +01:00
Wim Taymans 733cf7835e jack: add jack_set_sample_rate() extension 2023-10-24 11:08:49 +02:00
Wim Taymans b92b66cf5b jack: refactor function to get buffer data
Split out the function to get the buffer data.
Don't process mix with invalid id.
Check global_mix and io before processing the mix.
2023-10-19 16:06:14 +02:00
Wim Taymans 6ef8d31f55 jack: only set io in NEED_DATA after complete
Don't set the port io to NEED_DATA in prepare_output because this
might be called when we get the data from an input port that is linked
to out output port.

See #3514
2023-10-19 12:29:00 +02:00
Wim Taymans 13f52f4297 jack: don't require global-mix in prepare_output
We can directly use the port io, which is always available. This ensures
the mix->io status is set to NEED_DATA even when there is no global
mix.

This reverts part of 56786aedc4

See #3514
2023-10-19 12:20:58 +02:00
Wim Taymans 69d0f586b2 jack: use a separate thread for notify
Some jack clients will take a lock before doing IPC and then will
take the same lock in a notify callback. This prevents the IPC from
progressing and causes a deadlock.

Make a separate thread to dispatch the notify so that we don't block the
IPC in any case.

Fixes #3585
2023-10-17 13:05:19 +02:00
Wim Taymans 40cc2f7068 jack: don't wait for mix_set_io
Some jack clients like to lock the process function and so we can't be
sure we will deadlock while we try to wait for the data-loop.

Instead, don't sync with the data-loop when setting the mix-io, it will
happen later when it is possible. Queue a free operation of the memmap
after the mix_set_io if we need to clean up.

See #3585
2023-10-17 13:01:53 +02:00
Wim Taymans 7d5b809b19 jack: make option to make input writable 2023-10-16 11:40:03 +02:00
Wim Taymans 8f2ee0a29c Revert "jack: use a private writable mapping on input"
This reverts commit 6fefd49a8a.

We can't use PRIVATE because mmap docs say that we then might not see
changes in the data anymore from other processes.

Fixes #3575
2023-10-16 09:36:16 +02:00
Wim Taymans 6fefd49a8a jack: use a private writable mapping on input
See #3571
2023-10-14 12:23:39 +02:00
Wim Taymans 11320cf203 tweak number of buffers
In most cases we can use just 1 buffer.

The alsa-pcm-source needs at least 2 buffers so increment the min
limit.
2023-10-13 14:00:29 +02:00
Wim Taymans 6eb17393bf jack: remove fixed buffer size limit
Use the quantum_limit as the max buffer frames and allocate the ports
with the right samples at the end.
2023-10-13 13:04:28 +02:00
Wim Taymans bafa890aef jack: schedule all jack clients in the same group
Always group the jack clients together to avoid them using different
drivers (and transport/timing).

See #3562
2023-10-13 09:43:00 +02:00
Wim Taymans 45bab72abc jack: fix midi events in destination buffer
Don't fix up the midi events in the (read only) input buffer but
after we have converted it into the JACK midi buffer.

See #3560
2023-10-11 10:56:19 +02:00
Wim Taymans fcde479a82 env: PIPEWIRE_QUANTUM now uses FORCE_RATE and FORCE_QUANTUM
Make it force a RATE and QUANTUM on the graph. The non-force options
can already be done with PIPEWIRE_RATE and PIPEWIRE_LATENCY.
2023-10-10 15:10:19 +02:00
Wim Taymans 4568d90565 jack: sync after setting metadata
Do a do_sync after setting the metadata to ensure the messages are
flushed to the server and processed. Fixes an issue where jack_property
would exit before the messages are flushed and so nothing happens.
2023-09-19 12:44:59 +02:00
Wim Taymans bb10a7cb98 jack: setting the Latency to NULL clears the latency 2023-09-15 11:37:58 +02:00
Jan Alexander Steffens (heftig) fa7cd96b6e pipewire-jack: Disable LD_LIBRARY_PATH when libjack is in libdir
This avoids prepending /usr/lib to the LD_LIBRARY_PATH, which supersedes
DT_RUNPATH and can cause library confusion.
2023-09-15 08:49:36 +00:00
Jan Alexander Steffens (heftig) 43db03909b ci: ShellCheck preprocessed scripts separately
Change the shellcheck job so that we configure the build and check the
preprocessed versions of the scripts, not the bare ones, which might not
be syntactically valid yet.
2023-09-15 08:49:36 +00:00