1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

File source: play/pause button implemented with stream timing update

This commit is contained in:
f4exb 2015-08-06 01:14:44 +02:00
parent 0603bb41ca
commit 047e9f3e24
5 changed files with 87 additions and 8 deletions

View File

@ -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);
}

View File

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

View File

@ -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();

View File

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

View File

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