mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 21:20:31 -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:
		
							parent
							
								
									5f8bec8d86
								
							
						
					
					
						commit
						3fd1346d08
					
				@ -44,10 +44,13 @@ public:
 | 
				
			|||||||
		StError
 | 
							StError
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DSPEngine(MessageQueue* reportQueue, QObject* parent = NULL);
 | 
						DSPEngine(QObject* parent = NULL);
 | 
				
			||||||
	~DSPEngine();
 | 
						~DSPEngine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static DSPEngine *instance();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MessageQueue* getMessageQueue() { return &m_messageQueue; }
 | 
						MessageQueue* getMessageQueue() { return &m_messageQueue; }
 | 
				
			||||||
 | 
						MessageQueue* getReportQueue() { return &m_reportQueue; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void start();
 | 
						void start();
 | 
				
			||||||
	void stop();
 | 
						void stop();
 | 
				
			||||||
@ -72,7 +75,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	MessageQueue m_messageQueue;
 | 
						MessageQueue m_messageQueue;
 | 
				
			||||||
	MessageQueue* m_reportQueue;
 | 
						MessageQueue m_reportQueue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	State m_state;
 | 
						State m_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -116,6 +116,7 @@ private:
 | 
				
			|||||||
	void applySettings();
 | 
						void applySettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
 | 
						void handleDSPMessages();
 | 
				
			||||||
	void handleMessages();
 | 
						void handleMessages();
 | 
				
			||||||
	void updateStatus();
 | 
						void updateStatus();
 | 
				
			||||||
	void on_action_Start_triggered();
 | 
						void on_action_Start_triggered();
 | 
				
			||||||
@ -127,7 +128,6 @@ private slots:
 | 
				
			|||||||
	void on_action_View_Fullscreen_toggled(bool checked);
 | 
						void on_action_View_Fullscreen_toggled(bool checked);
 | 
				
			||||||
	void on_presetSave_clicked();
 | 
						void on_presetSave_clicked();
 | 
				
			||||||
	void on_presetUpdate_clicked();
 | 
						void on_presetUpdate_clicked();
 | 
				
			||||||
	void on_presetLastLoad_clicked();
 | 
					 | 
				
			||||||
	void on_presetLoad_clicked();
 | 
						void on_presetLoad_clicked();
 | 
				
			||||||
	void on_presetDelete_clicked();
 | 
						void on_presetDelete_clicked();
 | 
				
			||||||
	void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
 | 
						void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,16 +19,19 @@ class SDRANGELOVE_API PluginManager : public QObject {
 | 
				
			|||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	struct Plugin {
 | 
						struct Plugin
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
		QString filename;
 | 
							QString filename;
 | 
				
			||||||
		QPluginLoader* loader;
 | 
							QPluginLoader* loader;
 | 
				
			||||||
		PluginInterface* plugin;
 | 
							PluginInterface* plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Plugin(const QString& _filename, QPluginLoader* pluginLoader, PluginInterface* _plugin) :
 | 
							Plugin(const QString& _filename, QPluginLoader* pluginLoader, PluginInterface* _plugin) :
 | 
				
			||||||
			filename(_filename),
 | 
								filename(_filename),
 | 
				
			||||||
			loader(pluginLoader),
 | 
								loader(pluginLoader),
 | 
				
			||||||
			plugin(_plugin)
 | 
								plugin(_plugin)
 | 
				
			||||||
		{ }
 | 
							{ }
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	typedef QList<Plugin> Plugins;
 | 
						typedef QList<Plugin> Plugins;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	explicit PluginManager(MainWindow* mainWindow, DSPEngine* dspEngine, QObject* parent = NULL);
 | 
						explicit PluginManager(MainWindow* mainWindow, DSPEngine* dspEngine, QObject* parent = NULL);
 | 
				
			||||||
 | 
				
			|||||||
@ -23,10 +23,8 @@
 | 
				
			|||||||
#include "dsp/dspcommands.h"
 | 
					#include "dsp/dspcommands.h"
 | 
				
			||||||
#include "dsp/samplesource/samplesource.h"
 | 
					#include "dsp/samplesource/samplesource.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DSPEngine::DSPEngine(MessageQueue* reportQueue, QObject* parent) :
 | 
					DSPEngine::DSPEngine(QObject* parent) :
 | 
				
			||||||
	QThread(parent),
 | 
						QThread(parent),
 | 
				
			||||||
	m_messageQueue(),
 | 
					 | 
				
			||||||
	m_reportQueue(reportQueue),
 | 
					 | 
				
			||||||
	m_state(StNotStarted),
 | 
						m_state(StNotStarted),
 | 
				
			||||||
	m_sampleSource(NULL),
 | 
						m_sampleSource(NULL),
 | 
				
			||||||
	m_sampleSinks(),
 | 
						m_sampleSinks(),
 | 
				
			||||||
@ -48,6 +46,12 @@ DSPEngine::~DSPEngine()
 | 
				
			|||||||
	wait();
 | 
						wait();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Q_GLOBAL_STATIC(DSPEngine, dspEngine)
 | 
				
			||||||
 | 
					DSPEngine *DSPEngine::instance()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return dspEngine;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPEngine::start()
 | 
					void DSPEngine::start()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	DSPPing cmd;
 | 
						DSPPing cmd;
 | 
				
			||||||
@ -349,7 +353,7 @@ void DSPEngine::generateReport()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if(needReport) {
 | 
						if(needReport) {
 | 
				
			||||||
		Message* rep = DSPEngineReport::create(m_sampleRate, m_centerFrequency);
 | 
							Message* rep = DSPEngineReport::create(m_sampleRate, m_centerFrequency);
 | 
				
			||||||
		rep->submit(m_reportQueue);
 | 
							rep->submit(&m_reportQueue);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -45,7 +45,7 @@ MainWindow::MainWindow(QWidget* parent) :
 | 
				
			|||||||
	m_audioDeviceInfo(new AudioDeviceInfo),
 | 
						m_audioDeviceInfo(new AudioDeviceInfo),
 | 
				
			||||||
	m_messageQueue(new MessageQueue),
 | 
						m_messageQueue(new MessageQueue),
 | 
				
			||||||
	m_settings(),
 | 
						m_settings(),
 | 
				
			||||||
	m_dspEngine(new DSPEngine(m_messageQueue)),
 | 
						m_dspEngine(DSPEngine::instance()),
 | 
				
			||||||
	m_lastEngineState((DSPEngine::State)-1),
 | 
						m_lastEngineState((DSPEngine::State)-1),
 | 
				
			||||||
	m_startOsmoSDRUpdateAfterStop(false),
 | 
						m_startOsmoSDRUpdateAfterStop(false),
 | 
				
			||||||
	m_inputGUI(0),
 | 
						m_inputGUI(0),
 | 
				
			||||||
@ -54,6 +54,8 @@ MainWindow::MainWindow(QWidget* parent) :
 | 
				
			|||||||
	m_sampleFileName(std::string("./test.sdriq")),
 | 
						m_sampleFileName(std::string("./test.sdriq")),
 | 
				
			||||||
	m_pluginManager(new PluginManager(this, m_dspEngine))
 | 
						m_pluginManager(new PluginManager(this, m_dspEngine))
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						m_dspEngine->start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ui->setupUi(this);
 | 
						ui->setupUi(this);
 | 
				
			||||||
	delete ui->mainToolBar;
 | 
						delete ui->mainToolBar;
 | 
				
			||||||
	createStatusBar();
 | 
						createStatusBar();
 | 
				
			||||||
@ -83,6 +85,7 @@ MainWindow::MainWindow(QWidget* parent) :
 | 
				
			|||||||
	ui->menu_Window->addAction(ui->channelDock->toggleViewAction());
 | 
						ui->menu_Window->addAction(ui->channelDock->toggleViewAction());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	connect(m_messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleMessages()), Qt::QueuedConnection);
 | 
						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()));
 | 
						connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
 | 
				
			||||||
	m_statusTimer.start(500);
 | 
						m_statusTimer.start(500);
 | 
				
			||||||
@ -90,11 +93,12 @@ MainWindow::MainWindow(QWidget* parent) :
 | 
				
			|||||||
	m_masterTimer.start(50);
 | 
						m_masterTimer.start(50);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_pluginManager->loadPlugins();
 | 
						m_pluginManager->loadPlugins();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
 | 
						bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
 | 
				
			||||||
	m_pluginManager->fillSampleSourceSelector(ui->sampleSource);
 | 
						m_pluginManager->fillSampleSourceSelector(ui->sampleSource);
 | 
				
			||||||
	ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
 | 
						ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_dspEngine->start();
 | 
						//m_dspEngine->start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_spectrumVis = new SpectrumVis(ui->glSpectrum);
 | 
						m_spectrumVis = new SpectrumVis(ui->glSpectrum);
 | 
				
			||||||
	m_dspEngine->addSink(m_spectrumVis);
 | 
						m_dspEngine->addSink(m_spectrumVis);
 | 
				
			||||||
@ -311,12 +315,18 @@ void MainWindow::applySettings()
 | 
				
			|||||||
	updateSampleRate();
 | 
						updateSampleRate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::handleMessages()
 | 
					void MainWindow::handleDSPMessages()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Message* message;
 | 
						Message* message;
 | 
				
			||||||
	while((message = m_messageQueue->accept()) != 0) {
 | 
					
 | 
				
			||||||
 | 
						while ((message = m_dspEngine->getReportQueue()->accept()) != 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
		qDebug("Message: %s", message->getIdentifier());
 | 
							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;
 | 
								DSPEngineReport* rep = (DSPEngineReport*)message;
 | 
				
			||||||
			m_sampleRate = rep->getSampleRate();
 | 
								m_sampleRate = rep->getSampleRate();
 | 
				
			||||||
			m_centerFrequency = rep->getCenterFrequency();
 | 
								m_centerFrequency = rep->getCenterFrequency();
 | 
				
			||||||
@ -324,11 +334,23 @@ void MainWindow::handleMessages()
 | 
				
			|||||||
			updateCenterFreqDisplay();
 | 
								updateCenterFreqDisplay();
 | 
				
			||||||
			updateSampleRate();
 | 
								updateSampleRate();
 | 
				
			||||||
			message->completed();
 | 
								message->completed();
 | 
				
			||||||
			std::cerr << "MainWindow::handleMessages: m_fileSink->configure" << std::endl;
 | 
					 | 
				
			||||||
			m_fileSink->configure(m_dspEngine->getMessageQueue(), m_sampleFileName, m_sampleRate, m_centerFrequency);
 | 
								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()
 | 
					void MainWindow::on_presetLoad_clicked()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QTreeWidgetItem* item = ui->presetTree->currentItem();
 | 
						QTreeWidgetItem* item = ui->presetTree->currentItem();
 | 
				
			||||||
 | 
				
			|||||||
@ -35,8 +35,9 @@ void PluginManager::loadPlugins()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	qSort(m_plugins);
 | 
						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);
 | 
							it->plugin->initPlugin(&m_pluginAPI);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	updateSampleSourceDevices();
 | 
						updateSampleSourceDevices();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -289,20 +290,27 @@ int PluginManager::selectSampleSource(const QString& source)
 | 
				
			|||||||
void PluginManager::loadPlugins(const QDir& dir)
 | 
					void PluginManager::loadPlugins(const QDir& dir)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QDir pluginsDir(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));
 | 
							QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
 | 
				
			||||||
		PluginInterface* plugin = qobject_cast<PluginInterface*>(loader->instance());
 | 
							PluginInterface* plugin = qobject_cast<PluginInterface*>(loader->instance());
 | 
				
			||||||
		if(loader->isLoaded())
 | 
					
 | 
				
			||||||
 | 
							if (loader->isLoaded()) {
 | 
				
			||||||
			qWarning("loaded plugin %s", qPrintable(fileName));
 | 
								qWarning("loaded plugin %s", qPrintable(fileName));
 | 
				
			||||||
		if(plugin != NULL) {
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (plugin != NULL) {
 | 
				
			||||||
			m_plugins.append(Plugin(fileName, loader, plugin));
 | 
								m_plugins.append(Plugin(fileName, loader, plugin));
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			loader->unload();
 | 
								loader->unload();
 | 
				
			||||||
			delete loader;
 | 
								delete loader;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	foreach(QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
 | 
					
 | 
				
			||||||
 | 
						foreach (QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
 | 
				
			||||||
		loadPlugins(pluginsDir.absoluteFilePath(dirName));
 | 
							loadPlugins(pluginsDir.absoluteFilePath(dirName));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PluginManager::renameChannelInstances()
 | 
					void PluginManager::renameChannelInstances()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user