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.
rtpsession.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 
37 #ifndef RTPSESSION_H
38 
39 #define RTPSESSION_H
40 
41 #include "rtpconfig.h"
42 #include "rtppacketbuilder.h"
43 #include "rtpsessionsources.h"
44 #include "rtptransmitter.h"
45 #include "rtpcollisionlist.h"
46 #include "rtcpscheduler.h"
47 #include "rtcppacketbuilder.h"
48 #include "rtptimeutilities.h"
50 #include <list>
51 
52 #include "export.h"
53 
54 namespace qrtplib
55 {
56 
57 class RTPTransmitter;
58 class RTPSessionParams;
59 class RTPTransmissionParams;
60 class RTPAddress;
61 class RTPSourceData;
62 class RTPPacket;
63 class RTPPollThread;
64 class RTPTransmissionInfo;
65 class RTCPCompoundPacket;
66 class RTCPPacket;
67 class RTCPAPPPacket;
68 
77 {
78 public:
88  RTPSession(RTPRandom *rnd = 0);
89  virtual ~RTPSession();
90 
97  //int Create(const RTPSessionParams &sessparams, const RTPTransmissionParams *transparams = 0, RTPTransmitter::TransmissionProtocol proto = RTPTransmitter::IPv4UDPProto);
98 
106  int Create(const RTPSessionParams &sessparams, RTPTransmitter *transmitter);
107 
109  void Destroy();
110 
116  void BYEDestroy(const RTPTime &maxwaittime, const void *reason, std::size_t reasonlength);
117 
119  bool IsActive();
120 
122  uint32_t GetLocalSSRC();
123 
125  int AddDestination(const RTPAddress &addr);
126 
128  int DeleteDestination(const RTPAddress &addr);
129 
131  void ClearDestinations();
132 
134  bool SupportsMulticasting();
135 
137  int JoinMulticastGroup(const RTPAddress &addr);
138 
140  int LeaveMulticastGroup(const RTPAddress &addr);
141 
147  int SendPacket(const void *data, std::size_t len);
148 
153  int SendPacket(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc);
154 
161  int SendPacketEx(const void *data, std::size_t len, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords);
162 
169  int SendPacketEx(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords);
170 #ifdef RTP_SUPPORT_SENDAPP
171 
178  int SendRTCPAPPPacket(uint8_t subtype, const uint8_t name[4], const void *appdata, std::size_t appdatalen);
179 #endif // RTP_SUPPORT_SENDAPP
180 
184  int SendRawData(const void *data, std::size_t len, bool usertpchannel);
185 
187  int SetDefaultPayloadType(uint8_t pt);
188 
190  int SetDefaultMark(bool m);
191 
193  int SetDefaultTimestampIncrement(uint32_t timestampinc);
194 
201  int IncrementTimestamp(uint32_t inc);
202 
210  int IncrementTimestampDefault();
211 
218  int SetPreTransmissionDelay(const RTPTime &delay);
219 
227  RTPTransmissionInfo *GetTransmissionInfo();
228 
230  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
231 
235  RTPTime GetRTCPDelay();
236 
243  int BeginDataAccess();
244 
249  bool GotoFirstSource();
250 
255  bool GotoNextSource();
256 
261  bool GotoPreviousSource();
262 
269  bool GotoFirstSourceWithData();
270 
277  bool GotoNextSourceWithData();
278 
285  bool GotoPreviousSourceWithData();
286 
288  RTPSourceData *GetCurrentSourceInfo();
289 
293  RTPSourceData *GetSourceInfo(uint32_t ssrc);
294 
301  RTPPacket *GetNextPacket();
302 
304  uint16_t GetNextSequenceNumber() const;
305 
307  void DeletePacket(RTPPacket *p);
308 
310  int EndDataAccess();
311 
316  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
317 
319  int AddToIgnoreList(const RTPAddress &addr);
320 
322  int DeleteFromIgnoreList(const RTPAddress &addr);
323 
325  void ClearIgnoreList();
326 
328  int AddToAcceptList(const RTPAddress &addr);
329 
331  int DeleteFromAcceptList(const RTPAddress &addr);
332 
334  void ClearAcceptList();
335 
337  int SetMaximumPacketSize(std::size_t s);
338 
340  int SetSessionBandwidth(double bw);
341 
348  int SetTimestampUnit(double u);
349 
356  void SetNameInterval(int count);
357 
364  void SetEMailInterval(int count);
365 
372  void SetLocationInterval(int count);
373 
380  void SetPhoneInterval(int count);
381 
388  void SetToolInterval(int count);
389 
396  void SetNoteInterval(int count);
397 
399  int SetLocalName(const void *s, std::size_t len);
400 
402  int SetLocalEMail(const void *s, std::size_t len);
403 
405  int SetLocalLocation(const void *s, std::size_t len);
406 
408  int SetLocalPhone(const void *s, std::size_t len);
409 
411  int SetLocalTool(const void *s, std::size_t len);
412 
414  int SetLocalNote(const void *s, std::size_t len);
415 
416 protected:
424  virtual RTPTransmitter *NewUserDefinedTransmitter();
425 
432  virtual void OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress);
433 
435  virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress);
436 
442  virtual void OnSSRCCollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, bool isrtp);
443 
445  virtual void OnCNAMECollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, const uint8_t *cname, std::size_t cnamelength);
446 
448  virtual void OnNewSource(RTPSourceData *srcdat);
449 
451  virtual void OnRemoveSource(RTPSourceData *srcdat);
452 
454  virtual void OnTimeout(RTPSourceData *srcdat);
455 
457  virtual void OnBYETimeout(RTPSourceData *srcdat);
458 
462  virtual void OnAPPPacket(RTCPAPPPacket *apppacket, const RTPTime &receivetime, const RTPAddress *senderaddress);
463 
465  virtual void OnUnknownPacketType(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress);
466 
468  virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress);
469 
471  virtual void OnNoteTimeout(RTPSourceData *srcdat);
472 
474  virtual void OnRTCPSenderReport(RTPSourceData *srcdat);
475 
477  virtual void OnRTCPReceiverReport(RTPSourceData *srcdat);
478 
480  virtual void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, std::size_t itemlength);
481 #ifdef RTP_SUPPORT_SDESPRIV
482 
483  virtual void OnRTCPSDESPrivateItem(RTPSourceData *srcdat, const void *prefixdata, std::size_t prefixlen, const void *valuedata, std::size_t valuelen);
484 #endif // RTP_SUPPORT_SDESPRIV
485 
487  virtual void OnBYEPacket(RTPSourceData *srcdat);
488 
490  virtual void OnSendRTCPCompoundPacket(RTCPCompoundPacket *pack);
491 
494  void SetChangeOutgoingData(bool change)
495  {
496  m_changeOutgoingData = change;
497  }
498 
501  void SetChangeIncomingData(bool change)
502  {
503  m_changeIncomingData = change;
504  }
505 
515  virtual int OnChangeRTPOrRTCPData(const void *origdata, std::size_t origlen, bool isrtp, void **senddata, std::size_t *sendlen);
516 
520  virtual void OnSentRTPOrRTCPData(void *senddata, std::size_t sendlen, bool isrtp);
521 
528  virtual bool OnChangeIncomingData(RTPRawPacket *rawpack);
529 
540  virtual void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled);
541 private:
542  int InternalCreate(const RTPSessionParams &sessparams);
543  int CreateCNAME(uint8_t *buffer, std::size_t *bufferlength, bool resolve);
544  int ProcessPolledData();
545  int ProcessRTCPCompoundPacket(RTCPCompoundPacket &rtcpcomppack, RTPRawPacket *pack);
546  RTPRandom *GetRandomNumberGenerator(RTPRandom *r);
547  int SendRTPData(const void *data, std::size_t len);
548  int SendRTCPData(const void *data, std::size_t len);
549 
552 
554  bool created;
559  std::size_t maxpacksize;
568 
569  bool m_changeIncomingData, m_changeOutgoingData;
570 
576 
577  std::list<RTCPCompoundPacket *> byepackets;
578 
579  friend class RTPSessionSources;
580  friend class RTCPSessionPacketBuilder;
581 };
582 
584 {
585  return 0;
586 }
587 inline void RTPSession::OnRTPPacket(RTPPacket *, const RTPTime &, const RTPAddress *)
588 {
589 }
591 {
592 }
594 {
595 }
596 inline void RTPSession::OnCNAMECollision(RTPSourceData *, const RTPAddress *, const uint8_t *, std::size_t)
597 {
598 }
600 {
601 }
603 {
604 }
606 {
607 }
609 {
610 }
611 inline void RTPSession::OnAPPPacket(RTCPAPPPacket *, const RTPTime &, const RTPAddress *)
612 {
613 }
615 {
616 }
618 {
619 }
621 {
622 }
624 {
625 }
627 {
628 }
629 inline void RTPSession::OnRTCPSDESItem(RTPSourceData *, RTCPSDESPacket::ItemType, const void *, std::size_t)
630 {
631 }
632 
633 #ifdef RTP_SUPPORT_SDESPRIV
634 inline void RTPSession::OnRTCPSDESPrivateItem(RTPSourceData *, const void *, std::size_t, const void *, std::size_t)
635 {
636 }
637 #endif // RTP_SUPPORT_SDESPRIV
638 
640 {
641 }
643 {
644 }
645 
646 inline int RTPSession::OnChangeRTPOrRTCPData(const void *, std::size_t, bool, void **, std::size_t *)
647 {
649 }
650 inline void RTPSession::OnSentRTPOrRTCPData(void *, std::size_t, bool)
651 {
652 }
654 {
655  return true;
656 }
658 {
659 }
660 
661 } // end namespace
662 
663 #endif // RTPSESSION_H
664 
virtual void OnAPPPacket(RTCPAPPPacket *apppacket, const RTPTime &receivetime, const RTPAddress *senderaddress)
Definition: rtpsession.h:611
virtual void OnNewSource(RTPSourceData *srcdat)
Definition: rtpsession.h:599
virtual void OnRTCPSDESPrivateItem(RTPSourceData *srcdat, const void *prefixdata, std::size_t prefixlen, const void *valuedata, std::size_t valuelen)
Definition: rtpsession.h:634
RTPPacketBuilder packetbuilder
Definition: rtpsession.h:572
void SetChangeOutgoingData(bool change)
Definition: rtpsession.h:494
virtual void OnCNAMECollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, const uint8_t *cname, std::size_t cnamelength)
Definition: rtpsession.h:596
virtual void OnUnknownPacketType(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Definition: rtpsession.h:614
virtual void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, std::size_t itemlength)
Definition: rtpsession.h:629
RTCPPacketBuilder rtcpbuilder
Definition: rtpsession.h:574
RTPRandom * rtprnd
Definition: rtpsession.h:550
#define QRTPLIB_API
Definition: export.h:112
RTPSessionSources sources
Definition: rtpsession.h:571
virtual void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled)
Definition: rtpsession.h:657
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define ERR_RTP_RTPSESSION_CHANGEREQUESTEDBUTNOTIMPLEMENTED
Definition: rtperrors.h:214
virtual void OnNoteTimeout(RTPSourceData *srcdat)
Definition: rtpsession.h:620
virtual void OnRTCPSenderReport(RTPSourceData *srcdat)
Definition: rtpsession.h:623
RTPCollisionList collisionlist
Definition: rtpsession.h:575
unsigned char uint8_t
Definition: rtptypes_win.h:42
virtual void OnSentRTPOrRTCPData(void *senddata, std::size_t sendlen, bool isrtp)
Definition: rtpsession.h:650
unsigned short uint16_t
Definition: rtptypes_win.h:44
RTPTransmitter * rtptrans
Definition: rtpsession.h:553
virtual void OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Definition: rtpsession.h:587
std::size_t maxpacksize
Definition: rtpsession.h:559
virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Definition: rtpsession.h:617
virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Definition: rtpsession.h:590
RTCPScheduler rtcpsched
Definition: rtpsession.h:573
virtual bool OnChangeIncomingData(RTPRawPacket *rawpack)
Definition: rtpsession.h:653
std::list< RTCPCompoundPacket * > byepackets
Definition: rtpsession.h:577
virtual int OnChangeRTPOrRTCPData(const void *origdata, std::size_t origlen, bool isrtp, void **senddata, std::size_t *sendlen)
Definition: rtpsession.h:646
virtual void OnRemoveSource(RTPSourceData *srcdat)
Definition: rtpsession.h:602
virtual RTPTransmitter * NewUserDefinedTransmitter()
Definition: rtpsession.h:583
virtual void OnBYETimeout(RTPSourceData *srcdat)
Definition: rtpsession.h:608
double collisionmultiplier
Definition: rtpsession.h:565
virtual void OnSendRTCPCompoundPacket(RTCPCompoundPacket *pack)
Definition: rtpsession.h:642
void SetChangeIncomingData(bool change)
Definition: rtpsession.h:501
virtual void OnRTCPReceiverReport(RTPSourceData *srcdat)
Definition: rtpsession.h:626
virtual void OnBYEPacket(RTPSourceData *srcdat)
Definition: rtpsession.h:639
virtual void OnTimeout(RTPSourceData *srcdat)
Definition: rtpsession.h:605
virtual void OnSSRCCollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, bool isrtp)
Definition: rtpsession.h:593