3 |
Sound Channel Process Functions - Sun |
Sound Channel Process Functions - Sun |
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 2003 |
Copyright (C) Michael Gernoth mike@zerfleddert.de 2003-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 <unistd.h> |
#include <unistd.h> |
26 |
#include <fcntl.h> |
#include <fcntl.h> |
27 |
#include <errno.h> |
#include <errno.h> |
32 |
#include <stropts.h> |
#include <stropts.h> |
33 |
#endif |
#endif |
34 |
|
|
35 |
#define MAX_QUEUE 10 |
#define DEFAULTDEVICE "/dev/audio" |
36 |
|
|
|
int g_dsp_fd; |
|
|
BOOL g_dsp_busy = False; |
|
37 |
static BOOL g_reopened; |
static BOOL g_reopened; |
|
static BOOL g_swapaudio; |
|
38 |
static short g_samplewidth; |
static short g_samplewidth; |
39 |
|
static char *dsp_dev; |
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
40 |
|
|
41 |
BOOL |
BOOL |
42 |
wave_out_open(void) |
sun_open(void) |
43 |
{ |
{ |
|
char *dsp_dev = getenv("AUDIODEV"); |
|
|
|
|
|
if (dsp_dev == NULL) |
|
|
{ |
|
|
dsp_dev = xstrdup("/dev/audio"); |
|
|
} |
|
|
|
|
44 |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) |
45 |
{ |
{ |
46 |
perror(dsp_dev); |
perror(dsp_dev); |
50 |
/* Non-blocking so that user interface is responsive */ |
/* Non-blocking so that user interface is responsive */ |
51 |
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK); |
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK); |
52 |
|
|
|
queue_lo = queue_hi = 0; |
|
53 |
g_reopened = True; |
g_reopened = True; |
54 |
|
|
55 |
return True; |
return True; |
56 |
} |
} |
57 |
|
|
58 |
void |
void |
59 |
wave_out_close(void) |
sun_close(void) |
60 |
{ |
{ |
61 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
62 |
while (queue_lo != queue_hi) |
while (!rdpsnd_queue_empty()) |
63 |
{ |
rdpsnd_queue_next(0); |
|
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
|
|
free(packet_queue[queue_lo].s.data); |
|
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
|
} |
|
64 |
|
|
65 |
#if defined I_FLUSH && defined FLUSHW |
#if defined I_FLUSH && defined FLUSHW |
66 |
/* Flush the audiobuffer */ |
/* Flush the audiobuffer */ |
73 |
} |
} |
74 |
|
|
75 |
BOOL |
BOOL |
76 |
wave_out_format_supported(WAVEFORMATEX * pwfx) |
sun_format_supported(WAVEFORMATEX * pwfx) |
77 |
{ |
{ |
78 |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
if (pwfx->wFormatTag != WAVE_FORMAT_PCM) |
79 |
return False; |
return False; |
86 |
} |
} |
87 |
|
|
88 |
BOOL |
BOOL |
89 |
wave_out_set_format(WAVEFORMATEX * pwfx) |
sun_set_format(WAVEFORMATEX * pwfx) |
90 |
{ |
{ |
91 |
audio_info_t info; |
audio_info_t info; |
92 |
|
|
93 |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
ioctl(g_dsp_fd, AUDIO_DRAIN, 0); |
|
g_swapaudio = False; |
|
94 |
AUDIO_INITINFO(&info); |
AUDIO_INITINFO(&info); |
95 |
|
|
96 |
|
|
101 |
else if (pwfx->wBitsPerSample == 16) |
else if (pwfx->wBitsPerSample == 16) |
102 |
{ |
{ |
103 |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
info.play.encoding = AUDIO_ENCODING_LINEAR; |
|
/* Do we need to swap the 16bit values? (Are we BigEndian) */ |
|
|
#ifdef B_ENDIAN |
|
|
g_swapaudio = 1; |
|
|
#else |
|
|
g_swapaudio = 0; |
|
|
#endif |
|
104 |
} |
} |
105 |
|
|
106 |
g_samplewidth = pwfx->wBitsPerSample / 8; |
g_samplewidth = pwfx->wBitsPerSample / 8; |
133 |
} |
} |
134 |
|
|
135 |
void |
void |
136 |
wave_out_volume(uint16 left, uint16 right) |
sun_volume(uint16 left, uint16 right) |
137 |
{ |
{ |
138 |
audio_info_t info; |
audio_info_t info; |
139 |
uint balance; |
uint balance; |
165 |
} |
} |
166 |
|
|
167 |
void |
void |
168 |
wave_out_write(STREAM s, uint16 tick, uint8 index) |
sun_play(void) |
|
{ |
|
|
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) |
|
169 |
{ |
{ |
170 |
struct audio_packet *packet; |
struct audio_packet *packet; |
171 |
audio_info_t info; |
audio_info_t info; |
172 |
ssize_t len; |
ssize_t len; |
173 |
unsigned int i; |
unsigned int i; |
|
uint8 swap; |
|
174 |
STREAM out; |
STREAM out; |
|
static BOOL swapped = False; |
|
175 |
static BOOL sentcompletion = True; |
static BOOL sentcompletion = True; |
176 |
static uint32 samplecnt = 0; |
static uint32 samplecnt = 0; |
177 |
static uint32 numsamples; |
static uint32 numsamples; |
182 |
{ |
{ |
183 |
/* Device was just (re)openend */ |
/* Device was just (re)openend */ |
184 |
samplecnt = 0; |
samplecnt = 0; |
|
swapped = False; |
|
185 |
sentcompletion = True; |
sentcompletion = True; |
186 |
g_reopened = False; |
g_reopened = False; |
187 |
} |
} |
188 |
|
|
189 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
190 |
{ |
{ |
191 |
g_dsp_busy = 0; |
g_dsp_busy = 0; |
192 |
return; |
return; |
193 |
} |
} |
194 |
|
|
195 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
196 |
out = &packet->s; |
out = &packet->s; |
197 |
|
|
|
/* Swap the current packet, but only once */ |
|
|
if (g_swapaudio && !swapped) |
|
|
{ |
|
|
for (i = 0; i < out->end - out->p; i += 2) |
|
|
{ |
|
|
swap = *(out->p + i); |
|
|
*(out->p + i) = *(out->p + i + 1); |
|
|
*(out->p + i + 1) = swap; |
|
|
} |
|
|
swapped = True; |
|
|
} |
|
|
|
|
198 |
if (sentcompletion) |
if (sentcompletion) |
199 |
{ |
{ |
200 |
sentcompletion = False; |
sentcompletion = False; |
228 |
if (info.play.samples >= samplecnt + ((numsamples * 7) / 10)) |
if (info.play.samples >= samplecnt + ((numsamples * 7) / 10)) |
229 |
{ |
{ |
230 |
samplecnt += numsamples; |
samplecnt += numsamples; |
231 |
rdpsnd_send_completion(packet->tick, packet->index); |
/* We need to add 50 to tell windows that time has passed while |
232 |
free(out->data); |
* playing this packet */ |
233 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_queue_next(50); |
|
swapped = False; |
|
234 |
sentcompletion = True; |
sentcompletion = True; |
235 |
} |
} |
236 |
else |
else |
241 |
} |
} |
242 |
} |
} |
243 |
} |
} |
244 |
|
|
245 |
|
static struct audio_driver sun_driver = { |
246 |
|
.name = "sun", |
247 |
|
.description = "SUN/BSD output driver, default device: " DEFAULTDEVICE " or $AUDIODEV", |
248 |
|
|
249 |
|
.wave_out_open = sun_open, |
250 |
|
.wave_out_close = sun_close, |
251 |
|
.wave_out_format_supported = sun_format_supported, |
252 |
|
.wave_out_set_format = sun_set_format, |
253 |
|
.wave_out_volume = sun_volume, |
254 |
|
.wave_out_play = sun_play, |
255 |
|
|
256 |
|
.need_byteswap_on_be = 1, |
257 |
|
.need_resampling = 0, |
258 |
|
}; |
259 |
|
|
260 |
|
struct audio_driver * |
261 |
|
sun_register(char *options) |
262 |
|
{ |
263 |
|
if (options) |
264 |
|
{ |
265 |
|
dsp_dev = xstrdup(options); |
266 |
|
} |
267 |
|
else |
268 |
|
{ |
269 |
|
dsp_dev = getenv("AUDIODEV"); |
270 |
|
|
271 |
|
if (dsp_dev == NULL) |
272 |
|
{ |
273 |
|
dsp_dev = xstrdup(DEFAULTDEVICE); |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
|
return &sun_driver; |
278 |
|
} |