1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

FileSource: process record header if file is long enough. Else close file so that start is aborted with error

This commit is contained in:
f4exb 2018-10-02 08:45:14 +02:00
parent f4976485fc
commit 4a1376e474

View File

@ -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";