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