mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
Sdrdaemon: fixed SDRdaemon buffer read pointer update
This commit is contained in:
parent
07bfcb04dc
commit
d267d56de5
@ -37,7 +37,7 @@ SDRdaemonBuffer::SDRdaemonBuffer(uint32_t blockSize, uint32_t rateDivider) :
|
||||
m_sampleRate(1000000),
|
||||
m_sampleBytes(2),
|
||||
m_sampleBits(12),
|
||||
m_rawCount(0),
|
||||
m_writeCount(0),
|
||||
m_readCount(0),
|
||||
m_rawSize(0),
|
||||
m_rawBuffer(0),
|
||||
@ -141,26 +141,11 @@ void SDRdaemonBuffer::writeData(char *array, uint32_t length)
|
||||
}
|
||||
else
|
||||
{
|
||||
//writeDataUncompressed(array, length);
|
||||
writeToRawBufferUncompressed(array, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SDRdaemonBuffer::writeDataUncompressed(const char *array, uint32_t length)
|
||||
{
|
||||
if (m_inCount + length < m_frameSize)
|
||||
{
|
||||
std::memcpy((void *) &m_rawBuffer[m_rawCount], (const void *) array, length);
|
||||
m_inCount += length;
|
||||
}
|
||||
else if (m_inCount < m_frameSize)
|
||||
{
|
||||
std::memcpy((void *) &m_rawBuffer[m_rawCount], (const void *) array, m_frameSize - m_inCount); // copy rest of data in compressed Buffer
|
||||
m_inCount += m_frameSize - m_inCount;
|
||||
}
|
||||
}
|
||||
|
||||
void SDRdaemonBuffer::writeDataLZ4(const char *array, uint32_t length)
|
||||
{
|
||||
if (m_lz4InCount + length < m_lz4InSize)
|
||||
@ -197,7 +182,7 @@ void SDRdaemonBuffer::writeDataLZ4(const char *array, uint32_t length)
|
||||
m_nbCRCOK++;
|
||||
}
|
||||
|
||||
int compressedSize = LZ4_decompress_fast((const char*) m_lz4InBuffer, (char*) &m_rawBuffer[m_rawCount], m_frameSize);
|
||||
int compressedSize = LZ4_decompress_fast((const char*) m_lz4InBuffer, (char*) &m_rawBuffer[m_writeCount], m_frameSize);
|
||||
m_nbDecodes++;
|
||||
|
||||
if (compressedSize == m_lz4InSize)
|
||||
@ -214,16 +199,16 @@ void SDRdaemonBuffer::writeDataLZ4(const char *array, uint32_t length)
|
||||
void SDRdaemonBuffer::writeToRawBufferUncompressed(const char *array, uint32_t length)
|
||||
{
|
||||
// TODO: handle the 1 byte per I or Q sample
|
||||
if (m_rawCount + length < m_rawSize)
|
||||
if (m_writeCount + length < m_rawSize)
|
||||
{
|
||||
std::memcpy((void *) &m_rawBuffer[m_rawCount], (const void *) array, length);
|
||||
m_rawCount += length;
|
||||
std::memcpy((void *) &m_rawBuffer[m_writeCount], (const void *) array, length);
|
||||
m_writeCount += length;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy((void *) &m_rawBuffer[m_rawCount], (const void *) array, m_rawSize - m_rawCount);
|
||||
m_rawCount = length - (m_rawSize - m_rawCount);
|
||||
std::memcpy((void *) m_rawBuffer, (const void *) &array[m_rawSize - m_rawCount], m_rawCount);
|
||||
std::memcpy((void *) &m_rawBuffer[m_writeCount], (const void *) array, m_rawSize - m_writeCount);
|
||||
m_writeCount = length - (m_rawSize - m_writeCount);
|
||||
std::memcpy((void *) m_rawBuffer, (const void *) &array[m_rawSize - m_writeCount], m_writeCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,17 +227,16 @@ void SDRdaemonBuffer::writeToRawBufferLZ4(const char *array, uint32_t length)
|
||||
|
||||
uint8_t *SDRdaemonBuffer::readData(uint32_t length)
|
||||
{
|
||||
uint32_t readCount = m_readCount;
|
||||
|
||||
if (m_readCount + length < m_rawSize)
|
||||
{
|
||||
return &m_rawBuffer[readCount];
|
||||
uint32_t readCount = m_readCount;
|
||||
m_readCount += length;
|
||||
return &m_rawBuffer[readCount];
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t retLength = std::min(length, m_chunkSize);
|
||||
std::memcpy((void *) m_chunkBuffer, (const void *) &m_rawBuffer[readCount], m_rawSize - m_readCount); // read last bit from raw buffer
|
||||
std::memcpy((void *) m_chunkBuffer, (const void *) &m_rawBuffer[m_readCount], m_rawSize - m_readCount); // read last bit from raw buffer
|
||||
m_readCount = retLength - (m_rawSize - m_readCount);
|
||||
std::memcpy((void *) &m_chunkBuffer[m_rawSize - m_readCount], (const void *) m_rawBuffer, m_readCount); // read the rest at start of raw buffer
|
||||
return m_chunkBuffer;
|
||||
|
@ -73,7 +73,6 @@ public:
|
||||
private:
|
||||
void updateLZ4Sizes(uint32_t frameSize);
|
||||
void writeDataLZ4(const char *array, uint32_t length);
|
||||
void writeDataUncompressed(const char *array, uint32_t length);
|
||||
void writeToRawBufferLZ4(const char *array, uint32_t originalLength);
|
||||
void writeToRawBufferUncompressed(const char *array, uint32_t length);
|
||||
void updateBufferSize(uint32_t sampleRate, uint32_t frameSize);
|
||||
@ -101,7 +100,7 @@ private:
|
||||
uint8_t m_sampleBytes; //!< Current number of bytes per I or Q sample
|
||||
uint8_t m_sampleBits; //!< Current number of effective bits per sample
|
||||
|
||||
uint32_t m_rawCount; //!< Current write position in the raw samples buffer
|
||||
uint32_t m_writeCount; //!< Current write position in the raw samples buffer
|
||||
uint32_t m_readCount; //!< Current read position in the raw samples buffer
|
||||
uint32_t m_rawSize; //!< Size of the raw samples buffer in bytes
|
||||
uint8_t *m_rawBuffer; //!< Buffer for raw samples obtained from UDP (I/Q not in a formal I/Q structure)
|
||||
|
@ -26,7 +26,6 @@ const int SDRdaemonUDPHandler::m_rateDivider = 1000/SDRDAEMON_THROTTLE_MS;
|
||||
const int SDRdaemonUDPHandler::m_udpPayloadSize = 512;
|
||||
|
||||
SDRdaemonUDPHandler::SDRdaemonUDPHandler(SampleFifo *sampleFifo, MessageQueue *outputMessageQueueToGUI) :
|
||||
m_mutex(QMutex::Recursive),
|
||||
m_sdrDaemonBuffer(m_udpPayloadSize, m_rateDivider),
|
||||
m_dataSocket(0),
|
||||
m_dataAddress(QHostAddress::LocalHost),
|
||||
@ -67,7 +66,6 @@ void SDRdaemonUDPHandler::start()
|
||||
if (m_dataSocket->bind(m_dataAddress, m_dataPort))
|
||||
{
|
||||
qDebug("SDRdaemonUDPHandler::start: bind data socket to port %d", m_dataPort);
|
||||
connect(this, SIGNAL(dataReady()), this, SLOT(processData()));
|
||||
connect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()), Qt::QueuedConnection); // , Qt::QueuedConnection
|
||||
m_dataConnected = true;
|
||||
}
|
||||
@ -85,7 +83,6 @@ void SDRdaemonUDPHandler::stop()
|
||||
|
||||
if (m_dataConnected) {
|
||||
disconnect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
|
||||
disconnect(this, SIGNAL(dataReady()), this, SLOT(processData));
|
||||
m_dataConnected = false;
|
||||
}
|
||||
|
||||
@ -104,7 +101,7 @@ void SDRdaemonUDPHandler::dataReadyRead()
|
||||
{
|
||||
qint64 pendingDataSize = m_dataSocket->pendingDatagramSize();
|
||||
m_udpReadBytes = m_dataSocket->readDatagram(m_udpBuf, pendingDataSize, 0, 0);
|
||||
emit dataReady();
|
||||
processData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,8 +113,6 @@ void SDRdaemonUDPHandler::processData()
|
||||
}
|
||||
else if (m_udpReadBytes > 0)
|
||||
{
|
||||
QMutexLocker ml(&m_mutex);
|
||||
|
||||
m_sdrDaemonBuffer.updateBlockCounts(m_udpReadBytes);
|
||||
|
||||
if (m_sdrDaemonBuffer.readMeta(m_udpBuf, m_udpReadBytes))
|
||||
@ -165,8 +160,6 @@ void SDRdaemonUDPHandler::setSamplerate(uint32_t samplerate)
|
||||
<< " new:" << samplerate
|
||||
<< " old:" << m_samplerate;
|
||||
|
||||
QMutexLocker ml(&m_mutex);
|
||||
|
||||
m_samplerate = samplerate;
|
||||
m_chunksize = (m_samplerate / m_rateDivider)*4; // TODO: implement FF and slow motion here. 4 corresponds to live. 2 is half speed, 8 is doulbe speed
|
||||
m_bufsize = m_chunksize;
|
||||
|
@ -41,13 +41,8 @@ public:
|
||||
|
||||
public slots:
|
||||
void dataReadyRead();
|
||||
void processData();
|
||||
|
||||
signals:
|
||||
void dataReady();
|
||||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
SDRdaemonBuffer m_sdrDaemonBuffer;
|
||||
QUdpSocket *m_dataSocket;
|
||||
QHostAddress m_dataAddress;
|
||||
@ -71,6 +66,7 @@ private:
|
||||
static const int m_udpPayloadSize;
|
||||
|
||||
void setSamplerate(uint32_t samplerate);
|
||||
void processData();
|
||||
|
||||
private slots:
|
||||
void tick();
|
||||
|
Loading…
Reference in New Issue
Block a user