1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

Make DSP engine global static. Let DSP engine have its own report queue dostonct from Main Window message queue

This commit is contained in:
f4exb 2015-08-09 04:09:05 +02:00
parent 5f8bec8d86
commit 3fd1346d08
6 changed files with 62 additions and 28 deletions

View File

@ -44,10 +44,13 @@ public:
StError
};
DSPEngine(MessageQueue* reportQueue, QObject* parent = NULL);
DSPEngine(QObject* parent = NULL);
~DSPEngine();
static DSPEngine *instance();
MessageQueue* getMessageQueue() { return &m_messageQueue; }
MessageQueue* getReportQueue() { return &m_reportQueue; }
void start();
void stop();
@ -72,7 +75,7 @@ public:
private:
MessageQueue m_messageQueue;
MessageQueue* m_reportQueue;
MessageQueue m_reportQueue;
State m_state;

View File

@ -116,6 +116,7 @@ private:
void applySettings();
private slots:
void handleDSPMessages();
void handleMessages();
void updateStatus();
void on_action_Start_triggered();
@ -127,7 +128,6 @@ private slots:
void on_action_View_Fullscreen_toggled(bool checked);
void on_presetSave_clicked();
void on_presetUpdate_clicked();
void on_presetLastLoad_clicked();
void on_presetLoad_clicked();
void on_presetDelete_clicked();
void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

View File

@ -19,16 +19,19 @@ class SDRANGELOVE_API PluginManager : public QObject {
Q_OBJECT
public:
struct Plugin {
struct Plugin
{
QString filename;
QPluginLoader* loader;
PluginInterface* plugin;
Plugin(const QString& _filename, QPluginLoader* pluginLoader, PluginInterface* _plugin) :
filename(_filename),
loader(pluginLoader),
plugin(_plugin)
{ }
};
typedef QList<Plugin> Plugins;
explicit PluginManager(MainWindow* mainWindow, DSPEngine* dspEngine, QObject* parent = NULL);

View File

@ -23,10 +23,8 @@
#include "dsp/dspcommands.h"
#include "dsp/samplesource/samplesource.h"
DSPEngine::DSPEngine(MessageQueue* reportQueue, QObject* parent) :
DSPEngine::DSPEngine(QObject* parent) :
QThread(parent),
m_messageQueue(),
m_reportQueue(reportQueue),
m_state(StNotStarted),
m_sampleSource(NULL),
m_sampleSinks(),
@ -48,6 +46,12 @@ DSPEngine::~DSPEngine()
wait();
}
Q_GLOBAL_STATIC(DSPEngine, dspEngine)
DSPEngine *DSPEngine::instance()
{
return dspEngine;
}
void DSPEngine::start()
{
DSPPing cmd;
@ -349,7 +353,7 @@ void DSPEngine::generateReport()
if(needReport) {
Message* rep = DSPEngineReport::create(m_sampleRate, m_centerFrequency);
rep->submit(m_reportQueue);
rep->submit(&m_reportQueue);
}
}

View File

@ -45,7 +45,7 @@ MainWindow::MainWindow(QWidget* parent) :
m_audioDeviceInfo(new AudioDeviceInfo),
m_messageQueue(new MessageQueue),
m_settings(),
m_dspEngine(new DSPEngine(m_messageQueue)),
m_dspEngine(DSPEngine::instance()),
m_lastEngineState((DSPEngine::State)-1),
m_startOsmoSDRUpdateAfterStop(false),
m_inputGUI(0),
@ -54,6 +54,8 @@ MainWindow::MainWindow(QWidget* parent) :
m_sampleFileName(std::string("./test.sdriq")),
m_pluginManager(new PluginManager(this, m_dspEngine))
{
m_dspEngine->start();
ui->setupUi(this);
delete ui->mainToolBar;
createStatusBar();
@ -83,6 +85,7 @@ MainWindow::MainWindow(QWidget* parent) :
ui->menu_Window->addAction(ui->channelDock->toggleViewAction());
connect(m_messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleMessages()), Qt::QueuedConnection);
connect(m_dspEngine->getReportQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection);
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
@ -90,11 +93,12 @@ MainWindow::MainWindow(QWidget* parent) :
m_masterTimer.start(50);
m_pluginManager->loadPlugins();
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
m_pluginManager->fillSampleSourceSelector(ui->sampleSource);
ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
m_dspEngine->start();
//m_dspEngine->start();
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
m_dspEngine->addSink(m_spectrumVis);
@ -311,12 +315,18 @@ void MainWindow::applySettings()
updateSampleRate();
}
void MainWindow::handleMessages()
void MainWindow::handleDSPMessages()
{
Message* message;
while((message = m_messageQueue->accept()) != 0) {
while ((message = m_dspEngine->getReportQueue()->accept()) != 0)
{
qDebug("Message: %s", message->getIdentifier());
if(DSPEngineReport::match(message)) {
std::cerr << "MainWindow::handleDSPMessages: " << message->getIdentifier() << std::endl;
if (DSPEngineReport::match(message))
{
DSPEngineReport* rep = (DSPEngineReport*)message;
m_sampleRate = rep->getSampleRate();
m_centerFrequency = rep->getCenterFrequency();
@ -324,11 +334,23 @@ void MainWindow::handleMessages()
updateCenterFreqDisplay();
updateSampleRate();
message->completed();
std::cerr << "MainWindow::handleMessages: m_fileSink->configure" << std::endl;
m_fileSink->configure(m_dspEngine->getMessageQueue(), m_sampleFileName, m_sampleRate, m_centerFrequency);
} else {
if(!m_pluginManager->handleMessage(message))
message->completed();
}
}
}
void MainWindow::handleMessages()
{
Message* message;
while ((message = m_messageQueue->accept()) != 0)
{
qDebug("Message: %s", message->getIdentifier());
std::cerr << "MainWindow::handleMessages: " << message->getIdentifier() << std::endl;
if (!m_pluginManager->handleMessage(message)) {
message->completed();
}
}
}
@ -458,12 +480,6 @@ void MainWindow::on_presetUpdate_clicked()
}
}
void MainWindow::on_presetLastLoad_clicked()
{
m_settings.load();
applySettings();
}
void MainWindow::on_presetLoad_clicked()
{
QTreeWidgetItem* item = ui->presetTree->currentItem();

View File

@ -35,8 +35,9 @@ void PluginManager::loadPlugins()
qSort(m_plugins);
for(Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it)
for(Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) {
it->plugin->initPlugin(&m_pluginAPI);
}
updateSampleSourceDevices();
}
@ -289,20 +290,27 @@ int PluginManager::selectSampleSource(const QString& source)
void PluginManager::loadPlugins(const QDir& dir)
{
QDir pluginsDir(dir);
foreach(QString fileName, pluginsDir.entryList(QDir::Files)) {
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
{
QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
PluginInterface* plugin = qobject_cast<PluginInterface*>(loader->instance());
if(loader->isLoaded())
if (loader->isLoaded()) {
qWarning("loaded plugin %s", qPrintable(fileName));
if(plugin != NULL) {
}
if (plugin != NULL) {
m_plugins.append(Plugin(fileName, loader, plugin));
} else {
loader->unload();
delete loader;
}
}
foreach(QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
foreach (QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
loadPlugins(pluginsDir.absoluteFilePath(dirName));
}
}
void PluginManager::renameChannelInstances()