SDRdaemonFEC support. Use new simplified version

pull/27/head
f4exb 2016-07-06 00:43:38 +02:00
rodzic 7c17d19391
commit dddf872d56
2 zmienionych plików z 18 dodań i 35 usunięć

Wyświetl plik

@ -27,7 +27,7 @@ const int SDRdaemonFECBuffer::m_iqSampleSize = 2 * m_sampleSize;
SDRdaemonFECBuffer::SDRdaemonFECBuffer(uint32_t throttlems) :
m_frameHead(0),
m_decoderSlotHead(nbDecoderSlots/2),
m_decoderIndexHead(nbDecoderSlots/2),
m_curNbBlocks(0),
m_curNbRecovery(0),
m_throttlemsNominal(throttlems),
@ -76,7 +76,7 @@ void SDRdaemonFECBuffer::initDecodeAllSlots()
void SDRdaemonFECBuffer::initReadIndex()
{
m_readIndex = ((m_decoderSlotHead + (nbDecoderSlots/2)) % nbDecoderSlots) * sizeof(BufferFrame);
m_readIndex = ((m_decoderIndexHead + (nbDecoderSlots/2)) % nbDecoderSlots) * sizeof(BufferFrame);
m_wrDeltaEstimate = m_framesNbBytes / 2;
}
@ -102,7 +102,6 @@ void SDRdaemonFECBuffer::initDecodeSlot(int slotIndex)
m_decoderSlots[slotIndex].m_decoded = false;
m_decoderSlots[slotIndex].m_metaRetrieved = false;
m_decoderSlots[slotIndex].m_blockZero.m_metaData.init();
memset((void *) m_decoderSlots[slotIndex].m_blockZero.m_samples, 0, samplesPerBlockZero * sizeof(Sample));
memset((void *) m_frames[slotIndex].m_blocks, 0, (m_nbOriginalBlocks - 1) * samplesPerBlock * sizeof(Sample));
}
@ -114,10 +113,16 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
SuperBlock *superBlock = (SuperBlock *) array;
int frameIndex = superBlock->header.frameIndex;
int decoderIndex = frameIndex % nbDecoderSlots;
int blockIndex = superBlock->header.blockIndex;
// qDebug() << "SDRdaemonFECBuffer::writeData:"
// << " frameIndex: " << frameIndex
// << " decoderIndex: " << decoderIndex
// << " blockIndex: " << blockIndex;
if (m_frameHead == -1) // initial state
{
m_decoderSlotHead = decoderIndex; // new decoder slot head
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
initReadIndex(); // reset read index
initDecodeAllSlots(); // initialize all slots
@ -131,7 +136,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
if (-frameDelta < nbDecoderSlots) // new frame head not too new
{
//qDebug() << "SDRdaemonFECBuffer::writeData: new frame head (1): " << frameIndex << ":" << frameDelta << ":" << decoderIndex;
m_decoderSlotHead = decoderIndex; // new decoder slot head
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
dataAvailable = true;
initDecodeSlot(decoderIndex); // collect stats and re-initialize current slot
@ -139,8 +144,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
else if (-frameDelta <= 65536 - nbDecoderSlots) // loss of sync start over
{
//qDebug() << "SDRdaemonFECBuffer::writeData: loss of sync start over (1)" << frameIndex << ":" << frameDelta << ":" << decoderIndex;
m_decoderSlotHead = frameIndex % nbDecoderSlots; // new decoder slot head
decoderIndex = m_decoderSlotHead;
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
initReadIndex(); // reset read index
initDecodeAllSlots(); // re-initialize all slots
@ -151,7 +155,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
if (frameDelta > 65536 - nbDecoderSlots) // new frame head not too new
{
//qDebug() << "SDRdaemonFECBuffer::writeData: new frame head (2): " << frameIndex << ":" << frameDelta << ":" << decoderIndex;
m_decoderSlotHead = decoderIndex; // new decoder slot head
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
dataAvailable = true;
initDecodeSlot(decoderIndex); // collect stats and re-initialize current slot
@ -159,8 +163,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
else if (frameDelta >= nbDecoderSlots) // loss of sync start over
{
//qDebug() << "SDRdaemonFECBuffer::writeData: loss of sync start over (2)" << frameIndex << ":" << frameDelta << ":" << decoderIndex;
m_decoderSlotHead = frameIndex % nbDecoderSlots; // new decoder slot head
decoderIndex = m_decoderSlotHead;
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
initReadIndex(); // reset read index
initDecodeAllSlots(); // re-initialize all slots
@ -170,20 +173,16 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
// decoderIndex should now be correctly set
int blockIndex = superBlock->header.blockIndex;
int blockHead = m_decoderSlots[decoderIndex].m_blockCount;
if (blockHead < m_nbOriginalBlocks) // not enough blocks to decode -> store data
{
if (blockIndex == 0) // first block with meta
{
SuperBlockZero *superBlockZero = (SuperBlockZero *) array;
m_decoderSlots[decoderIndex].m_blockZero = superBlockZero->protectedBlock;
m_decoderSlots[decoderIndex].m_metaRetrieved = true;
ProtectedBlockZero *blockZero = (ProtectedBlockZero *) &superBlock->protectedBlock;
m_decoderSlots[decoderIndex].m_blockZero = *blockZero;
m_decoderSlots[decoderIndex].m_cm256DescriptorBlocks[blockHead].Block = (void *) &m_decoderSlots[decoderIndex].m_blockZero;
memcpy((void *) m_frames[decoderIndex].m_blockZero.m_samples,
(const void *) m_decoderSlots[decoderIndex].m_blockZero.m_samples,
samplesPerBlockZero * sizeof(Sample));
m_decoderSlots[decoderIndex].m_metaRetrieved = true;
}
else if (blockIndex < m_nbOriginalBlocks) // normal block
{
@ -238,9 +237,6 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
ProtectedBlockZero *recoveredBlockZero = (ProtectedBlockZero *) &m_decoderSlots[decoderIndex].m_recoveryBlocks[ir];
m_decoderSlots[decoderIndex].m_blockZero.m_metaData = recoveredBlockZero->m_metaData;
m_decoderSlots[decoderIndex].m_metaRetrieved = true;
memcpy((void *) m_frames[decoderIndex].m_blockZero.m_samples,
(const void *) recoveredBlockZero->m_samples,
samplesPerBlockZero * sizeof(Sample));
}
else
{

Wyświetl plik

@ -68,7 +68,6 @@ public:
};
static const int samplesPerBlock = (SDRDAEMONFEC_UDPSIZE - sizeof(Header)) / sizeof(Sample);
static const int samplesPerBlockZero = samplesPerBlock - (sizeof(MetaDataFEC) / sizeof(Sample));
struct ProtectedBlock
{
@ -84,13 +83,7 @@ public:
struct ProtectedBlockZero
{
MetaDataFEC m_metaData;
Sample m_samples[samplesPerBlockZero];
};
struct SuperBlockZero
{
Header header;
ProtectedBlockZero protectedBlock;
uint8_t m_filler[SDRDAEMONFEC_UDPSIZE - sizeof(Header) - sizeof(MetaDataFEC)]; // complete for a 512 byte block
};
#pragma pack(pop)
@ -144,14 +137,8 @@ private:
static const int nbDecoderSlots = SDRDAEMONFEC_NBDECODERSLOTS;
#pragma pack(push, 1)
struct BufferBlockZero
{
Sample m_samples[samplesPerBlockZero];
};
struct BufferFrame
{
BufferBlockZero m_blockZero;
ProtectedBlock m_blocks[m_nbOriginalBlocks - 1];
};
#pragma pack(pop)
@ -174,7 +161,7 @@ private:
DecoderSlot m_decoderSlots[nbDecoderSlots]; //!< CM256 decoding control/buffer slots
BufferFrame m_frames[nbDecoderSlots]; //!< Samples buffer
int m_framesNbBytes; //!< Number of bytes in samples buffer
int m_decoderSlotHead; //!< index of the current head frame slot in decoding slots
int m_decoderIndexHead; //!< index of the current head frame slot in decoding slots
int m_frameHead; //!< index of the current head frame sent
int m_curNbBlocks; //!< (stats) instantaneous number of blocks received
int m_curNbRecovery; //!< (stats) instantaneous number of recovery blocks used