From 278f085dbc5cff82e1ac9bb6ef7e37fd9abf3ee1 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 23 Jun 2016 00:58:07 +0200 Subject: [PATCH] SDRdaemonFEC support: debug (6). Corrected meta data processing --- .../sdrdaemonfec/sdrdaemonfecbuffer.cpp | 18 +++++++++++------- .../sdrdaemonfec/sdrdaemonfecbuffer.h | 8 ++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp index d6bc35810..67e4fe8b1 100644 --- a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp +++ b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp @@ -67,6 +67,7 @@ void SDRdaemonFECBuffer::initDecodeAllSlots() m_decoderSlots[i].m_blockCount = 0; m_decoderSlots[i].m_recoveryCount = 0; m_decoderSlots[i].m_decoded = false; + m_decoderSlots[i].m_metaRetrieved = false; m_decoderSlots[i].m_blockZero.m_metaData.init(); } } @@ -82,10 +83,10 @@ void SDRdaemonFECBuffer::initDecodeSlot(int slotIndex) int pseudoWriteIndex = slotIndex * sizeof(BufferFrame); m_wrDeltaEstimate = pseudoWriteIndex - m_readIndex; - if (m_decoderSlots[slotIndex].m_blockZero.m_metaData.m_nbFECBlocks < 0) { // meta data invalid - m_outputMeta = m_currentMeta; // use current meta - } else { + if (m_decoderSlots[slotIndex].m_metaRetrieved) { // meta data was retrieved in the current slot m_outputMeta = m_decoderSlots[slotIndex].m_blockZero.m_metaData; + } else { + m_outputMeta = m_currentMeta; // use stored current meta } // collect stats before voiding the slot @@ -97,6 +98,7 @@ void SDRdaemonFECBuffer::initDecodeSlot(int slotIndex) m_decoderSlots[slotIndex].m_blockCount = 0; m_decoderSlots[slotIndex].m_recoveryCount = 0; 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)); @@ -171,6 +173,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length) { SuperBlockZero *superBlockZero = (SuperBlockZero *) array; m_decoderSlots[decoderIndex].m_blockZero = superBlockZero->protectedBlock; + m_decoderSlots[decoderIndex].m_metaRetrieved = true; 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, @@ -192,13 +195,13 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length) } else if (!m_decoderSlots[decoderIndex].m_decoded) // ready to decode { - if (m_decoderSlots[decoderIndex].m_blockZero.m_metaData.m_nbFECBlocks < 0) // block zero has not been received + if (m_decoderSlots[decoderIndex].m_metaRetrieved) // block zero with its meta data has been received { - m_paramsCM256.RecoveryCount = m_currentMeta.m_nbFECBlocks; // take last value for number of FEC blocks + m_paramsCM256.RecoveryCount = m_decoderSlots[decoderIndex].m_blockZero.m_metaData.m_nbFECBlocks; } else { - m_paramsCM256.RecoveryCount = m_decoderSlots[decoderIndex].m_blockZero.m_metaData.m_nbFECBlocks; + m_paramsCM256.RecoveryCount = m_currentMeta.m_nbFECBlocks; // take last stored value for number of FEC blocks } if (m_decoderSlots[decoderIndex].m_recoveryCount > 0) // recovery data used @@ -223,6 +226,7 @@ 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)); @@ -237,7 +241,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length) //printMeta("SDRdaemonFECBuffer::writeData", &m_decoderSlots[decoderIndex].m_blockZero.m_metaData); - if (m_decoderSlots[decoderIndex].m_blockZero.m_metaData.m_nbFECBlocks >= 0) // meta data valid + if (m_decoderSlots[decoderIndex].m_metaRetrieved) // meta data has been retrieved (direct or recovery) { if (!(m_decoderSlots[decoderIndex].m_blockZero.m_metaData == m_currentMeta)) { diff --git a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h index 91a562aed..b1333836b 100644 --- a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h +++ b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h @@ -18,6 +18,7 @@ #define PLUGINS_SAMPLESOURCE_SDRDAEMONFEC_SDRDAEMONFECBUFFER_H_ #include +#include #include #include "cm256.h" #include "util/movingaverage.h" @@ -50,7 +51,6 @@ public: void init() { memset((void *) this, 0, sizeof(MetaDataFEC)); - m_nbFECBlocks = -1; } }; @@ -123,8 +123,11 @@ public: if (m_framesNbBytes) { int32_t val = (m_wrDeltaEstimate * 100) / (int32_t) m_framesNbBytes; + int32_t ret = val < 0 ? -val - 50 : 50 -val; + int32_t rp = (m_readIndex * 100) / (int32_t) m_framesNbBytes; + //qDebug() << "getBufferLengthInSecs: " << val << ":" << ret << ":" << rp; // conversion: [-100:-50[ : read leads (+) / [-50:0[ : read lags (-) / [0:50[ : read leads (+) / [50:100{ : read lags (-) - return val < 0 ? -val - 50 : 50 -val; + return ret; } else { @@ -162,6 +165,7 @@ private: int m_blockCount; //!< total number of blocks received for this frame int m_recoveryCount; //!< number of recovery blocks received bool m_decoded; //!< true if decoded + bool m_metaRetrieved; }; MetaDataFEC m_currentMeta; //!< Stored current meta data