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.
rtpsourcedata.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 RTPSOURCEDATA_H
38 
39 #define RTPSOURCEDATA_H
40 
41 #include "rtpconfig.h"
42 #include "rtptimeutilities.h"
43 #include "rtppacket.h"
44 #include "rtcpsdesinfo.h"
45 #include "rtptypes.h"
46 #include "rtpsources.h"
47 #include <list>
48 
49 #include "export.h"
50 
51 namespace qrtplib
52 {
53 
54 class RTPAddress;
55 
57 {
58 public:
60  ntptimestamp(0, 0), receivetime(0, 0)
61  {
62  hasinfo = false;
63  rtptimestamp = 0;
64  packetcount = 0;
65  bytecount = 0;
66  }
67  void Set(const RTPNTPTime &ntptime, uint32_t rtptime, uint32_t pcount, uint32_t bcount, const RTPTime &rcvtime)
68  {
69  ntptimestamp = ntptime;
70  rtptimestamp = rtptime;
71  packetcount = pcount;
72  bytecount = bcount;
73  receivetime = rcvtime;
74  hasinfo = true;
75  }
76 
77  bool HasInfo() const
78  {
79  return hasinfo;
80  }
82  {
83  return ntptimestamp;
84  }
86  {
87  return rtptimestamp;
88  }
90  {
91  return packetcount;
92  }
94  {
95  return bytecount;
96  }
98  {
99  return receivetime;
100  }
101 private:
102  bool hasinfo;
108 };
109 
111 {
112 public:
114  receivetime(0, 0)
115  {
116  hasinfo = false;
117  fractionlost = 0;
118  packetslost = 0;
119  exthighseqnr = 0;
120  jitter = 0;
121  lsr = 0;
122  dlsr = 0;
123  }
124  void Set(uint8_t fraclost, int32_t plost, uint32_t exthigh, uint32_t jit, uint32_t l, uint32_t dl, const RTPTime &rcvtime)
125  {
126  fractionlost = ((double) fraclost) / 256.0;
127  packetslost = plost;
128  exthighseqnr = exthigh;
129  jitter = jit;
130  lsr = l;
131  dlsr = dl;
132  receivetime = rcvtime;
133  hasinfo = true;
134  }
135 
136  bool HasInfo() const
137  {
138  return hasinfo;
139  }
140  double GetFractionLost() const
141  {
142  return fractionlost;
143  }
145  {
146  return packetslost;
147  }
149  {
150  return exthighseqnr;
151  }
153  {
154  return jitter;
155  }
157  {
158  return lsr;
159  }
161  {
162  return dlsr;
163  }
165  {
166  return receivetime;
167  }
168 private:
169  bool hasinfo;
170  double fractionlost;
177 };
178 
180 {
181 public:
182  RTPSourceStats();
183  void ProcessPacket(
184  RTPPacket *pack,
185  const RTPTime &receivetime,
186  double tsunit,
187  bool ownpacket,
188  bool *accept);
189 
190  bool HasSentData() const
191  {
192  return sentdata;
193  }
195  {
196  return packetsreceived;
197  }
199  {
200  return baseseqnr;
201  }
203  {
204  return exthighseqnr;
205  }
207  {
208  return jitter;
209  }
210 
212  {
213  return numnewpackets;
214  }
216  {
217  return savedextseqnr;
218  }
220  {
221  numnewpackets = 0;
222  savedextseqnr = exthighseqnr;
223  }
224 
226  {
227  lastmsgtime = t;
228  }
230  {
231  return lastmsgtime;
232  }
234  {
235  lastrtptime = t;
236  }
238  {
239  return lastrtptime;
240  }
241 
242  void SetLastNoteTime(const RTPTime &t)
243  {
244  lastnotetime = t;
245  }
247  {
248  return lastnotetime;
249  }
250 private:
251  bool sentdata;
253  uint32_t numcycles; // shifted left 16 bits
255  uint32_t exthighseqnr, prevexthighseqnr;
257  double djitter;
264 };
265 
267  prevpacktime(0, 0), lastmsgtime(0, 0), lastrtptime(0, 0), lastnotetime(0, 0)
268 {
269  sentdata = false;
270  packetsreceived = 0;
271  baseseqnr = 0;
272  exthighseqnr = 0;
273  prevexthighseqnr = 0;
274  jitter = 0;
275  numcycles = 0;
276  numnewpackets = 0;
277  prevtimestamp = 0;
278  djitter = 0;
279  savedextseqnr = 0;
280 }
281 
284 {
285 protected:
286  RTPSourceData(uint32_t ssrc);
287  virtual ~RTPSourceData();
288 public:
290  RTPPacket *GetNextPacket();
291 
293  void FlushPackets();
294 
296  bool HasData() const
297  {
298  if (!validated)
299  return false;
300  return packetlist.empty() ? false : true;
301  }
302 
305  {
306  return ssrc;
307  }
308 
312  bool IsOwnSSRC() const
313  {
314  return ownssrc;
315  }
316 
318  bool IsCSRC() const
319  {
320  return iscsrc;
321  }
322 
324  bool IsSender() const
325  {
326  return issender;
327  }
328 
333  bool IsValidated() const
334  {
335  return validated;
336  }
337 
339  bool IsActive() const
340  {
341  if (!validated)
342  return false;
343  if (receivedbye)
344  return false;
345  return true;
346  }
347 
351  void SetProcessedInRTCP(bool v)
352  {
353  processedinrtcp = v;
354  }
355 
359  bool IsProcessedInRTCP() const
360  {
361  return processedinrtcp;
362  }
363 
367  bool IsRTPAddressSet() const
368  {
369  return isrtpaddrset;
370  }
371 
375  bool IsRTCPAddressSet() const
376  {
377  return isrtcpaddrset;
378  }
379 
386  {
387  return rtpaddr;
388  }
389 
396  {
397  return rtcpaddr;
398  }
399 
401  bool ReceivedBYE() const
402  {
403  return receivedbye;
404  }
405 
410  uint8_t *GetBYEReason(std::size_t *len) const
411  {
412  *len = byereasonlen;
413  return byereason;
414  }
415 
418  {
419  return byetime;
420  }
421 
428  void SetTimestampUnit(double tsu)
429  {
430  timestampunit = tsu;
431  }
432 
434  double GetTimestampUnit() const
435  {
436  return timestampunit;
437  }
438 
440  bool SR_HasInfo() const
441  {
442  return SRinf.HasInfo();
443  }
444 
447  {
448  return SRinf.GetNTPTimestamp();
449  }
450 
453  {
454  return SRinf.GetRTPTimestamp();
455  }
456 
459  {
460  return SRinf.GetPacketCount();
461  }
462 
465  {
466  return SRinf.GetByteCount();
467  }
468 
471  {
472  return SRinf.GetReceiveTime();
473  }
474 
476  bool SR_Prev_HasInfo() const
477  {
478  return SRprevinf.HasInfo();
479  }
480 
483  {
484  return SRprevinf.GetNTPTimestamp();
485  }
486 
489  {
490  return SRprevinf.GetRTPTimestamp();
491  }
492 
495  {
496  return SRprevinf.GetPacketCount();
497  }
498 
501  {
502  return SRprevinf.GetByteCount();
503  }
504 
507  {
508  return SRprevinf.GetReceiveTime();
509  }
510 
512  bool RR_HasInfo() const
513  {
514  return RRinf.HasInfo();
515  }
516 
518  double RR_GetFractionLost() const
519  {
520  return RRinf.GetFractionLost();
521  }
522 
525  {
526  return RRinf.GetPacketsLost();
527  }
528 
531  {
532  return RRinf.GetExtendedHighestSequenceNumber();
533  }
534 
537  {
538  return RRinf.GetJitter();
539  }
540 
543  {
544  return RRinf.GetLastSRTimestamp();
545  }
546 
549  {
550  return RRinf.GetDelaySinceLastSR();
551  }
552 
555  {
556  return RRinf.GetReceiveTime();
557  }
558 
562  bool RR_Prev_HasInfo() const
563  {
564  return RRprevinf.HasInfo();
565  }
566 
568  double RR_Prev_GetFractionLost() const
569  {
570  return RRprevinf.GetFractionLost();
571  }
572 
575  {
576  return RRprevinf.GetPacketsLost();
577  }
578 
581  {
582  return RRprevinf.GetExtendedHighestSequenceNumber();
583  }
584 
587  {
588  return RRprevinf.GetJitter();
589  }
590 
593  {
594  return RRprevinf.GetLastSRTimestamp();
595  }
596 
599  {
600  return RRprevinf.GetDelaySinceLastSR();
601  }
602 
605  {
606  return RRprevinf.GetReceiveTime();
607  }
608 
610  bool INF_HasSentData() const
611  {
612  return stats.HasSentData();
613  }
614 
617  {
618  return stats.GetNumPacketsReceived();
619  }
620 
623  {
624  return stats.GetBaseSequenceNumber();
625  }
626 
629  {
630  return stats.GetExtendedHighestSequenceNumber();
631  }
632 
635  {
636  return stats.GetJitter();
637  }
638 
641  {
642  return stats.GetLastMessageTime();
643  }
644 
647  {
648  return stats.GetLastRTPPacketTime();
649  }
650 
652  double INF_GetEstimatedTimestampUnit() const;
653 
656  {
657  return stats.GetNumPacketsReceivedInInterval();
658  }
659 
662  {
663  return stats.GetSavedExtendedSequenceNumber();
664  }
665 
670  {
671  stats.StartNewInterval();
672  }
673 
675  RTPTime INF_GetRoundtripTime() const;
676 
679  {
680  return stats.GetLastNoteTime();
681  }
682 
684  uint8_t *SDES_GetCNAME(std::size_t *len) const
685  {
686  return SDESinf.GetCNAME(len);
687  }
688 
690  uint8_t *SDES_GetName(std::size_t *len) const
691  {
692  return SDESinf.GetName(len);
693  }
694 
696  uint8_t *SDES_GetEMail(std::size_t *len) const
697  {
698  return SDESinf.GetEMail(len);
699  }
700 
702  uint8_t *SDES_GetPhone(std::size_t *len) const
703  {
704  return SDESinf.GetPhone(len);
705  }
706 
708  uint8_t *SDES_GetLocation(std::size_t *len) const
709  {
710  return SDESinf.GetLocation(len);
711  }
712 
714  uint8_t *SDES_GetTool(std::size_t *len) const
715  {
716  return SDESinf.GetTool(len);
717  }
718 
720  uint8_t *SDES_GetNote(std::size_t *len) const
721  {
722  return SDESinf.GetNote(len);
723  }
724 
725 #ifdef RTP_SUPPORT_SDESPRIV
726 
728  {
729  SDESinf.GotoFirstPrivateValue();
730  }
731 
735  bool SDES_GetNextPrivateValue(uint8_t **prefix, std::size_t *prefixlen, uint8_t **value, std::size_t *valuelen)
736  {
737  return SDESinf.GetNextPrivateValue(prefix, prefixlen, value, valuelen);
738  }
739 
744  bool SDES_GetPrivateValue(uint8_t *prefix, std::size_t prefixlen, uint8_t **value, std::size_t *valuelen) const
745  {
746  return SDESinf.GetPrivateValue(prefix, prefixlen, value, valuelen);
747  }
748 #endif // RTP_SUPPORT_SDESPRIV
749 
750 protected:
751  std::list<RTPPacket *> packetlist;
752 
754  bool ownssrc;
755  bool iscsrc;
758  bool validated;
760  bool issender;
761 
766 
767  bool isrtpaddrset, isrtcpaddrset;
768  RTPAddress *rtpaddr, *rtcpaddr;
769 
772  std::size_t byereasonlen;
773 };
774 
776 {
777  if (!validated)
778  return 0;
779 
780  RTPPacket *p;
781 
782  if (packetlist.empty())
783  return 0;
784  p = *(packetlist.begin());
785  packetlist.pop_front();
786  return p;
787 }
788 
790 {
791  std::list<RTPPacket *>::const_iterator it;
792 
793  for (it = packetlist.begin(); it != packetlist.end(); ++it)
794  delete *it;
795  packetlist.clear();
796 }
797 
798 } // end namespace
799 
800 #endif // RTPSOURCEDATA_H
801 
RTPTime GetLastMessageTime() const
bool ReceivedBYE() const
bool RR_Prev_HasInfo() const
uint32_t INF_GetExtendedHighestSequenceNumber() const
int32_t RR_Prev_GetPacketsLost() const
uint32_t SR_GetPacketCount() const
uint8_t * SDES_GetPhone(std::size_t *len) const
double RR_GetFractionLost() const
RTPTime INF_GetLastMessageTime() const
RTPTime SR_Prev_GetReceiveTime() const
uint32_t GetDelaySinceLastSR() const
uint32_t GetSavedExtendedSequenceNumber() const
uint32_t GetLastSRTimestamp() const
int32_t RR_GetPacketsLost() const
RTPTime SR_GetReceiveTime() const
uint32_t SR_GetRTPTimestamp() const
bool IsRTCPAddressSet() const
uint32_t GetRTPTimestamp() const
Definition: rtpsourcedata.h:85
RTPTime INF_GetLastSDESNoteTime() const
uint8_t * GetBYEReason(std::size_t *len) const
uint32_t SR_Prev_GetRTPTimestamp() const
int32_t INF_GetNumPacketsReceived() const
uint32_t GetExtendedHighestSequenceNumber() const
uint8_t * SDES_GetName(std::size_t *len) const
const RTPAddress * GetRTPDataAddress() const
bool SDES_GetNextPrivateValue(uint8_t **prefix, std::size_t *prefixlen, uint8_t **value, std::size_t *valuelen)
uint32_t RR_GetLastSRTimestamp() const
RTPTime GetBYETime() const
void SetLastRTPPacketTime(const RTPTime &t)
#define QRTPLIB_API
Definition: export.h:112
uint32_t INF_GetSavedExtendedSequenceNumber() const
uint32_t GetNumPacketsReceived() const
uint32_t SR_Prev_GetPacketCount() const
uint32_t GetBaseSequenceNumber() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
const RTPAddress * GetRTCPDataAddress() const
uint32_t SR_GetByteCount() const
RTPTime RR_Prev_GetReceiveTime() const
RTPNTPTime SR_GetNTPTimestamp() const
uint32_t INF_GetBaseSequenceNumber() const
RTPPacket * GetNextPacket()
uint32_t RR_Prev_GetExtendedHighestSequenceNumber() const
void SetLastNoteTime(const RTPTime &t)
unsigned char uint8_t
Definition: rtptypes_win.h:42
uint32_t GetByteCount() const
Definition: rtpsourcedata.h:93
uint32_t RR_Prev_GetJitter() const
bool IsProcessedInRTCP() const
uint32_t RR_GetExtendedHighestSequenceNumber() const
RTCPSenderReportInfo SRprevinf
void SetTimestampUnit(double tsu)
bool SR_Prev_HasInfo() const
uint32_t GetExtendedHighestSequenceNumber() const
uint32_t SR_Prev_GetByteCount() const
RTPTime GetLastRTPPacketTime() const
uint32_t GetSSRC() const
uint8_t * SDES_GetLocation(std::size_t *len) const
int int32_t
Definition: rtptypes_win.h:45
double GetTimestampUnit() const
RTPTime RR_GetReceiveTime() const
uint8_t * SDES_GetTool(std::size_t *len) const
uint32_t RR_GetJitter() const
void Set(uint8_t fraclost, int32_t plost, uint32_t exthigh, uint32_t jit, uint32_t l, uint32_t dl, const RTPTime &rcvtime)
bool IsRTPAddressSet() const
int32_t GetNumPacketsReceivedInInterval() const
uint32_t RR_Prev_GetDelaySinceLastSR() const
uint8_t * SDES_GetEMail(std::size_t *len) const
uint32_t INF_GetNumPacketsReceivedInInterval() const
RTPSourceStats stats
uint8_t * SDES_GetCNAME(std::size_t *len) const
RTPTime GetReceiveTime() const
Definition: rtpsourcedata.h:97
RTCPReceiverReportInfo RRprevinf
uint32_t GetJitter() const
void SetLastMessageTime(const RTPTime &t)
bool SDES_GetPrivateValue(uint8_t *prefix, std::size_t prefixlen, uint8_t **value, std::size_t *valuelen) const
uint32_t RR_Prev_GetLastSRTimestamp() const
uint32_t GetPacketCount() const
Definition: rtpsourcedata.h:89
std::list< RTPPacket * > packetlist
bool IsValidated() const
uint32_t INF_GetJitter() const
RTPNTPTime GetNTPTimestamp() const
Definition: rtpsourcedata.h:81
uint32_t RR_GetDelaySinceLastSR() const
void SetProcessedInRTCP(bool v)
RTPNTPTime SR_Prev_GetNTPTimestamp() const
uint8_t * SDES_GetNote(std::size_t *len) const
RTPTime INF_GetLastRTPPacketTime() const
RTPTime GetLastNoteTime() const
bool INF_HasSentData() const
double RR_Prev_GetFractionLost() const
void Set(const RTPNTPTime &ntptime, uint32_t rtptime, uint32_t pcount, uint32_t bcount, const RTPTime &rcvtime)
Definition: rtpsourcedata.h:67