|
Hans de Goede |
56753f |
From 4b09edbfdaad4536617bbb53ccadfe531156ed56 Mon Sep 17 00:00:00 2001
|
|
Hans de Goede |
56753f |
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@gmail.com>
|
|
Hans de Goede |
56753f |
Date: Tue, 17 Apr 2012 14:32:43 +0200
|
|
Hans de Goede |
56753f |
Subject: [PATCH 509/509] Allow controlling volume with PulseAudio backend
|
|
Hans de Goede |
56753f |
|
|
Hans de Goede |
56753f |
Signed-off-by: Marc-Andr? Lureau <marcandre.lureau@redhat.com>
|
|
Hans de Goede |
56753f |
Signed-off-by: malc <av1474@comtv.ru>
|
|
Hans de Goede |
56753f |
---
|
|
Hans de Goede |
56753f |
audio/paaudio.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
Hans de Goede |
56753f |
1 file changed, 94 insertions(+), 5 deletions(-)
|
|
Hans de Goede |
56753f |
|
|
Hans de Goede |
56753f |
diff --git a/audio/paaudio.c b/audio/paaudio.c
|
|
Hans de Goede |
56753f |
index 6f50c1c..e6708d0 100644
|
|
Hans de Goede |
56753f |
--- a/audio/paaudio.c
|
|
Hans de Goede |
56753f |
+++ b/audio/paaudio.c
|
|
Hans de Goede |
56753f |
@@ -677,15 +677,103 @@ static void qpa_fini_in (HWVoiceIn *hw)
|
|
Hans de Goede |
56753f |
|
|
Hans de Goede |
56753f |
static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
Hans de Goede |
56753f |
{
|
|
Hans de Goede |
56753f |
- (void) hw;
|
|
Hans de Goede |
56753f |
- (void) cmd;
|
|
Hans de Goede |
56753f |
+ PAVoiceOut *pa = (PAVoiceOut *) hw;
|
|
Hans de Goede |
56753f |
+ pa_operation *op;
|
|
Hans de Goede |
56753f |
+ pa_cvolume v;
|
|
Hans de Goede |
56753f |
+ paaudio *g = &glob_paaudio;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_cvolume_init (&v);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ switch (cmd) {
|
|
Hans de Goede |
56753f |
+ case VOICE_VOLUME:
|
|
Hans de Goede |
56753f |
+ {
|
|
Hans de Goede |
56753f |
+ SWVoiceOut *sw;
|
|
Hans de Goede |
56753f |
+ va_list ap;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ va_start (ap, cmd);
|
|
Hans de Goede |
56753f |
+ sw = va_arg (ap, SWVoiceOut *);
|
|
Hans de Goede |
56753f |
+ va_end (ap);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ v.channels = 2;
|
|
Hans de Goede |
56753f |
+ v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
|
|
Hans de Goede |
56753f |
+ v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_threaded_mainloop_lock (g->mainloop);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ op = pa_context_set_sink_input_volume (g->context,
|
|
Hans de Goede |
56753f |
+ pa_stream_get_index (pa->stream),
|
|
Hans de Goede |
56753f |
+ &v, NULL, NULL);
|
|
Hans de Goede |
56753f |
+ if (!op)
|
|
Hans de Goede |
56753f |
+ qpa_logerr (pa_context_errno (g->context),
|
|
Hans de Goede |
56753f |
+ "set_sink_input_volume() failed\n");
|
|
Hans de Goede |
56753f |
+ else
|
|
Hans de Goede |
56753f |
+ pa_operation_unref (op);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ op = pa_context_set_sink_input_mute (g->context,
|
|
Hans de Goede |
56753f |
+ pa_stream_get_index (pa->stream),
|
|
Hans de Goede |
56753f |
+ sw->vol.mute, NULL, NULL);
|
|
Hans de Goede |
56753f |
+ if (!op) {
|
|
Hans de Goede |
56753f |
+ qpa_logerr (pa_context_errno (g->context),
|
|
Hans de Goede |
56753f |
+ "set_sink_input_mute() failed\n");
|
|
Hans de Goede |
56753f |
+ } else {
|
|
Hans de Goede |
56753f |
+ pa_operation_unref (op);
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_threaded_mainloop_unlock (g->mainloop);
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
return 0;
|
|
Hans de Goede |
56753f |
}
|
|
Hans de Goede |
56753f |
|
|
Hans de Goede |
56753f |
static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
Hans de Goede |
56753f |
{
|
|
Hans de Goede |
56753f |
- (void) hw;
|
|
Hans de Goede |
56753f |
- (void) cmd;
|
|
Hans de Goede |
56753f |
+ PAVoiceIn *pa = (PAVoiceIn *) hw;
|
|
Hans de Goede |
56753f |
+ pa_operation *op;
|
|
Hans de Goede |
56753f |
+ pa_cvolume v;
|
|
Hans de Goede |
56753f |
+ paaudio *g = &glob_paaudio;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_cvolume_init (&v);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ switch (cmd) {
|
|
Hans de Goede |
56753f |
+ case VOICE_VOLUME:
|
|
Hans de Goede |
56753f |
+ {
|
|
Hans de Goede |
56753f |
+ SWVoiceIn *sw;
|
|
Hans de Goede |
56753f |
+ va_list ap;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ va_start (ap, cmd);
|
|
Hans de Goede |
56753f |
+ sw = va_arg (ap, SWVoiceIn *);
|
|
Hans de Goede |
56753f |
+ va_end (ap);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ v.channels = 2;
|
|
Hans de Goede |
56753f |
+ v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
|
|
Hans de Goede |
56753f |
+ v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_threaded_mainloop_lock (g->mainloop);
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ /* FIXME: use the upcoming "set_source_output_{volume,mute}" */
|
|
Hans de Goede |
56753f |
+ op = pa_context_set_source_volume_by_index (g->context,
|
|
Hans de Goede |
56753f |
+ pa_stream_get_device_index (pa->stream),
|
|
Hans de Goede |
56753f |
+ &v, NULL, NULL);
|
|
Hans de Goede |
56753f |
+ if (!op) {
|
|
Hans de Goede |
56753f |
+ qpa_logerr (pa_context_errno (g->context),
|
|
Hans de Goede |
56753f |
+ "set_source_volume() failed\n");
|
|
Hans de Goede |
56753f |
+ } else {
|
|
Hans de Goede |
56753f |
+ pa_operation_unref(op);
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ op = pa_context_set_source_mute_by_index (g->context,
|
|
Hans de Goede |
56753f |
+ pa_stream_get_index (pa->stream),
|
|
Hans de Goede |
56753f |
+ sw->vol.mute, NULL, NULL);
|
|
Hans de Goede |
56753f |
+ if (!op) {
|
|
Hans de Goede |
56753f |
+ qpa_logerr (pa_context_errno (g->context),
|
|
Hans de Goede |
56753f |
+ "set_source_mute() failed\n");
|
|
Hans de Goede |
56753f |
+ } else {
|
|
Hans de Goede |
56753f |
+ pa_operation_unref (op);
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
+
|
|
Hans de Goede |
56753f |
+ pa_threaded_mainloop_unlock (g->mainloop);
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
+ }
|
|
Hans de Goede |
56753f |
return 0;
|
|
Hans de Goede |
56753f |
}
|
|
Hans de Goede |
56753f |
|
|
Hans de Goede |
56753f |
@@ -822,5 +910,6 @@ struct audio_driver pa_audio_driver = {
|
|
Hans de Goede |
56753f |
.max_voices_out = INT_MAX,
|
|
Hans de Goede |
56753f |
.max_voices_in = INT_MAX,
|
|
Hans de Goede |
56753f |
.voice_size_out = sizeof (PAVoiceOut),
|
|
Hans de Goede |
56753f |
- .voice_size_in = sizeof (PAVoiceIn)
|
|
Hans de Goede |
56753f |
+ .voice_size_in = sizeof (PAVoiceIn),
|
|
Hans de Goede |
56753f |
+ .ctl_caps = VOICE_VOLUME_CAP
|
|
Hans de Goede |
56753f |
};
|
|
Hans de Goede |
56753f |
--
|
|
Hans de Goede |
56753f |
1.7.10
|
|
Hans de Goede |
56753f |
|