|
|
|
@ -17,494 +17,325 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "samplemififo.h" |
|
|
|
#include "samplemififo.h" |
|
|
|
|
|
|
|
|
|
|
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SampleMIFifo::init(unsigned int nbStreams, unsigned int size) |
|
|
|
void SampleMIFifo::init(unsigned int nbStreams, unsigned int size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_nbStreams = nbStreams; |
|
|
|
m_nbStreams = nbStreams; |
|
|
|
m_size = size; |
|
|
|
m_size = size; |
|
|
|
m_fill = 0; |
|
|
|
m_fill = 0; |
|
|
|
m_head = 0; |
|
|
|
m_head = 0; |
|
|
|
m_tail = 0; |
|
|
|
m_data.resize(nbStreams); |
|
|
|
m_data.resize(nbStreams); |
|
|
|
m_vFill.clear(); |
|
|
|
m_vfill.resize(nbStreams); |
|
|
|
m_vHead.clear(); |
|
|
|
m_vhead.resize(nbStreams); |
|
|
|
|
|
|
|
m_vtail.resize(nbStreams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < nbStreams; stream++) |
|
|
|
for (unsigned int stream = 0; stream < nbStreams; stream++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_data[stream].resize(size); |
|
|
|
m_data[stream].resize(size); |
|
|
|
m_vfill[stream] = 0; |
|
|
|
m_vFill.push_back(0); |
|
|
|
m_vhead[stream] = 0; |
|
|
|
m_vHead.push_back(0); |
|
|
|
m_vtail[stream] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SampleMIFifo::SampleMIFifo(QObject* parent) : |
|
|
|
void SampleMIFifo::reset() |
|
|
|
QObject(parent) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_suppressed = -1; |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
m_size = 0; |
|
|
|
|
|
|
|
m_fill = 0; |
|
|
|
m_fill = 0; |
|
|
|
m_head = 0; |
|
|
|
m_head = 0; |
|
|
|
m_tail = 0; |
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_vFill[stream] = 0; |
|
|
|
|
|
|
|
m_vHead[stream] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SampleMIFifo::SampleMIFifo(unsigned int nbStreams, unsigned int size, QObject* parent) : |
|
|
|
SampleMIFifo::SampleMIFifo(QObject *parent) : |
|
|
|
QObject(parent) |
|
|
|
QObject(parent), |
|
|
|
|
|
|
|
m_nbStreams(0), |
|
|
|
|
|
|
|
m_size(0), |
|
|
|
|
|
|
|
m_fill(0), |
|
|
|
|
|
|
|
m_head(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
init(nbStreams, size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_suppressed = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_vsuppressed[stream] = -1; |
|
|
|
|
|
|
|
m_vmsgRateTimer.push_back(QTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::writeSync(const quint8* data, unsigned int count) |
|
|
|
SampleMIFifo::SampleMIFifo(unsigned int nbStreams, unsigned int size, QObject *parent) : |
|
|
|
|
|
|
|
QObject(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
init(nbStreams, size); |
|
|
|
unsigned int total; |
|
|
|
} |
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
unsigned int byteCount = count; |
|
|
|
|
|
|
|
count /= sizeof(Sample); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = std::min(count, m_size - m_fill); |
|
|
|
void SampleMIFifo::writeSync(const quint8* data, unsigned int count) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
unsigned int spaceLeft = m_size - m_fill; |
|
|
|
|
|
|
|
unsigned int size = count / sizeof(Sample); |
|
|
|
|
|
|
|
|
|
|
|
if (total < count) |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_suppressed < 0) |
|
|
|
if (size < spaceLeft) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_suppressed = 0; |
|
|
|
std::copy(&data[stream*count], &data[stream*count] + count, m_data[stream].begin() + m_fill); |
|
|
|
m_msgRateTimer.start(); |
|
|
|
m_fill += size; |
|
|
|
qCritical("SampleMIFifo: overflow - dropping %u samples", count - total); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_msgRateTimer.elapsed() > 2500) |
|
|
|
unsigned int remaining = size - spaceLeft; |
|
|
|
{ |
|
|
|
unsigned int bytesLeft = spaceLeft*sizeof(Sample); |
|
|
|
qCritical("SampleMIFifo: %u messages dropped", m_suppressed); |
|
|
|
std::copy(&data[stream*count], &data[stream*count] + bytesLeft, m_data[stream].begin() + m_fill); |
|
|
|
qCritical("SampleMIFifo: overflow - dropping %u samples", count - total); |
|
|
|
std::copy(&data[stream*count] + bytesLeft, &data[stream*count] + count, m_data[stream].begin()); |
|
|
|
m_suppressed = -1; |
|
|
|
m_fill = remaining; |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_suppressed++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
|
|
|
|
std::vector<const Sample*> vbegin; |
|
|
|
|
|
|
|
vbegin.resize(m_nbStreams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) { |
|
|
|
|
|
|
|
vbegin[stream] = (const Sample*) &data[stream*byteCount]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
len = std::min(remaining, m_size - m_tail); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::copy(vbegin[stream], vbegin[stream] + len, m_data[stream].begin() + m_tail); |
|
|
|
|
|
|
|
vbegin[stream] += len; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_tail += len; |
|
|
|
|
|
|
|
m_tail %= m_size; |
|
|
|
|
|
|
|
m_fill += len; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_fill > 0) { |
|
|
|
|
|
|
|
emit dataSyncReady(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
emit dataSyncReady(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::writeSync(std::vector<SampleVector::const_iterator> vbegin, unsigned int count) |
|
|
|
void SampleMIFifo::writeSync(const std::vector<SampleVector::const_iterator>& vbegin, unsigned int size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ((vbegin.size() != m_nbStreams)) { |
|
|
|
if ((m_data.size() == 0) || (m_data.size() != vbegin.size())) { |
|
|
|
return 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
unsigned int total; |
|
|
|
unsigned int spaceLeft = m_size - m_fill; |
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = std::min(count, m_size - m_fill); |
|
|
|
if (size < spaceLeft) |
|
|
|
|
|
|
|
|
|
|
|
if (total < count) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_suppressed < 0) |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) { |
|
|
|
{ |
|
|
|
std::copy(vbegin[stream], vbegin[stream] + size, m_data[stream].begin() + m_fill); |
|
|
|
m_suppressed = 0; |
|
|
|
} |
|
|
|
m_msgRateTimer.start(); |
|
|
|
|
|
|
|
qCritical("SampleMIFifo::writeSync: overflow - dropping %u samples", count - total); |
|
|
|
m_fill += size; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_msgRateTimer.elapsed() > 2500) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qCritical("SampleMIFifo::writeSync: %u messages dropped", m_suppressed); |
|
|
|
|
|
|
|
qCritical("SampleMIFifo::writeSync: overflow - dropping %u samples", count - total); |
|
|
|
|
|
|
|
m_suppressed = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_suppressed++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - m_tail); |
|
|
|
unsigned int remaining = size - spaceLeft; |
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::copy(vbegin[stream], vbegin[stream] + len, m_data[stream].begin() + m_tail); |
|
|
|
std::copy(vbegin[stream], vbegin[stream] + spaceLeft, m_data[stream].begin() + m_fill); |
|
|
|
vbegin[stream] += len; |
|
|
|
std::copy(vbegin[stream] + spaceLeft, vbegin[stream] + size, m_data[stream].begin()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_tail += len; |
|
|
|
m_fill = remaining; |
|
|
|
m_tail %= m_size; |
|
|
|
|
|
|
|
m_fill += len; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_fill > 0) { |
|
|
|
|
|
|
|
emit dataSyncReady(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
emit dataSyncReady(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::readSync(unsigned int count, |
|
|
|
void SampleMIFifo::readSync( |
|
|
|
std::vector<SampleVector::const_iterator*> vpart1Begin, std::vector<SampleVector::const_iterator*> vpart1End, |
|
|
|
std::vector<SampleVector::const_iterator*> vpart1Begin, std::vector<SampleVector::const_iterator*> vpart1End, |
|
|
|
std::vector<SampleVector::const_iterator*> vpart2Begin, std::vector<SampleVector::const_iterator*> vpart2End) |
|
|
|
std::vector<SampleVector::const_iterator*> vpart2Begin, std::vector<SampleVector::const_iterator*> vpart2End |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ((vpart1Begin.size() != m_nbStreams) |
|
|
|
if (m_data.size() == 0) { |
|
|
|
|| (vpart2Begin.size() != m_nbStreams) |
|
|
|
return; |
|
|
|
|| (vpart1End.size() != m_nbStreams) |
|
|
|
|
|
|
|
|| (vpart2End.size() != m_nbStreams)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
unsigned int total; |
|
|
|
|
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
unsigned int head = m_head; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = std::min(count, m_fill); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (total < count) { |
|
|
|
|
|
|
|
qCritical("SampleMIFifo::readSync: underflow - missing %u samples", count - total); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
std::vector<SampleVector>::iterator dataIt = m_data.begin(); |
|
|
|
if (remaining > 0) |
|
|
|
vpart1Begin.resize(m_nbStreams); |
|
|
|
{ |
|
|
|
vpart1End.resize(m_nbStreams); |
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
vpart2Begin.resize(m_nbStreams); |
|
|
|
|
|
|
|
vpart2End.resize(m_nbStreams); |
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*vpart1Begin[stream] = m_data[stream].begin() + head; |
|
|
|
|
|
|
|
*vpart1End[stream] = m_data[stream].begin() + head + len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head += len; |
|
|
|
|
|
|
|
head %= m_size; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*vpart1Begin[stream] = m_data[stream].end(); |
|
|
|
|
|
|
|
*vpart1End[stream] = m_data[stream].end(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (remaining > 0) |
|
|
|
if (m_head < m_fill) |
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
*vpart2Begin[stream] = m_data[stream].begin() + head; |
|
|
|
*vpart1Begin[stream] = m_data[stream].begin() + m_head; |
|
|
|
*vpart2End[stream] = m_data[stream].begin() + head + len; |
|
|
|
*vpart1End[stream] = m_data[stream].begin() + m_fill; |
|
|
|
|
|
|
|
*vpart2Begin[stream] = m_data[stream].end(); |
|
|
|
|
|
|
|
*vpart2End[stream] = m_data[stream].end(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (unsigned int stream = 0; stream < m_nbStreams; stream++) |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
*vpart2Begin[stream] = m_data[stream].end(); |
|
|
|
*vpart1Begin[stream] = m_data[stream].begin() + m_head; |
|
|
|
*vpart2End[stream] = m_data[stream].end(); |
|
|
|
*vpart1End[stream] = m_data[stream].end(); |
|
|
|
|
|
|
|
*vpart2Begin[stream] = m_data[stream].begin(); |
|
|
|
|
|
|
|
*vpart2End[stream] = m_data[stream].begin() + m_fill; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
m_head = m_fill; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::readSync(unsigned int count, |
|
|
|
void SampleMIFifo::readSync( |
|
|
|
int& ipart1Begin, int& ipart1End, |
|
|
|
std::vector<unsigned int>& vpart1Begin, std::vector<unsigned int>& vpart1End, |
|
|
|
int& ipart2Begin, int& ipart2End) |
|
|
|
std::vector<unsigned int>& vpart2Begin, std::vector<unsigned int>& vpart2End |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
if (m_data.size() == 0) { |
|
|
|
unsigned int total; |
|
|
|
return; |
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
unsigned int head = m_head; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total = std::min(count, m_fill); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (total < count) { |
|
|
|
|
|
|
|
qCritical("SampleMIFifo::readSync: underflow - missing %u samples", count - total); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
std::vector<SampleVector>::iterator dataIt = m_data.begin(); |
|
|
|
|
|
|
|
vpart1Begin.resize(m_nbStreams); |
|
|
|
|
|
|
|
vpart1End.resize(m_nbStreams); |
|
|
|
|
|
|
|
vpart2Begin.resize(m_nbStreams); |
|
|
|
|
|
|
|
vpart2End.resize(m_nbStreams); |
|
|
|
|
|
|
|
|
|
|
|
if (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
|
|
|
|
ipart1Begin = head; |
|
|
|
|
|
|
|
ipart1End =head + len; |
|
|
|
|
|
|
|
head += len; |
|
|
|
|
|
|
|
head %= m_size; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ipart1Begin = m_size; |
|
|
|
|
|
|
|
ipart1End = m_size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (remaining > 0) |
|
|
|
if (m_head < m_fill) |
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
ipart2Begin = head; |
|
|
|
{ |
|
|
|
ipart2End = head + len; |
|
|
|
vpart1Begin[stream] = m_head; |
|
|
|
} |
|
|
|
vpart1End[stream] = m_fill; |
|
|
|
|
|
|
|
vpart2Begin[stream] = 0; |
|
|
|
|
|
|
|
vpart2End[stream] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
ipart2Begin = m_size; |
|
|
|
for (unsigned int stream = 0; stream < m_data.size(); stream++) |
|
|
|
ipart2End = m_size; |
|
|
|
{ |
|
|
|
} |
|
|
|
vpart1Begin[stream] = m_head; |
|
|
|
|
|
|
|
vpart1End[stream] = m_size; |
|
|
|
|
|
|
|
vpart2Begin[stream] = 0; |
|
|
|
|
|
|
|
vpart2End[stream] = m_fill; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
m_head = m_fill; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::readCommitSync(unsigned int count) |
|
|
|
void SampleMIFifo::readSync( |
|
|
|
|
|
|
|
unsigned int& ipart1Begin, unsigned int& ipart1End, |
|
|
|
|
|
|
|
unsigned int& ipart2Begin, unsigned int& ipart2End |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
if (m_data.size() == 0) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (count > m_fill) |
|
|
|
if (m_head < m_fill) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qCritical("SampleMIFifo::readCommitSync: cannot commit more than available samples"); |
|
|
|
ipart1Begin = m_head; |
|
|
|
count = m_fill; |
|
|
|
ipart1End = m_fill; |
|
|
|
} |
|
|
|
ipart2Begin = 0; |
|
|
|
|
|
|
|
ipart2End = 0; |
|
|
|
m_head = (m_head + count) % m_size; |
|
|
|
} |
|
|
|
m_fill -= count; |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ipart1Begin = m_head; |
|
|
|
|
|
|
|
ipart1End = m_size; |
|
|
|
|
|
|
|
ipart2Begin = 0; |
|
|
|
|
|
|
|
ipart2End = m_fill; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return count; |
|
|
|
m_head = m_fill; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::writeAsync(const quint8* data, unsigned int count, unsigned int stream) |
|
|
|
void SampleMIFifo::writeAsync(const quint8* data, unsigned int count, unsigned int stream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
return 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
unsigned int total; |
|
|
|
unsigned int spaceLeft = m_size - m_vFill[stream]; |
|
|
|
unsigned int remaining; |
|
|
|
unsigned int size = count / sizeof(Sample); |
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
const Sample* begin = (const Sample*) data; |
|
|
|
|
|
|
|
count /= sizeof(Sample); |
|
|
|
|
|
|
|
total = std::min(count, m_size - m_vfill[stream]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (total < count) |
|
|
|
if (size < spaceLeft) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_vsuppressed[stream] < 0) |
|
|
|
std::copy(&data[stream*count], &data[stream*count] + count, m_data[stream].begin() + m_vFill[stream]); |
|
|
|
{ |
|
|
|
m_vFill[stream] += size; |
|
|
|
m_vsuppressed[stream] = 0; |
|
|
|
} |
|
|
|
m_msgRateTimer.start(); |
|
|
|
else |
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: overflow - dropping %u samples", stream, count - total); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_msgRateTimer.elapsed() > 2500) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: %u messages dropped", stream, m_vsuppressed[stream]); |
|
|
|
|
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: overflow - dropping %u samples", stream, count - total); |
|
|
|
|
|
|
|
m_vsuppressed[stream] = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_vsuppressed[stream]++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - m_vtail[stream]); |
|
|
|
unsigned int remaining = size - spaceLeft; |
|
|
|
std::copy(begin, begin + len, m_data[stream].begin() + m_vtail[stream]); |
|
|
|
unsigned int bytesLeft = spaceLeft * sizeof(Sample); |
|
|
|
begin += len; |
|
|
|
std::copy(&data[stream*count], &data[stream*count] + bytesLeft, m_data[stream].begin() + m_vFill[stream]); |
|
|
|
m_vtail[stream] += len; |
|
|
|
std::copy(&data[stream*count] + bytesLeft, &data[stream*count] + count, m_data[stream].begin()); |
|
|
|
m_vtail[stream] %= m_size; |
|
|
|
m_vFill[stream] = remaining; |
|
|
|
m_vfill[stream] += len; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_vfill[stream] > 0) { |
|
|
|
|
|
|
|
emit dataAsyncReady(stream); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
emit dataAsyncReady(stream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::writeAsync(SampleVector::const_iterator begin, unsigned int count, unsigned int stream) |
|
|
|
void SampleMIFifo::writeAsync(const SampleVector::const_iterator& begin, unsigned int size, unsigned int stream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
return 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
unsigned int total; |
|
|
|
int spaceLeft = m_data[stream].size() - m_vFill[stream]; |
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
total = std::min(count, m_size - m_vfill[stream]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (total < count) |
|
|
|
if (size < spaceLeft) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_vsuppressed[stream] < 0) |
|
|
|
std::copy(begin, begin + size, m_data[stream].begin() + m_vFill[stream]); |
|
|
|
{ |
|
|
|
m_vFill[stream] += size; |
|
|
|
m_vsuppressed[stream] = 0; |
|
|
|
} |
|
|
|
m_vmsgRateTimer[stream].start(); |
|
|
|
else |
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: overflow - dropping %u samples", stream, count - total); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_vmsgRateTimer[stream].elapsed() > 2500) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: %u messages dropped", stream, m_vsuppressed[stream]); |
|
|
|
|
|
|
|
qCritical("SampleSinkFifo::writeAsync[%u]: overflow - dropping %u samples", stream, count - total); |
|
|
|
|
|
|
|
m_vsuppressed[stream] = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_vsuppressed[stream]++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - m_vtail[stream]); |
|
|
|
int remaining = size - spaceLeft; |
|
|
|
std::copy(begin, begin + len, m_data[stream].begin() + m_vtail[stream]); |
|
|
|
std::copy(begin, begin + spaceLeft, m_data[stream].begin() + m_vFill[stream]); |
|
|
|
begin += len; |
|
|
|
std::copy(begin + spaceLeft, begin + size, m_data[stream].begin()); |
|
|
|
m_vtail[stream] += len; |
|
|
|
m_vFill[stream] = remaining; |
|
|
|
m_vtail[stream] %= m_size; |
|
|
|
|
|
|
|
m_vfill[stream] += len; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_vfill[stream] > 0) { |
|
|
|
|
|
|
|
emit dataAsyncReady(stream); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
emit dataAsyncReady(stream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::readAsync(unsigned int count, |
|
|
|
|
|
|
|
SampleVector::const_iterator* part1Begin, SampleVector::const_iterator* part1End, |
|
|
|
|
|
|
|
SampleVector::const_iterator* part2Begin, SampleVector::const_iterator* part2End, |
|
|
|
|
|
|
|
unsigned int stream) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
unsigned int total; |
|
|
|
|
|
|
|
unsigned int remaining; |
|
|
|
|
|
|
|
unsigned int len; |
|
|
|
|
|
|
|
unsigned int head = m_vhead[stream]; |
|
|
|
|
|
|
|
total = std::min(count, m_vfill[stream]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (total < count) { |
|
|
|
void SampleMIFifo::readAsync( |
|
|
|
qCritical("SampleSinkFifo::readAsync[%u]: underflow - missing %u samples", stream, count - total); |
|
|
|
SampleVector::const_iterator* part1Begin, SampleVector::const_iterator* part1End, |
|
|
|
|
|
|
|
SampleVector::const_iterator* part2Begin, SampleVector::const_iterator* part2End, |
|
|
|
|
|
|
|
unsigned int stream) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (stream >= m_data.size()) { |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remaining = total; |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
|
|
|
|
if (remaining > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
|
|
|
|
*part1Begin = m_data[stream].begin() + head; |
|
|
|
|
|
|
|
*part1End = m_data[stream].begin() + head + len; |
|
|
|
|
|
|
|
head += len; |
|
|
|
|
|
|
|
head %= m_size; |
|
|
|
|
|
|
|
remaining -= len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*part1Begin = m_data[stream].end(); |
|
|
|
|
|
|
|
*part1End = m_data[stream].end(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (remaining > 0) |
|
|
|
if (m_vHead[stream] < m_vFill[stream]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
len = std::min(remaining, m_size - head); |
|
|
|
*part1Begin = m_data[stream].begin() + m_vHead[stream]; |
|
|
|
*part2Begin = m_data[stream].begin() + head; |
|
|
|
*part1End = m_data[stream].begin() + m_vFill[stream]; |
|
|
|
*part2End = m_data[stream].begin() + head + len; |
|
|
|
*part2Begin = m_data[stream].begin(); |
|
|
|
} |
|
|
|
*part2End = m_data[stream].begin(); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
*part2Begin = m_data[stream].end(); |
|
|
|
*part1Begin = m_data[stream].begin() + m_vHead[stream]; |
|
|
|
*part2End = m_data[stream].end(); |
|
|
|
*part1End = m_data[stream].end(); |
|
|
|
} |
|
|
|
*part2Begin = m_data[stream].begin(); |
|
|
|
|
|
|
|
*part2End = m_data[stream].begin() + m_vFill[stream]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return total; |
|
|
|
m_vHead[stream] = m_vFill[stream]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int SampleMIFifo::readCommitAsync(unsigned int count, unsigned int stream) |
|
|
|
void SampleMIFifo::readAsync( |
|
|
|
|
|
|
|
unsigned int& ipart1Begin, unsigned int& ipart1End, |
|
|
|
|
|
|
|
unsigned int& ipart2Begin, unsigned int& ipart2End, |
|
|
|
|
|
|
|
unsigned int stream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (stream >= m_nbStreams) { |
|
|
|
if (stream >= m_data.size()) { |
|
|
|
return 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
QMutexLocker mutexLocker(&m_mutex); |
|
|
|
|
|
|
|
|
|
|
|
if (count > m_vfill[stream]) |
|
|
|
if (m_vHead[stream] < m_vFill[stream]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qCritical("SampleSinkFifo::readCommitAsync[%u]: cannot commit more than available samples", stream); |
|
|
|
ipart1Begin = m_vHead[stream]; |
|
|
|
count = m_vfill[stream]; |
|
|
|
ipart1End = m_vFill[stream]; |
|
|
|
} |
|
|
|
ipart2Begin = m_size; |
|
|
|
|
|
|
|
ipart2End = m_size; |
|
|
|
m_vhead[stream] = (m_vhead[stream] + count) % m_size; |
|
|
|
} |
|
|
|
m_vfill[stream] -= count; |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ipart1Begin = m_vHead[stream]; |
|
|
|
|
|
|
|
ipart1End = m_size; |
|
|
|
|
|
|
|
ipart2Begin = 0; |
|
|
|
|
|
|
|
ipart2End = m_vFill[stream]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return count; |
|
|
|
m_vHead[stream] = m_vFill[stream]; |
|
|
|
} |
|
|
|
} |