1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00

SDRdaemonFEC support. Use new simplified version

This commit is contained in:
f4exb 2016-07-06 00:43:38 +02:00
parent 7c17d19391
commit dddf872d56
2 changed files with 18 additions and 35 deletions

View File

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

View File

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