aboutsummaryrefslogtreecommitdiff
path: root/audio/audio.c
diff options
context:
space:
mode:
authorVolker RĂ¼melin <vr_qemu@t-online.de>2020-01-23 08:49:39 +0100
committerGerd Hoffmann <kraxel@redhat.com>2020-01-31 08:48:03 +0100
commitfdc8c5f4717f42f4b19b733ada30da2ba92a3ad1 (patch)
tree96e70e508afb0631a2f107f6e7a21a07eddc53e6 /audio/audio.c
parent69ac07863205ec281bcd2f2e6571202da0c315f7 (diff)
audio: fix bug 1858488
The combined generic buffer management code and buffer run out code in function audio_generic_put_buffer_out has a problematic behaviour. A few hundred milliseconds after playback starts the mixing buffer and the generic buffer are nearly full and the following pattern can be seen. On first call of audio_pcm_hw_run_out the buffer run code in audio_generic_put_buffer_out writes some data to the audio hardware but the generic buffer will fill faster and is full when audio_pcm_hw_run_out returns. This is because emulated audio devices can produce playback data at a higher rate than the audio backend hardware consumes this data. On next call of audio_pcm_hw_run_out the buffer run code in audio_generic_put_buffer_out writes some data to the audio hardware but no audio data is transferred to the generic buffer because the buffer is already full. Then the pattern repeats. For the emulated audio device this looks like the audio timer period has doubled. This patch splits the combined generic buffer management code and buffer run out code and calls the buffer run out code after buffer management code to break this pattern. The bug report is for the wav audio backend. But the problem is not limited to this backend. All audio backends which use the audio_generic_put_buffer_out function show this problem. Buglink: https://bugs.launchpad.net/qemu/+bug/1858488 Signed-off-by: Volker RĂ¼melin <vr_qemu@t-online.de> Message-Id: <20200123074943.6699-5-vr_qemu@t-online.de> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'audio/audio.c')
-rw-r--r--audio/audio.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/audio/audio.c b/audio/audio.c
index 12ed318813..b686429203 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1097,6 +1097,10 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut *hw, size_t live)
}
}
+ if (hw->pcm_ops->run_buffer_out) {
+ hw->pcm_ops->run_buffer_out(hw);
+ }
+
return clipped;
}
@@ -1413,6 +1417,28 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
hw->pending_emul -= size;
}
+void audio_generic_run_buffer_out(HWVoiceOut *hw)
+{
+ while (hw->pending_emul) {
+ size_t write_len, written;
+ ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
+
+ if (start < 0) {
+ start += hw->size_emul;
+ }
+ assert(start >= 0 && start < hw->size_emul);
+
+ write_len = MIN(hw->pending_emul, hw->size_emul - start);
+
+ written = hw->pcm_ops->write(hw, hw->buf_emul + start, write_len);
+ hw->pending_emul -= written;
+
+ if (written < write_len) {
+ break;
+ }
+ }
+}
+
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
{
if (unlikely(!hw->buf_emul)) {
@@ -1428,8 +1454,7 @@ void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
return hw->buf_emul + hw->pos_emul;
}
-size_t audio_generic_put_buffer_out_nowrite(HWVoiceOut *hw, void *buf,
- size_t size)
+size_t audio_generic_put_buffer_out(HWVoiceOut *hw, void *buf, size_t size)
{
assert(buf == hw->buf_emul + hw->pos_emul &&
size + hw->pending_emul <= hw->size_emul);
@@ -1440,35 +1465,6 @@ size_t audio_generic_put_buffer_out_nowrite(HWVoiceOut *hw, void *buf,
return size;
}
-size_t audio_generic_put_buffer_out(HWVoiceOut *hw, void *buf, size_t size)
-{
- audio_generic_put_buffer_out_nowrite(hw, buf, size);
-
- while (hw->pending_emul) {
- size_t write_len, written;
- ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
- if (start < 0) {
- start += hw->size_emul;
- }
- assert(start >= 0 && start < hw->size_emul);
-
- write_len = MIN(hw->pending_emul, hw->size_emul - start);
-
- written = hw->pcm_ops->write(hw, hw->buf_emul + start, write_len);
- hw->pending_emul -= written;
-
- if (written < write_len) {
- break;
- }
- }
-
- /*
- * fake we have written everything. non-written data remain in pending_emul,
- * so we do not have to clip them multiple times
- */
- return size;
-}
-
size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size)
{
size_t dst_size, copy_size;