mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-04 18:48:34 -04:00
UDPSink plugin: UDP buffer dynamic allocation (still fixed value)
This commit is contained in:
parent
7ac1f9e8f1
commit
a66193f7fd
@ -259,12 +259,12 @@ bool UDPSink::handleMessage(const Message& cmd)
|
||||
m_sampleRateSum = 0.0;
|
||||
m_sampleRateAvgCounter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("UDPSink::handleMessage: MsgSampleRateCorrection: corr: %+.6f new rate: %.0f",
|
||||
cfg.getCorrectionFactor(),
|
||||
m_actualInputSampleRate);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// qDebug("UDPSink::handleMessage: MsgSampleRateCorrection: corr: %+.6f new rate: %.0f",
|
||||
// cfg.getCorrectionFactor(),
|
||||
// m_actualInputSampleRate);
|
||||
// }
|
||||
|
||||
m_settingsMutex.lock();
|
||||
m_interpolatorDistanceRemain = 0;
|
||||
|
@ -27,6 +27,8 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
|
||||
m_dataPort(9999),
|
||||
m_dataConnected(false),
|
||||
m_udpReadBytes(0),
|
||||
m_nbUDPFrames(m_minNbUDPFrames),
|
||||
m_nbAllocatedUDPFrames(m_minNbUDPFrames),
|
||||
m_writeIndex(0),
|
||||
m_readFrameIndex(m_minNbUDPFrames/2),
|
||||
m_readIndex(0),
|
||||
@ -34,10 +36,12 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
|
||||
m_d(0),
|
||||
m_feedbackMessageQueue(0)
|
||||
{
|
||||
m_udpBuf = new udpBlk_t[m_minNbUDPFrames];
|
||||
}
|
||||
|
||||
UDPSinkUDPHandler::~UDPSinkUDPHandler()
|
||||
{
|
||||
delete[] m_udpBuf;
|
||||
}
|
||||
|
||||
void UDPSinkUDPHandler::start()
|
||||
@ -102,7 +106,7 @@ void UDPSinkUDPHandler::moveData()
|
||||
{
|
||||
memcpy(m_udpBuf[m_writeIndex], m_udpTmpBuf, m_udpBlockSize);
|
||||
|
||||
if (m_writeIndex < m_minNbUDPFrames - 1) {
|
||||
if (m_writeIndex < m_nbUDPFrames - 1) {
|
||||
m_writeIndex++;
|
||||
} else {
|
||||
m_writeIndex = 0;
|
||||
@ -131,14 +135,14 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes)
|
||||
{
|
||||
m_readIndex = 0;
|
||||
|
||||
if (m_readFrameIndex < m_minNbUDPFrames - 1)
|
||||
if (m_readFrameIndex < m_nbUDPFrames - 1)
|
||||
{
|
||||
m_readFrameIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_rwDelta = m_writeIndex; // raw R/W delta estimate
|
||||
float d = (m_rwDelta - (m_minNbUDPFrames/2))/(float) m_minNbUDPFrames;
|
||||
float d = (m_rwDelta - (m_nbUDPFrames/2))/(float) m_nbUDPFrames;
|
||||
//qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d);
|
||||
|
||||
if ((d < -0.45) || (d > 0.45))
|
||||
@ -182,8 +186,26 @@ void UDPSinkUDPHandler::configureUDPLink(const QString& address, quint16 port)
|
||||
|
||||
void UDPSinkUDPHandler::resetReadIndex()
|
||||
{
|
||||
m_readFrameIndex = (m_writeIndex + (m_minNbUDPFrames/2)) % m_minNbUDPFrames;
|
||||
m_rwDelta = m_minNbUDPFrames/2;
|
||||
m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames;
|
||||
m_rwDelta = m_nbUDPFrames/2;
|
||||
m_readIndex = 0;
|
||||
m_d = 0.0f;
|
||||
}
|
||||
|
||||
void UDPSinkUDPHandler::resizeBuffer(float sampleRate)
|
||||
{
|
||||
int halfNbFrames = std::max((sampleRate / 375.0), (m_minNbUDPFrames / 2.0));
|
||||
qDebug("UDPSinkUDPHandler::resizeBuffer: nb_frames: %d", 2*halfNbFrames);
|
||||
|
||||
if (2*halfNbFrames > m_nbAllocatedUDPFrames)
|
||||
{
|
||||
delete[] m_udpBuf;
|
||||
m_udpBuf = new udpBlk_t[2*halfNbFrames];
|
||||
m_nbAllocatedUDPFrames = 2*halfNbFrames;
|
||||
}
|
||||
|
||||
m_nbUDPFrames = 2*halfNbFrames;
|
||||
m_writeIndex = 0;
|
||||
|
||||
resetReadIndex();
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
void stop();
|
||||
void configureUDPLink(const QString& address, quint16 port);
|
||||
void resetReadIndex();
|
||||
void resizeBuffer(float sampleRate);
|
||||
|
||||
void readSample(Real &t);
|
||||
void readSample(Sample &s);
|
||||
@ -49,8 +50,8 @@ public:
|
||||
*/
|
||||
inline int32_t getBufferGauge() const
|
||||
{
|
||||
int32_t val = m_rwDelta - (m_minNbUDPFrames/2);
|
||||
return (100*val) / m_minNbUDPFrames;
|
||||
int32_t val = m_rwDelta - (m_nbUDPFrames/2);
|
||||
return (100*val) / m_nbUDPFrames;
|
||||
}
|
||||
|
||||
static const int m_udpBlockSize = 512; // UDP block size in number of bytes
|
||||
@ -72,7 +73,9 @@ private:
|
||||
bool m_dataConnected;
|
||||
udpBlk_t m_udpTmpBuf;
|
||||
qint64 m_udpReadBytes;
|
||||
udpBlk_t m_udpBuf[m_minNbUDPFrames];
|
||||
udpBlk_t *m_udpBuf;
|
||||
int m_nbUDPFrames;
|
||||
int m_nbAllocatedUDPFrames;
|
||||
int m_writeIndex;
|
||||
int m_readFrameIndex;
|
||||
int m_readIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user