fix for oss-driver (too fast acks)

some g_ prefixes for globals


git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@509 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2003-10-23 11:11:31 +00:00
parent a1b061098d
commit aa78fcc1b4
2 changed files with 61 additions and 20 deletions

View File

@ -23,6 +23,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
@ -30,6 +31,8 @@
int g_dsp_fd;
BOOL g_dsp_busy = False;
static int g_snd_rate;
static short g_samplewidth;
static struct audio_packet
{
@ -77,7 +80,7 @@ wave_out_format_supported(WAVEFORMATEX * pwfx)
BOOL
wave_out_set_format(WAVEFORMATEX * pwfx)
{
int speed, channels, format;
int channels, format;
ioctl(g_dsp_fd, SNDCTL_DSP_RESET, NULL);
ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL);
@ -87,6 +90,8 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
else if (pwfx->wBitsPerSample == 16)
format = AFMT_S16_LE;
g_samplewidth = pwfx->wBitsPerSample / 8;
if (ioctl(g_dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1)
{
perror("SNDCTL_DSP_SETFMT");
@ -102,8 +107,13 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
return False;
}
speed = pwfx->nSamplesPerSec;
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &speed) == -1)
if (channels == 2)
{
g_samplewidth *= 2;
}
g_snd_rate = pwfx->nSamplesPerSec;
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &g_snd_rate) == -1)
{
perror("SNDCTL_DSP_SPEED");
close(g_dsp_fd);
@ -180,6 +190,10 @@ wave_out_play(void)
struct audio_packet *packet;
ssize_t len;
STREAM out;
static long startedat_us;
static long startedat_s;
static BOOL started = False;
struct timeval tv;
while (1)
{
@ -192,6 +206,14 @@ wave_out_play(void)
packet = &packet_queue[queue_lo];
out = &packet->s;
if (!started)
{
gettimeofday(&tv, NULL);
startedat_us = tv.tv_usec;
startedat_s = tv.tv_sec;
started = True;
}
len = write(g_dsp_fd, out->p, out->end - out->p);
if (len == -1)
{
@ -203,11 +225,30 @@ wave_out_play(void)
out->p += len;
if (out->p == out->end)
{
long long duration;
long elapsed;
gettimeofday(&tv, NULL);
duration =
(out->size * (1000000 /
(g_samplewidth * g_snd_rate)));
elapsed =
(tv.tv_sec - startedat_s) * 1000000 +
(tv.tv_usec - startedat_us);
if ( elapsed >= (duration * 7) / 10 )
{
rdpsnd_send_completion(packet->tick, packet->index);
free(out->data);
queue_lo = (queue_lo + 1) % MAX_QUEUE;
started = False;
}
else
{
g_dsp_busy = 1;
return;
}
}
}
}

View File

@ -32,9 +32,9 @@
int g_dsp_fd;
BOOL g_dsp_busy = False;
static BOOL reopened;
static BOOL swapaudio;
static short samplewidth;
static BOOL g_reopened;
static BOOL g_swapaudio;
static short g_samplewidth;
static struct audio_packet
{
@ -64,7 +64,7 @@ wave_out_open(void)
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK);
queue_lo = queue_hi = 0;
reopened = True;
g_reopened = True;
return True;
}
@ -105,7 +105,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
int test = 1;
ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
swapaudio = False;
g_swapaudio = False;
AUDIO_INITINFO(&info);
@ -117,10 +117,10 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
{
info.play.encoding = AUDIO_ENCODING_LINEAR;
/* Do we need to swap the 16bit values? (Are we BigEndian) */
swapaudio = !(*(uint8 *) (&test));
g_swapaudio = !(*(uint8 *) (&test));
}
samplewidth = pwfx->wBitsPerSample / 8;
g_samplewidth = pwfx->wBitsPerSample / 8;
if (pwfx->nChannels == 1)
{
@ -129,7 +129,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
else if (pwfx->nChannels == 2)
{
info.play.channels = AUDIO_CHANNELS_STEREO;
samplewidth *= 2;
g_samplewidth *= 2;
}
info.play.sample_rate = pwfx->nSamplesPerSec;
@ -137,7 +137,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
info.play.samples = 0;
info.play.eof = 0;
info.play.error = 0;
reopened = True;
g_reopened = True;
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
{
@ -227,13 +227,13 @@ wave_out_play(void)
while (1)
{
if (reopened)
if (g_reopened)
{
/* Device was just (re)openend */
samplecnt = 0;
swapped = False;
sentcompletion = True;
reopened = False;
g_reopened = False;
}
if (queue_lo == queue_hi)
@ -246,7 +246,7 @@ wave_out_play(void)
out = &packet->s;
/* Swap the current packet, but only once */
if (swapaudio && !swapped)
if (g_swapaudio && !swapped)
{
for (i = 0; i < out->end - out->p; i += 2)
{
@ -260,7 +260,7 @@ wave_out_play(void)
if (sentcompletion)
{
sentcompletion = False;
numsamples = (out->end - out->p) / samplewidth;
numsamples = (out->end - out->p) / g_samplewidth;
}
len = 0;