2005-08-03 12:56:16 +02:00
|
|
|
/* -*- c-basic-offset: 8 -*-
|
2004-08-09 13:39:49 +02:00
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
Sound Channel Process Functions - SGI/IRIX
|
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
|
|
|
|
Copyright (C) Jeremy Meng <void.foo@gmail.com> 2004-2005
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2010-01-12 09:31:06 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2004-08-09 13:39:49 +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
|
2004-08-09 13:39:49 +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/>.
|
2004-08-09 13:39:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rdesktop.h"
|
2014-11-19 08:44:18 +01:00
|
|
|
#include "rdpsnd.h"
|
2004-08-09 13:39:49 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <dmedia/audio.h>
|
2014-11-19 08:44:18 +01:00
|
|
|
#include <unistd.h>
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2005-12-16 08:48:02 +01:00
|
|
|
/* #define IRIX_DEBUG 1 */
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
#define IRIX_MAX_VOL 65535
|
|
|
|
|
|
|
|
ALconfig audioconfig;
|
|
|
|
ALport output_port;
|
|
|
|
|
|
|
|
static int g_snd_rate;
|
|
|
|
static int width = AL_SAMPLE_16;
|
2006-09-17 13:04:50 +02:00
|
|
|
static char *sgi_output_device = NULL;
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
double min_volume, max_volume, volume_range;
|
|
|
|
int resource, maxFillable;
|
|
|
|
int combinedFrameSize;
|
|
|
|
|
2006-12-07 16:23:45 +01:00
|
|
|
void sgi_play(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
sgi_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv)
|
|
|
|
{
|
2006-12-24 16:24:17 +01:00
|
|
|
/* We need to be called rather often... */
|
2007-10-30 14:57:31 +01:00
|
|
|
if (output_port != (ALport) 0 && !rdpsnd_queue_empty())
|
|
|
|
FD_SET(0, wfds);
|
2006-12-07 16:23:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sgi_check_fds(fd_set * rfds, fd_set * wfds)
|
|
|
|
{
|
|
|
|
if (output_port == (ALport) 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!rdpsnd_queue_empty())
|
|
|
|
sgi_play();
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2006-09-17 13:04:50 +02:00
|
|
|
sgi_open(void)
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
2004-08-09 15:03:32 +02:00
|
|
|
ALparamInfo pinfo;
|
2006-09-17 13:04:50 +02:00
|
|
|
static int warned = 0;
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
#if (defined(IRIX_DEBUG))
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_open()");
|
2004-08-09 13:39:49 +02:00
|
|
|
#endif
|
|
|
|
|
2006-09-17 13:04:50 +02:00
|
|
|
if (!warned && sgi_output_device)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Warning, "sgi_open(), device-options not supported for libao-driver");
|
2006-09-17 13:04:50 +02:00
|
|
|
warned = 1;
|
|
|
|
}
|
|
|
|
|
2004-08-09 15:03:32 +02:00
|
|
|
if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_open(), alGetParamInfo failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2004-08-09 15:03:32 +02:00
|
|
|
}
|
|
|
|
min_volume = alFixedToDouble(pinfo.min.ll);
|
|
|
|
max_volume = alFixedToDouble(pinfo.max.ll);
|
|
|
|
volume_range = (max_volume - min_volume);
|
2017-01-26 14:19:40 +01:00
|
|
|
|
|
|
|
logger(Sound, Debug, "sgi_open(), minvol = %lf, maxvol= %lf, range = %lf",
|
|
|
|
min_volume, max_volume, volume_range);
|
|
|
|
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
audioconfig = alNewConfig();
|
2005-06-27 00:36:44 +02:00
|
|
|
if (audioconfig == (ALconfig) 0)
|
2004-08-09 15:03:32 +02:00
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_open(), alNewConfig failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2004-08-09 13:39:49 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_port = alOpenPort("rdpsnd", "w", 0);
|
2004-08-09 15:03:32 +02:00
|
|
|
if (output_port == (ALport) 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_open(), alOpenPort failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2004-08-09 13:39:49 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_open(), done");
|
2004-08-09 13:39:49 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-09-17 13:04:50 +02:00
|
|
|
sgi_close(void)
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
|
|
|
/* Ack all remaining packets */
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_close()");
|
2004-08-09 15:03:32 +02:00
|
|
|
|
2006-09-17 12:32:18 +02:00
|
|
|
while (!rdpsnd_queue_empty())
|
2006-10-27 14:29:05 +02:00
|
|
|
rdpsnd_queue_next(0);
|
2004-08-09 15:03:32 +02:00
|
|
|
alDiscardFrames(output_port, 0);
|
|
|
|
|
2004-08-09 13:39:49 +02:00
|
|
|
alClosePort(output_port);
|
2006-12-07 16:23:45 +01:00
|
|
|
output_port = (ALport) 0;
|
2004-08-09 13:39:49 +02:00
|
|
|
alFreeConfig(audioconfig);
|
2017-01-26 14:19:40 +01:00
|
|
|
|
|
|
|
logger(Sound, Debug, "sgi_close(), done");
|
2004-08-09 13:39:49 +02:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2007-01-04 05:55:56 +01:00
|
|
|
sgi_format_supported(RD_WAVEFORMATEX * pwfx)
|
2004-08-09 13:39:49 +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;
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2007-01-04 05:55:56 +01:00
|
|
|
sgi_set_format(RD_WAVEFORMATEX * pwfx)
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
|
|
|
int channels;
|
2004-08-09 15:03:32 +02:00
|
|
|
int frameSize, channelCount;
|
|
|
|
ALpv params;
|
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_set_format()");
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
if (pwfx->wBitsPerSample == 8)
|
|
|
|
width = AL_SAMPLE_8;
|
2004-08-09 15:03:32 +02:00
|
|
|
else if (pwfx->wBitsPerSample == 16)
|
2004-08-09 13:39:49 +02:00
|
|
|
width = AL_SAMPLE_16;
|
|
|
|
|
2005-06-27 00:36:44 +02:00
|
|
|
/* Limited support to configure an opened audio port in IRIX. The
|
2005-06-07 13:10:13 +02:00
|
|
|
number of channels is a static setting and can not be changed after
|
2005-06-27 00:36:44 +02:00
|
|
|
a port is opened. So if the number of channels remains the same, we
|
|
|
|
can configure other settings; otherwise we have to reopen the audio
|
2005-06-07 13:10:13 +02:00
|
|
|
port, using same config. */
|
2005-04-30 11:13:13 +02:00
|
|
|
|
2004-08-09 13:39:49 +02:00
|
|
|
channels = pwfx->nChannels;
|
|
|
|
g_snd_rate = pwfx->nSamplesPerSec;
|
|
|
|
|
|
|
|
alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
|
|
|
|
alSetWidth(audioconfig, width);
|
2005-06-07 13:10:13 +02:00
|
|
|
if (channels != alGetChannels(audioconfig))
|
2005-04-30 11:13:13 +02:00
|
|
|
{
|
|
|
|
alClosePort(output_port);
|
|
|
|
alSetChannels(audioconfig, channels);
|
|
|
|
output_port = alOpenPort("rdpsnd", "w", audioconfig);
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2005-04-30 11:13:13 +02:00
|
|
|
if (output_port == (ALport) 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_set_format(), alOpenPort failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2005-04-30 11:13:13 +02:00
|
|
|
return False;
|
|
|
|
}
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resource = alGetResource(output_port);
|
|
|
|
maxFillable = alGetFillable(output_port);
|
2004-08-09 15:03:32 +02:00
|
|
|
channelCount = alGetChannels(audioconfig);
|
|
|
|
frameSize = alGetWidth(audioconfig);
|
|
|
|
|
|
|
|
if (frameSize == 0 || channelCount == 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_set_format(), bad frameSize or channelCount");
|
2004-08-09 15:03:32 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
combinedFrameSize = frameSize * channelCount;
|
|
|
|
|
|
|
|
params.param = AL_RATE;
|
|
|
|
params.value.ll = (long long) g_snd_rate << 32;
|
|
|
|
|
|
|
|
if (alSetParams(resource, ¶ms, 1) < 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_set_format(), alSetParams failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2004-08-09 15:03:32 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
if (params.sizeOut < 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_set_format(), invalid rate %d", g_snd_rate);
|
2004-08-09 15:03:32 +02:00
|
|
|
return False;
|
|
|
|
}
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_set_format(), done");
|
|
|
|
|
2004-08-09 13:39:49 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-09-17 13:04:50 +02:00
|
|
|
sgi_volume(uint16 left, uint16 right)
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
2004-08-09 15:03:32 +02:00
|
|
|
double gainleft, gainright;
|
|
|
|
ALpv pv[1];
|
|
|
|
ALfixed gain[8];
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
|
|
|
|
logger(Sound, Debug, "sgi_volume(), left=%d, right=%d", left, right);
|
2004-08-09 15:03:32 +02:00
|
|
|
|
|
|
|
gainleft = (double) left / IRIX_MAX_VOL;
|
2004-08-09 13:39:49 +02:00
|
|
|
gainright = (double) right / IRIX_MAX_VOL;
|
|
|
|
|
2004-08-09 15:03:32 +02:00
|
|
|
gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
|
|
|
|
gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2004-08-09 15:03:32 +02:00
|
|
|
pv[0].param = AL_GAIN;
|
|
|
|
pv[0].value.ptr = gain;
|
|
|
|
pv[0].sizeIn = 8;
|
|
|
|
if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Error, "sgi_volume(), alSetParams failed: %s",
|
|
|
|
alGetErrorString(oserror()));
|
2004-08-09 15:03:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2017-01-26 14:19:40 +01:00
|
|
|
logger(Sound, Debug, "sgi_volume(), done");
|
2004-08-09 13:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-09-17 13:04:50 +02:00
|
|
|
sgi_play(void)
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
|
|
|
struct audio_packet *packet;
|
|
|
|
ssize_t len;
|
|
|
|
STREAM out;
|
|
|
|
int gf;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2006-09-17 12:32:18 +02:00
|
|
|
if (rdpsnd_queue_empty())
|
2004-08-09 13:39:49 +02:00
|
|
|
return;
|
|
|
|
|
2006-09-17 12:32:18 +02:00
|
|
|
packet = rdpsnd_queue_current_packet();
|
2019-04-09 13:25:50 +02:00
|
|
|
out = packet->s;
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2019-04-09 13:13:35 +02:00
|
|
|
len = s_remaining(out);
|
2004-08-09 13:39:49 +02:00
|
|
|
|
2004-08-09 15:03:32 +02:00
|
|
|
alWriteFrames(output_port, out->p, len / combinedFrameSize);
|
2004-08-09 13:39:49 +02:00
|
|
|
|
|
|
|
out->p += len;
|
|
|
|
if (out->p == out->end)
|
|
|
|
{
|
2005-04-30 11:13:13 +02:00
|
|
|
gf = alGetFilled(output_port);
|
2005-06-07 13:10:13 +02:00
|
|
|
if (gf < (4 * maxFillable / 10))
|
2004-08-09 13:39:49 +02:00
|
|
|
{
|
2006-10-26 11:47:17 +02:00
|
|
|
rdpsnd_queue_next(0);
|
2004-08-09 13:39:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-26 14:19:40 +01:00
|
|
|
/* logger(Sound,Debug, "sgi_play(), busy playing..."); */
|
2005-12-16 08:48:02 +01:00
|
|
|
usleep(10);
|
2004-08-09 13:39:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-17 13:04:50 +02:00
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
struct audio_driver *
|
|
|
|
sgi_register(char *options)
|
|
|
|
{
|
|
|
|
static struct audio_driver sgi_driver;
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2007-01-02 12:39:56 +01:00
|
|
|
memset(&sgi_driver, 0, sizeof(sgi_driver));
|
|
|
|
|
|
|
|
sgi_driver.name = "sgi";
|
|
|
|
sgi_driver.description = "SGI output driver";
|
2006-12-07 16:23:45 +01:00
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
sgi_driver.add_fds = sgi_add_fds;
|
|
|
|
sgi_driver.check_fds = sgi_check_fds;
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2006-12-24 14:53:23 +01:00
|
|
|
sgi_driver.wave_out_open = sgi_open;
|
|
|
|
sgi_driver.wave_out_close = sgi_close;
|
|
|
|
sgi_driver.wave_out_format_supported = sgi_format_supported;
|
|
|
|
sgi_driver.wave_out_set_format = sgi_set_format;
|
|
|
|
sgi_driver.wave_out_volume = sgi_volume;
|
|
|
|
|
|
|
|
sgi_driver.need_byteswap_on_be = 1;
|
|
|
|
sgi_driver.need_resampling = 0;
|
2006-12-07 12:54:29 +01:00
|
|
|
|
2006-09-17 13:04:50 +02:00
|
|
|
if (options)
|
|
|
|
{
|
|
|
|
sgi_output_device = xstrdup(options);
|
|
|
|
}
|
|
|
|
return &sgi_driver;
|
|
|
|
}
|