Mercurial > mplayer.hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
30017:7119354805e7 | 30018:ae5d67d8ee95 |
---|---|
47 static struct pa_context *context; | 47 static struct pa_context *context; |
48 | 48 |
49 /** Main event loop object */ | 49 /** Main event loop object */ |
50 static struct pa_threaded_mainloop *mainloop; | 50 static struct pa_threaded_mainloop *mainloop; |
51 | 51 |
52 /** A temporary variable to store the current volume */ | |
53 static pa_cvolume volume; | |
54 | |
55 static int broken_pause; | 52 static int broken_pause; |
56 | 53 |
57 LIBAO_EXTERN(pulse) | 54 LIBAO_EXTERN(pulse) |
58 | 55 |
59 #define GENERIC_ERR_MSG(ctx, str) \ | 56 #define GENERIC_ERR_MSG(ctx, str) \ |
142 const struct format_map_s *fmt_map; | 139 const struct format_map_s *fmt_map; |
143 char *devarg = NULL; | 140 char *devarg = NULL; |
144 char *host = NULL; | 141 char *host = NULL; |
145 char *sink = NULL; | 142 char *sink = NULL; |
146 char *version = pa_get_library_version(); | 143 char *version = pa_get_library_version(); |
144 struct pa_cvolume volume; | |
147 | 145 |
148 if (ao_subdevice) { | 146 if (ao_subdevice) { |
149 devarg = strdup(ao_subdevice); | 147 devarg = strdup(ao_subdevice); |
150 sink = strchr(devarg, ':'); | 148 sink = strchr(devarg, ':'); |
151 if (sink) *sink++ = 0; | 149 if (sink) *sink++ = 0; |
348 | 346 |
349 /** A callback function that is called when the | 347 /** A callback function that is called when the |
350 * pa_context_get_sink_input_info() operation completes. Saves the | 348 * pa_context_get_sink_input_info() operation completes. Saves the |
351 * volume field of the specified structure to the global variable volume. */ | 349 * volume field of the specified structure to the global variable volume. */ |
352 static void info_func(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) { | 350 static void info_func(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) { |
351 struct pa_cvolume *volume = userdata; | |
353 if (is_last < 0) { | 352 if (is_last < 0) { |
354 GENERIC_ERR_MSG(context, "Failed to get sink input info"); | 353 GENERIC_ERR_MSG(context, "Failed to get sink input info"); |
355 return; | 354 return; |
356 } | 355 } |
357 if (!i) | 356 if (!i) |
358 return; | 357 return; |
359 volume = i->volume; | 358 *volume = i->volume; |
360 pa_threaded_mainloop_signal(mainloop, 0); | 359 pa_threaded_mainloop_signal(mainloop, 0); |
361 } | 360 } |
362 | 361 |
363 static int control(int cmd, void *arg) { | 362 static int control(int cmd, void *arg) { |
364 switch (cmd) { | 363 switch (cmd) { |
365 case AOCONTROL_GET_VOLUME: { | 364 case AOCONTROL_GET_VOLUME: { |
366 ao_control_vol_t *vol = arg; | 365 ao_control_vol_t *vol = arg; |
367 uint32_t devidx = pa_stream_get_index(stream); | 366 uint32_t devidx = pa_stream_get_index(stream); |
367 struct pa_cvolume volume; | |
368 pa_threaded_mainloop_lock(mainloop); | 368 pa_threaded_mainloop_lock(mainloop); |
369 if (!waitop(pa_context_get_sink_input_info(context, devidx, info_func, NULL))) { | 369 if (!waitop(pa_context_get_sink_input_info(context, devidx, info_func, &volume))) { |
370 GENERIC_ERR_MSG(context, "pa_stream_get_sink_input_info() failed"); | 370 GENERIC_ERR_MSG(context, "pa_stream_get_sink_input_info() failed"); |
371 return CONTROL_ERROR; | 371 return CONTROL_ERROR; |
372 } | 372 } |
373 | 373 |
374 if (volume.channels != 2) | 374 if (volume.channels != 2) |
382 } | 382 } |
383 | 383 |
384 case AOCONTROL_SET_VOLUME: { | 384 case AOCONTROL_SET_VOLUME: { |
385 const ao_control_vol_t *vol = arg; | 385 const ao_control_vol_t *vol = arg; |
386 pa_operation *o; | 386 pa_operation *o; |
387 | 387 struct pa_cvolume volume; |
388 | |
389 pa_cvolume_reset(&volume, ao_data.channels); | |
388 if (volume.channels != 2) | 390 if (volume.channels != 2) |
389 pa_cvolume_set(&volume, volume.channels, (pa_volume_t)vol->left*PA_VOLUME_NORM/100); | 391 pa_cvolume_set(&volume, volume.channels, (pa_volume_t)vol->left*PA_VOLUME_NORM/100); |
390 else { | 392 else { |
391 volume.values[0] = (pa_volume_t)vol->left*PA_VOLUME_NORM/100; | 393 volume.values[0] = (pa_volume_t)vol->left*PA_VOLUME_NORM/100; |
392 volume.values[1] = (pa_volume_t)vol->right*PA_VOLUME_NORM/100; | 394 volume.values[1] = (pa_volume_t)vol->right*PA_VOLUME_NORM/100; |