diff --git a/sdrbase/dsp/sigmffilerecord.cpp b/sdrbase/dsp/sigmffilerecord.cpp index 2c0a70a856..885d5875a1 100644 --- a/sdrbase/dsp/sigmffilerecord.cpp +++ b/sdrbase/dsp/sigmffilerecord.cpp @@ -83,11 +83,11 @@ SigMFFileRecord::~SigMFFileRecord() stopRecording(); - if (m_metaFile.is_open()) { + if (m_metaFile.isOpen()) { m_metaFile.close(); } - if (m_sampleFile.is_open()) { + if (m_sampleFile.isOpen()) { m_sampleFile.close(); } @@ -100,37 +100,33 @@ void SigMFFileRecord::setFileName(const QString& fileName) { qDebug("SigMFFileRecord::setFileName: %s", qPrintable(fileName)); - if (m_metaFile.is_open()) { + if (m_metaFile.isOpen()) { m_metaFile.close(); } - if (m_sampleFile.is_open()) { + if (m_sampleFile.isOpen()) { m_sampleFile.close(); } m_fileName = fileName; + QString metaFileName = m_fileName + ".sigmf-meta"; + m_metaFile.setFileName(metaFileName); + QString sampleFileName = m_fileName + ".sigmf-data"; + m_sampleFile.setFileName(sampleFileName); - if (QFile::exists(fileName + ".sigmf-data") && QFile::exists(fileName + ".sigmf-meta")) + if (QFile::exists(metaFileName) && QFile::exists(sampleFileName)) { - m_metaFileName = m_fileName + ".sigmf-meta"; - std::ifstream metaStream; -#ifdef Q_OS_WIN - metaStream.open(m_metaFileName.toStdWString().c_str()); -#else - metaStream.open(m_metaFileName.toStdString().c_str()); -#endif - std::ostringstream meta_buffer; - meta_buffer << metaStream.rdbuf(); + QFile metaStream(metaFileName); + metaStream.open(QIODevice::ReadOnly); try { - from_json(json::parse(meta_buffer.str()), *m_metaRecord); + from_json(json::parse(metaStream.readAll().toStdString()), *m_metaRecord); metaStream.close(); std::string sdrAngelVersion = m_metaRecord->global.access().version; if (sdrAngelVersion.size() != 0) { qDebug("SigMFFileRecord::setFileName: appending mode"); - m_metaFile.open(m_metaFileName.toStdString().c_str(), std::ofstream::out); m_initialMsCount = 0; for (auto capture : m_metaRecord->captures) @@ -140,10 +136,18 @@ void SigMFFileRecord::setFileName(const QString& fileName) m_initialMsCount += (length * 1000) / sampleRate; } - m_sampleFileName = m_fileName + ".sigmf-data"; - m_sampleFile.open(m_sampleFileName.toStdString().c_str(), std::ios::binary & std::ios::app); - m_initialBytesCount = (uint64_t) m_sampleFile.tellp(); + m_sampleFile.setFileName(m_fileName + ".sigmf-data"); + if (!m_sampleFile.open(QIODevice::WriteOnly | QIODevice::Append)) + { + qWarning() << "SigMFFileRecord::setFileName: failed to open file: " << m_sampleFile.fileName(); + } + m_initialBytesCount = (uint64_t) m_sampleFile.size(); m_sampleStart = m_initialBytesCount / ((1<captures.emplace_back(recording_capture); m_sampleStart += m_sampleCount; // Flush meta to disk - m_metaFile.seekp(0); + m_metaFile.seek(0); std::string jsonRecord = json(*m_metaRecord).dump(2); - m_metaFile << jsonRecord; + m_metaFile.write(jsonRecord.c_str(), jsonRecord.size()); m_metaFile.flush(); + m_metaFile.resize(m_metaFile.pos()); } else { diff --git a/sdrbase/dsp/sigmffilerecord.h b/sdrbase/dsp/sigmffilerecord.h index e55f4fb8d4..21914450b3 100644 --- a/sdrbase/dsp/sigmffilerecord.h +++ b/sdrbase/dsp/sigmffilerecord.h @@ -22,12 +22,10 @@ #ifndef INCLUDE_SIGMF_FILERECORD_H #define INCLUDE_SIGMF_FILERECORD_H -#include -#include -#include #include #include +#include #include "dsp/sigmf_forward.h" #include "dsp/filerecordinterface.h" @@ -77,16 +75,14 @@ class SDRBASE_API SigMFFileRecord : public FileRecordInterface { QString m_hardwareId; QString m_fileName; - QString m_sampleFileName; - QString m_metaFileName; quint32 m_sampleRate; quint64 m_centerFrequency; qint64 m_msShift; bool m_recordOn; bool m_recordStart; QDateTime m_captureStartDT; - std::ofstream m_metaFile; - std::ofstream m_sampleFile; + QFile m_metaFile; + QFile m_sampleFile; quint64 m_sampleStart; quint64 m_sampleCount; quint64 m_initialMsCount;