3 |
Sound Channel Process Functions - libao-driver |
Sound Channel Process Functions - libao-driver |
4 |
Copyright (C) Matthew Chapman 2003 |
Copyright (C) Matthew Chapman 2003 |
5 |
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003 |
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003 |
6 |
Copyright (C) Michael Gernoth mike@zerfleddert.de 2005 |
Copyright (C) Michael Gernoth mike@zerfleddert.de 2005-2006 |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
21 |
*/ |
*/ |
22 |
|
|
23 |
#include "rdesktop.h" |
#include "rdesktop.h" |
24 |
|
#include "rdpsnd.h" |
25 |
|
#include "rdpsnd_dsp.h" |
26 |
#include <unistd.h> |
#include <unistd.h> |
27 |
#include <fcntl.h> |
#include <fcntl.h> |
28 |
#include <errno.h> |
#include <errno.h> |
29 |
#include <ao/ao.h> |
#include <ao/ao.h> |
30 |
#include <sys/time.h> |
#include <sys/time.h> |
31 |
|
|
|
#define MAX_QUEUE 10 |
|
32 |
#define WAVEOUTBUF 16 |
#define WAVEOUTBUF 16 |
33 |
|
|
|
int g_dsp_fd; |
|
|
BOOL g_dsp_busy = False; |
|
34 |
static ao_device *o_device = NULL; |
static ao_device *o_device = NULL; |
35 |
static int default_driver; |
static int default_driver; |
36 |
static int samplerate; |
static int samplerate; |
37 |
static int audiochannels; |
static int audiochannels; |
38 |
static BOOL reopened; |
static BOOL reopened; |
39 |
static short samplewidth; |
static short samplewidth; |
40 |
|
static char *libao_device = NULL; |
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
41 |
|
|
42 |
BOOL |
BOOL |
43 |
wave_out_open(void) |
libao_open(void) |
44 |
{ |
{ |
45 |
ao_sample_format format; |
ao_sample_format format; |
46 |
|
|
47 |
ao_initialize(); |
ao_initialize(); |
48 |
default_driver = ao_default_driver_id(); |
|
49 |
|
if (libao_device) |
50 |
|
{ |
51 |
|
default_driver = ao_driver_id(libao_device); |
52 |
|
} |
53 |
|
else |
54 |
|
{ |
55 |
|
default_driver = ao_default_driver_id(); |
56 |
|
} |
57 |
|
|
58 |
format.bits = 16; |
format.bits = 16; |
59 |
format.channels = 2; |
format.channels = 2; |
69 |
} |
} |
70 |
|
|
71 |
g_dsp_fd = 0; |
g_dsp_fd = 0; |
72 |
queue_lo = queue_hi = 0; |
rdpsnd_queue_init(); |
73 |
|
|
74 |
reopened = True; |
reopened = True; |
75 |
|
|
77 |
} |
} |
78 |
|
|
79 |
void |
void |
80 |
wave_out_close(void) |
libao_close(void) |
81 |
{ |
{ |
82 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
83 |
while (queue_lo != queue_hi) |
while (!rdpsnd_queue_empty()) |
84 |
{ |
{ |
85 |
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick, |
86 |
free(packet_queue[queue_lo].s.data); |
rdpsnd_queue_current_packet()->index); |
87 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_queue_next(); |
88 |
} |
} |
89 |
|
|
90 |
if (o_device != NULL) |
if (o_device != NULL) |
94 |
} |
} |
95 |
|
|
96 |
BOOL |
BOOL |
97 |
wave_out_format_supported(WAVEFORMATEX * pwfx) |
libao_format_supported(WAVEFORMATEX * pwfx) |
98 |
{ |
{ |
99 |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
100 |
return False; |
return False; |
111 |
} |
} |
112 |
|
|
113 |
BOOL |
BOOL |
114 |
wave_out_set_format(WAVEFORMATEX * pwfx) |
libao_set_format(WAVEFORMATEX * pwfx) |
115 |
{ |
{ |
116 |
ao_sample_format format; |
ao_sample_format format; |
117 |
|
|
139 |
} |
} |
140 |
|
|
141 |
void |
void |
142 |
wave_out_volume(uint16 left, uint16 right) |
libao_play(void) |
|
{ |
|
|
warning("volume changes not supported with libao-output\n"); |
|
|
} |
|
|
|
|
|
void |
|
|
wave_out_write(STREAM s, uint16 tick, uint8 index) |
|
|
{ |
|
|
struct audio_packet *packet = &packet_queue[queue_hi]; |
|
|
unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE; |
|
|
|
|
|
if (next_hi == queue_lo) |
|
|
{ |
|
|
error("No space to queue audio packet\n"); |
|
|
return; |
|
|
} |
|
|
|
|
|
queue_hi = next_hi; |
|
|
|
|
|
packet->s = *s; |
|
|
packet->tick = tick; |
|
|
packet->index = index; |
|
|
packet->s.p += 4; |
|
|
|
|
|
/* we steal the data buffer from s, give it a new one */ |
|
|
s->data = malloc(s->size); |
|
|
|
|
|
if (!g_dsp_busy) |
|
|
wave_out_play(); |
|
|
} |
|
|
|
|
|
void |
|
|
wave_out_play(void) |
|
143 |
{ |
{ |
144 |
struct audio_packet *packet; |
struct audio_packet *packet; |
145 |
STREAM out; |
STREAM out; |
158 |
prev_us = tv.tv_usec; |
prev_us = tv.tv_usec; |
159 |
} |
} |
160 |
|
|
161 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
162 |
{ |
{ |
163 |
g_dsp_busy = 0; |
g_dsp_busy = 0; |
164 |
return; |
return; |
165 |
} |
} |
166 |
|
|
167 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
168 |
out = &packet->s; |
out = &packet->s; |
169 |
|
|
170 |
if (((queue_lo + 1) % MAX_QUEUE) != queue_hi) |
next_tick = rdpsnd_queue_next_tick(); |
|
{ |
|
|
next_tick = packet_queue[(queue_lo + 1) % MAX_QUEUE].tick; |
|
|
} |
|
|
else |
|
|
{ |
|
|
next_tick = (packet->tick + 65535) % 65536; |
|
|
} |
|
171 |
|
|
172 |
len = 0; |
len = 0; |
173 |
|
|
222 |
(packet->tick + duration) % 65536, next_tick % 65536)); |
(packet->tick + duration) % 65536, next_tick % 65536)); |
223 |
} |
} |
224 |
|
|
225 |
/* Until all drivers are using the windows sound-ticks, we need to |
rdpsnd_send_completion(((packet->tick + duration) % 65536), packet->index); |
226 |
substract the 50 ticks added later by rdpsnd.c */ |
rdpsnd_queue_next(); |
|
rdpsnd_send_completion(((packet->tick + duration) % 65536) - 50, packet->index); |
|
|
free(out->data); |
|
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
227 |
} |
} |
228 |
|
|
229 |
g_dsp_busy = 1; |
g_dsp_busy = 1; |
230 |
return; |
return; |
231 |
} |
} |
232 |
|
|
233 |
|
struct audio_driver * |
234 |
|
libao_register(char *options) |
235 |
|
{ |
236 |
|
static struct audio_driver libao_driver; |
237 |
|
static char description[101]; |
238 |
|
|
239 |
|
libao_driver.wave_out_write = rdpsnd_queue_write; |
240 |
|
libao_driver.wave_out_open = libao_open; |
241 |
|
libao_driver.wave_out_close = libao_close; |
242 |
|
libao_driver.wave_out_format_supported = libao_format_supported; |
243 |
|
libao_driver.wave_out_set_format = libao_set_format; |
244 |
|
libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set; |
245 |
|
libao_driver.wave_out_play = libao_play; |
246 |
|
libao_driver.name = xstrdup("libao"); |
247 |
|
libao_driver.description = description; |
248 |
|
libao_driver.need_byteswap_on_be = 0; |
249 |
|
libao_driver.next = NULL; |
250 |
|
|
251 |
|
ao_initialize(); |
252 |
|
snprintf(description, 100, "libao output driver, default device: %s", ao_driver_info(ao_default_driver_id())->short_name); |
253 |
|
ao_shutdown(); |
254 |
|
|
255 |
|
if (options) |
256 |
|
{ |
257 |
|
libao_device = xstrdup(options); |
258 |
|
} |
259 |
|
|
260 |
|
return &libao_driver; |
261 |
|
} |