Commit graph

354 commits

Author SHA1 Message Date
Wim Taymans 7ef78b4464 jack: add extra object check
Make an invalid object type and mark removed objects as invalid.
Make sure we don't reference an invalid object for the various
callbacks and methods.

See #1265
2021-06-24 15:49:59 +02:00
Wim Taymans 8c77713a7b jack: don't emit connect callback with unknown ports
Lookup of globals needs a thread lock or context lock. There is no
need to take the context lock when we already have the thread lock.

Make a new method to find an object of a type.

Check that link objects are referencing valid ports. Check that the
connect callback is referencing valid ports.

Only return connections with valid ports.

See #1265
2021-06-22 11:16:45 +02:00
Wim Taymans 6186fc775d jack: improve debug
Log info messages when a port and client are added/removed
Log an info message when port_by_name/id can't find the port.

See #1265
2021-06-21 11:25:17 +02:00
George Kiagiadakis 59407d2f08 includes: update all references to extensions to point to pipewire/extensions
This also brings the advantage that all tools, examples, modules, components
can also be compiled standalone out-of-tree using libpipewire from the system
2021-06-18 17:54:18 +03:00
Wim Taymans d8ad87fd09 context: improve settings and defaults
Make structure with defaults that holds the defaults as they are loaded
from the config file or initialized with default values.

Copy this structure to a settings version that is used at runtime.

Add a force-quantum and force-rate field in the settings that can be
used to force a quantum and samplerate if != 0.
2021-06-17 11:11:45 +02:00
Wim Taymans 0ec760315e jack: there is no need to lock in get_aliases
See #1313
2021-06-17 10:56:39 +02:00
Wim Taymans 0f9fd45a58 jack: rework locking
Ensure all callbacks are called from the thread_loop and release
the thread lock before calling the callback.

Introduce a new rt_lock that is taken while the callbacks are called.
Only call the process_callback when we can acquire the rt_lock in the
data thread. This ensures the process callback is never called
concurrently with any other callback.

Give a warning when we try to call do_sync from the thread_loop
itself. We would deadlock because the thread that is supposed to do
the sync operation would be blocked in wait().

Fixes #1313
2021-06-17 10:46:04 +02:00
Wim Taymans 3e52c6598b jack: add more port checks
Check if the port id and direction is valid before accessing the
port array.
Handle unknown and invalid ports in many methods.
Free the port item after we removed the item from pipewire because
more methods are being called while removing the port and we don't
want them to fail.
2021-06-17 09:23:11 +02:00
Wim Taymans 61bcd4f988 jack: only use the "default" metadata 2021-06-16 12:17:52 +02:00
Wim Taymans e3a2f4a645 jack: keep context lock locked for callbacks
Also keep the context lock locked with emiting the registration,
portregistration and connect callbacks.

All the other callbacks are emited with the lock and it makes sense to
also emit these ones with the lock so that code in the callback gets
a consitent view.

See #1265
2021-06-13 19:26:10 +02:00
Peter Hutterer da339c286f meson.build: drop HAVE_CONFIG_H
This is an autotools leftover, with meson we're always guaranteed to have
the config.h file.
2021-06-10 09:04:16 +10:00
Wim Taymans a10cb3a597 jack: unlock mutex on error path
This needs some more fixing because it leaks everything.
2021-06-09 17:57:05 +02:00
Peter Hutterer 0054319d88 meson.build: add -D_GNU_SOURCE to the project arguments
This appends it to every compilation command so we can get rid of the c_args
for (almost all) executables.
2021-06-09 07:47:51 +00:00
Wim Taymans ec39cbee68 jack: improve debug
Add quotes around the port and client names.
2021-06-08 09:50:13 +02:00
Wim Taymans 2dcab4580f jack: store renamed port
When we rename the port, also store the new name in the port structure
so that we can actually find the port with the new name.

See #1265
2021-06-08 09:40:14 +02:00
Wim Taymans b142e7f09f jack: stop freewheeling correctly
Setting a NULL value for the property will remove the property and
will thus not send an update to the server and will thus not stop
freewheeling. Use "" to remove ourselves from the freewheel group
instead of looping forever.

See #1265
2021-06-07 12:22:47 +02:00
Wim Taymans 0792c690c2 jack: schedule port latency update from main thread
Ardour does the port latency update from the process thread. Schedule
an update on the main thread in all cases to avoid deadlocks.

See #1265
2021-06-07 11:16:24 +02:00
Wim Taymans 5a054cfc9e jack: call pw_ methods from within the lock
We're using a thread loop so always call methods with the lock or
we might cause lockups and crashes.

See #1265
2021-06-05 20:17:37 +02:00
Peter Hutterer 1d4b24d02b pipewire: allow NULL pointers in pw_memmap_free()
Just like the real free() we should just ignore a NULL pointer, makes the
caller code easier for those instances where properties are optional.
2021-06-02 10:56:46 +00:00
Arun Raghavan f19d998906 pw-jack: Fix empty string checks
shellcheck seems to hate x"$FOO" = x checks, so let's use the
appropriate test arguments instead.
2021-05-31 12:46:18 -04:00
Wim Taymans c319ed68d1 jack: implement more latency
Keep both input and output latency on the ports.

When setting the port latency only apply the rate latency values
and assume the node latency does not depend on buffer-size or time.
This is likely true because jack only knows about latency relative
to the rate.
2021-05-27 15:26:09 +02:00
Wim Taymans 12a3ea9539 jack: implement default latency handler
It combines all latency from one direction and sets it as the latency
for the other direction.

Also keep only one latency value per port, in the object.
2021-05-27 15:26:09 +02:00
Wim Taymans 4af2014168 jack: add latency reporting
Rework the param handling a little.
Keep properties for ports. Use this in the client and port info.
Trigger the latency callback when the port latency changed.
Update the port latency when it changed.
2021-05-27 15:26:09 +02:00
Wim Taymans b9b89b92b2 spa: add some latency helpers
Add more fields to the latency object.
Add methods to create, parse and process latency info.
2021-05-27 15:26:09 +02:00
Wim Taymans b588cc6b03 jack: listen to latency updates on ports
Listen for the latency updates on ports and use this to report
latency.
2021-05-27 15:26:09 +02:00
Peter Hutterer 5596e350ea pipewire-jack: fix scan-build errors for unused variables
All cases of value stored but never read
2021-05-26 07:51:27 +00:00
modula t 3aacc719b2 fix floating point exception when s->clock.position' is less than s->offset` 2021-05-26 07:46:14 +00:00
Fabrice Fontaine fa64d93e64 fix linking with -latomic
Linking with -latomic has been added to pipewire-jack since
b8c58c74d8

However, this is not the right place to add this dependency, atomic_dep
should be added to pipewire_dep to avoid the following build failure:

/home/giuliobenetti/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sparc-buildroot-linux-uclibc/9.3.0/../../../../sparc-buildroot-linux-uclibc/bin/ld: src/pipewire/libpipewire-0.3.so.0.326.0.p/filter.c.o: in function `impl_node_process':
filter.c:(.text+0xf28): undefined reference to `__atomic_fetch_add_4'

Indeed, atomic operation such as __atomic_fetch_add is used in libcamera
as well as in ./spa/plugins/libcamera/libcamera_wrapper.cpp,
./spa/include/spa/utils/ringbuffer.h and ./spa/include/spa/graph/graph.h

Fixes:
 - http://autobuild.buildroot.org/results/b5305e8e7dd1a5e8bfaba72b06251056ba7d1af1

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2021-05-24 08:33:50 +00:00
Peter Hutterer 4e70799922 treewide: drop strzcmp implementations in favor of spa_streq 2021-05-18 22:10:27 +10:00
Peter Hutterer 522f87d5ea treewide: replace strcmp() != 0 with !spa_streq
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer 95a84e797a treewide: replace !strcmp() with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer 7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer 20f8838f7b pw-jack: correct nested quotes
Found by ShellCheck, reformatted output:

In pipewire-jack/src/pw-jack.in line 58:
echo "	-s                  samplerate (default "$SAMPLERATE")"
	 SC2027: The surrounding quotes actually unquote this. Remove or escape them.
	 SC2086: Double quote to prevent globbing and word splitting.
2021-05-11 07:01:21 +00:00
Peter Hutterer 056d06da88 pw-jack: remove unecessary $ from arithmetic variables
Found by ShellCheck: SC2004: $/${} is unnecessary on arithmetic variables.
2021-05-11 07:01:21 +00:00
Wim Taymans 830f52cbb1 jack: join the freewheel group when freewheeling 2021-05-07 09:03:34 +02:00
Wim Taymans efc497a38a spa: make a new FREEWHEEL clock flag
When freewheeling, the clock is going faster than real time.
When freewheeling, skip samples in alsa sink/source.
2021-05-07 09:03:34 +02:00
Peter Hutterer 2405f0942b spa/buffer: rename SPA_MEMBER to SPA_PTROFF
SPA_MEMBER is misleading, all we're doing here is pointer+offset and a
type-casting the result. Rename to SPA_PTROFF which is more expressive (and
has the same number of characters so we don't need to re-indent).
2021-05-06 09:39:39 +00:00
Andrea Gelmini 85b136d8ce Fix typos
Signed-off-by: Andrea Gelmini <andrea.gelmini@gelma.net>
2021-04-30 16:27:34 +00:00
Andrea Gelmini 47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Nils Tonnätt b48d1facf4 Add server_libs variable to jack pkgconf file 2021-04-18 18:31:32 +00:00
Nils Tonnätt 01951fd278 Generate JACK pkgconfig file 2021-04-18 18:31:32 +00:00
Nils Tonnätt bd6d72be8f Install jack headers 2021-04-18 18:31:32 +00:00
Peter Hutterer 223f20709d meson: replace join_paths(a, b) with a / b
More readable and from the meson reference manual:
(since 0.49.0) Using the/ operator on strings is equivalent to calling join_paths.
2021-04-15 06:57:00 +00:00
Wim Taymans 877309bfbe use priority.session to select the default sink/source
priority.session is meant to be used to set routing priorities.

priority.driver is meant to be used by the scheduler to select what
nodes is best for driving the graph. This usually depends on the
hardware quality and the use case (Pro Audio devices are likely
to be used as driving the graph).

See #1028
2021-04-08 17:48:13 +02:00
Wim Taymans c50c0b91c5 jack: improve registration callbacks
Pass the type to the alloc function to make things pretier.

Emit the client added only for the first client and the removed
callback for the last client. Things like pavucontrol will make
many nodes with the same name, which we map to the same client,
only when the last node is gone, we emit the client removed.
2021-03-30 12:57:38 +02:00
Wim Taymans 74c6af1c55 jack: handle _port_get_buffer() on foreign ports
Some apps (ardour6) does a port_get_buffer() on a port that is not
its own port. This is not possible in PipeWire so make sure it
simply return NULL instead of crashing.

Fixes #988
2021-03-29 11:14:37 +02:00
Wim Taymans 222cffc850 jack: small cleanups and erro checks 2021-03-27 18:33:22 +01:00
Wim Taymans 27a5ebb87e jack: free server in error case 2021-03-25 19:07:13 +01:00
Wim Taymans c78901f9f9 jack: free client in error case 2021-03-25 17:54:24 +01:00
Wim Taymans df9644f109 jack: add jack.self-connect-mode
Add a property to restrict self-connections. This can be used to
stop clients from connecting themselves automatically.

Fixes #952
2021-03-23 12:24:38 +01:00
Wim Taymans 53024c1747 jack: free the global map when the client is closed 2021-03-22 11:21:44 +01:00
Florian Hülsmann 41d4039ee4 jack: omit debugging macros in jack_{error,info,log} 2021-03-16 08:59:01 +00:00
Florian Hülsmann 21ff2740d6 jack: jackctl_server_create2 add dummy driver 2021-03-16 08:59:01 +00:00
Florian Hülsmann 1a59711ce1 jack: jackserver sources, add stubs for control.h 2021-03-16 08:59:01 +00:00
Wim Taymans 196fe8b51b jack: use configured node.latency when inactive
In the inactive state, use the configured latency values for the
node instead of the current values used in the graph. We need to
do this because the graph only changes the buffer-size to our
requirements when the node becomes active.

Some clients do get_buffer_size before activating and would then
get a different value from when they would activate, causing some
apps to be confused and stop.

See #886
2021-03-12 15:58:34 +01:00
Wim Taymans 3e2d897f97 jack: improve debug 2021-03-07 10:46:08 +01:00
Wim Taymans 6c8c58ab4e jack: also match system ports in get_ports
Fixes #850
2021-03-07 09:44:40 +01:00
Wim Taymans ffab69f651 jack: move some debug to info
Use info to lay out the general app flow
2021-03-07 09:44:04 +01:00
Wim Taymans c8fd34a41d metadata: store default-nodes as JSON
Don't just store the id in the metadata but a JSON object with
the node name. This makes it possible to easily introspect the
metadata and also extend the metadata with more fields later.

Instead of matching the metadata id to the global ids we now
have to match it against the name.
2021-03-05 17:37:12 +01:00
Wim Taymans 0ad603375f jack: keep midi ports on the midi-bridge client
Separating them causes problems because there is no actual
client for the resulting ports then.
2021-03-04 18:06:07 +01:00
Wim Taymans d98d947e54 jack: handle "default" server name 2021-03-04 18:02:11 +01:00
Wim Taymans 052bc85dad jack: ship our own jack headers and build against them 2021-03-03 15:54:48 +01:00
Wim Taymans eacda22a7b jack: make constant of Monitor extension
See #788
2021-02-24 22:23:20 +01:00
Wim Taymans 8768cf1b68 jack: increase client name size
Increase the client name size and try hard not to exceed the client name
size especially when adding the Monitor suffix.
Also avoid some potentially unsafe strncpy.

See #788
2021-02-24 22:05:14 +01:00
Wim Taymans e340a44a35 jack: fix names of our ports
Write our port name into the port.name

See #796
See #780
See #569
2021-02-23 21:11:05 +01:00
Wim Taymans d54da879bf jack: add config option to shorten and filter names 2021-02-23 16:13:08 +01:00
Wim Taymans 149319819a jack: apply PIPEWIRE_PROPS after reading config
First apply config properties, then PIPEWIRE_PROPS.
We can set the node.latency in jack.conf
2021-02-20 21:02:05 +01:00
Wim Taymans 71e37f93f3 PIPEWIRE_LATENCY always overrides app settings 2021-02-20 20:59:41 +01:00
Wim Taymans 686524ce40 context: use the log.level from the config file
Use log.level from the config file if not otherwise set with
PIPEWIRE_DEBUG env.
Make client log.level = 0 by default to avoid spamming the console
with errors.

Fixes #725
Fixes #769
2021-02-19 12:44:03 +01:00
Wim Taymans 60233e30a7 jack: tweak names a little
Move the Description in the main node/port name. This then matches
the device names seen in pavucontrol.
Make the port alias contain the node nick.
2021-02-17 11:36:16 +01:00
Wim Taymans e66cb18659 jack: find system: port names as well
Make a system:capture_N or system:playback_M name for each port
and use this also in find_node when the node is a default node.
This makes it possible to

jack_connect system:capture_1 system:playback_1

and make it link the default source to defaukt sink.

Fixes #446
2021-02-17 11:16:02 +01:00
Wim Taymans 39cf575210 jack: don't log errors, let app deal with it 2021-02-17 11:15:31 +01:00
Wim Taymans af686653a9 jack: add option to merge monitors
Make a different name for the monitor port prefix so that they
appear as different clients.
Add an option to restore the previous behaviour.

See #736
2021-02-16 13:23:47 +01:00
Wim Taymans 0945b10227 jack: handle bridge nodes
Bridges have the device name in the port names so use this info
to construct better port names. Makes midi devices show up
as separate clients.
2021-02-12 21:15:14 +01:00
Wim Taymans ac910c7c1c Revert "jack: improve short name"
This reverts commit 8101334b1e.

We should use the same logic as jack1 and jack2 to improve
compatibility.
2021-02-12 20:46:34 +01:00
Wim Taymans 1e89b7cdc4 Revert "jack: sanitize client and port names"
This reverts commit 0ad8f0a6aa.

We should not do this here. We should instead sanitize the names
at the source.
2021-02-12 20:45:33 +01:00
Wim Taymans 0ad8f0a6aa jack: sanitize client and port names
Avoid : in client names and port names.

See #714
2021-02-12 12:29:45 +01:00
Wim Taymans 8101334b1e jack: improve short name
Search the : backwards so that we can deal with client names with :
in them.

See #714
2021-02-12 11:57:27 +01:00
Wim Taymans 80825aeaea conf: more work on config changes
Add -c option to pipewire to select config file. Use this to select
the uninstalled conf file.
Rename conf properties, prefix with context.
Simplify the main daemon now that everything can go in config.
Simplify pipewire-pulse now that we can put everything in config, it's
now virtually the same as pipewire but with a differenct config file.
Parse server addresses as array of strings.
2021-02-12 10:31:29 +01:00
Wim Taymans fc90a4e48a Implement config/state file handling
Make methods to load_config and load/save state. For now the config
and state directories are the same but it might not be. Implement
the search path for all config/state files as:

  $XDG_CONFIG_HOME/[$prefix]/$name
  $HOME/.config/[$prefix]/$name
  $PIPEWIRE_CONFIG_DIR/pipewire/[$prefix]/$name
  /etc/pipewire/[$prefix]/$name

Make some config files for jack and RT clients. Make pw-cat use the
client-rt config.

Use core state and config management in media-session.
Move all session manager state and config files to the build dir and
set the PIPEWIRE_CONFIG_DIR to this build dir.
2021-02-12 10:25:11 +01:00
Wim Taymans 83c403ed1c jack: use PIPEWIRE_PROPS for the context as well
Use PIPEWIRE_PROPS to create and connect the context as well. This
makes it possible to pass configuration to the modules loaded by
the context such as:

PIPEWIRE_PROPS="context.modules.args={nice.level=-14}" jack_simple_client

To set the nice level of the jack app.

See #698
2021-02-10 11:23:52 +01:00
Wim Taymans 51cfb98ea6 jack: Pass custom flags as port.extra info
Make a port.extra property that contains API specific extra port
information that is passed in the global object properties.
Use this to pass the custom jack flags for a port. Carla uses this
to mark CV ports.
2021-02-09 16:09:53 +01:00
Wim Taymans ef150bfb3c jack: return an empty session command
We need to return an empty message because apps don't expect a
NULL pointer.
2021-02-09 10:26:14 +01:00
Wim Taymans 19b6942965 jack: use PIPEWIRE_PROFILE_MODULES first
We want to respect the PROFILE_MODULES settings if any or else
we use the default,rtkit profile.

See #683
2021-02-08 18:02:58 +01:00
Wim Taymans 0f028dab40 jack: use the context data thread
Configure the data thread as cancelable, there is no need to make
another thread.

See #683
2021-02-08 15:29:48 +01:00
Wim Taymans 210950dc0a context: disable mlock warnings by default
Make this a tunable option instead.
2021-02-08 10:59:02 +01:00
Wim Taymans 3450bea416 jack: implement some missing methods
to make qjackctl 0.9.0 work
2021-02-04 15:48:36 +01:00
Wim Taymans 2b44f42845 pass the complete buffer size to snprintf
There is no reason to pass size-1, snprintf will always put a \0
at the end.
2021-02-02 12:09:29 +01:00
Wim Taymans abfc67a3ca Revert "remove mlock and use MAP_LOCKED"
This reverts commit ab91e94b59.

When no memory can be locked, the mmap fails with -EAGAIN.

Fixes #592
2021-01-19 14:47:52 +01:00
Wim Taymans ab91e94b59 remove mlock and use MAP_LOCKED
The warnings are confusing and a properly tuned system would have
the limits set correctly.
2021-01-19 11:59:21 +01:00
Wim Taymans c430b1de58 jack: move monitor ports after playback ports
Enumerate monitor ports after their playback ports, like how
jack does this.

See #527
2021-01-05 15:38:52 +01:00
Wim Taymans 776147c125 jack: also find port by aliases
one can also use the aliases to connect ports, qjackctl does this.

Fixes #527
2021-01-03 21:25:55 +01:00
Wim Taymans 2b507cbe79 jack: use the node activation position after connecting
Until we get assigned to a driver, use our own activation position
to report samplerate and buffer size.
2020-12-09 20:48:59 +01:00
Elliott Sales de Andrade 86fd6a0d3e Fix some possible-NULL pointer usage. 2020-11-23 15:36:08 +00:00
Wim Taymans fb44d3428c jack: block some cases
Refuse to run when we run in the daemon, we can't really do a blocking
connect to the daemon from its main thread.

Also refuse to run when we detect an old pipewire libaray. Blocks the
case where some app linked against 0.2 wants to use the replacement
libjack.so.
2020-11-19 12:37:10 +01:00
Wim Taymans f42da492f9 warn about lock just once 2020-11-14 21:21:20 +01:00
Wim Taymans 38bcab4610 jack: handle connect errors
Listen on the proxy for errors and report this to the caller. This
avoids hanging in jack_connect.
2020-11-04 21:05:45 +01:00
Wim Taymans c43026d93e don't handle EINTR and EAGAIN as the same
EAGAIN means a non-blocking operation would block and we should not
try again right away but leave the loop and wait instead.

See #358
2020-11-02 16:43:56 +01:00
Wim Taymans e094640c7b handle EINTR and EAGAIN
Just do the call again instead of failing or logging an error.

Fixes #358
2020-11-02 14:51:07 +01:00
Wim Taymans acfb48e3da pulse: improve debug 2020-10-27 16:46:12 +01:00