Commit Graph

165 Commits

Author SHA1 Message Date
Chris Spencer
9908b737b0 [client] audio: make the requested audio device period size configurable
This adds a new `audio:periodSize` option which defaults to 2048 frames.
For PipeWire, this controls the `PIPEWIRE_LATENCY` value. For PulseAudio,
the controls the target buffer length (`tlength`) value.
2022-02-25 20:41:47 +11:00
Tudor Brindus
91d6e3a82a [client] allow building with -Wstrict-prototypes
This is not yet turned on because cimgui does not build with it enabled.
2022-02-25 20:38:44 +11:00
Chris Spencer
0d97a51802 [client] audio: increase startup latency
Underruns can still happen quite easily at the beginning of playback,
particularly at very low latency settings. Further increase the startup
latency to avoid this.
2022-02-10 07:50:01 +11:00
Tudor Brindus
da548e3858 [client] ds: expose activation requesting 2022-02-08 14:54:55 +11:00
Chris Spencer
e1e60fdaa6 [client] audio: tune target latency
The target latency is now based upon the device maximum period size
(which may be configured by setting the `PIPEWIRE_LATENCY` environment
variable if using PipeWire), with some allowance for timing jitter from
Spice and the audio device.

PipeWire can change the period size dynamically at any time which must be
taken into account when selecting the target latency to avoid underruns
when the period size is increased. This is explained in detail within the
commit body.
2022-02-04 16:27:12 +11:00
Geoffrey McRae
22b968ff53 [client] audio: change the audio latency graph sample point
This removes the need for locking while also giving a better result in
the graph output. Also when the graph is disabled via the overlay
options it will no longer cause redraws.
2022-01-28 10:59:12 +11:00
Geoffrey McRae
a0477466d2 Revert "[client] audio: allow the audiodev to return the periodFrames"
This reverts commit 41884bfcc5.

PipeWire can change it's period size on the fly on us making this
approach invalid.
2022-01-28 10:00:35 +11:00
Geoffrey McRae
41884bfcc5 [client] audio: allow the audiodev to return the periodFrames
This change allows the audiodevs to return the minimum period frames
needed to start playback instead of having to rely on a pull to obtain
these details.

Additionally we are using this information to select an initial start
latency as well as to train the desired latency in order to keep it as
low as possible.
2022-01-27 18:03:11 +11:00
Chris Spencer
dd2d84a080 [client] audio: adjust playback speed to match audio device clock
This change is based on the techniques described in [1] and [2].

The input audio stream from Spice is not synchronised to the audio playback
device. While the input and output may be both nominally running at 48 kHz,
when compared against each other, they will differ by a tiny fraction of a
percent. Given enough time (typically on the order of a few hours), this
will result in the ring buffer becoming completely full or completely
empty. It will stay in this state permanently, periodically resulting in
glitches as the buffer repeatedly underruns or overruns.

To address this, adjust the speed of the received data to match the rate at
which it is being consumed by the audio device. This will result in a
slight pitch shift, but the changes should be small and smooth enough that
this is unnoticeable to the user.

The process works roughly as follows:
1. Every time audio data is received from Spice, or consumed by the audio
   device, sample the current time. These are fed into a pair of delay
   locked loops to produce smoothed approximations of the two clocks.
2. Compute the difference between the two clocks and compare this against
   the target latency to produce an error value. This error value will be
   quite stable during normal operation, but can change quite rapidly due
   to external factors, particularly at the start of playback. To smooth
   out any sudden changes in playback speed, which would be noticeable to
   the user, this value is also filtered through another delay locked loop.
3. Feed this error value into a PI controller to produce a ratio value.
   This is the target playback speed in order to bring the error value
   towards zero.
4. Resample the input audio using the computed ratio to apply the speed
   change. The output of the resampler is what is ultimately inserted into
   the ring buffer for consumption by the audio device.

Since this process targets a specific latency value, rather than simply
trying to rate match the input and output, it also has the effect of
'correcting' latency issues. If a high latency application (such as a media
player) is already running, the time between requesting the start of
playback and the audio device actually starting to consume samples can be
very high, easily in the hundreds of milliseconds. The changes here will
automatically adjust the playback speed over the course of a few minutes to
bring the latency back down to the target value.

[1] https://kokkinizita.linuxaudio.org/papers/adapt-resamp.pdf
[2] https://kokkinizita.linuxaudio.org/papers/usingdll.pdf
2022-01-27 18:03:11 +11:00
Geoffrey McRae
15f76339c8 [client] audio: move the memory copy into the pull function 2022-01-19 10:29:49 +11:00
Geoffrey McRae
04ae9217e8 [client] audio: allow the audiodev to determine the start fill level 2022-01-19 01:52:19 +11:00
Geoffrey McRae
b334f22223 [client] audio: rework audiodevs to be pull model from a common buffer 2022-01-18 09:02:44 +11:00
Geoffrey McRae
0ad26b7da7 [client] audio: redraw the graphs if they have been updated 2022-01-17 22:49:19 +11:00
Geoffrey McRae
689cc53255 [client] audio: add audio playback latency interface and graph 2022-01-17 22:13:41 +11:00
Geoffrey McRae
464fee3e20 [client] overlay/graphs: allow the graph to have a custom title format 2022-01-17 22:08:56 +11:00
Geoffrey McRae
5a3fe151e4 [client] main: don't use Linux keybinds if the guest is not Linux 2022-01-17 20:26:45 +11:00
Geoffrey McRae
6bba9bc25d [client/common] move ll from the client into the common code module 2022-01-12 12:22:18 +11:00
Geoffrey McRae
1851002fc1 [client] all: remove ll_walk and migrate over to ll_forEachNL 2022-01-12 12:17:29 +11:00
Geoffrey McRae
b99e1ea38e [client] ll: fix error in ll_forEachNL macro 2022-01-12 12:17:06 +11:00
Geoffrey McRae
e94252ad65 squash with ll 2022-01-12 10:03:31 +11:00
Geoffrey McRae
6fc0c69b2e [client] overlay/msg: provide a method to close messages from code 2022-01-12 09:35:09 +11:00
Geoffrey McRae
ced952a4c6 [client] ll: add new functionallity to allow removal of items 2022-01-12 09:33:36 +11:00
Geoffrey McRae
780cf5f362 [client] overlay: add modal message dialog support 2022-01-08 18:58:48 +11:00
Geoffrey McRae
0080e5f1b9 [client] overlay: add app_invalidateOverlay method 2022-01-08 15:18:40 +11:00
Geoffrey McRae
db2e38ae4d [client] overlay: add 25Hz tick function
This allows an overlay to manage itself for timed events like
alerts/messages, etc.
2022-01-08 14:33:07 +11:00
Geoffrey McRae
fe7973ea24 [client] audio: implement record interface and glue 2022-01-06 23:49:20 +11:00
Geoffrey McRae
e6bd36ec7c [client] audio: refactor audio to playback and add record funcs 2022-01-06 22:47:22 +11:00
Geoffrey McRae
952ebea2c5 [all] refresh copyright dates 2022-01-05 19:42:46 +11:00
Geoffrey McRae
0d27092ef5 [all] move min/max and upcast macros into common/util.h 2022-01-05 19:41:57 +11:00
Geoffrey McRae
433a5420cb [client] audio: update PureSpice and add support for volume control/mute 2021-12-26 11:09:42 +11:00
Geoffrey McRae
e810577317 [client] audio: initial addition of PipeWire audio support via SPICE 2021-12-26 11:09:42 +11:00
Geoffrey McRae
d69069fb09 [client] egl: keep the mouse cursor 1:1 when downscaling
This keeps the cursor a usable size when the guest is running a high
resolution and downscaling (ie, 4K -> FHD).
2021-12-26 11:08:42 +11:00
Quantum
ad4b40fad6 [client] opengl: add gl_dynprocs module
This is similar to egl_dynprocs, except for OpenGL functions.
2021-10-01 01:45:11 +10:00
Quantum
072c54977e [client] egl: use eglCreateImage and eglDestroyImage indirectly
The dmabuf path is optional, so we shouldn't require those functions to
link our program.
2021-09-29 17:48:50 +10:00
Quantum
5c7f168370 [client] egl_dynprocs: use official prototypes from system headers 2021-09-29 17:48:50 +10:00
Quantum
429620c48b [client] egl: dynamically import glBufferStorageEXT
On some implementations (e.g. llvmpipe), the function can only be queried via
eglGetProcAddress.
2021-08-19 21:28:45 +10:00
Quantum
3a00277e93 [client] spice: add ability to set keyboard LED state in guest
FIXME: update PureSpice
2021-08-15 09:46:31 +10:00
Quantum
9414449408 [client] app: add ability to receive keyboard typing in overlays 2021-08-14 14:44:26 +10:00
Quantum
579f998519 [client] all: replace assert with DEBUG_ASSERT 2021-08-14 12:19:07 +10:00
Geoffrey McRae
6387bf2d2e [client] rework the configuration overlay to allow for tabs 2021-08-12 09:04:45 +10:00
Quantum
7e982a6658 [client] util: replace util_mergeOverlappingRects with common version 2021-08-11 19:01:52 +10:00
Geoffrey McRae
f4a925a750 [client] main: destroy and finish fontconfig usage
Fixes ASAN reported memory leak
2021-08-08 16:21:48 +10:00
Geoffrey McRae
30ed563504 [client] interface: refactor to use camlCase function names 2021-08-08 15:43:42 +10:00
Geoffrey McRae
f8ae291090 [client] interface: switch to using UPCAST for the renderer's data 2021-08-08 15:32:01 +10:00
Geoffrey McRae
45d1f27fb4 [client] interface: rename LG_Renderer to LG_RendererOps
Part of the standardisation of using the `Ops` suffix for all interfaces
2021-08-08 14:43:04 +10:00
Geoffrey McRae
1a8267d55a [client] interface: cleanup the renderer interface
Removes the silly typedefs and adds some basic documentation as to the
usage of each function.
2021-08-08 14:39:40 +10:00
Geoffrey McRae
162b1b93db [client] main: don't include the swap into the render timings
If vsync is enabled the swap will block until vblank skewing the timing
metrics.
2021-08-07 01:45:42 +10:00
Quantum
08f3ad504c [client] imgui: implement new widget for displaying URLs
Note that actually opening the browser is not implemented yet.
2021-08-05 22:43:46 +10:00
Geoffrey McRae
6e7f39edee [client] app: allow selective full invalidation
Overlays only need to trigger a new frame if they have changed and not
full window invalidation, this change allows for this.
2021-08-05 06:47:36 +10:00
Geoffrey McRae
6c84c0eca6 [client] overlay: move keybinds and config into the overlays
This adds a new `earlyInit` call which allows the overlay to register
options before actually being intialized. Also the keybind handling and
state tracking for each overlay has been moved internal to the overlay
itself.
2021-08-05 06:40:06 +10:00