32 |
#define DEFAULTDEVICE "default" |
#define DEFAULTDEVICE "default" |
33 |
#define MAX_FRAMES 32 |
#define MAX_FRAMES 32 |
34 |
|
|
35 |
|
static struct pollfd pfds[32]; |
36 |
|
static int num_fds; |
37 |
|
|
38 |
static snd_pcm_t *pcm_handle = NULL; |
static snd_pcm_t *pcm_handle = NULL; |
39 |
static snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK; |
static snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK; |
40 |
static BOOL reopened; |
static BOOL reopened; |
43 |
static unsigned int rate; |
static unsigned int rate; |
44 |
static char *pcm_name; |
static char *pcm_name; |
45 |
|
|
46 |
|
void alsa_play(void); |
47 |
|
|
48 |
|
void |
49 |
|
alsa_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv) |
50 |
|
{ |
51 |
|
int err; |
52 |
|
struct pollfd *f; |
53 |
|
|
54 |
|
if (!pcm_handle) |
55 |
|
return; |
56 |
|
|
57 |
|
if (rdpsnd_queue_empty()) |
58 |
|
return; |
59 |
|
|
60 |
|
num_fds = snd_pcm_poll_descriptors_count(pcm_handle); |
61 |
|
|
62 |
|
if (num_fds > sizeof(pfds) / sizeof(*pfds)) |
63 |
|
return; |
64 |
|
|
65 |
|
err = snd_pcm_poll_descriptors(pcm_handle, pfds, num_fds); |
66 |
|
if (err < 0) |
67 |
|
return; |
68 |
|
|
69 |
|
for (f = pfds; f < &pfds[num_fds]; f++) |
70 |
|
{ |
71 |
|
if (f->events & POLLIN) |
72 |
|
FD_SET(f->fd, rfds); |
73 |
|
if (f->events & POLLOUT) |
74 |
|
FD_SET(f->fd, wfds); |
75 |
|
if (f->fd > *n && (f->events & (POLLIN | POLLOUT))) |
76 |
|
*n = f->fd; |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
|
void |
81 |
|
alsa_check_fds(fd_set * rfds, fd_set * wfds) |
82 |
|
{ |
83 |
|
struct pollfd *f; |
84 |
|
int err; |
85 |
|
unsigned short revents; |
86 |
|
|
87 |
|
if (!pcm_handle) |
88 |
|
return; |
89 |
|
|
90 |
|
for (f = pfds; f < &pfds[num_fds]; f++) |
91 |
|
{ |
92 |
|
f->revents = 0; |
93 |
|
if (f->fd != -1) |
94 |
|
{ |
95 |
|
/* Fixme: This doesn't properly deal with things like POLLHUP */ |
96 |
|
if (FD_ISSET(f->fd, rfds)) |
97 |
|
f->revents |= POLLIN; |
98 |
|
if (FD_ISSET(f->fd, wfds)) |
99 |
|
f->revents |= POLLOUT; |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
err = snd_pcm_poll_descriptors_revents(pcm_handle, pfds, num_fds, &revents); |
104 |
|
if (err < 0) |
105 |
|
return; |
106 |
|
|
107 |
|
if (revents & POLLOUT) |
108 |
|
alsa_play(); |
109 |
|
} |
110 |
|
|
111 |
BOOL |
BOOL |
112 |
alsa_open(void) |
alsa_open(void) |
113 |
{ |
{ |
119 |
return False; |
return False; |
120 |
} |
} |
121 |
|
|
|
g_dsp_fd = 0; |
|
|
|
|
122 |
reopened = True; |
reopened = True; |
123 |
|
|
124 |
return True; |
return True; |
287 |
prev_us = tv.tv_usec; |
prev_us = tv.tv_usec; |
288 |
} |
} |
289 |
|
|
290 |
|
/* We shouldn't be called if the queue is empty, but still */ |
291 |
if (rdpsnd_queue_empty()) |
if (rdpsnd_queue_empty()) |
|
{ |
|
|
g_dsp_busy = 0; |
|
292 |
return; |
return; |
|
} |
|
293 |
|
|
294 |
packet = rdpsnd_queue_current_packet(); |
packet = rdpsnd_queue_current_packet(); |
295 |
out = &packet->s; |
out = &packet->s; |
335 |
|
|
336 |
rdpsnd_queue_next(delay_us); |
rdpsnd_queue_next(delay_us); |
337 |
} |
} |
|
|
|
|
g_dsp_busy = 1; |
|
|
return; |
|
338 |
} |
} |
339 |
|
|
340 |
static struct audio_driver alsa_driver = { |
static struct audio_driver alsa_driver = { |
341 |
.name = "alsa", |
.name = "alsa", |
342 |
.description = "ALSA output driver, default device: " DEFAULTDEVICE, |
.description = "ALSA output driver, default device: " DEFAULTDEVICE, |
343 |
|
|
344 |
|
.add_fds = alsa_add_fds, |
345 |
|
.check_fds = alsa_check_fds, |
346 |
|
|
347 |
.wave_out_open = alsa_open, |
.wave_out_open = alsa_open, |
348 |
.wave_out_close = alsa_close, |
.wave_out_close = alsa_close, |
349 |
.wave_out_format_supported = alsa_format_supported, |
.wave_out_format_supported = alsa_format_supported, |
350 |
.wave_out_set_format = alsa_set_format, |
.wave_out_set_format = alsa_set_format, |
351 |
.wave_out_volume = rdpsnd_dsp_softvol_set, |
.wave_out_volume = rdpsnd_dsp_softvol_set, |
|
.wave_out_play = alsa_play, |
|
352 |
|
|
353 |
.need_byteswap_on_be = 0, |
.need_byteswap_on_be = 0, |
354 |
.need_resampling = 0, |
.need_resampling = 0, |