LADI
/
spa
1
Fork 0
Commit Graph

504 Commits

Author SHA1 Message Date
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
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
Wim Taymans f0cc49766f jack: use serial for uuid
We must use the serial for generating the uuid.

We use the serial for the port_id and jack_port_uuid_generate() can
be used to turn that into a uuid. So all mappings to and from
uuid need to be with serials.
2022-01-26 17:47:03 +01:00
Wim Taymans 910ba5856c jack: uuid is based on id, not serial
So that we can easily map properties to metadata.
2022-01-26 12:24:31 +01:00
Wim Taymans 0bc3d1444a Add PIPEWIRE_QUANTUM env variable
That tries to both set the buffersize and the samplerate of the graph.
Document them in README.md
Also add the same env variables to pw-stream and pw-filter.
2022-01-23 11:21:18 +01:00
Wim Taymans f4021c7f44 port: add some more warnings when unregister fails 2022-01-23 10:16:42 +01:00
Wim Taymans 6c84b77e4d jack: add some debug to port_register()
See #1714
2022-01-23 09:35:21 +01:00
Wim Taymans 6ab56804e8 jack: uuid of ports is based on the id, not serial 2022-01-23 09:35:21 +01:00
Barnabás Pőcze 899281be60 jack: fix member name in fastpath logs
The port struct's `id` member has been renamed to `port_id`,
but the `pw_log_trace_fp()` invocation sites weren't changed.

Fixes: 029539831d ("jack: rework port allocation")
2022-01-22 23:29:45 +01:00
Wim Taymans 029539831d jack: rework port allocation
Port ids should be allocated using a map.
Only keep a port_id for the ports we allocate ourselves.
Keep just one port free list, there is no reason to keep per direction
free lists.
Get the port from the object directly.

See #1714
2022-01-22 20:59:27 +01:00
Wim Taymans a77f5131b2 jack: add dummy jacknet implementation
So that applications can link to libjacknet

Fixes #2043
2022-01-19 19:47:28 +01:00
Wim Taymans ca3fada8cb jack: fix jacknet meson variable 2022-01-19 19:28:08 +01:00
Wim Taymans 709d25f0c4 make key for node.transport.sync 2022-01-18 20:34:03 +01:00
Wim Taymans 1b9a2b6079 jack: use serial for port_id
We can reuse the cache logic, id removal invalidates the object id but
it can still be accessed by the serial until it gets purged.
2022-01-17 12:20:29 +01:00
Wim Taymans ac919e2a10 jack: add PIPEWIRE_RATE env variable
So that you can make pipewire switch samplerates.
2022-01-14 10:12:05 +01:00
Wim Taymans 13830f2ded jack: update for no id reuse
Now that object ids are not reused we can simplify some things. We
don't need to keep a map around with our own unique ids.

Keep all objects in one per client list, mark the removed ones as
removed, allow lookups of the removed objects, recycle half of the
oldest removed objects when there are too many of them.
2022-01-13 14:53:19 +01:00
Wim Taymans dcac58609c jack: don't limit max buffer size 2022-01-12 17:41:13 +01:00
Wim Taymans 2b102a1046 jack: remember last return from jack_get_buffer_size
Remember what we last returned from jack_get_buffer_size and only
emit a buffersize change event when somwthing new is configured.

Fixes startup of jconvolver.

Fixes #1989
2022-01-07 17:12:43 +01:00
David Runge 41392eda7f Add custom variable to jack pkgconfig to distinguish implementations
pipewire-jack/src/meson.build:
Add the custom `jack_implementation=pipewire` pkgconfig variable to the
generated jack.pc file to be able to distinguish jack implementations.
As jack implementations exist with jack1, jack2 and pipewire-jack, it is
not (easily) possible to distinguish them by looking at the version
alone (particularly the case with jack2 vs. pipewire-jack, as they share
the same headers).

Related to #1666
2022-01-06 12:37:08 +00:00
Wim Taymans 611591d0fc json: add spa_json_parse_stringn()
It also checks the destination size.
2022-01-04 12:37:00 +01:00
Wim Taymans c46113faa3 json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
Wim Taymans 35cbe4e939 buffers: make alignment optional
Make the alignment parameter optional when negotiating buffers.
Default to a 16 bytes alignment and adjust for the max cpu
alignment.
Remove the useless align buffer parameter in plugins, we always
set it to 16 anyway.
2022-01-03 12:32:26 +01:00
Wim Taymans 4c0bba953a jack: avoid metadata updates to monitor nodes
Because there is no difference in the node id of the monitor and
the sink carla has problems.

See #1945
2021-12-24 11:30:56 +01:00
Wim Taymans 1f4d3b0a1b jack: encode monitor uuid with extra bit
So that we can make a difference between monitor and sink uuid.

See #1945
2021-12-23 12:25:59 +01:00
Wim Taymans f5908dbddf impl-node: start sync after reposition
After we get a reposition request, bring the state to the SYNC state
again so that clients can align with the new position.

Fixes a problem with reposition when using the jack transport.

Fixes #1907
2021-12-22 19:53:28 +01:00
Hendrik Borghorst 205774f3ab jack: Disconnect owned links on jack_deactivate
As per JACK API description the call to jack_deactivate should
disconnect all ports because an inactive client can't have connections.

This disconnect is missing in the current API and results in left-over
links after the call and malfunction to clients (e.g. Music Player
Daemon).

To fix it this commit goes through the list of links to owned ports and
disconnect them.

Signed-off-by: Hendrik Borghorst <hendrikborghorst@gmail.com>
2021-12-15 15:44:28 +00:00
Wim Taymans 3f2f1971c9 jack: debug driver id and clock name 2021-12-10 12:19:14 +01:00
Wim Taymans 19b53e8dbe jack: fix loopback links to client
When a client produces output on a port and there is a link between the
output port and an input port of the client, make sure that the new
data appears on the input port.

We do this by keeping track of what links are between our ports and when
we get the peer id of a port input, we can related this to our port
again. Some mixer inputs will then fetch content from our own ports and
so we can prepare the output for them. This can be converting midi to
control messages or moving the output buffer id to the io area so that
the input mixer can pick up the new buffer.

Fixes #1839
2021-12-07 15:31:32 +01:00
Wim Taymans 35cec1cf23 jack: recompute latencies after graph changes 2021-12-07 15:31:32 +01:00
Wim Taymans b71f47448c jack: always invoke buffer callback
Always pause processing until the main loop has processed the buffer
change callback. This makes it less likely for clients in the same
process to use a new buffersize before the other client has received
the callback.

In carla, one client is receiving the buffer size callback and the other
clients are expexted to be paused until the callback for the client is
completed.
2021-12-07 15:31:32 +01:00
Wim Taymans fe417bd123 improve latency debug 2021-12-07 15:31:32 +01:00
Wim Taymans dfb82f6f46 jack: refactor recompute_latencies 2021-12-07 11:21:24 +01:00
Wim Taymans fbef731793 make some warnings into log
Move some warnings when a wakeup was missed to info messages. The
warning can repeat a lot and is otherwise quite useless and already
reported elsewhere.
2021-12-07 10:19:10 +01:00
Wim Taymans c20f22466e jack: improve latency calculation
Don't do the default latency calculation, it might interfere with
the client latency values. Instead just use the client values and
fold multiples of quantum in the quantum latency field.
2021-12-03 17:59:56 +01:00
Wim Taymans 28370fc3cf jack: also call latency callback when buffersize changes 2021-12-03 17:58:25 +01:00
Wim Taymans 97cad7284a latency: fix latency combine calculations
0 is a valid min latency so we can't use it as an unset value. Use
some large value instead and when nothing was configured, assume it
is 0.

Fixes #1839
2021-12-02 14:49:48 +01:00
Wim Taymans 3df6e77996 jack: handle regcomp errors 2021-11-29 12:46:50 +01:00
Wim Taymans 5cff20eba4 jack: handle chunk offset and size
Use offset and size in captured buffers and make sure we don't use more
than the allocated buffer size.
2021-11-25 15:17:42 +01:00
Wim Taymans dd62b12a1f jack: implement stub internal client API
Fixes #1842
2021-11-22 12:52:15 +01:00
Wim Taymans aeb435087b jack: ensure we don't have negative latencies 2021-11-22 12:12:29 +01:00
Wim Taymans 52b9ca8f2e jack: recompute latency on buffer size change
The latencies might be expressed in quantum, which changes when the
buffer size changes.
2021-11-22 12:11:49 +01:00
Wim Taymans 2e87127700 jack: keep object cache
Keep per type free_lists so that we can't reuse an old port object for
a link/node. This makes it more likely that ports are still available
after being freed.

Keep all allocated objects indexed in a global cache map. Use the global
cache index as the jack_port_id_t in connection and port registration
callbacks. Since the port_id is unique per allocated object and since
the objects types are never changed, we can always find a port with the
given port_id in the cache.

This vastly improves tools like catia that insist on querying objects
after they have been removed/destroyed.
2021-11-18 12:14:38 +01:00
Wim Taymans fc12e5bed0 jack: improve port sort order
Sort ports per node and then per node-specific port_id. This will
keep related ports together and will sort them based on when they
were created.

Fixes #1780
2021-11-08 09:23:20 +01:00
Wim Taymans 9facfca45b jack: add option to disable monitor ports
Add a jack.show-monitor option (default true) that makes it possible
to hide the monitor ports.

Monitor ports are not enabled by default on JACK and maybe they also
should not for PipeWire. Or maybe we need some tweaks for some apps.

See #1760
2021-10-29 09:27:46 +02:00
Wim Taymans 31f387868a jack: reorganize jack_port_get_buffer()
Dequeue a new buffer only once and reuse this queued buffer when
jack_port_get_buffer() is called multiple times in process().

Recycle an old buffer in the next cycle.

After calling process, mark all input buffers as consumed, process the
empty buffers and move the output buffers to the mix ports.

Fixes #1748
2021-10-26 12:28:31 +02:00
Wim Taymans 6f75b1433c jack: add some more debug 2021-10-26 12:10:15 +02:00
Philippe Normand 1ac57e6e15 pipewire-jack: Fix compound-token-split-by-macro warning 2021-10-25 07:26:15 +00:00