23 |
#include <unistd.h> |
#include <unistd.h> |
24 |
#include <fcntl.h> |
#include <fcntl.h> |
25 |
#include <errno.h> |
#include <errno.h> |
26 |
|
#include <sys/time.h> |
27 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
28 |
#include <sys/soundcard.h> |
#include <sys/soundcard.h> |
29 |
|
|
31 |
|
|
32 |
int g_dsp_fd; |
int g_dsp_fd; |
33 |
BOOL g_dsp_busy = False; |
BOOL g_dsp_busy = False; |
34 |
|
static int g_snd_rate; |
35 |
|
static short g_samplewidth; |
36 |
|
|
37 |
static struct audio_packet |
static struct audio_packet |
38 |
{ |
{ |
80 |
BOOL |
BOOL |
81 |
wave_out_set_format(WAVEFORMATEX * pwfx) |
wave_out_set_format(WAVEFORMATEX * pwfx) |
82 |
{ |
{ |
83 |
int speed, channels, format; |
int channels, format; |
84 |
|
|
85 |
ioctl(g_dsp_fd, SNDCTL_DSP_RESET, NULL); |
ioctl(g_dsp_fd, SNDCTL_DSP_RESET, NULL); |
86 |
ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL); |
ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL); |
90 |
else if (pwfx->wBitsPerSample == 16) |
else if (pwfx->wBitsPerSample == 16) |
91 |
format = AFMT_S16_LE; |
format = AFMT_S16_LE; |
92 |
|
|
93 |
|
g_samplewidth = pwfx->wBitsPerSample / 8; |
94 |
|
|
95 |
if (ioctl(g_dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1) |
if (ioctl(g_dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1) |
96 |
{ |
{ |
97 |
perror("SNDCTL_DSP_SETFMT"); |
perror("SNDCTL_DSP_SETFMT"); |
107 |
return False; |
return False; |
108 |
} |
} |
109 |
|
|
110 |
speed = pwfx->nSamplesPerSec; |
if (channels == 2) |
111 |
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &speed) == -1) |
{ |
112 |
|
g_samplewidth *= 2; |
113 |
|
} |
114 |
|
|
115 |
|
g_snd_rate = pwfx->nSamplesPerSec; |
116 |
|
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &g_snd_rate) == -1) |
117 |
{ |
{ |
118 |
perror("SNDCTL_DSP_SPEED"); |
perror("SNDCTL_DSP_SPEED"); |
119 |
close(g_dsp_fd); |
close(g_dsp_fd); |
135 |
|
|
136 |
if (use_dev_mixer) |
if (use_dev_mixer) |
137 |
{ |
{ |
138 |
if ((fd_mix = open( "/dev/mixer", O_RDWR|O_NONBLOCK )) == -1 ) |
if ((fd_mix = open("/dev/mixer", O_RDWR | O_NONBLOCK)) == -1) |
139 |
{ |
{ |
140 |
perror("open /dev/mixer"); |
perror("open /dev/mixer"); |
141 |
return; |
return; |
190 |
struct audio_packet *packet; |
struct audio_packet *packet; |
191 |
ssize_t len; |
ssize_t len; |
192 |
STREAM out; |
STREAM out; |
193 |
|
static long startedat_us; |
194 |
|
static long startedat_s; |
195 |
|
static BOOL started = False; |
196 |
|
struct timeval tv; |
197 |
|
|
198 |
while (1) |
while (1) |
199 |
{ |
{ |
206 |
packet = &packet_queue[queue_lo]; |
packet = &packet_queue[queue_lo]; |
207 |
out = &packet->s; |
out = &packet->s; |
208 |
|
|
209 |
|
if (!started) |
210 |
|
{ |
211 |
|
gettimeofday(&tv, NULL); |
212 |
|
startedat_us = tv.tv_usec; |
213 |
|
startedat_s = tv.tv_sec; |
214 |
|
started = True; |
215 |
|
} |
216 |
|
|
217 |
len = write(g_dsp_fd, out->p, out->end - out->p); |
len = write(g_dsp_fd, out->p, out->end - out->p); |
218 |
if (len == -1) |
if (len == -1) |
219 |
{ |
{ |
226 |
out->p += len; |
out->p += len; |
227 |
if (out->p == out->end) |
if (out->p == out->end) |
228 |
{ |
{ |
229 |
rdpsnd_send_completion(packet->tick, packet->index); |
long long duration; |
230 |
free(out->data); |
long elapsed; |
231 |
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
|
232 |
|
gettimeofday(&tv, NULL); |
233 |
|
duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate))); |
234 |
|
elapsed = (tv.tv_sec - startedat_s) * 1000000 + (tv.tv_usec - startedat_us); |
235 |
|
|
236 |
|
if (elapsed >= (duration * 7) / 10) |
237 |
|
{ |
238 |
|
rdpsnd_send_completion(packet->tick, packet->index); |
239 |
|
free(out->data); |
240 |
|
queue_lo = (queue_lo + 1) % MAX_QUEUE; |
241 |
|
started = False; |
242 |
|
} |
243 |
|
else |
244 |
|
{ |
245 |
|
g_dsp_busy = 1; |
246 |
|
return; |
247 |
|
} |
248 |
} |
} |
249 |
} |
} |
|
|
|
250 |
} |
} |