13 #include "libmythbase/mythconfig.h"
21 #define LOC QString("AOOSS: ")
54 while (
int rate = settings->GetNextRate())
57 if(ioctl(
m_audioFd, SNDCTL_DSP_SPEED, &rate2) >= 0
59 settings->AddSupportedRate(rate);
63 Error(
LOC +
"Error retrieving formats" +
": " +
ENO);
68 int ofmt = AFMT_QUERY;
78 settings->AddSupportedFormat(fmt);
84 settings->setPassthrough(
static_cast<int>((
formats & AFMT_AC3) != 0) - 1);
87 for (
int i = 1; i <= 2; i++)
91 if (ioctl(
m_audioFd, SNDCTL_DSP_CHANNELS, &channel) >= 0 &&
94 settings->AddSupportedChannels(i);
111 LOG(VB_AUDIO, LOG_INFO,
LOC + QString(
"Opening OSS audio device '%1'.").arg(
m_mainDevice));
116 m_audioFd = open(device.constData(), O_WRONLY);
117 if (
m_audioFd < 0 && errno != EAGAIN && errno != EINTR)
121 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Something is currently using: %1.")
125 Error(
LOC + QString(
"Error opening audio device (%1)")
142 Error(
LOC + QString(
"Error removing the O_NONBLOCK flag from audio device FD (%1)").arg(
m_mainDevice) +
": " +
ENO);
146 int format = AFMT_QUERY;
159 #if defined(AFMT_AC3) && defined(SNDCTL_DSP_GETFMTS)
162 int format_support = 0;
163 if (!ioctl(
m_audioFd, SNDCTL_DSP_GETFMTS, &format_support) &&
164 (format_support & AFMT_AC3))
175 ioctl(
m_audioFd, SNDCTL_DSP_SETFMT, &format) < 0)
181 if (ioctl(
m_audioFd, SNDCTL_DSP_STEREO, &stereo) < 0 ||
183 ioctl(
m_audioFd, SNDCTL_DSP_SETFMT, &format) < 0)
189 Error(
LOC + QString(
"Unable to set audio device (%1) to %2 kHz, %3 bits, "
202 Error(
LOC +
"Error retrieving card buffer size" +
": " +
ENO);
210 if (ioctl(
m_audioFd, SNDCTL_DSP_GETCAPS, &caps) == 0)
212 if (!(caps & DSP_CAP_REALTIME))
213 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"The audio device cannot report buffer state "
214 "accurately! audio/video sync will be bad, continuing...");
218 Error(
LOC +
"Unable to get audio card capabilities" +
": " +
ENO);
248 uchar *tmpbuf = aubuf;
250 while ((written < size) &&
259 Error(
LOC + QString(
"Error writing to audio device (%1)")
268 int soundcard_buffer=0;
270 #ifdef SNDCTL_DSP_GETODELAY
271 if(ioctl(
m_audioFd, SNDCTL_DSP_GETODELAY, &soundcard_buffer) < 0)
272 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Error retrieving buffering delay" +
": " +
ENO);
274 return soundcard_buffer;
282 if (device.toLower() ==
"software")
285 QByteArray dev = device.toLatin1();
286 m_mixerFd = open(dev.constData(), O_RDONLY);
290 if (controlLabel ==
"Master")
297 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Unable to open mixer: '%1'").arg(device));
304 int tmpVol = (volume << 8) + volume;
305 int ret = ioctl(
m_mixerFd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmpVol);
307 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error Setting initial Master Volume") +
ENO);
310 tmpVol = (volume << 8) + volume;
311 ret = ioctl(
m_mixerFd, MIXER_WRITE(SOUND_MIXER_PCM), &tmpVol);
313 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error setting initial PCM Volume") +
ENO);
337 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error reading volume for channel %1").arg(channel));
342 volume = tmpVol & 0xff;
343 else if (channel == 1)
344 volume = (tmpVol >> 8) & 0xff;
346 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Invalid channel. Only stereo volume supported");
356 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error setting channel %1. Only 2 ch volume supported")
373 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error setting volume on channel %1").arg(channel));