Mercurial > mplayer.hg
annotate libao2/ao_pulse.c @ 34635:7e0f50b4921c
Fix vo_png after FFmpeg merge.
Now avcodec_open2() function wants a valid avctx->pix_fmt to be set,
but the current vo_png opens the encoder in preinit() function,
long before the exact pixel format is know.
The fix moves the avcodec_open2() function to vo_png::config() and
adds a check for changed pixel format in case there are more config() calls.
author | iive |
---|---|
date | Tue, 14 Feb 2012 17:06:09 +0000 |
parents | 96019b1174b8 |
children | 583c7cfc6653 |
rev | line source |
---|---|
24782 | 1 /* |
2 * PulseAudio audio output driver. | |
3 * Copyright (C) 2006 Lennart Poettering | |
4 * Copyright (C) 2007 Reimar Doeffinger | |
5 * | |
6 * This file is part of MPlayer. | |
7 * | |
8 * MPlayer is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * MPlayer is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
26743
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26649
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26649
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26649
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
24782 | 21 */ |
26743
0f42fb42843c
Use standard license headers with standard formatting.
diego
parents:
26649
diff
changeset
|
22 |
24782 | 23 #include <string.h> |
24 | |
25 #include <pulse/pulseaudio.h> | |
26 | |
27 #include "config.h" | |
28 #include "libaf/af_format.h" | |
34564
96019b1174b8
Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866)
iive
parents:
30020
diff
changeset
|
29 #include "osdep/timer.h" |
24782 | 30 #include "mp_msg.h" |
31 #include "audio_out.h" | |
32 #include "audio_out_internal.h" | |
33 | |
34 #define PULSE_CLIENT_NAME "MPlayer" | |
35 | |
36 /** General driver info */ | |
28823 | 37 static const ao_info_t info = { |
24782 | 38 "PulseAudio audio output", |
39 "pulse", | |
40 "Lennart Poettering", | |
41 "" | |
42 }; | |
43 | |
44 /** PulseAudio playback stream object */ | |
45 static struct pa_stream *stream; | |
46 | |
47 /** PulseAudio connection context */ | |
48 static struct pa_context *context; | |
49 | |
50 /** Main event loop object */ | |
51 static struct pa_threaded_mainloop *mainloop; | |
52 | |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
53 static int broken_pause; |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
54 |
24782 | 55 LIBAO_EXTERN(pulse) |
56 | |
57 #define GENERIC_ERR_MSG(ctx, str) \ | |
58 mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] "str": %s\n", \ | |
59 pa_strerror(pa_context_errno(ctx))) | |
60 | |
61 static void context_state_cb(pa_context *c, void *userdata) { | |
62 switch (pa_context_get_state(c)) { | |
63 case PA_CONTEXT_READY: | |
64 case PA_CONTEXT_TERMINATED: | |
65 case PA_CONTEXT_FAILED: | |
66 pa_threaded_mainloop_signal(mainloop, 0); | |
67 break; | |
68 } | |
69 } | |
70 | |
71 static void stream_state_cb(pa_stream *s, void *userdata) { | |
72 switch (pa_stream_get_state(s)) { | |
73 case PA_STREAM_READY: | |
74 case PA_STREAM_FAILED: | |
75 case PA_STREAM_TERMINATED: | |
76 pa_threaded_mainloop_signal(mainloop, 0); | |
77 break; | |
78 } | |
79 } | |
80 | |
81 static void stream_request_cb(pa_stream *s, size_t length, void *userdata) { | |
82 pa_threaded_mainloop_signal(mainloop, 0); | |
83 } | |
84 | |
85 static void stream_latency_update_cb(pa_stream *s, void *userdata) { | |
86 pa_threaded_mainloop_signal(mainloop, 0); | |
87 } | |
88 | |
89 static void success_cb(pa_stream *s, int success, void *userdata) { | |
90 if (userdata) | |
91 *(int *)userdata = success; | |
92 pa_threaded_mainloop_signal(mainloop, 0); | |
93 } | |
94 | |
25383 | 95 /** |
96 * \brief waits for a pulseaudio operation to finish, frees it and | |
97 * unlocks the mainloop | |
98 * \param op operation to wait for | |
99 * \return 1 if operation has finished normally (DONE state), 0 otherwise | |
100 */ | |
24782 | 101 static int waitop(pa_operation *op) { |
102 pa_operation_state_t state; | |
29117
010781e92294
Make sure waitop always unlocks the mainloop even if the operation could not
reimar
parents:
28823
diff
changeset
|
103 if (!op) { |
010781e92294
Make sure waitop always unlocks the mainloop even if the operation could not
reimar
parents:
28823
diff
changeset
|
104 pa_threaded_mainloop_unlock(mainloop); |
010781e92294
Make sure waitop always unlocks the mainloop even if the operation could not
reimar
parents:
28823
diff
changeset
|
105 return 0; |
010781e92294
Make sure waitop always unlocks the mainloop even if the operation could not
reimar
parents:
28823
diff
changeset
|
106 } |
24782 | 107 state = pa_operation_get_state(op); |
108 while (state == PA_OPERATION_RUNNING) { | |
109 pa_threaded_mainloop_wait(mainloop); | |
110 state = pa_operation_get_state(op); | |
111 } | |
112 pa_operation_unref(op); | |
113 pa_threaded_mainloop_unlock(mainloop); | |
114 return state == PA_OPERATION_DONE; | |
115 } | |
116 | |
117 static const struct format_map_s { | |
118 int mp_format; | |
119 pa_sample_format_t pa_format; | |
120 } format_maps[] = { | |
121 {AF_FORMAT_S16_LE, PA_SAMPLE_S16LE}, | |
122 {AF_FORMAT_S16_BE, PA_SAMPLE_S16BE}, | |
26649 | 123 #ifdef PA_SAMPLE_S32NE |
26603 | 124 {AF_FORMAT_S32_LE, PA_SAMPLE_S32LE}, |
125 {AF_FORMAT_S32_BE, PA_SAMPLE_S32BE}, | |
26649 | 126 #endif |
127 #ifdef PA_SAMPLE_FLOAT32NE | |
24782 | 128 {AF_FORMAT_FLOAT_LE, PA_SAMPLE_FLOAT32LE}, |
129 {AF_FORMAT_FLOAT_BE, PA_SAMPLE_FLOAT32BE}, | |
26649 | 130 #endif |
26602
d48e2d7191df
Make ao_pulse fall back to s16le format instead of just failing.
reimar
parents:
25386
diff
changeset
|
131 {AF_FORMAT_U8, PA_SAMPLE_U8}, |
24782 | 132 {AF_FORMAT_MU_LAW, PA_SAMPLE_ULAW}, |
133 {AF_FORMAT_A_LAW, PA_SAMPLE_ALAW}, | |
134 {AF_FORMAT_UNKNOWN, 0} | |
135 }; | |
136 | |
137 static int init(int rate_hz, int channels, int format, int flags) { | |
138 struct pa_sample_spec ss; | |
139 struct pa_channel_map map; | |
140 const struct format_map_s *fmt_map; | |
24921
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
141 char *devarg = NULL; |
24782 | 142 char *host = NULL; |
24919
51372a34bc7d
Make sink variable local, it is only used in one place
reimar
parents:
24782
diff
changeset
|
143 char *sink = NULL; |
30020 | 144 const char *version = pa_get_library_version(); |
24782 | 145 |
146 if (ao_subdevice) { | |
24921
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
147 devarg = strdup(ao_subdevice); |
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
148 sink = strchr(devarg, ':'); |
24920 | 149 if (sink) *sink++ = 0; |
24921
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
150 if (devarg[0]) host = devarg; |
24782 | 151 } |
152 | |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
153 broken_pause = 0; |
29120
aa06c29db609
Disable pause-hack from PulseAudio 0.9.15 on, it should be fixed.
reimar
parents:
29119
diff
changeset
|
154 // not sure which versions are affected, assume 0.9.11* to 0.9.14* |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
155 // known bad: 0.9.14, 0.9.13 |
29120
aa06c29db609
Disable pause-hack from PulseAudio 0.9.15 on, it should be fixed.
reimar
parents:
29119
diff
changeset
|
156 // known good: 0.9.9, 0.9.10, 0.9.15 |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
157 // to test: pause, wait ca. 5 seconds framestep and see if MPlayer hangs somewhen |
29120
aa06c29db609
Disable pause-hack from PulseAudio 0.9.15 on, it should be fixed.
reimar
parents:
29119
diff
changeset
|
158 if (strncmp(version, "0.9.1", 5) == 0 && version[5] >= '1' && version[5] <= '4') { |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
159 mp_msg(MSGT_AO, MSGL_WARN, "[pulse] working around probably broken pause functionality,\n" |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
160 " see http://www.pulseaudio.org/ticket/440\n"); |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
161 broken_pause = 1; |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
162 } |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
163 |
24782 | 164 ss.channels = channels; |
165 ss.rate = rate_hz; | |
166 | |
167 ao_data.samplerate = rate_hz; | |
168 ao_data.channels = channels; | |
169 | |
170 fmt_map = format_maps; | |
171 while (fmt_map->mp_format != format) { | |
172 if (fmt_map->mp_format == AF_FORMAT_UNKNOWN) { | |
26602
d48e2d7191df
Make ao_pulse fall back to s16le format instead of just failing.
reimar
parents:
25386
diff
changeset
|
173 mp_msg(MSGT_AO, MSGL_V, "AO: [pulse] Unsupported format, using default\n"); |
d48e2d7191df
Make ao_pulse fall back to s16le format instead of just failing.
reimar
parents:
25386
diff
changeset
|
174 fmt_map = format_maps; |
d48e2d7191df
Make ao_pulse fall back to s16le format instead of just failing.
reimar
parents:
25386
diff
changeset
|
175 break; |
24782 | 176 } |
177 fmt_map++; | |
178 } | |
26602
d48e2d7191df
Make ao_pulse fall back to s16le format instead of just failing.
reimar
parents:
25386
diff
changeset
|
179 ao_data.format = fmt_map->mp_format; |
24782 | 180 ss.format = fmt_map->pa_format; |
181 | |
182 if (!pa_sample_spec_valid(&ss)) { | |
183 mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Invalid sample spec\n"); | |
184 goto fail; | |
185 } | |
186 | |
187 pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_ALSA); | |
188 ao_data.bps = pa_bytes_per_second(&ss); | |
189 | |
190 if (!(mainloop = pa_threaded_mainloop_new())) { | |
191 mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Failed to allocate main loop\n"); | |
192 goto fail; | |
193 } | |
194 | |
195 if (!(context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), PULSE_CLIENT_NAME))) { | |
196 mp_msg(MSGT_AO, MSGL_ERR, "AO: [pulse] Failed to allocate context\n"); | |
197 goto fail; | |
198 } | |
199 | |
200 pa_context_set_state_callback(context, context_state_cb, NULL); | |
201 | |
202 if (pa_context_connect(context, host, 0, NULL) < 0) | |
203 goto fail; | |
204 | |
205 pa_threaded_mainloop_lock(mainloop); | |
206 | |
207 if (pa_threaded_mainloop_start(mainloop) < 0) | |
208 goto unlock_and_fail; | |
209 | |
210 /* Wait until the context is ready */ | |
211 pa_threaded_mainloop_wait(mainloop); | |
212 | |
213 if (pa_context_get_state(context) != PA_CONTEXT_READY) | |
214 goto unlock_and_fail; | |
215 | |
216 if (!(stream = pa_stream_new(context, "audio stream", &ss, &map))) | |
217 goto unlock_and_fail; | |
218 | |
219 pa_stream_set_state_callback(stream, stream_state_cb, NULL); | |
220 pa_stream_set_write_callback(stream, stream_request_cb, NULL); | |
221 pa_stream_set_latency_update_callback(stream, stream_latency_update_cb, NULL); | |
222 | |
30019
2d62e9614c8d
Allow pulseaudio to restore the previous volume on init instead of forcing to
reimar
parents:
30018
diff
changeset
|
223 if (pa_stream_connect_playback(stream, sink, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL) < 0) |
24782 | 224 goto unlock_and_fail; |
225 | |
226 /* Wait until the stream is ready */ | |
227 pa_threaded_mainloop_wait(mainloop); | |
228 | |
229 if (pa_stream_get_state(stream) != PA_STREAM_READY) | |
230 goto unlock_and_fail; | |
231 | |
232 pa_threaded_mainloop_unlock(mainloop); | |
233 | |
24921
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
234 free(devarg); |
24782 | 235 return 1; |
236 | |
237 unlock_and_fail: | |
238 | |
239 if (mainloop) | |
240 pa_threaded_mainloop_unlock(mainloop); | |
241 | |
242 fail: | |
243 if (context) | |
244 GENERIC_ERR_MSG(context, "Init failed"); | |
24921
148ca265fcb6
Change parsing to allow host == NULL and sink != NULL
reimar
parents:
24920
diff
changeset
|
245 free(devarg); |
24782 | 246 uninit(1); |
247 return 0; | |
248 } | |
249 | |
250 /** Destroy libao driver */ | |
251 static void uninit(int immed) { | |
252 if (stream && !immed) { | |
34564
96019b1174b8
Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866)
iive
parents:
30020
diff
changeset
|
253 /* Workaround the bug in pa_stream_drain that causes |
96019b1174b8
Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866)
iive
parents:
30020
diff
changeset
|
254 a delay of 2 second if the buffer is not empty */ |
96019b1174b8
Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866)
iive
parents:
30020
diff
changeset
|
255 usec_sleep(get_delay() * 1000 * 1000); |
96019b1174b8
Workaround a bug in Pulse Audio (http://pulseaudio.org/ticket/866)
iive
parents:
30020
diff
changeset
|
256 |
24782 | 257 pa_threaded_mainloop_lock(mainloop); |
258 waitop(pa_stream_drain(stream, success_cb, NULL)); | |
259 } | |
260 | |
261 if (mainloop) | |
262 pa_threaded_mainloop_stop(mainloop); | |
263 | |
264 if (stream) { | |
265 pa_stream_disconnect(stream); | |
266 pa_stream_unref(stream); | |
267 stream = NULL; | |
268 } | |
269 | |
270 if (context) { | |
271 pa_context_disconnect(context); | |
272 pa_context_unref(context); | |
273 context = NULL; | |
274 } | |
275 | |
276 if (mainloop) { | |
277 pa_threaded_mainloop_free(mainloop); | |
278 mainloop = NULL; | |
279 } | |
280 } | |
281 | |
282 /** Play the specified data to the pulseaudio server */ | |
283 static int play(void* data, int len, int flags) { | |
25386
bd46b759fd35
pa_stream_write reportedly needs locking of the main loop
reimar
parents:
25385
diff
changeset
|
284 pa_threaded_mainloop_lock(mainloop); |
25385 | 285 if (pa_stream_write(stream, data, len, NULL, 0, PA_SEEK_RELATIVE) < 0) { |
286 GENERIC_ERR_MSG(context, "pa_stream_write() failed"); | |
25386
bd46b759fd35
pa_stream_write reportedly needs locking of the main loop
reimar
parents:
25385
diff
changeset
|
287 len = -1; |
25385 | 288 } |
25386
bd46b759fd35
pa_stream_write reportedly needs locking of the main loop
reimar
parents:
25385
diff
changeset
|
289 pa_threaded_mainloop_unlock(mainloop); |
24782 | 290 return len; |
291 } | |
292 | |
293 static void cork(int b) { | |
294 int success = 0; | |
295 pa_threaded_mainloop_lock(mainloop); | |
296 if (!waitop(pa_stream_cork(stream, b, success_cb, &success)) || | |
297 !success) | |
298 GENERIC_ERR_MSG(context, "pa_stream_cork() failed"); | |
299 } | |
300 | |
301 /** Pause the audio stream by corking it on the server */ | |
302 static void audio_pause(void) { | |
303 cork(1); | |
304 } | |
305 | |
306 /** Resume the audio stream by uncorking it on the server */ | |
307 static void audio_resume(void) { | |
28633
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
308 // without this, certain versions will cause an infinite hang because |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
309 // pa_stream_writable_size returns 0 always. |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
310 // Note that this workaround causes A-V desync after pause |
28fe0787a67c
Work around a PulseAudio bug that causes MPlayer to hang after unpausing.
reimar
parents:
26743
diff
changeset
|
311 if (broken_pause) reset(); |
24782 | 312 cork(0); |
313 } | |
314 | |
315 /** Reset the audio stream, i.e. flush the playback buffer on the server side */ | |
316 static void reset(void) { | |
317 int success = 0; | |
318 pa_threaded_mainloop_lock(mainloop); | |
319 if (!waitop(pa_stream_flush(stream, success_cb, &success)) || | |
320 !success) | |
321 GENERIC_ERR_MSG(context, "pa_stream_flush() failed"); | |
322 } | |
323 | |
324 /** Return number of bytes that may be written to the server without blocking */ | |
325 static int get_space(void) { | |
326 size_t l; | |
327 pa_threaded_mainloop_lock(mainloop); | |
328 l = pa_stream_writable_size(stream); | |
329 pa_threaded_mainloop_unlock(mainloop); | |
24923 | 330 return l; |
24782 | 331 } |
332 | |
333 /** Return the current latency in seconds */ | |
334 static float get_delay(void) { | |
335 pa_usec_t latency = (pa_usec_t) -1; | |
336 pa_threaded_mainloop_lock(mainloop); | |
337 while (pa_stream_get_latency(stream, &latency, NULL) < 0) { | |
338 if (pa_context_errno(context) != PA_ERR_NODATA) { | |
339 GENERIC_ERR_MSG(context, "pa_stream_get_latency() failed"); | |
340 break; | |
341 } | |
342 /* Wait until latency data is available again */ | |
343 pa_threaded_mainloop_wait(mainloop); | |
344 } | |
345 pa_threaded_mainloop_unlock(mainloop); | |
346 return latency == (pa_usec_t) -1 ? 0 : latency / 1000000.0; | |
347 } | |
348 | |
349 /** A callback function that is called when the | |
350 * pa_context_get_sink_input_info() operation completes. Saves the | |
351 * 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) { | |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
353 struct pa_cvolume *volume = userdata; |
24782 | 354 if (is_last < 0) { |
355 GENERIC_ERR_MSG(context, "Failed to get sink input info"); | |
356 return; | |
357 } | |
358 if (!i) | |
359 return; | |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
360 *volume = i->volume; |
24782 | 361 pa_threaded_mainloop_signal(mainloop, 0); |
362 } | |
363 | |
364 static int control(int cmd, void *arg) { | |
365 switch (cmd) { | |
366 case AOCONTROL_GET_VOLUME: { | |
367 ao_control_vol_t *vol = arg; | |
368 uint32_t devidx = pa_stream_get_index(stream); | |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
369 struct pa_cvolume volume; |
24782 | 370 pa_threaded_mainloop_lock(mainloop); |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
371 if (!waitop(pa_context_get_sink_input_info(context, devidx, info_func, &volume))) { |
24782 | 372 GENERIC_ERR_MSG(context, "pa_stream_get_sink_input_info() failed"); |
373 return CONTROL_ERROR; | |
374 } | |
375 | |
376 if (volume.channels != 2) | |
377 vol->left = vol->right = pa_cvolume_avg(&volume)*100/PA_VOLUME_NORM; | |
378 else { | |
379 vol->left = volume.values[0]*100/PA_VOLUME_NORM; | |
380 vol->right = volume.values[1]*100/PA_VOLUME_NORM; | |
381 } | |
382 | |
383 return CONTROL_OK; | |
384 } | |
385 | |
386 case AOCONTROL_SET_VOLUME: { | |
387 const ao_control_vol_t *vol = arg; | |
388 pa_operation *o; | |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
389 struct pa_cvolume volume; |
24782 | 390 |
30018
ae5d67d8ee95
Get rid of global volume variable, it is only used for temporary values.
reimar
parents:
29120
diff
changeset
|
391 pa_cvolume_reset(&volume, ao_data.channels); |
24782 | 392 if (volume.channels != 2) |
393 pa_cvolume_set(&volume, volume.channels, (pa_volume_t)vol->left*PA_VOLUME_NORM/100); | |
394 else { | |
395 volume.values[0] = (pa_volume_t)vol->left*PA_VOLUME_NORM/100; | |
396 volume.values[1] = (pa_volume_t)vol->right*PA_VOLUME_NORM/100; | |
397 } | |
398 | |
29118
17c6a6c192a7
Also lock the mainloop when doing adjusting the volume for PulseAudio.
reimar
parents:
29117
diff
changeset
|
399 pa_threaded_mainloop_lock(mainloop); |
29119
52afd0fe451b
Split oversized of "argument" onto a separate line.
reimar
parents:
29118
diff
changeset
|
400 o = pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), &volume, NULL, NULL); |
52afd0fe451b
Split oversized of "argument" onto a separate line.
reimar
parents:
29118
diff
changeset
|
401 if (!o) { |
29118
17c6a6c192a7
Also lock the mainloop when doing adjusting the volume for PulseAudio.
reimar
parents:
29117
diff
changeset
|
402 pa_threaded_mainloop_unlock(mainloop); |
24782 | 403 GENERIC_ERR_MSG(context, "pa_context_set_sink_input_volume() failed"); |
404 return CONTROL_ERROR; | |
405 } | |
406 /* We don't wait for completion here */ | |
407 pa_operation_unref(o); | |
29118
17c6a6c192a7
Also lock the mainloop when doing adjusting the volume for PulseAudio.
reimar
parents:
29117
diff
changeset
|
408 pa_threaded_mainloop_unlock(mainloop); |
24782 | 409 return CONTROL_OK; |
410 } | |
411 | |
412 default: | |
413 return CONTROL_UNKNOWN; | |
414 } | |
415 } |