On 2025/01/26 3:25, Philippe Mathieu-Daudé wrote:
On 24/1/25 05:58, Akihiko Odaki wrote:
On 2025/01/23 17:43, Philippe Mathieu-Daudé wrote:
Hi Akihiko,

On 23/1/25 08:18, Akihiko Odaki wrote:
These functions can be used to re-initialize buffers when hardware
parameters change due to device hotplug, for example.

Signed-off-by: Akihiko Odaki <akihiko.od...@daynix.com>
Reviewed-by: Phil Dennis-Jordan <p...@philjordan.eu>
Reviewed-by: Christian Schoenebeck <qemu_...@crudebyte.com>
---
  audio/audio_int.h |  2 ++
  audio/audio.c     | 24 ++++++++++++++++++------
  2 files changed, 20 insertions(+), 6 deletions(-)


index 87b4e9b6f2f356b6e5e972eabc100cf270fcbc29..17c6bbd0ae9e6ff810c0989dbfa1710ef674ff0a 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1407,12 +1407,18 @@ void audio_run(AudioState *s, const char *msg)
  #endif
  }
+void audio_generic_initialize_buffer_in(HWVoiceIn *hw)
+{
+    g_free(hw->buf_emul);
+    hw->size_emul = hw->samples * hw->info.bytes_per_frame;
+    hw->buf_emul = g_malloc(hw->size_emul);

What about using g_realloc()? Otherwise LGTM.

g_realloc() will copy the content, which is not necessary here.

Oh I missed that! Maybe worth mentioning? Anyway, just nitpicking...

hw->size_emul = hw->samples * hw->info.bytes_per_frame;
g_free(hw->buf_emul); /* Discard previous content, no need to realloc */
hw->buf_emul = g_malloc(hw->size_emul);

I think we can just leave it as is. This function is named audio_generic_initialize_buffer_in() so it is not expected to keep the state.

Reply via email to