Просмотр исходного кода

spiceaudio: add a pcm_ops buffer_get_free function

It seems there is a demand [1] for low latency playback over
SPICE. Add a pcm_ops buffer_get_free function to reduce the
playback latency. The mixing engine buffer becomes a temporary
buffer.

[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg01644.html

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220923183640.8314-6-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Volker Rümelin 2 лет назад
Родитель
Сommit
90320051ea
1 измененных файлов с 10 добавлено и 2 удалено
  1. 10 2
      audio/spiceaudio.c

+ 10 - 2
audio/spiceaudio.c

@@ -120,6 +120,13 @@ static void line_out_fini (HWVoiceOut *hw)
     spice_server_remove_interface (&out->sin.base);
     spice_server_remove_interface (&out->sin.base);
 }
 }
 
 
+static size_t line_out_get_free(HWVoiceOut *hw)
+{
+    SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw);
+
+    return audio_rate_peek_bytes(&out->rate, &hw->info);
+}
+
 static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size)
 static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size)
 {
 {
     SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw);
     SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw);
@@ -133,8 +140,6 @@ static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size)
         *size = MIN((out->fsize - out->fpos) << 2, *size);
         *size = MIN((out->fsize - out->fpos) << 2, *size);
     }
     }
 
 
-    *size = audio_rate_get_bytes(&hw->info, &out->rate, *size);
-
     return out->frame + out->fpos;
     return out->frame + out->fpos;
 }
 }
 
 
@@ -142,6 +147,8 @@ static size_t line_out_put_buffer(HWVoiceOut *hw, void *buf, size_t size)
 {
 {
     SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw);
     SpiceVoiceOut *out = container_of(hw, SpiceVoiceOut, hw);
 
 
+    audio_rate_add_bytes(&out->rate, size);
+
     if (buf) {
     if (buf) {
         assert(buf == out->frame + out->fpos && out->fpos <= out->fsize);
         assert(buf == out->frame + out->fpos && out->fpos <= out->fsize);
         out->fpos += size >> 2;
         out->fpos += size >> 2;
@@ -282,6 +289,7 @@ static struct audio_pcm_ops audio_callbacks = {
     .init_out = line_out_init,
     .init_out = line_out_init,
     .fini_out = line_out_fini,
     .fini_out = line_out_fini,
     .write    = audio_generic_write,
     .write    = audio_generic_write,
+    .buffer_get_free = line_out_get_free,
     .get_buffer_out = line_out_get_buffer,
     .get_buffer_out = line_out_get_buffer,
     .put_buffer_out = line_out_put_buffer,
     .put_buffer_out = line_out_put_buffer,
     .enable_out = line_out_enable,
     .enable_out = line_out_enable,