diff libao2/ao_pulse.c @ 30018:ae5d67d8ee95

Get rid of global volume variable, it is only used for temporary values.
author reimar
date Fri, 18 Dec 2009 20:22:39 +0000
parents aa06c29db609
children 2d62e9614c8d
line wrap: on
line diff
--- a/libao2/ao_pulse.c	Fri Dec 18 19:29:33 2009 +0000
+++ b/libao2/ao_pulse.c	Fri Dec 18 20:22:39 2009 +0000
@@ -49,9 +49,6 @@
 /** Main event loop object */
 static struct pa_threaded_mainloop *mainloop;
 
-/** A temporary variable to store the current volume */
-static pa_cvolume volume;
-
 static int broken_pause;
 
 LIBAO_EXTERN(pulse)
@@ -144,6 +141,7 @@
     char *host = NULL;
     char *sink = NULL;
     char *version = pa_get_library_version();
+    struct pa_cvolume volume;
 
     if (ao_subdevice) {
         devarg = strdup(ao_subdevice);
@@ -350,13 +348,14 @@
  * pa_context_get_sink_input_info() operation completes. Saves the
  * volume field of the specified structure to the global variable volume. */
 static void info_func(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) {
+    struct pa_cvolume *volume = userdata;
     if (is_last < 0) {
         GENERIC_ERR_MSG(context, "Failed to get sink input info");
         return;
     }
     if (!i)
         return;
-    volume = i->volume;
+    *volume = i->volume;
     pa_threaded_mainloop_signal(mainloop, 0);
 }
 
@@ -365,8 +364,9 @@
         case AOCONTROL_GET_VOLUME: {
             ao_control_vol_t *vol = arg;
             uint32_t devidx = pa_stream_get_index(stream);
+            struct pa_cvolume volume;
             pa_threaded_mainloop_lock(mainloop);
-            if (!waitop(pa_context_get_sink_input_info(context, devidx, info_func, NULL))) {
+            if (!waitop(pa_context_get_sink_input_info(context, devidx, info_func, &volume))) {
                 GENERIC_ERR_MSG(context, "pa_stream_get_sink_input_info() failed");
                 return CONTROL_ERROR;
             }
@@ -384,7 +384,9 @@
         case AOCONTROL_SET_VOLUME: {
             const ao_control_vol_t *vol = arg;
             pa_operation *o;
+            struct pa_cvolume volume;
 
+            pa_cvolume_reset(&volume, ao_data.channels);
             if (volume.channels != 2)
                 pa_cvolume_set(&volume, volume.channels, (pa_volume_t)vol->left*PA_VOLUME_NORM/100);
             else {