Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/205'
Browse files Browse the repository at this point in the history
* origin/pr/205: (24 commits)
  Fix audio quality problems
  Pass streams to stream callbacks
  Avoid crashing during shutdown
  Do not rely on pw_context_get_support() on modern PipeWire
  Drop support for PipeWire < 0.3.30
  Fix package descriptions
  Set node.rate for streams
  Add utility program to run any PipeWire stream
  Use libvchan_send and libvchan_recv for all-or-nothing ops
  Allow capturing vchan size in one go
  Better error reporting
  Avoid zeroing out recorded samples if underrun
  Atomically send initial stream states
  Use a #define for the stream rate
  Do not send QUBES_PA_SINK_UNCORK_CMD on overrun
  Fix error message when spa_format_parse() fails
  Downgrade unknown ID errors to warnings
  Reduce usage of confusing 'direction' flag
  Cleanup license metadata
  Obtain rate_match and position SPA IOs
  ...
  • Loading branch information
marmarek committed Feb 5, 2024
2 parents d4b8cdf + 92a144b commit 3b287d5
Show file tree
Hide file tree
Showing 7 changed files with 879 additions and 326 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ xf86-input-mfndev/config.h.in
xf86-input-mfndev/depcomp
xf86-input-mfndev/ltmain.sh
xf86-qubes-common/libxf86-qubes-common.so
pipewire/qubes-pw-module.so
/pipewire/qubes-pw-module.so
/pipewire/pw-module-run
*.dep
/gui-agent/qubes-gui
/gui-common/qubes-gui-runuser
8 changes: 4 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ Depends:
Conflicts: pulseaudio-qubes
Recommends: pipewire-pulse
Description: PipeWire module to enable sound support in Qubes VM
Experimental PipeWire module to enable sound support in Qubes VMs.
Unlike the PulseAudio support in the pulseaudio-qubes package, this
works with the stock PipeWire service and does not depend on internal
PipeWire headers. It is also less code.
PipeWire module to enable sound support in Qubes VMs. Unlike the
PulseAudio support in the pulseaudio-qubes package, this works with
the stock PipeWire service and does not depend on internal
PipeWire headers.

Package: qubes-gui-agent-xfce
Architecture: any
Expand Down
39 changes: 26 additions & 13 deletions pipewire/30_qubes.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,40 @@ context.properties = {
# experiencing a bunch of overruns or underruns.
#default.clock.min-quantum = 512

# The Qubes PipeWire module requires a buffer size to be provided.
# The record buffer size comes from the org.qubes-os.record-buffer-size
# property, and the playback buffer size comes from the
# org.qubes-os.record-buffer-size property. If either of these
# properties is missing, the value of org.qubes-os.vchan-buffer-size is
# used as a default.
#org.qubes-os.vchan-buffer-size = 32768
# Set the allowed audio rates to work around problems with Firefox
default.clock.allowed-rates = [ 44100 48000 ]

# Use a smaller buffer size for both recording and playback.
#org.qubes-os.vchan-buffer-size = 16384;
# Default size of the recording buffer in bytes. This is very large
# because a larger buffer only wastes some memory, whereas a small
# buffer risks overruns in the audio daemon (pacat-simple-vchan).
org.qubes-os.record.buffer-size = 1048576

# Use a larger buffer size for recording only
#org.qubes-os.record-buffer-size = 65536
# Default size of the playback buffer in bytes. This is smaller
# because a large buffer provides less benefit here: it is much more
# likely for the audio daemon to underrun (not be able to obtain
# enough samples) than for this module to overrun (run out of space).
org.qubes-os.playback.buffer-size = 65536

# Use a smaller buffer size for playback only
#org.qubes-os.playback-buffer-size = 16384
# The Qubes PipeWire module tries to keep the amount of data buffered
# in each vchan roughly constant. These parameters set this amount.
# Note that these parameters have units of *bytes*, not samples!
# FIXME: use samples instead.

# Target number of bytes in the playback vchan
org.qubes-os.playback.target-buffer = 8192

# Target number of bytes in the recording vchan
org.qubes-os.record.target-buffer = 8192
}

context.modules = [
{
name = libpipewire-module-qubes
# Arguments passed to the module override context properties.
# To reduce xruns at the expense of increased recording latency,
# one could add:
#
# args = { org.qubes-os.record.target-buffer = 16384 }
args = { }
}
]
8 changes: 6 additions & 2 deletions pipewire/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ extra_ldflags := $(shell pkg-config --libs libpipewire-0.3 vchan-xen) -lqubesdb
CFLAGS += $(extra_cflags)
LDLIBS += $(extra_ldflags)
LDFLAGS += -ggdb -Wl,--no-as-needed,--no-allow-shlib-undefined,-z,relro,-z,now
qubes-pw-module.so: build/qubes-pw-module.o | Makefile
all: qubes-pw-module.so pw-module-run
%.so: build/%.o | Makefile
@mkdir -p -m 0700 -- build
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -shared $(LDLIBS)
%: build/%.o | Makefile
@mkdir -p -m 0700 -- build
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

build/%.o: %.c Makefile
@mkdir -p -m 0700 -- build
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -MP -MD -MF $@.dep

.PHONY: clean
.PHONY: clean all .PHONY
clean:
rm -rf -- build
-include build/*.o.dep
41 changes: 41 additions & 0 deletions pipewire/pw-module-run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* SPDX-FileCopyrightText: Copyright © 2021-2023 Wim Taymans */
/* SPDX-FileCopyrightText: Copyright © 2021-2023 Demi Marie Obenour */
/* SPDX-License-Identifier: MIT */
/* C11 headers */
#include <stddef.h>
#include <stdlib.h>

/* glibc headers */
#include <err.h>

#include <pipewire/pipewire.h>
#include <pipewire/impl-module.h>

int main(int argc, char **argv)
{
pw_init(&argc, &argv);
if (argc < 3 || (argc & 1) == 0)
errx(1, "Usage: module-loader MODULE ARGS [MODULE ARGS...]\nTotal number of arguments must be even.");
struct pw_main_loop *loop = pw_main_loop_new(NULL);
if (!loop)
err(1, "pw_main_loop_new");
struct pw_context *context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0);
if (!context)
err(1, "pw_context_new");
struct pw_impl_module **modules = calloc(argc >> 1, sizeof(*modules));
if (!modules)
err(1, "calloc(%d, %zu)", argc, sizeof(*modules));
for (int i = 1; i < argc - 1; i += 2) {
if ((modules[i / 2] = pw_context_load_module(context, argv[i], argv[i + 1], NULL)) == NULL)
err(1, "pw_context_load_module");
}
int e = pw_main_loop_run(loop);
if (e < 0) {
errno = -e;
err(1, "pw_main_loop_run()");
}
pw_context_destroy(context);
pw_main_loop_destroy(loop);

return 0;
}
Loading

0 comments on commit 3b287d5

Please sign in to comment.