From patchwork Tue Mar 13 15:20:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 146434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 35419B6EF1 for ; Wed, 14 Mar 2012 02:47:41 +1100 (EST) Received: from localhost ([::1]:42720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7TYz-0004M7-R6 for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2012 11:23:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7TXw-00023f-SY for qemu-devel@nongnu.org; Tue, 13 Mar 2012 11:22:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7TXq-0003Id-EO for qemu-devel@nongnu.org; Tue, 13 Mar 2012 11:21:56 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:37138) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7TXq-00038q-4r for qemu-devel@nongnu.org; Tue, 13 Mar 2012 11:21:50 -0400 Received: by mail-ey0-f173.google.com with SMTP id f11so352200eaa.4 for ; Tue, 13 Mar 2012 08:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=UeL/i2dkULcv643E8iQgmlX1H7zl3ZsZuHP+Crc8Ghw=; b=MrhxjAwEkp7f6YeuCBh7APOouM8OUlwBT4kzDMrWBqzHHRQKVl91ROJ4go7iymv7ry yITkM3kE0bgGLwj1e5WUXjBxsj9gZ0780uMgjKPJgBTCQZfUFXZ9h2kpEI29NAye3mUV s7OiNHOBpHDXNFwngWqi0ob4MtVBFeC9HSnnwRzmuyjoTW7lWxu+HmK371kfQvIV6J6n WRojreKxPiGhYGmSiyOU0kuSDkDMQGyuzkEVpMCnQB8ZCwSHEoepCO+wP8tlTWweVLjQ 7NIoIsaefbsbUrElbpDWoROf+8KRd+7Ly7Hq2aAy/VTeulszEpNOM026sC+fRiFKz44i HWYg== Received: by 10.213.34.16 with SMTP id j16mr1368020ebd.124.1331652108533; Tue, 13 Mar 2012 08:21:48 -0700 (PDT) Received: from localhost (254.pool85-58-48.dynamic.orange.es. [85.58.48.254]) by mx.google.com with ESMTPS id o49sm2952689eeb.7.2012.03.13.08.21.46 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Mar 2012 08:21:47 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2012 16:20:57 +0100 Message-Id: <1331652059-10090-10-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331652059-10090-1-git-send-email-marcandre.lureau@redhat.com> References: <1331652059-10090-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.173 Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , dnb@redhat.com, dlaor@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v4 09/11] Allow controlling volume with PulseAudio backend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Marc-André Lureau --- audio/paaudio.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 94 insertions(+), 5 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 6f50c1c..e6708d0 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -677,15 +677,103 @@ 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; } @@ -822,5 +910,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 };