| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #ifndef INCLUDE_THREADEDSAMPLESINK_H
 | 
					
						
							|  |  |  | #define INCLUDE_THREADEDSAMPLESINK_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include "samplesink.h"
 | 
					
						
							|  |  |  | #include "dsp/samplefifo.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							|  |  |  | #include "util/export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SampleSink; | 
					
						
							| 
									
										
										
										
											2015-08-21 08:54:28 +02:00
										 |  |  | class QThread; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Because Qt is a piece of shit this class cannot be a nested protected class of ThreadedSampleSink | 
					
						
							|  |  |  |  * So let's make everything public | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ThreadedSampleFifo : public QObject { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	ThreadedSampleFifo(SampleSink* sampleSink, std::size_t size = 1<<18); | 
					
						
							|  |  |  | 	~ThreadedSampleFifo(); | 
					
						
							|  |  |  | 	void writeToFifo(SampleVector::const_iterator& begin, SampleVector::const_iterator& end); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SampleSink* m_sampleSink; | 
					
						
							|  |  |  | 	SampleFifo m_sampleFifo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public slots: | 
					
						
							|  |  |  | 	void handleFifoData(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This class is a wrapper for SampleSink that runs the SampleSink object in its own thread | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-08-30 01:26:51 +02:00
										 |  |  | class SDRANGEL_API ThreadedSampleSink : public QObject { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2015-08-21 08:54:28 +02:00
										 |  |  | 	ThreadedSampleSink(SampleSink* sampleSink, QObject *parent = 0); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	~ThreadedSampleSink(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const SampleSink *getSink() const { return m_sampleSink; } | 
					
						
							|  |  |  | 	MessageQueue* getInputMessageQueue() { return m_sampleSink->getInputMessageQueue(); } //!< Return pointer to sample sink's input message queue
 | 
					
						
							|  |  |  | 	MessageQueue* getOutputMessageQueue() { return m_sampleSink->getOutputMessageQueue(); } //!< Return pointer to sample sink's output message queue
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void start(); //!< this thread start()
 | 
					
						
							|  |  |  | 	void stop();  //!< this thread exit() and wait()
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 01:56:38 +01:00
										 |  |  | 	bool handleSinkMessage(const Message& cmd); //!< Send message to sink synchronously
 | 
					
						
							| 
									
										
										
										
											2015-08-20 03:38:31 +02:00
										 |  |  | 	void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); //!< Feed sink with samples
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	QString getSampleSinkObjectName() const; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-21 08:54:28 +02:00
										 |  |  | 	QThread *m_thread; //!< The thead object
 | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	ThreadedSampleFifo *m_threadedSampleFifo; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	SampleSink* m_sampleSink; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_THREADEDSAMPLESINK_H
 |