From 047e9f3e24a42b3de7c60ac4ccfae1d70a527a29 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 6 Aug 2015 01:14:44 +0200 Subject: [PATCH] File source: play/pause button implemented with stream timing update --- .../samplesource/filesource/filesourcegui.cpp | 20 +++++++--- .../filesource/filesourceinput.cpp | 30 ++++++++++++-- .../samplesource/filesource/filesourceinput.h | 40 +++++++++++++++++++ .../filesource/filesourcethread.cpp | 3 ++ .../filesource/filesourcethread.h | 2 + 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/plugins/samplesource/filesource/filesourcegui.cpp b/plugins/samplesource/filesource/filesourcegui.cpp index f86f6a19e..0f3ba46a6 100644 --- a/plugins/samplesource/filesource/filesourcegui.cpp +++ b/plugins/samplesource/filesource/filesourcegui.cpp @@ -129,7 +129,7 @@ bool FileSourceGui::handleMessage(Message* message) } else if(FileSourceInput::MsgReportFileSourceStreamData::match(message)) { - std::cerr << "FileSourceGui::handleMessage: MsgReportFileSourceStreamData" << std::endl; + //std::cerr << "FileSourceGui::handleMessage: MsgReportFileSourceStreamData" << std::endl; m_sampleRate = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getSampleRate(); m_centerFrequency = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getCenterFrequency(); m_startingTimeStamp = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getStartingTimeStamp(); @@ -137,6 +137,12 @@ bool FileSourceGui::handleMessage(Message* message) message->completed(); return true; } + else if(FileSourceInput::MsgReportFileSourceStreamTiming::match(message)) + { + m_samplesCount = ((FileSourceInput::MsgReportFileSourceStreamTiming*)message)->getSamplesCount(); + std::cerr << "FileSourceGui::handleMessage: MsgReportFileSourceStreamTiming: " << m_samplesCount << std::endl; + updateWithStreamTime(); + } else { return false; @@ -165,6 +171,8 @@ void FileSourceGui::updateHardware() void FileSourceGui::on_play_toggled(bool checked) { + FileSourceInput::MsgConfigureFileSourceWork* message = FileSourceInput::MsgConfigureFileSourceWork::create(checked); + message->submit(m_pluginAPI->getDSPEngineMessageQueue()); } void FileSourceGui::on_showFileDialog_clicked(bool checked) @@ -212,15 +220,17 @@ void FileSourceGui::updateWithStreamTime() } QTime t(0, 0, 0, 0); - t.addSecs(t_sec); - t.addMSecs(t_msec); + t = t.addSecs(t_sec); + t = t.addMSecs(t_msec); QString s_time = t.toString("hh:mm:ss.zzz"); ui->relTimeText->setText(s_time); + //std::cerr << "FileSourceGui::updateWithStreamTime: " << t_sec << "." << t_msec << " " << s_time.toStdString() << std::endl; + quint64 startingTimeStampMsec = m_startingTimeStamp * 1000; QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec); - dt.addSecs(t_sec); - dt.addMSecs(t_msec); + dt = dt.addSecs(t_sec); + dt = dt.addMSecs(t_msec); QString s_date = dt.toString("yyyyMMdd hh.mm.ss.zzz"); ui->absTimeText->setText(s_date); } diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index bd8fa74d1..a5dee5738 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -28,8 +28,10 @@ MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceName, Message) +MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceWork, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message) +MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamTiming, Message) FileSourceInput::Settings::Settings() : m_fileName("./test.sdriq") @@ -187,14 +189,36 @@ std::time_t FileSourceInput::getStartingTimeStamp() const bool FileSourceInput::handleMessage(Message* message) { - if(MsgConfigureFileSourceName::match(message)) { - std::cerr << "FileSourceInput::handleMessage: MsgConfigureFileName" << std::endl; + if (MsgConfigureFileSourceName::match(message)) + { + //std::cerr << "FileSourceInput::handleMessage: MsgConfigureFileName" << std::endl; MsgConfigureFileSourceName* conf = (MsgConfigureFileSourceName*) message; m_fileName = conf->getFileName(); openFileStream(); message->completed(); return true; - } else { + } + else if (MsgConfigureFileSourceWork::match(message)) + { + //std::cerr << "FileSourceInput::handleMessage: MsgConfigureFileSourceWork: "; + MsgConfigureFileSourceWork* conf = (MsgConfigureFileSourceWork*) message; + bool working = conf->isWorking(); + //std::cerr << (working ? "working" : "not working") << std::endl; + if (m_fileSourceThread != 0) + { + if (working) { + m_fileSourceThread->startWork(); + } else { + m_fileSourceThread->stopWork(); + } + + MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount())->submit(m_guiMessageQueue); + } + message->completed(); + return true; + } + else + { return false; } } diff --git a/plugins/samplesource/filesource/filesourceinput.h b/plugins/samplesource/filesource/filesourceinput.h index 73e957390..4ac16fabe 100644 --- a/plugins/samplesource/filesource/filesourceinput.h +++ b/plugins/samplesource/filesource/filesourceinput.h @@ -80,6 +80,26 @@ public: { } }; + class MsgConfigureFileSourceWork : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool isWorking() const { return m_working; } + + static MsgConfigureFileSourceWork* create(bool working) + { + return new MsgConfigureFileSourceWork(working); + } + + private: + bool m_working; + + MsgConfigureFileSourceWork(bool working) : + Message(), + m_working(working) + { } + }; + class MsgReportFileSourceAcquisition : public Message { MESSAGE_CLASS_DECLARATION @@ -126,6 +146,26 @@ public: { } }; + class MsgReportFileSourceStreamTiming : public Message { + MESSAGE_CLASS_DECLARATION + + public: + std::size_t getSamplesCount() const { return m_samplesCount; } + + static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount) + { + return new MsgReportFileSourceStreamTiming(samplesCount); + } + + protected: + std::size_t m_samplesCount; + + MsgReportFileSourceStreamTiming(std::size_t samplesCount) : + Message(), + m_samplesCount(samplesCount) + { } + }; + FileSourceInput(MessageQueue* msgQueueToGUI, const QTimer& masterTimer); ~FileSourceInput(); diff --git a/plugins/samplesource/filesource/filesourcethread.cpp b/plugins/samplesource/filesource/filesourcethread.cpp index 42ed5f275..9ee136171 100644 --- a/plugins/samplesource/filesource/filesourcethread.cpp +++ b/plugins/samplesource/filesource/filesourcethread.cpp @@ -31,6 +31,7 @@ FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sam m_bufsize(0), m_chunksize(0), m_sampleFifo(sampleFifo), + m_samplesCount(0), m_samplerate(0) { assert(m_ifstream != 0); @@ -142,12 +143,14 @@ void FileSourceThread::tick() // TODO: handle loop playback situation m_ifstream->clear(); m_ifstream->seekg(0, std::ios::beg); + m_samplesCount = 0; //stopWork(); //m_ifstream->close(); } else { m_sampleFifo->write(m_buf, m_chunksize); + m_samplesCount += m_chunksize / 4; } } } diff --git a/plugins/samplesource/filesource/filesourcethread.h b/plugins/samplesource/filesource/filesourcethread.h index 2fd48837f..d4dc92298 100644 --- a/plugins/samplesource/filesource/filesourcethread.h +++ b/plugins/samplesource/filesource/filesourcethread.h @@ -40,6 +40,7 @@ public: void stopWork(); void setSamplerate(int samplerate); bool isRunning() const { return m_running; } + std::size_t getSamplesCount() const { return m_samplesCount; } void connectTimer(const QTimer& timer); @@ -53,6 +54,7 @@ private: std::size_t m_bufsize; std::size_t m_chunksize; SampleFifo* m_sampleFifo; + std::size_t m_samplesCount; int m_samplerate; static const int m_rateDivider;