Commit graph

3300 commits

Author SHA1 Message Date
Tanu Kaskinen
f790925c7b x11-bell: ignore volume from X11
X11 has its own bell volume setting, controlled with the "xset b"
command. If we use that volume, then the "System Sounds" slider in
pavucontrol doesn't affect the x11-bell sample volume, which in my
opinion is a bad thing. Ignoring the volume suggestion from X11 allows
module-stream-restore to apply the "event" role volume.
2017-01-19 03:00:45 +02:00
Pali Rohár
3397127f00 bluetooth: Add optional heuristic for switching between hsp and a2dp profiles
Not all VOIP applications (specially those which use alsa) set media.role to
phone. This means we need some heuristic to determinate if we want to switch
from a2dp to hsp profile based on number and types of source output (recording)
streams.

And also some people want to use their bluetooth headset (with microphone) as
their default recording device but some do not want to because of low quality.

This patch implements optional heuristic which is disabled by default. It is
disabled by default to not break experience of current pulseaudio users because
heuristic cannot be optimal. Heuristic is implemented in module-bluetooth-policy
module and decide if pulseaudio should switch to a hsp profile or not. It checks
if there is some source output with pass all these conditions:

* does not have set media.role
* does not use peak resample method (which is used by desktop volume programs)
* has assigned client/application (non virtual stream)
* does not record from monitor of sink

And if yes it switch to hsp profile.

By default this heuristic is disabled and can be enabled when loading module
module-bluetooth-policy with specifying parameter auto_switch=2

Because it is disabled by default nobody will be affected by this change unless
manually change auto_switch parameter.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-01-19 03:00:45 +02:00
Hajime Fujita
19873dff0a rtp: Introduce pa_rtsp_exec_ready()
In the current RTSP implementation, there is a vulnerable window
between the RTSP object creation and the URL initialization.
If any RTSP command is issued during this period, it will lead to
crash by assertion violation.

This patch introduces pa_rtsp_exec_ready(), which returns if it is
safe to issue RTSP commands.

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Martin Blanchard
60a1c27517 rtp: Random seq number at the beginning of the session
Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Colin Leroy
a0199dd99d rtp: New pa_rtsp_options function
Add a function performing a call to the OPTIONS request; also,
in some special cases, tuning transport parameters is required (default:
"RTP/AVP/TCP;unicast;interleaved=0-1;mode=record") ! The RAOP client for
example needs to overwrite them.

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Martin Blanchard
6665acac56 raop: Cosmetic fixes / Match coding style
Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Hajime Fujita
d623c689e6 rtp: Freeing ioline when disconnecting
pa_ioline_close does not free the ioline structure itself, so we
have to unref the structure if we want to free it.

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-01-19 02:56:53 +02:00
Tanu Kaskinen
0530c252b4 zeroconf-publish: fix unitialized DBusError
BugLink: https://bugs.archlinux.org/task/52484
2017-01-12 14:10:13 +02:00
Tanu Kaskinen
c3393d27a5 suspend-on-idle: use earlier (safer) hooks for stream unlink notifications
In the "unlink post" hook it's not guaranteed that the stream's old
device exists any more, so let's use the "unlink" hook that is safer.
For example, module-bluetooth-policy does a card profile change in the
source-output "unlink post" hook, which invalidates the source-output's
source pointer.

When the "unlink" hook is fired, the stream is still linked to its
device, which affects the return values of the check_suspend()
functions. The unlinked streams should be ignored by the check_suspend()
functions, so I had to add extra parameters to those functions.
2016-12-20 01:26:41 +02:00
Tanu Kaskinen
2250dbfd69 bluetooth-policy: do A2DP profile restoring a bit later
This fixes a crash that happens if the bluetooth headset is the only
non-monitor source in the system and the last "phone" stream dies.
When the stream dies, the native protocol calls pa_source_output_unlink()
and would call pa_source_output_unref() next, but without this patch,
things happen during the unlinking, and the unreffing ends up being
performed on a stream that is already freed.

pa_source_output_unlink() fires the "unlink" hook before doing anything
else. module-bluetooth-policy then switches the headset profile from HSP
to A2DP within that hook. The HSP source gets removed, and at this point
the dying stream is still connected to it, and needs to be rescued.
Rescuing fails, because there are no other sources in the system, so the
stream gets killed. The native protocol has a kill callback, which again
calls pa_source_output_unlink() and pa_source_output_unref(). This is
the point where the native protocol drops its own reference to the
stream, but another unref call is waiting to be executed once we return
from the original unlink call.

I first tried to avoid the double unreffing by making it safe to do
unlinking recursively, but I found out that there's code that assumes
that once unlink() returns, unlinking has actually occurred (a
reasonable assumption), and at least with my implementation this was not
guaranteed. I now think that we must avoid situations where unlinking
happens recursively. It's just too hairy to deal with. This patch moves
the bluetooth profile switch to happen at a time when the dead stream
isn't any more connected to the source, so it doesn't have to be
rescued or killed.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=97906
2016-12-20 01:26:30 +02:00
Tanu Kaskinen
60695e3d84 don't assume that pa_asyncq_new() always succeeds
Bug 96741 shows a case where an assertion is hit, because
pa_asyncq_new() failed due to running out of file descriptors.
pa_asyncq_new() is used in only one place (not counting the call in
asyncq-test): pa_asyncmsgq_new(). Now pa_asyncmsgq_new() can fail too,
which requires error handling in many places. One of those places is
pa_thread_mq_init(), which can now fail too, and that needs additional
error handling in many more places. Luckily there weren't any places
where adding better error handling wouldn't have been easy, so there are
many changes in this patch, but they are not complicated.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=96741
2016-12-20 01:19:06 +02:00
Tanu Kaskinen
3e52972c61 rtp: don't use memblocks for non-audio data
pa_memblockq_push() expects all memchunks to be aligned to PCM frame
boundaries, and that means both the index and length fields of
pa_memchunk. pa_rtp_recv(), however, used a memblock for storing both
the RTP packet metadata and the actual audio data. The metadata was
"removed" from the audio data by setting the memchunk index
appropriately, so the metadata stayed in the memblock, but it was not
played back. The metadata length is not necessarily divisible by the PCM
frame size, which caused pa_memblock_push() to crash in an assertion
with some sample specs, because the memchunk index was not properly
aligned. In my tests the metadata length was 12, so it was compatible
with many configurations, but eight-channel audio didn't work.

This patch adds a separate buffer for receiving the RTP packets. As a
result, an extra memcpy is needed for moving the audio data from the
receive buffer to the memblock buffer.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=96612
2016-12-20 01:13:48 +02:00
Tanu Kaskinen
c81f3da53b remove module-xenpv-sink
The module doesn't build any more[1], and when starting to investigate
the build failure, I asked the module author if he'd know something
about the breakage. He said that he didn't know about backward
compatibility problems with libxen, but more importantly, he said that
the module probably doesn't have any users[2]. It doesn't make sense to
keep maintaining a module that doesn't have users, so let's drop it.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=98793
[2] https://lists.freedesktop.org/archives/pulseaudio-discuss/2016-November/027172.html
2016-12-09 13:09:26 +02:00
Juha Kuikka
6a786c9375 bluetooth: fix race condition in BlueZ5 device disconnection
SW: Pulseaudio 8.0 / BlueZ 5.39

Symptoms:
While disconnecting/reconnecting a paired bluetooth headset (LG HBS750)
audio fails roughly on every other connection.

On a failed connection "pactl list cards" shows the bluetooth device's
card but "Active Profile: off". Issuing "pacmd set-card-profile X
a2dp_sink" makes audio work immediately.

I realized that when this happened, the previous disconnection did not
remove the card, instead it was only configured for "Active Profile:
off" but otherwise left in place.

Upon looking at PA debug logs I saw that the transport for the a2dp_sink
was first set into disconnected state and then into idle state. In
"device_connection_changed_cb()" this causes the
"pa_bluetooth_device_any_transport_connected()" return true and the
module-bluez5-device is not unloaded.

Further investigation shows that this is caused by a race of
module-bluez5-device.c:thread_func() and
MediaPoint1::ClearConfiguration().

When the FD in thread_func() is closed (POLLHUP) an
BLUETOOTH_MESSAGE_STREAM_FD_HUP message is sent into the main thread.
The handler of this message unconditionally sets the transport into IDLE
state. This is a problem if it has already been set into DISCONNECTED
state.
2016-11-28 13:17:44 +02:00
Tanu Kaskinen
e262379eb8 raop: add compatibility with openssl 1.1.0
Openssl 1.1.0 made all structs opaque, which caused a build failure in
raop_client.c. The struct member assignments are now replaced with a
call to RSA_set0_key().

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=96726

Reviewed-by: Felipe Sateler <fsateler@debian.org>
2016-11-04 16:30:37 +02:00
Anton Lundin
11a0c2ef5d raop: Correct spelling of KTH
KTH is a Swedish institution of higher education, and in its full name
spelled Kungliga Tekniska högskolan.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2016-10-26 20:13:32 +03:00
Pali Rohár
e32a462cc4 bluetooth: Add support for automatic switch between hsp and a2dp profiles also for bluez5
Bluez5 uses different profile names as bluez4, so we need to check for
a2dp_sink and headset_head_unit too for bluez5 support.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2016-09-23 17:37:06 +05:30
Philip Withnall
768e57c8a0 zeroconf-discover: fix a memory leak
Coverity CID: #1358700

https://bugs.freedesktop.org/show_bug.cgi?id=97876
2016-09-21 12:25:15 +03:00
Deepak Srivastava
feecced5cd xen: Fixed possible memory leak.
module-xenpv-sink.c - In pa__init(...), memory for pa_modargs *ma is not released before returning from function.

Signed-off-by: Deepak Srivastava <srivastava.d@samsung.com>
2016-09-20 10:44:20 +03:00
Pali Rohár
2abcbd2041 bluetooth: bluez5: Add profile name to sinks and sources
See commit 380a7fc240.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2016-09-18 14:58:49 +03:00
Tanu Kaskinen
c73bbee878 zeroconf-publish: unref D-Bus connection
pa_dbus_bus_get() increments the bus connection refcount, but unreffing
the connection was never done.
2016-09-05 18:59:27 +03:00
Tanu Kaskinen
de2f560137 zeroconf-publish: fix uninitialized variable
get_icon_name() returns the icon_name variable, and without this
change the function might exit before icon_name is initialized.
2016-09-05 18:59:27 +03:00
Sylvain Baubeau
963b3ea695 zeroconf: use local icon for shared devices
systemd-hostnamed provides an icon for the machine it is running on.
If it is running, module-zeroconf-publish uses this icon for the
'icon-name' attribute in the Avahi properties. module-zeroconf-discover
passes this icon to module-tunnel using the module parameter
{sink/source}_properties.

This allows to display a portable, desktop or phone instead of
the generic sound card icon.
2016-09-05 18:59:03 +03:00
Peter Meerwald-Stadler
492aafd93d bluetooth: Fix negative array index write
CID 1533121
2016-08-17 17:32:10 +02:00
Peter Meerwald-Stadler
aa1882c93f bluetooth: Reorganize code to avoid Coverity NULL dereference warning
CID 1353122

this is a false-positive because

   if (dbus_message_has_interface(p->message, "org.bluez.Manager") ||
        dbus_message_has_interface(p->message, "org.bluez.Adapter"))
        d = NULL;
    else if (!(d = pa_hashmap_get(y->devices, dbus_message_get_path(p->message)))) {
        pa_log_warn("Received GetProperties() reply from unknown device: %s (device removed?)",
dbus_message_get_path(p->message));
        goto finish2;
    }

d can be NULL only if p->message interface is org.bluez.Manager or
org.bluez.Adapter. If

    dbus_message_is_method_call(p->message, "org.bluez.Device", "GetProperties")

returns true, we know that the interface is org.bluez.Device.

thanks, Tanu!
2016-08-17 17:32:03 +02:00
Peter Meerwald-Stadler
41a2849261 bluetooth: Fix dead code
CID 1353115

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2016-08-16 10:31:44 +02:00
Peter Meerwald-Stadler
4231befa77 bluetooth: Don't free modargs twice
CID1353139

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2016-08-16 10:31:44 +02:00
Peter Meerwald-Stadler
8b076c3ed9 Remove newline at end of log messages
Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2016-08-16 07:03:25 +02:00
Peter Meerwald-Stadler
9cc778123f modules: Use pa_assert_se() to check return value of dbus_message_iter_close_container()
CID 1140353

... as it is done everythere else
2016-08-15 23:53:34 +02:00
Peter Meerwald-Stadler
05d964cf81 modules: Check pa_threaded_mainloop_start() return value
CID 1138500
2016-08-15 23:53:32 +02:00
Peter Meerwald-Stadler
61344493bf alsa: Check pa_modargs_get_value_boolean() retval for use_ucm
CID 1137983
2016-08-15 23:53:32 +02:00
Nils Schneider
9e4ee38c17 pipe-sink: align buffer
The pipe buffer is likely to be a power of 2 (e.g. 4096 bytes). This
works nicely for 16 bit stereo samples but breaks when using 24 bit
samples.

This patch aligns the buffer using pa_frame_align().
2016-08-13 00:34:18 +03:00
Tanu Kaskinen
32c2a6d64a bluetooth: don't create the HSP/HFP profile twice
create_card_profile() used to get called separately for HSP and HFP,
so if a headset supports both profiles, a profile named
"headset_head_unit" would get created twice. The second instance would
get immediately freed, so that wasn't a particularly serious problem.
However, I think it makes more sense to create the profile only once.
This patch makes things so that before a profile is created, we check
what name that profile would have, and if a profile with that name
already exists, we don't create the profile.

A couple of Yocto releases (jethro and krogoth) have non-upstream
patches that suffer from this double creation. The patches add
associations between profiles and ports, and those associations use
the profile name as the key. When the second profile gets freed, the
associations between the profile and its ports get removed, and since
the profile name is used as the key, this erroneously affects the
first profile too. Crashing ensues.

BugLink: https://bugzilla.yoctoproject.org/show_bug.cgi?id=10018
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
83ac6c5ae5 bluetooth: refactor BlueZ 4 transport state setting
Add transport_set_state() that encapsulates changing the variable,
logging and firing the change hook.

I also made a cosmetic change to the corresponding BlueZ 5 log
message so that both messages have the format that I like.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
15e3d828dd bluetooth: unify BlueZ 4 and BlueZ 5 profile constant names
This should make it slightly easier to copy code between BlueZ 4 and
BlueZ 5.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
52a9ee618f bluetooth: unify BlueZ 4 and BlueZ 5 UUID handling
A hashmap is more convenient than a linked list for storing the UUIDs,
so change the BlueZ 4 code accordingly.

Rename the BlueZ 4 UUID constants to match the BlueZ 5 naming.

The only changes to the BlueZ 5 code are the addition of one comment
and making another comment a bit clearer.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
570288ccc9 bluetooth: update device's valid flag after parsing properties
The properties_received flag affects whether the device should be
considered valid, so let's update the valid flag after setting the
properties_received flag.

There's a call to device_update_valid() anyway later when setting
the device adapters, so this change isn't strictly necessary, but
this makes it more obvious that the code is correct (and less
fragile).
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
eec4d29247 bluetooth: remove a redundant assignment
pa_bluetooth_transport_put() assigns the transport to the device's
transports array, so the caller doesn't have to do that.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
c538bc7aa4 card-restore: don't switch profiles when availability changes
module-card-restore should only restore the initial state of new
cards, but profile_available_changed_callback() changed the profile
whenever the saved profile became available. That caused interference
with module-bluetooth-policy, which also sets card profiles based on
the availability changes.

The original reason for having this code was to work around the
problem that bluetooth cards used to be created with only one profile
available, and other profiles would become available soon after the
card creation. Now the bluetooth card creation is delayed until all
profiles are available, so this bad workaround can be removed.

Discussion:
https://lists.freedesktop.org/archives/pulseaudio-discuss/2016-August/026575.html
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
d9b885e0f1 bluetooth: wait for all profiles to connect before creating card
The CONNECTION_CHANGED hook is used to notify the discovery module
about new and removed devices. When a bluetooth device connects, the
hook used to be called immediately when the first profile connected.
That meant that only one profile was marked as available during the
card creation, other profiles would get marked as available later.

That makes it hard for module-card-restore to restore the saved
profile, if the saved profile becomes available with some delay.
module-card-restore has a workaround for this problem, but that turned
out to interfere with module-bluetooth-policy, so the workaround will
be removed in the next patch.

The BlueZ 4 code doesn't need changes, because we use the
org.bluez.Audio interface to get a notification when all profiles are
connected.
2016-08-10 21:37:33 +03:00
Arun Raghavan
74c9549a42 stream-interaction: Fix a memory leak
CID: 1352053
2016-08-10 22:23:02 +05:30
Pali Rohár
bde2ff8794 bluetooth: Add support for automatic switch between hsp and a2dp profiles
With this patch module-bluetooth-policy automatically switch from a2dp profile
to hsp profile if some VOIP application with media.role=phone wants to start
recording audio.

By default a2dp profile is used for listening music, but for VOIP calls is
needed profile with microphone support (hsp). So this patch will switch to
hsp profile if some application want to use microphone (and specify it in
media.role as "phone). After recording is stopped profile is switched back
to a2dp. So this patch allows to use bluetooth microphone for VOIP applications
with media.role=phone automatically without need of user interaction.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2016-07-22 16:30:25 +05:30
Georg Chini
dfa4f42480 loopback: Stop tracking max_request and min_memblockq_length
They are not needed any longer because the regulation is now based on the
difference between current and configured latency.
2016-07-14 01:14:03 +03:00
Georg Chini
c03633766c loopback: Adjust rate based on latency difference
Replace the current latency controller with a modified P-controller. For
better readability separate the controller function. For small latency
differences, the controller forms a classical P-controller while it saturates
at 1% deviation from the base rate for large latency differences.
2016-07-14 01:13:53 +03:00
Georg Chini
4a11742652 loopback: Restart timer after 1/3 second
After switching source or sink, call adjust_rates after a third of a second
instead of waiting one full adjust time. This will ensure that latency regulation
starts as soon as possible.
2016-07-14 01:13:43 +03:00
Georg Chini
919cc2f3f9 loopback: Move timer restart and snapshots to timer callback
Restaring the timer and obtaining the latency snapshots belong to the timer callback.
To maintain an adjust time as near as possible to the configured value, the timer is
now restarted immediately at the beginning of the timer callback.
2016-07-14 01:13:32 +03:00
Georg Chini
b494bd62dd loopback: Change memblockq length
The size of the memblockq must be increased to allow for long latencies
at high sample rates.
2016-07-14 01:13:19 +03:00
Georg Chini
8c39a5c16c loopback: Improve latency estimation
To improve the overall latency estimation, the delay between the two snapshots
is taken into account. To minimize the snapshot delay, the order of the snapshots
is reverted. Additionally the latency at the base rate is calculated. It will be
used later as the input to the latency controller.
2016-07-14 01:11:50 +03:00
Georg Chini
2d7a5cda43 loopback: Improve latency estimation in snapshots
The delay and render memblockq are using the source and sink sample specs,
so using pa_bytes_to_usec() will produce better estimates of the delays than
using pa_resmpler_result(). Because the delays are considered to be part of
the sink or source latency, they are added to them. source_output_buffer
becomes obsolete.
2016-07-14 01:11:36 +03:00
Georg Chini
86e54c8c13 loopback: Save time stamps during latency snapshots
Saving the time stamps is necessary to account for the delay between the two
latency snapshots. Time stamps will be used in later patches.
2016-07-14 01:05:49 +03:00