Commit graph

471 commits

Author SHA1 Message Date
Barnabás Pőcze
7aae9a3e8b pipewire-jack: indent with tabs to avoid clang-tidy warnings 2023-02-25 20:48:45 +01:00
Barnabás Pőcze
0e0a2627aa treewide: print pthread_t as a pointer
On glibc, `pthread_t` is `unsigned long int` while on musl
it has a pointer type. To avoid format string warnings,
cast it to `void *` and use the `%p` format specifier.
2023-02-25 20:45:28 +01: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
0511970537 jack: use 32 bits for frame times
JACK uses 32 bits for frame times so truncate our 64 bits position
to get the wraparounds right.
2023-02-16 10:16:36 +01:00
Wim Taymans
274b63e972 jack: improve frame to and from time functions
Also support times and frames before the current one by doing a signed
diff.
Also take into account the rate adjusted period time.
2023-02-09 16:44:47 +01:00
Wim Taymans
03cb7f3549 jack: make jack.merge-monitor default true
Make jack.merge-monitor true by default because this is what JACK also
does.

Add an exception for Mixxx because that makes it easier to select the
capture/monitor ports.

Fixes #1760
2023-01-25 09:48:28 +01:00
Wim Taymans
95f87301c7 clarify PIPEWIRE_NODE
PIPEWIRE_NODE is mapped to TARGET_OBJECT so it contains the serial or
the node name.
Make sure pw-stream maps this to TARGET_OBJECT.
Make JACK use the PIPEWIRE_NODE for serial or node.name.
2023-01-10 17:11:43 +01:00
Wim Taymans
97aafe2234 fix use_buffers checks
We can set 0 buffers even if there is no format.
Return -ENOSPC when too many buffers are set.
2023-01-10 12:30:25 +01:00
Wim Taymans
50dad68eb4 midi: fix midi event sorting
The high bit is always 1 so we can use only the lower 3 bits for the
priority.
2022-12-13 16:41:20 +01:00
Wim Taymans
480902eb3a jack: sort midi events better
Use the same sorting as ardour for midi events with the same timestamp
so that the order is:

Controller messages > Program Change > Note Off > Note On >
    Note Pressure > Channel Pressure > Pitch Bend

Fixes #1868
2022-12-13 13:01:26 +01:00
Wim Taymans
0c50ccac87 jack: only process valid ports
In the data-loop we can check the valid flag safely to check if ports
are valid for processing.

See #2863
2022-12-02 09:46:05 +01:00
Wim Taymans
8e9b136b10 jack: use node.passive to make passive links
Let the node.passive property make passive links. PIPEWIRE_LINK_PASSIVE
overrides the node property.

Add some nice tweaks for qsynth so that it suspends and fades out
nicely by default.
2022-11-21 16:02:30 +01:00
Wim Taymans
0918899bf8 client-node: send the mix_info before Buffer IO
We don't always need to send buffers to a remote port, when the port
is an output port, all the mix ports use the same buffers. This means
that when we add another link to a port, we don't get the mix_info
anymore and then we don't know the peer_id and we don't complete the
link and we don't call the connection_callback.

Instead, send the mix_info right before sending the Buffer Io area. We
always do this for all mix io and after we have sent the buffers so this
is a better place.

Fixes #2841
2022-11-20 19:24:01 +01:00
Wim Taymans
518ccdf624 jack: add jack.filter-char to specify the filter character 2022-11-10 17:40:25 +01:00
Wim Taymans
643d95f515 jack: set port valid state safely
When unregistering a port, set the port to invalid first and sync the
data loop so that it will not be used anymore from the data loop.

See #2652
2022-10-20 21:34:01 +02:00
Wim Taymans
1aef910dcc jack: make jack_bufsize adjust the global quantum
Bind to the settings metadata.
Add a property to control if a client will set a temporary or global
quantum whith jack_bufsize.
Make a match rule for jack_bufsize and force a global quantum change.

Fixes #1273
2022-10-20 16:34:47 +02:00
Wim Taymans
f0753ffdf9 jack: improve acquire/drop_rt methods
Instead of calling the default implementation that does not implement
these methods, keep the last thread-utils around in a global and use
that instead.
2022-10-13 12:09:36 +02:00
Wim Taymans
38e3c2be6c jack: client_thread_id() returns NULL
client_thread_id() returns NULL on jack1 and jack2 when the client is
not activated yet, so do the same here.
2022-10-13 12:08:27 +02:00
Wim Taymans
b178d222d5 jack: also implement drop_rt in our custom thread utils 2022-10-13 11:56:28 +02:00
Niklāvs Koļesņikovs
cba334f028 treewide: fix some strict-prototypes Clang warnings/errors
Clang 15 at least with my build configuration emits warnings about
function prototypes that lack argument types. Most notably this
happens with functions that take no arguments which in compiler view
equates to the void type i.e. void f(void) instead of void f(). As I
understand, this will become an error in some future Clang release,
so might as well fix it now.

Since these were discovered not by a linter but by the actual compiler
for my particular build configuration, some f() may have escaped for
now. But at least it's enough to build PipeWire with most optional
features enabled even when -Werror=strict-prototypes is enabled.

For anyone else wanting to have a go at this, these can be upgraded
from warnings to errors by adding -Werror=strict-prototypes to the
custom CFLAGS which probably works with GCC, too, but has only been
done with Clang 15.0.2.

Finally my editor automatically stripped trailing spaces upon saving
the modified files. I assume it's probably not worth keeping those
invisible bytes around but this may have slightly dubious implications
as it did also turn indented empty lines of JACK license header into
regular empty lines.

Signed-off-by: Niklāvs Koļesņikovs <89q1r14hd@relay.firefox.com>
2022-10-12 07:32:47 +00:00
Demi Marie Obenour
400860f63c Add <stdint.h> includes
This is to make the headers standalone.
2022-09-23 15:19:01 +00:00
Wim Taymans
c8ef655b3e jack: group all jack nodes in the same application group
Make sure all jack nodes from the same pid are in the same group.

It is normally not a problem for different JACK clients to live in
different groups and be scheduled by different drivers with different
quantum and rate.

Some applications (like Carla), however, make multiple clients and
expect all of them to use the same quantum and rate. Enforce this by
adding all jack clients to the application jack group.
2022-08-31 16:08:05 +02:00
Tasos Sahanidis
0e847c97c8 jack: Increase JACK_CLIENT_NAME_SIZE
Some devices have really long names, especially when taking localisation
into account due to multibyte characters.
2022-08-20 19:35:39 +00:00
Tasos Sahanidis
7884ff82db jack: Include NULL in return value of jack_client_name_size()
This fixes an assertion failure in PortAudio's JACK backend when the
monitor client name is longer than than JACK_CLIENT_NAME_SIZE.
2022-08-20 19:35:39 +00:00
Barnabás Pőcze
1275fc99df pipewire-jack: do not dereference value from pw_data_loop_get_thread()
`pw_data_loop_get_thread()` returns a `pthread_t` cast to `struct spa_thread *`,
so simply casting it back to `pthread_t` is enough.
2022-08-11 16:50:05 +02:00
Barnabás Pőcze
3f3b70ad83 pipewire-jack: return a zero initialized pthread_t in case of error
When the `client` argument is NULL, return a zero initialized
`pthread_t` object from `jack_client_thread_id()`. Returning
`-EINVAL` can be problematic because even though `pthread_t` is
a typedef for `unsigned long` in glibc, it is still a pointer,
not a numeric identifier. And in musl, it is a typedef to a
pointer, which results in a warning:

  In file included from ../spa/include/spa/support/cpu.h:34,
                   from ../pipewire-jack/src/pipewire-jack.c:40:
  ../pipewire-jack/src/pipewire-jack.c: In function 'jack_client_thread_id':
  ../spa/include/spa/utils/defs.h:274:11: warning: returning 'int' from a function with return type 'jack_native_thread_t' {aka 'struct __pthread *'} makes pointer from integer without a cast [-Wint-conversion]
    274 |    return (val);     \
        |           ^
  ../pipewire-jack/src/pipewire-jack.c:3775:2: note: in expansion of macro 'spa_return_val_if_fail'
   3775 |  spa_return_val_if_fail(c != NULL, -EINVAL);
2022-08-11 16:45:25 +02:00
Wim Taymans
d7da581b9c jack: return error when disconnected
When we are disconnected from the server (EPIPE), don't try to wait for
the result of a sync operation but return the error.

Fixes #2606
2022-08-11 11:04:50 +02:00
Wim Taymans
ab898f8ae6 jack: use context properties for rules
For a JACK client, the context and node is the same. It makes sense to
also run the rules on the context properties so that application
name etc. can be matched as well.

Fixes #2580
2022-08-10 09:52:20 +02:00
Wim Taymans
83e3aba980 jack: clean transport when closing the client
See #2569
2022-08-09 20:55:41 +02:00
Wim Taymans
1cd4655883 jack: add some debug when process is skipped
See #2627
2022-08-08 19:29:09 +02:00
Wim Taymans
aaeafa49c1 fix some printf arguments 2022-07-18 15:39:06 +02:00
Hubert Figuière
86257a0013 jack.pc libraries should only be libjack 2022-07-17 23:12:19 -04:00
Wim Taymans
40552a0e91 jack: only mix when we have input to mix
Avoids a crash when starting ardour6.
2022-07-12 15:10:02 +02:00
Wim Taymans
23984f8790 jack: improve mix function
Avoid many reads and writes to temp buffer.
2022-07-10 21:59:05 +02:00
Wim Taymans
40f50deae9 alsa: remove NoteOn 0-velocity fixup
Pass MIDI events as they are.

JACK requires NoteOn 0-velocity midi events to be patched to NoteOff
events for compatibility with LV2 plugins. Let's do this patchup in
the JACK layer then and add an option to disable it.

It's best to pass the midi messages unmodified and then patch them up
wherever they need patching up.
2022-06-20 15:51:33 +02:00
Barnabás Pőcze
f2c53622d2 pipewire-jack: use jack_client_close() to free client in error path
The client needs to be cleaned up properly, otherwise references
to its storage may remain, which can later result in use-after-frees.
For example, the via the various embedded `spa_hook`s in it.

See #2394
2022-06-04 12:42:44 +02:00
Barnabás Pőcze
c6a5698eac pipewire-jack: check before destroying
Check pointers before calling the destructors (where needed), so that
a not fully constructed `client` object may be passed to `jack_client_close()`.

Furthermore, remove the metadata proxy and object listeners as well.
2022-06-04 12:42:17 +02:00
Barnabás Pőcze
15d5ab2425 pipewire-jack: move client-node setup right after creation
Move the client-node setup code right after the client-node
creation, so that they are close to each other.
2022-06-04 12:42:17 +02:00
Barnabás Pőcze
d7a7d7f738 pipewire-jack: initialize certain members right after allocation
Move the initialization of some of `client`'s members right after
allocation, so that it will be simpler to tear down the client object
even if `jack_client_open()` fails later.

Furthermore, initialize `client::driver_id` to `SPA_ID_INVALID`.
2022-06-04 12:42:17 +02:00
Fabrice Fontaine
85ca67b927 fix detection of reallocarray
Fix detection of reallocarray (e.g. on glibc) raised since commit
0708a39b43

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-05-30 09:33:27 +02:00
Félix Poisot
5daa660a62 jack: replace unmatched atomic store with mutex
Fixes #1867, as this is the only u64 atomic access in the tree

All other accesses to pw_node_activation::sync_timeout are unprotected,
so they must assume lock ownership
2022-05-21 16:55:34 +00:00
Wim Taymans
43fec3ee3b jack: check properties after we configured them
Or else PIPEWIRE_PROPS will not have any effect.
2022-05-04 15:04:33 +02:00
Wim Taymans
c0cf2d802b jack: handle allocation errors better 2022-04-27 09:26:40 +02:00
Wim Taymans
f641e4ecb3 jack: don't wait for activation update
We could do an invoke, wait, then the process could do a jack_connect()
, do_sync and we deadlock. it's probably better to not wait for
completion.
2022-04-26 20:32:25 +02:00
Wim Taymans
838ab996d0 jack: fix a potential deadlock
When some blocking method is performed on the process thread, like
jack_connect() mark the data thread as blocked while we wait for the
thread loop to process the result.

If we then try to do a blocking _invoke from the thread loop on the
data thread, make sure we don't wait for it to complete or else we
deadlock.
2022-04-26 20:15:58 +02:00
Wim Taymans
bb8a0b5e06 jack: only call buffer_size callback after change
Don't call the buffersize callback the first time but only when the
size changed since the last process or get_buffer_size() call.

Fixes #2324
2022-04-23 21:37:45 +02:00
Wim Taymans
61d318125e move PIPEWIRE_PROPS to stream and filter
Make all streams and filters handle PIPEWIRE_PROPS.
The order for applying stream/filter properties is:

1) application provided properties.
2) generic config.
3) match rules.
4) environment variables (PIPEWIRE_PROPS, ...) from generic to
   more specific.
5) defaults.
2022-04-22 09:37:21 +02:00
Wim Taymans
0b96b87331 thread: implement some properties
Make helper method to parse thread properties and add 2 new properties
to control name and stack-size of the thread.
Use properties when creating threads with the default utils.
Use the default thread utils instead of pthread_create so that the
properties are used.
2022-04-18 13:02:27 +02:00
Wim Taymans
5f7421b946 jack: remove some pthread attributes
JOINABLE and SCOPE_SYSTEM are defaults.
EXPLICIT_SCHED is not needed and causes qemu with resourcecontrol to
fail.

Fixes #2297
2022-04-18 11:52:22 +02:00
Quentin Wenger
d2250e9d1c Cleanup argument names in methods and events interfaces: object/data, 2nd pass. 2022-04-18 07:49:35 +00:00