Commit graph

599 commits

Author SHA1 Message Date
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
Quentin Wenger
22fc9eec35 Cleanup argument names in methods and events interfaces
First method argument is object, first event argument is data.

Closes !963
2022-04-15 10:11:49 +02:00
Wim Taymans
5b01a2e738 jack: fix port sort
When the nodes are equal, sort playback ports befor monitor ports.
Then sort by system-id (port-id) and then by serial number.

See #2260
2022-04-02 09:42:22 +02:00
Wim Taymans
617405e08c jack: don't sort ports on alias
The alias is not a good property to sort on, it contains the object
path and could sort playback_11 before playback_2.

Just group ports of the same node together, then sort by port_id and if
that fails, use the serial number.

See #2260
2022-04-01 17:29:39 +02:00
Wim Taymans
f0424c0b99 thread: deprecate pw_thread_utils_set()
Setting a global thread-utils is not a good idea, especially
when multiple contexts will register their own interface.

Instead, set the thread-utils as a context object and use this to
configure the data loop in the context.

In JACK we need a per context implementation of the interface so that
we can find the context specific thread-utils.

See #2252
2022-03-30 20:39:34 +02:00
Wim Taymans
6041d939a0 jack: make a custom thread-utils
Make a custom thread_utils that can use the configured global
thread creator and set this in the data-loop.

This ensure that the data loop uses the creator thread when activated.

See #1495
2022-03-29 11:37:47 +02:00
Wim Taymans
d306786012 jack: start/stop loop in activate/deactivate
Stop the loop from the context.
Start the loop in activate.
Stop the loop in deactivate.
2022-03-29 11:36:31 +02:00
Wim Taymans
36185b830a jack: clear last error before sync
We are really interested in the error code of the statements we queued
before the sync so clear any previous error first. Otherwise we might
pick up a previous random error, which never gets cleared.

See #1714
2022-03-26 21:35:28 +01:00
Stanisław Pitucha
ca9da0ed5a Fix the comparison parens
The parens were unnecessary and didn't seem to match the intent for the
result.
2022-02-18 14:09:30 +00:00
Wim Taymans
d3f879e4ed jack: only set force-latency property
There is no point in setting a node.latency property when we also set a
force-quantum.
2022-02-11 12:22:02 +01:00
Wim Taymans
f123b58f1f jack: release lock when doing do_sync from data thread
If we do_sync from the data thread, release the rt_lock so that any
callbacks that may happen while waiting can grab the rt_lock.

We could also temporarily disable the rt_lock grabbing before the
callbacks.

In any case the callbacks will need to be called while we execute
the blocking function in the process callback.
2022-02-10 17:13:48 +01:00
Wim Taymans
104f0c766a jack: remove some listeners 2022-02-09 15:52:14 +01:00
Wim Taymans
78a7370bc6 jack: remove some more limits
Remove limit on max results from _get_ports() and _get_all_connections()
by using a dynamic array.
Keep the limit on the max number of midi inputs we can mix.
2022-02-09 15:40:45 +01:00
Wim Taymans
4353fa83d6 pipewire-jack: there is no port max anymore 2022-02-09 15:21:49 +01:00
Wim Taymans
fae7a1f592 jack: use node.lock-quantum by default
As soon as a JACK app is started, the automatic quantum change is
disabled. This means no pulse/alsa app can change the quantum.

The only way to change the quantum is with node.force-quantum or
with the settings metadata.

This means only a JACK buffersize change (usually controlled from the
JACK app, such as in ardour) or a metadata change (from the command
line) can modify things. Both of those are usually caused by a user
action.

For JACK apps where the quantum is allowed to change automatically,
explicit rules need to be placed in the config.
2022-02-08 18:35:12 +01:00
Wim Taymans
3b26af32d0 jack: add an option to display default device as system: 2022-02-04 17:06:54 +01:00
Wim Taymans
877dc77645 conf: move rule matching to config
And remove duplicated code. This is generally useful and sufficiently
generic API to include.
2022-02-04 10:43:31 +01:00
Wim Taymans
3a5c2ec623 jack: exit do_sync when in error
When we are already in error, return the error right away.
2022-02-03 12:01:30 +01:00
Wim Taymans
432f464297 conf: implement match rules with conf_section_for_each 2022-02-01 16:35:16 +01:00
Wim Taymans
65c487564b context: add a function to merge config properties
Add a function that takes a section and merges the properties into
a target properties. Replace some usage of get_config_section().
2022-02-01 15:11:45 +01:00
Wim Taymans
6149c01b51 jack: pass size_t as len 2022-02-01 13:28:10 +01:00
Wim Taymans
24c97b1c7e context: add force-quantum and force-rate property
Add a node.force-quantum and node.force-rate property. When no global
quantum or rate is enforce with settings, the last updated node property
is used as the quantum.

Make jack use the force-quantum property when set_buffersize is used to
make sure that the quantum is not just a suggestion but a hard forced
one. This makes it possible for ardour or other jack apps to raise the
quantum above the max-quantum but also ensure that it will not change
by any other application (unless other jack apps).

Fixes #2079
2022-01-31 17:59:18 +01:00
Wim Taymans
8698d5a548 jack: handle metadata remove
Add a proxy listener to the metadata so that we can remove our ref to it
when it is destroyed.
2022-01-31 15:04:08 +01:00