From 84178789e439b274805aa7cebf3f1fadc4c799a7 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 21 Aug 2018 17:23:48 +0200 Subject: [PATCH] SDRdaemon: fixed core dump --- sdrdaemon/channel/sdrdaemonchannelsink.cpp | 12 ++++---- sdrdaemon/channel/sdrdaemondatablock.h | 35 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.cpp b/sdrdaemon/channel/sdrdaemonchannelsink.cpp index 90c13db21..2b7c2141a 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsink.cpp @@ -110,13 +110,15 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const metaData.m_tv_sec = tv.tv_sec; metaData.m_tv_usec = tv.tv_usec; + if (!m_dataBlock) { // on the very first cycle there is no data block allocated + m_dataBlock = new SDRDaemonDataBlock(); + } + boost::crc_32_type crc32; crc32.process_bytes(&metaData, 20); metaData.m_crc32 = crc32.checksum(); SDRDaemonSuperBlock& superBlock = m_dataBlock->m_superBlocks[0]; // first block - - memset((void *) &superBlock, 0, SDRDaemonUdpSize); - + superBlock.init(); superBlock.m_header.m_frameIndex = m_frameCount; superBlock.m_header.m_blockIndex = m_txBlockIndex; memcpy((void *) &superBlock.m_protectedBlock, (const void *) &metaData, sizeof(SDRDaemonMetaDataFEC)); @@ -136,10 +138,6 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const m_currentMetaFEC = metaData; } - if (!m_dataBlock) { - m_dataBlock = new SDRDaemonDataBlock(); - } - m_txBlockIndex = 1; // next Tx block with data } // block zero diff --git a/sdrdaemon/channel/sdrdaemondatablock.h b/sdrdaemon/channel/sdrdaemondatablock.h index da51e4896..2bb9f28f4 100644 --- a/sdrdaemon/channel/sdrdaemondatablock.h +++ b/sdrdaemon/channel/sdrdaemondatablock.h @@ -25,6 +25,7 @@ #include #include +#include #include "dsp/dsptypes.h" #define UDPSINKFEC_UDPSIZE 512 @@ -51,8 +52,15 @@ struct SDRDaemonMetaDataFEC void init() { - memset((void *) this, 0, sizeof(SDRDaemonMetaDataFEC)); + m_centerFrequency = 0; + m_sampleRate = 0; + m_sampleBytes = 0; + m_sampleBits = 0; + m_nbOriginalBlocks = 0; m_nbFECBlocks = -1; + m_tv_sec = 0; + m_tv_usec = 0; + m_crc32 = 0; } }; @@ -61,6 +69,13 @@ struct SDRDaemonHeader uint16_t m_frameIndex; uint8_t m_blockIndex; uint8_t m_filler; + + void init() + { + m_frameIndex = 0; + m_blockIndex = 0; + m_filler = 0; + } }; static const int SDRDaemonUdpSize = UDPSINKFEC_UDPSIZE; @@ -70,12 +85,22 @@ static const int SDRDaemonSamplesPerBlock = (UDPSINKFEC_UDPSIZE - sizeof(SDRDaem struct SDRDaemonProtectedBlock { Sample m_samples[SDRDaemonSamplesPerBlock]; + + void init() { + std::fill(m_samples, m_samples+SDRDaemonSamplesPerBlock, Sample{0,0}); + } }; struct SDRDaemonSuperBlock { SDRDaemonHeader m_header; SDRDaemonProtectedBlock m_protectedBlock; + + void init() + { + m_header.init(); + m_protectedBlock.init(); + } }; #pragma pack(pop) @@ -99,8 +124,14 @@ struct SDRDaemonTxControlBlock class SDRDaemonDataBlock { public: + SDRDaemonDataBlock() { + m_superBlocks = new SDRDaemonSuperBlock[256]; + } + ~SDRDaemonDataBlock() { + delete[] m_superBlocks; + } SDRDaemonTxControlBlock m_controlBlock; - SDRDaemonSuperBlock m_superBlocks[256]; + SDRDaemonSuperBlock *m_superBlocks; }; #endif /* SDRDAEMON_CHANNEL_SDRDAEMONDATABLOCK_H_ */