Commit graph

9980 commits

Author SHA1 Message Date
Igor V. Kovalenko
5f43173209 build-sys: meson: Rearrange shell completion between daemon and client
Rename bash completion file to pactl and install it with client build.
Completions specific to daemon are now just symlinks, create target directory
first to install them.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Igor V. Kovalenko
80c0a497d3 build-sys: meson: Rearrange dependencies under client and daemon options
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Igor V. Kovalenko
6dd14ad9f1 build-sys: meson: Move remaining tests under daemon and client builds
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Igor V. Kovalenko
6928714b64 build-sys: meson: change daemon-only to client
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Mart Raudsepp
4cf4a1fd5b build-sys: meson: Allow building the daemon only
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Mart Raudsepp
a67f894775 build-sys: meson: Relax sanity checks for daemonless builds
Echo canceller, udev and speex resampling is only used by the daemon, so
don't error or warn about those in -Ddaemon=false builds.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/659>
2021-11-17 16:06:23 +00:00
Igor V. Kovalenko
1a3ffd4cee bluetooth: Fix device->adapter dependency while releasing discovery
Change d7f95170a1 added a dependency on device
adapter pointer being valid while checking if bluetooth profile is supported by
device.

When adapter object is released, each device holding pointer to adapter being
released is notified to reset that to NULL. Since adapter objects are released
first when discovery object is unreferenced, each device will have adapter
pointer reset before the time device objects are released.

Fix observed crash by examining device adapter pointer. If it is NULL report
that device does not support any bluetooth profile instead of looking at UUIDs
supported by adapter.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/646>
2021-11-17 15:30:03 +00:00
Marijn Suijten
0c5672390b bluetooth/backend-native: Replace tab-indents with spaces
Fixes: 7fd89e491 ("bluetooth: Try to reconnect SCO")
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/649>
2021-11-17 15:25:00 +00:00
Georg Chini
fdf37d9a91 loopback: Add log_interval parameter
Add a log_interval parameter to control the amount of logging. Default is
no logging. Like for adjust_time, the parameter is a double to allow values
below 1s.
If the log interval is too small, logging will occur on every iteration.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
0f91b2146d loopback: Change adjust_time parameter to double to allow adjust times below 1s
The adjust_time parameter is changed to double to allow better granularity
and adjust times below 1s. This may be useful for a better latency control,
although with alsa devices and the current smoother code no significant
improvement could be found for values below 500ms.
This patch also changes the default adjust time to 1s, the old value of 10s
does not allow a tight control of the end to end latency and would lead to
unnecessary jitter.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
dd18b06321 loopback: Only use controller weight after target latency has been crossed twice
The previous patch slows down initial convergence. Therefore do not use
the controller weight until we can assume that we reached an equilibrium.
Because it takes some time before the reported latency values are reliable,
assume that a steady state is reached when the target latency has been
crossed twice.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
edbf8fb509 loopback: Add adjust_threshold_usec parameter
In many situations, the P-controller is too sensitive and therefore exhibits rate hunting.
To avoid rate hunting, the sensibility of the controller is set by the new parameter
adjust_threshold_usec. The parameter value is the deviation from the target latency in usec
which is needed to produce a 1 Hz deviation from the optimum sample rate.
The default is set to 250 usec, which should be sufficient in most cases. If the accuracy
of the latency reports is bad and rate hunting is observed, the parameter must be increased,
while it can be lowered to achieve less latency jitter if the latency reports are accurate.
More details at
https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
66e6a5ca88 loopback: Track prediction error; debug and cosmetic changes
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
68f7aee7c0 loopback: Add latency prediction and Kalman filter
A Kalman filter is added to further reduce noise. The Kalman filter needs a
latency prediction as input, so estimate the next expected latency as well.
Again, theory is at
https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
6a906e54cc loopback: Optimize adaptive re-sampling
The current code assumes that the time domains of source and sink are
equal. This leads to a saw-tooth characteristics of the resulting end
to end latency.
This patch adds an iterative calculation of an optimum rate which accounts
for the difference between the source and sink time domains, thereby massively
enhancing the latency stability. Theoretical background for the calculation
can be found at
https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
285427ce30 loopback: Limit controller step size to 2.01‰
The current loopback controller can produce a rate jump of up to 1% at startup,
which may be audible. To prevent large initial jumps, a second controller is
introduced, which produces a rate, that is not more than 2‰ away from the last
rate. Only during the startup phase, the rates produced by this controller will
be nearer to the base rate than those produced by the original controller.
Therefore choosing the rate which is nearer to the base rate will ensure that
the secondary controller only moderates the startup phase and has no influence
during continued operation.
The maximum step size of the original controller after the initial jump is
limited to 2.01‰ of the base rate, see documentation at
https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Georg Chini
e7abd862b1 loopback: Do not detect underruns during initial latency adjustments
Currently module-loopback detects underruns even if sink_input_pop_cb()
was not yet called twice and initial latency adjustments are active.
This leads to unnecessary rewind requests.

This patch delays detecting underruns until the initial adjustments
are done.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/56>
2021-11-07 18:17:37 +00:00
Igor V. Kovalenko
fa3b66d249 lirc: Fix module version
Including lirc_client.h header overrides PACKAGE_VERSION with the one from lirc
packege. Fix this by moving lirc_client.h include after module definition block.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/660>
2021-11-06 13:45:30 +03:00
Marijn Suijten
add6e71e4c pulsecore/shm: Remove shm_marker struct packing for pa_atomic_t fields
Taking addresses of fields in a packed struct are not guaranteed to be
aligned, resulting in warnings such as:

    ../src/pulsecore/shm.c: In function 'sharedmem_create':
    ../src/pulsecore/shm.c:198:25: error: taking address of packed member of 'struct shm_marker' may result in an unaligned pointer value [-Werror=address-of-packed-member]
      198 |         pa_atomic_store(&marker->pid, (int) getpid());
          |                         ^~~~~~~~~~~~

The struct already has its fields and types laid out in such a way that
the desired packing (without padding) is guaranteed - enforce this with
a `static_assert` to get rid of the unaligned pointer warning.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/653>
2021-11-05 07:50:56 +00:00
Marijn Suijten
6e1ba7179c tests/mix-test: Don't pass unnecessary NULL fmt argument to fail_unless
GCC warns on all these `fail_unless` calls:

    warning: too many arguments for format [-Wformat-extra-args]

`fail_unless` only takes an expression and optionally a string literal
as message with formatting args.  Passing NULL for this message should
not be necessary as indicated by all the other tests not passing it
either.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/653>
2021-11-05 07:50:56 +00:00
Marijn Suijten
76652c8cdd gitlab-ci: Turn on Werror for meson builds
Prevent simple warnings like !651 from slipping into the build.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/653>
2021-11-05 07:50:56 +00:00
Marijn Suijten
874788433c gitlab-ci: Bump Ubuntu image to 20.04
e04f14eb/dc9dc70f introduced preprocessor warnings to deny the use of
any `alsa-lib` older than `1.2.1`, and with a future patch disallowing
warnings entirely through `-Werror` we now need a distribution that
serves a new enough `alsa-lib`.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/653>
2021-11-05 07:50:56 +00:00
Georg Chini
0497821afc solaris: Allow module-solaris to use alternative smoother code
This is untested.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
a92f566e36 raop-sink: Allow module-raop-sink to use alternative smoother code
This is untested.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
74585e1632 esound-sink: Allow module-esound-sink to use alternative smoother code
This is untested.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
a7c970e208 tunnel: Allow module-tunnel to use alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
79aaec7bb3 combine-sink: Allow module-combine-sink to use alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
1b5f3fc577 stream: Allow stream.c to use alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
84ec08e6f1 bluetooth: Allow bluetooth to use alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
8db67737d4 alsa sink/source: Allow alsa to use alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
6f16203144 Add configuration option enable-smoother-2 to enable alternative smoother code
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
156b572954 pulsecore: Add alternative time smoother implementation
This patch adds an alternative time smoother implementation based on the theory
found at https://www.freedesktop.org/software/pulseaudio/misc/rate_estimator.odt.

The functions were written to replace the current smoother functions nearly on
a one-to-one basis, though there are a few differences:
- The smoother_2_put() function takes a byte count instead of a sound card
  time as argument. This was changed because in most places a sample count
  was converted to a time before passing it to the smoother.
- The smoother needs to know sample rate and frame size to convert byte
  counts to time.
- A smoother_2_get_delay() function was added to directly retrieve the stream
  delay from the smoother.
- A hack for USB devices was added which works around an issue in the alsa
  latency reports for USB devices.

The smoother delivers much better precision than the current implementation.
For results, see the document referenced above.

The new functions are still unused. The following patches will convert all
callers of the smoother functions so that they can use both smoother
implementations, depending on a configure option.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/55>
2021-11-03 21:13:38 +00:00
Georg Chini
851c377d6b tests: Add resampler rewind test
This patch adds a test program that generates a square wave of a given frequency,
length and sample rate. This is then resampled to another rate, rewound and the
rewound part is run through the resampler again. After that, the results of the
first and second resampler pass are compared.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
a37fd7eada sink-input: Query sink inputs for max_rewind value when setting max_rewind
This patch is in preparation of allowing virtual sinks to specify their own
max_rewind limit.

Currently pa_sink_set_max_rewind_within_thread() simply sets the value of
max_rewind and informs the sink inputs about the new value. Virtual sinks
may however provide their own limit on max_rewind.

This patch allows to query the active sink inputs for the max_rewind value
they support and sets max_rewind to the minimum supported value. This way,
the max_rewind value from the virtual sinks can be communicated to the master
sink.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
5c6d91a97c sink-input: Limit rewinding to max_rewind for virtual sinks
This patch is in preparation of allowing virtual sinks to specify their own
max_rewind limit.
Currently, virtual sinks cannot specify their max_rewind limit, but just copy
the value from the master sink. This may not be correct, if the DSP code of the
virtual sink has limited (or no) rewinding capability.
Because the DSP code of the virtual sink is rewound in the process_rewind()
callback of the sink input, it must be ensured, that rewinding a sink input
to the master of a virtual sink is limited similar to rewinding a sink.
There are two remaining exceptions:

1) If an underrun is detected. In that case, the filter should be reset anyway.
2) When the sink input of the filter is moved and attached to the destination
sink.

The move case is handled without involvement of the implementer, so the implementer
can only receive a rewind larger than max_rewind when the filter should be reset
anyway.

All existing virtual sinks do not distinguish between reset and rewind of the
filter.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
f121779f88 loopback: Add resampler delay to latency snapshots
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
129a59a2f0 virtual sources: Include resampler delay in latency reports
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
d55fde2fed source-output: Fix rewinding
If the output implements a process_rewind() callback, the resampler delay is
not taken into account. This leads to glitches during volume changes when
source and source output rates differ.

This patch fixes the problem.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
a275a0b811 sink-input: Change move logic
The introduction of the history queue makes it possible to implement moving
of streams without involving the implementer. Instead of dropping all data
from the render memblockq and requesting the implementer to rewrite the
data, the render memblockq is now reconstructed from the history queue.

Additionally, the render queue will be filled with silence matching the
amount of audio that is left playing on the old sink to avoid playing
the same audio twice.

This patch slightly breaks moving for virtual sinks because they do not
yet include the resampler delay in their latency reports. This will be
fixed in a different patch set.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
da539ed336 sink-input: Implement resampler pseudo rewinding
This patch uses the two previous patches to implemnt pseudo-rewinding for the
resamplers by feeding some old data into the resampler after a reset. This is
necessary because PA is using external resamplers that do not implement
rewinding.

To get exactly the same output data from the resampler after a rewind if possible,
the matching period is calculated. This is the number of input samples that produces
an integral number of output samples. After the matching period, the resampler state
repeats. If the matching period is not too large, feeding history into the resampler
will start at a point that is a multiple of the matching period back in time. Then
the resampler will produce exactly the same samples.

The PA_RESAMPLER_MAX_HISTORY value has been replaced by PA_RESAMPLER_MAX_DELAY_USEC
and the required number of history samples is calculated from the sink input sample
rate. The number of history samples can be as large as about 12500.

This fixes glitches during volume changes when the sink runs on a rate different
from the sink input rate.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
656179a8fe resampler: Add pa_resampler_prepare() and pa_resampler_get_delay() functions
The pa_resampler_get_delay() function allows to retrieve the current resampler
delay in input samples for all supported resamplers. The return value is a double
to maintain precision when using variable rate resamplers. Because in many places
the delay is needed in usec, pa_resampler_get_delay_usec() was also supplied.

The speex resampler now skips leading zero samples to provide meaningful delay values.

In the next patch, the pa_resampler_prepare() function will be used to train the
resampler after a rewind. It takes data from a history memblockq and runs it through
the resampler. The output data is discarded.

To make this logic possible, the soxr resampler had to be converted to use variable
rate. The fixed rate version has a variable delay, therefore the logic above could
not be applied. Additionally, with fixed rate, the delay is larger than 150ms in
some situations, while with variable rate the delay is fixed and comparable to the
other resamplers.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Georg Chini
1bfabd6512 sink-input: Add history memblockq
A new memblockq is added to the sink input code to keep some history of the
input data. The queue is kept in sync with the render memblockq. The old input
data will be used to prepare the resampler after a rewind.

pa_resampler_request() and pa_resampler_result() have been changed to round
as good as possible to avoid loosing or duplicating samples during rewinds.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
2021-11-03 18:37:31 +00:00
Igor V. Kovalenko
90ccfc1688 null-sink: Recalculate max_request and max_rewind while resuming sink
When sink is suspended for reconfiguration changing sample spec, upon resume
internal thread_info max_request and max_rewind are out of date and possibly
not aligned to frame size anymore.

Recalculate thread max_request and max_rewind before resuming sink.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/658>
2021-11-03 15:59:22 +00:00
Igor V. Kovalenko
15c9ee5fec x11: Close session manager connection on ICE I/O error callback
When ICE I/O error occurs ICE connection is closed via IceCloseConnection.
This causes crash while releasing session manager connection later because
this ICE connection was initiated and is managed by session manager, and it will
attempt to close this ICE connection again.

Fix this by closing session manager connection instead.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/650>
2021-11-03 15:29:02 +00:00
Igor V. Kovalenko
696ffb464c message-params: Remove unwanted translations from log statements
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/655>
2021-10-24 13:37:47 +03:00
Igor V. Kovalenko
c0ad3efc18 bluetooth: Release container with device UUID strings
Stop leaking container with UUID strings when releasing adapter.

Fixes: 4b55b8a9d ("bluetooth: Keep a list of local adapters' UUIDs")
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/652>
2021-10-22 09:18:01 +03:00
Marijn Suijten
44ac675a8b bluetooth/native: Include util header for pa_msleep
Commit 7fd89e491 ("bluetooth: Try to reconnect SCO") introduces a call
to pa_msleep but failed to include the header, resulting in a:

    ../pulseaudio/src/modules/bluetooth/backend-native.c: In function ‘sco_acquire_cb’:
    ../pulseaudio/src/modules/bluetooth/backend-native.c:336:17: warning: implicit declaration of function ‘pa_msleep’ [-Wimplicit-function-declaration]
      336 |                 pa_msleep(300);
          |                 ^~~~~~~~~

(Un)fortunately this implicit declaration gets resolved at link-time,
otherwise the issue would have been caught sooner.

Fixes: 7fd89e491 ("bluetooth: Try to reconnect SCO")
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/651>
2021-10-22 00:24:33 +02:00
Marijn Suijten
ca9b723afa daemon/cmdline: Invert log-level list to match numerical values
Just like the manpage these written out log levels should correspond to
the numerical values listed before, intead of being in the opposite
order and provoking thoughts of the relation being the wrong way around
where 0=debug and 4=error.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/647>
2021-10-20 17:16:21 +02:00
Igor V. Kovalenko
8262815e94 message-params: If message paremeters is not JSON, wrap into JSON string
Requiring user to invoke send-message with correctly quoted parameters string
is not good for usability. Wrap parameters string into JSON string and try
again. If that works, log a warning use wrapped JSON string with parameters.

As an example these two commands will now invoke the same action:

    pactl send-message /card/bluez_card... switch-codec '"CODECNAME"'
    pactl send-message /card/bluez_card... switch-codec CODECNAME

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/648>
2021-10-19 09:45:27 +03:00
Tanu Kaskinen
5a03d84c32 i18n: Update .pot and .po files
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/645>
2021-10-08 21:57:34 +03:00