From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7ALI-0000wu-DU for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:51:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7AKx-00004z-CT for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:51:35 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:63230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7AKx-0008JW-3F for qemu-devel@nongnu.org; Mon, 12 Mar 2012 14:51:15 -0400 Received: by mail-ey0-f173.google.com with SMTP id f11so1649617eaa.4 for ; Mon, 12 Mar 2012 11:51:14 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" Date: Mon, 12 Mar 2012 19:50:10 +0100 Message-Id: <1331578211-18232-11-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1331578211-18232-1-git-send-email-marcandre.lureau@redhat.com> References: <1331578211-18232-1-git-send-email-marcandre.lureau@redhat.com> Subject: [Qemu-devel] [PATCH 10/11] Allow controlling volume with PulseAudio backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , dnb@redhat.com, dlaor@redhat.com, kraxel@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.7.6