SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
udpsourceudphandler.h
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef PLUGINS_CHANNELTX_UDPSINK_UDPSOURCEUDPHANDLER_H_
19 #define PLUGINS_CHANNELTX_UDPSINK_UDPSOURCEUDPHANDLER_H_
20 
21 #include <QObject>
22 #include <QUdpSocket>
23 #include <QHostAddress>
24 #include <QMutex>
25 #include <stdint.h>
26 
27 #include "dsp/dsptypes.h"
28 #include "util/message.h"
29 #include "util/messagequeue.h"
30 
31 class UDPSourceUDPHandler : public QObject
32 {
33  Q_OBJECT
34 public:
36  virtual ~UDPSourceUDPHandler();
37 
38  void start();
39  void stop();
40  void configureUDPLink(const QString& address, quint16 port);
41  void resetReadIndex();
42  void resizeBuffer(float sampleRate);
43 
44  void readSample(qint16 &t);
45  void readSample(AudioSample &a);
46  void readSample(Sample &s);
47 
48  void setAutoRWBalance(bool autoRWBalance) { m_autoRWBalance = autoRWBalance; }
49  void setFeedbackMessageQueue(MessageQueue *messageQueue) { m_feedbackMessageQueue = messageQueue; }
50 
55  inline int32_t getBufferGauge() const
56  {
57  int32_t val = m_rwDelta - (m_nbUDPFrames/2);
58  return (100*val) / m_nbUDPFrames;
59  }
60 
61  static const int m_udpBlockSize = 512; // UDP block size in number of bytes
62  static const int m_minNbUDPFrames = 256; // number of frames of block size in the UDP buffer
63 
64 public slots:
65  void dataReadyRead();
66 
67 private:
68  class MsgUDPAddressAndPort : public Message {
70 
71  public:
72  const QString& getAddress() const { return m_address; }
73  quint16 getPort() const { return m_port; }
74 
75  static MsgUDPAddressAndPort* create(QString address, quint16 port)
76  {
77  return new MsgUDPAddressAndPort(address, port);
78  }
79 
80  private:
81  QString m_address;
82  quint16 m_port;
83 
84  MsgUDPAddressAndPort(QString address, quint16 port) :
85  Message(),
86  m_address(address),
87  m_port(port)
88  { }
89  };
90 
91  typedef char (udpBlk_t)[m_udpBlockSize];
92 
93  void moveData(char *blk);
94  void advanceReadPointer(int nbBytes);
95  void applyUDPLink(const QString& address, quint16 port);
96  bool handleMessage(const Message& message);
97 
98  QUdpSocket *m_dataSocket;
99  QHostAddress m_dataAddress;
100  QHostAddress m_remoteAddress;
101  quint16 m_dataPort;
102  quint16 m_remotePort;
104  udpBlk_t *m_udpBuf;
105  char m_udpDump[m_udpBlockSize + 8192]; // UDP block size + largest possible block
113  float m_d;
117 
118 private slots:
119  void handleMessages();
120 };
121 
122 
123 
124 #endif /* PLUGINS_CHANNELTX_UDPSINK_UDPSOURCEUDPHANDLER_H_ */
void applyUDPLink(const QString &address, quint16 port)
static MsgUDPAddressAndPort * create(QString address, quint16 port)
int32_t getBufferGauge() const
void setAutoRWBalance(bool autoRWBalance)
void advanceReadPointer(int nbBytes)
void readSample(qint16 &t)
audio mono
void configureUDPLink(const QString &address, quint16 port)
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
MsgUDPAddressAndPort(QString address, quint16 port)
static const int m_minNbUDPFrames
int int32_t
Definition: rtptypes_win.h:45
char m_udpDump[m_udpBlockSize+8192]
MessageQueue m_inputMessageQueue
typedef char(udpBlk_t)[m_udpBlockSize]
void resizeBuffer(float sampleRate)
static const int m_udpBlockSize
MessageQueue * m_feedbackMessageQueue
bool handleMessage(const Message &message)
void setFeedbackMessageQueue(MessageQueue *messageQueue)