Commit graph

3300 commits

Author SHA1 Message Date
Luiz Augusto von Dentz
f45fc03e3d bluetooth: ofono: Detect if Connect has been called
This detects if profile has already been called and we are waiting
the response.
2017-05-04 12:53:06 +02:00
Luiz Augusto von Dentz
cf23f07ec7 bluetooth: ofono: Fix asserting when connecting as AG
Check the card Type property instead of assuming ofono would only be used
for HF role.
2017-05-04 12:52:00 +02:00
Luiz Augusto von Dentz
fe43e72604 bluetooth: ofono: Don't attempt to connect if fd is ready
If SCO fd is already set don't attempt to connect again.
2017-05-04 12:49:53 +02:00
Tanu Kaskinen
4e3aa53a3f jack-sink: fix latency calculation
The compiler warned about number_of_frames being possibly used
uninitialized, and on closer inspection I found that it was indeed not
initialized if saved_frame_time_valid is false.

In commit fe70b9e11a "source/sink: Allow pa_{source,
sink}_get_latency_within_thread() to return negative values" the
number_of_frames variable was added as an unsigned version of the l
variable, and number_of_frames partially replaced the l variable. The
replacement should have gone all the way, however. This patch removes
the remaining uses of the l variable and substitutes number_of_frames
on its place, and as a result, number_of_frames is now always
initialized.
2017-05-02 16:53:40 +03:00
Tanu Kaskinen
6b34896130 improve default sink/source handling
Currently the default sink policy is simple: either the user has
configured it explicitly, in which case we always use that as the
default, or we pick the sink with the highest priority. The sink
priorities are currently static, so there's no need to worry about
updating the default sink when sink priorities change.

I intend to make things a bit more complex: if the active port of a sink
is unavailable, the sink should not be the default sink, and I also want
to make sink priorities dependent on the active port, so changing the
port should cause re-evaluation of which sink to choose as the default.
Currently the default sink choice is done only when someone calls
pa_namereg_get_default_sink(), and change notifications are only sent
when a sink is created or destroyed. That makes it hard to add new rules
to the default sink selection policy.

This patch moves the default sink selection to
pa_core_update_default_sink(), which is called whenever something
happens that can affect the default sink choice. That function needs to
know the previous choice in order to send change notifications as
appropriate, but previously pa_core.default_sink was only set when the
user had configured it explicitly. Now pa_core.default_sink is always
set (unless there are no sinks at all), so pa_core_update_default_sink()
can use that to get the previous choice. The user configuration is saved
in a new variable, pa_core.configured_default_sink.

pa_namereg_get_default_sink() is now unnecessary, because
pa_core.default_sink can be used directly to get the
currently-considered-best sink. pa_namereg_set_default_sink() is
replaced by pa_core_set_configured_default_sink().

I haven't confirmed it, but I expect that this patch will fix problems
in the D-Bus protocol related to default sink handling. The D-Bus
protocol used to get confused when the current default sink gets
removed. It would incorrectly think that if there's no explicitly
configured default sink, then there's no default sink at all. Even
worse, when the D-Bus thinks that there's no default sink, it concludes
that there are no sinks at all, which made it impossible to configure
the default sink via the D-Bus interface. Now that pa_core.default_sink
is always set, except when there really aren't any sinks, the D-Bus
protocol should behave correctly.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99425
2017-05-02 16:10:19 +03:00
Tanu Kaskinen
ea3ebd09d1 alsa: don't assume that hw:x is an analog output
Previously, if front:x didn't work, we would try to use hw:x for analog
stereo output. There's no guarantee that hw:x is an analog output,
however. For example, the Intel HDMI LPE driver uses hw:x for HDMI
output, and PulseAudio incorrectly created analog profiles for that
card, because front:x doesn't work but hw:x does.

This patch changes things so that the analog stereo mapping doesn't any
more use hw:x as a fallback. A separate "unknown stereo" fallback
mapping is added to handle the rare case where hw:x is the only PCM
device that works.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100488
2017-05-02 14:23:56 +03:00
Georg Chini
db4fbb0121 virtual sources and sinks: Fix possible segfault
Several virtual sources and sinks apart from module-echo-cancel also query the master
sink or source to estimate the current latency. Those modules might potentially show
the bug that is described for module-echo-cancel in bug 100277.

This patch checks in the message handlers for the PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY
if the master sink or source is valid and returns 0 as latency if not. This is however
not yet sufficient to solve the issue. Additional patches will follow.
2017-04-24 20:31:54 +02:00
Georg Chini
3bb94c4e83 echo-cancel: Fix segfault during profile switch
When module-echo-cancel is loaded and there is only one sound card, then during a
profile switch, all sinks and sources can become temporarily unavailable. If
module-always sink is loaded, it will load a null-sink in that situation. If
also module-switch-on-connect is loaded, it will try to move the sink-inputs to
the new null-sink. If a sink-input was connected to the echo-cancel sink,
pa_sink_input_start_move() will send a PA_SINK_GET_LATENCY message to the
echo-cancel sink. The message handler will then in turn call
pa_sink_get_latency_within_thread() for the invalid master sink of module-echo-cancel.
This lead to a segfault.

This patch checks in the message handler if the master sink (or source) is valid and
returns 0 if not.
2017-04-24 20:30:48 +02:00
Georg Chini
ce9ea846e9 bluez5-util: Fix segfault during shutdown of daemon
If a HFP audio gateway was connected via the ofono backend, pulse would
segfault during shutdown of the daemon. pa_bluetooth_discovery_unref()
removed the devices and transports before the ofono backend was freed.
Because the ofono backend keeps its own list of transports, transport_free()
was then called during termination of the ofono backend with an invalid
transport. Bug reported by Andrew Hlynskyi.

This patch moves the termination of the ofono and native backends before
freeing the devices.
2017-04-21 21:49:58 +02:00
Corentin Noël
92a6fe7453 echo-cancel: Change the DEVICE_MASTER_DEVICE property when changing device 2017-04-20 15:58:45 +05:30
Georg Chini
fe70b9e11a source/sink: Allow pa_{source, sink}_get_latency_within_thread() to return negative values
The reported latency of source or sink is based on measured initial conditions.
If the conditions contain an error, the estimated latency values may become negative.
This does not indicate that the latency is indeed negative but can be considered
merely an offset error. The current get_latency_in_thread() calls and the
implementations of the PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY messages truncate negative
latencies because they do not make sense from a physical point of view. In fact,
the values are truncated twice, once in the message handler and a second time in
the pa_{source,sink}_get_latency_within_thread() call itself.
This leads to two problems for the latency controller within module-loopback:

- Truncating leads to discontinuities in the latency reports which then trigger
  unwanted end to end latency corrections.
- If a large negative port latency offsets is set, the reported latency is always 0,
  making it impossible to control the end to end latency at all.

This patch is a pre-condition for solving these problems.
It adds a new flag to pa_{sink,source}_get_latency_within_thread() to allow
negative return values. Truncating is also removed in all implementations of the
PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY message handlers. The allow_negative flag
is set to false for all calls of pa_{sink,source}_get_latency_within_thread()
except when used within PA_{SINK,SOURCE}_MESSAGE_GET_LATENCY. This means that the
original behavior is not altered in most cases. Only if a positive latency offset
is set and the message returns a negative value, the reported latency is smaller
because the values are not truncated twice.

Additionally let PA_SOURCE_MESSAGE_GET_LATENCY return -pa_sink_get_latency_within_thread()
for monitor sources because the source gets the data before it is played.
2017-04-17 19:50:10 +02:00
Tanu Kaskinen
65f7ca4414 ladspa-sink, virtual-surround-sink: fix master sink argument handling
The old code worked incorrectly in several situations. For example,
trying to use the "master" argument wouldn't work, because if
"sink_master" wasn't specified, pa_namereg_get() would pick the default
sink as the master sink.
2017-04-16 15:18:53 +03:00
Georg Chini
f3265f944a loopback: Implement underrun protection
The latency controller will try to adjust to the configured latency regardless
of underruns. If the configured latency is set too small, it will lead to
periodically occuring underruns. Therefore an underrun protection is implemented
which will increase the target latency if too many underruns are detected.
Underruns are tracked and if more than 3 underruns occur, the target latency
is increased in increments of 5 ms. One underrun per hour is accepted.
The protection ensures, that independent from the configured latency the
module will converge to a stable latency if the configured latency is too
small.

The print_msg argument to update_minimum_latency() had to be re-introduced,
because there is one place where the message should not be logged.
2017-04-14 15:02:36 +02:00
KimjeongYeon
caabff2728 filter-apply: Add ability to pass parameters to a filter module
Currently passing parameters to a filter loaded by module-filter-apply is
not possible.

To enable passing parameters to a filter this patch uses an additional property
filter.apply.{MODULE_NAME}.parameters. This way, filters like virtual-surround-sink
and ladspa-sink are fully supported. For example:
paplay file.wav --property=filter.apply=ladspa-sink \
                --property=filter.apply.ladspa-sink.parameters="plugin=ladspa \
                  label=ladspa_stereo control=0"
2017-04-13 21:24:46 +02:00
KimjeongYeon
145da09aca ladspa-sink: Add sink_master argument to enable filter-apply to load the module
Currently, module-filter-apply cannot load module-ladspa-sink because filter-apply
provides the argument "sink_master" but ladspa-sink expects "master" instead.

Therefore this patch adds the sink_master argument to module-ladspa-sink.

Additionally, the autoloaded argument was also added.
2017-04-13 21:01:13 +02:00
KimjeongYeon
ba4de85b53 virtual-surround-sink: Add sink_master argument to enable filter-apply to load the module
Currently, module-filter-apply cannot load module-virtual-surround-sink because filter-apply
provides the argument "sink_master" but virtual-surround-sink expects "master" instead.

Therefore this patch adds the sink_master argument to module-virtual-surround-sink.

Additionally, the autoloaded argument was also added.
2017-04-13 20:57:26 +02:00
KimjeongYeon
1f0c4f7d6a filter-apply: Fix memory leak in process()
fltr->name should be freed before freeing fltr. Because filter_free()
can never be called from other places without f set, the pa_assert()
can be removed and filter_free() can be used in process() as well.
2017-04-13 20:41:20 +02:00
Georg Chini
d3d980ff49 loopback: Reset sink input rate when source or sink changes
If source or sink are changed, the current sink input rate may be different
from the default rate. Switch sink input rate back to default to avoid the
influence of the previous combination of source and sink.
2017-04-11 21:49:11 +02:00
Georg Chini
5bc363d4b8 loopback: Add hooks to track port latency offsets
The previous patch assumed constant port latency offsets. The offsets can
however be changed by the user, therefore these changes need to be tracked
as well. This patch adds the necessary hooks.

Also the print_msg argument was removed from update_minimum_latency() and
update_latency_boundaries() because the message should always be logged.
2017-04-10 21:47:23 +02:00
Georg Chini
6f2e22e7ad Merge branch 'master' of ssh://git.freedesktop.org/git/pulseaudio/pulseaudio 2017-04-07 08:20:43 +02:00
Georg Chini
c936aa23c3 loopback: Calculate and track minimum possible latency
With the current code, the user can request any end-to-end latency. Because there
is no protection against underruns, setting the latency too small will result in
repetitive underruns.

This patch tries to mitigate the problem by calculating the minimum possible latency
for the current combination of source and sink. The actual calculation has been put
in a separate function so it can easily be changed. To keep the values up to date,
changes in the latency ranges have to be tracked.

The calculated minimum latency is used to limit the configured latency.
The minimum latency is only a "best guess", so the actual minimum may be much
larger (for example for USB devices) or much smaller than the calculated value.

Changes of the port latency offsets are not yet handled, this will be done in a
separate patch.
2017-04-07 08:18:08 +02:00
Tanu Kaskinen
b6777d7f09 pipe-sink: set correct latency
The old pa_sink_set_fixed_latency() call didn't take into account that
other places use pa_frame_align() on the pa_pipe_buf() result, so the
configured latency could be sometimes slightly too high.

Adding a buffer_size variable in userdata makes it a bit easier to keep
all places that deal with the buffer size in sync.
2017-04-06 22:57:23 +03:00
Tanu Kaskinen
d7e85813bd bluetooth: allow UTF-8 in device descriptions
Users may configure the device alias to have characters outside the
ASCII range, so our name cleanup routine was too aggressive. Let's just
make sure that the device description is a valid UTF-8 string.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=98160
2017-04-02 20:48:52 +03:00
Georg Chini
a3acc167aa loopback: Do not skip audio at startup
The code is now waiting for source and sink to start up, so the skip
logic is not necessary anymore.
2017-03-31 07:50:12 +02:00
Tanu Kaskinen
41e974d863 bluetooth: assert that dbus_message_iter_append_basic() doesn't fail
The function can only fail if there's not enough memory available, and
if that happens, the convention in PulseAudio is to abort.

CID: 1353106, 1353108, 1353140
2017-03-30 19:27:02 +03:00
Arun Raghavan
2c2ca1c949 echo-cancel: Try to minimise in-flight chunks in snapshot latency
We don't always know whether the in-flight memory chunks will be
rendered or skipped (if the source is not in RUNNING). This can cause us
to have an erroneous estimate of drift, particularly when the canceller
starts.

To avoid this, we explicitly flush out the send and receive sides of the
message queue of audio chunks going from the sink to the source before
trying to perform a resync.
2017-03-29 11:04:06 +05:30
Georg Chini
f4f01f6833 loopback: Fix corking logic of module-loopback
When moving from a user suspended source or sink to an idle suspended source or sink
the sink input or source output would not be uncorked because we did not check for
the suspend cause.

Uncorking also would not be possible in that situation because the state change callback
of the source output or sink input is called before the new source or sink is attached,
leading to a crash of pulseaudio due to a cork() call without valid source or sink.

The previous patch fixes this problem, therefore sink input or source output can now also
be uncorked when the destination is idle suspended.
2017-03-29 07:11:50 +02:00
Georg Chini
3650346f70 sink-input/source-output: Don't crash when cork() is called without valid sink or source
If pa_sink_input_cork() or pa_source_output_cork() were called without a sink
or source attached, the calls would crash pulseaudio.

This patch fixes the problem, so that a source output or sink input can still
be corked or uncorked while source or sink are invalid. This is needed to
correct the corking logic in module-loopback.
2017-03-29 07:10:28 +02:00
Tanu Kaskinen
cb78d6f57c bluez5-util: fix profile waiting logic
There were two bugs in the old logic. The first one:

If a device has two profiles, the old code would start the wait timer
when the first profile connects, but when the second profile connects,
the timer would not get stopped and the CONNECTION_CHANGED hook would
not get fired, because the code for that was inside an if block that
only gets executed when the first profile connects. As a result,
module-bluez5-device loading would always be delayed until the wait
timeout expires.

The second bug:

A crash was observed in device_start_waiting_for_profiles(). That
function is called whenever the connected profile count changes from 0
to 1. The function also has an assertion that checks that the timer is
not running when the function is called. That assertion crashed in the
following scenario with a headset that supports HSP and A2DP:

1. First HSP gets connected. The timer is started.

2. Then HSP gets disconnected for some reason. The timer is still
running.

3. Then A2DP gets connected. device_start_waiting_for_profiles() is
called, because the connected profile count changed from 0 to 1 again.
The timer is already running, so the assertion fails.

First I thought I'd remove the assertion from
device_start_waiting_for_profiles() and just restart the timer on the
second call, but then I figured that when the device returns to the
"everything disconnected" state in step 2, it would be better to stop
the timer. The purpose of the timer is to delay the notification of the
device becoming connected, but if the device becomes disconnected during
the waiting period, the notification doesn't make sense any more, and
therefore the timer doesn't make sense either.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100237
2017-03-28 21:56:05 +03:00
Jungsup Lee
fa44127ebe allow-passthrough: Fix indentation
Signed-off-by: Jungsup Lee <jungsup4.lee@samsung.com>
2017-03-27 20:32:25 +02:00
Arun Raghavan
2de5fc222e echo-cancel: Fix assert with webrtc's built-in drift compensation
The webrtc canceller seems to have changed to require that the
set_stream_drift_samples() method be called before every call of
ProcessStream().

So we now call ec->set_stream_drift_samples() before calling
ec->record() by:

1. Always calling do_push_drift_comp() instead of only when the sink is
   running

2. Calling set_stream_drift_samples() in the loop with record() instead
   of outside

We do kind of leak this quirk of the webrtc canceller into the generic
bits of module-echo-cancel, but this should not be harmful in the
general case either.
2017-03-21 09:52:09 +05:30
Tanu Kaskinen
2530eb8d1b bluetooth-policy: retain backwards compatibility
The auto_switch argument was added in PulseAudio 10.0. In that release
the argument type was boolean. The type was changed to integer in commit
3397127f00. This patch adds backwards compatibility so that old
configuration files won't break when upgrading PulseAudio to 11.0.
2017-03-17 21:57:42 +02:00
Georg Chini
e26a675263 bluez5-util: Disconnect AG devices when ofono is started and headset=auto
With headset=auto it is possible that AG devices are connected and handled
via the native backend when ofono is started. Because the HS role will then
be disabled in the native backend, AG devices must be disconnected and any
future connections will be handled by ofono.
2017-03-14 07:32:31 +01:00
Georg Chini
adc2e8cd0a bluetooth: use native and ofono backends in parallel with headset=auto
This patch changes the behavior of the headset=auto switch for module-bluez5-discover.
With headset=auto now both backends will be active at the same time for the AG role and
the switching between the backends is only done for the HS role.
headset=ofono and headset=native remain unchanged.

This allows to use old HSP only headsets while running ofono and to have headset support
via pulseaudio if ofono is started with the --noplugin=hfp_ag_bluez5 option.
2017-03-11 19:02:16 +01:00
Peter Meerwald-Stadler
fa7329a2dd oss: Fix dead code
mode cannot be 0
Coverity ID: #1137964

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-10 10:18:33 +01:00
Tanu Kaskinen
0ced45265c dbus: fix card profile change signals
The "profile->card != c->card" check always evaluated to false, so the
CardProfileUpdated signal was never sent. The reason: call_data was
assigned to a pa_card_profile pointer, but the correct type is a pa_card
pointer.
2017-03-10 00:34:59 +02:00
Tanu Kaskinen
6022a1ee99 udev-detect: don't use readdir_r(), it's deprecated
readdir_r() was supposed to be a thread-safe version of readdir(), but
the interface turned out to be problematic. Due to the problems and the
fact that readdir() is safe enough on modern libc implementations, glibc
deprecated readdir_r() in version 2.24.

The man page contains more information about what's wrong with
readdir_r(): http://man7.org/linux/man-pages/man3/readdir_r.3.html
2017-03-10 00:32:34 +02:00
Arun Raghavan
1992c4cce1 echo-cancel: Limit the maximum sink/source latency
On systems with constrained CPUs, we might run into a situation where
the master source/sink is configured to have too high a latency.

On the source side, this would cause us to wake up with a large chunk of
data to process, which might cause us to exhust our RT limit and thus be
killed.

So it makes sense to limit the overall latency that we request from the
source (and correspondingly, the sink, so we don't starve for playback
data on the source side).

The 10 blocks maximum is somewhat arbitrary (I'm assuming the system has
enough headroom to process 10 chunks through the canceller without
getting close to the RT limit). This might make sense to make tunable in
the future.
2017-03-09 22:17:48 +05:30
Arun Raghavan
c82e4913e8 alsa: Avoid creating tiny memchunks on write iterations
If the ALSA device supports granular pointer reporting, we end up in a
situation where we write out a bunch of data, iterate, and then find a
small amount of data available in the buffer (consumed while we were
writing data into the available buffer space). We do this 10 times
before quitting the write loop.

This is inefficient in itself, but can also have wider consequences. For
example, with module-combine-sink, this will end up pushing the same
small chunks to all other devices too.

Given both of these, it just makes sense to not try to write out data
unless a minimum threshold is available. This could potentially be a
fragment, but it's likely most robust to just work with a fraction of
the total available buffer size.
2017-03-09 22:17:48 +05:30
Peter Meerwald-Stadler
2898a5188c raop: Error out on parsing server port component
don't ignore server port parsing errors as suggested by Hajime Fujita

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Hajime Fujita <crisp.fujita@nifty.com>
2017-03-09 13:51:51 +01:00
Peter Meerwald-Stadler
add5a175b6 raop: Log if pa_atoi() fails, latency is not used anyway
Coverity ID: #1398152

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-09 13:51:51 +01:00
Peter Meerwald-Stadler
4cfd544f21 raop: Fix potential NULL dereference
wath may be NULL, as suggested by Hajime Fujita
Coverity ID: #1398156

setting val = NULL is not needed

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Hajime Fujita <crisp.fujita@nifty.com>
2017-03-09 13:51:51 +01:00
Peter Meerwald-Stadler
a8ce3ef844 raop: Fix potential dereference after NULL check
Coverity ID: #1398157

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-09 13:51:51 +01:00
Arun Raghavan
bfe0e6366d combine-sink: Use PA_MAX instead of ternary operator for clarity 2017-03-09 12:18:06 +05:30
Peter Meerwald-Stadler
74abce331b raop: Fix check for invalid file descriptor
file descriptor 0 is valid

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-08 14:31:29 +01:00
Peter Meerwald-Stadler
a199b9045e build: Use #ifdef to check for #defines
for example, in case HAVE_MEMFD is #undef, checking with #if HAVE_MEMFD
gives a warning (gcc 5.4.1, Ubuntu)

pulsecore/shm.c: In function 'sharedmem_create':
pulsecore/shm.c:208:5: warning: "HAVE_MEMFD" is not defined [-Wundef]
 #if HAVE_MEMFD

use #ifdef or #if defined() to check for presence of a #define

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-08 14:31:29 +01:00
Moritz Bruder
48ba5e4957 waveout: add argument deprecation error 2017-03-07 18:15:17 +02:00
Moritz Bruder
7259df9590 waveout: fix wrong input device
Both input and output device were chosen with the same device number.
This is problematic as those numbers don't have to correspond.
Additionally the input device was named after the output device. This
commit adresses both issues by providing specific parameters for each
type.
2017-03-07 18:15:08 +02:00
Wim Taymans
e1dc75da99 backend-native: add support for the HSP Headset role
This is a rebase of Wim Taymans patch to support the HSP headset role that has
somehow been forgotten. Original patch can be found at
https://lists.freedesktop.org/archives/pulseaudio-discuss/2015-February/023242.html
Rebase and minor changes by Georg Chini.

In addition to the HSP Audio Gateway, also add support for the headset
role in the native bluetooth backend. In this role, pulseaudio is used as
headset.

In the headset role, we create source and sink to receive and send the samples
from the gateway, respectively. Module-bluetooth-policy will automatically load
loopback modules to link these to a sink and source for playback. Because this
makes the source the speaker and the sink the microphone, we need to reverse the
roles of source and sink compared to the gateway role.

In the gateway role, adjusting the sink volume generates a +VGS command to set
the volume on the headset. Likewise, receiving AT+VGS updates the sink volume.

In the headset role, receiving a +VGS should set the source volume and any
source volume changes should be reported back to the gateway with AT+VGS.
2017-03-07 15:17:43 +02:00
Peter Meerwald-Stadler
0cb72beace raop: Fix potential NULL dereference
'realm' is mandatory

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
2017-03-07 09:47:46 +01:00