1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -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);
d.readS32(10, &s32tmp, 10);
ui->volume->setValue(s32tmp);
ui->volumeText->setText(tr("%1").arg(s32tmp/10.0, 0, 'f', 1));
d.readS32(11, &s32tmp, 2500);
ui->fmDeviation->setText(QString("%1").arg(s32tmp));

View File

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

View File

@ -49,17 +49,19 @@ public:
*/
inline int32_t getBufferGauge() const
{
int32_t val = m_rwDelta - (m_nbUDPFrames/2);
return (100*val) / m_nbUDPFrames;
int32_t val = m_rwDelta - (m_minNbUDPFrames/2);
return (100*val) / m_minNbUDPFrames;
}
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:
void dataReadyRead();
private:
typedef char (udpBlk_t)[m_udpBlockSize];
void moveData();
void advanceReadPointer(int nbBytes);
@ -68,9 +70,9 @@ private:
QHostAddress m_remoteAddress;
quint16 m_dataPort;
bool m_dataConnected;
char m_udpTmpBuf[m_udpBlockSize];
udpBlk_t m_udpTmpBuf;
qint64 m_udpReadBytes;
char m_udpBuf[m_nbUDPFrames][m_udpBlockSize];
udpBlk_t m_udpBuf[m_minNbUDPFrames];
int m_writeIndex;
int m_readFrameIndex;
int m_readIndex;