annotate libao2/ao_polyp.c @ 17889:180736f5c1d8

codec-cfg depend on help_mp.h. Fix // builds.
author albeu
date Sat, 18 Mar 2006 17:41:24 +0000
parents cae0dbeb44bb
children afcc7b017a63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
1 #include <assert.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
2
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
3 #include <polyp/polyplib.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
4 #include <polyp/polyplib-error.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
5 #include <polyp/mainloop.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
6
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14245
diff changeset
7 #include "config.h"
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
8 #include "audio_out.h"
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
9 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
10 #include "libaf/af_format.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13878
diff changeset
11 #include "mp_msg.h"
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
12
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
13 #define POLYP_CLIENT_NAME "MPlayer"
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
14
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
15 /** General driver info */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
16 static ao_info_t info = {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
17 "Polypaudio audio output",
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
18 "polyp",
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
19 "Lennart Poettering",
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
20 ""
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
21 };
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
22
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
23 /** The sink to connect to */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
24 static char *sink = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
25
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
26 /** Polypaudio playback stream object */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
27 static struct pa_stream *stream = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
28
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
29 /** Polypaudio connection context */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
30 static struct pa_context *context = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
31
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
32 /** Main event loop object */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
33 static struct pa_mainloop *mainloop = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
34
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
35 /** Some special libao macro magic */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
36 LIBAO_EXTERN(polyp)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
37
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
38 /** Wait until no further actions are pending on the connection context */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
39 static void wait_for_completion(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
40 assert(context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
41
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
42 while (pa_context_is_pending(context))
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
43 pa_mainloop_iterate(mainloop, 1, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
44 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
45
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
46 /** Make sure that the connection context doesn't starve to death */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
47 static void keep_alive(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
48 assert(context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
49
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
50 while (pa_mainloop_iterate(mainloop, 0, NULL) > 0);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
51 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
52
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
53 /** Wait until the specified operation completes */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
54 static void wait_for_operation(struct pa_operation *o) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
55 assert(o && context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
56
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
57 while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
58 pa_mainloop_iterate(mainloop, 1, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
59
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
60 pa_operation_unref(o);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
61 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
62
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
63 /** libao initialization function, arguments are sampling frequency,
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
64 * number of channels, sample type and some flags */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
65 static int init(int rate_hz, int channels, int format, int flags) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
66 struct pa_sample_spec ss;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
67 struct pa_buffer_attr a;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
68 char hn[128];
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
69 char *host = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
70
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
71 assert(!context && !stream && !mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
72
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
73 if (ao_subdevice) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
74 int i = strcspn(ao_subdevice, ":");
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
75 if (i >= sizeof(hn))
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
76 i = sizeof(hn)-1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
77
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
78 if (i > 0) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
79 strncpy(host = hn, ao_subdevice, i);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
80 hn[i] = 0;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
81 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
82
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
83 if (ao_subdevice[i] == ':')
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
84 sink = ao_subdevice+i+1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
85 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
86
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
87 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] -%s-%s-\n", host, sink);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
88
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
89
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
90 ss.channels = channels;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
91 ss.rate = rate_hz;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
92
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
93 switch (format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
94 case AF_FORMAT_U8:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
95 ss.format = PA_SAMPLE_U8;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
96 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
97 case AF_FORMAT_S16_LE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
98 ss.format = PA_SAMPLE_S16LE;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
99 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
100 case AF_FORMAT_S16_BE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
101 ss.format = PA_SAMPLE_S16BE;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
102 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
103 case AF_FORMAT_FLOAT_NE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
104 ss.format = PA_SAMPLE_FLOAT32;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
105 break;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
106 default:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
107 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Unsupported sample spec\n");
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
108 goto fail;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
109 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
110
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
111
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
112 if (!pa_sample_spec_valid(&ss)) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
113 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Invalid sample spec\n");
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
114 goto fail;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
115 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
116
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
117
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
118 mainloop = pa_mainloop_new();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
119 assert(mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
120
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
121 context = pa_context_new(pa_mainloop_get_api(mainloop), POLYP_CLIENT_NAME);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
122 assert(context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
123
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
124 pa_context_connect(context, host, 1, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
125
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
126 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
127
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
128 if (pa_context_get_state(context) != PA_CONTEXT_READY) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
129 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Failed to connect to server: %s\n", pa_strerror(pa_context_errno(context)));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
130 goto fail;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
131 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
132
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
133 stream = pa_stream_new(context, "audio stream", &ss);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
134 assert(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
135
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
136 a.maxlength = pa_bytes_per_second(&ss)*1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
137 a.tlength = a.maxlength*9/10;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
138 a.prebuf = a.tlength/2;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
139 a.minreq = a.tlength/10;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
140
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
141 pa_stream_connect_playback(stream, sink, &a, PA_STREAM_INTERPOLATE_LATENCY, PA_VOLUME_NORM);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
142
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
143 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
144
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
145 if (pa_stream_get_state(stream) != PA_STREAM_READY) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
146 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Failed to connect to server: %s\n", pa_strerror(pa_context_errno(context)));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
147 goto fail;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
148 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
149
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
150 return 1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
151
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
152 fail:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
153 uninit(1);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
154 return 0;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
155 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
156
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
157 /** Destroy libao driver */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
158 static void uninit(int immed) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
159 if (stream) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
160 if (!immed && pa_stream_get_state(stream) == PA_STREAM_READY)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
161 wait_for_operation(pa_stream_drain(stream, NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
162
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
163 pa_stream_unref(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
164 stream = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
165 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
166
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
167 if (context) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
168 pa_context_unref(context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
169 context = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
170 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
171
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
172 if (mainloop) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
173 pa_mainloop_free(mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
174 mainloop = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
175 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
176 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
177
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
178 /** Play the specified data to the polypaudio server */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
179 static int play(void* data, int len, int flags) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
180 assert(stream && context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
181
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
182 if (pa_stream_get_state(stream) != PA_STREAM_READY)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
183 return -1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
184
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
185 if (!len)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
186 wait_for_operation(pa_stream_trigger(stream, NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
187 else
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
188 pa_stream_write(stream, data, len, NULL, 0);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
189
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
190 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
191
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
192 if (pa_stream_get_state(stream) != PA_STREAM_READY)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
193 return -1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
194
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
195 return len;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
196 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
197
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
198 /** Pause the audio stream by corking it on the server */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
199 static void audio_pause() {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
200 assert(stream && context && pa_stream_get_state(stream) == PA_STREAM_READY);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
201 wait_for_operation(pa_stream_cork(stream, 1, NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
202 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
203
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
204 /** Resume the audio stream by uncorking it on the server */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
205 static void audio_resume() {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
206 assert(stream && context && pa_stream_get_state(stream) == PA_STREAM_READY);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
207 wait_for_operation(pa_stream_cork(stream, 0, NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
208 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
209
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
210 /** Reset the audio stream, i.e. flush the playback buffer on the server side */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
211 static void reset() {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
212 assert(stream && context && pa_stream_get_state(stream) == PA_STREAM_READY);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
213 wait_for_operation(pa_stream_flush(stream, NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
214 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
215
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
216 /** Return number of bytes that may be written to the server without blocking */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
217 static int get_space(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
218 uint32_t l;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
219 assert(stream && context && pa_stream_get_state(stream) == PA_STREAM_READY);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
220
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
221 keep_alive();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
222
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
223 l = pa_stream_writable_size(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
224
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
225 return l;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
226 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
227
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
228 /* A temporary latency variable */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
229 /* static pa_usec_t latency = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
230
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
231 /* static void latency_func(struct pa_stream *s, const struct pa_latency_info *l, void *userdata) { */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
232 /* int negative = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
233
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
234 /* if (!l) { */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
235 /* mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Invalid sample spec: %s\n", pa_strerror(pa_context_errno(context))); */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
236 /* return; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
237 /* } */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
238
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
239 /* latency = pa_stream_get_latency(s, l, &negative); */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
240
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
241 /* /\* Nor really required *\/ */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
242 /* if (negative) */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
243 /* latency = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
244 /* } */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
245
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
246 /** Return the current latency in seconds */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
247 static float get_delay(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
248 assert(stream && context && pa_stream_get_state(stream) == PA_STREAM_READY);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
249 pa_usec_t latency;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
250
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
251 /* latency = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
252 /* wait_for_operation(pa_stream_get_latency(stream, latency_func, NULL)); */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
253 /* pa_operation_unref(pa_stream_get_latency(stream, latency_func, NULL)); */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
254
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
255 latency = pa_stream_get_interpolated_latency(stream, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
256
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
257 return (float) latency/1000000;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
258 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
259
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
260 /** A temporary variable to store the current volume */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
261 static pa_volume_t volume = PA_VOLUME_NORM;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
262
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
263 /** A callback function that is called when the
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
264 * pa_context_get_sink_input_info() operation completes. Saves the
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
265 * volume field of the specified structure to the global variable volume. */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
266 static void info_func(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
267 if (is_last < 0) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
268 mp_msg(MSGT_AO, MSGL_ERR, "AO: [polyp] Failed to get sink input info: %s\n", pa_strerror(pa_context_errno(context)));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
269 return;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
270 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
271
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
272 if (!i)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
273 return;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
274
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
275 volume = i->volume;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
276 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
277
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
278 /** Issue special libao controls on the device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
279 static int control(int cmd, void *arg) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
280
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
281 if (!context || !stream)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
282 return CONTROL_ERROR;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
283
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
284 switch (cmd) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
285
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
286 case AOCONTROL_SET_DEVICE:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
287 /* Change the playback device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
288 sink = (char*)arg;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
289 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
290
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
291 case AOCONTROL_GET_DEVICE:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
292 /* Return the playback device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
293 *(char**)arg = sink;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
294 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
295
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
296 case AOCONTROL_GET_VOLUME: {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
297 /* Return the current volume of the playback stream */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
298 ao_control_vol_t *vol = (ao_control_vol_t*) arg;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
299
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
300 volume = PA_VOLUME_NORM;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
301 wait_for_operation(pa_context_get_sink_input_info(context, pa_stream_get_index(stream), info_func, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
302 vol->left = vol->right = (int) (pa_volume_to_user(volume)*100);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
303 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
304 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
305
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
306 case AOCONTROL_SET_VOLUME: {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
307 /* Set the playback volume of the stream */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
308 const ao_control_vol_t *vol = (ao_control_vol_t*) arg;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
309 int v = vol->left;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
310 if (vol->right > v)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
311 v = vol->left;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
312
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
313 wait_for_operation(pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), pa_volume_from_user((double)v/100), NULL, NULL));
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
314
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
315 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
316 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
317
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
318 default:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
319 /* Unknown CONTROL command */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
320 return CONTROL_UNKNOWN;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
321 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
322 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
323