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; |
38 |
static BOOL g_swapaudio; |
static BOOL g_swapaudio; |
39 |
static short g_samplewidth; |
static short g_samplewidth; |
40 |
|
|
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
|
|
|
41 |
BOOL |
BOOL |
42 |
wave_out_open(void) |
wave_out_open(void) |
43 |
{ |
{ |
45 |
|
|
46 |
if (dsp_dev == NULL) |
if (dsp_dev == NULL) |
47 |
{ |
{ |
48 |
dsp_dev = xstrdup("/dev/audio"); |
dsp_dev = xstrdup(DEFAULTDEVICE); |
49 |
} |
} |
50 |
|
|
51 |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) |
57 |
/* Non-blocking so that user interface is responsive */ |
/* Non-blocking so that user interface is responsive */ |
58 |
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); |
59 |
|
|
60 |
queue_lo = queue_hi = 0; |
rdpsnd_queue_init(); |
61 |
g_reopened = True; |
g_reopened = True; |
62 |
|
|
63 |
return True; |
return True; |
67 |
wave_out_close(void) |
wave_out_close(void) |
68 |
{ |
{ |
69 |
/* Ack all remaining packets */ |
/* Ack all remaining packets */ |
70 |
while (queue_lo != queue_hi) |
while (!rdpsnd_queue_empty()) |
71 |
{ |
{ |
72 |
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); |
rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick, |
73 |
free(packet_queue[queue_lo].s.data); |
rdpsnd_queue_current_packet()->index); |
74 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_queue_next(); |
75 |
} |
} |
76 |
|
|
77 |
#if defined I_FLUSH && defined FLUSHW |
#if defined I_FLUSH && defined FLUSHW |
184 |
} |
} |
185 |
|
|
186 |
void |
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 |
|
187 |
wave_out_play(void) |
wave_out_play(void) |
188 |
{ |
{ |
189 |
struct audio_packet *packet; |
struct audio_packet *packet; |
208 |
g_reopened = False; |
g_reopened = False; |
209 |
} |
} |
210 |
|
|
211 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
212 |
{ |
{ |
213 |
g_dsp_busy = 0; |
g_dsp_busy = 0; |
214 |
return; |
return; |
215 |
} |
} |
216 |
|
|
217 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
218 |
out = &packet->s; |
out = &packet->s; |
219 |
|
|
220 |
/* Swap the current packet, but only once */ |
/* Swap the current packet, but only once */ |
262 |
if (info.play.samples >= samplecnt + ((numsamples * 7) / 10)) |
if (info.play.samples >= samplecnt + ((numsamples * 7) / 10)) |
263 |
{ |
{ |
264 |
samplecnt += numsamples; |
samplecnt += numsamples; |
265 |
rdpsnd_send_completion(packet->tick, packet->index); |
/* We need to add 50 to tell windows that time has passed while |
266 |
free(out->data); |
* playing this packet */ |
267 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_send_completion(packet->tick + 50, packet->index); |
268 |
|
rdpsnd_queue_next(); |
269 |
swapped = False; |
swapped = False; |
270 |
sentcompletion = True; |
sentcompletion = True; |
271 |
} |
} |