Skip to content
Snippets Groups Projects
  1. Jan 15, 2021
    • Volker Rümelin's avatar
      paaudio: send recorded data in smaller chunks · d9a8b27a
      Volker Rümelin authored
      
      Tell PulseAudio to send recorded audio data in smaller chunks
      than timer_period, so there's a good chance that qemu can read
      recorded audio data every time it looks for new data.
      
      PulseAudio tries to send buffer updates at a fragsize / 2 rate.
      With fragsize = timer_period / 2 * 3 the update rate is 75% of
      timer_period. The lower limit for the recording buffer size
      maxlength is fragsize * 2.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-19-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      d9a8b27a
    • Volker Rümelin's avatar
      paaudio: limit minreq to 75% of audio timer_rate · 00413ed9
      Volker Rümelin authored
      
      Currently with the playback buffer attribute minreq = -1 and flag
      PA_STREAM_EARLY_REQUESTS PulseAudio uses minreq = tlength / 4.
      To improve audio playback with larger PulseAudio server side
      buffers, limit minreq to a maximum of 75% of audio timer_rate.
      That way there is a good chance qemu receives a stream buffer
      size update before it tries to write data to the playback stream.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-18-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      00413ed9
    • Volker Rümelin's avatar
      paaudio: comment bugs in functions qpa_init_* · cffd2fdf
      Volker Rümelin authored
      
      The audio buffer size in audio/paaudio.c is typically larger
      than expected. Just comment the bugs in qpa_init_in() and
      qpa_init_out() for now. Fixing these bugs may break glitch free
      audio playback with fine tuned user audio settings.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-17-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      cffd2fdf
    • Volker Rümelin's avatar
      paaudio: remove unneeded code · 521ce714
      Volker Rümelin authored
      
      Commit baea032e "audio/paaudio: fix ignored buffer_length setting"
      added code to handle buffer_length defaults. This was unnecessary
      because the audio_buffer_* functions in audio/audio.c already handle
      this. Remove the unneeded code.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-16-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      521ce714
    • Volker Rümelin's avatar
      paaudio: wait until the playback stream is ready · 7007cd3f
      Volker Rümelin authored
      
      Don't call pa_stream_writable_size() in qpa_get_buffer_out()
      before the playback stream is ready. This prevents a lot of the
      following pulseaudio error messages.
      
      pulseaudio: pa_stream_writable_size failed
      pulseaudio: Reason: Bad state
      
      To reproduce start qemu with
      -parallel none -device gus,audiodev=audio0 -audiodev pa,id=audio0
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-15-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      7007cd3f
    • Volker Rümelin's avatar
      paaudio: wait for PA_STREAM_READY in qpa_write() · e270c548
      Volker Rümelin authored
      
      Don't call pa_stream_writable_size() in qpa_write() before the
      playback stream is ready. This prevents a lot of the following
      pulseaudio error messages.
      
      pulseaudio: pa_stream_writable_size failed
      pulseaudio: Reason: Bad state
      
      To reproduce start qemu with
      -parallel none -device gus,audiodev=audio0
      -audiodev pa,id=audio0,out.mixing-engine=off
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-14-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      e270c548
    • Volker Rümelin's avatar
      paaudio: avoid to clip samples multiple times · bea29e9f
      Volker Rümelin authored
      
      The pulseaudio backend currently converts, clips and copies audio
      playback samples in the mixing-engine sample buffer multiple
      times.
      
      In qpa_get_buffer_out() the function pa_stream_begin_write()
      returns a rather large buffer and this allows audio_pcm_hw_run_out()
      in audio/audio.c to copy all samples in the mixing-engine buffer
      to the pulse audio buffer. Immediately after copying, qpa_write()
      notices with a call to pa_stream_writable_size() that pulse audio
      only needs a smaller part of the copied samples and ignores the
      rest. This copy and ignore process happens several times for each
      audio sample.
      
      To fix this behaviour, call pa_stream_writable_size() in
      qpa_get_buffer_out() to limit the number of samples
      audio_pcm_hw_run_out() will convert. With this change the
      pulseaudio pcm_ops functions put_buffer_out and write are no
      longer identical and a separate qpa_put_buffer_out is needed.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
      Message-Id: <20210110100239.27588-13-vr_qemu@t-online.de>
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      bea29e9f
  2. Feb 06, 2020
  3. Jan 31, 2020
  4. Jan 06, 2020
    • Volker Rümelin's avatar
      paaudio: wait until the recording stream is ready · 7c9eb86e
      Volker Rümelin authored
      
      Don't call pa_stream_peek before the recording stream is ready.
      
      Information to reproduce the problem.
      
      Start and stop Audacity in the guest several times because the
      problem is racy.
      
      libvirt log file:
      -audiodev pa,id=audio0,server=localhost,out.latency=30000,
       out.mixing-engine=off,in.mixing-engine=off \
      -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,
       resourcecontrol=deny \
      -msg timestamp=on
      : Domain id=4 is tainted: custom-argv
      char device redirected to /dev/pts/1 (label charserial0)
      audio: Device pcspk: audiodev default parameter is deprecated,
       please specify audiodev=audio0
      audio: Device hda: audiodev default parameter is deprecated,
       please specify audiodev=audio0
      pulseaudio: pa_stream_peek failed
      pulseaudio: Reason: Bad state
      pulseaudio: pa_stream_peek failed
      pulseaudio: Reason: Bad state
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 20200104091122.13971-5-vr_qemu@t-online.de
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      7c9eb86e
    • Volker Rümelin's avatar
      paaudio: try to drain the recording stream · acc3b63e
      Volker Rümelin authored
      
      There is no guarantee a single call to pa_stream_peek every
      timer_period microseconds can read a recording stream faster
      than the data gets produced at the source. Let qpa_read try to
      drain the recording stream.
      
      To reproduce the problem:
      
      Start qemu with -audiodev pa,id=audio0,in.mixing-engine=off
      
      On the host connect the qemu recording stream to the monitor of
      a hardware output device. While the problem can also be seen
      with a hardware input device, it's obvious with the monitor of
      a hardware output device.
      
      In the guest start audio recording with audacity and notice the
      slow recording data rate.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 20200104091122.13971-4-vr_qemu@t-online.de
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      acc3b63e
    • Volker Rümelin's avatar
      paaudio: drop recording stream in qpa_fini_in · 4db3e634
      Volker Rümelin authored
      
      Every call to pa_stream_peek which returns a data length > 0
      should have a corresponding pa_stream_drop. A call to qpa_read
      does not necessarily call pa_stream_drop immediately after a
      call to pa_stream_peek. Test in qpa_fini_in if a last
      pa_stream_drop is needed.
      
      This prevents following messages in the libvirt log file after
      a recording stream gets closed and a new one opened.
      
      pulseaudio: pa_stream_drop failed
      pulseaudio: Reason: Bad state
      pulseaudio: pa_stream_drop failed
      pulseaudio: Reason: Bad state
      
      To reproduce start qemu with
      -audiodev pa,id=audio0,in.mixing-engine=off
      and in the guest start and stop Audacity several times.
      
      Signed-off-by: default avatarVolker Rümelin <vr_qemu@t-online.de>
      Message-id: 20200104091122.13971-3-vr_qemu@t-online.de
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      4db3e634
  5. Oct 26, 2019
  6. Oct 18, 2019
  7. Sep 23, 2019
  8. Aug 21, 2019
  9. Jul 03, 2019
    • Martin Schrodt's avatar
      fix microphone lag with PA · 58c15e52
      Martin Schrodt authored
      
      Several people have reported to have bag microphone lag with the PA
      backend. While I cannot reproduce the problem here, it seems that their
      PA somehow decides to buffer the microphone input for way too long,
      causing this delay. This patch sets an upper limit to the amount of
      data PA should hold. This fixes the problem reliably on their side,
      while having no adverse effects on mine.
      
      Signed-off-by: default avatarMartin Schrodt <martin@schrodt.org>
      Message-id: 20190615153852.99040-1-martin@schrodt.org
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      58c15e52
  10. Jun 12, 2019
  11. Mar 18, 2019
    • Martin Schrodt's avatar
      audio/paaudio: fix microphone input being unusable · ade10301
      Martin Schrodt authored
      
      The current code does not specify the metrics of the buffers for the
      input device. This makes PulseAudio choose very bad defaults, which
      causes input to be unusable: Audio put in gets out 30 seconds later.
      This patch fixes that and makes the latency configurable as well.
      
      Signed-off-by: default avatarMartin Schrodt <martin@schrodt.org>
      Message-id: 20190315084653.120020-4-martin@schrodt.org
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      ade10301
    • Martin Schrodt's avatar
      audio/paaudio: prolong and make latency configurable · f6142777
      Martin Schrodt authored
      
      The latency of a connection to the PulseAudio server is determined by
      the tlength parameter. This was hardcoded to 10ms, which is a bit too
      tight on my machine, causing audio on host and guest to malfunction.
      A setting of 15ms works fine here. To allow tweaking, I also made the
      setting configurable via the new -audiodev config. This allows to squeeze out better timings in scenarios where the emulation allows it.
      
      I also removed setting of the minreq parameter to (seemingly arbitrary) half the latency, since it showed worse audio quality during my tests. Allowing PulseAudio to request smaller chunks helped.
      
      Signed-off-by: default avatarMartin Schrodt <martin@schrodt.org>
      Message-id: 20190315084653.120020-3-martin@schrodt.org
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      f6142777
    • Martin Schrodt's avatar
      audio/paaudio: fix ignored buffer_length setting · baea032e
      Martin Schrodt authored
      
      Audiodev configuration allows to set the length of the buffered data.
      The setting was ignored and a constant value used instead.
      This patch makes the code apply the setting properly, and uses the
      previous default if nothing is supplied.
      
      Signed-off-by: default avatarMartin Schrodt <martin@schrodt.org>
      Message-id: 20190315084653.120020-2-martin@schrodt.org
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      baea032e
  12. Mar 11, 2019
  13. Jan 24, 2019
    • Gerd Hoffmann's avatar
      audio: check for pulseaudio daemon pidfile · d175505b
      Gerd Hoffmann authored
      
      Check whenever the pulseaudio daemon pidfile is present before trying to
      initialize the pulseaudio backend.  Just return NULL if that is not the
      case, so qemu will check the next backend in line.
      
      In case the user explicitly configured a non-default pulseaudio server
      skip the check.
      
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Message-id: 20190124112055.547-5-kraxel@redhat.com
      d175505b
  14. Nov 12, 2018
  15. Mar 12, 2018
  16. Feb 06, 2018
  17. Jan 16, 2018
    • Eric Blake's avatar
      maint: Fix macros with broken 'do/while(0); ' usage · 2562755e
      Eric Blake authored
      
      The point of writing a macro embedded in a 'do { ... } while (0)'
      loop (particularly if the macro has multiple statements or would
      otherwise end with an 'if' statement) is so that the macro can be
      used as a drop-in statement with the caller supplying the
      trailing ';'.  Although our coding style frowns on brace-less 'if':
        if (cond)
          statement;
        else
          something else;
      that is the classic case where failure to use do/while(0) wrapping
      would cause the 'else' to pair with any embedded 'if' in the macro
      rather than the intended outer 'if'.  But conversely, if the macro
      includes an embedded ';', then the same brace-less coding style
      would now have two statements, making the 'else' a syntax error
      rather than pairing with the outer 'if'.  Thus, even though our
      coding style with required braces is not impacted, ending a macro
      with ';' makes our code harder to port to projects that use
      brace-less styles.
      
      The change should have no semantic impact.  I was not able to
      fully compile-test all of the changes (as some of them are
      examples of the ugly bit-rotting debug print statements that are
      completely elided by default, and I didn't want to recompile
      with the necessary -D witnesses - cleaning those up is left as a
      bite-sized task for another day); I did, however, audit that for
      all files touched, all callers of the changed macros DID supply
      a trailing ';' at the callsite, and did not appear to be used
      as part of a brace-less conditional.
      
      Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Acked-by: default avatarCornelia Huck <cohuck@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Acked-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-Id: <20171201232433.25193-7-eblake@redhat.com>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      2562755e
Loading