diff mbox series

[06/10] hw/audio/virtio-sound: introduce virtio_snd_pcm_open()

Message ID 20240104203422.12308-6-vr_qemu@t-online.de
State New
Headers show
Series virtio-sound migration part 1 | expand

Commit Message

Volker Rümelin Jan. 4, 2024, 8:34 p.m. UTC
Split out the function virtio_snd_pcm_open() from
virtio_snd_pcm_prepare(). A later patch also needs
the new function. There is no functional change.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 hw/audio/virtio-snd.c | 57 +++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

Comments

Marc-André Lureau Jan. 5, 2024, 11:39 a.m. UTC | #1
On Fri, Jan 5, 2024 at 12:34 AM Volker Rümelin <vr_qemu@t-online.de> wrote:
>
> Split out the function virtio_snd_pcm_open() from
> virtio_snd_pcm_prepare(). A later patch also needs
> the new function. There is no functional change.
>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  hw/audio/virtio-snd.c | 57 +++++++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 26 deletions(-)
>
> diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
> index 9f3269d72b..a1d2b3367e 100644
> --- a/hw/audio/virtio-snd.c
> +++ b/hw/audio/virtio-snd.c
> @@ -443,6 +443,36 @@ static void virtio_snd_get_qemu_audsettings(audsettings *as,
>      as->endianness = target_words_bigendian() ? 1 : 0;
>  }
>
> +/*
> + * Open a stream.
> + *
> + * @stream: VirtIOSoundPCMStream *stream
> + */
> +static void virtio_snd_pcm_open(VirtIOSoundPCMStream *stream)
> +{
> +    virtio_snd_get_qemu_audsettings(&stream->as, &stream->params);
> +    stream->positions[0] = VIRTIO_SND_CHMAP_FL;
> +    stream->positions[1] = VIRTIO_SND_CHMAP_FR;
> +
> +    if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
> +        stream->voice.out = AUD_open_out(&stream->s->card,
> +                                         stream->voice.out,
> +                                         "virtio-sound.out",
> +                                         stream,
> +                                         virtio_snd_pcm_out_cb,
> +                                         &stream->as);
> +        AUD_set_volume_out(stream->voice.out, 0, 255, 255);
> +    } else {
> +        stream->voice.in = AUD_open_in(&stream->s->card,
> +                                       stream->voice.in,
> +                                       "virtio-sound.in",
> +                                       stream,
> +                                       virtio_snd_pcm_in_cb,
> +                                       &stream->as);
> +        AUD_set_volume_in(stream->voice.in, 0, 255, 255);
> +    }
> +}
> +
>  /*
>   * Close a stream and free all its resources.
>   *
> @@ -468,8 +498,6 @@ static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream)
>   */
>  static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
>  {
> -    audsettings as;
> -    virtio_snd_pcm_set_params *params;
>      VirtIOSoundPCMStream *stream;
>
>      stream = virtio_snd_pcm_get_stream(s, stream_id);
> @@ -491,30 +519,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
>          QSIMPLEQ_INIT(&stream->invalid);
>      }
>
> -    params = virtio_snd_pcm_get_params(s, stream_id);
> -
> -    virtio_snd_get_qemu_audsettings(&as, params);
> -    stream->positions[0] = VIRTIO_SND_CHMAP_FL;
> -    stream->positions[1] = VIRTIO_SND_CHMAP_FR;
> -    stream->as = as;
> -
> -    if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
> -        stream->voice.out = AUD_open_out(&s->card,
> -                                         stream->voice.out,
> -                                         "virtio-sound.out",
> -                                         stream,
> -                                         virtio_snd_pcm_out_cb,
> -                                         &as);
> -        AUD_set_volume_out(stream->voice.out, 0, 255, 255);
> -    } else {
> -        stream->voice.in = AUD_open_in(&s->card,
> -                                        stream->voice.in,
> -                                        "virtio-sound.in",
> -                                        stream,
> -                                        virtio_snd_pcm_in_cb,
> -                                        &as);
> -        AUD_set_volume_in(stream->voice.in, 0, 255, 255);
> -    }
> +    virtio_snd_pcm_open(stream);
>
>      stream->state = VSND_PCMSTREAM_STATE_PREPARED;
>
> --
> 2.35.3
>
diff mbox series

Patch

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 9f3269d72b..a1d2b3367e 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -443,6 +443,36 @@  static void virtio_snd_get_qemu_audsettings(audsettings *as,
     as->endianness = target_words_bigendian() ? 1 : 0;
 }
 
+/*
+ * Open a stream.
+ *
+ * @stream: VirtIOSoundPCMStream *stream
+ */
+static void virtio_snd_pcm_open(VirtIOSoundPCMStream *stream)
+{
+    virtio_snd_get_qemu_audsettings(&stream->as, &stream->params);
+    stream->positions[0] = VIRTIO_SND_CHMAP_FL;
+    stream->positions[1] = VIRTIO_SND_CHMAP_FR;
+
+    if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
+        stream->voice.out = AUD_open_out(&stream->s->card,
+                                         stream->voice.out,
+                                         "virtio-sound.out",
+                                         stream,
+                                         virtio_snd_pcm_out_cb,
+                                         &stream->as);
+        AUD_set_volume_out(stream->voice.out, 0, 255, 255);
+    } else {
+        stream->voice.in = AUD_open_in(&stream->s->card,
+                                       stream->voice.in,
+                                       "virtio-sound.in",
+                                       stream,
+                                       virtio_snd_pcm_in_cb,
+                                       &stream->as);
+        AUD_set_volume_in(stream->voice.in, 0, 255, 255);
+    }
+}
+
 /*
  * Close a stream and free all its resources.
  *
@@ -468,8 +498,6 @@  static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream)
  */
 static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
 {
-    audsettings as;
-    virtio_snd_pcm_set_params *params;
     VirtIOSoundPCMStream *stream;
 
     stream = virtio_snd_pcm_get_stream(s, stream_id);
@@ -491,30 +519,7 @@  static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
         QSIMPLEQ_INIT(&stream->invalid);
     }
 
-    params = virtio_snd_pcm_get_params(s, stream_id);
-
-    virtio_snd_get_qemu_audsettings(&as, params);
-    stream->positions[0] = VIRTIO_SND_CHMAP_FL;
-    stream->positions[1] = VIRTIO_SND_CHMAP_FR;
-    stream->as = as;
-
-    if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
-        stream->voice.out = AUD_open_out(&s->card,
-                                         stream->voice.out,
-                                         "virtio-sound.out",
-                                         stream,
-                                         virtio_snd_pcm_out_cb,
-                                         &as);
-        AUD_set_volume_out(stream->voice.out, 0, 255, 255);
-    } else {
-        stream->voice.in = AUD_open_in(&s->card,
-                                        stream->voice.in,
-                                        "virtio-sound.in",
-                                        stream,
-                                        virtio_snd_pcm_in_cb,
-                                        &as);
-        AUD_set_volume_in(stream->voice.in, 0, 255, 255);
-    }
+    virtio_snd_pcm_open(stream);
 
     stream->state = VSND_PCMSTREAM_STATE_PREPARED;