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:
parent
a1b061098d
commit
aa78fcc1b4
49
rdpsnd_oss.c
49
rdpsnd_oss.c
@ -23,6 +23,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
|
|
||||||
@ -30,6 +31,8 @@
|
|||||||
|
|
||||||
int g_dsp_fd;
|
int g_dsp_fd;
|
||||||
BOOL g_dsp_busy = False;
|
BOOL g_dsp_busy = False;
|
||||||
|
static int g_snd_rate;
|
||||||
|
static short g_samplewidth;
|
||||||
|
|
||||||
static struct audio_packet
|
static struct audio_packet
|
||||||
{
|
{
|
||||||
@ -77,7 +80,7 @@ wave_out_format_supported(WAVEFORMATEX * pwfx)
|
|||||||
BOOL
|
BOOL
|
||||||
wave_out_set_format(WAVEFORMATEX * pwfx)
|
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_RESET, NULL);
|
||||||
ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL);
|
ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL);
|
||||||
@ -87,6 +90,8 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
else if (pwfx->wBitsPerSample == 16)
|
else if (pwfx->wBitsPerSample == 16)
|
||||||
format = AFMT_S16_LE;
|
format = AFMT_S16_LE;
|
||||||
|
|
||||||
|
g_samplewidth = pwfx->wBitsPerSample / 8;
|
||||||
|
|
||||||
if (ioctl(g_dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1)
|
if (ioctl(g_dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1)
|
||||||
{
|
{
|
||||||
perror("SNDCTL_DSP_SETFMT");
|
perror("SNDCTL_DSP_SETFMT");
|
||||||
@ -102,8 +107,13 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
speed = pwfx->nSamplesPerSec;
|
if (channels == 2)
|
||||||
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &speed) == -1)
|
{
|
||||||
|
g_samplewidth *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_snd_rate = pwfx->nSamplesPerSec;
|
||||||
|
if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &g_snd_rate) == -1)
|
||||||
{
|
{
|
||||||
perror("SNDCTL_DSP_SPEED");
|
perror("SNDCTL_DSP_SPEED");
|
||||||
close(g_dsp_fd);
|
close(g_dsp_fd);
|
||||||
@ -180,6 +190,10 @@ wave_out_play(void)
|
|||||||
struct audio_packet *packet;
|
struct audio_packet *packet;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
STREAM out;
|
STREAM out;
|
||||||
|
static long startedat_us;
|
||||||
|
static long startedat_s;
|
||||||
|
static BOOL started = False;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -192,6 +206,14 @@ wave_out_play(void)
|
|||||||
packet = &packet_queue[queue_lo];
|
packet = &packet_queue[queue_lo];
|
||||||
out = &packet->s;
|
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);
|
len = write(g_dsp_fd, out->p, out->end - out->p);
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
{
|
{
|
||||||
@ -203,11 +225,30 @@ wave_out_play(void)
|
|||||||
|
|
||||||
out->p += len;
|
out->p += len;
|
||||||
if (out->p == out->end)
|
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);
|
rdpsnd_send_completion(packet->tick, packet->index);
|
||||||
free(out->data);
|
free(out->data);
|
||||||
queue_lo = (queue_lo + 1) % MAX_QUEUE;
|
queue_lo = (queue_lo + 1) % MAX_QUEUE;
|
||||||
|
started = False;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_dsp_busy = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
26
rdpsnd_sun.c
26
rdpsnd_sun.c
@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
int g_dsp_fd;
|
int g_dsp_fd;
|
||||||
BOOL g_dsp_busy = False;
|
BOOL g_dsp_busy = False;
|
||||||
static BOOL reopened;
|
static BOOL g_reopened;
|
||||||
static BOOL swapaudio;
|
static BOOL g_swapaudio;
|
||||||
static short samplewidth;
|
static short g_samplewidth;
|
||||||
|
|
||||||
static struct audio_packet
|
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);
|
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK);
|
||||||
|
|
||||||
queue_lo = queue_hi = 0;
|
queue_lo = queue_hi = 0;
|
||||||
reopened = True;
|
g_reopened = True;
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
int test = 1;
|
int test = 1;
|
||||||
|
|
||||||
ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
|
ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
|
||||||
swapaudio = False;
|
g_swapaudio = False;
|
||||||
AUDIO_INITINFO(&info);
|
AUDIO_INITINFO(&info);
|
||||||
|
|
||||||
|
|
||||||
@ -117,10 +117,10 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
{
|
{
|
||||||
info.play.encoding = AUDIO_ENCODING_LINEAR;
|
info.play.encoding = AUDIO_ENCODING_LINEAR;
|
||||||
/* Do we need to swap the 16bit values? (Are we BigEndian) */
|
/* 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)
|
if (pwfx->nChannels == 1)
|
||||||
{
|
{
|
||||||
@ -129,7 +129,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
else if (pwfx->nChannels == 2)
|
else if (pwfx->nChannels == 2)
|
||||||
{
|
{
|
||||||
info.play.channels = AUDIO_CHANNELS_STEREO;
|
info.play.channels = AUDIO_CHANNELS_STEREO;
|
||||||
samplewidth *= 2;
|
g_samplewidth *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.play.sample_rate = pwfx->nSamplesPerSec;
|
info.play.sample_rate = pwfx->nSamplesPerSec;
|
||||||
@ -137,7 +137,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
|
|||||||
info.play.samples = 0;
|
info.play.samples = 0;
|
||||||
info.play.eof = 0;
|
info.play.eof = 0;
|
||||||
info.play.error = 0;
|
info.play.error = 0;
|
||||||
reopened = True;
|
g_reopened = True;
|
||||||
|
|
||||||
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
|
if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
|
||||||
{
|
{
|
||||||
@ -227,13 +227,13 @@ wave_out_play(void)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (reopened)
|
if (g_reopened)
|
||||||
{
|
{
|
||||||
/* Device was just (re)openend */
|
/* Device was just (re)openend */
|
||||||
samplecnt = 0;
|
samplecnt = 0;
|
||||||
swapped = False;
|
swapped = False;
|
||||||
sentcompletion = True;
|
sentcompletion = True;
|
||||||
reopened = False;
|
g_reopened = False;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue_lo == queue_hi)
|
if (queue_lo == queue_hi)
|
||||||
@ -246,7 +246,7 @@ wave_out_play(void)
|
|||||||
out = &packet->s;
|
out = &packet->s;
|
||||||
|
|
||||||
/* Swap the current packet, but only once */
|
/* Swap the current packet, but only once */
|
||||||
if (swapaudio && !swapped)
|
if (g_swapaudio && !swapped)
|
||||||
{
|
{
|
||||||
for (i = 0; i < out->end - out->p; i += 2)
|
for (i = 0; i < out->end - out->p; i += 2)
|
||||||
{
|
{
|
||||||
@ -260,7 +260,7 @@ wave_out_play(void)
|
|||||||
if (sentcompletion)
|
if (sentcompletion)
|
||||||
{
|
{
|
||||||
sentcompletion = False;
|
sentcompletion = False;
|
||||||
numsamples = (out->end - out->p) / samplewidth;
|
numsamples = (out->end - out->p) / g_samplewidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user