1
Fork 0
Commit Graph

565 Commits

Author SHA1 Message Date
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
Wim Taymans 6abc6e6693 jack: mark client active a little earlier
So that we get all the notifications queued and emitted when we complete
the activation.
2023-09-13 17:48:28 +02:00
Wim Taymans b094057b0b handle NULL latency param
Fixes #3504
2023-09-13 11:13:48 +02:00
Wim Taymans 56786aedc4 jack: safely update the mixer io areas
The buffer io area is used to enable/disable a port and should be
synchronized with the processing loop. Use invoke to safely update the
mixer io area.

Keep track of the number of mixers on a port and clear the global mixer
buffer io when there are none. Check and use the global mixer io when
processing output to avoid using an inactive output without buffers and
crashing.

Fixes #3506
2023-09-13 10:59:35 +02:00
Wim Taymans 18f29bd840 jack: make sure we emit port registration events
When we activate, emit the port registration events of our own port,
even when they were suppressed (and marked registered) when we created
them. This is what JACK2 does as well.
2023-09-12 15:54:34 +02:00
Wim Taymans 42b23bddc3 jack: always emit buffer frames after activate
This seems to be what JACK2 does as well.
2023-09-12 15:54:34 +02:00
Wim Taymans c8c2f5902c jack: emit connect unregister before port unregister
When we deactivate a client, first emit the connection unregister
and then the port unregister callbacks.
2023-09-12 15:54:34 +02:00
Wim Taymans f404168739 jack: mark object registered when emit is suppressed
When we don't manage to emit the notify, still mark the object as
registered. Otherwise we might not emit the unregistered
notify later on.

This usually happens when a client connects and the notifies are
suppressed for all the objects in the graph. When they later disappear
we do want to emit the unregistered notify.
2023-08-30 18:23:07 +02:00
Wim Taymans 001c6e1cc1 jack: support jack_port_tie
We can't really do zero copy because our downstream peer does not have
access to the memfd of our upstream peer. Instead, just memcpy the
data for now.
2023-08-25 14:28:38 +02:00
Wim Taymans c41c812325 jack: make sure we can always find our own ports
find_port_by_name() is used to find our own ports before they become
visible so make sure we can always find them.

Fixes #3485
2023-08-24 19:28:57 +02:00
Wim Taymans 88e4a69765 jack: emit latency notify when buffer_frames changes
When the buffer frames change, make sure we emit a latency recalculation
even if we don't have a buffer_size callback.

Remove the unused GRAPH notify.

Protect ringbuffer writes to the notify queue with a lock because we
can't know what thread they execute in.

Make a new TOTAL_LATENCY notify type to trigger a complete latency
recalculation.
2023-08-23 17:28:24 +02:00
Wim Taymans cbf97d4b00 jack: handle node.always-process = false jack nodes
Node that have the node.always-process = false property do not conform
to the jack API because they will be suspended even when they don't
inactivate themselves. Don't hide the ports for those clients when
inactive.

Fixes #3416
2023-08-07 19:58:20 +02:00
Wim Taymans 31f91ce9f4 jack: ports become visible when the registration is queued
As soon as the port registration is queued (but not yet emited) the port
becomes visible.

See #3416
2023-08-07 19:57:01 +02:00
Sandro Bonazzola a1c109772b Update FSF address 2023-08-07 09:36:59 +00:00
Wim Taymans 0055cc613d jack: always do graph update when link changes
Don't make a special event but do the graph change callbacks when
a link was notified. Bundle all graph updates together when we can.
2023-08-03 11:43:42 +02:00
Wim Taymans da464853e5 jack: handle port registration events for jack clients
The jack client API expects the ports to unregister when a jack client is
deactivated and to register when it is activated. We use pause/resume
for deactivate/activate and don't really destroy the ports.

Track the state of the node (client) and emit port registration when it
changes state. Also make sure we don't emit a port registration when the
node is deactivated.

Fixes #3260
2023-08-02 17:30:35 +02:00
Nedko Arnaudov 1cb17c05e9 Use 0.3.PWVER for soname versioning, instead of 0.PWVER.0 2023-08-01 11:08:56 +02:00
Wim Taymans 0501ef165a spa: add atomic.h and port macros to it 2023-07-13 12:25:22 +02:00
Wim Taymans e86a770349 private: we only ever decrement activation with 1 2023-07-13 12:18:11 +02:00