Commit graph

2580 commits

Author SHA1 Message Date
Wim Taymans 6c3c88f9d3 audioconvert: handle follower EnumFormat changes as well 2021-09-01 13:22:57 +02:00
Wim Taymans 774db99d12 alsa: emit params using the user flags
Use the user field to tag changes in params, toggle the serial flag when
emiting the port or node info.
2021-09-01 13:22:52 +02:00
Wim Taymans ab3e265b2c alsa: emit param changes correctly
Use the param user field to tag changes in the params.
codec changes emits an EnumFormat and Props change.
Accumulate various param changes and emit them together.
2021-09-01 13:22:47 +02:00
Wim Taymans 01f640709e alsa: always list PCM as iec958 codec
Always put PCM as the supported format for iec958.
Only accept iec958codecs for iec958 capable nodes.
2021-09-01 13:22:39 +02:00
Wim Taymans 71055dce73 alsa: handle excessive delay values gracefully
When we read an excessively large delay value, clamp it to twice the
delay so that we don't set our timeout to something too far in the
future.
2021-08-31 12:38:18 +02:00
Wim Taymans 09ee977141 alsa: cache UCM config
ALSA has problems with creating more than 8 configs per card so cache
the config per card and reuse it.

Fixes problems with no devices after logging out and in again because
ALSA can't create UCM profiles anymore.

See #1553
2021-08-30 17:36:11 +02:00
Pauli Virtanen b057c9166d bluez5: don't try to autoconnect same device via multiple adapters
If you use multiple BT adapters, it's annoying that PW tries to
autoconnect to the device via all available adapters, and you end up
with multiple connections to the same device (which does not necessarily
work).

Avoid this by autoconnecting with only the first adapter that sees the
device.
2021-08-29 16:34:41 +03:00
Pauli Virtanen 63ba9f98ba bluez5: don't create aptx-ll/faststream sink endpoints
We don't currently implement encoding for the duplex channel
for these codecs, so they are not fully functional as A2DP sinks,
and their main use is anyway with headphones.

Also, the number of endpoints in BlueZ appears to be limited, and
appears to be counted across all adapters.  Unclear whether this comes
from AVDTP limitation, but currently plugging in a second BT adapter
causes the second media application registration to fail.  This change
reduces the number of endpoints enough so that registration succeeds for
two adapters.
2021-08-25 20:58:15 +03:00
Wim Taymans 743aaa3dbd audioconvert: don't just copy the converter flags
We need to manage our own flags based on the direction of the follower.

We also need to make sure we only clear the NEED_CONFIGURE flag
after we are actually configured, not just when we configured our
internal converter.

See #1548
2021-08-25 15:11:54 +02:00
Wim Taymans 9dbfa63193 audioconvert: silence an info debug message 2021-08-23 17:44:56 +02:00
Wim Taymans b0a9945ed0 alsa: only enable PCM iec958 codec when configured
Rework the codec enumeration a little and don't automatically enable PCM
as the code unless requested by the user.
2021-08-23 17:07:17 +02:00
Wim Taymans 2e6f80f808 alsa: only list IEC958 codecs when iec958 or hdmi device. 2021-08-23 11:58:29 +02:00
Wim Taymans 437275460c alsa: add set_format for iec958 formats 2021-08-23 11:31:52 +02:00
Wim Taymans 5feb88575c spa: add helpers to parse and create iec958 formats 2021-08-23 11:31:52 +02:00
Wim Taymans 9dfe35b17c alsa: add enumeration of iec958 format
For hdmi and iec958 devices, enumerate the iec958 formats and
codecs. Initially only PCM is supported as a codec but with
a property or an init option, the list of codecs can be dynamically
configured.
2021-08-23 11:31:52 +02:00
Wim Taymans 8147772cf5 spa: add definitions for IEC958 (S/PDIF)
Add Format subtype and codec property.
Add codecs to include in the format codec property.
Add property to configure elements with supported codecs.
Add type info.
2021-08-23 11:31:52 +02:00
Wim Taymans 0af0cceca2 audioadapter: use format directly when reconfiguring
There is no need to parse and then recreate the format.
2021-08-23 11:20:52 +02:00
Wim Taymans 2427eeae2b audioconvert: reset converter format as well
Reset the format of the converter so that when we go back to DSP mode,
we don't expose the old ports again.
.
2021-08-23 11:20:52 +02:00
Wim Taymans 8f7a972a48 audioadapter: fix passthrough switching some more
Remove the follower ports when leaving passthrough, add the DSP
ports.
Set up the link_io between follower and convert again when leaving
passthrough.
2021-08-23 11:20:40 +02:00
Wim Taymans 9090f19b0a audioconvert: improve passthrough mode
When in passthrough mode, use the position io to update the
io_rate_match fields for the follower. This makes it possible for the
follower to also provide the right amount of data when the converter
is not selected in passthrough.

Add an option to configure the converter in None port config where it
removes all the ports. We can use this when removing the converter to
make sure all it's ports are removed.

When we remove the converter, make sure we expose the follower ports
directly so we can use them for passthrough.
2021-08-23 11:11:11 +02:00
Pauli Virtanen ab5fcf4a66 bluez5: boost A2DP duplex microphone volume by 20 dB
There doesn't seem to be a way to control the A2DP duplex microphone
HW volume gain, and devices sometimes have very low mic volumes.

Work around this by boosting the software volume scale by +20 dB.  If it
causes clipping, the user can just reduce the volume to bring SW gain
below 1.0.
2021-08-23 08:17:46 +00:00
Pauli Virtanen e08cdf27d5 bluez5: add FastStream codec
A2DP codec that uses SBC.  Has a duplex channel, which sends an SBC
stream back.
2021-08-23 08:17:46 +00:00
Pauli Virtanen c628975a75 bluez5: update fastream caps from bluez 2021-08-23 08:17:46 +00:00
Julian Bouzas b368bea98c audioconvert: do _port_set_param on fmtconvert if convert mode
The fmtconvert plugin does not support SPA_PARAM_PortConfig. Instead, we need to
set the format in the specific port with SPA_PARAM_Format.
2021-08-23 08:11:21 +00:00
Pauli Virtanen dedc08cdf8 bluez5: enable duplex for aptx-ll
aptX-LL sink devices may send back mSBC encoded data corresponding to
microphone input.  It appears to be enabled when the bidirectional link
is set in the caps, and the device also supports this.

Implement mSBC decoding in the duplex channel.

Tested to be working on Avantree Aria Pro.
2021-08-22 17:41:50 +03:00
Pauli Virtanen 623b6df8a2 bluez5: work around obscure issue with a2dp-source with duplex
For unknown reason the BT socket when working with A2DP "duplex" stream,
sometimes stops waking up poll when data arrives. Regardless, recv() can
read data packets from it.

To work around this, when A2DP source is in duplex mode, instead of
polling on data, we poll on a timer.
2021-08-21 20:00:52 +03:00
Pauli Virtanen eca37b58a6 bluez5: make room for a2dp duplex channel
Some non-standard A2DP codecs (FastStream/aptX-LL) have "voice duplex
channel" that can be used to provide an A2DP duplex mode.

Add support for duplex channels, accounting for the fact that the two
directions may be encoded with different actual codecs.
2021-08-21 20:00:52 +03:00
Pauli Virtanen f00ec34787 bluez5: use lower latency for aptx-ll codec
This pushes the latency to 256 samples, which still seems to work
Latency of 128 seems to be too small. (NB. the number of input samples
is also the size of packets sent in bytes)

Since pipewire clients usually use powers of two, this may be the
smallest value that makes sense.
2021-08-18 19:55:22 +00:00
Pauli Virtanen 90b62ba2b3 bluez5: add aptx-LL codec
Support the low-latency variant of the aptx codec.

The magic mostly seems to be on the device side, since the stream is the
same as standard aptx, but latency is smaller even if stream/packet
sizes are the same.

Sound output latency is noticeably less than with the standard aptx.
Tested on Sennheiser HD 250 / Avantree Aria Pro.

The codec in principle also supports bidirectional duplex streams,
but that is not implemented here.
2021-08-18 19:55:22 +00:00
Pauli Virtanen 73994feda9 bluez5: allow same codec ID to correspond to multiple endpoints
The codec IDs are user-visible properties.

Some codecs can have multiple endpoints (e.g. different caps struct, or
multiple possible vendor ids), so this detail should not leak to the
user.
2021-08-18 19:55:22 +00:00
Pauli Virtanen fc2fe12794 bluez5: update a2dp-codecs.h from bluez with aptx-ll caps 2021-08-18 19:55:22 +00:00
Julian Bouzas cad64bc992 audioadapter: add support for passthrough mode
Allows audioadapter to behave as its follower
2021-08-17 16:01:10 +00:00
Wim Taymans 49c1c0386f pw-cat: fix raw read
raw read needs bytes, so use the stride to calculate it from frames.
Move ulaw/alaw to packed formats.
2021-08-17 17:56:31 +02:00
Wim Taymans e9679afb12 audioconvert: support alaw/ulaw conversion 2021-08-17 17:33:29 +02:00
Wim Taymans df9f79d869 audioconvert: add converstion to and from alaw/ulaw 2021-08-17 17:32:25 +02:00
Wim Taymans d0d7f2f20b spa: add alaw and ulaw defines
Add alaw and ulaw as raw formats.
2021-08-17 17:31:03 +02:00
Wim Taymans fd82da938a audioconvert: add more format support
Add support to endian conversion as well.
2021-08-17 15:03:03 +02:00
Wim Taymans a5e2e955d2 audioconvert: add more conversions
Add the other endian conversions.
2021-08-17 14:45:00 +02:00
Wim Taymans c39d374ca8 alsa: hook up latencyOffsetNsec in ALSA sink/source
This property is exposed on the device Route and forwarded to the
nodes. It then configured the process_latency.ns field, which
influences the reported port latency.

This makes it possible to change the internal port latency on the
sink and source with pavucontrol and tweak the synchronization to
compensate for internal latencies in the device.
2021-08-17 11:57:12 +02:00
Wim Taymans 391465d1cd audioadapter: emit Latency param changed when follower changed
When the follower port Emits a latency param changed, our reported
latency also changes so we need to emit the changed notify.
2021-08-17 10:49:05 +02:00
Wim Taymans a2083d12d4 alsa: add params to set default internal latency 2021-08-17 10:15:40 +02:00
Wim Taymans 6d196b1d11 alsa: use ProcessLatency param to get and set internal latency 2021-08-17 10:04:12 +02:00
Anukul 6c9f342775 Update 90-pipewire-alsa.rules --> add rule for gsx 1200 2021-08-16 10:04:49 +00:00
Pauli Virtanen 672223d055 bluez5: avoid poll busy loop in a2dp-sink
Disable flush polling when we don't have data ready to write to the
socket (or socket send failed). This avoids entering into a poll busy
loop, which may result to rtkit killing the process.
2021-08-13 23:37:48 +03:00
Pauli Virtanen 5071589aea bluez5: enable SBC-XQ codec by default, if allowed by quirks
Enable SBC-XQ by default, and move it at the end of the codecs list, so
that bluez does not connect to it automatically except when it is the
codec used previously.

When the codec is disabled by quirks, it won't appear in the codecs
list, and so can't be selected by user (and so won't be connected
automatically).

However, since SelectConfiguration does not carry information which
device is in question, we cannot prevent BlueZ connecting to the codec
even if it's disabled for a specific device. If the "impossible" occurs
regardless, we won't reject the connection and the profile will be shown
as the generic "A2DP" one.  If the sound is garbled, the user can select
some other profile that works.
2021-08-13 18:45:16 +00:00
Zsombor Welker f5850af4d8 bluez5: handle XAPL battery level per Apple Guidelines
Corrects the handling of AT+XAPL Apple extensions to send
`+XAPL=iPhone,2` instead of `+XAPL: iPhone,2` based on Apple's
documentation.

Replaces magic numbers with enum values.

[Accessory Design Guidelines](https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf)
2021-08-13 10:30:36 +02:00
Zsombor Welker a1777d00e3 bluez5: correct parsing order for HF indicator 2 based battery status
Since "AT+BIND=" was before "AT+BIND=?", the seconds statement was never
matched.
2021-08-12 21:13:22 +02:00
Sanchayan Maity be6824cb15 bluez5-device: Set device intended role for HFP 2021-08-12 18:54:46 +00:00
Zsombor Welker f87942027f bluez5: report HF indicator 2 based battery status
HF indicator 2 (see [assigned-numbers], Hands-Free Profile) is able to
report battery percentage at 1% intervals (in range [0, 100]), contrary
to the `+XAPL` `+IPHONEACCEV` extension which only supports 10%
increments.  This does not guarantee increased granularity however, as
peers may still be limited to imprecise battery measurements internally
or round to coarser percentages.
Supporting both additionally broadens the range of devices for which PW
can report its battery level.

[assigned-numbers]:
https://www.bluetooth.com/specifications/assigned-numbers/
2021-08-12 18:45:44 +00:00
Wim Taymans 44c6ec146e filter-chain: parse config options
Remove LADSPA dependencies, only use it in ladspa_plugin.c
Parse convolver config, like filename
2021-08-11 21:33:48 +02:00
Wim Taymans 0a5a4c046d alsa: Free global state
We need to do this or else newly plugged devices might not load.

It does not seem to harm UCM config on my machine, so this reverts
3d372424cc

See #1478
2021-08-10 11:25:41 +02:00
Wim Taymans b7162d2c09 alsa: free alibpref after use 2021-08-10 11:14:15 +02:00
Wim Taymans bdc164f509 udev: fix behringer UMC202 usb device id
See https://usb-ids.gowdy.us/read/UD/1397/0507
2021-08-10 10:45:47 +02:00
Wim Taymans 35d7ad5529 acp: compare the HW volume against stored HW volume
When we store the real_volume we get a hardware_volume as stored
in the mixer and a residual software_volume.

When we read the volume from the card, we need to compare this against
the hardware_volume we stored to check if something changed, not
against the real_volume that also contains the leftover software_volume.
2021-08-09 14:18:20 +02:00
Nils Tonnätt dd12910769 Revert "[Meson] Fix all deprecation warnings"
This reverts commit f7e1175ef0.
2021-08-08 19:18:40 +00:00
Nils Tonnätt f7e1175ef0 [Meson] Fix all deprecation warnings 2021-08-06 07:56:16 +00:00
Wim Taymans a9fecd50ed bluez5: improve debug
Log the errno when something is wrong.
2021-08-05 15:41:50 +02:00
Wim Taymans e3a643bffe bluez5: remove useless pod_frame() call 2021-08-05 15:41:26 +02:00
Peter Hutterer 5ae528c957 spa: move the log version define so it matches other implementations
Makes it match up with the comment now too
2021-08-05 09:51:40 +00:00
Peter Hutterer 1244229faf spa: document the spa_hook interface with an example 2021-08-05 09:51:40 +00:00
Peter Hutterer d8f6033b9d spa: document the spa_interface and how it works 2021-08-05 09:51:40 +00:00
Peter Hutterer 56acf766a5 doc: split the spa_interfaces out as separate group from the spa_hooks 2021-08-05 09:51:40 +00:00
Wim Taymans c6dc7e98fd dbus: protect against NULL data
Make sure we don't accidentally unref a NULL data.
2021-08-03 19:11:15 +02:00
Daniel Stone bf112940d0 spa: Only test __cplusplus value when it's defined
In higher warning levels, clang complains about testing the value of
__cplusplus when it's not defined.
2021-08-03 15:43:59 +00:00
Peter Hutterer 51a177eb6d tree-wide: replace strstr(a, b) == a with spa_strstartswith()
spa_strstartswith() is more immediately understandable.

Coccinelle spatch file:
	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) != E1
	+ !spa_strstartswith(E1, E2)

	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) == E1
	+ spa_strstartswith(E1, E2)

Applied to the tree except for alsa/acp/compat.h because it looks like
that header is still mostly as-is from PA.
2021-08-02 08:24:21 +00:00
Huang-Huang Bao 9f2d6d6d28 bluez5: fix rounding error on hardware volume conversion
Ensure the conversions between spa_bt_volume_linear_to_hw and spa_bt_volume_hw_to_linear are reversible when
operating on hardware volume.
2021-07-30 08:46:14 +00:00
Simon Ser 73217818cc spa: document enum spa_video_format
References: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1470
2021-07-30 07:29:44 +00:00
Neal Gompa 1216371f8c bluez5: Use libfreeaptx instead of libopenaptx
libfreeaptx is a fork of libopenaptx prior to the dubious licensing
situation was introduced to the library.

As it's fully API compatible, let's use that instead for those who
want to use aptX support.

The library source is available at https://github.com/iamthehorker/libfreeaptx
2021-07-29 15:22:04 +00:00
Wim Taymans 2dabd337dc audioconvert: clear negotiated rate
When we clear the format on the non-dsp port, set the rate back to
0 so that we can negotiate a new rate if needed.
2021-07-29 13:35:41 +02:00
Peter Hutterer 4e90760155 spa: silence a doxygen warning
warning: documented symbol 'spa_log_error foo' was not declared or defined.
2021-07-29 14:03:00 +10:00
Wim Taymans 44583367db pod: add prop option to avoid fixation
Add a DONT_FIXATE flag to spa_pod_props. The flag avoids fixation
of the property by spa_pod_fixate().

When filtering properties, 'and' the flags together in the filtered
property. This mostly preserves the merged property flags. It also
merges the DONT_FIXATE flags so that when both sides can handle
the non-fixated result, it will be returned.

This can be used to let PipeWire filter out the common property
fields and leave the final selection of fields to the producer. This can
only work when the final selected field can be transported in some
other way than the format param, like on the buffer fields or in
metadata. One use case is negotiation of the DMABUF modifiers.

See #1084
2021-07-28 11:03:26 +02:00
Peter Hutterer 49f3d5842e test: replace all spa_assert() macros with spa_assert_se()
These are tests, we never want those to be optimized away.
2021-07-27 10:24:44 +10:00
Peter Hutterer 63d833dabf spa: use spa_assert_se() for bugs in the util string functions
These are programming bugs that should never happen, so let's always
abort.
2021-07-27 10:24:44 +10:00
Wim Taymans 78f52a7073 loop: avoid corruption of ringbuffer
The ringbuffer can't be written to from multiple threads.

When both the main loop and data thread do _invoke, they both write to
the ringbuffer and cause it to be corrupted because the ringbuffer is
not multi-writer safe.

Doing invoke from the thread itself is usually done to flush things out
so we really only need to flush the ringbuffer and call the callback.

See #1451
2021-07-26 11:39:48 +02:00
Pauli Virtanen 606108f409 spa: add spa_strstartswith 2021-07-24 14:36:03 +03:00
Javier Martinez Canillas 76cb5c1169 libcamera: remove unused buffer variable in LibCamera::stop()
To fix build warning about a variable being unused in LibCamera::stop():

[1/2] Compiling C++ object spa/plugins/libcamera/libspa-libcamera.so.p/libcamera_wrapper.cpp.o
../spa/plugins/libcamera/libcamera_wrapper.cpp: In member function ‘void LibCamera::stop()’:
../spa/plugins/libcamera/libcamera_wrapper.cpp:531:58: warning: unused variable ‘buffer’ [-Wunused-variable]
  531 |                 for (const std::unique_ptr<FrameBuffer> &buffer : this->allocator_->buffers(stream)) {
      |                                                          ^~~~~~
2021-07-23 07:59:10 +00:00
Javier Martinez Canillas 5471a0018b libcamera: fix no-longer existent <libcamera/buffer.h> header inclusion
The SPA plugin is including a <libcamera/buffer.h> header file, but this
got renamed to <libcamera/framebuffer.h> to match the defined class name:

../spa/plugins/libcamera/libcamera_wrapper.cpp:52:10: fatal error: libcamera/buffer.h: No such file or directory
   52 | #include <libcamera/buffer.h>
      |          ^~~~~~~~~~~~~~~~~~~~

Fixes #1435
2021-07-23 07:59:10 +00:00
Pauli Virtanen cb10d87bb8 bluez5: handle no data written to sco socket
If socket write results to EAGAIN/EWOULDBLOCK or rx data starts late,
spa_bt_sco_io_write may return 0, and we should give up and skip ahead
(and not loop in RT thread with very small timeout).
2021-07-23 07:58:39 +00:00
Wim Taymans a33df863b4 acp: sync with pulseaudio 2021-07-21 13:11:17 +02:00
Wim Taymans 3d372424cc alsa: don't free alsa global info for each node
Don't clear the global config or else we might lose the UCM state.

See #1437
2021-07-21 12:18:43 +02:00
Wim Taymans 08e34a99fd acp: use AUX channels for PRO audio profile
That way we can actually use the channel names to make custom loopback
mappings.
2021-07-21 11:27:09 +02:00
Wim Taymans 1ad54e8a26 spa: add 64 AUX channels
Make 64 AUX channels instead of using the CUSTOM range for them.
2021-07-21 11:25:43 +02:00
Wim Taymans a91502b3e0 loop: improve invoke avail check
First calculate the size of the aligned payload and then check if
we can fit this aligned payload in the remaining space in the
ringbuffer.

Otherwise we might be able to fit the item + payload in the remaining
space but then place the alignment bytes at the begginning, which would
break alignment of the next invoke_item struct.
2021-07-19 10:12:15 +02:00
Wim Taymans 7f4fa64291 loop: Fix crash because of overflow
Also check if there is enough space to write the payload bytes.

We check if there is enough space for the invoke_item structure first.
Then we calculate how much bytes we need to use for the payload but we
fail to check if we can actually write that much data, risking
overwriting existing data from the ringbuffer and causing a crash later
when we try to jump to invalid memory.

Add some more comments.
2021-07-19 09:53:23 +02:00
Peter Hutterer 257fd83f65 Replace Pipewire with PipeWire for consistency
And set up a CI job to check for that.
2021-07-14 16:56:54 +10:00
Julian Bouzas 4732aea0c6 spa: clear all devices when udev monitor stops
Otherwise the udev device leaks when restarting the monitor
2021-07-13 17:03:30 +00:00
Julian Bouzas 7bf50fd8ed spa: alsa: acp: free device name in add_pro_profile 2021-07-13 17:03:30 +00:00
Pauli Virtanen 0c9f0210ed bluez5: sco-io: start writing only after the packet size is known
The kernel-provided SCO write MTU is currently never the correct packet
size for writing, so don't try to use it. Some adapter firmware (eg.
BCM20702A0 0b05:17cb) appears in practice sensitive to the alignment of
the msbc frames, and writes with wrong packet size break things but only
on certain headsets. For other adapters, this doesn't appear to matter.
2021-07-11 16:14:03 +00:00
lsde 579481ab70 Use correct RTP payload type for aptX, LDAC,SBC
According to the A2DP spec, the payload type should be
set to a number between 96 and 127.
This is fixed for AAC codec, but not the rest.

Original PulseAudio issue: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/591
2021-07-11 16:10:20 +00:00
Julian Bouzas 2dcdc80030 spa: alsa: acp: fix memleak when destroying card profles 2021-07-08 11:08:00 -04:00
Wim Taymans 8184d4576a handle snprintf errors better 2021-07-06 17:56:04 +02:00
Wim Taymans d88e8edd11 avoid shadowing arguments 2021-07-06 17:55:16 +02:00
Wim Taymans acad6b8f2b audioconvert: use the right variable
Keep the result of the follower in res2, fail if we could not set the
properties on both the follower and the converter.
2021-07-06 16:28:57 +02:00
Wim Taymans 9fa72f22cb thread: fix compilation 2021-07-06 16:20:05 +02:00
Wim Taymans 1ff535e6eb spa: move thread to SPA support
It can be more generally useful eventually.
2021-07-06 15:48:20 +02:00
Wim Taymans 3a879e8b1a audioconvert: fix s24_32 to float
s24_32 needs to be sign extended before converting to float because the
upper bits are undefined and might be anything.

Fixes #1393
2021-07-06 12:42:39 +02:00
Konstantin Kharlamov 252816f757 bluez5: fix wrongly typed started field in spa_bt_sco_io
This is a bitfield, but it's unclear what it achieves since this is the
only member of a bitfield, so it may be more efficient to just make it a
bool.

Fixes a LGTM warning:

    Bit field started of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type.
2021-07-06 00:07:21 +03:00
Konstantin Kharlamov dea1a0bee2 audiotestsrc: convert sizes to const size_t
`sizes` members participate in multiplication and subsequent assignment
into port->bpf, which has size_t. So LGTM rightfully complains, there's
a chance the multiplication will overflow before the assignment happens.

Should have no influence on performance since 64 bit multiplication is
as fast, and since the struct is constified, a wise compiler should make
sure it doesn't take excess space either.

Fixes LGTM warning:

    Multiplication result may overflow 'unsigned int' before it is converted to 'size_t'.
2021-07-05 23:30:45 +03:00
Konstantin Kharlamov ab71d2c3cb audioconvert: fix potential NULL reference in resample_native_init
That was found by GCC fanalyze pass. Fixes warning:

    ../spa/plugins/audioconvert/resample-native.c: In function ‘resample_native_init’:
    ../spa/plugins/audioconvert/resample-native.c:385:9: warning: dereference of NULL ‘0B’ [CWE-476] [-Wanalyzer-null-dereference]
      385 |         spa_log_debug(r->log, "native %p: q:%d in:%d out:%d n_taps:%d n_phases:%d features:%08x:%08x",
2021-07-05 19:35:06 +03:00
Wim Taymans 0b758a2301 alsa-seq: fix off-by-one for event offset
The event offsets need to go from 0 to quantum-1 to be valid to the
current midi event buffer.

Fixes #1395
2021-07-05 16:25:11 +02:00
Wim Taymans 35194d6de0 node-driver: remove timers when not a driver 2021-07-01 12:28:18 +02:00
Wim Taymans 620b34cd6b null-audio-sink: only start timers when driving
Check if we are driving or following and only start the timers when we
are the driver of the graph.

Ready events from non-drivers are not really a problem because they are
ignored. They only cause unnecessary wakeups in the graph.
2021-07-01 11:33:21 +02:00
George Kiagiadakis 36c7e820d8 test nodes: make the timerfd non-blocking
Relates to #1377
2021-07-01 11:52:35 +03:00
George Kiagiadakis 5aa9c95390 node-driver: make the timerfd non-blocking
Relates to #1377
2021-07-01 11:52:28 +03:00
George Kiagiadakis c633004bf3 null-sink: make the timerfd non-blocking
Fixes #1377
2021-07-01 11:37:01 +03:00
Barnabás Pőcze f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Barnabás Pőcze 48dbb4da3c spa: bluez: native: do not use spa_aprintf()
Instead of spa_aprintf(), convert `rfcomm_send_{cmd,query}`
to take a printf-style format string.

Furthermore, handle overflows and return errors from
`rfcomm_send_{cmd,reply}`. And make those functions
take an rfcomm as argument instead of any spa_source.
And match conversion specifiers to the actual types
in format strings.
2021-06-30 14:44:08 +02:00
Niklāvs Koļesņikovs e062c4d8de meson.build: adds summary() to optional programs 2021-06-29 17:23:37 +00:00
Wim Taymans ae89ae093e acp: strip UCM alibpref from mapping
Strip the alibpref from the device string in the mapping name. This
name is used to generate the node name eventually and we don't want
this random identifier in it.

Fixes #1362
2021-06-29 17:43:00 +02:00
Wim Taymans 82f2e85a0f fmt-ops: fix neon stereo resample 2021-06-28 17:20:50 +02:00
Barnabás Pőcze 84b9644ee3 spa: utils: defs: fix SPA_FOR_EACH_ELEMENT usage example
To iterate over an array of `T`, the iterator must be `(const) T *`,
so that the types are compatible when `T[]` decays into `T *`.

In the example when `struct foo *[]` decays, it becomes `struct foo **`,
which is not compatible with the the type of iterator, `struct foo *`.

Fix that by changing the type of the array to `struct foo[]`.
2021-06-28 15:07:02 +02:00
Wim Taymans d6a569620c v4l2: DmaBuf and MemFd are mostly the same
If the caller asks for MemFd, pass a DmaBuf because it is mostly
the same for v4l2.

Not very correct but it's not yet trivial to fall back to memfd.
And this way we have something to give to the clients that will work
when the client asks for MemFd or MemPtr.
2021-06-28 14:55:05 +02:00
Barnabás Pőcze d06a2e2140 spa: meson.build: look for libcamera under another name
libcamera commit ec7afef665a87eb389a5a4cb9ff35e9c24bbcc29 (2021-06-24)
changed the name of the generated pkg-config file from 'camera.pc'
to 'libcamera.pc'.

First look for the libcamera dependency under the new name 'libcamera',
and if that's not found, look for it under the older name 'camera'.

Fixes #1355
2021-06-27 18:24:15 +00:00
Pauli Virtanen 2b515b5e50 dbus: keep a ref to DBusConnection if reconnecting is not handled
Several places in the code don't handle reconnecting DBus connections
yet. In those cases, a ref to the DBusConnection handle needs to be
kept, so that there's no use-after-free if it gets freed by spa_dbus
if the connection is broken.

Adjust spa_dbus so that others keeping additional refs is safe.
2021-06-26 16:11:40 +03:00
Niklāvs Koļesņikovs de72ed5590
meson.build: adds V4L2 header and enablement reporting via summary()
Until now the 'v4l2' feature was not actually checking that its
required header has been found, this commit adds a check for
<linux/videodev2.h> and correctly reports both header status and whether
the feature itself ends up enabled (depends on libudev).
2021-06-25 15:13:07 +03:00
Niklāvs Koļesņikovs b55bafae09
meson.build: move libcamera and libdrm summary() to 'Backend' section 2021-06-25 15:13:07 +03:00
Niklāvs Koļesņikovs 38d5de789d
meson_options.txt: disable vulkan option since it's not ready for use
According to George Kiagiadakis it being set to auto is an accident,
because the Vulkan support does not [yet] provide anything useful.
2021-06-25 15:12:27 +03:00
Ivan 0a02396995 meson: Make summary() respect vulkan headers detection
Fix false positive that caused by summary() checking only for vulkan
library but not headers.
2021-06-25 11:27:31 +00:00
Peter Hutterer 0880ff9a84 spa: add spa_strendswith (copy from protocol-pulse)
Useful function, let's make it generally available.
2021-06-25 08:42:24 +00:00
Niklāvs Koļesņikovs 71d39e90ed meson: adds post meson setup/--reconfigure summary for auto features
As suggested by George Kiagiadakis, adds calls to summary() function
for each feature that is by default set to auto, so that an overview
of their effective state is printed at the end of meson setup or
meson --reconfigure command.

Currently ordering is a bit messy but tidying it up would detach
the summary() functions from the dependencies they rely on and could
be done later along with meson_options.txt re-ordering so that the
two match as much as possible.
2021-06-25 08:31:12 +00:00
Stefano Ragni 243d534476 dbus: fix bus type reported in logs 2021-06-25 08:26:00 +00:00
Wim Taymans 016f02616b json: don't escape / 2021-06-24 16:18:59 +02:00
Wim Taymans 2acf29a86c Revert "json: also escape '/' as required by JSON"
This reverts commit eb8546a682.

We don't need to escape the / according to  RFC7159
2021-06-24 16:12:47 +02:00
Wim Taymans 679df3f9d9 v4l2: implement latency get and set 2021-06-24 16:05:31 +02:00
Peter Hutterer 0f0565175e doc: rework the SPA plugin documentation
Add more info to the main SPA page and split the design vs plugin pages up,
together with some more documentation to ideally lower make this easier to
understand on a glance.

Most of the actual plugin loading documentation are unmodified.
2021-06-24 10:54:13 +00:00
Wim Taymans 48e6e41d95 audioconvert: improve latency handling
When setting the Latency parameter on one side of the converter, set
it also on the other size. We should actually implement propagating
the latency through all the elements of the converter later.

Implement latency handling on fmtconvert.

merger and splitter change latency on all ports when on port changes.

All this makes the configured and exposed latencies visible on all
ports from adapter.
2021-06-24 12:20:44 +02:00
Wim Taymans 22fe0b293a audioconvert: add some more debug 2021-06-24 12:11:38 +02:00
Wim Taymans 8ee9a7b5e5 audioadapter: latency is writable 2021-06-24 12:07:06 +02:00
Wim Taymans f03f1926e3 seq: track port latency 2021-06-24 10:04:19 +02:00
Wim Taymans 4c09eb227f alsa: rename indexes into port and node params 2021-06-24 10:03:41 +02:00
Wim Taymans 8cf5927e95 alsa: keep track of input and output latency
track and report both input and output latency.
2021-06-24 09:59:48 +02:00
Konstantin Kharlamov ed9560fb03 alsa: fix "now.tv_sec maybe used uninitialized" warnings
Fixes a number of warnings that look like this:

    In file included from ../spa/include/spa/utils/result.h:37,
                     from ../spa/plugins/alsa/alsa-seq.c:35:
    In function ‘set_timers’,
        inlined from ‘do_reassign_follower’ at ../spa/plugins/alsa/alsa-seq.c:909:2:
    ../spa/include/spa/utils/defs.h:191:39: warning: ‘now.tv_sec’ may be used uninitialized [-Wmaybe-uninitialized]
      191 | #define SPA_TIMESPEC_TO_NSEC(ts) ((ts)->tv_sec * SPA_NSEC_PER_SEC + (ts)->tv_nsec)
          |                                   ~~~~^~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c:840:28: note: in expansion of macro ‘SPA_TIMESPEC_TO_NSEC’
      840 |         state->next_time = SPA_TIMESPEC_TO_NSEC(&now);
          |                            ^~~~~~~~~~~~~~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c: In function ‘do_reassign_follower’:
    ../spa/plugins/alsa/alsa-seq.c:836:25: note: ‘now’ declared here
      836 |         struct timespec now;
          |                         ^~~

The reason for these warnings is that spa_system_clock_gettime() may
fail if a version check fails, but the code in question didn't check for
the possible fail. If it failed, then execution would continue, and the
arguments that were passed to the macro will be used uninitialized.

Fix this by checking whether function succeeded.
2021-06-22 22:42:25 +03:00
Konstantin Kharlamov 252e798ece alsa: remove unused res variable in alsa_on_timeout_event 2021-06-22 22:42:25 +03:00
Wim Taymans 79866a93cd Param: add process latency param and info 2021-06-22 16:29:29 +02:00
Pauli Virtanen b98b9e0e77 bluez5: deal with old libusb versions 2021-06-22 10:58:50 +03:00
Pauli Virtanen 9d38d375d2 bluez5: add and use quirk for broken mic HW volume
Some headsets emit AT+VGM even though +VGM commands do not actually
adjust the recording volume.
2021-06-22 10:58:50 +03:00
Pauli Virtanen 9422e76d89 bluez5: enable hw volume on all profiles, if device quirks permit it 2021-06-22 10:58:50 +03:00
Pauli Virtanen 5e0b63b149 bluez5: backend-native: use quirks + usb adapter caps for checking msbc
Use the quirks database to check whether to enable MSBC codec for each
device.

If quirks don't allow ALT1 mode for an USB adapter, check whether the
adapter has an usable ALT6 mode and disable MSBC if not.
2021-06-22 10:58:50 +03:00
Pauli Virtanen b57ae8c2a6 bluez5: add support for hardware quirk/feature database
Implement hardware quirk/feature database with pattern matching.
2021-06-22 10:58:50 +03:00
Pauli Virtanen 2c9764da1d bluez5: parse bluez vendor/product ids
It seems few devices support the Device Id via bluez.

Try to figure out vendor/product ids for usb devices also via sysfs.
Also try to figure out the adapter bus type.
2021-06-22 10:58:50 +03:00
Huang-Huang Bao ea28cb95c0 bluez5: don't autoconnect device if no profiles
Otherwise timers would be created for every bluetooth devices, even they don't have audio profiles.
2021-06-21 07:10:02 +00:00
Huang-Huang Bao db6e73895f bluez5: clean up connection status handling
Also separate device info emitting into a new function.
2021-06-21 07:10:02 +00:00
Huang-Huang Bao 3433f40cd9 bluez5: fix device connection issue if profile(UUIDs) info is delayed
Keep all types of devices, only emit device info if device has audio profiles.
Heuristically add profiles based on bluez actions so device can still be connected
even without initial UUIDs info from signal InterfaceAdded for org.bluez.Device1.

Fixes #1330
2021-06-21 07:10:02 +00:00
Pauli Virtanen b44fdf5ebb bluez5: backend-native: don't send +BCS if no codec negotiation
Fix issue with sending +BCS for CVSD even though codec negotation is not
available for the RFCOMM.
2021-06-20 19:40:00 +03:00
George Kiagiadakis 2723b0c6e2 meson: export plugin and data dirs for other projects to find them
SPA_PLUGIN_DIR is exported in pkgconfig as 'plugindir'
PIPEWIRE_MODULE_DIR is exported as 'moduledir'
PIPEWIRE_CONFIG_DIR is exported only in uninstalled environments
as 'confdatadir' (not making this public due to the possible upcoming
configuration changes in pipewire)

All variables are also exported on the meson dependency objects,
so that subprojects can find them.

Wireplumber can then find them like this:

  pipewire_moduledir = pipewire_dep.get_variable(
    pkgconfig: 'moduledir', internal: 'moduledir', default_value: '')

... and this works regardless of whether wireplumber is being
configured as a subproject or using the uninstalled pkgconfig files
or using the system installation of pipewire.

This is required in order to run wireplumber tests in the
uninstalled environment with 'meson test'
2021-06-18 19:24:28 +03:00
George Kiagiadakis 7ab5c35cad meson: declare spa_dep and override_dependency() for spa and pipewire
This allows meson subprojects (or projects using pipewire as a meson
subproject) to be able to use dependency('libpipewire-0.3') and
dependency('libspa-0.2') to find the uninstalled versions of these
libraries directly from the build dir instead of going through pkg-config
2021-06-18 17:54:18 +03:00
Wim Taymans 4aa80c7a71 splitter: we always produce output
Always set the HAVE_OUTPUT flag because we always consume the
input and produce output, either to a buffer or an error.
This makes sure processing never stalls when something is wrong
on the output side.

See #1305
2021-06-17 18:34:01 +02:00
Wim Taymans 2ad202b8e8 audioconvert: track and compensate for rate changes
Follow the rate of the _io_position area and adjust the resampler
to match. This ensures that we always process at the DSP samplerate
to the target negotiated fixed rate of the device/stream.
2021-06-17 11:11:45 +02:00
Wim Taymans 519bd342be audioconvert: don't use samplerate to negotiate
The merger and splitter use the samplerate from the _io_position
for the DSP formats so set the samplerate to 0 to make sure we
don't use it to negotiate a format with the peer.
2021-06-17 11:11:45 +02:00
Wim Taymans 7ba7179eee audioconvert: use the position rate to negotiate
When we have an io_position, use the rate as the samplerate when
negotiating.
2021-06-17 11:11:45 +02:00
Wim Taymans ed80d72d51 audioconvert: also set io_position on channelmix
Also make the channelmix node aware of the io_position so that
is can use this later to get the default rate.
2021-06-17 11:11:45 +02:00
Wim Taymans c726dd887c alsa: refactory _io_position checking
Move the code to check the position duration for changes to one
new method.
Also check for samplerate changes and adjust the resampler state
accordingly.
2021-06-17 11:11:44 +02:00
Huang-Huang Bao 4c9ac08310 bluez5: always emit node object info for dynamic node
impl_add_listener() could be called more than one time, ensure that we always emit node info
so that session manager(bluez-monitor) can receives it.

Fixes #1308
2021-06-17 07:22:46 +00:00
Barnabás Pőcze 7cecb1567d spa: tests: remove double dot from names of test files
Previously, the configured test file would be named like the following:

  spa-include-test-spa_control_control_h..cpp

fix that by removing one of the dots.

Furthermore, use the already existing `find` object instead of
calling `find_program` one more time.
2021-06-16 19:45:27 +02:00
Wim Taymans a90c86dd47 defs: reorganize the assert macros a little
Make a special Coverity version of spa_assert_se borrowed from
PulseAudio
NDEBUG now compiles the asserts to nop, except for the _se one.

See !755
2021-06-11 20:05:25 +02:00
Wim Taymans a6b687ee98 audioadapter: proxy Latency param from follower port 2021-06-10 23:42:05 +02:00
Wim Taymans 826f52344f spa: properly re-encode the keys and string values
Instead of pasting quotes around them.
2021-06-10 16:32:16 +02:00
Wim Taymans 1c513464c8 alsa: strip and add the _alibpref from device names
Strip the _alibpref from the device name, it contains a local counter
to identify the ucm card that should remain internal. We set a flag on
the device to notify of this.

Re-add the _alibpref of the local card to the device name if the
device was flagged.

See #1286
2021-06-10 15:36:26 +02:00
Wim Taymans 283e13629c alsa: use the local alibpref of the card
The _alibpref of the device was created in the session manager and
does not match our local _alibpref. Patch the device name with
the local _alibpref to make things match.

See #1286
2021-06-10 13:25:54 +02:00
Wim Taymans 23a0f29d48 acp: don't use the card index for alibpref
The alibpref fallback does not contain the card number but it is
a local counter instead. Just check if it starts with something in
case the alsa library is not patched to return _alibpref.
2021-06-10 13:25:53 +02:00
Wim Taymans d8e0176bcf alsa: open UCM only once.
See #1286 #1269
2021-06-10 09:58:11 +02:00
takooakes 51d01b33c8 Expose output select for Soundblaster cards
Enable selecting Speakers or Headphones for Soundblaster cards.
This switch was name Output Select.
2021-06-10 07:39:04 +00:00
Peter Hutterer 18b3efa2ed spa: make two headers compatible with older gcc-c++
c++ 7.5.0 can only initialize structs with continuous members, so let's
initialize the fields explicitly to NULL.

Fixes #1284
2021-06-10 15:19:15 +10:00
Peter Hutterer 5cf3c28fa4 config.h is a local header, not a system one
Change the #include accordingly, that's what we use in the rest of the tree
too.
2021-06-10 09:04:16 +10: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
Peter Hutterer 5ba43b8349 audioconvert: add config.h to include directories
Some of the files here #include "config.h"
2021-06-10 09:04:16 +10:00
Peter Hutterer e38cc427bf spa: fix indentation in audioconvert/meson.build
Was partially using spaces, partially 2-space tabs. Use 2 spaces only and fix
the few lines where the indentation was completely out of whack.
2021-06-10 09:04:16 +10:00
Wim Taymans eb8546a682 json: also escape '/' as required by JSON 2021-06-09 18:03:42 +02:00
Wim Taymans 4b6fb5e96a v4l2: report latency 2021-06-09 17:15:34 +02:00
Peter Hutterer 9a65d90e88 test: move the spa tests to pwtest
Move the spa tests to the pwtest framework. The pod tests have only been
wrapped in the function callers, they don't use the variuos pwtest helpers -
too much work for very little gain here. Can be done incrementally if needed.

Note that this removes the spa tests from the installed tests. Arguably,
installing those tests was unnecessary anyway since they are static binaries
and don't load anything. So having them installed runs the same tests as
having them run in the source tree.

Goal for the pwtest framework is to allow for installed tests, just not there
yet.
2021-06-09 18:00:59 +10:00
Peter Hutterer 7909c99ead test: convert two spa tests to pwtest 2021-06-09 18:00:39 +10:00
Peter Hutterer ed3f882fa9 test: add the pwtest test framework
Heavily inspired by libinput's litest framework (built around check), this is
a from-scratch framework that simplifies adding tests for various parts of
pipewire. See the pwtest.h documentation for details but the basics are:

- PW_TEST() and PWTEST_SUITE() specify the tests to be run
- Test are run in forked processes, any errors/signals are caught and printed
  to the log
- Tests have a custom pipewire daemon started on demand to talk to [1]. The
  daemon's log is available in the test output.
- Output is YAML to be processed into whatever format needed

[1] There are limits here, since we can't emulate devices yet there is only
so much we can rely on with the daemon.
2021-06-09 18:00:06 +10: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
Peter Hutterer fee4d0eae1 spa: switch the include header test to C++ by default
If we have a C++ compiler, compile all the #include tests with that - it'll
pick up any issues that a C compiler will pick up anyway. This saves us from
having a separate C++ compiler test and it'll test each header separately for
C++ compatibility..
2021-06-09 07:43:46 +00:00
Wim Taymans 4c64afc4ff acp: add hw-mute and hw-volume as properties 2021-06-09 09:41:49 +02:00
Peter Hutterer f3a98debec spa: don't run the spa_scnprintf abort test under valgrind
valgrind doesn't know we expect this to fail, so let's not confuse it
2021-06-08 20:21:50 +10:00
Peter Hutterer 10270621c2 spa: fix a missing include 2021-06-08 20:21:50 +10:00
Evgeniy Khramtsov 98ce5acb69 utils: define SIGABRT for FreeBSD 2021-06-07 20:53:16 +03:00
Wim Taymans 8132c4e2b4 acp: add fallback alibpref just in case
Until we are sure that everybody has a recent enough version of
alsa-lib 1.2.5
2021-06-07 13:04:03 +02:00
Barnabás Pőcze bec615971c spa: utils: hook: use tab 2021-06-07 10:54:19 +00:00
Wim Taymans 16674a07a5 logger: improve formatting
Make enough room for the timestamp to include the last ]
Add a space before the actual log line.
2021-06-07 12:52:21 +02:00
Peter Hutterer 83f8a2896f alsa-mixer: drop the VALGRIND_HAVE_MEMCHECK hacks
Cause for this was a missing ioctl, fixed in 2014. See valgrind commit
4ef60ef1029e6933773b7de9966ece7185129d84
2021-06-07 10:44:27 +00:00
Peter Hutterer d9cc1a25f1 Include the valgrind headers in our tree
These headers are designed for including in the project. So the user doesn't
need to install valgrind-devel and we don't have to worry about whether the
headers are available or not.
2021-06-07 10:44:27 +00:00
Peter Hutterer d08d989412 spa: add a test for missing includes
For each header in the spa directory, generate a compilation test that
includes just that header. This way we can pick up missing #includes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-07 10:31:17 +00:00
Peter Hutterer 6499f96396 spa: add missing #includes 2021-06-07 10:31:17 +00:00
Peter Hutterer c049689884 logger: set linebuffering for the log
Set this once during setup so we don't have to remember to call fflush() after
each logging operation.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-07 10:29:36 +00:00
Peter Hutterer 1c083a6d69 logger: clamp the log time to 5 digits
In the interested of making the logs narrower, let's drop some digits from the
clock_gettime() seconds value. Clamping to 5 digigts, this gives us just under
28h before we wrap which is likely good enough for debugging.
2021-06-07 10:29:36 +00:00
Peter Hutterer 9737d6e3da logger: align debug messages better
Taken from https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/655#note_912691
2021-06-07 10:29:36 +00:00
Peter Hutterer 1a710cad3c logger: reduce the number of appending snprintf calls
Write the timestamp and location into a temporary buffer, then include them in
the message print. This makes bugs involving size vs length less likely and
provides a fixed limit for how much space the filename can take in the
message.
2021-06-07 10:29:36 +00:00
Peter Hutterer db989d851d spa: auto-generate the cpp compilation test
Replace the manually maintained header list with a Python script that finds
all header files and includes them in order. This adds another 25 or so
previously headers to the C++ compilation tests.
2021-06-07 07:20:21 +00:00
Peter Hutterer fb75367975 spa: add a missing include
../spa/include/spa/node/node.h:639:14: error: ‘ENOTSUP’ was not declared in this scope
2021-06-07 07:20:21 +00:00
Peter Hutterer 48eadac1f1 logger: switch snprintf to spa_snprintf
The two are functionally equivalent, but spa_snprintf never returns a value
higher than the size, preventing memory corruption where our input string
exceeds the target buffer size (see c851349f1).

Niche case: we can no longer differ between real overflow and fitting an
N-byte string into an N+1 sized buffer, we now get a "...truncated" message
now for log messages of exactly 999 bytes long.
2021-06-07 15:37:51 +10:00
Peter Hutterer 47c173c83f spa/util: add spa_scnprintf to use over snprintf
Wraps the glibc snprintf/vsnprintf calls, but aborts if given a negative size
and zero-terminates the buffer on error.

The returned value is clipped to size - 1 which avoids issues like the one
fixed in c851349f17.
2021-06-07 15:16:35 +10:00
Huang-Huang Bao 8c42e6aecb alsa,bluez5: handle SPA_PARAM_Latency in port_set_param
Simply return 0 instead of -ENOENT.

Fixes #1262
2021-06-05 17:52:40 +00:00
Huang-Huang Bao d3fcc0a37a bluez5: correct parameter names in spa_bt_sco_io_create declaration
From its definition and parameters passed to its function call, the 3rd parameter
is read_mtu and the 4th is write_mtu.

Fixes #1256
2021-06-05 15:17:10 +00:00
Peter Hutterer 81cc466752 spa: the cpp test is a compilation test only
No point installing or even running it, we don't do anything here.
2021-06-04 18:46:29 +10:00
Peter Hutterer a71e68e945 spa: add missing header guards and extern C define for spa/pod/filter.h 2021-06-04 18:46:29 +10:00
Peter Hutterer a179e0fecd spa: fix a C++ typecast warning
void* cannot be automatically type-casted so let's do this explicitly.

../spa/include/spa/param/latency-utils.h: In function ‘spa_pod* spa_latency_build(spa_pod_builder*, uint32_t, const spa_latency_info*)’:
../spa/include/spa/pod/builder.h:651:1: error: invalid conversion from ‘void*’ to ‘spa_pod*’ [-fpermissive]
2021-06-04 17:57:11 +10:00
Peter Hutterer 3332e271be spa: fix compiler warnings about missing braces in initializer
First element is a spa_list, so {{0}} it is.

../spa/include/spa/node/utils.h:98:40: warning: missing braces around initializer for ‘spa_list’ [-Wmissing-braces]
   98 |         struct spa_hook listener = { 0 };
2021-06-04 17:57:11 +10:00
Peter Hutterer 98503a84b3 spa: fix an C++ invalid type conversion
In file included from spa/tests/test-cpp.cpp:49:
../spa/include/spa/param/latency-utils.h: In function ‘int spa_latency_parse(const spa_pod*, spa_latency_info*)’:
../spa/include/spa/param/latency-utils.h:95:25: error: invalid conversion from ‘int’ to ‘spa_direction’ [-fpermissive]
   95 |         info->direction &= 1;
      |         ~~~~~~~~~~~~~~~~^~~~
      |                         |
      |                         int
2021-06-04 17:57:10 +10:00
Wim Taymans 3fcb9c44ef spa: use strtoull for atou32
On machines with a 32 bits long, converting a negative value will
still result in  v == (uint32_t)v and the unit test will fail.
Extend to 64 bits and strtoull to reject negative values in atou32.
2021-06-03 11:40:27 +02:00
Wim Taymans 0b0a4897d6 spa: use unsigned long for strtoul result 2021-06-03 11:18:57 +02:00
Peter Hutterer 4d45182801 spa: add SPA_FOR_EACH_ELEMENT for array traversal 2021-06-03 07:25:32 +00:00
Huang-Huang Bao c7cac40e03 bluez5: init node soft volumes to 1.0f 2021-06-03 07:17:41 +00:00
Huang-Huang Bao f92a5b3bbd bluez5: emit node volume and mute right after bluez5 node creating
bluez5 nodes will always be removed & created again during profile changing, hence
node volume & mute will always be reset. This is OK if profile did changed, because
session manager would carries volume & mute to bluez5 route param. But if profile
was not changed after setting profile (a2dp-sink-sbc -> a2dp-sink -> a2dp-sink-sbc),
session manager would think node volume & mute are not changed and no route
setting is performed, causing route volume out of sync with node volume.

To fix this, we emit node volume and mute right after bluez5 node is created.

Fixes #1254
2021-06-03 07:17:41 +00:00
Huang-Huang Bao 27433c4000 bluez5: clean up node volume emitting
The problem described in previous 'volume_changed()' has been fixed
in 5bf2144438, hence we don't need
that workaround anymore.
2021-06-03 07:17:41 +00:00
Wim Taymans 35e81fbfdc alsa: rework UCM open
Use _alibpref to check if a device needs a UCM local config. Mark
the device as such and use this to set the OPEN_UCM property on
the device.
Open the UCM for a card when the device has the property set. Use the
same logic for loading the UCM as the acp code.

See #1251
2021-06-02 17:25:21 +02:00
Wim Taymans e3d3f04780 alsa: if we are passed a UCM device, make sure to open UCM
UCM devices can require local data from use_case_mgr_open() but since
we do that in a separate process, make sure we reopen the use case
manager in case we are passed a UCM device so that the config is
available.

See #1251
2021-06-02 13:23:08 +02:00
Peter Hutterer 6826df07da spa/utils: add spa_atou32, spa_atoi64,spa_atou64, spa_atod, spa_atof
Same as the existing spa_atoi32 but for uint32_t, {u}int64_t, float and
double.
2021-06-02 07:39:41 +00:00
Peter Hutterer c3ab4ec9dc spa: fix documentation for spa_atoi32
The val isn't undefined on failure, it's unmodified.
2021-06-02 07:39:41 +00:00
Peter Hutterer 1a5faa7b52 spa: add a header for ANSI color sequences
Makes the code more readable and guarantees we use the same sequences for the
same colors everywhere.
2021-06-02 14:17:29 +10:00
Wim Taymans 620e8de52a acp: copy the db_fix key as well
Or else we will try to free the original key twice and segfault.

Fixes #1125
2021-06-01 12:43:08 +02:00
Wim Taymans f544e4d87c acp: reset volume when enabling a device
When we enable a device, the node will be created and its software
volume will be set to 100%. Update the device volume with this as
well so that changing the volume has an effect.

Fixes #1198
2021-06-01 11:47:59 +02:00
Wim Taymans bc6e11d6e4 audioconvert: move some info to debug 2021-05-31 16:17:43 +02:00
Hui Wang e375930813 alsa-mixer: only use switch to mute Front in the Headphone path
According to the alsa-info.txt in the pipewire issues of #747 and #1206,
the Front Playback Volume is shared by Headphone and Lineout or
Headphone and Speaker, But Headphone, Lineout or Speaker they all have
independent Playback Switch, change to only use switch to mute the
Lineout or Speaker. This could resolve the issues of #747 and #1206.

See #1206 and #747
2021-05-31 13:08:19 +02:00
Wim Taymans 4dc3d79ff2 alsa: sync with pulseaudio 2021-05-31 13:03:52 +02:00
Peter Hutterer 98353560da spa: remove semicolon at end of SPA_LIST_INIT 2021-05-31 07:35:59 +00:00
Huang-Huang Bao e953bb3238
meson: fix build if bluez5 option is disabled
Don't look up codecs dependencies and don't include 'bluez5' subdir if 'bluez5' option is disabled or libbluetooth is not found.
See https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/707.
2021-05-28 21:01:38 +08:00
Huang-Huang Bao 38bcec9022
bluez5: add port latency reporting 2021-05-28 20:02:10 +08:00
Huang-Huang Bao d8435cd5fd
bluez5: use definations to index node and port params 2021-05-28 19:40:19 +08:00
Oschowa 8892152b13 meson: Require bluetooth codec library dependencies only when bluez5 is
enabled
2021-05-28 09:49:46 +00:00
Barnabás Pőcze c851349f17 spa: logger: fix potential buffer overrun when message is long
If the message was too long, then the `vsnprintf()` call would
fill up `location`, leaving no space for the color escape sequence
and the newline, causing a stack buffer overrun here:

  size += snprintf(p + size, len - size, "%s\n", impl->colors ? suffix : "");

Fix that by reserving the last 24 bytes of the message buffer.
2021-05-28 09:40:11 +00:00
Wim Taymans 70722c0741 channelmix: provide some more upmix options
If nothing else is possible, also try to upmix from FC

See #1237
2021-05-27 18:08:07 +02:00
Wim Taymans 9262f576d5 spa: fix unit test, add new object type 2021-05-27 15:26:09 +02:00
Wim Taymans 0222e408e0 audioconvert: use the right latency param
We need to use the latency param of the port direction to configure
the other port.
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 0779862cda alsa-seq: add port latency reporting 2021-05-27 15:26:09 +02:00
Wim Taymans cd32404e92 port: implement latency reporting some more
Implement a port recalculate latency method that takes the min
and max latency of all peer ports and sets that as the new port
latency.
When a link is made, let the output and input port recalculate
latencies.
Pass latency param in audioconvert.
2021-05-27 15:26:09 +02:00
Wim Taymans 1cd6d7b01d spa: Implement latency reporting
Implement latency reporting in alsa
Implement latency reporting on audioconf by passing on the latency
from the follower to outside of the adapter.
2021-05-27 15:26:09 +02:00
Wim Taymans 1a8f274a80 spa: add Latency param and object
Add a new latency param that contains a latency object.
The latency object contains the min and max delay from a port to
the terminal sink/source. It is also possible to express this
delay as a fraction of the quantum to avoid having to recalculate
the latency every time the quantum changes.
2021-05-27 15:26:09 +02:00
Wim Taymans 46ef88e520 spa: save the old change_mask and restore when emitting full
When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
2021-05-27 15:21:44 +02:00
Wim Taymans 751f9a9ea0 dbus: make sure we don't unref a NULL dbus connection
See #1213
2021-05-26 10:52:38 +02:00
Peter Hutterer e83f039833 alsa: free the strdup'd substring on error
n is the return value of pa_split()

Found by scan-build
2021-05-26 10:03:49 +02:00
Peter Hutterer bc64b32798 bluez: fix a memleak on error
If the allocation failed, our strdup'ed path would leak.

Found by scan-build
2021-05-26 10:03:43 +02:00
Peter Hutterer 4dd886188a alsa: fix scan-build errors for unused variables
All cases of value stored but never read
2021-05-26 07:51:27 +00:00
Peter Hutterer 851a64d8c8 doc: add spa to doxygen output
This requires a helper script: doxygen doesn't differ between static methods
and static inline methods. EXTRACT_STATIC defines whether it parses *any*
static method but we're currently using all C files as input files as well. We
cannot convince doxygen to just parse static inline functions in header files
so for SPA we hack around this: meson passes the spa headers to a shell script
with simply copies those changed to `/* static */ inline void (foo)` and doxygen
then runs on those header files.

The result: we get all spa functions added to your doxygen output at the cost
of a few sed calls.
2021-05-26 07:44:55 +00:00
Peter Hutterer 07533cb708 spa: group the spa headers into doxygen modules
Subdirectories buffer, control, debug, monitor, pod, support and utils, others
are still missing. Headers are grouped either per subdirectory (e.g. buffer/
gets added to group spa_buffer) or per-file (e.g. spa_json is a separate
group), whatever seemed like the most sensible approach.
2021-05-26 07:44:55 +00:00
Peter Hutterer d0aff793b7 spa: doxygenize the param/video comments 2021-05-26 07:44:55 +00:00
Johannes Wolf 799ba7de16 alsa-profiles: Add NI Komplete Audio 6 profile set 2021-05-26 07:35:25 +00:00
Georges Basile Stavracas Neto f1cc525d7e Add channel paths to analog-surround-*
Motu M4 has four inputs (two line-in inputs, and two complete ones
with gain and XLR and whatnot), as well as four outputs (two monitor
pairs, and an unnaccounted headphone).

Sadly, like a few other interfaces, it wasn't being given an input
profile, since the matching code goes through default.conf testing
each config, and ends up selecting 'analog-surround-40', which does
not have input mapping. The inputs would fallback to 'multichannel-
input', which also doesn't have input paths.

Add input paths to all analog-surround-* mappings, and remove their
'direction=output' fields since they handle both out and in.
2021-05-25 18:41:22 -03:00
Valentin David 6216de6ca0
alsa: Add support for SteelSeries Arctis 9 Wireless 2021-05-21 14:39:45 +02:00
columbarius d735d32eb3 spa: respect mandatory properties while filtering 2021-05-21 10:41:34 +00:00
columbarius da566c2865 spa: add property flag SPA_POD_PROP_FLAG_MANDATORY
This flag is used to announce that the respective key is mandatory and
therefore the object containing this key is not suitable to be merged
with other objects missing it.
2021-05-21 10:41:34 +00:00
Wim Taymans 39a2636c9b alsa: clean up port and node params 2021-05-21 11:08:52 +02:00
Wim Taymans 89c10dad70 spa: Clean up some of the param handling 2021-05-21 10:10:38 +02:00
Peter Hutterer 4cf18c92f8 spa: fix few doxygen errors 2021-05-21 15:04:22 +10:00
Peter Hutterer 71c6a175c4 Drop double semicolons 2021-05-20 07:24:22 +00:00
Peter Hutterer cdfd50e166 spa: add spa_atob() to convert a string to a boolean
This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
2021-05-18 22:18:56 +10:00
Peter Hutterer 92514d57e4 treewide: replace plain strcmp() calls with 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