Skip to contentSkip to conversation

audio: -audiodev option, multiple options

PATCH In review Kővágó, Zoltán 5 participants 68 messages Aug 21, 2015 – Sep 7, 2015 Page 2 of 2

Subsystems (5)
lore
Share & tools
lore
#61 lore raw

PATCH v2 49/49 audio: split ctl_* functions into enable_* and volume_*

In reply to Kővágó, Zoltán

This way we no longer need vararg functions, improving compile time error detection. Also now it's possible to check actually what commands are supported, without needing to manually update ctl_caps.

---
 audio/alsaaudio.c      |  56 +++++++++-------------
 audio/audio.c          |  45 ++++++++++-------
 audio/audio_int.h      |  15 ++----
 audio/audio_template.h |   1 -
 audio/coreaudio.c      |  13 ++---
 audio/dsoundaudio.c    |  50 ++++++++-----------
 audio/noaudio.c        |  14 +++---
 audio/ossaudio.c       |  78 ++++++++++++------------------
 audio/paaudio.c        | 128 ++++++++++++++++++++-----------------------------
 audio/sdlaudio.c       |  17 ++-----
 audio/spiceaudio.c     | 101 ++++++++++++++++----------------------
 audio/wavaudio.c       |   7 ++-
 12 files changed, 214 insertions(+), 311 deletions(-)
audio/alsaaudio.c +22 -34
index adb3b40..44f28f4 100644
@@ -746,34 +746,28 @@ static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int ctl)
     return 0;
 }
 
-static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
+static void alsa_enable_out(HWVoiceOut *hw, bool enable)
 {
     ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
     AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->alsa->alsa_out;
 
-    switch (cmd) {
-    case VOICE_ENABLE:
-        {
-            bool poll_mode = !apdo->has_try_poll || apdo->try_poll;
+    if (enable) {
+        bool poll_mode = !apdo->has_try_poll || apdo->try_poll;
 
-            ldebug ("enabling voice\n");
-            if (poll_mode && alsa_poll_out (hw)) {
-                poll_mode = 0;
-            }
-            hw->poll_mode = poll_mode;
-            return alsa_voice_ctl (alsa->handle, "playback", VOICE_CTL_PREPARE);
+        ldebug ("enabling voice\n");
+        if (poll_mode && alsa_poll_out (hw)) {
+            poll_mode = 0;
         }
-
-    case VOICE_DISABLE:
+        hw->poll_mode = poll_mode;
+        alsa_voice_ctl(alsa->handle, "playback", VOICE_CTL_PREPARE);
+    } else {
         ldebug ("disabling voice\n");
         if (hw->poll_mode) {
             hw->poll_mode = 0;
             alsa_fini_poll (&alsa->pollhlp);
         }
-        return alsa_voice_ctl (alsa->handle, "playback", VOICE_CTL_PAUSE);
+        alsa_voice_ctl(alsa->handle, "playback", VOICE_CTL_PAUSE);
     }
-
-    return -1;
 }
 
 static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
@@ -862,35 +856,29 @@ static size_t alsa_read(HWVoiceIn *hw, void *buf, size_t len)
     return pos;
 }
 
-static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
+static void alsa_enable_in(HWVoiceIn *hw, bool enable)
 {
     ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
     AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->alsa->alsa_in;
 
-    switch (cmd) {
-    case VOICE_ENABLE:
-        {
-            bool poll_mode = !apdo->has_try_poll || apdo->try_poll;
+    if (enable) {
+        bool poll_mode = !apdo->has_try_poll || apdo->try_poll;
 
-            ldebug ("enabling voice\n");
-            if (poll_mode && alsa_poll_in (hw)) {
-                poll_mode = 0;
-            }
-            hw->poll_mode = poll_mode;
-
-            return alsa_voice_ctl (alsa->handle, "capture", VOICE_CTL_START);
+        ldebug ("enabling voice\n");
+        if (poll_mode && alsa_poll_in (hw)) {
+            poll_mode = 0;
         }
+        hw->poll_mode = poll_mode;
 
-    case VOICE_DISABLE:
+        alsa_voice_ctl(alsa->handle, "capture", VOICE_CTL_START);
+    } else {
         ldebug ("disabling voice\n");
         if (hw->poll_mode) {
             hw->poll_mode = 0;
             alsa_fini_poll (&alsa->pollhlp);
         }
-        return alsa_voice_ctl (alsa->handle, "capture", VOICE_CTL_PAUSE);
+        alsa_voice_ctl(alsa->handle, "capture", VOICE_CTL_PAUSE);
     }
-
-    return -1;
 }
 
 static void *alsa_audio_init(Audiodev *dev)
@@ -928,13 +916,13 @@ static struct audio_pcm_ops alsa_pcm_ops = {
     .fini_out = alsa_fini_out,
     .buffer_size_out = alsa_buffer_size_out,
     .write    = alsa_write,
-    .ctl_out  = alsa_ctl_out,
+    .enable_out = alsa_enable_out,
 
     .init_in  = alsa_init_in,
     .fini_in  = alsa_fini_in,
     .buffer_size_in = alsa_buffer_size_in,
     .read     = alsa_read,
-    .ctl_in   = alsa_ctl_in,
+    .enable_in = alsa_enable_in,
 };
 
 struct audio_driver alsa_audio_driver = {
audio/audio.c +28 -17

117 lines not on this page · raw message

audio/audio_int.h +4 -11
index 16ffa12..6f2f309 100644
@@ -71,7 +71,6 @@ typedef struct HWVoiceOut {
 
     QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
     QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
-    int ctl_caps;
     struct audio_pcm_ops *pcm_ops;
     QLIST_ENTRY (HWVoiceOut) entries;
 } HWVoiceOut;
@@ -92,7 +91,6 @@ typedef struct HWVoiceIn {
     size_t pos_emul, pending_emul, size_emul;
 
     QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
-    int ctl_caps;
     struct audio_pcm_ops *pcm_ops;
     QLIST_ENTRY (HWVoiceIn) entries;
 } HWVoiceIn;
@@ -143,7 +141,6 @@ struct audio_driver {
     int max_voices_in;
     int voice_size_out;
     int voice_size_in;
-    int ctl_caps;
 };
 
 struct audio_pcm_ops {
@@ -160,7 +157,8 @@ struct audio_pcm_ops {
      * buf must be equal the pointer returned by get_buffer_out,
      * size may be smaller */
     size_t (*put_buffer_out)(HWVoiceOut *hw, void *buf, size_t size);
-    int    (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
+    void   (*enable_out)(HWVoiceOut *hw, bool enable);
+    void   (*volume_out)(HWVoiceOut *hw, struct mixeng_volume *vol);
 
     int    (*init_in) (HWVoiceIn *hw, audsettings *as, void *drv_opaque);
     void   (*fini_in) (HWVoiceIn *hw);
@@ -168,7 +166,8 @@ struct audio_pcm_ops {
     size_t (*buffer_size_in)(HWVoiceIn *hw);
     void  *(*get_buffer_in)(HWVoiceIn *hw, size_t *size);
     void   (*put_buffer_in)(HWVoiceIn *hw, void *buf, size_t size);
-    int    (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
+    void   (*enable_in)(HWVoiceIn *hw, bool enable);
+    void   (*volume_in)(HWVoiceIn *hw, struct mixeng_volume *vol);
 };
 
 void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
@@ -247,12 +246,6 @@ void audio_rate_start(RateCtl *rate);
 size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
                             size_t bytes_avail);
 
-#define VOICE_ENABLE 1
-#define VOICE_DISABLE 2
-#define VOICE_VOLUME 3
-
-#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
-
 static inline size_t audio_ring_dist(size_t dst, size_t src, size_t len)
 {
     return (dst >= src) ? (dst - src) : (len - src + dst);
audio/audio_template.h +0 -1
index 473eac9..762efea 100644
@@ -256,7 +256,6 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
 
     hw->s = s;
     hw->pcm_ops = drv->pcm_ops;
-    hw->ctl_caps = drv->ctl_caps;
 
     QLIST_INIT (&hw->sw_head);
 #ifdef DAC
audio/coreaudio.c +4 -9
index 3262e96..7fdf469 100644
@@ -473,13 +473,12 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
     }
 }
 
-static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
+static void coreaudio_enable_out (HWVoiceOut *hw, bool enable)
 {
     OSStatus status;
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 
-    switch (cmd) {
-    case VOICE_ENABLE:
+    if (enable) {
         /* start playback */
         if (!isPlaying(core->outputDeviceID)) {
             status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
@@ -487,9 +486,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
                 coreaudio_logerr (status, "Could not resume playback\n");
             }
         }
-        break;
-
-    case VOICE_DISABLE:
+    } else {
         /* stop playback */
         if (!isAtexit) {
             if (isPlaying(core->outputDeviceID)) {
@@ -499,9 +496,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
                 }
             }
         }
-        break;
     }
-    return 0;
 }
 
 static void *coreaudio_audio_init(Audiodev *dev)
@@ -521,7 +516,7 @@ static struct audio_pcm_ops coreaudio_pcm_ops = {
     .buffer_size_out = coreaudio_buffer_size_out,
     .get_buffer_out = coreaudio_get_buffer_out,
     .put_buffer_out = coreaudio_put_buffer_out_nowrite,
-    .ctl_out  = coreaudio_ctl_out
+    .enable_out = coreaudio_enable_out
 };
 
 struct audio_driver coreaudio_audio_driver = {
audio/dsoundaudio.c +20 -30

140 lines not on this page · raw message

audio/noaudio.c +6 -8
index 3cb3a89..0618b60 100644
@@ -58,14 +58,13 @@ static void no_fini_out (HWVoiceOut *hw)
     (void) hw;
 }
 
-static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
+static void no_enable_out(HWVoiceOut *hw, bool enable)
 {
     NoVoiceOut *no = (NoVoiceOut *) hw;
 
-    if (cmd == VOICE_ENABLE) {
+    if (enable) {
         audio_rate_start(&no->rate);
     }
-    return 0;
 }
 
 static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
@@ -91,14 +90,13 @@ static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)
     return bytes;
 }
 
-static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
+static void no_enable_in(HWVoiceIn *hw, bool enable)
 {
     NoVoiceIn *no = (NoVoiceIn *) hw;
 
-    if (cmd == VOICE_ENABLE) {
+    if (enable) {
         audio_rate_start(&no->rate);
     }
-    return 0;
 }
 
 static void *no_audio_init (Audiodev *dev)
@@ -115,12 +113,12 @@ static struct audio_pcm_ops no_pcm_ops = {
     .init_out = no_init_out,
     .fini_out = no_fini_out,
     .write    = no_write,
-    .ctl_out  = no_ctl_out,
+    .enable_out = no_enable_out,
 
     .init_in  = no_init_in,
     .fini_in  = no_fini_in,
     .read     = no_read,
-    .ctl_in   = no_ctl_in
+    .enable_in = no_enable_in
 };
 
 struct audio_driver no_audio_driver = {
audio/ossaudio.c +31 -47

135 lines not on this page · raw message

audio/paaudio.c +51 -77

171 lines not on this page · raw message

audio/sdlaudio.c +3 -14
index 7b32332..83e38fe 100644
@@ -350,20 +350,9 @@ static size_t sdl_buffer_size_out(HWVoiceOut *hw)
     return sdl->samples;
 }
 
-static int sdl_ctl_out (HWVoiceOut *hw, int cmd, ...)
+static void sdl_enable_out(HWVoiceOut *hw, bool enable)
 {
-    (void) hw;
-
-    switch (cmd) {
-    case VOICE_ENABLE:
-        SDL_PauseAudio (0);
-        break;
-
-    case VOICE_DISABLE:
-        SDL_PauseAudio (1);
-        break;
-    }
-    return 0;
+    SDL_PauseAudio(!enable);
 }
 
 static void *sdl_audio_init(Audiodev *dev)
@@ -417,7 +406,7 @@ static struct audio_pcm_ops sdl_pcm_ops = {
     .buffer_size_out = sdl_buffer_size_out,
     .get_buffer_out = sdl_get_buffer_out,
     .put_buffer_out = sdl_put_buffer_out_nowrite,
-    .ctl_out  = sdl_ctl_out,
+    .enable_out = sdl_enable_out,
 };
 
 struct audio_driver sdl_audio_driver = {
audio/spiceaudio.c +42 -59

163 lines not on this page · raw message

audio/wavaudio.c +3 -4
index 14afaaf..5b35173 100644
@@ -169,14 +169,13 @@ static void wav_fini_out (HWVoiceOut *hw)
     wav->f = NULL;
 }
 
-static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)
+static void wav_enable_out(HWVoiceOut *hw, bool enable)
 {
     WAVVoiceOut *wav = (WAVVoiceOut *) hw;
 
-    if (cmd == VOICE_ENABLE) {
+    if (enable) {
         audio_rate_start(&wav->rate);
     }
-    return 0;
 }
 
 static void *wav_audio_init(Audiodev *dev)
@@ -194,7 +193,7 @@ static struct audio_pcm_ops wav_pcm_ops = {
     .init_out = wav_init_out,
     .fini_out = wav_fini_out,
     .write    = wav_write_out,
-    .ctl_out  = wav_ctl_out,
+    .enable_out = wav_enable_out,
 };
 
 struct audio_driver wav_audio_driver = {
Signature · 1 line
2.5.0
#62 lore raw
In reply to Kővágó, Zoltán
Quoted 12 lines · Zoltán

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Adding qapi & net folks to Cc. Ping.

How to go forward with the QAPI bits in this series (Patches 1-9)? Patch #1 got reviews from block folks. Patch #3 has a comment from Eduardo pending. What about the other ones? Fine as-is? I remember from the pre-2.4 freeze discussions that there at least was agreement that flattening the qapi structs is the way to go.

I'd prefer if the qapi maintainers can pick up and merge these patches. But I can also merge them via audio queue if I get reviews from the qapi maintainers.

thanks,
Gerd

#63 lore raw

2015-09-03 12:15 keltezéssel, Gerd Hoffmann írta:

Quoted 18 lines · Zoltán
Quoted 12 lines

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Quoted 7 lines

Adding qapi & net folks to Cc. Ping.

How to go forward with the QAPI bits in this series (Patches 1-9)? Patch #1 got reviews from block folks. Patch #3 has a comment from Eduardo pending. What about the other ones? Fine as-is? I remember from the pre-2.4 freeze discussions that there at least was agreement that flattening the qapi structs is the way to go.

Eduardo's comment was about s/NumaDriver/NumaOptionType/, and I didn't want to resend the whole series just to fix this small problem (as there will be other problems too, I think). IIRC Markus still had opposition with patch #9 (support nested structs in OptsVisitor).

Zoltan

#64 lore raw
In reply to Gerd Hoffmann
Quoted 18 lines · Gerd Hoffmann
Quoted 12 lines · Zoltán

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Quoted 7 lines

Adding qapi & net folks to Cc. Ping.

How to go forward with the QAPI bits in this series (Patches 1-9)? Patch #1 got reviews from block folks. Patch #3 has a comment from Eduardo pending. What about the other ones? Fine as-is? I remember from the pre-2.4 freeze discussions that there at least was agreement that flattening the qapi structs is the way to go.

Still on my list of patches to review (seems to be a rather large list, sadly). I should get to it before Monday.

Quoted 4 lines

I'd prefer if the qapi maintainers can pick up and merge these patches. But I can also merge them via audio queue if I get reviews from the qapi maintainers.

I'll leave it up to Markus on which tree is better for the qapi patches to go through.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#65 lore raw

2015-09-03 17:07 keltezéssel, Eric Blake írta:

Quoted 31 lines · Gerd Hoffmann
Quoted 18 lines · Zoltán
Quoted 12 lines

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Quoted 7 lines

Adding qapi & net folks to Cc. Ping.

How to go forward with the QAPI bits in this series (Patches 1-9)? Patch #1 got reviews from block folks. Patch #3 has a comment from Eduardo pending. What about the other ones? Fine as-is? I remember from the pre-2.4 freeze discussions that there at least was agreement that flattening the qapi structs is the way to go.

Still on my list of patches to review (seems to be a rather large list, sadly). I should get to it before Monday.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

I'd prefer if the qapi maintainers can pick up and merge these patches. But I can also merge them via audio queue if I get reviews from the qapi maintainers.

I'll leave it up to Markus on which tree is better for the qapi patches to go through.

Okay, I've rebased the patches to master and applied (some of) the changes suggested by Eric. Since it looks like there are still some problems with the qapi parts, it may be better if I split out the qapi patches into a separate series, and go back to the audio patches when the qapi bits are merged. Should I go ahead?

Zoltan

#66 lore raw
Quoted 40 lines · Kővágó Zoltán

2015-09-03 17:07 keltezéssel, Eric Blake írta:

Quoted 31 lines · Gerd Hoffmann
Quoted 18 lines · Zoltán
Quoted 12 lines

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Quoted 7 lines

Adding qapi & net folks to Cc. Ping.

How to go forward with the QAPI bits in this series (Patches 1-9)? Patch #1 got reviews from block folks. Patch #3 has a comment from Eduardo pending. What about the other ones? Fine as-is? I remember from the pre-2.4 freeze discussions that there at least was agreement that flattening the qapi structs is the way to go.

Still on my list of patches to review (seems to be a rather large list, sadly). I should get to it before Monday.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

I'd prefer if the qapi maintainers can pick up and merge these patches. But I can also merge them via audio queue if I get reviews from the qapi maintainers.

I'll leave it up to Markus on which tree is better for the qapi patches to go through.

Quoted 5 lines

Okay, I've rebased the patches to master and applied (some of) the changes suggested by Eric. Since it looks like there are still some problems with the qapi parts, it may be better if I split out the qapi patches into a separate series, and go back to the audio patches when the qapi bits are merged. Should I go ahead?

Given the size of this series, splitting it up into separately reviewable parts sounds like an excellent idea.

#67 lore raw
In reply to Kővágó, Zoltán
Quoted 12 lines · Zoltán

This patch series adds support to multiple audio backends. Afterwards I add support to multiple backends. Audio fronteds gain a new audiodev option to specify the id of the audiodev to use. The audiodev= option is required, unless you use the old environment variable based configuration, in that case it must not used (and you can't use multiple backends).

Finally I also make mixeng usage optional, it can save us some useless format converting when not needed. Also makes easier to support formats currently not supported by qemu (as only the backend has to support it, not the mixeng).

Quoted 4 lines

For easier testing pull https://github.com/DirtYiCE/qemu.git tag audio-multi-v2.

Please review.

Looks good overall to me, passed some simple testing. Want do more testing before merging, need to find some time for it. Also we need to get the qapi bits merged first.

There are some issues flagged by codestyle.pl. For a good part they are already in the existing code. Sometimes you fixed the existing problems, sometimes you didn't. A few new issues (long lines for example) are there too. But given how many issues in existing audio code we have I guess the easiest way to handle this is to fix it afterwards with indent.

cheers,
Gerd