12 #include "libmythbase/mythconfig.h"
19 #define LOC QString("AOOSS: ")
52 while (
int rate = settings->GetNextRate())
55 if(ioctl(
m_audioFd, SNDCTL_DSP_SPEED, &rate2) >= 0
57 settings->AddSupportedRate(rate);
61 VBERRENO(
"Error retrieving formats");
66 int ofmt = AFMT_QUERY;
76 settings->AddSupportedFormat(fmt);
82 settings->setPassthrough(
static_cast<int>((
formats & AFMT_AC3) != 0) - 1);
85 for (
int i = 1; i <= 2; i++)
89 if (ioctl(
m_audioFd, SNDCTL_DSP_CHANNELS, &channel) >= 0 &&
92 settings->AddSupportedChannels(i);
114 m_audioFd = open(device.constData(), O_WRONLY);
115 if (
m_audioFd < 0 && errno != EAGAIN && errno != EINTR)
119 VBWARN(QString(
"Something is currently using: %1.")
123 VBERRENO(QString(
"Error opening audio device (%1)")
140 VBERRENO(QString(
"Error removing the O_NONBLOCK flag from audio device FD (%1)").arg(
m_mainDevice));
144 int format = AFMT_QUERY;
157 #if defined(AFMT_AC3) && defined(SNDCTL_DSP_GETFMTS)
160 int format_support = 0;
161 if (!ioctl(
m_audioFd, SNDCTL_DSP_GETFMTS, &format_support) &&
162 (format_support & AFMT_AC3))
173 ioctl(
m_audioFd, SNDCTL_DSP_SETFMT, &format) < 0)
179 if (ioctl(
m_audioFd, SNDCTL_DSP_STEREO, &stereo) < 0 ||
181 ioctl(
m_audioFd, SNDCTL_DSP_SETFMT, &format) < 0)
187 VBERRENO(QString(
"Unable to set audio device (%1) to %2 kHz, %3 bits, "
199 if (ioctl(
m_audioFd, SNDCTL_DSP_GETOSPACE, &info) < 0)
200 VBERRENO(
"Error retrieving card buffer size");
208 if (ioctl(
m_audioFd, SNDCTL_DSP_GETCAPS, &caps) == 0)
210 if (!(caps & DSP_CAP_REALTIME))
211 VBWARN(
"The audio device cannot report buffer state "
212 "accurately! audio/video sync will be bad, continuing...");
215 VBERRENO(
"Unable to get audio card capabilities");
244 uchar *tmpbuf = aubuf;
246 while ((written < size) &&
255 VBERRENO(QString(
"Error writing to audio device (%1)")
264 int soundcard_buffer=0;
266 #ifdef SNDCTL_DSP_GETODELAY
267 if(ioctl(
m_audioFd, SNDCTL_DSP_GETODELAY, &soundcard_buffer) < 0)
270 return soundcard_buffer;
278 if (device.toLower() ==
"software")
281 QByteArray dev = device.toLatin1();
282 m_mixerFd = open(dev.constData(), O_RDONLY);
286 if (controlLabel ==
"Master")
293 VBERROR(QString(
"Unable to open mixer: '%1'").arg(device));
300 int tmpVol = (volume << 8) + volume;
301 int ret = ioctl(
m_mixerFd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmpVol);
303 VBERROR(QString(
"Error Setting initial Master Volume") +
ENO);
306 tmpVol = (volume << 8) + volume;
307 ret = ioctl(
m_mixerFd, MIXER_WRITE(SOUND_MIXER_PCM), &tmpVol);
309 VBERROR(QString(
"Error setting initial PCM Volume") +
ENO);
333 VBERROR(QString(
"Error reading volume for channel %1").arg(channel));
338 volume = tmpVol & 0xff;
339 else if (channel == 1)
340 volume = (tmpVol >> 8) & 0xff;
342 VBERROR(
"Invalid channel. Only stereo volume supported");
352 VBERROR(QString(
"Error setting channel %1. Only 2 ch volume supported")
372 VBERROR(QString(
"Error setting volume on channel %1").arg(channel));