| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2016 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 06:57:41 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | #ifndef PLUGINS_SAMPLESOURCE_REMOTEINPUT_REMOTEINPUTUDPHANDLER_H_
 | 
					
						
							|  |  |  | #define PLUGINS_SAMPLESOURCE_REMOTEINPUT_REMOTEINPUTUDPHANDLER_H_
 | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QObject>
 | 
					
						
							|  |  |  | #include <QUdpSocket>
 | 
					
						
							|  |  |  | #include <QHostAddress>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QElapsedTimer>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  | #include "util/messagequeue.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | #include "remoteinputbuffer.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | #define REMOTEINPUT_THROTTLE_MS 50
 | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | class SampleSinkFifo; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | class MessageQueue; | 
					
						
							|  |  |  | class QTimer; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | class RemoteInputUDPHandler : public QObject | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-06-28 06:56:21 +02:00
										 |  |  | 	class MsgReportSampleRateChange : public Message { | 
					
						
							|  |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		int getSampleRate() const { return m_sampleRate; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		static MsgReportSampleRateChange* create(int sampleRate) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return new MsgReportSampleRateChange(sampleRate); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	protected: | 
					
						
							|  |  |  | 		int m_sampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MsgReportSampleRateChange(int sampleRate) : | 
					
						
							|  |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_sampleRate(sampleRate) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	RemoteInputUDPHandler(SampleSinkFifo* sampleFifo, DeviceAPI *deviceAPI); | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | 	~RemoteInputUDPHandler(); | 
					
						
							| 
									
										
										
										
											2020-06-28 06:56:21 +02:00
										 |  |  | 	void setMessageQueueToInput(MessageQueue *queue) { m_messageQueueToInput = queue; } | 
					
						
							|  |  |  | 	void setMessageQueueToGUI(MessageQueue *queue) { m_messageQueueToGUI = queue; } | 
					
						
							|  |  |  |     void start(); | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	void stop(); | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  | 	void configureUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin); | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	void getRemoteAddress(QString& s) const { s = m_remoteAddress.toString(); } | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  |     int getNbOriginalBlocks() const { return RemoteNbOrginalBlocks; } | 
					
						
							| 
									
										
										
										
											2017-12-26 02:18:30 +01:00
										 |  |  |     bool isStreaming() const { return m_masterTimerConnected; } | 
					
						
							|  |  |  |     int getSampleRate() const { return m_samplerate; } | 
					
						
							| 
									
										
										
										
											2019-04-26 03:07:50 +02:00
										 |  |  |     int getCenterFrequency() const { return m_centerFrequency; } | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  |     int getBufferGauge() const { return m_remoteInputBuffer.getBufferGauge(); } | 
					
						
							| 
									
										
										
										
											2018-11-13 13:45:55 +01:00
										 |  |  |     uint64_t getTVmSec() const { return m_tv_msec; } | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  |     int getMinNbBlocks() { return m_remoteInputBuffer.getMinNbBlocks(); } | 
					
						
							|  |  |  |     int getMaxNbRecovery() { return m_remoteInputBuffer.getMaxNbRecovery(); } | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | public slots: | 
					
						
							|  |  |  | 	void dataReadyRead(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  |     class MsgUDPAddressAndPort : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const QString& getAddress() const { return m_address; } | 
					
						
							|  |  |  |         quint16 getPort() const { return m_port; } | 
					
						
							|  |  |  |         const QString& getMulticastAddress() const { return m_multicastAddress; } | 
					
						
							|  |  |  |         bool getMulticastJoin() const { return m_multicastJoin; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgUDPAddressAndPort* create(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgUDPAddressAndPort(address, port, multicastAddress, multicastJoin); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         QString m_address; | 
					
						
							|  |  |  |         quint16 m_port; | 
					
						
							|  |  |  |         QString m_multicastAddress; | 
					
						
							|  |  |  |         bool m_multicastJoin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgUDPAddressAndPort(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_address(address), | 
					
						
							|  |  |  |             m_port(port), | 
					
						
							|  |  |  |             m_multicastAddress(multicastAddress), | 
					
						
							|  |  |  |             m_multicastJoin(multicastJoin) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2017-12-26 02:18:30 +01:00
										 |  |  | 	const QTimer& m_masterTimer; | 
					
						
							|  |  |  | 	bool m_masterTimerConnected; | 
					
						
							|  |  |  | 	bool m_running; | 
					
						
							| 
									
										
										
										
											2018-02-24 10:29:27 +01:00
										 |  |  |     uint32_t m_rateDivider; | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | 	RemoteInputBuffer m_remoteInputBuffer; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	QUdpSocket *m_dataSocket; | 
					
						
							|  |  |  | 	QHostAddress m_dataAddress; | 
					
						
							|  |  |  | 	QHostAddress m_remoteAddress; | 
					
						
							|  |  |  | 	quint16 m_dataPort; | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  | 	QHostAddress m_multicastAddress; | 
					
						
							|  |  |  | 	bool m_multicast; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	bool m_dataConnected; | 
					
						
							|  |  |  | 	char *m_udpBuf; | 
					
						
							|  |  |  | 	qint64 m_udpReadBytes; | 
					
						
							| 
									
										
										
										
											2016-10-06 19:18:02 +02:00
										 |  |  | 	SampleSinkFifo *m_sampleFifo; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	uint32_t m_samplerate; | 
					
						
							| 
									
										
										
										
											2019-04-26 03:07:50 +02:00
										 |  |  | 	uint64_t m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2018-11-13 13:45:55 +01:00
										 |  |  | 	uint64_t m_tv_msec; | 
					
						
							| 
									
										
										
										
											2020-06-28 06:56:21 +02:00
										 |  |  |     MessageQueue *m_messageQueueToInput; | 
					
						
							|  |  |  | 	MessageQueue *m_messageQueueToGUI; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	uint32_t m_tickCount; | 
					
						
							|  |  |  | 	std::size_t m_samplesCount; | 
					
						
							|  |  |  |     QTimer *m_timer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QElapsedTimer m_elapsedTimer; | 
					
						
							|  |  |  | 	int m_throttlems; | 
					
						
							| 
									
										
										
										
											2019-04-30 08:43:55 +02:00
										 |  |  |     int32_t m_readLengthSamples; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  |     uint32_t m_readLength; | 
					
						
							| 
									
										
										
										
											2018-01-24 08:49:18 +01:00
										 |  |  |     int32_t *m_converterBuffer; | 
					
						
							|  |  |  |     uint32_t m_converterBufferNbSamples; | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  |     bool m_throttleToggle; | 
					
						
							|  |  |  |     bool m_autoCorrBuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  |     MessageQueue m_inputMessageQueue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 02:18:30 +01:00
										 |  |  | 	void connectTimer(); | 
					
						
							|  |  |  |     void disconnectTimer(); | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 	void processData(); | 
					
						
							| 
									
										
										
										
											2020-06-28 08:17:39 +02:00
										 |  |  |     void adjustNbDecoderSlots(const RemoteMetaDataFEC& metaData); | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  | 	void applyUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool muticastJoin); | 
					
						
							|  |  |  | 	bool handleMessage(const Message& message); | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  | 	void tick(); | 
					
						
							| 
									
										
										
										
											2020-08-26 18:52:36 +02:00
										 |  |  |     void handleMessages(); | 
					
						
							| 
									
										
										
										
											2016-06-19 09:56:49 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:26:26 +01:00
										 |  |  | #endif /* PLUGINS_SAMPLESOURCE_REMOTEINPUT_REMOTEINPUTUDPHANDLER_H_ */
 |