mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 04:50:29 -04:00 
			
		
		
		
	File Sink: applied new threadning method. Part of #1346
This commit is contained in:
		
							parent
							
								
									6040bab4f9
								
							
						
					
					
						commit
						b44eb18df6
					
				| @ -22,6 +22,8 @@ | |||||||
| #include <QNetworkAccessManager> | #include <QNetworkAccessManager> | ||||||
| #include <QNetworkReply> | #include <QNetworkReply> | ||||||
| #include <QBuffer> | #include <QBuffer> | ||||||
|  | #include <QThread> | ||||||
|  | #include <QMutexLocker> | ||||||
| 
 | 
 | ||||||
| #include "SWGChannelSettings.h" | #include "SWGChannelSettings.h" | ||||||
| #include "SWGWorkspaceInfo.h" | #include "SWGWorkspaceInfo.h" | ||||||
| @ -52,6 +54,8 @@ const char* const FileSink::m_channelId = "FileSink"; | |||||||
| FileSink::FileSink(DeviceAPI *deviceAPI) : | FileSink::FileSink(DeviceAPI *deviceAPI) : | ||||||
|         ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), |         ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), | ||||||
|         m_deviceAPI(deviceAPI), |         m_deviceAPI(deviceAPI), | ||||||
|  |         m_mutex(QMutex::Recursive), | ||||||
|  |         m_running(false), | ||||||
|         m_spectrumVis(SDR_RX_SCALEF), |         m_spectrumVis(SDR_RX_SCALEF), | ||||||
|         m_centerFrequency(0), |         m_centerFrequency(0), | ||||||
|         m_frequencyOffset(0), |         m_frequencyOffset(0), | ||||||
| @ -59,10 +63,6 @@ FileSink::FileSink(DeviceAPI *deviceAPI) : | |||||||
| { | { | ||||||
|     setObjectName(m_channelId); |     setObjectName(m_channelId); | ||||||
| 
 | 
 | ||||||
|     m_basebandSink = new FileSinkBaseband(); |  | ||||||
|     m_basebandSink->setSpectrumSink(&m_spectrumVis); |  | ||||||
|     m_basebandSink->moveToThread(&m_thread); |  | ||||||
| 
 |  | ||||||
|     applySettings(m_settings, true); |     applySettings(m_settings, true); | ||||||
| 
 | 
 | ||||||
|     m_deviceAPI->addChannelSink(this); |     m_deviceAPI->addChannelSink(this); | ||||||
| @ -81,10 +81,13 @@ FileSink::FileSink(DeviceAPI *deviceAPI) : | |||||||
|         this, |         this, | ||||||
|         &FileSink::handleIndexInDeviceSetChanged |         &FileSink::handleIndexInDeviceSetChanged | ||||||
|     ); |     ); | ||||||
|  | 
 | ||||||
|  |     start(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| FileSink::~FileSink() | FileSink::~FileSink() | ||||||
| { | { | ||||||
|  |     qDebug("FileSink::~FileSink"); | ||||||
|     QObject::disconnect( |     QObject::disconnect( | ||||||
|         m_networkManager, |         m_networkManager, | ||||||
|         &QNetworkAccessManager::finished, |         &QNetworkAccessManager::finished, | ||||||
| @ -95,13 +98,9 @@ FileSink::~FileSink() | |||||||
|     m_deviceAPI->removeChannelSinkAPI(this); |     m_deviceAPI->removeChannelSinkAPI(this); | ||||||
|     m_deviceAPI->removeChannelSink(this); |     m_deviceAPI->removeChannelSink(this); | ||||||
| 
 | 
 | ||||||
|     if (m_basebandSink->isRunning()) { |  | ||||||
|     stop(); |     stop(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|     delete m_basebandSink; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void FileSink::setDeviceAPI(DeviceAPI *deviceAPI) | void FileSink::setDeviceAPI(DeviceAPI *deviceAPI) | ||||||
| { | { | ||||||
|     if (deviceAPI != m_deviceAPI) |     if (deviceAPI != m_deviceAPI) | ||||||
| @ -117,8 +116,11 @@ void FileSink::setDeviceAPI(DeviceAPI *deviceAPI) | |||||||
| void FileSink::setMessageQueueToGUI(MessageQueue* queue) | void FileSink::setMessageQueueToGUI(MessageQueue* queue) | ||||||
| { | { | ||||||
|     ChannelAPI::setMessageQueueToGUI(queue); |     ChannelAPI::setMessageQueueToGUI(queue); | ||||||
|  | 
 | ||||||
|  |     if (m_running) { | ||||||
|         m_basebandSink->setMessageQueueToGUI(queue); |         m_basebandSink->setMessageQueueToGUI(queue); | ||||||
|     } |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| uint32_t FileSink::getNumberOfDeviceStreams() const | uint32_t FileSink::getNumberOfDeviceStreams() const | ||||||
| { | { | ||||||
| @ -128,18 +130,55 @@ uint32_t FileSink::getNumberOfDeviceStreams() const | |||||||
| void FileSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) | void FileSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) | ||||||
| { | { | ||||||
|     (void) firstOfBurst; |     (void) firstOfBurst; | ||||||
|  | 
 | ||||||
|  |     if (m_running) { | ||||||
|         m_basebandSink->feed(begin, end); |         m_basebandSink->feed(begin, end); | ||||||
|     } |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void FileSink::start() | void FileSink::start() | ||||||
| { | { | ||||||
|  |     QMutexLocker m_lock(&m_mutex); | ||||||
|  | 
 | ||||||
|  |     if (m_running) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 	qDebug("FileSink::start"); | 	qDebug("FileSink::start"); | ||||||
|     m_basebandSink->reset(); |     m_thread = new QThread(); | ||||||
|  |     m_basebandSink = new FileSinkBaseband(); | ||||||
|  |     m_basebandSink->setFifoLabel(QString("%1 [%2:%3]") | ||||||
|  |         .arg(m_channelId) | ||||||
|  |         .arg(m_deviceAPI->getDeviceSetIndex()) | ||||||
|  |         .arg(getIndexInDeviceSet()) | ||||||
|  |     ); | ||||||
|  |     m_basebandSink->setSpectrumSink(&m_spectrumVis); | ||||||
|  |     m_basebandSink->moveToThread(m_thread); | ||||||
|  | 
 | ||||||
|  |     QObject::connect( | ||||||
|  |         m_thread, | ||||||
|  |         &QThread::started, | ||||||
|  |         m_basebandSink, | ||||||
|  |         &FileSinkBaseband::startWork | ||||||
|  |     ); | ||||||
|  |     QObject::connect( | ||||||
|  |         m_thread, | ||||||
|  |         &QThread::finished, | ||||||
|  |         m_basebandSink, | ||||||
|  |         &QObject::deleteLater | ||||||
|  |     ); | ||||||
|  |     QObject::connect( | ||||||
|  |         m_thread, | ||||||
|  |         &QThread::finished, | ||||||
|  |         m_thread, | ||||||
|  |         &QThread::deleteLater | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|     m_basebandSink->setMessageQueueToGUI(getMessageQueueToGUI()); |     m_basebandSink->setMessageQueueToGUI(getMessageQueueToGUI()); | ||||||
|     m_basebandSink->setDeviceHwId(m_deviceAPI->getHardwareId()); |     m_basebandSink->setDeviceHwId(m_deviceAPI->getHardwareId()); | ||||||
|     m_basebandSink->setDeviceUId(m_deviceAPI->getDeviceUID()); |     m_basebandSink->setDeviceUId(m_deviceAPI->getDeviceUID()); | ||||||
|     m_basebandSink->startWork(); |     m_basebandSink->startWork(); | ||||||
|     m_thread.start(); |     m_thread->start(); | ||||||
| 
 | 
 | ||||||
|     DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency); |     DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency); | ||||||
|     m_basebandSink->getInputMessageQueue()->push(dspMsg); |     m_basebandSink->getInputMessageQueue()->push(dspMsg); | ||||||
| @ -152,14 +191,23 @@ void FileSink::start() | |||||||
|         MsgReportStartStop *msg = MsgReportStartStop::create(true); |         MsgReportStartStop *msg = MsgReportStartStop::create(true); | ||||||
|         getMessageQueueToGUI()->push(msg); |         getMessageQueueToGUI()->push(msg); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     m_running = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSink::stop() | void FileSink::stop() | ||||||
| { | { | ||||||
|     qDebug("FileSink::stop"); |     QMutexLocker m_lock(&m_mutex); | ||||||
|     m_basebandSink->stopWork(); | 
 | ||||||
| 	m_thread.exit(); |     if (!m_running) { | ||||||
| 	m_thread.wait(); |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     qDebug("FileSink::stop:"); | ||||||
|  |     m_running = false; | ||||||
|  | 
 | ||||||
|  | 	m_thread->quit(); | ||||||
|  | 	m_thread->wait(); | ||||||
| 
 | 
 | ||||||
|     if (getMessageQueueToGUI()) |     if (getMessageQueueToGUI()) | ||||||
|     { |     { | ||||||
| @ -180,8 +228,10 @@ bool FileSink::handleMessage(const Message& cmd) | |||||||
| 
 | 
 | ||||||
|         m_basebandSampleRate = cfg.getSampleRate(); |         m_basebandSampleRate = cfg.getSampleRate(); | ||||||
|         m_centerFrequency = cfg.getCenterFrequency(); |         m_centerFrequency = cfg.getCenterFrequency(); | ||||||
|         DSPSignalNotification *notif = new DSPSignalNotification(cfg); | 
 | ||||||
|         m_basebandSink->getInputMessageQueue()->push(notif); |         if (m_running) { | ||||||
|  |             m_basebandSink->getInputMessageQueue()->push(new DSPSignalNotification(cfg)); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         if (getMessageQueueToGUI()) { |         if (getMessageQueueToGUI()) { | ||||||
|             getMessageQueueToGUI()->push(new DSPSignalNotification(cfg)); |             getMessageQueueToGUI()->push(new DSPSignalNotification(cfg)); | ||||||
| @ -328,8 +378,11 @@ void FileSink::applySettings(const FileSinkSettings& settings, bool force) | |||||||
|         reverseAPIKeys.append("streamIndex"); |         reverseAPIKeys.append("streamIndex"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if (m_running) | ||||||
|  |     { | ||||||
|         FileSinkBaseband::MsgConfigureFileSinkBaseband *msg = FileSinkBaseband::MsgConfigureFileSinkBaseband::create(settings, force); |         FileSinkBaseband::MsgConfigureFileSinkBaseband *msg = FileSinkBaseband::MsgConfigureFileSinkBaseband::create(settings, force); | ||||||
|         m_basebandSink->getInputMessageQueue()->push(msg); |         m_basebandSink->getInputMessageQueue()->push(msg); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if ((settings.m_useReverseAPI) && (reverseAPIKeys.size() != 0)) |     if ((settings.m_useReverseAPI) && (reverseAPIKeys.size() != 0)) | ||||||
|     { |     { | ||||||
| @ -352,14 +405,17 @@ void FileSink::applySettings(const FileSinkSettings& settings, bool force) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSink::record(bool record) | void FileSink::record(bool record) | ||||||
|  | { | ||||||
|  |     if (m_running) | ||||||
|     { |     { | ||||||
|         FileSinkBaseband::MsgConfigureFileSinkWork *msg = FileSinkBaseband::MsgConfigureFileSinkWork::create(record); |         FileSinkBaseband::MsgConfigureFileSinkWork *msg = FileSinkBaseband::MsgConfigureFileSinkWork::create(record); | ||||||
|         m_basebandSink->getInputMessageQueue()->push(msg); |         m_basebandSink->getInputMessageQueue()->push(msg); | ||||||
|     } |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| uint64_t FileSink::getMsCount() const | uint64_t FileSink::getMsCount() const | ||||||
| { | { | ||||||
|     if (m_basebandSink) { |     if (m_running) { | ||||||
|         return m_basebandSink->getMsCount(); |         return m_basebandSink->getMsCount(); | ||||||
|     } else { |     } else { | ||||||
|         return 0; |         return 0; | ||||||
| @ -368,7 +424,7 @@ uint64_t FileSink::getMsCount() const | |||||||
| 
 | 
 | ||||||
| uint64_t FileSink::getByteCount() const | uint64_t FileSink::getByteCount() const | ||||||
| { | { | ||||||
|     if (m_basebandSink) { |     if (m_running) { | ||||||
|         return m_basebandSink->getByteCount(); |         return m_basebandSink->getByteCount(); | ||||||
|     } else { |     } else { | ||||||
|         return 0; |         return 0; | ||||||
| @ -377,7 +433,7 @@ uint64_t FileSink::getByteCount() const | |||||||
| 
 | 
 | ||||||
| unsigned int FileSink::getNbTracks() const | unsigned int FileSink::getNbTracks() const | ||||||
| { | { | ||||||
|     if (m_basebandSink) { |     if (m_running) { | ||||||
|         return m_basebandSink->getNbTracks(); |         return m_basebandSink->getNbTracks(); | ||||||
|     } else { |     } else { | ||||||
|         return 0; |         return 0; | ||||||
| @ -454,9 +510,12 @@ int FileSink::webapiActionsPost( | |||||||
|             bool record = swgFileSinkActions->getRecord() != 0; |             bool record = swgFileSinkActions->getRecord() != 0; | ||||||
| 
 | 
 | ||||||
|             if (!m_settings.m_squelchRecordingEnable) |             if (!m_settings.m_squelchRecordingEnable) | ||||||
|  |             { | ||||||
|  |                 if (m_running) | ||||||
|                 { |                 { | ||||||
|                     FileSinkBaseband::MsgConfigureFileSinkWork *msg = FileSinkBaseband::MsgConfigureFileSinkWork::create(record); |                     FileSinkBaseband::MsgConfigureFileSinkWork *msg = FileSinkBaseband::MsgConfigureFileSinkWork::create(record); | ||||||
|                     m_basebandSink->getInputMessageQueue()->push(msg); |                     m_basebandSink->getInputMessageQueue()->push(msg); | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|                 if (getMessageQueueToGUI()) |                 if (getMessageQueueToGUI()) | ||||||
|                 { |                 { | ||||||
| @ -623,16 +682,20 @@ void FileSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& resp | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSink::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) | void FileSink::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) | ||||||
|  | { | ||||||
|  |     response.getFileSinkReport()->setRecordTimeMs(getMsCount()); | ||||||
|  |     response.getFileSinkReport()->setRecordSize(getByteCount()); | ||||||
|  |     response.getFileSinkReport()->setRecordCaptures(getNbTracks()); | ||||||
|  | 
 | ||||||
|  |     if (m_running) | ||||||
|     { |     { | ||||||
|         response.getFileSinkReport()->setSpectrumSquelch(m_basebandSink->isSquelchOpen() ? 1 : 0); |         response.getFileSinkReport()->setSpectrumSquelch(m_basebandSink->isSquelchOpen() ? 1 : 0); | ||||||
|         response.getFileSinkReport()->setSpectrumMax(m_basebandSink->getSpecMax()); |         response.getFileSinkReport()->setSpectrumMax(m_basebandSink->getSpecMax()); | ||||||
|         response.getFileSinkReport()->setSinkSampleRate(m_basebandSink->getSinkSampleRate()); |         response.getFileSinkReport()->setSinkSampleRate(m_basebandSink->getSinkSampleRate()); | ||||||
|     response.getFileSinkReport()->setRecordTimeMs(getMsCount()); |  | ||||||
|     response.getFileSinkReport()->setRecordSize(getByteCount()); |  | ||||||
|         response.getFileSinkReport()->setRecording(m_basebandSink->isRecording() ? 1 : 0); |         response.getFileSinkReport()->setRecording(m_basebandSink->isRecording() ? 1 : 0); | ||||||
|     response.getFileSinkReport()->setRecordCaptures(getNbTracks()); |  | ||||||
|         response.getFileSinkReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); |         response.getFileSinkReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); | ||||||
|     } |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void FileSink::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const FileSinkSettings& settings, bool force) | void FileSink::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const FileSinkSettings& settings, bool force) | ||||||
| { | { | ||||||
| @ -779,7 +842,7 @@ void FileSink::networkManagerFinished(QNetworkReply *reply) | |||||||
| 
 | 
 | ||||||
| void FileSink::handleIndexInDeviceSetChanged(int index) | void FileSink::handleIndexInDeviceSetChanged(int index) | ||||||
| { | { | ||||||
|     if (index < 0) { |     if (!m_running || (index < 0)) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,7 +19,6 @@ | |||||||
| #define INCLUDE_FILESINK_H_ | #define INCLUDE_FILESINK_H_ | ||||||
| 
 | 
 | ||||||
| #include <QObject> | #include <QObject> | ||||||
| #include <QThread> |  | ||||||
| #include <QMutex> | #include <QMutex> | ||||||
| #include <QNetworkRequest> | #include <QNetworkRequest> | ||||||
| 
 | 
 | ||||||
| @ -31,6 +30,7 @@ | |||||||
| 
 | 
 | ||||||
| class QNetworkAccessManager; | class QNetworkAccessManager; | ||||||
| class QNetworkReply; | class QNetworkReply; | ||||||
|  | class QThread; | ||||||
| 
 | 
 | ||||||
| class DeviceAPI; | class DeviceAPI; | ||||||
| class DeviceSampleSource; | class DeviceSampleSource; | ||||||
| @ -159,8 +159,10 @@ public: | |||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     DeviceAPI *m_deviceAPI; |     DeviceAPI *m_deviceAPI; | ||||||
|     QThread m_thread; |     QThread *m_thread; | ||||||
|     FileSinkBaseband *m_basebandSink; |     FileSinkBaseband *m_basebandSink; | ||||||
|  |     QMutex m_mutex; | ||||||
|  |     bool m_running; | ||||||
|     FileSinkSettings m_settings; |     FileSinkSettings m_settings; | ||||||
|     SpectrumVis m_spectrumVis; |     SpectrumVis m_spectrumVis; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,9 +15,9 @@ | |||||||
| // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | ||||||
| ///////////////////////////////////////////////////////////////////////////////////
 | ///////////////////////////////////////////////////////////////////////////////////
 | ||||||
| 
 | 
 | ||||||
|  | #include <QTimer> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
| 
 | 
 | ||||||
| #include "dsp/downchannelizer.h" |  | ||||||
| #include "dsp/dspengine.h" | #include "dsp/dspengine.h" | ||||||
| #include "dsp/dspcommands.h" | #include "dsp/dspcommands.h" | ||||||
| #include "dsp/spectrumvis.h" | #include "dsp/spectrumvis.h" | ||||||
| @ -30,24 +30,22 @@ MESSAGE_CLASS_DEFINITION(FileSinkBaseband::MsgConfigureFileSinkBaseband, Message | |||||||
| MESSAGE_CLASS_DEFINITION(FileSinkBaseband::MsgConfigureFileSinkWork, Message) | MESSAGE_CLASS_DEFINITION(FileSinkBaseband::MsgConfigureFileSinkWork, Message) | ||||||
| 
 | 
 | ||||||
| FileSinkBaseband::FileSinkBaseband() : | FileSinkBaseband::FileSinkBaseband() : | ||||||
|  |     m_channelizer(&m_sink), | ||||||
|     m_specMax(0), |     m_specMax(0), | ||||||
|     m_squelchLevel(0), |     m_squelchLevel(0), | ||||||
|     m_squelchOpen(false), |     m_squelchOpen(false), | ||||||
|     m_running(false), |  | ||||||
|     m_mutex(QMutex::Recursive) |     m_mutex(QMutex::Recursive) | ||||||
| { | { | ||||||
|     m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000)); |  | ||||||
|     m_channelizer = new DownChannelizer(&m_sink); |  | ||||||
| 
 |  | ||||||
|     qDebug("FileSinkBaseband::FileSinkBaseband"); |     qDebug("FileSinkBaseband::FileSinkBaseband"); | ||||||
|     connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick())); |     m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000)); | ||||||
|     m_timer.start(200); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| FileSinkBaseband::~FileSinkBaseband() | FileSinkBaseband::~FileSinkBaseband() | ||||||
| { | { | ||||||
|  |     qDebug("FileSinkBaseband::~FileSinkBaseband"); | ||||||
|     m_inputMessageQueue.clear(); |     m_inputMessageQueue.clear(); | ||||||
|     delete m_channelizer; |     stopWork(); | ||||||
|  |     qDebug("FileSinkBaseband::~FileSinkBaseband: done"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkBaseband::reset() | void FileSinkBaseband::reset() | ||||||
| @ -60,6 +58,15 @@ void FileSinkBaseband::reset() | |||||||
| void FileSinkBaseband::startWork() | void FileSinkBaseband::startWork() | ||||||
| { | { | ||||||
|     QMutexLocker mutexLocker(&m_mutex); |     QMutexLocker mutexLocker(&m_mutex); | ||||||
|  |     qDebug("FileSinkBaseband::startWork"); | ||||||
|  |     m_timer = new QTimer(); | ||||||
|  |     connect( | ||||||
|  |         m_timer, | ||||||
|  |         &QTimer::timeout, | ||||||
|  |         this, | ||||||
|  |         &FileSinkBaseband::tick | ||||||
|  |     ); | ||||||
|  |     m_timer->start(200); | ||||||
|     QObject::connect( |     QObject::connect( | ||||||
|         &m_sampleFifo, |         &m_sampleFifo, | ||||||
|         &SampleSinkFifo::dataReady, |         &SampleSinkFifo::dataReady, | ||||||
| @ -67,22 +74,33 @@ void FileSinkBaseband::startWork() | |||||||
|         &FileSinkBaseband::handleData, |         &FileSinkBaseband::handleData, | ||||||
|         Qt::QueuedConnection |         Qt::QueuedConnection | ||||||
|     ); |     ); | ||||||
|     connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); |     QObject::connect( | ||||||
|     m_running = true; |         &m_inputMessageQueue, | ||||||
|  |         &MessageQueue::messageEnqueued, | ||||||
|  |         this, | ||||||
|  |         &FileSinkBaseband::handleInputMessages | ||||||
|  |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkBaseband::stopWork() | void FileSinkBaseband::stopWork() | ||||||
| { | { | ||||||
|     QMutexLocker mutexLocker(&m_mutex); |     QMutexLocker mutexLocker(&m_mutex); | ||||||
|  |     qDebug("FileSinkBaseband::stopWork"); | ||||||
|  |     m_timer->stop(); | ||||||
|     m_sink.stopRecording(); |     m_sink.stopRecording(); | ||||||
|     disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); |     QObject::disconnect( | ||||||
|  |         &m_inputMessageQueue, | ||||||
|  |         &MessageQueue::messageEnqueued, | ||||||
|  |         this, | ||||||
|  |         &FileSinkBaseband::handleInputMessages | ||||||
|  |     ); | ||||||
|     QObject::disconnect( |     QObject::disconnect( | ||||||
|         &m_sampleFifo, |         &m_sampleFifo, | ||||||
|         &SampleSinkFifo::dataReady, |         &SampleSinkFifo::dataReady, | ||||||
|         this, |         this, | ||||||
|         &FileSinkBaseband::handleData |         &FileSinkBaseband::handleData | ||||||
|     ); |     ); | ||||||
|     m_running = false; |     delete m_timer; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) | void FileSinkBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) | ||||||
| @ -105,12 +123,12 @@ void FileSinkBaseband::handleData() | |||||||
| 
 | 
 | ||||||
| 		// first part of FIFO data
 | 		// first part of FIFO data
 | ||||||
|         if (part1begin != part1end) { |         if (part1begin != part1end) { | ||||||
|             m_channelizer->feed(part1begin, part1end); |             m_channelizer.feed(part1begin, part1end); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 		// second part of FIFO data (used when block wraps around)
 | 		// second part of FIFO data (used when block wraps around)
 | ||||||
| 		if(part2begin != part2end) { | 		if(part2begin != part2end) { | ||||||
|             m_channelizer->feed(part2begin, part2end); |             m_channelizer.feed(part2begin, part2end); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 		m_sampleFifo.readCommit((unsigned int) count); | 		m_sampleFifo.readCommit((unsigned int) count); | ||||||
| @ -150,13 +168,13 @@ bool FileSinkBaseband::handleMessage(const Message& cmd) | |||||||
|             << " cnterFrequency: " << notif.getCenterFrequency(); |             << " cnterFrequency: " << notif.getCenterFrequency(); | ||||||
|         m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(notif.getSampleRate())); |         m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(notif.getSampleRate())); | ||||||
|         m_centerFrequency = notif.getCenterFrequency(); |         m_centerFrequency = notif.getCenterFrequency(); | ||||||
|         m_channelizer->setBasebandSampleRate(notif.getSampleRate()); |         m_channelizer.setBasebandSampleRate(notif.getSampleRate()); | ||||||
|         int desiredSampleRate = m_channelizer->getBasebandSampleRate() / (1<<m_settings.m_log2Decim); |         int desiredSampleRate = m_channelizer.getBasebandSampleRate() / (1<<m_settings.m_log2Decim); | ||||||
|         m_channelizer->setChannelization(desiredSampleRate, m_settings.m_inputFrequencyOffset); |         m_channelizer.setChannelization(desiredSampleRate, m_settings.m_inputFrequencyOffset); | ||||||
|         m_sink.applyChannelSettings( |         m_sink.applyChannelSettings( | ||||||
|             m_channelizer->getChannelSampleRate(), |             m_channelizer.getChannelSampleRate(), | ||||||
|             desiredSampleRate, |             desiredSampleRate, | ||||||
|             m_channelizer->getChannelFrequencyOffset(), |             m_channelizer.getChannelFrequencyOffset(), | ||||||
|             m_centerFrequency + m_settings.m_inputFrequencyOffset); |             m_centerFrequency + m_settings.m_inputFrequencyOffset); | ||||||
| 
 | 
 | ||||||
| 		return true; | 		return true; | ||||||
| @ -193,12 +211,12 @@ void FileSinkBaseband::applySettings(const FileSinkSettings& settings, bool forc | |||||||
|     if ((settings.m_log2Decim != m_settings.m_log2Decim) |     if ((settings.m_log2Decim != m_settings.m_log2Decim) | ||||||
|      || (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) |      || (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) | ||||||
|     { |     { | ||||||
|         int desiredSampleRate = m_channelizer->getBasebandSampleRate() / (1<<settings.m_log2Decim); |         int desiredSampleRate = m_channelizer.getBasebandSampleRate() / (1<<settings.m_log2Decim); | ||||||
|         m_channelizer->setChannelization(desiredSampleRate, settings.m_inputFrequencyOffset); |         m_channelizer.setChannelization(desiredSampleRate, settings.m_inputFrequencyOffset); | ||||||
|         m_sink.applyChannelSettings( |         m_sink.applyChannelSettings( | ||||||
|             m_channelizer->getChannelSampleRate(), |             m_channelizer.getChannelSampleRate(), | ||||||
|             desiredSampleRate, |             desiredSampleRate, | ||||||
|             m_channelizer->getChannelFrequencyOffset(), |             m_channelizer.getChannelFrequencyOffset(), | ||||||
|             m_centerFrequency + settings.m_inputFrequencyOffset); |             m_centerFrequency + settings.m_inputFrequencyOffset); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -218,7 +236,7 @@ void FileSinkBaseband::applySettings(const FileSinkSettings& settings, bool forc | |||||||
| 
 | 
 | ||||||
| int FileSinkBaseband::getChannelSampleRate() const | int FileSinkBaseband::getChannelSampleRate() const | ||||||
| { | { | ||||||
|     return m_channelizer->getChannelSampleRate(); |     return m_channelizer.getChannelSampleRate(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkBaseband::tick() | void FileSinkBaseband::tick() | ||||||
|  | |||||||
| @ -20,17 +20,17 @@ | |||||||
| 
 | 
 | ||||||
| #include <QObject> | #include <QObject> | ||||||
| #include <QMutex> | #include <QMutex> | ||||||
| #include <QTimer> |  | ||||||
| 
 | 
 | ||||||
| #include "dsp/samplesinkfifo.h" | #include "dsp/samplesinkfifo.h" | ||||||
|  | #include "dsp/downchannelizer.h" | ||||||
| #include "util/message.h" | #include "util/message.h" | ||||||
| #include "util/messagequeue.h" | #include "util/messagequeue.h" | ||||||
| 
 | 
 | ||||||
| #include "filesinksink.h" | #include "filesinksink.h" | ||||||
| #include "filesinksettings.h" | #include "filesinksettings.h" | ||||||
| 
 | 
 | ||||||
| class DownChannelizer; |  | ||||||
| class SpectrumVis; | class SpectrumVis; | ||||||
|  | class QTimer; | ||||||
| 
 | 
 | ||||||
| class FileSinkBaseband : public QObject | class FileSinkBaseband : public QObject | ||||||
| { | { | ||||||
| @ -84,12 +84,10 @@ public: | |||||||
| 
 | 
 | ||||||
|     void reset(); |     void reset(); | ||||||
|     void startWork(); |     void startWork(); | ||||||
|     void stopWork(); |  | ||||||
|     void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end); |     void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end); | ||||||
|     MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
 |     MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
 | ||||||
|     int getChannelSampleRate() const; |     int getChannelSampleRate() const; | ||||||
|     void setBasebandSampleRate(int sampleRate); |     void setBasebandSampleRate(int sampleRate); | ||||||
|     bool isRunning() const { return m_running; } |  | ||||||
|     void setSpectrumSink(SpectrumVis* spectrumSink) { m_spectrumSink = spectrumSink; m_sink.setSpectrumSink(spectrumSink); } |     void setSpectrumSink(SpectrumVis* spectrumSink) { m_spectrumSink = spectrumSink; m_sink.setSpectrumSink(spectrumSink); } | ||||||
|     uint64_t getMsCount() const { return m_sink.getMsCount(); } |     uint64_t getMsCount() const { return m_sink.getMsCount(); } | ||||||
|     uint64_t getByteCount() const { return m_sink.getByteCount(); } |     uint64_t getByteCount() const { return m_sink.getByteCount(); } | ||||||
| @ -105,7 +103,7 @@ public: | |||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     SampleSinkFifo m_sampleFifo; |     SampleSinkFifo m_sampleFifo; | ||||||
|     DownChannelizer *m_channelizer; |     DownChannelizer m_channelizer; | ||||||
|     FileSinkSink m_sink; |     FileSinkSink m_sink; | ||||||
|     SpectrumVis *m_spectrumSink; |     SpectrumVis *m_spectrumSink; | ||||||
| 	MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
 | 	MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
 | ||||||
| @ -115,10 +113,10 @@ private: | |||||||
|     float m_squelchLevel; |     float m_squelchLevel; | ||||||
|     bool m_squelchOpen; |     bool m_squelchOpen; | ||||||
|     int64_t m_centerFrequency; |     int64_t m_centerFrequency; | ||||||
|     bool m_running; |  | ||||||
|     QMutex m_mutex; |     QMutex m_mutex; | ||||||
|     QTimer m_timer; |     QTimer *m_timer; | ||||||
| 
 | 
 | ||||||
|  |     void stopWork(); | ||||||
|     bool handleMessage(const Message& cmd); |     bool handleMessage(const Message& cmd); | ||||||
|     void applySettings(const FileSinkSettings& settings, bool force = false); |     void applySettings(const FileSinkSettings& settings, bool force = false); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user