mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-06 03:29:12 -04:00
Foolproof AudioFifo to try fix issue #210. Consequently removed useless timeout parameter on read and write methods
This commit is contained in:
parent
d084d6ff5b
commit
5771ef4783
@ -136,7 +136,7 @@ void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector
|
||||
|
||||
if (m_audioBufferFill > 0)
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
@ -263,7 +263,7 @@ void AMDemod::processOneSample(Complex &ci)
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
const PluginDescriptor AMDemodPlugin::m_pluginDescriptor = {
|
||||
QString("AM Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -246,7 +246,7 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if(res != m_audioBufferFill) {
|
||||
qDebug("BFMDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
|
||||
@ -262,7 +262,7 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill > 0)
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill) {
|
||||
qDebug("BFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
const PluginDescriptor BFMPlugin::m_pluginDescriptor = {
|
||||
QString("Broadcast FM Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -296,7 +296,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
if (nbAudioSamples > 0)
|
||||
{
|
||||
if (!m_settings.m_audioMute) {
|
||||
m_audioFifo1.write((const quint8*) dsdAudio, nbAudioSamples, 10);
|
||||
m_audioFifo1.write((const quint8*) dsdAudio, nbAudioSamples);
|
||||
}
|
||||
|
||||
m_dsdDecoder.resetAudio1();
|
||||
@ -311,7 +311,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
if (nbAudioSamples > 0)
|
||||
{
|
||||
if (!m_settings.m_audioMute) {
|
||||
m_audioFifo2.write((const quint8*) dsdAudio, nbAudioSamples, 10);
|
||||
m_audioFifo2.write((const quint8*) dsdAudio, nbAudioSamples);
|
||||
}
|
||||
|
||||
m_dsdDecoder.resetAudio2();
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
const PluginDescriptor DSDDemodPlugin::m_pluginDescriptor = {
|
||||
QString("DSD Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -302,7 +302,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
@ -318,7 +318,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill > 0)
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
const PluginDescriptor NFMPlugin::m_pluginDescriptor = {
|
||||
QString("NFM Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -253,7 +253,7 @@ void SSBDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
@ -265,7 +265,7 @@ void SSBDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
}
|
||||
}
|
||||
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
const PluginDescriptor SSBPlugin::m_pluginDescriptor = {
|
||||
QString("SSB Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -152,7 +152,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if(m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill) {
|
||||
qDebug("WFMDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
|
||||
@ -168,7 +168,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
|
||||
|
||||
if (m_audioBufferFill > 0)
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill) {
|
||||
qDebug("WFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
const PluginDescriptor WFMPlugin::m_pluginDescriptor = {
|
||||
QString("WFM Demodulator"),
|
||||
QString("4.0.6"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -414,7 +414,7 @@ void UDPSink::audioReadyRead()
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
@ -436,7 +436,7 @@ void UDPSink::audioReadyRead()
|
||||
|
||||
if (m_audioBufferFill >= m_audioBuffer.size())
|
||||
{
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
@ -448,7 +448,7 @@ void UDPSink::audioReadyRead()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill)
|
||||
if (m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill) != m_audioBufferFill)
|
||||
{
|
||||
qDebug("UDPSink::audioReadyRead: lost samples");
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ void AMMod::pullAudio(int nbSamples)
|
||||
m_audioBuffer.resize(nbAudioSamples);
|
||||
}
|
||||
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbAudioSamples, 10);
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbAudioSamples);
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
const PluginDescriptor AMModPlugin::m_pluginDescriptor = {
|
||||
QString("AM Modulator"),
|
||||
QString("4.0.7"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -155,7 +155,7 @@ void NFMMod::pullAudio(int nbSamples)
|
||||
m_audioBuffer.resize(nbSamplesAudio);
|
||||
}
|
||||
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio, 10);
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio);
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
const PluginDescriptor NFMModPlugin::m_pluginDescriptor = {
|
||||
QString("NFM Modulator"),
|
||||
QString("4.0.7"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -179,7 +179,7 @@ void SSBMod::pullAudio(int nbSamples)
|
||||
m_audioBuffer.resize(nbSamplesAudio);
|
||||
}
|
||||
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio, 10);
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio);
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
const PluginDescriptor SSBModPlugin::m_pluginDescriptor = {
|
||||
QString("SSB Modulator"),
|
||||
QString("4.0.7"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -177,7 +177,7 @@ void WFMMod::pullAudio(int nbSamples)
|
||||
m_audioBuffer.resize(nbSamplesAudio);
|
||||
}
|
||||
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio, 10);
|
||||
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio);
|
||||
m_audioBufferFill = 0;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
const PluginDescriptor WFMModPlugin::m_pluginDescriptor = {
|
||||
QString("WFM Modulator"),
|
||||
QString("4.0.7"),
|
||||
QString("4.1.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -52,9 +52,6 @@ AudioFifo::~AudioFifo()
|
||||
m_fifo = 0;
|
||||
}
|
||||
|
||||
m_writeWaitCondition.wakeOne();
|
||||
m_readWaitCondition.wakeOne();
|
||||
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
@ -65,68 +62,27 @@ bool AudioFifo::setSize(uint32_t numSamples)
|
||||
return create(numSamples);
|
||||
}
|
||||
|
||||
uint AudioFifo::write(const quint8* data, uint32_t numSamples, int timeout_ms)
|
||||
uint AudioFifo::write(const quint8* data, uint32_t numSamples)
|
||||
{
|
||||
QTime time;
|
||||
uint32_t total;
|
||||
uint32_t remaining;
|
||||
uint32_t copyLen;
|
||||
|
||||
if(m_fifo == 0)
|
||||
{
|
||||
if (m_fifo == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
time.start();
|
||||
m_mutex.lock();
|
||||
|
||||
if(timeout_ms == 0)
|
||||
{
|
||||
total = MIN(numSamples, m_size - m_fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
total = numSamples;
|
||||
}
|
||||
|
||||
total = MIN(numSamples, m_size - m_fill);
|
||||
remaining = total;
|
||||
|
||||
while (remaining > 0)
|
||||
while (remaining != 0)
|
||||
{
|
||||
if (isFull())
|
||||
{
|
||||
if (time.elapsed() < timeout_ms)
|
||||
{
|
||||
m_writeWaitLock.lock();
|
||||
m_mutex.unlock();
|
||||
int ms = timeout_ms - time.elapsed();
|
||||
|
||||
if(ms < 1)
|
||||
{
|
||||
ms = 1;
|
||||
}
|
||||
|
||||
bool ok = m_writeWaitCondition.wait(&m_writeWaitLock, ms);
|
||||
m_writeWaitLock.unlock();
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
return total - remaining;
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
|
||||
if(m_fifo == 0)
|
||||
{
|
||||
m_mutex.unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex.unlock();
|
||||
return total - remaining;
|
||||
}
|
||||
m_mutex.unlock();
|
||||
return total - remaining; // written so far
|
||||
}
|
||||
|
||||
copyLen = MIN(remaining, m_size - m_fill);
|
||||
@ -137,75 +93,33 @@ uint AudioFifo::write(const quint8* data, uint32_t numSamples, int timeout_ms)
|
||||
m_fill += copyLen;
|
||||
data += copyLen * m_sampleSize;
|
||||
remaining -= copyLen;
|
||||
m_readWaitCondition.wakeOne();
|
||||
}
|
||||
|
||||
m_mutex.unlock();
|
||||
return total;
|
||||
}
|
||||
|
||||
uint AudioFifo::read(quint8* data, uint32_t numSamples, int timeout_ms)
|
||||
uint AudioFifo::read(quint8* data, uint32_t numSamples)
|
||||
{
|
||||
QTime time;
|
||||
uint32_t total;
|
||||
uint32_t remaining;
|
||||
uint32_t copyLen;
|
||||
|
||||
if(m_fifo == 0)
|
||||
{
|
||||
if (m_fifo == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
time.start();
|
||||
m_mutex.lock();
|
||||
|
||||
if(timeout_ms == 0)
|
||||
{
|
||||
total = MIN(numSamples, m_fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
total = numSamples;
|
||||
}
|
||||
|
||||
total = MIN(numSamples, m_fill);
|
||||
remaining = total;
|
||||
|
||||
while(remaining > 0)
|
||||
while (remaining != 0)
|
||||
{
|
||||
if(isEmpty())
|
||||
if (isEmpty())
|
||||
{
|
||||
if(time.elapsed() < timeout_ms)
|
||||
{
|
||||
m_readWaitLock.lock();
|
||||
m_mutex.unlock();
|
||||
int ms = timeout_ms - time.elapsed();
|
||||
|
||||
if(ms < 1)
|
||||
{
|
||||
ms = 1;
|
||||
}
|
||||
|
||||
bool ok = m_readWaitCondition.wait(&m_readWaitLock, ms);
|
||||
m_readWaitLock.unlock();
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
return total - remaining;
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
|
||||
if(m_fifo == 0)
|
||||
{
|
||||
m_mutex.unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex.unlock();
|
||||
return total - remaining;
|
||||
}
|
||||
m_mutex.unlock();
|
||||
return total - remaining; // read so far
|
||||
}
|
||||
|
||||
copyLen = MIN(remaining, m_fill);
|
||||
@ -217,7 +131,6 @@ uint AudioFifo::read(quint8* data, uint32_t numSamples, int timeout_ms)
|
||||
m_fill -= copyLen;
|
||||
data += copyLen * m_sampleSize;
|
||||
remaining -= copyLen;
|
||||
m_writeWaitCondition.wakeOne();
|
||||
}
|
||||
|
||||
m_mutex.unlock();
|
||||
@ -236,7 +149,6 @@ uint AudioFifo::drain(uint32_t numSamples)
|
||||
m_head = (m_head + numSamples) % m_size;
|
||||
m_fill -= numSamples;
|
||||
|
||||
m_writeWaitCondition.wakeOne();
|
||||
return numSamples;
|
||||
}
|
||||
|
||||
@ -247,8 +159,6 @@ void AudioFifo::clear()
|
||||
m_fill = 0;
|
||||
m_head = 0;
|
||||
m_tail = 0;
|
||||
|
||||
m_writeWaitCondition.wakeOne();
|
||||
}
|
||||
|
||||
bool AudioFifo::create(uint32_t numSamples)
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
|
||||
bool setSize(uint32_t numSamples);
|
||||
|
||||
uint32_t write(const quint8* data, uint32_t numSamples, int timeout_ms = INT_MAX);
|
||||
uint32_t read(quint8* data, uint32_t numSamples, int timeout_ms = INT_MAX);
|
||||
uint32_t write(const quint8* data, uint32_t numSamples);
|
||||
uint32_t read(quint8* data, uint32_t numSamples);
|
||||
|
||||
uint32_t drain(uint32_t numSamples);
|
||||
void clear();
|
||||
@ -58,11 +58,6 @@ private:
|
||||
uint32_t m_head;
|
||||
uint32_t m_tail;
|
||||
|
||||
QMutex m_writeWaitLock;
|
||||
QMutex m_readWaitLock;
|
||||
QWaitCondition m_writeWaitCondition;
|
||||
QWaitCondition m_readWaitCondition;
|
||||
|
||||
bool create(uint32_t numSamples);
|
||||
};
|
||||
|
||||
|
@ -181,7 +181,7 @@ qint64 AudioInput::writeData(const char *data, qint64 len)
|
||||
|
||||
for (std::list<AudioFifo*>::iterator it = m_audioFifos.begin(); it != m_audioFifos.end(); ++it)
|
||||
{
|
||||
(*it)->write(reinterpret_cast<const quint8*>(data), len/4, 10);
|
||||
(*it)->write(reinterpret_cast<const quint8*>(data), len/4);
|
||||
}
|
||||
|
||||
return len;
|
||||
|
@ -241,7 +241,7 @@ qint64 AudioOutput::readData(char* data, qint64 maxLen)
|
||||
for (std::list<AudioFifo*>::iterator it = m_audioFifos.begin(); it != m_audioFifos.end(); ++it)
|
||||
{
|
||||
// use outputBuffer as temp - yes, one memcpy could be saved
|
||||
unsigned int samples = (*it)->read((quint8*) data, samplesPerBuffer, 1);
|
||||
unsigned int samples = (*it)->read((quint8*) data, samplesPerBuffer);
|
||||
const qint16* src = (const qint16*) data;
|
||||
std::vector<qint32>::iterator dst = m_mixBuffer.begin();
|
||||
|
||||
|
@ -118,7 +118,7 @@ void DVSerialWorker::handleInputMessages()
|
||||
|
||||
if (audioFifo)
|
||||
{
|
||||
uint res = audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
|
||||
uint res = audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
|
||||
|
||||
if (res != m_audioBufferFill)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user