From 4a1376e47476f9468ec9f5b7b1e1d26ad724f566 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 2 Oct 2018 08:45:14 +0200 Subject: [PATCH] FileSource: process record header if file is long enough. Else close file so that start is aborted with error --- .../filesource/filesourceinput.cpp | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 3736dcc0a..032d39f85 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -81,18 +81,23 @@ void FileSourceInput::openFileStream() m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate); quint64 fileSize = m_ifstream.tellg(); - m_ifstream.seekg(0,std::ios_base::beg); - FileRecord::Header header; - FileRecord::readHeader(m_ifstream, header); - m_sampleRate = header.sampleRate; - m_centerFrequency = header.centerFrequency; - m_startingTimeStamp = header.startTimeStamp; - m_sampleSize = header.sampleSize; + if (fileSize > sizeof(FileRecord::Header)) + { + // TODO: add CRC + m_ifstream.seekg(0,std::ios_base::beg); + FileRecord::Header header; + FileRecord::readHeader(m_ifstream, header); - if (fileSize > sizeof(FileRecord::Header)) { - m_recordLength = (fileSize - sizeof(FileRecord::Header)) / (4 * m_sampleRate); - } else { + m_sampleRate = header.sampleRate; + m_centerFrequency = header.centerFrequency; + m_startingTimeStamp = header.startTimeStamp; + m_sampleSize = header.sampleSize; + + m_recordLength = (fileSize - sizeof(FileRecord::Header)) / (4 * m_sampleRate); + } + else + { m_recordLength = 0; } @@ -108,6 +113,10 @@ void FileSourceInput::openFileStream() m_recordLength); // file stream data getMessageQueueToGUI()->push(report); } + + if (m_recordLength == 0) { + m_ifstream.close(); + } } void FileSourceInput::seekFileStream(int seekPercentage) @@ -132,6 +141,12 @@ void FileSourceInput::init() bool FileSourceInput::start() { + if (!m_ifstream.is_open()) + { + qWarning("FileSourceInput::start: file not open. not starting"); + return false; + } + QMutexLocker mutexLocker(&m_mutex); qDebug() << "FileSourceInput::start";