25 #include <sys/ioctl.h>
27 #if __has_include(<sys/soundcard.h>)
28 # include <sys/soundcard.h>
29 #elif __has_include(<soundcard.h>)
30 # include <soundcard.h>
32 # error attemping to compile OSS support without soundcard.h
39 #define LOC QString("AudioInOSS: ")
40 #define LOC_DEV QString("AudioInOSS(%1): ").arg(m_deviceName.constData())
44 if (!device.isEmpty())
63 LOG(VB_GENERAL, LOG_ERR,
LOC_DEV + QString(
"open failed: ") +
ENO);
69 if (ioctl(
m_dspFd, SNDCTL_DSP_SETTRIGGER, &chk) < 0)
71 LOG(VB_GENERAL, LOG_WARNING,
72 LOC_DEV +
"failed to disable audio device: " +
ENO);
86 #if (Q_BYTE_ORDER == Q_BIG_ENDIAN)
96 if (ioctl(
m_dspFd, SNDCTL_DSP_SETFMT, &format) < 0)
99 QString(
"failed to set audio format %1: ").arg(tag) +
ENO);
103 if (format != choice)
106 QString(
"set audio format not %1 as requested").arg(tag));
116 QString(
"failed to set audio sample bits to %1: ")
117 .arg(sample_bits) +
ENO);
124 QString(
"requested %1 sample bits, got %2")
132 QString(
"failed to set audio channels to %1: ").arg(channels)+
ENO);
139 QString(
"requested %1 channels, got %2")
144 int choice_sample_rate = sample_rate;
149 QString(
"failed to set sample rate to %1: ").arg(sample_rate)+
ENO);
156 QString(
"requested sample rate %1, got %2")
159 LOG(VB_AUDIO, LOG_INFO,
LOC_DEV +
"device open");
171 LOG(VB_AUDIO, LOG_INFO,
LOC_DEV +
"device closed");
176 bool started =
false;
180 if (ioctl(
m_dspFd, SNDCTL_DSP_SETTRIGGER, &trig) < 0)
182 LOG(VB_GENERAL, LOG_WARNING,
183 LOC_DEV +
"failed to disable audio device: " +
ENO);
185 trig = PCM_ENABLE_INPUT;
186 if (ioctl(
m_dspFd, SNDCTL_DSP_SETTRIGGER, &trig) < 0)
189 QString(
"Start() failed: ") +
ENO);
193 LOG(VB_AUDIO, LOG_INFO,
LOC_DEV +
"capture started");
202 bool stopped =
false;
204 if (ioctl(
m_dspFd, SNDCTL_DSP_SETTRIGGER, &trig) < 0)
207 QString(
"stop action failed: ") +
ENO);
212 LOG(VB_AUDIO, LOG_INFO,
LOC_DEV +
"capture stopped");
222 if (ioctl(
m_dspFd, SNDCTL_DSP_GETBLKSIZE, &frag) < 0)
225 QString(
"fragment size query failed, returned %1: ").arg(frag) +
230 LOG(VB_AUDIO, LOG_INFO,
LOC_DEV + QString(
"block size %1").arg(frag));
240 while (bytes_read < num_bytes && retries < 3)
242 int this_read =
read(
m_dspFd, buffer, num_bytes - bytes_read);
246 QString(
"GetSamples read failed: ") +
ENO);
250 bytes_read += this_read;
254 if (num_bytes > bytes_read)
257 QString(
"GetSamples short read, %1 of %2 bytes")
258 .arg(bytes_read).arg(num_bytes));
269 audio_buf_info ispace;
270 if (ioctl(
m_dspFd, SNDCTL_DSP_GETISPACE, &ispace) < 0)
273 QString(
"get ready bytes failed, returned %1: ")
274 .arg(ispace.bytes) +
ENO);
276 else if ((readies = ispace.bytes) > 0)
277 LOG(VB_AUDIO, LOG_DEBUG,
LOC_DEV + QString(
"ready bytes %1")