🐛 Give each VM's recording a sound device of its own
A recording made while an output played got nothing. On reims-ctl's one virtio sound device of an output and an input stream, the guest starts the input with each output and soon stops posting receive buffers, so a recording that joins a playing output gets none, and QEMU has nowhere to put the host's input. AppleVirtIOSound's HAL plug-in makes one Core Audio device of each virtio-snd device and starts all of its streams together, posting an input's receive buffers only at its start and as each completes while its ring has room (read from its code). On a device started for an output, nothing reads that ring. reims-ctl now gives every VM a playback-only device at 0x7 (streams=1) and a capture-only one at 0x8 (streams=1,input-streams=1, vendor/qemu 1422502b), beside the HDA controller as before. What the guest sees: two "Apple Virtual Sound Device"s, the default output and the default input, where one device was both. Measured on a macOS 26.7.2 guest on homelab-um790's Radeon 780M, one cold boot each way (job m3-max-24761, docs/qemu.md "x86-64 macOS guests: audio"). With the two devices, a 10 s recording 20 s into a 50 s play got 117 receive buffers and the host source's live audio in each second. On the one device the same recording got no buffer, 2 s of older samples and 8 s of zeros. An output alone no longer starts the input, and the host's source stays suspended through it. A QEMU built before 1422502b refuses input-streams, so this reims-ctl needs the QEMU its installer builds (install-ctl.sh without --skip-qemu, whose warning names a changed QEMU).
This commit is contained in:
1 parent
c15786ce4c
commit
bca8c6e7f0
4 files changed
+61
-16
No files matched your search
@@ -331,8 +331,8 @@ pub struct CreateArgs {
|
||||
/// Keep the library's log and the serial console
|
||||
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
|
||||
pub logs: Option<bool>,
|
||||
/// A virtio sound device on the host's sound, with a microphone, and the HDA controller
|
||||
/// OpenCore's boot chime plays on
|
||||
/// Two virtio sound devices on the host's sound, a speaker and a microphone, and the HDA
|
||||
/// controller OpenCore's boot chime plays on
|
||||
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
|
||||
pub audio: Option<bool>,
|
||||
/// Its network card (user-mode NAT); --network false makes it with none, as an offline
|
||||
|
||||
@@ -11,9 +11,12 @@
|
||||
//! - user networking with virtio-net, and an optional SSH port forward; with networking off,
|
||||
//! `-nic none`, without which QEMU gives the machine its default NIC on user networking (on
|
||||
//! q35 an e1000e in the first free slot, 1, where the root port's address is);
|
||||
//! - a virtio sound device on the host's audio backend, one output stream and one input stream,
|
||||
//! which x86-64 macOS's AppleVirtIOSound drives (docs/qemu.md, "x86-64 macOS guests: audio"):
|
||||
//! Safari's Media Source players fail without an output device; and an ICH9 Intel HDA
|
||||
//! - two virtio sound devices on the host's audio backend, which x86-64 macOS's AppleVirtIOSound
|
||||
//! drives (docs/qemu.md, "x86-64 macOS guests: audio"): one with an output stream alone, since
|
||||
//! Safari's Media Source players fail without an output device, and one with an input stream
|
||||
//! alone, so a recording starts the guest's input whether or not an output plays (on one device
|
||||
//! with both, the guest starts the input with each output and stops reading it, and a recording
|
||||
//! made while an output plays gets nothing); and an ICH9 Intel HDA
|
||||
//! controller with a line-out codec on that backend, for OpenCore's boot chime: its AudioDxe
|
||||
//! drives HDA, not virtio sound, and x86-64 macOS 26 has no HDA driver, so the guest's only
|
||||
//! output is the virtio device;
|
||||
@@ -325,7 +328,9 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
|
||||
push(&["-audiodev", &audiodev(vm, ctx)]);
|
||||
push(&[
|
||||
"-device",
|
||||
"virtio-sound-pci,id=audio,audiodev=snd0,addr=0x7",
|
||||
"virtio-sound-pci,id=audio,audiodev=snd0,addr=0x7,streams=1",
|
||||
"-device",
|
||||
"virtio-sound-pci,id=audioin,audiodev=snd0,addr=0x8,streams=1,input-streams=1",
|
||||
]);
|
||||
// At ICH9's own slot for it.
|
||||
push(&["-device", "ich9-intel-hda,id=hda,addr=0x1b"]);
|
||||
@@ -551,7 +556,9 @@ mod tests {
|
||||
&["-audiodev", "pipewire,id=snd0"],
|
||||
&[
|
||||
"-device",
|
||||
"virtio-sound-pci,id=audio,audiodev=snd0,addr=0x7",
|
||||
"virtio-sound-pci,id=audio,audiodev=snd0,addr=0x7,streams=1",
|
||||
"-device",
|
||||
"virtio-sound-pci,id=audioin,audiodev=snd0,addr=0x8,streams=1,input-streams=1",
|
||||
],
|
||||
&["-device", "ich9-intel-hda,id=hda,addr=0x1b"],
|
||||
&["-device", "hda-output,bus=hda.0,audiodev=snd0"],
|
||||
|
||||
@@ -1584,8 +1584,8 @@ impl App {
|
||||
"audio",
|
||||
"Audio",
|
||||
c.audio.enabled,
|
||||
"A virtio sound device on the host's sound, with a microphone, and the HDA \
|
||||
controller OpenCore's boot chime plays on.",
|
||||
"Two virtio sound devices on the host's sound, a speaker and a microphone, and \
|
||||
the HDA controller OpenCore's boot chime plays on.",
|
||||
),
|
||||
Field::toggle(
|
||||
"logs",
|
||||
|
||||
+45
-7
@@ -763,16 +763,20 @@ on `reims-graphics-pci` it is **unknown**.
|
||||
|
||||
### x86-64 macOS guests: audio
|
||||
|
||||
reims-ctl gives every VM a virtio sound device, with one output and one
|
||||
input stream:
|
||||
reims-ctl gives every VM two virtio sound devices, one with an output
|
||||
stream alone and one with an input stream alone (vendor/qemu's
|
||||
`input-streams` property):
|
||||
|
||||
```sh
|
||||
-audiodev pipewire,id=snd0 -device virtio-sound-pci,audiodev=snd0,addr=0x7
|
||||
-audiodev pipewire,id=snd0
|
||||
-device virtio-sound-pci,id=audio,audiodev=snd0,addr=0x7,streams=1
|
||||
-device virtio-sound-pci,id=audioin,audiodev=snd0,addr=0x8,streams=1,input-streams=1
|
||||
```
|
||||
|
||||
macOS's `AppleVirtIO` kext has `AppleVirtIOSound`, matching virtio device
|
||||
0x19. **Measured**
|
||||
with a macOS 26.7.2 (25G332) x86-64 guest on reims-ctl's q35 command, on a
|
||||
with a macOS 26.7.2 (25G332) x86-64 guest on reims-ctl's q35 command with
|
||||
one device of both streams (`virtio-sound-pci,audiodev=snd0,addr=0x7`), on a
|
||||
Radeon 780M host:
|
||||
- `AppleVirtIOPCITransport` binds the device (`pci1af4,1059`), with
|
||||
`AppleVirtIOSound` and its user client on it. Core Audio lists one
|
||||
@@ -785,9 +789,9 @@ Radeon 780M host:
|
||||
- Safari's Media Source player plays H.264 with AAC (fragmented MP4) and
|
||||
VP9 with Opus (WebM) to the end, and their audio reaches QEMU.
|
||||
|
||||
The guest starts its input stream with each output stream, and reads it
|
||||
only at first. **Measured** with the 26.7.2 guest on reims-ctl's audio
|
||||
devices, on a host whose PipeWire default source is an analog input and
|
||||
On one device of both streams, the guest starts its input stream with each
|
||||
output stream, and reads it only at first. **Measured** with the 26.7.2
|
||||
guest on that device, on a host whose PipeWire default source is an analog input and
|
||||
whose sink is the dummy `auto_null` (homelab-um790's Radeon 780M,
|
||||
2026-11-12, QEMU's `virtio_snd_*` traces):
|
||||
- Each `afplay` sets up and starts stream 1, the input, with stream 0,
|
||||
@@ -829,6 +833,40 @@ whose sink is the dummy `auto_null` (homelab-um790's Radeon 780M,
|
||||
on the usb-tablet at its Allow button).
|
||||
- A host with no source (um870, ms01) runs no capture cycles.
|
||||
|
||||
Why, read from the code of AppleVirtIOSound's HAL plug-in (the x86_64
|
||||
slice of macOS 27.0.1's `AppleVirtIOSound.driver`, disassembled for this
|
||||
and not committed): the plug-in makes one Core Audio device of each
|
||||
virtio-snd device, with all of its streams, and starts them together. It
|
||||
posts an input stream's receive buffers at the stream's start (four) and
|
||||
again at each one's completion while its ring buffer has room, and a
|
||||
client's read takes from that ring. On a device started for an output,
|
||||
nothing reads the input's ring, which fills, and the posting ends until
|
||||
the device stops.
|
||||
|
||||
So reims-ctl gives the input a device of its own. **Measured** with the
|
||||
26.7.2 guest on the two devices above and, as the control, on the one
|
||||
device of both streams, one cold boot each on the same host with the same
|
||||
phases (homelab-um790's Radeon 780M, 2026-11-13, vendor/qemu 1422502b,
|
||||
QEMU's `virtio_snd_*` traces; the harness named the sink as the capture's
|
||||
target, and the default source, an analog input, ran in its place):
|
||||
- Core Audio lists two devices named "Apple Virtual Sound Device": one with
|
||||
2 input channels, the default input, and one with 2 output channels,
|
||||
the default output and system output. Each `AppleVirtIOSound` has one
|
||||
stream.
|
||||
- An `afplay` starts the output device's stream alone: the input stays
|
||||
stopped, and the host's source suspended, through plays of 25 and 50 s.
|
||||
- A 10 s recording started 20 s into a 50 s play starts the input
|
||||
device's stream 0.65 s after its command, and the guest posts receive
|
||||
buffers to its end, 117 of them, at most 0.13 s apart. The host's
|
||||
default source runs with it, no read found more than 2,824 bytes
|
||||
waiting, and the recording holds the source's audio in each of its 10
|
||||
seconds (98.7% of its samples non-zero; that host's analog input carries
|
||||
full-scale noise). On the one device the same recording got no receive
|
||||
buffer and no captured read: its first 2 s hold samples from before it,
|
||||
and its other 8 s are zeros.
|
||||
- A recording alone runs as on the one device: 94 receive buffers in 8 s,
|
||||
and the source's audio in each second.
|
||||
|
||||
|
||||
`pa` in place of `pipewire` uses PulseAudio, and `none` gives the guest a
|
||||
working output whose samples QEMU drops. macOS 26 for x86-64 ships no
|
||||
|
||||
Reference in new issue
Block a user