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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Setting these callbacks adds the HW_{VOLUME,MUTE}_CTRL flag even when
PulseAudio is solely responsible for performing attenuation whilst only
keeping the peer posted on changes. For this case the hardware callback
is not registered at all but instead a hook is attached to catch
PA_CORE_HOOK_{SINK,SOURCE}_VOLUME_CHANGED. Only when the peer performs
attenuation (the peer is in HeadSet/HandsFree role) are the callbacks
used, without touching PA software volume at all. A future change could
potentially use software volume to compensate for the extremely coarse
16 steps of volume control in HSP and HFP, and to allow volume over
100%.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/519>
Since commit cb91d7a1 the watermark is increased when there is nothing to rewind.
This is also done in the case when there was actually no rewind requested at all,
so the watermark is increased needlessly.
This patch fixes the issue by skipping the rewind if none is requested.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/530>
Originally written for A2DP this rework of that patch enables late-bound
hardware volume control on HFP and HSP. As per the specification the
headphones (where gain control for both speaker and microphone could
happen in hardware on the peer) are supposed to send initial values for
these before the SCO connection is created; these `AT+VG[MS]` commands
are also used to determine support for it. PA uses this information in
`add_{sink,source}` to attach hardware volume callbacks, _if_ it is
supported. Otherwise PA performs the attenuation in software.
Unfortunately headphones like the WH-1000XM3's connect to A2DP
initially and only send `AT+VGS` (microphone hardware gain is not
supported) _during_ SCO connection when the user switches to the HFP
profile afterwards; the callbacks set up dynamically in
`rfcomm_io_callback` are written after the sink and source have been
created (`add_{sink,source}`), leaving them without hardware volume
callbacks and with software volume when adjusted on the PA side. (The
headphones can still send volume updates resulting in abrupt changes if
software and peer volume differ. Furthermore the same attenuation is
applied twice - once in PA software, once on the peer).
To solve this problem we simply check whether the callbacks have been
attached whenever the peer sends a volume change, and if not attach the
callbacks to the sink/source and reset software volume.
Fixes: d510ddc7f ("bluetooth: Perform software attenuation until HF/HS reports gain control")
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/528>
HF/HS hardware attenuation is optional on HFP: the peer indicates
support with the AT+BRSF command, when bit 4 is set. That does not
explicitly mandate speaker or microphone gain control; either is
dynamically detected as soon as `AT+VG[MS]=` is received. Otherwise
software attenuation is performed.
It is also optional on HSP but nothing is mentioned about feature
detection, assume it is the same as HFP: perform software attenuation
until the HF/HS peer sends an `AT+VG[MS]=` command.
When PA is a HS/HF (and the peer the AG) we attenuate both channels in
software and unconditionally keep the peer up to date with
`AT+VGM/AT+VGS` commands.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
Generalize the distinction between local and peer-attenuated volumes
into a function, paving the way for future changes where this needs to
be checked in more places and when A2DP Absolute Volume support is
added.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
Sink and source naming is more generic when dealing with audio that is
directional in the sense that it either goes to or comes from the other
device, but not necessarily a microphone or speaker. A concrete example
is the swapped meaning when the current device is in the HeadSet
profile. The incoming audio can come from any source, not necessarily a
microphone. Likewise, audio captured by the microphone of the headset is
not necessarily played back by a speaker on the AG, it is merely acting
as a sink for the data: further handling is irrelevant to the naming.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
For the upcoming A2DP AVRCP Absolute Volume feature the code in BlueZ5
has to be generic to be reusable. Move this conversion so that it
becomes possible to implement A2DP volume - which uses different values
- on top without duplicating existing callback functionality.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
The format of COMMAND line sent from HS to AG is COMMAND<cr>
The format of RESPONSE line sent from AG to HS is <cr><lf>RESPONSE<cr><lf>
Split rfcomm_write into rfcomm_write_command and rfcomm_write_response to handle
line formatting correctly.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/520>
Commit 4868fcf5f3 ("daemon: Rely on
systemd unit file for X11 plugin initialization") added a new systemd
unit file, pulseaudio-x11.service, generated from a respective .in file.
Unfortunately, this was only hooked up to meson, and is not currently
installed by autotools. Among other breakage, "make dist" produces a
tarball that meson is then unable to build (because a file is missing).
Signed-off-by: Faidon Liambotis <paravoid@debian.org>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/514>
On cpu-volume-test, cpu_info is initialized only on i386/amd64 systems,
and otherwise passed on to pa_cpu_init_orc() uninitialized.
If one was unlucky enough, they could end up with cpu_info.cpu_type ==
PA_CPU_X86 on a non-x86 system, and use and test the Orc codepath
without that being functional, and thus with the test failing.
This has been observed in the wild on the ppc64el Debian buildds. See
Debian bug #982740 for more context.
Define cpu_info here in the same way as in other tests.
Signed-off-by: Faidon Liambotis <paravoid@debian.org>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/511>