diff --git a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp index 5a3e0b549..f4a9f11c2 100644 --- a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp +++ b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.cpp @@ -46,6 +46,8 @@ SDRdaemonFECBuffer::SDRdaemonFECBuffer(uint32_t throttlems) : m_currentMeta.init(); m_framesNbBytes = nbDecoderSlots * sizeof(BufferFrame); m_wrDeltaEstimate = m_framesNbBytes / 2; + m_tvOut_sec = 0; + m_tvOut_usec = 0; m_readNbBytes = 1; m_paramsCM256.BlockBytes = sizeof(ProtectedBlock); // never changes m_paramsCM256.OriginalCount = m_nbOriginalBlocks; // never changes @@ -169,6 +171,17 @@ void SDRdaemonFECBuffer::checkSlotData(int slotIndex) m_wrDeltaEstimate = pseudoWriteIndex - m_readIndex; m_nbWrites++; + int rwDelayBytes = (m_wrDeltaEstimate > 0 ? m_wrDeltaEstimate : sizeof(BufferFrame) * nbDecoderSlots + m_wrDeltaEstimate); + int sampleRate = m_currentMeta.m_sampleRate; + + if (sampleRate > 0) + { + int64_t ts = m_currentMeta.m_tv_sec * 1000000LL + m_currentMeta.m_tv_usec; + ts -= (rwDelayBytes * 1000000LL) / (sampleRate * sizeof(Sample)); + m_tvOut_sec = ts / 1000000LL; + m_tvOut_usec = ts - (m_tvOut_sec * 1000000LL); + } + if (!m_decoderSlots[slotIndex].m_decoded) { qDebug() << "SDRdaemonFECBuffer::checkSlotData: incomplete frame:" diff --git a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h index f428f268d..9353ab34c 100644 --- a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h +++ b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecbuffer.h @@ -92,6 +92,10 @@ public: // meta data const MetaDataFEC& getCurrentMeta() const { return m_currentMeta; } + // samples timestamp + uint32_t getTVOutSec() const { return m_tvOut_sec; } + uint32_t getTVOutUsec() const { return m_tvOut_usec; } + // stats int getCurNbBlocks() const { return m_curNbBlocks; } @@ -187,6 +191,8 @@ private: bool m_framesDecoded; //!< [stats] true if all frames were decoded since last poll int m_readIndex; //!< current byte read index in frames buffer int m_wrDeltaEstimate; //!< Sampled estimate of write to read indexes difference + uint32_t m_tvOut_sec; //!< Estimated returned samples timestamp (seconds) + uint32_t m_tvOut_usec; //!< Estimated returned samples timestamp (microseconds) int m_readNbBytes; //!< Nominal number of bytes per read (50ms) uint32_t m_throttlemsNominal; //!< Initial throttle in ms diff --git a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecudphandler.cpp b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecudphandler.cpp index 55f232d2f..760081afb 100644 --- a/plugins/samplesource/sdrdaemonfec/sdrdaemonfecudphandler.cpp +++ b/plugins/samplesource/sdrdaemonfec/sdrdaemonfecudphandler.cpp @@ -149,8 +149,10 @@ void SDRdaemonFECUDPHandler::processData() const SDRdaemonFECBuffer::MetaDataFEC& metaData = m_sdrDaemonBuffer.getCurrentMeta(); bool change = false; - m_tv_sec = metaData.m_tv_sec; - m_tv_usec = metaData.m_tv_usec; +// m_tv_sec = metaData.m_tv_sec; +// m_tv_usec = metaData.m_tv_usec; + m_tv_sec = m_sdrDaemonBuffer.getTVOutSec(); + m_tv_usec = m_sdrDaemonBuffer.getTVOutUsec(); if (m_centerFrequency != metaData.m_centerFrequency) {