Skip to content

audio: change "low latency" buffer parameters #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

marmarek
Copy link
Member

This helps a lot when debugging various underruns.
@marmarek
Copy link
Member Author

FYI @DemiMarie I've added logging I used for graphs here. Since it proved useful, I'll make it opt-in in default binary too.

Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am quite concerned about a latency regression here. I would prefer to set .maxlength to 4096, while keeping .tlength at 4096.

@marmarek
Copy link
Member Author

marmarek commented Feb 22, 2024

I am quite concerned about a latency regression here

It isn't regression at all. maxlength used to be server default, which IIUC is about 4MB. PA agent used smaller vchan buffer, so it didn't manage to fill the whole PA's buffer, but it was still 8k.

@marmarek
Copy link
Member Author

And generally (if that would be the case, which isn't) no underruns takes priority over low latency.

Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffer attribute changes look fine, but if pa_stream_get_latency() fails the code will log either wrong data or uninitialized stack rubble.

Comment on lines +222 to +225
if (pa_stream_get_latency(s, &latency, &negative))
pacat_log("pa_stream_get_latency() failed");

pacat_log("process_playback_data(): vchan data %d max_length %d latency %llu", space_in_vchan, max_length, latency);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pa_stream_get_latency(s, &latency, &negative))
pacat_log("pa_stream_get_latency() failed");
pacat_log("process_playback_data(): vchan data %d max_length %d latency %llu", space_in_vchan, max_length, latency);
if (pa_stream_get_latency(s, &latency, &negative))
pacat_log("pa_stream_get_latency() failed");
else
pacat_log("process_playback_data(): vchan data %d max_length %d latency %llu", space_in_vchan, max_length, latency);

otherwise we might log uninitialized stack rubble

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but a) I still want other values logged, and b) thanks to PA_STREAM_INTERPOLATE_TIMING that happens basically only once at the very start.

@@ -210,6 +215,16 @@ static void process_playback_data(struct userdata *u, pa_stream *s, size_t max_l
return;
}

if (verbose > 1) {
pa_usec_t latency = 0;
int negative;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int negative;
int negative = 0;

avoid logging junk from the stack

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use the value at all, so it doesn't matter.

@qubesos-bot
Copy link

qubesos-bot commented Feb 23, 2024

OpenQA test summary

Complete test suite and dependencies: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.2&build=2024040413-4.2&flavor=pull-requests

New failures, excluding unstable

Compared to: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.2&build=2024031904-4.2&flavor=update

Failed tests

78 failures

Fixed failures

Compared to: https://openqa.qubes-os.org/tests/94176#dependencies

34 fixed
  • system_tests_basic_vm_qrexec_gui

  • system_tests_pvgrub_salt_storage

    • StorageFile: test_000_volatile (failure)
      AssertionError: libvirt event impl drain timeout
  • system_tests_extra

    • TC_00_Appmenus: test_121_create_appvm_with_whitelist (failure)
      '/tmp/tmpj_cxpqzs/test-inst-app/apps/org.qubes-os.qubes-vm-setting...

    • TC_00_QVCTest_debian-12-xfce: test_010_screenshare (failure)
      AssertionError: 4.5510031017096475 not less than 2.0

    • TC_00_QVCTest_debian-12-xfce: test_020_webcam (failure)
      ^^^^^^^^^^^^^^^^^^^^^^... AssertionError

    • TC_00_QVCTest_fedora-39-xfce: test_010_screenshare (failure)
      ^^^^^^^^^^^^^^^^^^^^^^... AssertionError

    • TC_00_QVCTest_fedora-39-xfce: test_020_webcam (error)
      ~~~~^~~~~~~~~~... ZeroDivisionError: division by zero

    • TC_00_QVCTest_whonix-gateway-17: test_010_screenshare (failure)
      AssertionError: 'qubes-video-companion screenshare' exited early (1...

    • TC_00_QVCTest_whonix-gateway-17: test_020_webcam (failure)
      self.assertIsNone(p.returncode)... AssertionError: 1 is not None

    • TC_00_QVCTest_whonix-workstation-17: test_010_screenshare (failure)
      AssertionError: 'qubes-video-companion screenshare' exited early (1...

    • TC_00_QVCTest_whonix-workstation-17: test_020_webcam (failure)
      self.assertIsNone(p.returncode)... AssertionError: 1 is not None

  • system_tests_basic_vm_qrexec_gui_zfs

    • TC_20_AudioVM_Pulse_debian-12-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 8.25297052154195...

    • TC_20_AudioVM_Pulse_fedora-39-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 9.44344671201814...

    • TC_20_AudioVM_PipeWire_debian-12-xfce-pool: test_226_audio_playback_pipewire (failure)
      AssertionError: too short audio, expected 10s, got 8.33129251700680...

    • TC_20_AudioVM_PipeWire_fedora-39-xfce-pool: test_226_audio_playback_pipewire (failure)
      AssertionError: too short audio, expected 10s, got 8.69671201814059...

  • system_tests_basic_vm_qrexec_gui_btrfs

    • TC_20_AudioVM_Pulse_debian-12-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 8.73378684807256...

    • TC_20_AudioVM_Pulse_fedora-39-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 8.99789115646258...

    • TC_20_AudioVM_PipeWire_debian-12-xfce-pool: test_226_audio_playback_pipewire (failure)
      AssertionError: too short audio, expected 10s, got 9.47451247165532...

  • system_tests_basic_vm_qrexec_gui_ext4

    • TC_20_AudioVM_Pulse_debian-12-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 8.77791383219954...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_221_audio_rec_muted_pulseaudio (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_222_audio_rec_unmuted_pulseaudio (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_223_audio_play_hvm (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_224_audio_rec_muted_hvm (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_Pulse_whonix-workstation-17-pool: test_225_audio_rec_unmuted_hvm (failure)
      AssertionError: Timeout waiting for pulseaudio start in test-inst-v...

    • TC_20_AudioVM_PipeWire_fedora-39-xfce-pool: test_226_audio_playback_pipewire (failure)
      AssertionError: too short audio, expected 10s, got 9.14578231292517...

  • system_tests_basic_vm_qrexec_gui_xfs

    • TC_20_AudioVM_Pulse_debian-12-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 9.48453514739229...

    • TC_20_AudioVM_Pulse_fedora-39-xfce-pool: test_220_audio_play_pulseaudio (failure)
      AssertionError: too short audio, expected 10s, got 9.49594104308390...

  • system_tests_basic_vm_qrexec_gui@hw1

    • TC_20_AudioVM_Pulse_debian-12-xfce: test_223_audio_play_hvm (failure)
      AssertionError: too short audio, expected 10s, got 8.65913832199546...

    • TC_20_AudioVM_Pulse_fedora-39-xfce: test_220_audio_play_pulseaudio (failure)
      AssertionError: Command 'paplay --format=float32le --rate=44100 --c...

    • TC_20_AudioVM_Pulse_fedora-39-xfce: test_223_audio_play_hvm (failure)
      AssertionError: too short audio, expected 10s, got 8.71560090702948...

Unstable tests

  • system_tests_whonix

    whonix_torbrowser/ (1/5 times with errors)
    whonix_torbrowser/Failed (1/5 times with errors)
    • job 92213 # Test died: no candidate needle with tag(s) 'anon-whonix-tor-brows...
  • system_tests_basic_vm_qrexec_gui

    TC_20_AudioVM_Pulse_debian-12-xfce/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 92010 AssertionError: too short audio, expected 10s, got 9.13582766439909...
    • job 92220 AssertionError: Command 'paplay --format=float32le --rate=44100 --c...
    • job 92785 AssertionError: too short audio, expected 10s, got 9.0062358276644,...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.90877551020408...
    • job 94385 AssertionError: too short audio, expected 10s, got 8.26902494331065...
    TC_20_AudioVM_Pulse_fedora-38-xfce/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 92010 AssertionError: too short audio, expected 10s, got 8.25360544217687...
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 92785 AssertionError: too short audio, expected 10s, got 8.95287981859410...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.84258503401360...
    • job 94385 AssertionError: too short audio, expected 10s, got 8.97528344671201...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_221_audio_rec_muted_pulseaudio (1/5 times with errors)
    • job 94189 AssertionError: source-output for VM test-inst-vm1 not found
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_223_audio_play_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_226_audio_playback_pipewire (3/5 times with errors)
    • job 92785 AssertionError: too short audio, expected 10s, got 9.40351473922902...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.83732426303854...
    • job 94385 AssertionError: too short audio, expected 10s, got 9.34784580498866...
    TC_20_AudioVM_PipeWire_fedora-38-xfce/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 92220 AssertionError: too short audio, expected 10s, got 9.49464852607709...
  • system_tests_pvgrub_salt_storage

    TC_41_HVMGrub_fedora-38-xfce/test_000_standalone_vm (2/5 times with errors)
    • job 92026 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 92232 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-39-xfce/test_000_standalone_vm (3/5 times with errors)
    • job 92797 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94201 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94397 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-38-xfce/test_000_standalone_vm (1/5 times with errors)
    • job 92026 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-39-xfce/test_000_standalone_vm (2/5 times with errors)
    • job 94201 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94397 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    StorageFile/test_000_volatile (1/5 times with errors)
    • job 94201 AssertionError: libvirt event impl drain timeout
    TC_41_HVMGrub_fedora-38-xfce/test_010_template_based_vm (2/5 times with errors)
    • job 92026 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 92232 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-39-xfce/test_010_template_based_vm (3/5 times with errors)
    • job 92797 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94201 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94397 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-38-xfce/test_010_template_based_vm (1/5 times with errors)
    • job 92026 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-39-xfce/test_010_template_based_vm (2/5 times with errors)
    • job 94201 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 94397 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
  • system_tests_splitgpg

    TC_10_Thunderbird_fedora-39-xfce/test_000_send_receive_default (3/5 times with errors)
    • job 92799 Exception: Failed to send message with error 'unknown'
    • job 94203 Exception: Failed to send message with error 'unknown'
    • job 94399 Exception: Failed to send message with error 'unknown'
    TC_10_Thunderbird_fedora-38-xfce/test_010_send_receive_inline_signed_only (1/5 times with errors)
    • job 92234 Exception: Failed to send message with error 'unknown'
    TC_10_Thunderbird_fedora-39-xfce/test_010_send_receive_inline_signed_only (3/5 times with errors)
    • job 92799 Exception: Failed to send message with error 'unknown'
    • job 94203 Exception: Failed to send message with error 'unknown'
    • job 94399 Exception: Failed to send message with error 'unknown'
    TC_10_Thunderbird_fedora-39-xfce/test_020_send_receive_inline_with_attachment (3/5 times with errors)
    • job 92799 Exception: Failed to send message with error 'unknown'
    • job 94203 Exception: Failed to send message with error 'unknown'
    • job 94399 Exception: Failed to send message with error 'unknown'
  • system_tests_extra

    TC_00_QVCTest_debian-12-xfce/test_010_screenshare (2/5 times with errors)
    • job 94184 AssertionError: 4.5510031017096475 not less than 2.0
    • job 94380 ^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    TC_00_QVCTest_fedora-39-xfce/test_010_screenshare (2/5 times with errors)
    • job 94184 ^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    • job 94380 ^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    TC_00_QVCTest_whonix-gateway-17/test_010_screenshare (2/5 times with errors)
    • job 94184 AssertionError: 'qubes-video-companion screenshare' exited early (1...
    • job 94380 AssertionError: 'qubes-video-companion screenshare' exited early (1...
    TC_00_QVCTest_whonix-workstation-17/test_010_screenshare (2/5 times with errors)
    • job 94184 AssertionError: 'qubes-video-companion screenshare' exited early (1...
    • job 94380 AssertionError: 'qubes-video-companion screenshare' exited early (1...
    TC_00_QVCTest_debian-12-xfce/test_020_webcam (2/5 times with errors)
    • job 94184 ^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    • job 94380 ^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    TC_00_QVCTest_fedora-39-xfce/test_020_webcam (2/5 times with errors)
    • job 94184 ~~~~^~~~~~~~~~... ZeroDivisionError: division by zero
    • job 94380 ~~~~^~~~~~~~~~... ZeroDivisionError: division by zero
    TC_00_QVCTest_whonix-gateway-17/test_020_webcam (2/5 times with errors)
    • job 94184 self.assertIsNone(p.returncode)... AssertionError: 1 is not None
    • job 94380 self.assertIsNone(p.returncode)... AssertionError: 1 is not None
    TC_00_QVCTest_whonix-workstation-17/test_020_webcam (2/5 times with errors)
    • job 94184 self.assertIsNone(p.returncode)... AssertionError: 1 is not None
    • job 94380 self.assertIsNone(p.returncode)... AssertionError: 1 is not None
    TC_00_Appmenus/test_121_create_appvm_with_whitelist (2/5 times with errors)
    • job 94184 '/tmp/tmpj_cxpqzs/test-inst-app/apps/org.qubes-os.qubes-vm-setting...
    • job 94380 '/tmp/tmpb0w885he/test-inst-app/apps/org.qubes-os.qubes-vm-setting...
  • system_tests_usbproxy

    TC_20_USBProxy_core3_debian-12-xfce/test_070_attach_not_installed_front (1/5 times with errors)
    • job 95152 qubesusbproxy.core3ext.QubesUSBException: Device attach failed: 202...
    TC_20_USBProxy_core3_whonix-gateway-17/test_070_attach_not_installed_front (1/5 times with errors)
    • job 95152 qubesusbproxy.core3ext.QubesUSBException: Device attach failed: 202...
  • system_tests_network_updates

    TC_10_QvmTemplate_debian-12-xfce/test_010_template_install (1/5 times with errors)
    • job 94200 AssertionError: libvirt event impl drain timeout
    VmUpdates_debian-12-xfce/test_131_no_network_qubes_vm_update_cli (2/5 times with errors)
    • job 92021 AssertionError: qubes-vm-update return unexpected code: 0 in (1, 2)
    • job 92231 AssertionError: qubes-vm-update return unexpected code: 0 in (1, 2)
  • system_tests_dispvm

    TC_20_DispVM_fedora-39-xfce/test_100_open_in_dispvm (1/5 times with errors)
    • job 94390 AssertionError: './open-file test.txt' failed with ./open-file test...
  • system_tests_basic_vm_qrexec_gui_zfs

    TC_00_Basic/test_120_start_standalone_with_cdrom_dom0 (1/5 times with errors)
    • job 92775 AssertionError: 1 != 0 : b'Timeout waiting for dom0:loop4 device to...
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (4/5 times with errors)
    • job 91798 AssertionError: too short audio, expected 10s, got 9.19061224489796...
    • job 92775 AssertionError: too short audio, expected 10s, got 8.92689342403628...
    • job 94179 AssertionError: too short audio, expected 10s, got 8.25297052154195...
    • job 94379 AssertionError: Command 'paplay --format=float32le --rate=44100 --c...
    TC_20_AudioVM_Pulse_fedora-38-xfce-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 91798 AssertionError: too short audio, expected 10s, got 8.94136054421768...
    • job 92000 AssertionError: too short audio, expected 10s, got 9.49195011337868...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 92775 AssertionError: too short audio, expected 10s, got 8.97582766439909...
    • job 94179 AssertionError: too short audio, expected 10s, got 9.44344671201814...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94179 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94379 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce-pool/test_226_audio_playback_pipewire (2/5 times with errors)
    • job 92775 AssertionError: too short audio, expected 10s, got 9.49938775510204...
    • job 94179 AssertionError: too short audio, expected 10s, got 8.33129251700680...
    TC_20_AudioVM_PipeWire_fedora-39-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 94179 AssertionError: too short audio, expected 10s, got 8.69671201814059...
  • system_tests_basic_vm_qrexec_gui_btrfs

    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 92011 AssertionError: too short audio, expected 10s, got 8.35183673469387...
    • job 92221 AssertionError: too short audio, expected 10s, got 8.16569160997732...
    • job 92786 AssertionError: too short audio, expected 10s, got 6.71056689342403...
    • job 94190 AssertionError: too short audio, expected 10s, got 8.73378684807256...
    • job 94386 AssertionError: too short audio, expected 10s, got 9.32555555555555...
    TC_20_AudioVM_Pulse_fedora-38-xfce-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 92011 AssertionError: too short audio, expected 10s, got 8.88408163265306...
    • job 92221 AssertionError: too short audio, expected 10s, got 9.05950113378684...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 92786 AssertionError: too short audio, expected 10s, got 8.91759637188208...
    • job 94190 AssertionError: too short audio, expected 10s, got 8.99789115646258...
    • job 94386 AssertionError: too short audio, expected 10s, got 9.21634920634920...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94190 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94386 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce-pool/test_226_audio_playback_pipewire (2/5 times with errors)
    • job 92221 AssertionError: too short audio, expected 10s, got 9.43346938775510...
    • job 94190 AssertionError: too short audio, expected 10s, got 9.47451247165532...
    TC_20_AudioVM_PipeWire_fedora-38-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 92221 AssertionError: too short audio, expected 10s, got 9.48482993197278...
    TC_20_AudioVM_PipeWire_fedora-39-xfce-pool/test_226_audio_playback_pipewire (2/5 times with errors)
    • job 92786 AssertionError: too short audio, expected 10s, got 9.09208616780045...
    • job 94386 AssertionError: too short audio, expected 10s, got 7.64335600907029...
  • system_tests_basic_vm_qrexec_gui_ext4

    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 92012 AssertionError: too short audio, expected 10s, got 9.32294784580498...
    • job 92222 AssertionError: too short audio, expected 10s, got 7.86945578231292...
    • job 92787 AssertionError: too short audio, expected 10s, got 8.15968253968254...
    • job 94191 AssertionError: too short audio, expected 10s, got 7.61653061224489...
    • job 94268 AssertionError: too short audio, expected 10s, got 8.77791383219954...
    TC_20_AudioVM_Pulse_fedora-38-xfce-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 92012 AssertionError: too short audio, expected 10s, got 8.59505668934240...
    • job 92222 AssertionError: too short audio, expected 10s, got 9.04922902494331...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 92787 AssertionError: too short audio, expected 10s, got 8.98693877551020...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_222_audio_rec_unmuted_pulseaudio (1/5 times with errors)
    • job 92012 qubes.exc.QubesVMError: Failed to attach audio input from dom0 to t...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94191 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94268 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_fedora-39-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 94268 AssertionError: too short audio, expected 10s, got 9.14578231292517...
  • system_tests_basic_vm_qrexec_gui_xfs

    TC_30_Gui_daemon/test_000_clipboard (1/5 times with errors)
    • job 92788 self.assertEqual(test_string, test_o... AssertionError: 'test23' != ''
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 92013 AssertionError: Command 'paplay --format=float32le --rate=44100 --c...
    • job 92223 AssertionError: too short audio, expected 10s, got 9.39870748299319...
    • job 92788 AssertionError: too short audio, expected 10s, got 8.30274376417233...
    • job 94192 AssertionError: too short audio, expected 10s, got 9.48453514739229...
    • job 94388 AssertionError: too short audio, expected 10s, got 9.32911564625850...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 92788 AssertionError: too short audio, expected 10s, got 9.10965986394557...
    • job 94192 AssertionError: too short audio, expected 10s, got 9.49594104308390...
    • job 94388 AssertionError: too short audio, expected 10s, got 8.73632653061224...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_222_audio_rec_unmuted_pulseaudio (1/5 times with errors)
    • job 94388 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94192 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94388 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 92788 AssertionError: too short audio, expected 10s, got 9.49714285714285...
    TC_20_AudioVM_PipeWire_fedora-39-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 94388 AssertionError: too short audio, expected 10s, got 9.47580498866213...
  • system_tests_whonix@hw1

    whonix_torbrowser/ (1/5 times with errors)
    whonix_torbrowser/Failed (1/5 times with errors)
    • job 92213 # Test died: no candidate needle with tag(s) 'anon-whonix-tor-brows...
  • system_tests_basic_vm_qrexec_gui@hw1

    TC_20_AudioVM_Pulse_debian-12-xfce/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 92010 AssertionError: too short audio, expected 10s, got 9.13582766439909...
    • job 92220 AssertionError: Command 'paplay --format=float32le --rate=44100 --c...
    • job 92785 AssertionError: too short audio, expected 10s, got 9.0062358276644,...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.90877551020408...
    • job 94385 AssertionError: too short audio, expected 10s, got 8.26902494331065...
    TC_20_AudioVM_Pulse_fedora-38-xfce/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 92010 AssertionError: too short audio, expected 10s, got 8.25360544217687...
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 92785 AssertionError: too short audio, expected 10s, got 8.95287981859410...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.84258503401360...
    • job 94385 AssertionError: too short audio, expected 10s, got 8.97528344671201...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_220_audio_play_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_221_audio_rec_muted_pulseaudio (1/5 times with errors)
    • job 94189 AssertionError: source-output for VM test-inst-vm1 not found
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_221_audio_rec_muted_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_222_audio_rec_unmuted_pulseaudio (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_223_audio_play_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 94189 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 94385 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_226_audio_playback_pipewire (3/5 times with errors)
    • job 92785 AssertionError: too short audio, expected 10s, got 9.40351473922902...
    • job 94189 AssertionError: too short audio, expected 10s, got 8.83732426303854...
    • job 94385 AssertionError: too short audio, expected 10s, got 9.34784580498866...
    TC_20_AudioVM_PipeWire_fedora-38-xfce/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 92220 AssertionError: too short audio, expected 10s, got 9.49464852607709...

@marmarek
Copy link
Member Author

marmarek commented Feb 23, 2024

system_tests_basic_vm_qrexec_gui@hw1

* TC_20_AudioVM_Pulse_debian-12-xfce: [test_223_audio_play_hvm](https://openqa.qubes-os.org/tests/92414#step/TC_20_AudioVM_Pulse_debian-12-xfce/4) (failure)
  `AssertionError: frequency 977.2385421984841 not in specified range,...`

* TC_20_AudioVM_Pulse_fedora-38-xfce: [test_223_audio_play_hvm](https://openqa.qubes-os.org/tests/92414#step/TC_20_AudioVM_Pulse_fedora-38-xfce/4) (failure)
  `AssertionError: frequency 986.4409885532086 not in specified range,...`

* TC_20_AudioVM_Pulse_whonix-workstation-17: [test_220_audio_play_pulseaudio](https://openqa.qubes-os.org/tests/92414#step/TC_20_AudioVM_Pulse_whonix-workstation-17/1) (failure)
  `AssertionError: frequency 945.4942192569575 not in specified range,...`

* TC_20_AudioVM_Pulse_whonix-workstation-17: [test_223_audio_play_hvm](https://openqa.qubes-os.org/tests/92414#step/TC_20_AudioVM_Pulse_whonix-workstation-17/4) (failure)
  `AssertionError: too short audio, expected 10s, got 8.94485260770975...`

This is a regression. Those tests are about emulated sound card for HVM, so PipeWire agent is not involved. But PulseAudio agent running in a stubdomain is. Depending on a test, both playback and recording failed. I'll inspect logs more closely and experiment with some parameters, but I suspect changing maxlength for this case is a mistake. But it could be also related to migration to PipeWire in dom0, not this PR.

@marmarek
Copy link
Member Author

The HVM playback was problem in a test (yet another difference between Pulseaudio and PipeWire). But HVM recording seems to be legit issue.

@DemiMarie
Copy link
Contributor

Want me to make the changes conditional on buffer sizes? The PipeWire agent uses much bigger buffers.

@marmarek
Copy link
Member Author

If that will be necessary, I can also add an option for that (qvm-start-daemon knows very well if given pacat process is for the domain itself or its stubdomain).

@DemiMarie
Copy link
Contributor

If that will be necessary, I can also add an option for that (qvm-start-daemon knows very well if given pacat process is for the domain itself or its stubdomain).

I thought the problem was with PulseAudio vs PipeWire in the guest.

@marmarek
Copy link
Member Author

I have an alternative idea - instead of changing buffer parameters, change how much data is read from the vchan, using this:

/** Return the number of bytes requested by the server that have not yet
 * been written.
 *
 * It is possible to write more than this amount, up to the stream's
 * buffer_attr.maxlength bytes. This is usually not desirable, though, as
 * it would increase stream latency to be higher than requested
 * (buffer_attr.tlength).
 *
 * (size_t) -1 is returned on error.
 */
size_t pa_stream_writable_size(const pa_stream *p);

@DemiMarie
Copy link
Contributor

@marmarek The code already does this for reads initiated by vchan activity.

@marmarek
Copy link
Member Author

Hmm, I'm trying to get what is the size (nbytes) parameter to the write callback. In our code it's called max_length, but it isn't clear if it's really max size or requested size.

@DemiMarie
Copy link
Contributor

Hmm, I'm trying to get what is the size (nbytes) parameter to the write callback. In our code it's called max_length, but it isn't clear if it's really max size or requested size.

Checking the source indicates that it is the same value that pa_stream_writable_size() would return.

@marmarek
Copy link
Member Author

Ok, then it wouldn't change anything.

@marmarek
Copy link
Member Author

But in that case, my change tlength->maxlength shouldn't matter for playback. But as the failing recording test shows, it does matter for recording, in negative way. I'll rollback the change, but maybe make tlength configurable?

Oh, and also, fragsize 4096 is incompatible with PA's agent 2048 vchan size, and it works only due to blocking vchan calls. I'll try changing to 2048 and see if that helps.

@marmarek
Copy link
Member Author

or better change PA's agent vchan to 4096 ?

@marmarek
Copy link
Member Author

marmarek commented Feb 23, 2024

In any case, this shows rather clearly that prebuf/tlength handling in Pulseaudio is broken...

Log timing information about playback stream, used for debugging
underruns.
Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strtoul() is a terrible API, sorry…

Comment on lines 1079 to 1091
case 't':
bufattr = &custom_bufattr;
errno = 0;
custom_bufattr.tlength = strtoul(optarg, &endptr, 0);
if (*endptr || errno == ERANGE)
err(1, "Invalid -t argument: %s", optarg);
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case 't':
bufattr = &custom_bufattr;
errno = 0;
custom_bufattr.tlength = strtoul(optarg, &endptr, 0);
if (*endptr || errno == ERANGE)
err(1, "Invalid -t argument: %s", optarg);
break;
case 't':
bufattr = &custom_bufattr;
errno = 0;
unsigned long p = strtoul(optarg, &endptr, 0);
if (*endptr)
errx(1, "Invalid -t argument: %s", optarg);
if (p > UINT32_MAX)
errno = ERANGE;
if (errno)
err(1, "Invalid -t argument: %s", optarg);
break;

PipeWire audio agent synchronizes to pacat-simple-vchan rate of taking
data out of vchan and wants to ensure it never ends empty. Pulseaudio
and PipeWire seems to handle them differently (looks like Pulseaudio is
less accurate in this regard). With PipeWire in dom0, it is closer to
what is configured, and theoretically could lead to underruns. Make it
configurable (beyond just disabling low latency mode), so it's easier to
mitigate issues. Note also that PA_STREAM_ADJUST_LATENCY is enabled, so
the tlength avalue includes hardware buffer size, which may differ from
system to system. And also, tlength affects default prebuf value.

While at it, reduce fragsize for recording. Pulseaudio agent (used in
older distributions, and in a stubdomain) uses vchan of 2048 bytes, so
record stream chunked into 4096 doesn't fit. It works only because
pacat-simple-vchan uses blocking vchan writes, but that may negatively
impact parallel playback stream. And also, smaller fragsize may reduce
latency (although it was good enough already).

QubesOS/qubes-issues#8955
@marmarek
Copy link
Member Author

The HVM playback was problem in a test (yet another difference between Pulseaudio and PipeWire). But HVM recording seems to be legit issue.

Or maybe another issue with tests? I found this in the log:

1708756176.132966 Buffer metrics: maxlength=4194304, tlength=4096, prebuf=4294967295, minreq=4294967295
1708756176.133012 Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'.
1708756176.150634 Connected to device alsa_output.pci-0000_00_03.0.analog-stereo.monitor (48, not suspended).
1708756176.150793 Recording requested but not allowed
1708756176.180393 Stream started.�[K
1708756176.184494 Stream underrun.�[K
1708756176.210018 Stream started.�[K
1708756177.311861 Stream underrun.�[K
1708756177.320785 Stream started.�[K
1708756179.361800 Stream underrun.�[K
1708756179.362170 Stream started.�[K
1708756179.525348 Stream underrun.�[K
1708756179.548189 Stream started.�[K
1708756180.041450 Stream underrun.�[K
1708756180.059797 Stream started.�[K
1708756184.109916 Stream underrun.�[K
1708756184.129262 Stream started.�[K
2024-02-24 01:29:45,889 icon-receiver: connected: test-inst-vm1
1708756186.376039 Setting audio-input to enabled
1708756186.376245 Recording start
app: Connection to qubesd terminated, reconnecting in 1.0 seconds

So, recording was enabled quite late in the test, no wonder it recorded shorter sound than intended (or nothing at all). But also, there was a few underruns, might be relevant.
Anyway, this needs a closer look, the issue wasn't there before migrating to PipeWire.

@marmarek
Copy link
Member Author

The HVM recording on debian-12 seems to be a pipewire bug (see QubesOS/qubes-issues#8590). It's fixed in newer pipewire (and so the test passes on fedora template). It was "working" before because the test was broken (and I got it fixed in QubesOS/qubes-core-admin#581). I'll exclude it for now.

Remaining thing to check is recording on whonix-workstation template - which runs pulseaudio (not pipewire-pulse).

@marmarek
Copy link
Member Author

Remaining thing to check is recording on whonix-workstation template - which runs pulseaudio (not pipewire-pulse).

I'm struggling with this case. It looks like with pipewire in dom0 it fails, but with pulseaudio in dom0 it works. More specifically, the failing setup is:

  • qube based on whonix-workstation-17
  • pulseaudio inside the qube (as whonix-ws has), with qubes module unloaded
  • virt_mode hvm
  • qvm-features audio-model ich6
  • running on nested virt (inside KVM)
  • dom0 configured to record "monitor" stream by default, and recording allowed for the test qube
  • playing in dom0, and recording in VM

I've tried changing various parameters, like fragsize (both down and up), and also updated PA agent inside stubdomain (so it uses 8KiB vchan buffer instead of 2KiB). Nothing helped. What does help is switching dom0 audio daemon back to pulseaudio. The test passes also with (new, fedora-38) pipewire running inside the qube.

The result is some missing samples, mostly in the middle. And the test fails with: AssertionError: too short audio, expected 10s, got 8.36628117913832... Recorded audio can be fetched from https://openqa.qubes-os.org/tests/92456/file/system_tests-audio-sample-qubes.tests.integ.vm_qrexec_gui.tar.gz (play with paplay --raw --format=float32le --rate=44100 --channels=1).

The specific setup above is unusual enough (especially the nested virt) that it shouldn't matter in theory. But very obvious issues in this setup usually correlated with more subtle issues on more usual configurations. And it's usually easier to debug more obvious issue. What I worry here, is that switching audio daemon in dom0 will regress audio recording for non-Linux HVMs (or even Linux, but without qubes packages).

Any ideas what else I can try?

@DemiMarie
Copy link
Contributor

Remaining thing to check is recording on whonix-workstation template - which runs pulseaudio (not pipewire-pulse).

I'm struggling with this case. It looks like with pipewire in dom0 it fails, but with pulseaudio in dom0 it works. More specifically, the failing setup is:

  • qube based on whonix-workstation-17
  • pulseaudio inside the qube (as whonix-ws has), with qubes module unloaded
  • virt_mode hvm
  • qvm-features audio-model ich6
  • running on nested virt (inside KVM)
  • dom0 configured to record "monitor" stream by default, and recording allowed for the test qube
  • playing in dom0, and recording in VM

I've tried changing various parameters, like fragsize (both down and up), and also updated PA agent inside stubdomain (so it uses 8KiB vchan buffer instead of 2KiB). Nothing helped. What does help is switching dom0 audio daemon back to pulseaudio. The test passes also with (new, fedora-38) pipewire running inside the qube.

The result is some missing samples, mostly in the middle. And the test fails with: AssertionError: too short audio, expected 10s, got 8.36628117913832... Recorded audio can be fetched from https://openqa.qubes-os.org/tests/92456/file/system_tests-audio-sample-qubes.tests.integ.vm_qrexec_gui.tar.gz (play with paplay --raw --format=float32le --rate=44100 --channels=1).

The specific setup above is unusual enough (especially the nested virt) that it shouldn't matter in theory. But very obvious issues in this setup usually correlated with more subtle issues on more usual configurations. And it's usually easier to debug more obvious issue. What I worry here, is that switching audio daemon in dom0 will regress audio recording for non-Linux HVMs (or even Linux, but without qubes packages).

Any ideas what else I can try?

  1. @adrelanos is switching to PipeWire an option?
  2. What about using PipeWire in the stubdomain, or (better yet) having QEMU talk to pacat directly, with no audio server involved?

@marmarek
Copy link
Member Author

  1. is switching to PipeWire an option?

That is not the point... I fear what we see here is a symptom of broken audio in HVM in general, that will manifest in other cases, maybe even not Linux.

2. What about using PipeWire in the stubdomain, or (better yet) having QEMU talk to pacat directly, with no audio server involved?

The former I don't like, due to significantly higher memory usage for PipeWire, which is even more critical in stubdomain. The latter might be an option in theory, but given how "well" it went with pipewire agent implementation, I'm skeptical we will improve the situation this way.

@marmarek
Copy link
Member Author

Oh, and if I retry the test few more times, it fails with new pipewire in the VM too. But after switching to pulseaudio in dom0 it works every time.

@adrelanos
Copy link
Member

  1. @adrelanos is switching to PipeWire an option?

As far as Qubes-Whonix is concerned, yes, very much so. This is unspecific to Qubes-Whonix.

(Non-Qubes-Whonix is already on PipeWire.)

qubes-whonix debian/control contains Depends: on pulseaudio-qubes. Happy to change to something else. Please let me know.

@DemiMarie
Copy link
Contributor

Oh, and if I retry the test few more times, it fails with new pipewire in the VM too. But after switching to pulseaudio in dom0 it works every time.

So I think the test matrix is:

  1. direction: recording vs playback
  2. dom0 audio server: PipeWire + pipewire-pulse vs PulseAudio
  3. system: nested virt vs bare hardware
  4. guest audio: emulated vs Qubes PV
  5. guest audio server: PulseAudio vs PipeWire

Which of these 32 possibilities are good and which are bad? Is there an openQA run where I can look at the results of all of these?

My understanding is:

  1. With PipeWire in both dom0 and domU, Fill vchan partially before uncorking stream qubes-gui-agent-linux#207 is needed to fix a single underrun immediately after the stream is uncorked. Otherwise, everything works fine on bare hardware, but I have no idea about nested virt.
  2. With PulseAudio in dom0, a PulseAudio server bug causes very large latency and problems with the PipeWire agent. This problem is independent of PipeWire vs PulseAudio in the guest, but the PulseAudio agent doesn’t trigger it, presumably because of extra buffering there.
  3. Earlier revisions in this PR tried and failed work around the PulseAudio bug, so the plan is to switch to PipeWire in dom0.
  4. Switching to PipeWire in dom0 fixes playback in all cases, but recording is now broken in a subset of cases.

Is this accurate? I’m somewhat confused as to what is happening here, which is why I am asking for the results in all 32 possible cases.

@marmarek
Copy link
Member Author

Which of these 32 possibilities are good and which are bad? Is there an openQA run where I can look at the results of all of these?

I think it should be possible to collect all the combinations.

Take a most recent run: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.2&build=2024022504-4.2&flavor=pull-requests

click on vm_qrexec_gui tests

direction: recording vs playback

"rec" or "play" in test name

dom0 audio server: PipeWire + pipewire-pulse vs PulseAudio

recent runs use pipewire in dom0; for pulseaudio in dom0 you need an earlier run, for example this: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.2&build=2024021900-4.2&groupid=11; but note the audio_rec_unmuted_hvm test wasn't fixed at that time, so it's skipped in many cases)

system: nested virt vs bare hardware

the one with "@hw1" is on bare hardware, others are nested virt

guest audio: emulated vs Qubes PV

"hvm" in test name is emulated, others are qubes pv

guest audio server: PulseAudio vs PipeWire

template:

  • fedora - pipewire >= 1.0
  • debian - pipewire 0.3.something
  • whonix-workstation - pulseaudio
  • whonix-gateway - nothing (and test skipped)

Especially for nested virt, check few jobs (the whole vm_qrexec_gui suite is ran several times with different storage, so you have quite a few data points) - a single passing instance doesn't necessarily mean it's good. Failures are collected in qubesos-bot message in relevant PR (this included), you can check edits history for older reports - that's usually quicker way than manually clicking on all the jobs.

Oh, and one more thing, failure "only silence detected" is not interesting - it's either buggy test, or the known issue in the old pipewire.

My understanding is:

1. With PipeWire in both dom0 and domU, https://github.com/QubesOS/qubes-gui-agent-linux/pull/207 is needed to fix a single underrun immediately after the stream is uncorked. Otherwise, everything works fine on bare hardware, but I have no idea about nested virt.

For PV audio - yes, both bare hw and nested virt is good. And the single underrun at the start is not a problem (looks like an artifact prebuf kicking in), so that PR isn't needed IMO.

2. With PulseAudio in dom0, a PulseAudio server bug causes very large latency and problems with the PipeWire agent. This problem is independent of PipeWire vs PulseAudio in the guest, but the PulseAudio agent doesn’t trigger it, presumably because of extra buffering there.

Large latencies and a lot of underruns for several seconds after starting playback on nested virt (and some less on bare hw, but still problematic). Neither of those problem affect dom0 PA + domU PA setup, only dom0 PA + domU PW is affected.

3. Earlier revisions in this PR tried and failed work around the PulseAudio bug, so the plan is to switch to PipeWire in dom0.

Yes.

4. Switching to PipeWire in dom0 fixes playback in all cases, but recording is now broken in a subset of cases.

Recording using emulated audio is affected. And on the very last run, I see a single failure of emulated playback (with pulseaudio in domU).

@DemiMarie
Copy link
Contributor

  1. With PipeWire in both dom0 and domU, Fill vchan partially before uncorking stream qubes-gui-agent-linux#207 is needed to fix a single underrun immediately after the stream is uncorked. Otherwise, everything works fine on bare hardware, but I have no idea about nested virt.

For PV audio - yes, both bare hw and nested virt is good. And the single underrun at the start is not a problem (looks like an artifact prebuf kicking in), so that PR isn't needed IMO.

I’d still like to eliminate the underrun, mostly because it can hide real underruns (not due to prebuf) which indicate actual problems. I vaguely remember this being a problem when developing the PipeWire agent.

@marmarek
Copy link
Member Author

What I don't like about that PR is second-guessing what dom0 part is doing, including some variable parameters (like buffer size to fill in). That will lead to issues sooner or latter (for example, if we'd reduce pacat buffer sizes at some point in the future, the prefill PR will cause overruns at start). If pacat needs to delay uncork until at least some amount of data is collected, it's the job of pacat to do that, not domU agent. And the prebuf feature does exactly that. I'm not sure why I haven't managed to get it working with real Pulseaudio (it could be a bug in PA, but very well it could be also some other bug in pacat), but with PipeWire in dom0 it seems to work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants