2005-08-03 12:56:16 +02:00
|
|
|
/* -*- c-basic-offset: 8 -*-
|
2003-10-01 14:35:17 +02:00
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
Sound Channel Process Functions - Open Sound System
|
2011-04-13 13:13:04 +02:00
|
|
|
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 2003-2008
|
2011-04-13 13:28:19 +02:00
|
|
|
Copyright (C) GuoJunBo <guojunbo@ict.ac.cn> 2003
|
2008-07-11 05:51:23 +02:00
|
|
|
Copyright 2006-2008 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
2011-04-13 10:55:42 +02:00
|
|
|
Copyright 2005-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2010-01-12 09:31:06 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2003-10-01 14:35:17 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2010-01-12 09:31:06 +01:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
2003-10-01 14:35:17 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2010-01-12 09:31:06 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-01 14:35:17 +02:00
|
|
|
*/
|
|
|
|
|
2006-04-13 09:37:24 +02:00
|
|
|
/*
|
|
|
|
This is a workaround for Esound bug 312665.
|
|
|
|
FIXME: Remove this when Esound is fixed.
|
|
|
|
*/
|
|
|
|
#ifdef _FILE_OFFSET_BITS
|
|
|
|
#undef _FILE_OFFSET_BITS
|
|
|
|
#endif
|
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2003-10-01 14:35:17 +02:00
|
|
|
#include "rdesktop.h"
|
2006-09-17 12:32:18 +02:00
|
|
|
#include "rdpsnd.h"
|
2006-09-18 12:17:24 +02:00
|
|
|
#include "rdpsnd_dsp.h"
|
2003-10-01 14:35:17 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2006-10-26 11:47:17 +02:00
|
|
|
#include <unistd.h>
|
2003-10-23 13:11:31 +02:00
|
|
|
#include <sys/time.h>
|
2003-10-01 14:35:17 +02:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/soundcard.h>
|
2006-10-26 11:47:17 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2006-09-17 12:32:18 +02:00
|
|
|
#define DEFAULTDEVICE "/dev/dsp"
|
2006-07-12 11:57:05 +02:00
|
|
|
#define MAX_LEN 512
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
static int dsp_fd = -1;
|
2007-01-02 17:37:54 +01:00
|
|
|
static int dsp_mode;
|
2006-12-07 16:23:45 +01:00
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL dsp_configured;
|
2007-01-10 10:15:15 +01:00
|
|
|
static RD_BOOL dsp_broken;
|
2007-01-02 17:37:54 +01:00
|
|
|
|
|
|
|
static int stereo;
|
|
|
|
static int format;
|
2007-01-18 06:42:11 +01:00
|
|
|
static uint32 snd_rate;
|
2006-07-12 11:57:05 +02:00
|
|
|
static short samplewidth;
|
2006-09-17 13:04:50 +02:00
|
|
|
static char *dsp_dev;
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL in_esddsp;
|
2006-10-26 11:47:17 +02:00
|
|
|
|
2006-12-07 12:54:29 +01:00
|
|
|
/* This is a just a forward declaration */
|
|
|
|
static struct audio_driver oss_driver;
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void oss_play(void);
|
|
|
|
static void oss_record(void);
|
2008-10-02 20:21:58 +02:00
|
|
|
static RD_BOOL oss_set_format(RD_WAVEFORMATEX * pwfx);
|
2006-12-07 16:23:45 +01:00
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2006-12-07 16:23:45 +01:00
|
|
|
oss_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv)
|
|
|
|
{
|
|
|
|
if (dsp_fd == -1)
|
|
|
|
return;
|
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
if ((dsp_mode == O_WRONLY || dsp_mode == O_RDWR) && !rdpsnd_queue_empty())
|
2007-01-02 17:37:54 +01:00
|
|
|
FD_SET(dsp_fd, wfds);
|
2008-10-02 20:21:58 +02:00
|
|
|
if (dsp_mode == O_RDONLY || dsp_mode == O_RDWR)
|
2007-01-02 17:37:54 +01:00
|
|
|
FD_SET(dsp_fd, rfds);
|
2006-12-07 16:23:45 +01:00
|
|
|
if (dsp_fd > *n)
|
|
|
|
*n = dsp_fd;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2006-12-07 16:23:45 +01:00
|
|
|
oss_check_fds(fd_set * rfds, fd_set * wfds)
|
|
|
|
{
|
|
|
|
if (FD_ISSET(dsp_fd, wfds))
|
|
|
|
oss_play();
|
2007-01-02 17:37:54 +01:00
|
|
|
if (FD_ISSET(dsp_fd, rfds))
|
|
|
|
oss_record();
|
2006-12-07 16:23:45 +01:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL
|
2006-10-26 11:47:17 +02:00
|
|
|
detect_esddsp(void)
|
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
char *preload;
|
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
if (fstat(dsp_fd, &s) == -1)
|
2006-10-26 11:47:17 +02:00
|
|
|
return False;
|
|
|
|
|
|
|
|
if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
preload = getenv("LD_PRELOAD");
|
|
|
|
if (preload == NULL)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
if (strstr(preload, "esddsp") == NULL)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
static void
|
|
|
|
oss_restore_format()
|
|
|
|
{
|
|
|
|
RD_WAVEFORMATEX wfx;
|
|
|
|
memset(&wfx, 0, sizeof(RD_WAVEFORMATEX));
|
|
|
|
switch (format)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2008-10-02 20:21:58 +02:00
|
|
|
case AFMT_U8:
|
|
|
|
wfx.wBitsPerSample = 8;
|
|
|
|
break;
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
wfx.wBitsPerSample = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wfx.wBitsPerSample = 0;
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
2008-10-02 20:21:58 +02:00
|
|
|
wfx.nChannels = stereo ? 2 : 1;
|
|
|
|
wfx.nSamplesPerSec = snd_rate;
|
|
|
|
oss_set_format(&wfx);
|
|
|
|
}
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
static RD_BOOL
|
|
|
|
oss_open(int wanted)
|
|
|
|
{
|
2007-01-02 17:37:54 +01:00
|
|
|
if (dsp_fd != -1)
|
|
|
|
{
|
2008-10-02 20:21:58 +02:00
|
|
|
if (wanted == dsp_mode)
|
2007-01-02 17:37:54 +01:00
|
|
|
{
|
2008-10-02 20:21:58 +02:00
|
|
|
/* should probably not happen */
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* device open but not our mode. Before
|
|
|
|
reopening O_RDWR, verify that the device is
|
|
|
|
duplex capable */
|
|
|
|
int caps;
|
|
|
|
ioctl(dsp_fd, SNDCTL_DSP_SETDUPLEX, 0);
|
|
|
|
if ((ioctl(dsp_fd, SNDCTL_DSP_GETCAPS, &caps) < 0)
|
|
|
|
|| !(caps & DSP_CAP_DUPLEX))
|
|
|
|
{
|
|
|
|
warning("This device is not capable of full duplex operation.\n");
|
|
|
|
return False;
|
|
|
|
}
|
2007-01-02 17:37:54 +01:00
|
|
|
close(dsp_fd);
|
2008-10-02 20:21:58 +02:00
|
|
|
dsp_mode = O_RDWR;
|
2007-01-02 17:37:54 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-02 20:21:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dsp_mode = wanted;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsp_configured = False;
|
|
|
|
dsp_broken = False;
|
|
|
|
|
|
|
|
dsp_fd = open(dsp_dev, dsp_mode | O_NONBLOCK);
|
2007-01-02 17:37:54 +01:00
|
|
|
|
|
|
|
if (dsp_fd == -1)
|
|
|
|
{
|
2008-10-02 20:21:58 +02:00
|
|
|
perror(dsp_dev);
|
|
|
|
return False;
|
2007-01-02 17:37:54 +01:00
|
|
|
}
|
|
|
|
|
2006-10-26 11:47:17 +02:00
|
|
|
in_esddsp = detect_esddsp();
|
|
|
|
|
2003-10-01 14:35:17 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2006-09-17 13:04:50 +02:00
|
|
|
oss_close(void)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2006-12-07 16:23:45 +01:00
|
|
|
close(dsp_fd);
|
|
|
|
dsp_fd = -1;
|
2007-01-02 17:37:54 +01:00
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static RD_BOOL
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_open_out(void)
|
|
|
|
{
|
|
|
|
if (!oss_open(O_WRONLY))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_close_out(void)
|
|
|
|
{
|
|
|
|
oss_close();
|
2008-10-02 20:21:58 +02:00
|
|
|
if (dsp_mode == O_RDWR)
|
|
|
|
{
|
|
|
|
if (oss_open(O_RDONLY))
|
|
|
|
oss_restore_format();
|
|
|
|
}
|
2007-01-02 17:37:54 +01:00
|
|
|
|
|
|
|
/* Ack all remaining packets */
|
|
|
|
while (!rdpsnd_queue_empty())
|
|
|
|
rdpsnd_queue_next(0);
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static RD_BOOL
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_open_in(void)
|
|
|
|
{
|
|
|
|
if (!oss_open(O_RDONLY))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_close_in(void)
|
|
|
|
{
|
|
|
|
oss_close();
|
2008-10-02 20:21:58 +02:00
|
|
|
if (dsp_mode == O_RDWR)
|
|
|
|
{
|
|
|
|
if (oss_open(O_WRONLY))
|
|
|
|
oss_restore_format();
|
|
|
|
}
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static RD_BOOL
|
2007-01-04 05:55:56 +01:00
|
|
|
oss_format_supported(RD_WAVEFORMATEX * pwfx)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
|
|
|
if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
|
|
|
|
return False;
|
|
|
|
if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
|
|
|
|
return False;
|
|
|
|
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static RD_BOOL
|
2007-01-04 05:55:56 +01:00
|
|
|
oss_set_format(RD_WAVEFORMATEX * pwfx)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2007-01-02 17:37:54 +01:00
|
|
|
int fragments;
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL driver_broken = False;
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
assert(dsp_fd != -1);
|
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
if (dsp_configured)
|
|
|
|
{
|
|
|
|
if ((pwfx->wBitsPerSample == 8) && (format != AFMT_U8))
|
|
|
|
return False;
|
|
|
|
if ((pwfx->wBitsPerSample == 16) && (format != AFMT_S16_LE))
|
|
|
|
return False;
|
|
|
|
|
2011-01-03 14:14:50 +01:00
|
|
|
if ((pwfx->nChannels == 2) != ! !stereo)
|
2007-01-02 17:37:54 +01:00
|
|
|
return False;
|
|
|
|
|
|
|
|
if (pwfx->nSamplesPerSec != snd_rate)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
ioctl(dsp_fd, SNDCTL_DSP_RESET, NULL);
|
|
|
|
ioctl(dsp_fd, SNDCTL_DSP_SYNC, NULL);
|
2003-10-01 14:35:17 +02:00
|
|
|
|
|
|
|
if (pwfx->wBitsPerSample == 8)
|
|
|
|
format = AFMT_U8;
|
|
|
|
else if (pwfx->wBitsPerSample == 16)
|
|
|
|
format = AFMT_S16_LE;
|
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
samplewidth = pwfx->wBitsPerSample / 8;
|
2003-10-23 13:11:31 +02:00
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
|
|
|
perror("SNDCTL_DSP_SETFMT");
|
2006-11-02 12:55:59 +01:00
|
|
|
oss_close();
|
2003-10-01 14:35:17 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2004-09-03 20:04:48 +02:00
|
|
|
if (pwfx->nChannels == 2)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2004-09-03 20:04:48 +02:00
|
|
|
stereo = 1;
|
2006-07-12 11:57:05 +02:00
|
|
|
samplewidth *= 2;
|
2004-09-03 20:04:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stereo = 0;
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_STEREO, &stereo) == -1)
|
2003-10-23 13:11:31 +02:00
|
|
|
{
|
2004-09-03 20:04:48 +02:00
|
|
|
perror("SNDCTL_DSP_CHANNELS");
|
2006-11-02 12:55:59 +01:00
|
|
|
oss_close();
|
2004-09-03 20:04:48 +02:00
|
|
|
return False;
|
2003-10-23 13:11:31 +02:00
|
|
|
}
|
|
|
|
|
2006-10-01 20:47:04 +02:00
|
|
|
oss_driver.need_resampling = 0;
|
2006-07-12 11:57:05 +02:00
|
|
|
snd_rate = pwfx->nSamplesPerSec;
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_SPEED, &snd_rate) == -1)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2007-01-18 06:42:11 +01:00
|
|
|
uint32 rates[] = { 44100, 48000, 0 };
|
|
|
|
uint32 *prates = rates;
|
2006-10-01 20:47:04 +02:00
|
|
|
|
|
|
|
while (*prates != 0)
|
|
|
|
{
|
|
|
|
if ((pwfx->nSamplesPerSec != *prates)
|
2006-12-07 16:23:45 +01:00
|
|
|
&& (ioctl(dsp_fd, SNDCTL_DSP_SPEED, prates) != -1))
|
2006-10-01 20:47:04 +02:00
|
|
|
{
|
|
|
|
oss_driver.need_resampling = 1;
|
|
|
|
snd_rate = *prates;
|
|
|
|
if (rdpsnd_dsp_resample_set
|
|
|
|
(snd_rate, pwfx->wBitsPerSample, pwfx->nChannels) == False)
|
|
|
|
{
|
|
|
|
error("rdpsnd_dsp_resample_set failed");
|
2006-11-02 12:55:59 +01:00
|
|
|
oss_close();
|
2006-10-01 20:47:04 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prates++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*prates == 0)
|
|
|
|
{
|
|
|
|
perror("SNDCTL_DSP_SPEED");
|
2006-11-02 12:55:59 +01:00
|
|
|
oss_close();
|
2006-10-01 20:47:04 +02:00
|
|
|
return False;
|
|
|
|
}
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
/* try to get 12 fragments of 2^12 bytes size */
|
|
|
|
fragments = (12 << 16) + 12;
|
2006-12-07 16:23:45 +01:00
|
|
|
ioctl(dsp_fd, SNDCTL_DSP_SETFRAGMENT, &fragments);
|
2004-09-04 00:35:08 +02:00
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
if (!driver_broken)
|
2004-09-04 00:35:08 +02:00
|
|
|
{
|
|
|
|
audio_buf_info info;
|
|
|
|
|
2004-11-23 14:29:12 +01:00
|
|
|
memset(&info, 0, sizeof(info));
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_GETOSPACE, &info) == -1)
|
2004-09-04 00:35:08 +02:00
|
|
|
{
|
|
|
|
perror("SNDCTL_DSP_GETOSPACE");
|
2006-11-02 12:55:59 +01:00
|
|
|
oss_close();
|
2004-09-04 00:35:08 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.fragments == 0 || info.fragstotal == 0 || info.fragsize == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"Broken OSS-driver detected: fragments: %d, fragstotal: %d, fragsize: %d\n",
|
|
|
|
info.fragments, info.fragstotal, info.fragsize);
|
2006-07-12 11:57:05 +02:00
|
|
|
driver_broken = True;
|
2004-09-04 00:35:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
dsp_configured = True;
|
|
|
|
|
2003-10-01 14:35:17 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2006-09-17 13:04:50 +02:00
|
|
|
oss_volume(uint16 left, uint16 right)
|
2003-10-13 18:09:45 +02:00
|
|
|
{
|
|
|
|
uint32 volume;
|
|
|
|
|
2003-10-15 16:01:32 +02:00
|
|
|
volume = left / (65536 / 100);
|
|
|
|
volume |= right / (65536 / 100) << 8;
|
2003-10-22 14:16:03 +02:00
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, MIXER_WRITE(SOUND_MIXER_PCM), &volume) == -1)
|
2003-10-13 18:09:45 +02:00
|
|
|
{
|
2006-10-01 13:08:09 +02:00
|
|
|
warning("hardware volume control unavailable, falling back to software volume control!\n");
|
2006-09-18 12:17:24 +02:00
|
|
|
oss_driver.wave_out_volume = rdpsnd_dsp_softvol_set;
|
2006-10-01 13:08:09 +02:00
|
|
|
rdpsnd_dsp_softvol_set(left, right);
|
2003-10-13 18:09:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2006-09-17 13:04:50 +02:00
|
|
|
oss_play(void)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
|
|
|
struct audio_packet *packet;
|
|
|
|
ssize_t len;
|
|
|
|
STREAM out;
|
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
assert(dsp_fd != -1);
|
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
/* We shouldn't be called if the queue is empty, but still */
|
2006-09-17 12:32:18 +02:00
|
|
|
if (rdpsnd_queue_empty())
|
2006-07-12 11:57:05 +02:00
|
|
|
return;
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2006-09-17 12:32:18 +02:00
|
|
|
packet = rdpsnd_queue_current_packet();
|
2006-07-12 11:57:05 +02:00
|
|
|
out = &packet->s;
|
2003-10-01 14:35:17 +02:00
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
len = out->end - out->p;
|
2004-09-04 00:35:08 +02:00
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
len = write(dsp_fd, out->p, (len > MAX_LEN) ? MAX_LEN : len);
|
2006-07-12 11:57:05 +02:00
|
|
|
if (len == -1)
|
|
|
|
{
|
|
|
|
if (errno != EWOULDBLOCK)
|
2007-01-10 10:15:15 +01:00
|
|
|
{
|
|
|
|
if (!dsp_broken)
|
|
|
|
perror("RDPSND: write()");
|
|
|
|
dsp_broken = True;
|
|
|
|
rdpsnd_queue_next(0);
|
|
|
|
}
|
2006-07-12 11:57:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-10 10:15:15 +01:00
|
|
|
dsp_broken = False;
|
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
out->p += len;
|
2006-10-26 11:47:17 +02:00
|
|
|
|
2006-07-12 11:57:05 +02:00
|
|
|
if (out->p == out->end)
|
|
|
|
{
|
2006-10-26 11:47:17 +02:00
|
|
|
int delay_bytes;
|
|
|
|
unsigned long delay_us;
|
|
|
|
audio_buf_info info;
|
2004-09-04 00:35:08 +02:00
|
|
|
|
2006-10-26 11:47:17 +02:00
|
|
|
if (in_esddsp)
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2006-10-26 11:47:17 +02:00
|
|
|
/* EsounD has no way of querying buffer status, so we have to
|
|
|
|
* go with a fixed size. */
|
|
|
|
delay_bytes = out->size;
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
2006-07-12 11:57:05 +02:00
|
|
|
else
|
2003-10-01 14:35:17 +02:00
|
|
|
{
|
2006-10-26 11:47:17 +02:00
|
|
|
#ifdef SNDCTL_DSP_GETODELAY
|
|
|
|
delay_bytes = 0;
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_GETODELAY, &delay_bytes) == -1)
|
2006-10-26 11:47:17 +02:00
|
|
|
delay_bytes = -1;
|
|
|
|
#else
|
|
|
|
delay_bytes = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (delay_bytes == -1)
|
|
|
|
{
|
2006-12-07 16:23:45 +01:00
|
|
|
if (ioctl(dsp_fd, SNDCTL_DSP_GETOSPACE, &info) != -1)
|
2006-10-26 11:47:17 +02:00
|
|
|
delay_bytes = info.fragstotal * info.fragsize - info.bytes;
|
|
|
|
else
|
|
|
|
delay_bytes = out->size;
|
|
|
|
}
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
2006-10-26 11:47:17 +02:00
|
|
|
|
|
|
|
delay_us = delay_bytes * (1000000 / (samplewidth * snd_rate));
|
|
|
|
rdpsnd_queue_next(delay_us);
|
2003-10-01 14:35:17 +02:00
|
|
|
}
|
|
|
|
}
|
2006-09-17 13:04:50 +02:00
|
|
|
|
2008-10-02 11:48:20 +02:00
|
|
|
static void
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_record(void)
|
|
|
|
{
|
|
|
|
char buffer[32768];
|
|
|
|
int len;
|
|
|
|
|
2008-10-02 20:21:58 +02:00
|
|
|
assert(dsp_fd != -1);
|
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
len = read(dsp_fd, buffer, sizeof(buffer));
|
|
|
|
if (len == -1)
|
|
|
|
{
|
|
|
|
if (errno != EWOULDBLOCK)
|
2007-01-10 10:15:15 +01:00
|
|
|
{
|
|
|
|
if (!dsp_broken)
|
|
|
|
perror("RDPSND: read()");
|
|
|
|
dsp_broken = True;
|
|
|
|
rdpsnd_queue_next(0);
|
|
|
|
}
|
2007-01-02 17:37:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-10 10:15:15 +01:00
|
|
|
dsp_broken = False;
|
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
rdpsnd_record(buffer, len);
|
|
|
|
}
|
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
struct audio_driver *
|
|
|
|
oss_register(char *options)
|
|
|
|
{
|
2007-01-02 12:39:56 +01:00
|
|
|
memset(&oss_driver, 0, sizeof(oss_driver));
|
|
|
|
|
|
|
|
oss_driver.name = "oss";
|
2006-12-24 14:53:23 +01:00
|
|
|
oss_driver.description =
|
2007-01-02 12:39:56 +01:00
|
|
|
"OSS output driver, default device: " DEFAULTDEVICE " or $AUDIODEV";
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
oss_driver.add_fds = oss_add_fds;
|
|
|
|
oss_driver.check_fds = oss_check_fds;
|
2006-12-07 16:23:45 +01:00
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_driver.wave_out_open = oss_open_out;
|
|
|
|
oss_driver.wave_out_close = oss_close_out;
|
2006-12-24 14:53:23 +01:00
|
|
|
oss_driver.wave_out_format_supported = oss_format_supported;
|
|
|
|
oss_driver.wave_out_set_format = oss_set_format;
|
|
|
|
oss_driver.wave_out_volume = oss_volume;
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2007-01-02 17:37:54 +01:00
|
|
|
oss_driver.wave_in_open = oss_open_in;
|
|
|
|
oss_driver.wave_in_close = oss_close_in;
|
|
|
|
oss_driver.wave_in_format_supported = oss_format_supported;
|
|
|
|
oss_driver.wave_in_set_format = oss_set_format;
|
|
|
|
oss_driver.wave_in_volume = NULL; /* FIXME */
|
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
oss_driver.need_byteswap_on_be = 0;
|
|
|
|
oss_driver.need_resampling = 0;
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2006-09-17 13:04:50 +02:00
|
|
|
if (options)
|
|
|
|
{
|
|
|
|
dsp_dev = xstrdup(options);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dsp_dev = getenv("AUDIODEV");
|
|
|
|
|
|
|
|
if (dsp_dev == NULL)
|
|
|
|
{
|
2007-01-02 12:39:56 +01:00
|
|
|
dsp_dev = DEFAULTDEVICE;
|
2006-09-17 13:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &oss_driver;
|
|
|
|
}
|