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.
rtpudptransmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31  */
32 
33 #ifndef QRTPLIB_RTPUDPTRANSMITTER_H_
34 #define QRTPLIB_RTPUDPTRANSMITTER_H_
35 
36 #include "rtptransmitter.h"
37 #include "export.h"
38 
39 #include <QObject>
40 #include <QHostAddress>
41 #include <QNetworkInterface>
42 #include <QQueue>
43 #include <QMutex>
44 
45 #include <stdint.h>
46 #include <list>
47 
48 #define RTPUDPV4TRANS_HASHSIZE 8317
49 #define RTPUDPV4TRANS_DEFAULTPORTBASE 5000
50 #define RTPUDPV4TRANS_RTPRECEIVEBUFFER 32768
51 #define RTPUDPV4TRANS_RTCPRECEIVEBUFFER 32768
52 #define RTPUDPV4TRANS_RTPTRANSMITBUFFER 32768
53 #define RTPUDPV4TRANS_RTCPTRANSMITBUFFER 32768
54 
55 class QUdpSocket;
56 
57 namespace qrtplib
58 {
59 
62 {
63 public:
65 
67  void SetBindIP(const QHostAddress& bindAddress) {
68  m_bindAddress = bindAddress;
69  }
70 
72  void SetMulticastInterface(const QNetworkInterface& mcastInterface) {
73  m_mcastInterface = mcastInterface;
74  }
75 
79  void SetPortbase(uint16_t pbase)
80  {
81  m_portbase = pbase;
82  }
83 
85  QHostAddress GetBindIP() const
86  {
87  return m_bindAddress;
88  }
89 
91  QNetworkInterface GetMulticastInterface() const
92  {
93  return m_mcastInterface;
94  }
95 
98  {
99  return m_portbase;
100  }
101 
104  {
105  m_rtpsendbufsz = s;
106  }
107 
110  {
111  m_rtprecvbufsz = s;
112  }
113 
116  {
117  m_rtcpsendbufsz = s;
118  }
119 
122  {
123  m_rtcprecvbufsz = s;
124  }
125 
127  void SetRTCPMultiplexing(bool f)
128  {
129  m_rtcpmux = f;
130  }
131 
133  void SetAllowOddPortbase(bool f)
134  {
135  m_allowoddportbase = f;
136  }
137 
141  {
142  m_forcedrtcpport = rtcpport;
143  }
144 
148  void SetUseExistingSockets(QUdpSocket *rtpsocket, QUdpSocket *rtcpsocket)
149  {
150  m_rtpsock = rtpsocket;
151  m_rtcpsock = rtcpsocket;
152  m_useexistingsockets = true;
153  }
154 
157  {
158  return m_rtpsendbufsz;
159  }
160 
163  {
164  return m_rtprecvbufsz;
165  }
166 
169  {
170  return m_rtcpsendbufsz;
171  }
172 
175  {
176  return m_rtcprecvbufsz;
177  }
178 
180  bool GetRTCPMultiplexing() const
181  {
182  return m_rtcpmux;
183  }
184 
186  bool GetAllowOddPortbase() const
187  {
188  return m_allowoddportbase;
189  }
190 
193  {
194  return m_forcedrtcpport;
195  }
196 
199  bool GetUseExistingSockets(QUdpSocket **rtpsocket, QUdpSocket **rtcpsocket) const
200  {
201  if (!m_useexistingsockets) {
202  return false;
203  }
204 
205  *rtpsocket = m_rtpsock;
206  *rtcpsocket = m_rtcpsock;
207 
208  return true;
209  }
210 
211 private:
212  QHostAddress m_bindAddress;
213  QNetworkInterface m_mcastInterface;
215  int m_rtpsendbufsz, m_rtprecvbufsz;
216  int m_rtcpsendbufsz, m_rtcprecvbufsz;
217  bool m_rtcpmux;
220 
221  QUdpSocket *m_rtpsock, *m_rtcpsock;
223 };
224 
227 {
233  m_rtcpmux = false;
234  m_allowoddportbase = false;
235  m_forcedrtcpport = 0;
236  m_rtpsock = 0;
237  m_rtcpsock = 0;
238  m_useexistingsockets = false;
239 }
240 
243 {
244 public:
246  QHostAddress localIP,
247  QUdpSocket *rtpsock,
248  QUdpSocket *rtcpsock,
249  uint16_t rtpport,
250  uint16_t rtcpport) :
251  RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto)
252  {
253  m_localIP = localIP;
254  m_rtpsocket = rtpsock;
255  m_rtcpsocket = rtcpsock;
256  m_rtpPort = rtpport;
257  m_rtcpPort = rtcpport;
258  }
259 
261  {
262  }
263 
265  QUdpSocket *GetRTPSocket() const
266  {
267  return m_rtpsocket;
268  }
269 
271  QUdpSocket *GetRTCPSocket() const
272  {
273  return m_rtcpsocket;
274  }
275 
278  {
279  return m_rtpPort;
280  }
281 
284  {
285  return m_rtcpPort;
286  }
287 private:
288  QHostAddress m_localIP;
289  QUdpSocket *m_rtpsocket, *m_rtcpsocket;
290  uint16_t m_rtpPort, m_rtcpPort;
291 };
292 
293 #define RTPUDPTRANS_HEADERSIZE (20+8)
294 
301 class QRTPLIB_API RTPUDPTransmitter: public QObject, public RTPTransmitter
302 {
303  Q_OBJECT
304 public:
306  virtual ~RTPUDPTransmitter();
307 
308  virtual int Init();
309  virtual int Create(std::size_t maxpacksize, const RTPTransmissionParams *transparams);
310  virtual int BindSockets();
311  void moveToThread(QThread *thread);
312  virtual void Destroy();
313  virtual RTPTransmissionInfo *GetTransmissionInfo();
314  virtual void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
315 
316  virtual bool ComesFromThisTransmitter(const RTPAddress& addr);
317  virtual std::size_t GetHeaderOverhead()
318  {
319  return RTPUDPTRANS_HEADERSIZE;
320  }
321 
322  virtual int SendRTPData(const void *data, std::size_t len);
323  virtual int SendRTCPData(const void *data, std::size_t len);
324 
325  virtual int AddDestination(const RTPAddress &addr);
326  virtual int DeleteDestination(const RTPAddress &addr);
327  virtual void ClearDestinations();
328 
329  virtual bool SupportsMulticasting();
330  virtual int JoinMulticastGroup(const RTPAddress &addr);
331  virtual int LeaveMulticastGroup(const RTPAddress &addr);
332 
333  virtual int SetReceiveMode(RTPTransmitter::ReceiveMode m);
334  virtual int AddToIgnoreList(const RTPAddress &addr);
335  virtual int DeleteFromIgnoreList(const RTPAddress &addr);
336  virtual void ClearIgnoreList();
337  virtual int AddToAcceptList(const RTPAddress &addr);
338  virtual int DeleteFromAcceptList(const RTPAddress &addr);
339  virtual void ClearAcceptList();
340  virtual int SetMaximumPacketSize(std::size_t s);
341 
342  virtual RTPRawPacket *GetNextPacket();
343 
344 
345 private:
346  bool m_init;
347  bool m_created;
349  QUdpSocket *m_rtpsock, *m_rtcpsock;
351  QHostAddress m_localIP;
352  QNetworkInterface m_multicastInterface;
353  uint16_t m_rtpPort, m_rtcpPort;
355 
356  std::size_t m_maxpacksize;
357  static const std::size_t m_absoluteMaxPackSize = 65535;
358  char m_rtpBuffer[m_absoluteMaxPackSize];
359  char m_rtcpBuffer[m_absoluteMaxPackSize];
360 
361  std::list<RTPAddress> m_destinations;
362  std::list<RTPAddress> m_acceptList;
363  std::list<RTPAddress> m_ignoreList;
364  QQueue<RTPRawPacket*> m_rawPacketQueue;
366 
367  bool ShouldAcceptData(const RTPAddress& address);
368 
369 private slots:
370  void readRTPPendingDatagrams();
371  void readRTCPPendingDatagrams();
372 
373 signals:
374  void NewDataAvailable();
375 };
376 
377 
378 } // namespace
379 
380 #endif /* QRTPLIB_RTPUDPTRANSMITTER_H_ */
virtual std::size_t GetHeaderOverhead()
std::list< RTPAddress > m_destinations
std::list< RTPAddress > m_ignoreList
QQueue< RTPRawPacket * > m_rawPacketQueue
bool GetUseExistingSockets(QUdpSocket **rtpsocket, QUdpSocket **rtcpsocket) const
#define RTPUDPV4TRANS_RTCPTRANSMITBUFFER
RTPTransmitter::ReceiveMode m_receivemode
#define RTPUDPV4TRANS_DEFAULTPORTBASE
QNetworkInterface m_multicastInterface
from parameters multicast interface
#define QRTPLIB_API
Definition: export.h:112
#define RTPUDPV4TRANS_RTCPRECEIVEBUFFER
#define RTPUDPV4TRANS_RTPRECEIVEBUFFER
QUdpSocket * GetRTCPSocket() const
QHostAddress m_localIP
from parameters bind IP
unsigned short uint16_t
Definition: rtptypes_win.h:44
void SetBindIP(const QHostAddress &bindAddress)
QNetworkInterface GetMulticastInterface() const
std::list< RTPAddress > m_acceptList
void SetMulticastInterface(const QNetworkInterface &mcastInterface)
#define RTPUDPTRANS_HEADERSIZE
RTPUDPTransmissionInfo(QHostAddress localIP, QUdpSocket *rtpsock, QUdpSocket *rtcpsock, uint16_t rtpport, uint16_t rtcpport)
void SetUseExistingSockets(QUdpSocket *rtpsocket, QUdpSocket *rtcpsocket)
#define RTPUDPV4TRANS_RTPTRANSMITBUFFER
void SetForcedRTCPPort(uint16_t rtcpport)