Commit graph

193 commits

Author SHA1 Message Date
Georg Chini
051f7508b4 virtual sources: Propagate asyncmsgq change after source-output move
Currently, when the master of a virtual source is moved, the change of the
asyncmsgq is not propagated to other attached virtual sources. This leads
to a crash when the original master source is no longer available.

This patch fixes the issue by modifying the moving callback to propagate the
change to attached virtual sources.

Virtual sinks show a similar bug but that will be fixed in a different patch
series.
2020-01-13 20:40:04 +01:00
Rasmus Thomsen
bff163089c meson: link libintl if it's not provided by libc
This fixes the build on musl with external gettext
2019-09-25 04:42:03 +00:00
Arun Raghavan
1e996445f7 build-sys: meson: Add atomic ops related checks 2019-08-15 18:57:13 +05:30
Arun Raghavan
7f44a623e0 build-sys: meson: Correctly set up RPATH
This was being done automatically by autotools, now we need to manually
specify this for each executable/library with a dependency in a
non-standard directory.
2019-08-05 09:52:32 +05:30
Arun Raghavan
f996ad0688 build-sys: meson: Add -Wl,no-delete to relevant libraries
This mirrors the autotools option for all server-side dynamic libraries.
2019-08-05 09:52:32 +05:30
Arnaud Rebillout
d717089218 meson: Build libwebrtc-util as a shared library
As it'sdone in the autotools

Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
2019-06-08 11:57:00 +02:00
Arnaud Rebillout
e0f23a41e1 meson: Fix install paths
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
2019-06-08 11:57:00 +02:00
Arun Raghavan
37dbeae031 build-sys: Fix up meson install paths
Brings things in line with the autotools build, and adds ALSA mixer
paths and profile-sets into the meson build system as well.

The module installation path is also now customisable.
2019-06-06 18:49:59 +02:00
Arnaud Rebillout
66ac9ee37a webrtc: Silence -Wsign-compare warning
webrtc.cc:202:19: warning: comparison of integer expressions of different signedness:
  'int' and 'std::vector<webrtc::CartesianPoint<float> >::size_type' {aka 'long unsigned int'}

Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
2018-10-04 08:44:18 +05:30
Arnaud Rebillout
88d77ff852 meson: Enable echo-cancel module, add libwebrtc_util lib, add speex and webrtc dependencies
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
2018-10-04 08:44:18 +05:30
Joseph Herlant
3fb7e9bcb1
Fix typo: differnt -> different 2018-09-17 09:56:41 -07:00
Joseph Herlant
83c3384d3a
Fix typo: Extention -> Extension 2018-09-17 09:55:37 -07:00
Joseph Herlant
517c727a98
Fix typo: Doulbe -> Double 2018-09-17 09:54:36 -07:00
Tanu Kaskinen
6665b466d2 sink, source: remove the state getters
pa_sink_get_state() and pa_source_get_state() just return the state
variable. We can as well access the state variable directly.

There are no behaviour changes, except that module-virtual-source
accessed the main thread's sink state variable from its push() callback.
I fixed the module so that it uses the thread_info.state variable
instead. Also, the compiler started to complain about comparing a sink
state variable to a source state enum value in protocol-esound.c. The
underlying bug was that a source pointer was assigned to a variable
whose type was a sink pointer (somehow using the pa_source_get_state()
macro confused the compiler enough so that it didn't complain before).
I fixed the variable type.
2018-07-02 21:23:13 +03:00
Tanu Kaskinen
b4a36453da sink-input, source-output: remove the state getters
pa_sink_input_get_state() and pa_source_output_get_state() just return
the state variable. We can as well access the state variable directly.

There are no behaviour changes, except that some filter sources accessed
the main thread's state variable from their push() callbacks. I fixed
them so that they use the thread_info.state variable instead.
2018-07-02 18:54:03 +03:00
Raman Shyshniou
556cdfa190 optimize set_state_in_io_thread() callbacks
Source and sink are passed in arguments to set_state_in_io_thread()
callbacks. There is optimal to access them directly.
2018-06-21 06:05:36 +05:30
Tanu Kaskinen
ad0616d4c9 pass pa_suspend_cause_t to set_state_in_io_thread() callbacks
The suspend cause isn't yet used by any of the callbacks. The alsa sink
and source will use it to sync the mixer when the SESSION suspend cause
is removed. Currently the syncing is done in pa_sink/source_suspend(),
and I want to change that, because pa_sink/source_suspend() shouldn't
have any alsa specific code.
2018-03-20 13:00:44 +02:00
Tanu Kaskinen
b2537a8f38 replace sink/source SET_STATE handlers with callbacks
There are no behaviour changes, the code from almost all the SET_STATE
handlers is moved with minimal changes to the newly introduced
set_state_in_io_thread() callback. The only exception is module-tunnel,
which has to call pa_sink_render() after pa_sink.thread_info.state has
been updated. The set_state_in_io_thread() callback is called before
updating that variable, so moving the SET_STATE handler code to the
callback isn't possible.

The purpose of this change is to make it easier to get state change
handling right in modules. Hooking to the SET_STATE messages in modules
required care in calling pa_sink/source_process_msg() at the right time
(or not calling it at all, as was the case on resume failures), and
there were a few bugs (fixed before this patch). Now the core takes care
of ordering things correctly.

Another motivation for this change is that there was some talk about
adding a suspend_cause variable to pa_sink/source.thread_info. The
variable would be updated in the core SET_STATE handler, but that would
not work with the old design, because in case of resume failures modules
didn't call the core message handler.
2018-03-16 20:05:38 +02:00
Tanu Kaskinen
0fad369ceb sink, source: rename set_state() to set_state_in_main_thread()
There will be a new callback named set_state_in_io_thread(). It seems
like a good idea to have a similar name for the main thread variant.
2018-03-16 19:54:59 +02:00
Tanu Kaskinen
6ed37aeef2 pass pa_suspend_cause_t to set_state() callbacks
The suspend cause isn't yet used by any of the callbacks. The alsa sink
and source will use it to sync the mixer when the SESSION suspend cause
is removed. Currently the syncing is done in pa_sink/source_suspend(),
and I want to change that, because pa_sink/source_suspend() shouldn't
have any alsa specific code.
2018-02-22 09:13:40 +02:00
Arun Raghavan
d9624e0382 build-sys: Stop using symdef headers for modules
This removes the symdef header generation m4 magic in favour of a
simpler macro method, allowing us to skip one unnecessary build step
while moving to meson, and removing an 11 year old todo!
2017-12-12 12:58:52 +05:30
Tanu Kaskinen
3d698d17af sink-input, source-output: add sink/source_requested_by_application flag
When a stream is created, and the stream creator specifies which device
should be used, that can affect automatic routing policies.
Specifically, module-device-manager shouldn't apply its priority list
routing when a stream has been routed by the application that created
the stream.

A stream that was initially routed by the application may be moved for
some valid reason (e.g. user requesting a move, or the original device
disappearing). When the stream is moved away from its initial device,
the "device requested by application" flag isn't relevant any more, so
it's set to false and never reset to true again.

The change in module-device-manager's routing logic will be done in the
following patch.
2017-12-02 16:13:21 +02:00
Tanu Kaskinen
6b92027c19 echo-cancel: fix a memory leak
The pa_echo_canceller_msg object was never unreffed.
2017-11-21 15:18:26 +02:00
Tanu Kaskinen
5f29b838ff echo-cancel: ignore remaining canceller messages after the module has been unloaded
Not ignoring the messages caused crashing due to accessing the userdata
after it had been freed.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=103528
2017-11-21 15:18:05 +02:00
Arun Raghavan
2c9a2aa01e echo-cancel: Expose dereverb in the speex canceller
Enabled by default.
2017-10-24 22:33:23 +05:30
Arun Raghavan
fa228745c1 echo-cancel: Fix speex echo state setting
The state should be set even if echo suppression is disabled, which is
not currently the case.
2017-10-24 22:33:23 +05:30
Tanu Kaskinen
3979fba0ac echo-cancel: don't set latency range if the device doesn't support dynamic latency
pa_sink/source_set_latency_range() has an assertion that is triggered
when setting the latency range on a fixed latency device.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=102020
2017-08-04 09:02:56 +03:00
Georg Chini
edc465da77 virtual sources and sinks: Don't double attach a sink input or source output on filter load
When a filter is loaded and module-switch-on-connect is present, switch-on-connect
will make the filter the default sink or source and move streams from the old
default to the filter. This is done from the sink/source put hook, therefore streams
are moved to the filter before the module init function of the filter calls
sink_input_put() or source_output_put(). The move succeeds because the asyncmsq
already points to the queue of the master sink or source. When the master sink or
source is attached to the sink input or source output, the attach callback will call
pa_{sink,source}_attach_within_thread(). These functions assume that all streams
are detached. Because streams were already moved to the filter by switch-on-connect,
this assumption leads to an assertion in pa_{sink_input,source_output}_attach().

This patch fixes the problem by reverting the order of the pa_{sink,source}_put()
calls and the pa_{sink_input,source_output}_put calls and creating the sink input
or source output corked. The initial rewind that is done for the master sink is
moved to the sink message handler. The order of the unlink calls is swapped as well
to prevent that the filter appears to be moving during module unload.

The patch also seems to improve user experience, the move of a stream to the filter
sink is now done without any audible interruption on my system.

The patch is only tested for module-echo-cancel.

Bug-Link: https://bugs.freedesktop.org/show_bug.cgi?id=100065
2017-05-18 07:46:46 +02:00
Georg Chini
00aeedfe98 virtual sinks and sources: Revert commits
This patch reverts commit db4fbb0121 and
3bb94c4e83. They were the wrong approach
to fix the bug (and did not fix it anyway).
2017-05-18 07:46:08 +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
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
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
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
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
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
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
99c3bc69d5 webrtc: improve comment about mic geometry
The first mic channel position is not relevant for the target
direction definition.
2016-06-22 21:04:47 +05:30
Tanu Kaskinen
0b6e4694a5 echo-cancel: rework move handling
When autoloaded, module-echo-cancel doesn't support moving the sink
input and source output that it creates, but the move prevention was
implemented by manually requesting module unloading in the middle of
the stream move procedure, rather than by just setting the DONT_MOVE
flags. This patch removes the module unloading code from the moving()
callbacks and adds the DONT_MOVE flags. In addition to saving some
code, this also prevents problems related to trying to move streams
connected to the echo cancel sink or source while the echo cancel sink
or source is in the middle of a move too (a crash will happen in such
situation, as demonstrated in
https://bugs.freedesktop.org/show_bug.cgi?id=93443).
2016-04-25 13:47:08 +03:00
Arun Raghavan
fa2b0b4aad echo-cancel: Convert AGC API to deal with pa_volume_t
It is expected that the underlying AGC mechanism will likely provide a
single volume for the source rather than a per-channel volume. Dealing
with per-channel volumes just adds complexity with regards to the
actual volume setting (depending on whether volume sharing is enabled or
not, we would set the volume on the source output of the virtual source,
and their sample specs may be different).

Using a single volume allows us to sidestep this problem entirely.
2016-02-25 19:06:44 +05:30
Arun Raghavan
05a6af744b echo-cancel: Add beamforming support in the webrtc canceller 2016-02-25 09:17:25 +05:30
Arun Raghavan
cfd3a948de echo-cancel: Remove pa_ prefix on private functions 2016-02-25 09:17:25 +05:30
Arun Raghavan
be5e196c1a echo-cancel: Update a copyright notice 2016-02-25 09:17:25 +05:30
Arun Raghavan
07663b06b3 echo-cancel: Use webrtc's deinterleaved API
This is required to have unequal channel counts on capture in and out
streams, which is needed for beamforming to work. The deinterleaved API
only works with floating point samples.
2016-02-25 09:17:10 +05:30
Arun Raghavan
3133ff8e11 echo-cancel: webrtc canceller supports different in/out channel counts
Needed for upcoming beamforming code.
2016-02-25 09:09:13 +05:30
Arun Raghavan
222a98846c echo-cancel: Improve webrtc canceller error handling a bit 2016-02-25 09:09:13 +05:30
Arun Raghavan
5baecd37c3 echo-cancel: Fix webrtc canceller when rec channels != play channels
The calculations around how many samples were sent to the canceller
engine was not updated when we started supporting different channel
counts for playback and capture.
2016-02-25 09:09:13 +05:30
Arun Raghavan
08afc36ae4 echo-cancel: Make webrtc AGC start volume a modarg
Allows for tuning based on the target hardware.
2016-02-25 09:09:13 +05:30
Arun Raghavan
8de7dfec14 echo-cancel: Use anonymous unions for echo canceller params
Makes this part of the code just a little less verbose.
2016-02-25 09:09:13 +05:30
Arun Raghavan
8949ed96c6 echo-cancel: Add a modarg toggle for VAD in the webrtc canceller 2016-02-25 09:09:12 +05:30