1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-04 16:01:14 -05:00

UDPSink plugin: typedef for UDP block buffer

This commit is contained in:
f4exb 2017-08-17 00:38:08 +02:00
parent af5103552c
commit 7ac1f9e8f1
3 changed files with 15 additions and 12 deletions

View File

@ -166,6 +166,7 @@ bool UDPSinkGUI::deserialize(const QByteArray& data)
ui->udpAddress->setText(strtmp); ui->udpAddress->setText(strtmp);
d.readS32(10, &s32tmp, 10); d.readS32(10, &s32tmp, 10);
ui->volume->setValue(s32tmp); ui->volume->setValue(s32tmp);
ui->volumeText->setText(tr("%1").arg(s32tmp/10.0, 0, 'f', 1));
d.readS32(11, &s32tmp, 2500); d.readS32(11, &s32tmp, 2500);
ui->fmDeviation->setText(QString("%1").arg(s32tmp)); ui->fmDeviation->setText(QString("%1").arg(s32tmp));

View File

@ -28,9 +28,9 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
m_dataConnected(false), m_dataConnected(false),
m_udpReadBytes(0), m_udpReadBytes(0),
m_writeIndex(0), m_writeIndex(0),
m_readFrameIndex(m_nbUDPFrames/2), m_readFrameIndex(m_minNbUDPFrames/2),
m_readIndex(0), m_readIndex(0),
m_rwDelta(m_nbUDPFrames/2), m_rwDelta(m_minNbUDPFrames/2),
m_d(0), m_d(0),
m_feedbackMessageQueue(0) m_feedbackMessageQueue(0)
{ {
@ -102,7 +102,7 @@ void UDPSinkUDPHandler::moveData()
{ {
memcpy(m_udpBuf[m_writeIndex], m_udpTmpBuf, m_udpBlockSize); memcpy(m_udpBuf[m_writeIndex], m_udpTmpBuf, m_udpBlockSize);
if (m_writeIndex < m_nbUDPFrames - 1) { if (m_writeIndex < m_minNbUDPFrames - 1) {
m_writeIndex++; m_writeIndex++;
} else { } else {
m_writeIndex = 0; m_writeIndex = 0;
@ -131,14 +131,14 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes)
{ {
m_readIndex = 0; m_readIndex = 0;
if (m_readFrameIndex < m_nbUDPFrames - 1) if (m_readFrameIndex < m_minNbUDPFrames - 1)
{ {
m_readFrameIndex++; m_readFrameIndex++;
} }
else else
{ {
m_rwDelta = m_writeIndex; // raw R/W delta estimate m_rwDelta = m_writeIndex; // raw R/W delta estimate
float d = (m_rwDelta - (m_nbUDPFrames/2))/(float) m_nbUDPFrames; float d = (m_rwDelta - (m_minNbUDPFrames/2))/(float) m_minNbUDPFrames;
//qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d); //qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d);
if ((d < -0.45) || (d > 0.45)) if ((d < -0.45) || (d > 0.45))
@ -182,8 +182,8 @@ void UDPSinkUDPHandler::configureUDPLink(const QString& address, quint16 port)
void UDPSinkUDPHandler::resetReadIndex() void UDPSinkUDPHandler::resetReadIndex()
{ {
m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames; m_readFrameIndex = (m_writeIndex + (m_minNbUDPFrames/2)) % m_minNbUDPFrames;
m_rwDelta = m_nbUDPFrames/2; m_rwDelta = m_minNbUDPFrames/2;
m_readIndex = 0; m_readIndex = 0;
m_d = 0.0f; m_d = 0.0f;
} }

View File

@ -49,17 +49,19 @@ public:
*/ */
inline int32_t getBufferGauge() const inline int32_t getBufferGauge() const
{ {
int32_t val = m_rwDelta - (m_nbUDPFrames/2); int32_t val = m_rwDelta - (m_minNbUDPFrames/2);
return (100*val) / m_nbUDPFrames; return (100*val) / m_minNbUDPFrames;
} }
static const int m_udpBlockSize = 512; // UDP block size in number of bytes static const int m_udpBlockSize = 512; // UDP block size in number of bytes
static const int m_nbUDPFrames = 256; // number of frames of block size in the UDP buffer static const int m_minNbUDPFrames = 256; // number of frames of block size in the UDP buffer
public slots: public slots:
void dataReadyRead(); void dataReadyRead();
private: private:
typedef char (udpBlk_t)[m_udpBlockSize];
void moveData(); void moveData();
void advanceReadPointer(int nbBytes); void advanceReadPointer(int nbBytes);
@ -68,9 +70,9 @@ private:
QHostAddress m_remoteAddress; QHostAddress m_remoteAddress;
quint16 m_dataPort; quint16 m_dataPort;
bool m_dataConnected; bool m_dataConnected;
char m_udpTmpBuf[m_udpBlockSize]; udpBlk_t m_udpTmpBuf;
qint64 m_udpReadBytes; qint64 m_udpReadBytes;
char m_udpBuf[m_nbUDPFrames][m_udpBlockSize]; udpBlk_t m_udpBuf[m_minNbUDPFrames];
int m_writeIndex; int m_writeIndex;
int m_readFrameIndex; int m_readFrameIndex;
int m_readIndex; int m_readIndex;