28 |
#endif |
#endif |
29 |
|
|
30 |
#include "rdesktop.h" |
#include "rdesktop.h" |
31 |
|
#include "rdpsnd.h" |
32 |
#include <unistd.h> |
#include <unistd.h> |
33 |
#include <fcntl.h> |
#include <fcntl.h> |
34 |
#include <errno.h> |
#include <errno.h> |
36 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
37 |
#include <sys/soundcard.h> |
#include <sys/soundcard.h> |
38 |
|
|
39 |
|
#define DEFAULTDEVICE "/dev/dsp" |
40 |
#define MAX_LEN 512 |
#define MAX_LEN 512 |
|
#define MAX_QUEUE 10 |
|
41 |
|
|
|
int g_dsp_fd; |
|
|
BOOL g_dsp_busy = False; |
|
42 |
static int snd_rate; |
static int snd_rate; |
43 |
static short samplewidth; |
static short samplewidth; |
44 |
|
|
|
static struct audio_packet |
|
|
{ |
|
|
struct stream s; |
|
|
uint16 tick; |
|
|
uint8 index; |
|
|
} packet_queue[MAX_QUEUE]; |
|
|
static unsigned int queue_hi, queue_lo; |
|
|
|
|
45 |
BOOL |
BOOL |
46 |
wave_out_open(void) |
wave_out_open(void) |
47 |
{ |
{ |
49 |
|
|
50 |
if (dsp_dev == NULL) |
if (dsp_dev == NULL) |
51 |
{ |
{ |
52 |
dsp_dev = xstrdup("/dev/dsp"); |
dsp_dev = xstrdup(DEFAULTDEVICE); |
53 |
} |
} |
54 |
|
|
55 |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY)) == -1) |
if ((g_dsp_fd = open(dsp_dev, O_WRONLY)) == -1) |
192 |
} |
} |
193 |
|
|
194 |
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 = (uint8 *) malloc(s->size); |
|
|
|
|
|
if (!g_dsp_busy) |
|
|
wave_out_play(); |
|
|
} |
|
|
|
|
|
void |
|
195 |
wave_out_play(void) |
wave_out_play(void) |
196 |
{ |
{ |
197 |
struct audio_packet *packet; |
struct audio_packet *packet; |
202 |
static BOOL started = False; |
static BOOL started = False; |
203 |
struct timeval tv; |
struct timeval tv; |
204 |
|
|
205 |
if (queue_lo == queue_hi) |
if (rdpsnd_queue_empty()) |
206 |
{ |
{ |
207 |
g_dsp_busy = 0; |
g_dsp_busy = 0; |
208 |
return; |
return; |
209 |
} |
} |
210 |
|
|
211 |
packet = &packet_queue[queue_lo]; |
packet = rdpsnd_queue_current_packet(); |
212 |
out = &packet->s; |
out = &packet->s; |
213 |
|
|
214 |
if (!started) |
if (!started) |
242 |
|
|
243 |
if (elapsed >= (duration * 85) / 100) |
if (elapsed >= (duration * 85) / 100) |
244 |
{ |
{ |
245 |
rdpsnd_send_completion(packet->tick, packet->index); |
/* We need to add 50 to tell windows that time has passed while |
246 |
free(out->data); |
* playing this packet */ |
247 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
rdpsnd_send_completion(packet->tick + 50, packet->index); |
248 |
|
rdpsnd_queue_next(); |
249 |
started = False; |
started = False; |
250 |
} |
} |
251 |
else |
else |