From 942a7ca8033c4eca2065d2c6ef9cb96d9e85e19a Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 23 Feb 2016 01:29:03 +0100 Subject: [PATCH] SDRdaemon plugin: fixed LZ4 writes and uncompressed writes --- .../sdrdaemon/sdrdaemonbuffer.cpp | 41 ++++++++----------- .../samplesource/sdrdaemon/sdrdaemonbuffer.h | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp index 5804f806e..8e999f7d0 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp +++ b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp @@ -96,7 +96,7 @@ bool SDRdaemonBuffer::readMeta(char *array, uint32_t length) m_nbBlocks = 0; m_inCount = 0; - if (!(m_currentMeta == *metaData)) + if (!m_lz4 && !(m_currentMeta == *metaData)) { std::cerr << "SDRdaemonBuffer::readMeta: "; printMeta(metaData); @@ -203,23 +203,7 @@ void SDRdaemonBuffer::writeDataLZ4(const char *array, uint32_t length) m_nbLz4CRCOK = 0; } - uint64_t crc64 = m_crc64.calculate_crc(m_lz4InBuffer, m_lz4InSize); - - if (memcmp(&crc64, &m_dataCRC, 8) == 0) - { - m_nbLz4CRCOK++; - } - - int compressedSize = LZ4_decompress_fast((const char*) m_lz4InBuffer, (char*) &m_rawBuffer[m_writeIndex], m_frameSize); - m_nbLz4Decodes++; - - if (compressedSize == m_lz4InSize) - { - m_nbLz4SuccessfulDecodes++; - } - - writeToRawBufferLZ4((const char *) m_lz4InBuffer, m_frameSize); - + writeToRawBufferLZ4(); m_lz4InCount = 0; } } @@ -235,22 +219,33 @@ void SDRdaemonBuffer::writeToRawBufferUncompressed(const char *array, uint32_t l else { std::memcpy((void *) &m_rawBuffer[m_writeIndex], (const void *) array, m_rawSize - m_writeIndex); - m_writeIndex = length - (m_rawSize - m_writeIndex); - std::memcpy((void *) m_rawBuffer, (const void *) &array[m_rawSize - m_writeIndex], m_writeIndex); + length -= m_rawSize - m_writeIndex; + std::memcpy((void *) m_rawBuffer, (const void *) &array[m_rawSize - m_writeIndex], length); + m_writeIndex = length; } } -void SDRdaemonBuffer::writeToRawBufferLZ4(const char *array, uint32_t length) +void SDRdaemonBuffer::writeToRawBufferLZ4() { + uint64_t crc64 = m_crc64.calculate_crc(m_lz4InBuffer, m_lz4InSize); + + if (memcmp(&crc64, &m_dataCRC, 8) == 0) + { + m_nbLz4CRCOK++; + } + else + { + return; + } + int compressedSize = LZ4_decompress_fast((const char*) m_lz4InBuffer, (char*) m_lz4OutBuffer, m_frameSize); m_nbLz4Decodes++; if (compressedSize == m_lz4InSize) { m_nbLz4SuccessfulDecodes++; + writeToRawBufferUncompressed((const char *) m_lz4OutBuffer, m_frameSize); } - - writeToRawBufferUncompressed((const char *) m_lz4OutBuffer, m_frameSize); } uint8_t *SDRdaemonBuffer::readDataChunk() diff --git a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h index 31cf04494..cb1b5fcf8 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h @@ -80,7 +80,7 @@ public: private: void updateLZ4Sizes(uint32_t frameSize); void writeDataLZ4(const char *array, uint32_t length); - void writeToRawBufferLZ4(const char *array, uint32_t originalLength); + void writeToRawBufferLZ4(); void writeToRawBufferUncompressed(const char *array, uint32_t length); void updateBufferSize(uint32_t sampleRate); void printMeta(MetaData *metaData);