| 
									
										
										
										
											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                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | #include <dsp/basebandsamplesink.h>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QMutex>
 | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "samplesinkfifo.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "util/messagequeue.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | class BasebandSampleSink; | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API ThreadedBasebandSampleSinkFifo : public QObject { | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-10-14 18:47:19 +02:00
										 |  |  | 	ThreadedBasebandSampleSinkFifo(BasebandSampleSink* sampleSink, std::size_t size = 1<<18); | 
					
						
							|  |  |  | 	~ThreadedBasebandSampleSinkFifo(); | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 	void writeToFifo(SampleVector::const_iterator& begin, SampleVector::const_iterator& end); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | 	BasebandSampleSink* m_sampleSink; | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 	SampleSinkFifo m_sampleFifo; | 
					
						
							| 
									
										
										
										
											2015-08-24 00:51:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API ThreadedBasebandSampleSink : public QObject { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-10-03 15:55:16 +02:00
										 |  |  | 	ThreadedBasebandSampleSink(BasebandSampleSink* sampleSink, QObject *parent = 0); | 
					
						
							|  |  |  | 	~ThreadedBasebandSampleSink(); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 01:49:28 +02:00
										 |  |  | 	const BasebandSampleSink *getSink() const { return m_basebandSampleSink; } | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2018-03-06 02:23:47 +01:00
										 |  |  |     const QThread *getThread() const { return m_thread; } | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							| 
									
										
										
										
											2016-10-14 18:47:19 +02:00
										 |  |  | 	ThreadedBasebandSampleSinkFifo *m_threadedBasebandSampleSinkFifo; | 
					
						
							| 
									
										
										
										
											2016-10-04 01:49:28 +02:00
										 |  |  | 	BasebandSampleSink* m_basebandSampleSink; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_THREADEDSAMPLESINK_H
 |