Commit graph

7549 commits

Author SHA1 Message Date
Jason Nader
0e4a92ca69 pactl: add get_default_sink command
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/430>
2021-05-17 15:35:07 +00:00
Marijn Suijten
d9db47bdb5 bluetooth: Add avrcp_absolute_volume module flag for disablement
Not all peers might work fine with Absolute Volume, provide the user
with an option to disable it without impairing other AVRCP-related
commands like media status and playback controls.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Marijn Suijten
25426bc029 bluetooth: Delay A2DP Absolute Volume setup until property is available
The Volume property on org.bluez.MediaTransport1 is required to utilize
Absolute Volume, but it will only become availabe if the peer device
supports the feature.  This happens asynchronously somewhere after the
transport itself has been acquired, after which the callbacks are
attached and software volume is reset.

To prevent race conditions availability of the property is also checked
on startup through a "Get" call.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Marijn Suijten
c6b771537e bluetooth: Report a2dp_source volume changes to the source device
Write the current volume to the `Volume` DBus property to keep the
volume on the remote in sync.  Without this the remote device shows the
wrong volume, and any attempts to change it will cause an unexpected
jump when the local volume has also been adjusted.

Thanks to prior investments to improve volume synchronization, setting
up callbacks and sending initial volume to the peer for HFP/HSP
implementing this feature is as easy as unconditionally assigning a
valid function to `set_source_volume`.  `source_setup_volume_callback`
is already responsible for attaching a `SOURCE_VOLUME_CHANGED` hook and
sending initial (restored) volume to the peer (signifying support for
Absolute Volume - if not derived from the presence of FEATURE_CATEGORY_2
on the profile yet).

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Marijn Suijten
ac21b07ad6 bluetooth: Synchronize AVRCP Absolute Volume with A2DP sink
Like the previous commit this handles `Volume` property changes but
applies them to an A2DP sink instead of source stream.  As mentioned in
the AVRCP spec v1.6.2 §5.8 the rendering device (A2DP sink) is
responsible for performing volume attenuation meaning PulseAudio should
pass through audio as-is without performing any attenuation in SW.
Setting a valid pointer to `set_sink_volume` and returning `true` from
`should_attenuate_volume` attaches a hardware callback to `pa_sink` such
that no volume attenuation is performed anymore.

In addition to receiving volume change notifications it is also possible
to control remote volume by writing a new value to the DBus property.
This is especially useful when playing back to in-ear audio devices
which usually lack physical buttons to adjust the final volume on the
sink.

While software volume (used before this patch) is generally fine it is
annoying to crank it up all the way to 100% when a previous connection
to a different device left saved volume on the peer at a low volume.
Providing this bidirectional synchronization is most natural to users
who wish to use physical controls on their headphones, are used to this
from their smartphone, or aforementioned volume mismatches where both PA
as source and the peer as sink/rendering device are performing
attenutation.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Marijn Suijten
710a35cdc3 bluetooth: Update source software volume on AVRCP SetAbsoluteVolume
The A2DP spec mandates that the audio rendering device - the device
receiving audio, in our case a `pa_source` - is responsible for
performing attenuation:

AVRCP v1.6.2, §5.8:
    The SetAbsoluteVolume command is used to set an absolute volume to be used by the rendering device.

BlueZ models this call as a change of the `Volume` property on the
`org.bluez.MediaTransport1` interface.  Supporting Absolute Volume is
optional but BlueZ unconditionally reports feature category 2 in its
profile, mandating support.  Hence remote devices (ie. a phone) playing
back audio to a machine running PulseAudio assume volume is to be
changed through SetAbsoluteVolume, without performing any local
attenuation.

Future changes will implement this feature the other way around: setting
an initial value for the `Volume` property as well as propagating
`pa_source` volume changes back to the peer.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Marijn Suijten
c098a75d10 bluetooth: Move HSP_MAX_GAIN to header for reuse in n_volume_steps
Instead of hardcoding the number `16`, use `HSP_MAX_GAIN + 1`.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/239>
2021-05-17 14:50:03 +00:00
Georg Chini
dbaf450394 null-sink: Request no more than the configured latency from sink-input
In the case, where the latency is larger than the maximum block size,
module-null-sink will request multiples of the maximum block size from
the sink input instead of limiting the requested amount of data to the
the configured latency.

This patch fixes the problem.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/554>
2021-05-17 14:40:15 +00:00
Hui Wang
80efd7a64c Revert "alsa-mixer: Set "Front" control to 0 dB on headphone path"
This reverts commit 96369919e5.

The commit was originally for the issue of Headphone can't output
sound, that was because the Headphone and Lineout share the 1st alsa
mixer and DAC, but this commit introduced a new issue of the speaker
is not muted after switching to headphone.

A recent merged kernel commit (f48652bbe3ae@linux) could fix the 1st
issue, so we could revert the fix of the 1st issue from PA, then the
2nd issue is fixed automatically.

BugLink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/747
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/553>
2021-05-17 14:30:33 +00:00
Jan Alexander Steffens (heftig)
2a07c83cfc build-sys: meson: Add missing include dir
Otherwise building module-echo-cancel fails here:

    FAILED: src/modules/module-echo-cancel.so.p/echo-cancel_adrian-aec.c.o
    cc -Isrc/modules/module-echo-cancel.so.p -I. -I../pulseaudio -Isrc -I../pulseaudio/src -I/usr/include/orc-0.4 -flto=auto -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=gnu11 -march=x86-64 -mtune=generic -O2 -p>
    ../pulseaudio/src/modules/echo-cancel/adrian-aec.c:30:10: fatal error: adrian-aec-orc-gen.h: No such file or directory
       30 | #include "adrian-aec-orc-gen.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/552>
2021-05-12 21:10:54 +02:00
Christopher Arndt
2af43a8baf Add port order metadata to JACK sink / source ports
Adds JACK metadata property to ports created by *module-jack-sink*
and *module-jack-source* with key `JACK_METADATA_ORDER`, the port index
(1-based, in order of creation) as value and type
`http://www.w3.org/2001/XMLSchema#int`.

This allows JACK applications, which use JACK metadata, to list or display
these ports in correct order.

See also: https://jackaudio.org/api/group__Metadata.html

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/550>
2021-05-03 12:19:17 +00:00
Patrick Gaskin
39125a0f2b win32: Use DACLs when setting socket permissions
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/548>
2021-05-03 11:43:10 +00:00
Patrick Gaskin
a238a58186 cli-command: Replace config dir with toplevel for .include on win32
This makes the behaviour match pa_{open,find}_config_file by
replacing PA_DEFAULT_CONFIG_DIR with the toplevel.

This fixes the hardcoded paths for {default,system}.pa.d introduced
in 45abd0b43c (!361).

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/545>
2021-05-03 10:58:45 +00:00
Igor V. Kovalenko
4ec89c27c9 bluetooth: adjust sync to source with different sample spec
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/544>
2021-05-03 10:49:32 +00:00
Patrick Gaskin
d21d0d89a5 build-sys: meson: Merge system_conf config data from default_conf
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/547>
2021-04-23 01:52:55 -04:00
Georg Chini
1c1d0c7827 stream-restore: Fix use of uninitialized variable
The variable card_name in sink_input_preferred_sink_changed_cb and
source_output_preferred_source_changed_cb could be used uninitialized,
which leads to invalid database entries.

This patch fixes the problem.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/543>
2021-04-20 12:18:43 +02:00
Igor V. Kovalenko
424580a901 build-sys: meson: allow building client libraries only
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/540>
2021-04-19 18:48:59 +00:00
Martin Wilck
1a73fb9eb9 parecord: really fix recording OGG
432a91ed ("fix "Failed to open audio file" for FLAC and OGG)" claimed
to fix recording of OGG files with pacat, but it really fixed only
FLAC. This patch must be added on top to fix OGG, too.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/542>
2021-04-19 18:24:34 +02:00
Georg Chini
468e3669aa loopback: Fix crash bug
The loopback message may be called after the sink input is already destroyed which causes
a crash. Also memory is leaked because the message object is not correctly freed.

This patch fixes the problems by adding a "dead" flag to the message structure and freeing
the message object on exit.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/541>
2021-04-19 15:21:07 +00:00
Igor V. Kovalenko
38905a096c alsa-mixer: Allow selected fallback mappings in all profile sets
When fallback mapping is selected all subsequent profile sets containing
selected mapping are ignored. When there are only e.g. fallback input mappings
available, admitted profile set will only contain one profile with selected
first input fallback mapping and no outputs, and rest of profiles will only
contain outputs and no inputs. When there are only fallback input and output
mappings, there will be no profiles admitted at all.

Fix this by making sure that selected first fallback input or output mapping
is actually allowed to exist in all probed profile sets.

Note while this change allows selected fallback mappings to be found in duplex
configuraitons, probing fallbacks still can fail if there is more than one input
fallback and first one (selected) does not work in duplex configurations.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/539>
2021-04-19 14:48:36 +00:00
Martin Wilck
432a91ed43 parecord: fix "Failed to open audio file" for FLAC and OGG
This patch fixes the following error:

$ pacat --file-format=ogg -r test.ogg
Failed to open audio file.
$ parecord sep.flac
Failed to open audio file.

libsndfile errors out if a WAV or OGG file is set to have anything but
SF_ENDIAN_FILE:

f4d1646e5c

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/526>
2021-04-19 13:35:48 +00:00
Igor V. Kovalenko
fec9eb178d bluetooth: disable HSP HS profile by default
A few headsets have issues if HFP HF profile connection is attempted before
HSP HS profile connection is closed. Looks like this could happen because
bluez bluetoothd alows to make simultaneous HSP HS and HFP HF peer connections.

One of affected headsets is WH-1000XM2

Until we find out how to prevent simultaneous HSP HS and HFP HF connections,
when native backend has HFP HF profile enabled (this is the default) do disable
HSP HS completely unless user explicitly request it via discovery modarg.

Do this by adding module-bluetooth-discover arg enable_native_hsp_hs,
default to inverse of enable_native_hfp_hf.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/538>
2021-04-16 08:33:42 +03:00
Igor V. Kovalenko
e3fa937508 bluetooth: handle HFP codec list in any order
HFP HF peer can send +BAC= list of codecs in any order and pa only expects "1,2"
Fix this by actually parsing codec list elements while looking for "2" (mSBC)

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/537>
2021-04-14 21:30:27 +00:00
Lyndon Brown
651e0db07b proplist: tweak documentation for pa_proplist_get()
to clarify that only mutating proplist calls potentially invalidate results
of earlier get requests, thus addressing the confusion found at [1].

[1]: https://github.com/jnqnfe/pulse-binding-rust/issues/38

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/536>
2021-04-09 01:47:58 +01:00
Igor V. Kovalenko
1a194c9918 bluetooth: mSBC: log lost input audio packets at debug level
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
6a92940796 bluetooth: add modarg to allow disabling mSBC codec
Add module-bluetooth-discover argument enable_msbc, default is true (enabled)

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
310e2877a0 bluetooth: split BT codec from A2DP SEP configuration api
Common API for all bluetooth codecs is now pa_bt_codec.
API to negotiate and configure A2DP SEP over Bluez is now pa_a2dp_endpoint_conf.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
c7c9ca22ab bluetooth: set initial packet size to 60
Raise initial MTU size to fix frame size when hci can do 60 byte frames.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
9de895fe23 bluetooth: add more call indicators
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
436a98a50b bluetooth: produce silence on mSBC decoding error
We are supposed to conceal packet loss. This is not trivial but we can at least
produce silence instead of breaking on mSBC decoding error.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
436813d8a8 bluetooth: remember negotiated HFP codec in native backend
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
ddad63a23c bluetooth: show negotiated HFP codec
While codec switching for HFP is not implemented, show current codec via
messaging api.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
f0d32e9454 bluetooth: add mSBC to backend-ofono
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
030dc8b968 bluetooth: prepare to redo transport writeout scheduling
Bluetooth SCO is synchronous stream, make our writes more uniformly paced.
To do this, first separate writing to socket from rendering a frame.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
976fc1d099 bluetooth: mSBC: ignore empty encoded frame
If input block size is shorter than SBC frame codesize, encoder will return 0.
Log this and skip whole input block.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
7d191b64d9 bluetooth: mSBC: ignore all-zero packets
This is a workaround for hardware/driver which inserts all-zero packets in what
otherwise looks like a valid mSBC stream.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
6c0c9cf845 bluetooth: use helper to set multiple transport object attributes
For mSBC to work correctly the following must be set correctly
- codec object
- transport write method
- transport setsockopt method

Use helper method to set all three simultaneously.
Static configuration structure may be cleaner solution.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
62776cc815 bluetooth: apply write MTU detection based on read packet size
HFP Audio Connection SCO configuration is negotiated symmetrically in both
directions, and USB HCI SCO packet framing is also symmetric in both directions.
This means that packet size will be the same for reads and writes over HFP SCO
socket.

HFP profile specification states that valid speech data shall exist on the
Synchronous Connection in both directions after the Audio Connection is
established.

This guarantees that an incoming packet will arrive shortly after SCO connection
is established. Use it's size to fix write MTU in case kernel value is wrong.

Discussion here https://lore.kernel.org/patchwork/patch/1303411/

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
James Bottomley
4444ecad6f bluetooth: add wideband audio codec negotiation to HFP
The HFP protocol supports the ability to negotiate codecs if that is
supported by both AG and HF.  This patch adds advertising of codec
negotiation support and the ability to negotiate a codec change.  The
only currently supported extra codec (as of HF 1.7.1) is mSBC.  mSBC
requires that the transmission be done over an eSCO link with
Transparent Data.  The linux kernel ensures the former, but we have to
manually set the socket to transparent data.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
James Bottomley
f22cfa8f81 bluetooth: add support for mSBC codec
Adding processing support for the mSBC codec is somewhat problematic,
because, although it is a SBC codec, the a2dp handling can't simply be
reused because the codec is used on an eSCO link with transparent
data, meaning the transmission unit has to be 48 bytes (fragmenting
the codec packets) and reassembly and boundary detection is required
to be done by the implementation.  Therefore we have to implement
separate render and push routines for msbc that do this fragmentation.

Fragmentation is done by emulating circular buffers.  The receive
(push) buffer is easy, since the mSBC packet size is 60, simply have a
buffer of this size in the sbc_info area where the fragments are
reassembled.  Once we have a full 60 bytes, decode and restart from
zero.  The send (render) buffer is more problematic, since the
transmit must be done from contiguous memory.  This means that the
buffer must be the lowest common multiple of the transmission unit and
the packet size.  This value is 240 since 240/48 == 5 and 240/60 == 4.
So the buffer pointers are reset at 240 which is a whole number of
both rendered packets and eSCO transmission units.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
a7b21fb555 bluetooth: add CVSD codec implementation
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
913e7767d6 bluetooth: unify decoder code paths
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Igor V. Kovalenko
3902cee4a5 bluetooth: unify encoder code paths
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
2021-04-05 15:43:32 +00:00
Tanu Kaskinen
8a87af380a stream-restore: Fix NULL preferred device handling
When an application sets a device for a newly created stream, we treat
that as a temporary setting, and don't save it as the preferred device
for future streams. The handling for this was broken, however: if the
stream already had a preferred device saved in the stream-restore
database, that was unset.

This was a regression introduced in
bc0e728320 and
70bbbcdc84. These commits tried to detect
in subscribe_callback() when the preferred device is cleared, but as a
side effect the preferred device started to get cleared from the
database also when a stream was created with a device set by the
application.

There's no way for subscribe_callback() to distinguish the different
cases of the preferred device being NULL. This problem is solved by
using the PREFERRED_SINK/SOURCE_CHANGED hooks. The hooks are only called
when the preferred device really changes.

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1063
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/535>
2021-04-05 15:17:15 +00:00
Tanu Kaskinen
737ebcdfdb sink-input, source-output: Add hooks for preferred device changes
The hooks are fired when the preferred device changes. This is useful
for module-stream-restore.

I added new set_preferred_sink/source() functions for firing the hooks.
The functions also log the preferred device changes.

There was already pa_sink_input_set_preferred_sink(), but that had a
side effect of moving the stream, so I needed a new function. Since it
can be confusing when the two similarly named functions should be
called, I added a comment for pa_sink_input_set_preferred_sink() that
explains the different situations.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/535>
2021-04-05 15:17:15 +00:00
Igor V. Kovalenko
1f204a1357 bluetooth: prioritize native backend HFP HF connection
Bluez prepends newly registered profile to a list of supported profiles,
and new peer profile connections are attempted in reverse order of profile
registration.

Currently native backend would register HFP AG profile before HSP AG profile.
When peer supports both HFP HF and HSP HS profiles, this registration order
causes extra HSP HS connection attempt before native backend would reject it
to make sure peer is reconnected with HFP HF profile.

Reorder HSP AG profile registration before HFP AG to make sure peer supporting
both profiles connects with HFP HF profile first.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/534>
2021-04-03 08:48:06 +03:00
Igor V. Kovalenko
a2db3fcfb2 message-params: clean up
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/525>
2021-03-27 11:18:22 +00:00
Igor V. Kovalenko
1dd05f4a9b message-params: use JSON instead of custom format
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/525>
2021-03-27 11:18:22 +00:00
Igor V. Kovalenko
0ba768b2e9 json: add JSON encoder
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/525>
2021-03-27 11:18:22 +00:00
Igor V. Kovalenko
1df4a311d4 json: improve supported numbers
Use 64bit signed integers and fix double value conversion.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/525>
2021-03-27 11:18:22 +00:00