29 |
#include <ao/ao.h> |
#include <ao/ao.h> |
30 |
#include <sys/time.h> |
#include <sys/time.h> |
31 |
|
|
32 |
#define WAVEOUTLEN 1024 |
#define WAVEOUTLEN 16 |
33 |
|
|
34 |
static ao_device *o_device = NULL; |
static ao_device *o_device = NULL; |
35 |
static int default_driver; |
static int default_driver; |
36 |
static BOOL reopened; |
static BOOL reopened; |
37 |
static char *libao_device = NULL; |
static char *libao_device = NULL; |
38 |
|
|
39 |
|
void libao_play(void); |
40 |
|
|
41 |
|
void |
42 |
|
libao_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv) |
43 |
|
{ |
44 |
|
/* We need to be called rather often... */ |
45 |
|
FD_SET(0, wfds); |
46 |
|
} |
47 |
|
|
48 |
|
void |
49 |
|
libao_check_fds(fd_set * rfds, fd_set * wfds) |
50 |
|
{ |
51 |
|
if (o_device == NULL) |
52 |
|
return; |
53 |
|
|
54 |
|
if (!rdpsnd_queue_empty()) |
55 |
|
libao_play(); |
56 |
|
} |
57 |
|
|
58 |
BOOL |
BOOL |
59 |
libao_open(void) |
libao_open(void) |
60 |
{ |
{ |
83 |
return False; |
return False; |
84 |
} |
} |
85 |
|
|
|
g_dsp_fd = 0; |
|
|
rdpsnd_queue_init(); |
|
|
|
|
86 |
reopened = True; |
reopened = True; |
87 |
|
|
88 |
return True; |
return True; |
94 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
95 |
while (!rdpsnd_queue_empty()) |
while (!rdpsnd_queue_empty()) |
96 |
{ |
{ |
97 |
rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick, |
rdpsnd_queue_next(0); |
|
rdpsnd_queue_current_packet()->index); |
|
|
rdpsnd_queue_next(); |
|
98 |
} |
} |
99 |
|
|
100 |
if (o_device != NULL) |
if (o_device != NULL) |
101 |
ao_close(o_device); |
ao_close(o_device); |
102 |
|
|
103 |
|
o_device = NULL; |
104 |
|
|
105 |
ao_shutdown(); |
ao_shutdown(); |
106 |
} |
} |
107 |
|
|
153 |
prev_us = tv.tv_usec; |
prev_us = tv.tv_usec; |
154 |
} |
} |
155 |
|
|
156 |
|
/* We shouldn't be called if the queue is empty, but still */ |
157 |
if (rdpsnd_queue_empty()) |
if (rdpsnd_queue_empty()) |
|
{ |
|
|
g_dsp_busy = 0; |
|
158 |
return; |
return; |
|
} |
|
159 |
|
|
160 |
packet = rdpsnd_queue_current_packet(); |
packet = rdpsnd_queue_current_packet(); |
161 |
out = &packet->s; |
out = &packet->s; |
175 |
|
|
176 |
if ((out->p == out->end) || duration > next_tick - packet->tick + 500) |
if ((out->p == out->end) || duration > next_tick - packet->tick + 500) |
177 |
{ |
{ |
178 |
|
unsigned int delay_us; |
179 |
|
|
180 |
prev_s = tv.tv_sec; |
prev_s = tv.tv_sec; |
181 |
prev_us = tv.tv_usec; |
prev_us = tv.tv_usec; |
182 |
|
|
187 |
(packet->tick + duration) % 65536, next_tick % 65536)); |
(packet->tick + duration) % 65536, next_tick % 65536)); |
188 |
} |
} |
189 |
|
|
190 |
rdpsnd_send_completion(((packet->tick + duration) % 65536), packet->index); |
delay_us = ((out->size/4) * (1000000 / 44100)); |
|
rdpsnd_queue_next(); |
|
|
} |
|
191 |
|
|
192 |
g_dsp_busy = 1; |
rdpsnd_queue_next(delay_us); |
193 |
return; |
} |
194 |
} |
} |
195 |
|
|
196 |
struct audio_driver * |
struct audio_driver * |
197 |
libao_register(char *options) |
libao_register(char *options) |
198 |
{ |
{ |
199 |
static struct audio_driver libao_driver; |
static struct audio_driver libao_driver; |
|
struct ao_info *libao_info; |
|
|
static char description[101]; |
|
200 |
|
|
201 |
libao_driver.wave_out_write = rdpsnd_queue_write; |
libao_driver.name = xstrdup("libao"); |
202 |
|
libao_driver.description = xstrdup("libao output driver, default device: system dependent"); |
203 |
|
|
204 |
|
libao_driver.add_fds = libao_add_fds; |
205 |
|
libao_driver.check_fds = libao_check_fds; |
206 |
|
|
207 |
libao_driver.wave_out_open = libao_open; |
libao_driver.wave_out_open = libao_open; |
208 |
libao_driver.wave_out_close = libao_close; |
libao_driver.wave_out_close = libao_close; |
209 |
libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported; |
libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported; |
210 |
libao_driver.wave_out_set_format = libao_set_format; |
libao_driver.wave_out_set_format = libao_set_format; |
211 |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
212 |
libao_driver.wave_out_play = libao_play; |
|
|
libao_driver.name = xstrdup("libao"); |
|
|
libao_driver.description = description; |
|
213 |
libao_driver.need_byteswap_on_be = 1; |
libao_driver.need_byteswap_on_be = 1; |
214 |
libao_driver.need_resampling = 1; |
libao_driver.need_resampling = 1; |
|
libao_driver.next = NULL; |
|
|
|
|
|
ao_initialize(); |
|
|
|
|
|
libao_info = ao_driver_info(ao_default_driver_id()); |
|
|
|
|
|
if (libao_info) |
|
|
{ |
|
|
snprintf(description, 100, "libao output driver, default device: %s", |
|
|
libao_info->short_name); |
|
|
} |
|
|
else |
|
|
{ |
|
|
snprintf(description, 100, "libao output driver, default device: none"); |
|
|
} |
|
|
|
|
|
ao_shutdown(); |
|
215 |
|
|
216 |
if (options) |
if (options) |
217 |
{ |
{ |