The link might have been made using the node name/nick/description but
we always want to place the id in the properties to make it easier for
apps to handle the relations between objects.
See #1723
The media session modules need to load config files through
sm_media_session_load_conf() and that must be the same config dir as our
main configuration file's directory.
For buffers on the 'dequeued' list, the busy counter was already
incremented in impl_node_process_input(). So it must be decremented again
when these buffers are removed.
The current code has several issues if a pipewiresrc is stopped and deleted
while a buffer is still in use downstream.
- pw_stream_queue_buffer() is never called for the corresponding
pw_buffer. As a result, the busy counter is never decremented and
pw_stream_dequeue_buffer() of the corresponding pipewire output will
return NULL whenever it encounters this buffer.
- The pipewiresrc does not own the buffer reference unless the buffer is
queued in the source, so calling gst_buffer_unref() unconditionally
causes refcount issues for the buffer.
- buffer_recycle() can race with on_remove_buffer() and
gst_pipewire_src_close(). As a result, buffer_recycle() may access pwsrc
when it was already deleted.
The buffer has its own reference to the pool. So the pool object lock can
be used to ensure that the pwsrc, core and stream remain valid in.
buffer_recycle(). If the 'dispose' function pointer was already cleared,
then on_remove_buffer() has already finished, so abort early.
With the pool lock held, it is save to access the pipewire loop. Now the
loop lock can be used to synchronize with on_remove_buffer(). 'dispose'
must be checked again in case on_remove_buffer() was triggered by something
other than gst_pipewire_src_close().
In on_remove_buffer() unref the buffer if it is queued. Otherwise call
pw_stream_queue_buffer() to ensure that the busy counter is decremented
correctly.
The proxy errors are really from the session manager informing us about
decisions it made (failure to link, etc). The state of the stream is not
really affected by this so just emit the error signal and let the app
decide what to do.
Use this to override the default $PIPEWIRE_CONFIG_DIR/media-session.d
directory. This allows us to have separate configuration directories for
pipewire and media-session.
Make things work then there is no default input device and the default
source is actually the monitor of the default sink.
Also implement lookups of monitor sources with the monitor id as the
name.
Fixes#1691
pause_node() will check the IDLE state of the node and will not
deactivate the node when suspending when it was already IDLE.
Fixes an issue where node.pause-on-idle=false filters would not want to
resume after a suspend.
If we try to fetch a property as some specific type and the parsing
fails, log a warning. This should catch any client bugs where the
properties are set wrongly.
Two method calls to get properties,
- pw_properties_fetch_$type()
- pw_properties_get_$type()
The former allows for easy error checking and conditional setting of
properties. The latter for easy fetching of a property with a default
value. This simplifies the code and makes property parsing behave more
consistently across the code base.
Before:
str = pw_properties_get(props, "foo");
if (str)
myval = pw_properties_parse_int(props, str);
if (myval == 0) /* parsing error or a valid zero */
do_stuff(myval);
Now:
if (pw_properties_fetch_int32(props, "foo", &myval) == 0)
do_stuff(myval);
If we build media-session before the daemon we have the executable
variable available and can rely on meson to fill in the path instead of
handling it manually.
There are only two values we care about that are identical, we can
re-set those in a new configuration_data() object.
All the other values set by the pipewire daemon are related to how we
start the session manager which isn't applicable here.
When pause-on-idle is false, the node can be destroyed without ever
being deactivated, which would crash. Make sure we deactivate in destroy
and remove the node from the graph.
Add a method to enable/disable the denormals flush-to-zero and
denormals-as-zero CPU options.
Add a config option to make it possible to disable this again.
Fixes high CPU usage when dealing with denormals, which can happen
in many DSP functions.
Fixes#1681
AUX channels can link to any other channel but when AUX channels are
linked, they must match exactly.
Fixes some issues with split devices with aux channels.
Some devices (Bose Mini Soundlink II, Air 1 Plus, ...) don't enable
AVRCP volume control, or fail to enable it before a hardware button is
pressed. However, these devices appear to enable it, if an AVRCP player
is present.
As a workaround, register a dummy AVRCP player for each adapter. It only
displays the current transport acquisition state as playing/stopped, but
just its presence appears to be enough to make devices behave.
Multiple AVRCP players interfere with each other, as BlueZ uses the one
registered earliest as the default player. So add also a config option
for disabling this. (It's not common to have mpris-proxy etc. running,
so defaulting to true should be OK.)
See pipewire#1157
Take some parts out of the public documentation, add a lot of internal
documentation to make it easier for the next person to figure out how
this works.
The use of static inline prevents doxygen from generating docs, put a
note in to link to the header file directly.
Re-using an id after removing it is a bug in the caller but there are
two cases where we corrupt the free list without warning:
Removing an object twice:
id = pw_map_insert_new(object);
pw_map_remove(map, id);
pw_map_remove(map, id);
And inserting an element at an index previously removed:
id = pw_map_insert_new(object);
pw_map_remove(map, id);
pw_map_insert_at(map, id, new_object);
The latter is arguably valid code, or at least it'll look like it's
valid code.
For both cases, check if the id to remove/insert at is a free item and
handle that accordingly.
The Doxygen "Modules" page is not very illuminative, as different parts
of the API are mixed together and not all parts are included.
Try to address this:
Put all parts of the public API to some Doxygen group, usually one group
per header file. Use short, systematic names.
Make these groups sub-groups of a few top-level groups, roughly
corresponding to the different logical parts of the API (core, impl,
stream, filter, spa, utilities).
check if a node has AUX channels and mark it as unpositioned in that
case.
If the peer node we need to link to has unpositioned channels, don't try
to configure the node for the unpositioned layout but instead configure
it to its default format and link the ports one by one, as many as there
are.
This is mostly for Pro-audio devices. It does not make sense to
try to remix a stereo stream to 18 channels. Most likely the pro-audio
card does not have 18 speakers connected and we would not known how to
remix anyway because the channels don't have a position. So, just take
the 2 channels and link them to the 2 first AUX inputs, which is usually
more correct and mimics what other players do when outputting to JACK.
If a specific remapping needs to be done for the pro-audio card, it
needs to be configured with a virtual device.
Output ports share the same buffers on all mix outputs and the buffers
are stored in a special mix area with id SPA_ID_INVALID.
The special mix area does not have the peer_id of the link, we need to
get that from the non-shared mix area.
This fixes some invalid peer port-id values in the set_mix_info event.
Make it possible to let a plugin suggest a samplerate for the filter.
Make the convolver suggest the samplerate of the IR file anf use that
if nothing else is specified in the config.
Fixes#1659
module-zeroconf-discover loads module-pulse-tunnel for each entity
exposed on the network. Previously, however, the destroy event
of the loaded pulse-tunnel modules were not handled.
This resulted in a use-after-free because both `pw_context_destroy()`
and `module-zeroconf-discover.c:impl_free()` tried to destroy
the pulse-tunnel modules. The reason for that is that since
1de16afc40 the modules
are prepended to the module list of the context, not appended,
therefore modules are destroyed in LIFO order, thus the pulse-tunnel
modules were destroyed before the zeroconf-discover module that
loaded them.
Fix that by handling the destroy event of the loaded pulse-tunnel
modules.
Fixes#1653
Where pipewire and friends are started via socket activation,
a PA client connection to the pulse socket triggers
pipewire-pulse.service. That in turn triggers pipewire.service through
Wants/After and once that is started up, pipewire-pulse actually
starts up.
At the same time, pipewire-media-session or wireplumber are started
through WantedBy/after in the respective service files.
Depending on which leg the race condition got out of bed with today,
pipewire-pulse may be finished before the session manager has set up the
graph and the PA client doesn't see any devices.
Fix this by adding a dependency on the session manager in
pipewire-pulse, installed via an Alias so media-session and wireplumber
can install the same alias. Wants is a light dependency, so for the case
where it doesn't exist we fall back to the current behavior anyway.
This doesn't remove the race condition since systemd may deem the
session manager to have started before the graph is set up, but it
should reduce the occurances.
The disadvantage here: only one Alias will be installed by systemd, so
first-come, first-serve in the case of both media-session and
wireplumber being installed.
See #1553
Without this, a journal entry merely looks like this:
Stopping Multimedia Service ...
Which is obviously terrible from a branding perspective but also makes
it harder for users to figure out what process was responsible for this
entry.
Media-session itself uses ms.core, there are only two files that could
have a sub-topic but right now they don't use it (match-rules and
metadata).
The modules use the ms.mod.* namespace, so it's trivial to filter on
those.
This is more complicated than a normal module because we have two
logging topics: mod.protocol-native and conn.protocol-native for wire
messages. Because the latter use spa_debug (through spa_debug_pod) we
need to #define our way around so those too use the right topics.
Note that this removes the previous "connection" category, it is now
"conn.protocol-native" instead.
pw_log_log/logv now go through the topic-based logger using the
"default" topic. Log topics themselves can be allocated by the call
sites. The simplest way to use a topic from e.g. a module:
PW_LOG_TOPIC_STATIC(mod_topic, "mod.foo");
#define PW_LOG_TOPIC_DEFAULT mod_topic
...
void pipewire__module_init() {
PW_LOG_TOPIC_INIT(mod_topic);
...
}
With the #define all pw_log_foo() are now routed through the custom
topic. For the cases where the log topic must be specified, a
pw_logt_foo() set of macros is available.
Log topics are enabled through the PIPEWIRE_DEBUG environment variable
which now supports globs, e.g. PIPEWIRE_DEBUG="*:I;mod.access:D"
to enable global INFO but DEBUG for the access module.
Namespaces documented are "pw", "mod" and "conn", for pipewire-internal
stuff, modules and connection dumping. The latter is special-cased to
avoid spamming the log files, it requires an expcit "conn.<glob>"
pattern to enable.
The "default" topic always exists and is the fallback for any
pw_log_foo() invocation that does not use a topic.
Previous commit 69e935e unconditionally called pw_log_set_level() after
the option parsing. If pw_init() changed the logging level based on
PIPEWIRE_DEBUG, we'd now overwrite that change.
Call pw_log_set_level() only if -v is actually given on the commandline.
This means a commandline option will override PIPEWIRE_DEBUG if set but
that is intended.
Fixes 69e935e8a4
Use a global lock to serialize concurrent pw_init calls.
Use a global lock to protect the global registry. With the alsa api,
multiple threads could open the device and create streams and
load/unload plugins.
See !942
The previous code had alsa optional if pipewire-alsa was on
auto/disabled bug failed later with missing alsa if media-session was in
the session manager array. Which it is by default.
Fixes#1632
If the device doesn't have an active Route, also check the EnumRoute to
see if there is something available. If nothing is available, also avoid
selecting this node.
Fixes#1624
For default nodes, that are explicitly configured, skip the route check.
This makes it possible for the user to select a non-available node
as the default still.
Fixes#1624
When we need to remove all items, copy the storage to a temporary
array and clear the storage.
When one of the callbacks would add a new item to the storage it would
operate on the new empty storage and the loop to iteratively clear
subjects would be able to complete.
Fixes#1622
It seems not uncommon that people have not properly configured ofono
running, which results to loss of HFP/HSP functionality. It's less
surprising if the backend selection is fixed in the configuration file,
and (by default) does not depend on running services.
Add a configuration file option for selecting HFP/HSP backend, and set
the default value to the native backend. Emit warnings if conflicting
backend services are detected to be running.
Also cleanup hfp/hsp backend handling a bit, now that it's mostly
abstracted behind an interface.
It's not really the responsibility of the session manager to load the
bluez5 device quirks, and it's easier for eg. Wireplumber if it doesn't
need to do it.
Move loading bluez-hardware.conf to be the responsibility of the bluez5
spa plugin, similarly as the alsa plugin deals with the ACP database.
Put the configuration to share/spa-0.2/bluez5, mirroring the plugin
directory structure in lib/spa-0.2/bluez5.
When the memory is removed, clear the node io areas so that it doesn't
accidentally get reused.
Fixes a crash in cheese when the node is stopped and then resumed.
This makes it easier to figure out if a particular module was missing
from the build. Example output:
Optional Modules
rt : YES
rtkit : YES
portal : YES
pulse-tunnel : YES
zeroconf-discover : YES
roc-sink : NO
roc-source : NO
When the node support transport sync. That is, when it will clear the
pending_sync flag from its activation area when it completed a new
seek.
Before this patch, the pending sync was always automatically cleared,
which broke some applications that are time masters such as bitwig.
Fixes#1589
Use the core.info clock rate as the default sample rate as soon as the
manager exposes the core object. Otherwise the default sample rate is 0
until someone calls GET_SERVER_INFO, which as a side effect sets the
default sample rate.
Fixes issues with sinks not appearing right away.
Fixes#1588
Allow one of "XEWIDT" to refer to none, errors, warnings, info, debug
and trace, respectively because they're immediately recognizable. Well,
except maybe the X.
PIPEWIRE_DEBUG="I" is equivalent to PIPEWIRE_DEBUG="3" for example.
When none of the nodes have a valid passthrough format, don't check if
passthrough is possible.
Without the check, it is possible that a node has a common format with
the peer that is not a passthrough format, like a raw audio format.
Fixes#1587
Some applications might expect the process function to run concurrently
with the callbacks. PipeWire tries to avoid this by using a lock for the
duration of the process callback. Make an option to disable this.
See #1576
When the node is suspended, don't take into account the lock-quantum
settings or else the graph would not want to change to the requested
quantum of the node.
Say we have a jack node with node.lock-quantum = true and
node.latency=256/48000. When it joins the graph and is suspended, the
lock-quantum is ignored and the node.latency is set on the graph.
After that, the lock-quantum ensures the graph quantum doesn't change
anymore until the node is suspended.
When we move a node from one driver to another, move the quantum and
rate if the target driver was idle so that we can mostly continue
uninterupted until a quantum/rate change is calculated.
When the driver is going to be idle or not running, avoid updating
the quantum.
This is mostly when a node is moved to another driver. Changing the
quantum of the old driver would have the clients briefly see the useless
quantum before being moved to the new driver.
default-session-manager is only used in the pw-uninstalled.sh developer
script. c25cec230c added the ability to
use the system-installed wireplumber but other than that this option is
largely superfluous.
Drop it and pick whichever the first entry to session-manager is. For
the vast use-case of either MS or WP this will just work fine and for
the niche case of building both SMs one just needs to make sure the
order is as desired.
And in the case of no session manager, the config line to start the SM
is now commented out.
The sources are used by the documentation, so rather than duplicating
the checks for whether to build it or not, just define it as
always-present empty array and fill it when needed.
Otherwise we get a meson error if media-session is disabled but
documentation is enabled.
Right now, meson -Dsession-managers=wireplumber will fail the build
because the default session manager option is set to media-session - and
if that isn't being built we error out.
Use an 'auto' value instead, selecting the first session-manager in the
list as the default one.
We have -Dsession-managers and -Ddefault-session-manager, the latter is
currently only used for pw-uninstalled.sh. Let's adjust the error
message to use "default" so it's a bit easier to understand by this may
fail with -Dsession-managers=wireplumber.
When multiple links are created at the same time for the same port, we
get into a race where multiple links will try to set a format
asynchronously and eventually break the links. Avoid this by marking the
port as busy for as long as an async format or buffer is pending and
avoid starting new link negotiation when one of the ports is busy.
This problem was observed when ardour6 tries to link all device capture
ports to its single monitor port.
For the stream group, we break into the three components we write out
and print those.
For the IPv6 address printing inside [], we can make this a condition on
the printf statement.
Change codec factory names to api.codec.bluez5.*, so that they won't
conflict with old config file lib name rules for api.bluez5.*
Specify the fallback library name when loading the codecs, so that it
works without the rules in config files.
Each dictionary needs to fully match but out of the dicts we have, only
one needs to match to apply. Reword that for clarity.
Also document regex vs normal string comparison vs the magic null
string.
Make easier to package A2DP codecs separately, by splitting each to a
separate SPA plugin. Adjust the code to not use a global variable for
the codec list.
The A2DP SPA interface API is in the bluez5 private headers, and not
exposed in installed SPA headers, as it's too close to the
implementation.
Instruct the policy to not configure audio adapter nodes in DSP mode. Instead,
Device nodes will always be configured in passthrough mode, and client nodes
will be configured in convert or passthrough mode depending on whether the
client format matches the device format or not.
The current _info_update() methods will always reset the change_mask in
the new info structure.
This causes problems if multiple updates are applied to the info before
the rescan in the session manager of pulse-server is excuted. The first
update is cleared and this causes the session manager to sometimes miss
the state changes of nodes and fail to suspend them.
Add a new method to merge with optional reset of the various
introspection info structures. We can use this instead and simply
accumulate all changes until the rescan code has processed all changes.
When we destroy a node that still has another driver, recalculate the
graph so that the driver has a chance to idle.
This can happen when we add an inactive node to the driver and then
destroy the node, like for jack clients.
Make sure we always suspend before reconfiguring a device.
Put the node and the device in passthrough mode when requested. Move
back to DSP mode after the node is unlinked.
Parse the exclusive flag of a stream once when the node info changes.
Use a new variable 'passthrough' to remember the current state of
a node and the peer.
Parse non-raw formats as well.
Check if two nodes can passthrough by intersecting the EnumFormat
params. If it is possible, configure the node for passthrough.
Don't try to reconnect nodes in passthrough.
Fail if we can't find a node compatible with passthrough.
See #629
Just like the latency, move the codecs to the device Route param.
This way, it is easier for the session manager to save and restore
the codecs as part of the Route settings.
If a program using pipewire-alsa calls snd_pcm_close() immediately after
snd_pcm_prepare() without reading or writing any data the client node
may be removed before the session manager can link it, which would
result in the following log warnings:
can't link 35:40 -> 43:48: link-factory: unknown input port 48
error id:25 seq:11467 res:-22 (Invalid argument): link-factory: unknown input port 48
can't link 35:41 -> 43:46: link-factory: unknown input port 46
error id:16 seq:11468 res:-22 (Invalid argument): link-factory: unknown input port 46
We start with setting the visitied flag on the driver. Still follow the
links to other visited nodes because it might make them active. for
example, adding a link between two midi ports should make the midi
driver running so that data flows between the ports.
See #1559