SDRDaemon: anonymize protected block

This commit is contained in:
f4exb 2018-09-10 18:52:40 +02:00
parent 6341bddef3
commit 1590db3ce2
8 changed files with 60 additions and 24 deletions

View File

@ -82,7 +82,8 @@ DaemonSink::~DaemonSink()
void DaemonSink::setTxDelay(int txDelay, int nbBlocksFEC)
{
double txDelayRatio = txDelay / 100.0;
double delay = m_sampleRate == 0 ? 1.0 : (127*SDRDaemonSamplesPerBlock*txDelayRatio) / m_sampleRate;
int samplesPerBlock = SDRDaemonNbBytesPerBlock / sizeof(Sample);
double delay = m_sampleRate == 0 ? 1.0 : (127*samplesPerBlock*txDelayRatio) / m_sampleRate;
delay /= 128 + nbBlocksFEC;
m_txDelay = roundf(delay*1e6); // microseconds
qDebug() << "DaemonSink::setTxDelay:"
@ -152,10 +153,11 @@ void DaemonSink::feed(const SampleVector::const_iterator& begin, const SampleVec
m_txBlockIndex = 1; // next Tx block with data
} // block zero
// TODO: handle different sample sizes...
if (m_sampleIndex + inRemainingSamples < SDRDaemonSamplesPerBlock) // there is still room in the current super block
// handle different sample sizes...
int samplesPerBlock = SDRDaemonNbBytesPerBlock / sizeof(Sample);
if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
{
memcpy((void *) &m_superBlock.m_protectedBlock.m_samples[m_sampleIndex],
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
inRemainingSamples * sizeof(Sample));
m_sampleIndex += inRemainingSamples;
@ -163,10 +165,10 @@ void DaemonSink::feed(const SampleVector::const_iterator& begin, const SampleVec
}
else // complete super block and initiate the next if not end of frame
{
memcpy((void *) &m_superBlock.m_protectedBlock.m_samples[m_sampleIndex],
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
(SDRDaemonSamplesPerBlock - m_sampleIndex) * sizeof(Sample));
it += SDRDaemonSamplesPerBlock - m_sampleIndex;
(samplesPerBlock - m_sampleIndex) * sizeof(Sample));
it += samplesPerBlock - m_sampleIndex;
m_sampleIndex = 0;
m_superBlock.m_header.m_frameIndex = m_frameCount;

View File

@ -287,7 +287,8 @@ void DaemonSinkGUI::on_nbFECBlocks_valueChanged(int value)
void DaemonSinkGUI::updateTxDelayTime()
{
double txDelayRatio = m_settings.m_txDelay / 100.0;
double delay = m_sampleRate == 0 ? 0.0 : (127*SDRDaemonSamplesPerBlock*txDelayRatio) / m_sampleRate;
int samplesPerBlock = SDRDaemonNbBytesPerBlock / sizeof(Sample);
double delay = m_sampleRate == 0 ? 0.0 : (127*samplesPerBlock*txDelayRatio) / m_sampleRate;
delay /= 128 + m_settings.m_nbFECBlocks;
ui->txDelayTime->setText(tr("%1µs").arg(QString::number(delay*1e6, 'f', 0)));
}

View File

@ -46,6 +46,7 @@ DaemonSrc::DaemonSrc(DeviceSinkAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_sourceThread(0),
m_running(false),
m_dataReadQueue(SDR_TX_SAMP_SZ <= 16 ? 4 : 8),
m_nbCorrectableErrors(0),
m_nbUncorrectableErrors(0)
{

View File

@ -147,10 +147,11 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const
m_txBlockIndex = 1; // next Tx block with data
} // block zero
// TODO: handle different sample sizes...
if (m_sampleIndex + inRemainingSamples < SDRDaemonSamplesPerBlock) // there is still room in the current super block
// handle different sample sizes...
int samplesPerBlock = SDRDaemonNbBytesPerBlock / sizeof(Sample);
if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
{
memcpy((void *) &m_superBlock.m_protectedBlock.m_samples[m_sampleIndex],
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
inRemainingSamples * sizeof(Sample));
m_sampleIndex += inRemainingSamples;
@ -158,10 +159,10 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const
}
else // complete super block and initiate the next if not end of frame
{
memcpy((void *) &m_superBlock.m_protectedBlock.m_samples[m_sampleIndex],
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
(SDRDaemonSamplesPerBlock - m_sampleIndex) * sizeof(Sample));
it += SDRDaemonSamplesPerBlock - m_sampleIndex;
(samplesPerBlock - m_sampleIndex) * sizeof(Sample));
it += samplesPerBlock - m_sampleIndex;
m_sampleIndex = 0;
m_superBlock.m_header.m_frameIndex = m_frameCount;

View File

@ -50,6 +50,7 @@ SDRDaemonChannelSource::SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_sourceThread(0),
m_running(false),
m_dataReadQueue(SDR_TX_SAMP_SZ <= 16 ? 4 : 8),
m_nbCorrectableErrors(0),
m_nbUncorrectableErrors(0)
{

View File

@ -83,14 +83,14 @@ struct SDRDaemonHeader
static const int SDRDaemonUdpSize = UDPSINKFEC_UDPSIZE;
static const int SDRDaemonNbOrginalBlocks = UDPSINKFEC_NBORIGINALBLOCKS;
static const int SDRDaemonSamplesPerBlock = (UDPSINKFEC_UDPSIZE - sizeof(SDRDaemonHeader)) / sizeof(Sample);
static const int SDRDaemonNbBytesPerBlock = UDPSINKFEC_UDPSIZE - sizeof(SDRDaemonHeader);
struct SDRDaemonProtectedBlock
{
Sample m_samples[SDRDaemonSamplesPerBlock];
uint8_t buf[SDRDaemonNbBytesPerBlock];
void init() {
std::fill(m_samples, m_samples+SDRDaemonSamplesPerBlock, Sample{0,0});
std::fill(buf, buf+SDRDaemonNbBytesPerBlock, 0);
}
};

View File

@ -25,7 +25,8 @@
const uint32_t SDRDaemonDataReadQueue::MinimumMaxSize = 10;
SDRDaemonDataReadQueue::SDRDaemonDataReadQueue() :
SDRDaemonDataReadQueue::SDRDaemonDataReadQueue(uint32_t sampleSize) :
m_sampleSize(sampleSize),
m_dataBlock(0),
m_maxSize(MinimumMaxSize),
m_blockIndex(1),
@ -95,7 +96,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
qDebug("SDRDaemonDataReadQueue::readSample: initial pop new block: queue size: %u", length());
m_blockIndex = 1;
m_dataBlock = m_dataReadQueue.takeFirst();
s = m_dataBlock->m_superBlocks[m_blockIndex].m_protectedBlock.m_samples[m_sampleIndex];
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}
@ -107,9 +108,11 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
return;
}
if (m_sampleIndex < SDRDaemonSamplesPerBlock)
uint32_t samplesPerBlock = SDRDaemonNbBytesPerBlock / m_sampleSize;
if (m_sampleIndex < samplesPerBlock)
{
s = m_dataBlock->m_superBlocks[m_blockIndex].m_protectedBlock.m_samples[m_sampleIndex];
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}
@ -120,7 +123,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
if (m_blockIndex < SDRDaemonNbOrginalBlocks)
{
s = m_dataBlock->m_superBlocks[m_blockIndex].m_protectedBlock.m_samples[m_sampleIndex];
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}
@ -141,7 +144,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
//qDebug("SDRDaemonDataReadQueue::readSample: pop new block: queue size: %u", length());
m_blockIndex = 1;
m_dataBlock = m_dataReadQueue.takeFirst();
s = m_dataBlock->m_superBlocks[m_blockIndex].m_protectedBlock.m_samples[m_sampleIndex];
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}

View File

@ -31,7 +31,7 @@ class Sample;
class SDRDaemonDataReadQueue
{
public:
SDRDaemonDataReadQueue();
SDRDaemonDataReadQueue(uint32_t sampleSize);
~SDRDaemonDataReadQueue();
void push(SDRDaemonDataBlock* dataBlock); //!< push block on the queue
@ -45,6 +45,7 @@ public:
static const uint32_t MinimumMaxSize;
private:
uint32_t m_sampleSize;
QQueue<SDRDaemonDataBlock*> m_dataReadQueue;
SDRDaemonDataBlock *m_dataBlock;
uint32_t m_maxSize;
@ -52,6 +53,32 @@ private:
uint32_t m_sampleIndex;
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
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex)
{
if (sizeof(Sample) == m_sampleSize)
{
s = *((Sample*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]));
}
else if ((sizeof(Sample) == 4) && (m_sampleSize == 8))
{
int32_t rp = *( (int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]) );
int32_t ip = *( (int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize+4]) );
s.setReal(rp>>8);
s.setImag(ip>>8);
}
else if ((sizeof(Sample) == 8) && (m_sampleSize == 4))
{
int32_t rp = *( (int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]) );
int32_t ip = *( (int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize+2]) );
s.setReal(rp<<8);
s.setImag(ip<<8);
}
else
{
s = Sample{0, 0};
}
}
};