Remote source first fixes

This commit is contained in:
f4exb 2021-12-10 23:40:28 +01:00
parent 8715f4c037
commit f7f5f4b2dd
6 changed files with 34 additions and 31 deletions

View File

@ -31,6 +31,7 @@ RemoteSourceSource::RemoteSourceSource() :
connect(&m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()), Qt::QueuedConnection);
m_cm256p = m_cm256.isInitialized() ? &m_cm256 : 0;
m_currentMeta.init();
m_dataReadQueue.setSize(50);
applyChannelSettings(m_channelSampleRate, true);
}
@ -52,7 +53,7 @@ void RemoteSourceSource::pull(SampleVector::iterator begin, unsigned int nbSampl
void RemoteSourceSource::pullOne(Sample& sample)
{
m_dataReadQueue.readSample(sample, true); // true is scale for Tx
// m_dataReadQueue.readSample(sample, true); // true is scale for Tx
Complex ci;
@ -130,14 +131,13 @@ void RemoteSourceSource::handleData()
{
RemoteDataBlock* dataBlock;
while (m_running && ((dataBlock = m_dataQueue.pop()) != 0)) {
while (m_running && ((dataBlock = m_dataQueue.pop()) != nullptr)) {
handleDataBlock(dataBlock);
}
}
void RemoteSourceSource::handleDataBlock(RemoteDataBlock* dataBlock)
{
(void) dataBlock;
if (dataBlock->m_rxControlBlock.m_blockCount < RemoteNbOrginalBlocks)
{
qWarning("RemoteSourceSource::handleDataBlock: incomplete data block: not processing");
@ -271,10 +271,11 @@ void RemoteSourceSource::applyChannelSettings(int channelSampleRate, bool force)
if ((channelSampleRate != m_channelSampleRate) || force)
{
uint32_t metaSampleRate = m_currentMeta.m_sampleRate == 0 ? channelSampleRate : m_currentMeta.m_sampleRate;
m_interpolatorDistanceRemain = 0;
m_interpolatorConsumed = false;
m_interpolatorDistance = (Real) m_currentMeta.m_sampleRate / (Real) channelSampleRate;
m_interpolator.create(48, m_currentMeta.m_sampleRate, m_currentMeta.m_sampleRate / 2.2, 3.0);
m_interpolatorDistance = (Real) metaSampleRate / (Real) channelSampleRate;
m_interpolator.create(48, metaSampleRate, metaSampleRate / 2.2, 3.0);
}
m_channelSampleRate = channelSampleRate;

View File

@ -99,7 +99,7 @@ void RemoteSourceWorker::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
while ((message = m_inputMessageQueue.pop()) != nullptr)
{
if (MsgDataBind::match(*message))
{
@ -107,6 +107,7 @@ void RemoteSourceWorker::handleInputMessages()
MsgDataBind* notif = (MsgDataBind*) message;
qDebug("RemoteSourceWorker::handleInputMessages: MsgDataBind: %s:%d", qPrintable(notif->getAddress().toString()), notif->getPort());
disconnect(&m_socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
m_socket.abort();
m_socket.bind(notif->getAddress(), notif->getPort());
connect(&m_socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}

View File

@ -30,7 +30,8 @@
RemoteDataQueue::RemoteDataQueue(QObject* parent) :
QObject(parent),
m_lock(QMutex::Recursive),
m_queue()
m_queue(),
m_count(0)
{
}
@ -38,7 +39,7 @@ RemoteDataQueue::~RemoteDataQueue()
{
RemoteDataBlock* data;
while ((data = pop()) != 0)
while ((data = pop()) != nullptr)
{
qDebug() << "RemoteDataQueue::~RemoteDataQueue: data block was still in queue";
delete data;
@ -50,12 +51,13 @@ void RemoteDataQueue::push(RemoteDataBlock* data, bool emitSignal)
if (data)
{
m_lock.lock();
m_queue.append(data);
m_queue.enqueue(data);
m_count++;
// qDebug("RemoteDataQueue::push: %d %d", m_count, m_queue.size());
m_lock.unlock();
}
if (emitSignal)
{
if (emitSignal) {
emit dataBlockEnqueued();
}
}
@ -64,13 +66,11 @@ RemoteDataBlock* RemoteDataQueue::pop()
{
QMutexLocker locker(&m_lock);
if (m_queue.isEmpty())
{
return 0;
}
else
{
return m_queue.takeFirst();
if (m_queue.isEmpty()) {
return nullptr;
} else {
m_count--;
return m_queue.dequeue();
}
}

View File

@ -52,6 +52,7 @@ signals:
private:
QMutex m_lock;
QQueue<RemoteDataBlock*> m_queue;
int m_count;
};
#endif /* CHANNEL_REMOTEDATAQUEUE_H_ */

View File

@ -28,7 +28,7 @@
const uint32_t RemoteDataReadQueue::MinimumMaxSize = 10;
RemoteDataReadQueue::RemoteDataReadQueue() :
m_dataBlock(0),
m_dataBlock(nullptr),
m_maxSize(MinimumMaxSize),
m_blockIndex(1),
m_sampleIndex(0),
@ -40,7 +40,7 @@ RemoteDataReadQueue::~RemoteDataReadQueue()
{
RemoteDataBlock* data;
while ((data = pop()) != 0)
while ((data = pop()) != nullptr)
{
qDebug("RemoteDataReadQueue::~RemoteDataReadQueue: data block was still in queue");
delete data;
@ -58,11 +58,11 @@ void RemoteDataReadQueue::push(RemoteDataBlock* dataBlock)
}
if (m_full) {
m_full = (length() > m_maxSize/2); // do not fill queue again before queue is half size
m_full = (length() > m_maxSize/10); // do not fill queue again before queue is half size
}
if (!m_full) {
m_dataReadQueue.append(dataBlock);
m_dataReadQueue.enqueue(dataBlock);
}
}
@ -70,14 +70,14 @@ RemoteDataBlock* RemoteDataReadQueue::pop()
{
if (m_dataReadQueue.isEmpty())
{
return 0;
return nullptr;
}
else
{
m_blockIndex = 1;
m_sampleIndex = 0;
return m_dataReadQueue.takeFirst();
return m_dataReadQueue.dequeue();
}
}
@ -91,13 +91,13 @@ void RemoteDataReadQueue::setSize(uint32_t size)
void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
{
// depletion/repletion state
if (m_dataBlock == 0)
if (m_dataBlock == nullptr)
{
if (length() >= m_maxSize/2)
if (length() >= m_maxSize/10)
{
qDebug("RemoteDataReadQueue::readSample: initial pop new block: queue size: %u", length());
m_blockIndex = 1;
m_dataBlock = m_dataReadQueue.takeFirst();
m_dataBlock = m_dataReadQueue.dequeue();
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
m_sampleIndex++;
m_sampleCount++;
@ -133,7 +133,7 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
else
{
delete m_dataBlock;
m_dataBlock = 0;
m_dataBlock = nullptr;
if (length() == 0) {
qWarning("RemoteDataReadQueue::readSample: try to pop new block but queue is empty");
@ -141,9 +141,8 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
if (length() > 0)
{
//qDebug("RemoteDataReadQueue::readSample: pop new block: queue size: %u", length());
m_blockIndex = 1;
m_dataBlock = m_dataReadQueue.takeFirst();
m_dataBlock = m_dataReadQueue.dequeue();
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
m_sampleIndex++;
m_sampleCount++;

View File

@ -39,7 +39,6 @@ public:
~RemoteDataReadQueue();
void push(RemoteDataBlock* dataBlock); //!< push block on the queue
RemoteDataBlock* pop(); //!< Pop block from the queue
void readSample(Sample& s, bool scaleForTx = false); //!< Read sample from queue possibly scaling to Tx size
uint32_t length() const { return m_dataReadQueue.size(); } //!< Returns queue length
uint32_t size() const { return m_maxSize; } //!< Returns queue size (max length)
@ -57,6 +56,8 @@ private:
uint32_t m_sampleCount; //!< use a counter capped below 2^31 as it is going to be converted to an int in the web interface
bool m_full; //!< full condition was hit
RemoteDataBlock* pop(); //!< Pop block from the queue
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
{
int sampleSize = m_dataBlock->m_superBlocks[blockIndex].m_header.m_sampleBytes * 2; // I/Q sample size in data block