annotate libao2/ao_polyp.c @ 19796:4cbe82f67e1e

add support for vp6 in flash
author aurel
date Tue, 12 Sep 2006 00:20:53 +0000
parents 99e20a22d5d0
children 84f95595f31f
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>
18490
rathann
parents: 14479
diff changeset
2 #include <string.h>
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
3
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
4 #include <polyp/polyplib.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
5 #include <polyp/polyplib-error.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
6 #include <polyp/mainloop.h>
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
7
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14245
diff changeset
8 #include "config.h"
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
9 #include "audio_out.h"
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
10 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
11 #include "libaf/af_format.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13878
diff changeset
12 #include "mp_msg.h"
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
13
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
14 #define POLYP_CLIENT_NAME "MPlayer"
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
15
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
16 /** General driver info */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
17 static ao_info_t info = {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
18 "Polypaudio audio output",
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
19 "polyp",
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
20 "Lennart Poettering",
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
24 /** The sink to connect to */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
25 static char *sink = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
26
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
27 /** Polypaudio playback stream object */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
28 static struct pa_stream *stream = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
29
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
30 /** Polypaudio connection context */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
31 static struct pa_context *context = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
32
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
33 /** Main event loop object */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
34 static struct pa_mainloop *mainloop = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
35
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
36 /** Some special libao macro magic */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
37 LIBAO_EXTERN(polyp)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
38
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
39 /** 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
40 static void wait_for_completion(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
41 assert(context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
42
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
43 while (pa_context_is_pending(context))
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
44 pa_mainloop_iterate(mainloop, 1, NULL);
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
47 /** 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
48 static void keep_alive(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
49 assert(context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
50
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
51 while (pa_mainloop_iterate(mainloop, 0, NULL) > 0);
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
54 /** Wait until the specified operation completes */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
55 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
56 assert(o && context && mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
57
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
58 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
59 pa_mainloop_iterate(mainloop, 1, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
60
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
61 pa_operation_unref(o);
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
64 /** libao initialization function, arguments are sampling frequency,
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
65 * number of channels, sample type and some flags */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
66 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
67 struct pa_sample_spec ss;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
68 struct pa_buffer_attr a;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
69 char hn[128];
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
70 char *host = NULL;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
71
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
72 assert(!context && !stream && !mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
73
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
74 if (ao_subdevice) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
75 int i = strcspn(ao_subdevice, ":");
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
76 if (i >= sizeof(hn))
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
77 i = sizeof(hn)-1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
78
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
79 if (i > 0) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
80 strncpy(host = hn, ao_subdevice, i);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
81 hn[i] = 0;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
84 if (ao_subdevice[i] == ':')
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
85 sink = ao_subdevice+i+1;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
88 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
89
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
90
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
91 ss.channels = channels;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
92 ss.rate = rate_hz;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
93
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
94 switch (format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
95 case AF_FORMAT_U8:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
96 ss.format = PA_SAMPLE_U8;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
97 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
98 case AF_FORMAT_S16_LE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
99 ss.format = PA_SAMPLE_S16LE;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
100 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
101 case AF_FORMAT_S16_BE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
102 ss.format = PA_SAMPLE_S16BE;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
103 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
104 case AF_FORMAT_FLOAT_NE:
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
105 ss.format = PA_SAMPLE_FLOAT32;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
106 break;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
107 default:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
108 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
109 goto fail;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
113 if (!pa_sample_spec_valid(&ss)) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
114 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
115 goto fail;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
119 mainloop = pa_mainloop_new();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
120 assert(mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
121
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
122 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
123 assert(context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
124
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
125 pa_context_connect(context, host, 1, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
126
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
127 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
128
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
129 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
130 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
131 goto fail;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
134 stream = pa_stream_new(context, "audio stream", &ss);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
135 assert(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
136
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
137 a.maxlength = pa_bytes_per_second(&ss)*1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
138 a.tlength = a.maxlength*9/10;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
139 a.prebuf = a.tlength/2;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
140 a.minreq = a.tlength/10;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
141
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
142 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
143
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
144 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
145
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
146 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
147 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
148 goto fail;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
151 return 1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
152
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
153 fail:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
154 uninit(1);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
155 return 0;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
158 /** Destroy libao driver */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
159 static void uninit(int immed) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
160 if (stream) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
161 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
162 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
163
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
164 pa_stream_unref(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
165 stream = NULL;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
168 if (context) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
169 pa_context_unref(context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
170 context = NULL;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
173 if (mainloop) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
174 pa_mainloop_free(mainloop);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
175 mainloop = NULL;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
179 /** Play the specified data to the polypaudio server */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
180 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
181 assert(stream && context);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
182
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
183 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
184 return -1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
185
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
186 if (!len)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
187 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
188 else
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
189 pa_stream_write(stream, data, len, NULL, 0);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
190
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
191 wait_for_completion();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
192
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
193 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
194 return -1;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
195
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
196 return len;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
199 /** Pause the audio stream by corking it on the server */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18490
diff changeset
200 static void audio_pause(void) {
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
201 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
202 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
203 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
204
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
205 /** Resume the audio stream by uncorking it on the server */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18490
diff changeset
206 static void audio_resume(void) {
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
207 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
208 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
209 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
210
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
211 /** Reset the audio stream, i.e. flush the playback buffer on the server side */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 18490
diff changeset
212 static void reset(void) {
13878
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
213 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
214 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
215 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
216
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
217 /** 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
218 static int get_space(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
219 uint32_t l;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
220 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
221
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
222 keep_alive();
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
223
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
224 l = pa_stream_writable_size(stream);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
225
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
226 return l;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
229 /* A temporary latency variable */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
230 /* static pa_usec_t latency = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
231
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
232 /* 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
233 /* int negative = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
234
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
235 /* if (!l) { */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
236 /* 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
237 /* return; */
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
240 /* latency = pa_stream_get_latency(s, l, &negative); */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
241
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
242 /* /\* Nor really required *\/ */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
243 /* if (negative) */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
244 /* latency = 0; */
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
247 /** Return the current latency in seconds */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
248 static float get_delay(void) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
249 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
250 pa_usec_t latency;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
251
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
252 /* latency = 0; */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
253 /* 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
254 /* 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
255
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
256 latency = pa_stream_get_interpolated_latency(stream, NULL);
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
257
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
258 return (float) latency/1000000;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
261 /** A temporary variable to store the current volume */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
262 static pa_volume_t volume = PA_VOLUME_NORM;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
263
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
264 /** A callback function that is called when the
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
265 * 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
266 * 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
267 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
268 if (is_last < 0) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
269 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
270 return;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
273 if (!i)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
274 return;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
275
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
276 volume = i->volume;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
279 /** Issue special libao controls on the device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
280 static int control(int cmd, void *arg) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
281
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
282 if (!context || !stream)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
283 return CONTROL_ERROR;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
284
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
285 switch (cmd) {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
286
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
287 case AOCONTROL_SET_DEVICE:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
288 /* Change the playback device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
289 sink = (char*)arg;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
290 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
291
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
292 case AOCONTROL_GET_DEVICE:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
293 /* Return the playback device */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
294 *(char**)arg = sink;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
295 return CONTROL_OK;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
296
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
297 case AOCONTROL_GET_VOLUME: {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
298 /* Return the current volume of the playback stream */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
299 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
300
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
301 volume = PA_VOLUME_NORM;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
302 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
303 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
304 return CONTROL_OK;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
307 case AOCONTROL_SET_VOLUME: {
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
308 /* Set the playback volume of the stream */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
309 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
310 int v = vol->left;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
311 if (vol->right > v)
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
312 v = vol->left;
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
313
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
314 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
315
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
316 return CONTROL_OK;
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
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
319 default:
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
320 /* Unknown CONTROL command */
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
321 return CONTROL_UNKNOWN;
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 }
66637fa67531 polyaudio audio driver patch by Lennart Poettering <mzzcynlre at 0pointer.de>
faust3
parents:
diff changeset
324