Commit Graph

12409 Commits

Author SHA1 Message Date
Wim Taymans df50952f48 tests: add right include for close/unlink/pipe2 2024-03-15 12:39:20 +01:00
Wim Taymans 76ce2f77a4 test: handle running without a server
The security context test requires a running server, exit gracefully for
now when there is server running, like in the CI.
2024-03-15 12:25:30 +01:00
Wim Taymans 7e9e261fa6 conf: support property rules
Add pw_conf_section_update_props_rules() that will not only update the
properties of a section but wil also apply rules in section.rules and
match against the context properties.

Use this by default when using pw_context_conf_update_props().

Add a new method to get a string name of the VM type. Place the
cpu.vm.name in the context properties.

This makes it possible to deprecate the vm.overrides with something more
flexible based on rules. Update the conf files and docs to refect this.
2024-03-15 12:10:41 +01:00
Wim Taymans afd0affd97 conf: handle !null checks 2024-03-15 12:10:40 +01:00
Wim Taymans 6c6046f5ac tests: update unit test for added field 2024-03-15 12:10:40 +01:00
Wim Taymans a69e2ecda5 gst: fall back to buffer time when no header
This at least sets some form of timestamp on the buffers.
2024-03-15 12:10:40 +01:00
Wim Taymans f0dcdf4d31 stream: add time field to pw_buffer
For capture streams, place the time of the cycle when we received this
buffer in the new buffer time field.

Without this (and without timestamps in an optional header metadata)
it's impossible to determine when a buffer was created. With this field
and the pw_stream_get_time_n() and pw_stream_get_nsec() we can derive
the mapping to ticks and delay in the graph.
2024-03-15 12:10:40 +01:00
Arun Raghavan 46e6fd2ae4 spa: alsa: Read ctl events instead of doing a global diff
This does a couple of things: first, we implement revents demangling,
which seems to be required (although hw: devices work fine without it).

The second is to actually read the ctl events so we can tell when
elements we care about have changed, instead of reading everything and
trying to do a diff.

The latter is also required from a correctness perspective, as otherwise
the ctl might keep triggering wakeups while the fd is ready to be read.
2024-03-14 10:13:41 -04:00
Wim Taymans 8a1ed01923 protocol-native: update the properties correctly 2024-03-14 11:10:38 +01:00
Wim Taymans 9af26d1718 stream: improve the timing info
Always copy the timing info when capturing, not only when there is a
buffer to dequeue.

We can update the rate_queued and rate_size with defaults when we don't
have rate matching. We can then also directly use the rate_size field
to update the buffer requested size.
2024-03-14 11:06:12 +01:00
Wim Taymans 1d8a96d240 stream: update some docs 2024-03-13 15:27:47 +01:00
Wim Taymans 69cc3832d4 tools: improve error reporting
Add better error reporting in the security context and pw-container.

Add manpage for pw-container.
2024-03-13 12:53:04 +01:00
Wim Taymans 81181e255f tools: add pw-container tool
This makes a new custom security context with the given properties
and runs the program in this context.
2024-03-13 12:53:04 +01:00
Wim Taymans 477c6e8e90 protocol-native: improve security context properties
Remove the engine_name, use pipewire.sec.engine in the properties. Make
some constants for this.

Document some more properties.
2024-03-13 12:53:04 +01:00
Wim Taymans d250f6932c protocol-native: don't allow recursive security context
Place the engine name in pipewire.sec.context and make sure that a
client with a pipewire.sec.context property can't make new contexts.
2024-03-13 12:53:04 +01:00
Wim Taymans e7846fc12a protocol-native: add security context API
Add a new extension that can create a server on a user provided socket
with user provided security properties.

This is mainly used in flatpaks that want to create and bind a pipewire
socket with specific permissions for the flatpak app.

The flatpak will also provide an fd that will be closed when the server
can be removed.
2024-03-13 12:53:04 +01:00
Wim Taymans c5e8da7247 protocol-native: add props to the sockets keys
Make it possible to set extra properties on the sockets created from the
config options with a props key.
2024-03-13 12:44:24 +01:00
Wim Taymans e86a68db3f gst: add a clock to gst pipewiresink 2024-03-12 17:36:50 +01:00
Wim Taymans 4437f6e000 gst: only remove port once
The port has node_data set/cleared when it is added/removed to/from
the node. Make sure we only remove the port once to avoid a valgrind
error.
2024-03-12 16:54:50 +01:00
Wim Taymans 7a9dfc188a jack: improve midi buffer handling
nframes in the midi buffer should be set to the current cycle
buffer_size and it should restrict the timestamps that can be set on the
midi events.

Keep the last max_frames around in a globals so that we can use it to
set the midi buffer to the default size.

Return NULL when we do jack_port_get_buffer() with larger nframes than
the current cycle buffer_size, just like JACK. Otherwise this could
result in a crash when we try to mix more than the available buffer
space.

Check and reset the midi buffer better. Check if the MAGIC is still ok.
jack_midi_reset_buffer() should restore the MAGIC and other values.
2024-03-12 16:41:59 +01:00
Wim Taymans ca4f9d4989 jack: set the output buffer size correctly
The output buffer size is always the current cycle buffer_size.
The size that is give by the JACK API is only used to restrict the
number of mixdown samples or midi offsets.

Fixes #3892
2024-03-12 15:53:02 +01:00
Wim Taymans f86ea21b19 module-ffado: add more port properties
Mark control ports so that wireplumber does not attempt to link them.
Clear ports before making new ones, don't free NULL ports.
2024-03-12 12:22:34 +01:00
Wim Taymans 84af13a10b settings: add default.clock.quantum-floor property
Remove some of the hardcoded values (the absolute smallest buffer size,
independent on the sample rate) to a config option. Set it to the
default value of 4, like what it was before.

Change the hardcoded absolute lowest limit to 1 because anything else
does not make sense.

Enforce the quantum-floor when calculating the final graph quantum.

Fixes #3908
2024-03-12 10:21:31 +01:00
Pauli Virtanen e784de3933 spa: use log topics everywhere
Use log topics properly everywhere, convert from "#define NAME".
2024-03-11 18:45:21 +02:00
Wim Taymans c963ca47c1 module-ffado: disable pause on idle
Let the module run for a little longer until the session manager
suspends it.
2024-03-11 16:55:35 +01:00
Wim Taymans ea524b158c audioconvert: add monitor.passthrough option
Add a monitor.passthrough option. This will pass all latency information
directly between the port and its monitor ports.

This is interesting when the adapter (and audioconvert) is used with a
null-audio-sink that simply forwards the data to a real sink/souce. In
that case, we want the sink/source latency to be passed unmodified.

Set the monitor.passthrough on the pulseaudio null-sink because
a passthrough virtual sink is the most likely use case for this.

Add some monitor.passthrough default config where it makes sense.

Fixes #3888
2024-03-11 16:20:27 +01:00
Wim Taymans 10830ab9f8 module-ffado: copt link.group property 2024-03-11 13:22:20 +01:00
Pauli Virtanen da1a5568a1 doc: add options to change what /usr and /etc paths are shown
Add options to change the 'prefix' and 'sysconfdir' values shown in
documentation, e.g. on config file man pages.

Update CI to set them, so that its produced output doesn't show
/builds/pipewire/... on man pages
2024-03-10 22:25:42 +02:00
Pauli Virtanen e2a546006a doc: minor documentation improvements
Document a few properties more, and fix some wrong things.

Mark types of properties.
2024-03-10 19:08:41 +02:00
Wim Taymans 1e92ecea53 jack: fix multiple midi input ports
On the midi input ports, do the same trick as on the output ports:
first convert the midi to JACK and then copy the whole buffer to the
port specific storage.

This makes it possible to have a different midi buffer per port and
allow multiple threads to get the buffer concurrently.

Fixes #3901
2024-03-08 16:31:00 +01:00
Wim Taymans 37900ff765 module-ffado: make the event buffer per port
Or else ports overwrite eachother.
2024-03-08 15:24:33 +01:00
Wim Taymans fc0b638045 module-ffado: handle MIDI correctly
When the midi message does not fit in the current cycle, save it in a
buffer and send it in the next cycle.

Incomplete midi messages will be received in the next cycle and need to
be sent out at timestamp 0 of the cycle.

Detect dropped and incomplete messages and give a warning.

Try to close/open the ffado device when streaming_start() fails. This
seems to be the case after suspend/resume or a cable disconnect.
Unfortunately, ffado seems to be stuck in an unrecoverable state,
though, to make it really work...

Clean up port buffers when the filter is destroyed.
2024-03-08 13:00:34 +01:00
Pauli Virtanen 7d0ca2d103 spa: node-driver: always put CLOCK_MONOTONIC values to clock->nsec
When timer is not using monotonic clock, apply clock offset to translate
the time values to the monotonic clock when putting them to spa_io_clock
nsec fields.

Get appropriate clock offset by smoothed filtering.  The parameters here
keep the offset jitter < 10ns or so.

As monotonic/boottime/realtime all contain adjtime(), there generally is
no drift in the offset here, so just averaging should be fine.

Also fix using wrong timer clock when freewheeling.
2024-03-07 20:04:54 +02:00
Barnabás Pőcze c12e9a745d pw-top: only check terminal size in non-batch mode
If ncurses is not initialized, then the global `LINES` variable stays 0.
This will cause problems because there is an unconditional `if (y > LINES)`
check when printing the driven nodes for a given driver node, resulting
in only the first one being printed.

Commit 71653e04d2 ("pw-top: add 'batch-mode' and iterations known from top")
that introduced batch mode missed this one condition, so fix that
by only checking the for terminal overflow in non-batch mode as
it is done a couple lines above.

Fixes #3899
2024-03-07 17:17:35 +00:00
Barnabás Pőcze cf984fcd4c spa: alsa: fix clang build
Variable declarations after a label are not allowed,
and clang does not accept them. Fix the build failure
by removing the variable.

Fixes b3fbd0e607 ("alsa-pcm: add_bind_ctl_param: add support for array")
2024-03-07 17:16:55 +00:00
Robert Mader 1a6bb994a5 gst: Fix sanitization of non-writable caps
`gst_caps_make_writable()` may create a copy which we have to keep
using afterwards. The return value was meant to be used for that,
but was promptly forgotten for the initial user.
Avoid such errors in the future by using an in-out parameter instead.

While on it, add a type check and remove a check for an impossible
condition.

Fixes: 8a271a87b ("gst: Sanitize caps before translating")
2024-03-07 17:16:18 +00:00
Antonio Larrosa 2df931483d Specify "Audio" in gstreamer sink/src metadata to fix autodetect
gst-play uses autoaudiosink by default when playing audio, which
iterates over all sinks sorting them by rank. By default,
pipewiresink sets the rank to 0, but it can be overridden
by setting the GST_PLUGIN_FEATURE_RANK env. var. like this:

`GST_PLUGIN_FEATURE_RANK=pipewiresink:268 gst-play-1.0  /usr/share/sounds/alsa/test.wav`

But that doesn't work either because the autoaudiosink plugin also
filters the available options, testing for "Sink" and "Audio" to
appear in the classification metadata

(in the strstr comparison in
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-good/gst/autodetect/gstautodetect.c?ref_type=heads#L220
klass is what's set by pipewire as classification,
self->type_klass is "Sink" and self->media_klass is "Audio")

Just adding the word Audio to the classification metadata fixes
this and allows pipewiresink to be selected by autoaudiosink.

I also set it in the source plugin since looking at the code,
autoaudiosrc works exactly the same.
2024-03-07 17:15:20 +00:00
Wim Taymans 60d68e0d66 module-ffado: implement MIDI send and receive 2024-03-07 18:11:01 +01:00
Wim Taymans f3d9b823bd module-ffado: various fixes to make things work
The FFADO source needs to be the driver and the sink the follower so
that captured data can flow to playback without delay.

Instead of starting a new thread for FFADO, use a timer and the data
loop to wait for FFADO. This is not so nice because we do blocking waits
on the data thread but then we can schedule the source and sink without
a context switch from FFADO. We use a timer so that we can set a timeout
period before starting the graph and catch xruns. The timer will be
restarted immediately when the graph completes and we can go back into
the FFADO wait.

FFADO Xrun should result in a new wait() call.

Handle channels better, use AUX for the channels when they don't match
the given positions.

Silence playback when we don't have a sink or sink data.

Stop and start FFADO when the sink/source pause/resume.

PIPEWIRE_CONFIG_NAME=client-rt.conf pw-cli -m load-module
libpipewire-module-ffado-driver '{ ffado.period-size=32 ffado.period-num=2 }
now gives 4.722ms latency measured with jack_iodelay, equal to JACK.

See #3558
2024-03-06 18:01:33 +01:00
Emil Svendsen b3fbd0e607 alsa-pcm: add_bind_ctl_param: add support for array
ALSA controls are represented as an array. So let's make it possible to
handle array's and bytes.
2024-03-06 08:44:13 +01:00
Emil Svendsen 96f35e15a0 alsa-pcm: bind_ctl: add better ctl name matching
For matching kctl without the numid you need to specify interface,
device, subdevice, name and index. So the current implementation can
only match kctls on IFACE_PCM, device 0, subdevice 0 and index 0.

Instead of adding all these matching parameters this commit fetches all
kctls attached to the audio card and match on the first occurred kctl
with matching name.

This should be sufficient for audio cards with unique kctl names. When
non unique names are needed, more kctl matching parameters needs to be
added.
2024-03-05 17:48:56 +00:00
Robert Mader 8a271a87b7 gst: Sanitize caps before translating
DMABuf caps without concrete formats and modifiers don't map well to the
Pipewire negotiation process.
Introduce a new gst_caps_sanitize() helper function, where such cases
can be handled.
2024-03-05 12:08:32 +01:00
Robert Mader f1b75fc6f8 gst: Add support for DMA_DRM / explicit modifiers
Gstreamer 1.24 added and largely switched to a new, modifier aware
DMABuf API. Unfortunately that breaks the existing DMABuf support in the
PW Gst element.

Add support for the new API.
2024-03-05 12:08:32 +01:00
Wim Taymans f2f60ee0ec jack-tunnel: convert JACK time to MONOTONIC
JACK current_msec can be in MONOTONIC_RAW or MONOTONIC, depending on how
JACK was compiled (but it's likely MONOTONIC_RAW). PipeWire requires the
nsec field to be in MONOTONIC so take some time snapshots from both
clocks and apply a translation.

Also make sure we only get the nsec time from streams that exist.

See #3886
2024-03-04 15:34:42 +01:00
Wim Taymans f4e391dd41 stream: add pw_stream_get_nsec() to get current time
Make a method to get the current time to compare agains the pw_time-now
field. This is currently CLOCK_MONOTONIC but make this into a method
so that we can more easily change it later.
2024-03-04 12:59:26 +01:00
Emil Svendsen 81d8ecf0dc alsa-pcm: snd_ctl_open: remove device suffix
ALSA controls can only be opened on the card itself and will fail when
trying to open controls on the ALSA device. The device name we get may
or may not include the device suffix. If no suffix is present the
default device is 0 that's why currently it works on most audio cards.
But all other devices above 0 needs the suffix [1].

[1]
Device 0: hw:cardname
Device 0: hw:cardname,0
Device 1: hw:cardname,1
Device 2: hw:cardname,2
Device X: hw:cardname,X
2024-03-04 09:45:37 +00:00
Dimitrios Katsaros c1eacce3fc alsa: Use hi-res timestamps in irq mode when available
We know in IRQ mode that any valid hi-res timestamp that the
driver privides will be before the wakeup event in pipewire.

This makes it so in IRQ mode we use better timestamping when possible,
which decreases jitter injected into the DLL, which in turn reduces
the amount of oscillations the resampler is exposed to.
2024-03-01 21:46:21 +01:00
David Turner 0cfe57f33d Add SOC-style jack names to HDMI audio paths
Currently the HDMI output paths have jack mixers named "HDMI/DP" and
with append-pcm-to-name=true.  However, most of the SOC audio drivers
are just named "HDMI" and don't add the ",pcm=N".  Add these alternate
jack names to the HDMI audio path files so that jack detection will work
on these SOCs.
2024-03-01 09:33:55 +00:00
Wim Taymans 0f14cc3b13 gst: remove timeouts when autoconnect=false
When we disable autoconnect, disable the timeouts as well. Otherwise the
user has to connect the stream within the 30 second timeout or get a
failure. With autoconnect we can reasonably assume there is a problem
when the stream is not connected after 30 seconds.

Fixes #3884
2024-03-01 10:29:18 +01:00
Wim Taymans 06f63f489a node: add node.sync-group and node.sync
node.sync-group can contain a list of strings. When a node in the graph
sets node.sync = true, it will be scheduled with all of the other nodes with
common node.sync-group strings. By default all nodes are placed in
group.sync.0 except the freewheel and dummy driver.

Use this to ensure that all nodes are grouped under the same driver
(that is not the freewheel and dummy driver) as soon as the transport is
started so that the transport is visible to all nodes from the same
sync-groups. We also don't deactive the sync-group anymore for the node,
even if the transport is stopped, to avoid driver changes and transport
jumps.

When the node that activated the sync/transport is destroyed, things are
restored to their original state. Note that this is different from JACK
where starting the transport outlives the application and always needs
to be explicitly stopped again. We can't really do this (by default) because
it leaves the graph in an unnatural state with all devices in sync.

The reason for the node.sync-group is that it is possible to still have N
different subgraphs with a separate transports by manually specifying
the node.sync-group.

It's also slightly different from the node.group, that is always active.
The sync-group is something you only want to enable in specific cases
because it groups drivers together and enables adaptive resampling etc.

It's also possible to place this option in the jack.conf file to
automatically sync all devices and apps as soon as a jack app is started.

Fixes #3850
2024-02-29 18:04:05 +01:00