All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 10/11] audio: allow controlling volume with PulseAudio backend
Date: Thu, 13 Oct 2011 14:26:23 +0200	[thread overview]
Message-ID: <1318508784-8172-10-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1318508784-8172-1-git-send-email-marcandre.lureau@redhat.com>

---
 audio/paaudio.c |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/audio/paaudio.c b/audio/paaudio.c
index beed434..7ddc16d 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -664,15 +664,100 @@ static void qpa_fini_in (HWVoiceIn *hw)
 
 static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
 {
-    (void) hw;
-    (void) cmd;
+    PAVoiceOut *pa = (PAVoiceOut *) hw;
+    pa_operation *op;
+    pa_cvolume v;
+    paaudio *g = &glob_paaudio;
+
+    pa_cvolume_init (&v);
+
+    switch (cmd) {
+    case VOICE_VOLUME:
+        {
+            SWVoiceOut *sw;
+            va_list ap;
+
+            va_start (ap, cmd);
+            sw = va_arg (ap, SWVoiceOut *);
+            va_end (ap);
+
+            v.channels = 2;
+            v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
+            v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
+
+            pa_threaded_mainloop_lock (g->mainloop);
+
+            op = pa_context_set_sink_input_volume (g->context,
+                pa_stream_get_index (pa->stream),
+                &v, NULL, NULL);
+            if (!op)
+                qpa_logerr (pa_context_errno (g->context),
+                            "set_sink_input_volume() failed\n");
+            else
+                pa_operation_unref (op);
+
+            op = pa_context_set_sink_input_mute (g->context,
+                pa_stream_get_index (pa->stream),
+               sw->vol.mute, NULL, NULL);
+            if (!op)
+                qpa_logerr (pa_context_errno (g->context),
+                            "set_sink_input_mute() failed\n");
+            else
+                pa_operation_unref (op);
+
+            pa_threaded_mainloop_unlock (g->mainloop);
+        }
+    }
     return 0;
 }
 
 static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
 {
-    (void) hw;
-    (void) cmd;
+    PAVoiceIn *pa = (PAVoiceIn *) hw;
+    pa_operation *op;
+    pa_cvolume v;
+    paaudio *g = &glob_paaudio;
+
+    pa_cvolume_init (&v);
+
+    switch (cmd) {
+    case VOICE_VOLUME:
+        {
+            SWVoiceIn *sw;
+            va_list ap;
+
+            va_start (ap, cmd);
+            sw = va_arg (ap, SWVoiceIn *);
+            va_end (ap);
+
+            v.channels = 2;
+            v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
+            v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
+
+            pa_threaded_mainloop_lock (g->mainloop);
+
+            /* FIXME: use the upcoming "set_source_output_{volume,mute}" */
+            op = pa_context_set_source_volume_by_index (g->context,
+                pa_stream_get_device_index (pa->stream),
+                &v, NULL, NULL);
+            if (!op)
+                qpa_logerr (pa_context_errno (g->context),
+                            "set_source_volume() failed\n");
+            else
+                pa_operation_unref(op);
+
+            op = pa_context_set_source_mute_by_index (g->context,
+                pa_stream_get_index (pa->stream),
+                sw->vol.mute, NULL, NULL);
+            if (!op)
+                qpa_logerr (pa_context_errno (g->context),
+                            "set_source_mute() failed\n");
+            else
+                pa_operation_unref (op);
+
+            pa_threaded_mainloop_unlock (g->mainloop);
+        }
+    }
     return 0;
 }
 
@@ -801,5 +886,6 @@ struct audio_driver pa_audio_driver = {
     .max_voices_out = INT_MAX,
     .max_voices_in  = INT_MAX,
     .voice_size_out = sizeof (PAVoiceOut),
-    .voice_size_in  = sizeof (PAVoiceIn)
+    .voice_size_in  = sizeof (PAVoiceIn),
+    .ctl_caps       = VOICE_VOLUME_CAP
 };
-- 
1.7.6.2

  parent reply	other threads:[~2011-10-13 12:27 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-21 16:10 [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream Marc-André Lureau
2011-09-21 16:10 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
2011-09-21 16:10 ` [Qemu-devel] [PATCH 02/11] audio: don't apply volume effect if backend has VOICE_VOLUME_CAP Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 03/11] audio: use a nominal volume of 1^32-1 Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 04/11] hw/ac97: remove USE_MIXER code Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 05/11] hw/ac97: the volume mask was not always 0x1f Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 07/11] audio/spice: add " Marc-André Lureau
2011-10-11  8:49   ` Gerd Hoffmann
2011-10-13 12:06     ` Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 08/11] RFC: use full PulseAudio API, largely adapted from pa_simple* Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 09/11] RFC: configure: pa_simple is not needed anymore Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 10/11] RFC: allow controlling volume with PulseAudio backend Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 11/11] RFC: make mixemu mandatory Marc-André Lureau
2011-10-11  8:54 ` [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream Gerd Hoffmann
2011-10-13 12:26 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 02/11] audio: don't apply volume effect if backend has VOICE_VOLUME_CAP Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 03/11] audio: use a nominal volume of 1^32-1 Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 04/11] hw/ac97: remove USE_MIXER code Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 05/11] hw/ac97: the volume mask was not always 0x1f Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 07/11] audio/spice: add " Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 08/11] audio: use full PulseAudio API, largely adapted from pa_simple* Marc-André Lureau
2011-10-13 12:26   ` [Qemu-devel] [PATCH 09/11] configure: pa_simple is not needed anymore Marc-André Lureau
2011-10-13 12:26   ` Marc-André Lureau [this message]
2011-10-13 12:26   ` [Qemu-devel] [PATCH 11/11] audio: make mixemu mandatory Marc-André Lureau
2012-03-01 14:27 ` [Qemu-devel] [PATCH 00/11] apply volume on client side Marc-André Lureau
2012-03-01 14:27 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
2012-03-01 14:27 ` [Qemu-devel] [PATCH 02/11] audio: don't apply volume effect if backend has VOICE_VOLUME_CAP Marc-André Lureau
2012-03-01 14:27 ` [Qemu-devel] [PATCH 03/11] audio: use a nominal volume of 1^32-1 Marc-André Lureau
2012-03-01 15:16   ` Eric Blake
2012-03-01 14:28 ` [Qemu-devel] [PATCH 04/11] hw/ac97: remove USE_MIXER code Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 05/11] hw/ac97: the volume mask was not always 0x1f Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 07/11] audio/spice: add " Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 08/11] Do not use pa_simple PulseAudio API Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 09/11] configure: pa_simple is not needed anymore Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 10/11] Allow controlling volume with PulseAudio backend Marc-André Lureau
2012-03-01 14:28 ` [Qemu-devel] [PATCH 11/11] Make mixemu mandatory Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1318508784-8172-10-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.