jrtplib  3.7.1
rtpsourcedata.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2007 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale 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 "rtpmemoryobject.h"
48 #include <list>
49 
50 class RTPAddress;
51 
52 class RTCPSenderReportInfo
53 {
54 public:
55  RTCPSenderReportInfo():ntptimestamp(0,0),receivetime(0,0) { hasinfo = false; rtptimestamp = 0; packetcount = 0; bytecount = 0; }
56  void Set(const RTPNTPTime &ntptime,uint32_t rtptime,uint32_t pcount,
57  uint32_t bcount,const RTPTime &rcvtime) { ntptimestamp = ntptime; rtptimestamp = rtptime; packetcount = pcount; bytecount = bcount; receivetime = rcvtime; hasinfo = true; }
58 
59  bool HasInfo() const { return hasinfo; }
60  RTPNTPTime GetNTPTimestamp() const { return ntptimestamp; }
61  uint32_t GetRTPTimestamp() const { return rtptimestamp; }
62  uint32_t GetPacketCount() const { return packetcount; }
63  uint32_t GetByteCount() const { return bytecount; }
64  RTPTime GetReceiveTime() const { return receivetime; }
65 private:
66  bool hasinfo;
67  RTPNTPTime ntptimestamp;
68  uint32_t rtptimestamp;
69  uint32_t packetcount;
70  uint32_t bytecount;
71  RTPTime receivetime;
72 };
73 
74 class RTCPReceiverReportInfo
75 {
76 public:
77  RTCPReceiverReportInfo():receivetime(0,0) { hasinfo = false; fractionlost = 0; packetslost = 0; exthighseqnr = 0; jitter = 0; lsr = 0; dlsr = 0; }
78  void Set(uint8_t fraclost,int32_t plost,uint32_t exthigh,
79  uint32_t jit,uint32_t l,uint32_t dl,const RTPTime &rcvtime) { fractionlost = ((double)fraclost)/256.0; packetslost = plost; exthighseqnr = exthigh; jitter = jit; lsr = l; dlsr = dl; receivetime = rcvtime; hasinfo = true; }
80 
81  bool HasInfo() const { return hasinfo; }
82  double GetFractionLost() const { return fractionlost; }
83  int32_t GetPacketsLost() const { return packetslost; }
84  uint32_t GetExtendedHighestSequenceNumber() const { return exthighseqnr; }
85  uint32_t GetJitter() const { return jitter; }
86  uint32_t GetLastSRTimestamp() const { return lsr; }
87  uint32_t GetDelaySinceLastSR() const { return dlsr; }
88  RTPTime GetReceiveTime() const { return receivetime; }
89 private:
90  bool hasinfo;
91  double fractionlost;
92  int32_t packetslost;
93  uint32_t exthighseqnr;
94  uint32_t jitter;
95  uint32_t lsr;
96  uint32_t dlsr;
97  RTPTime receivetime;
98 };
99 
100 class RTPSourceStats
101 {
102 public:
103  RTPSourceStats();
104  void ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,double tsunit,bool ownpacket,bool *accept,bool applyprobation,bool *onprobation);
105 
106  bool HasSentData() const { return sentdata; }
107  uint32_t GetNumPacketsReceived() const { return packetsreceived; }
108  uint32_t GetBaseSequenceNumber() const { return baseseqnr; }
109  uint32_t GetExtendedHighestSequenceNumber() const { return exthighseqnr; }
110  uint32_t GetJitter() const { return jitter; }
111 
112  int32_t GetNumPacketsReceivedInInterval() const { return numnewpackets; }
113  uint32_t GetSavedExtendedSequenceNumber() const { return savedextseqnr; }
114  void StartNewInterval() { numnewpackets = 0; savedextseqnr = exthighseqnr; }
115 
116  void SetLastMessageTime(const RTPTime &t) { lastmsgtime = t; }
117  RTPTime GetLastMessageTime() const { return lastmsgtime; }
118  void SetLastRTPPacketTime(const RTPTime &t) { lastrtptime = t; }
119  RTPTime GetLastRTPPacketTime() const { return lastrtptime; }
120 
121  void SetLastNoteTime(const RTPTime &t) { lastnotetime = t; }
122  RTPTime GetLastNoteTime() const { return lastnotetime; }
123 private:
124  bool sentdata;
125  uint32_t packetsreceived;
126  uint32_t numcycles; // shifted left 16 bits
127  uint32_t baseseqnr;
128  uint32_t exthighseqnr,prevexthighseqnr;
129  uint32_t jitter,prevtimestamp;
130  double djitter;
131  RTPTime prevpacktime;
132  RTPTime lastmsgtime;
133  RTPTime lastrtptime;
134  RTPTime lastnotetime;
135  uint32_t numnewpackets;
136  uint32_t savedextseqnr;
137 #ifdef RTP_SUPPORT_PROBATION
138  uint16_t prevseqnr;
139  int probation;
140  RTPSources::ProbationType probationtype;
141 #endif // RTP_SUPPORT_PROBATION
142 };
143 
144 inline RTPSourceStats::RTPSourceStats():prevpacktime(0,0),lastmsgtime(0,0),lastrtptime(0,0),lastnotetime(0,0)
145 {
146  sentdata = false;
147  packetsreceived = 0;
148  baseseqnr = 0;
149  exthighseqnr = 0;
150  prevexthighseqnr = 0;
151  jitter = 0;
152  numcycles = 0;
153  numnewpackets = 0;
154  prevtimestamp = 0;
155  djitter = 0;
156  savedextseqnr = 0;
157 #ifdef RTP_SUPPORT_PROBATION
158  probation = 0;
159  prevseqnr = 0;
160 #endif // RTP_SUPPORT_PROBATION
161 }
162 
164 class RTPSourceData : public RTPMemoryObject
165 {
166 protected:
167  RTPSourceData(uint32_t ssrc, RTPMemoryManager *mgr = 0);
168  virtual ~RTPSourceData();
169 public:
172 
174  void FlushPackets();
175 
177  bool HasData() const { if (!validated) return false; return packetlist.empty()?false:true; }
178 
180  uint32_t GetSSRC() const { return ssrc; }
181 
185  bool IsOwnSSRC() const { return ownssrc; }
186 
188  bool IsCSRC() const { return iscsrc; }
189 
191  bool IsSender() const { return issender; }
192 
197  bool IsValidated() const { return validated; }
198 
200  bool IsActive() const { if (!validated) return false; if (receivedbye) return false; return true; }
201 
205  void SetProcessedInRTCP(bool v) { processedinrtcp = v; }
206 
210  bool IsProcessedInRTCP() const { return processedinrtcp; }
211 
215  bool IsRTPAddressSet() const { return isrtpaddrset; }
216 
220  bool IsRTCPAddressSet() const { return isrtcpaddrset; }
221 
227  const RTPAddress *GetRTPDataAddress() const { return rtpaddr; }
228 
234  const RTPAddress *GetRTCPDataAddress() const { return rtcpaddr; }
235 
237  bool ReceivedBYE() const { return receivedbye; }
238 
243  uint8_t *GetBYEReason(size_t *len) const { *len = byereasonlen; return byereason; }
244 
246  RTPTime GetBYETime() const { return byetime; }
247 
254  void SetTimestampUnit(double tsu) { timestampunit = tsu; }
255 
257  double GetTimestampUnit() const { return timestampunit; }
258 
260  bool SR_HasInfo() const { return SRinf.HasInfo(); }
261 
263  RTPNTPTime SR_GetNTPTimestamp() const { return SRinf.GetNTPTimestamp(); }
264 
266  uint32_t SR_GetRTPTimestamp() const { return SRinf.GetRTPTimestamp(); }
267 
269  uint32_t SR_GetPacketCount() const { return SRinf.GetPacketCount(); }
270 
272  uint32_t SR_GetByteCount() const { return SRinf.GetByteCount(); }
273 
275  RTPTime SR_GetReceiveTime() const { return SRinf.GetReceiveTime(); }
276 
278  bool SR_Prev_HasInfo() const { return SRprevinf.HasInfo(); }
279 
281  RTPNTPTime SR_Prev_GetNTPTimestamp() const { return SRprevinf.GetNTPTimestamp(); }
282 
284  uint32_t SR_Prev_GetRTPTimestamp() const { return SRprevinf.GetRTPTimestamp(); }
285 
287  uint32_t SR_Prev_GetPacketCount() const { return SRprevinf.GetPacketCount(); }
288 
290  uint32_t SR_Prev_GetByteCount() const { return SRprevinf.GetByteCount(); }
291 
293  RTPTime SR_Prev_GetReceiveTime() const { return SRprevinf.GetReceiveTime(); }
294 
296  bool RR_HasInfo() const { return RRinf.HasInfo(); }
297 
299  double RR_GetFractionLost() const { return RRinf.GetFractionLost(); }
300 
302  int32_t RR_GetPacketsLost() const { return RRinf.GetPacketsLost(); }
303 
305  uint32_t RR_GetExtendedHighestSequenceNumber() const { return RRinf.GetExtendedHighestSequenceNumber(); }
306 
308  uint32_t RR_GetJitter() const { return RRinf.GetJitter(); }
309 
311  uint32_t RR_GetLastSRTimestamp() const { return RRinf.GetLastSRTimestamp(); }
312 
314  uint32_t RR_GetDelaySinceLastSR() const { return RRinf.GetDelaySinceLastSR(); }
315 
317  RTPTime RR_GetReceiveTime() const { return RRinf.GetReceiveTime(); }
318 
322  bool RR_Prev_HasInfo() const { return RRprevinf.HasInfo(); }
323 
325  double RR_Prev_GetFractionLost() const { return RRprevinf.GetFractionLost(); }
326 
328  int32_t RR_Prev_GetPacketsLost() const { return RRprevinf.GetPacketsLost(); }
329 
331  uint32_t RR_Prev_GetExtendedHighestSequenceNumber() const { return RRprevinf.GetExtendedHighestSequenceNumber(); }
332 
334  uint32_t RR_Prev_GetJitter() const { return RRprevinf.GetJitter(); }
335 
337  uint32_t RR_Prev_GetLastSRTimestamp() const { return RRprevinf.GetLastSRTimestamp(); }
338 
340  uint32_t RR_Prev_GetDelaySinceLastSR() const { return RRprevinf.GetDelaySinceLastSR(); }
341 
343  RTPTime RR_Prev_GetReceiveTime() const { return RRprevinf.GetReceiveTime(); }
344 
346  bool INF_HasSentData() const { return stats.HasSentData(); }
347 
349  int32_t INF_GetNumPacketsReceived() const { return stats.GetNumPacketsReceived(); }
350 
352  uint32_t INF_GetBaseSequenceNumber() const { return stats.GetBaseSequenceNumber(); }
353 
355  uint32_t INF_GetExtendedHighestSequenceNumber() const { return stats.GetExtendedHighestSequenceNumber(); }
356 
358  uint32_t INF_GetJitter() const { return stats.GetJitter(); }
359 
361  RTPTime INF_GetLastMessageTime() const { return stats.GetLastMessageTime(); }
362 
364  RTPTime INF_GetLastRTPPacketTime() const { return stats.GetLastRTPPacketTime(); }
365 
367  double INF_GetEstimatedTimestampUnit() const;
368 
370  uint32_t INF_GetNumPacketsReceivedInInterval() const { return stats.GetNumPacketsReceivedInInterval(); }
371 
373  uint32_t INF_GetSavedExtendedSequenceNumber() const { return stats.GetSavedExtendedSequenceNumber(); }
374 
378  void INF_StartNewInterval() { stats.StartNewInterval(); }
379 
382 
384  RTPTime INF_GetLastSDESNoteTime() const { return stats.GetLastNoteTime(); }
385 
387  uint8_t *SDES_GetCNAME(size_t *len) const { return SDESinf.GetCNAME(len); }
388 
390  uint8_t *SDES_GetName(size_t *len) const { return SDESinf.GetName(len); }
391 
393  uint8_t *SDES_GetEMail(size_t *len) const { return SDESinf.GetEMail(len); }
394 
396  uint8_t *SDES_GetPhone(size_t *len) const { return SDESinf.GetPhone(len); }
397 
399  uint8_t *SDES_GetLocation(size_t *len) const { return SDESinf.GetLocation(len); }
400 
402  uint8_t *SDES_GetTool(size_t *len) const { return SDESinf.GetTool(len); }
403 
405  uint8_t *SDES_GetNote(size_t *len) const { return SDESinf.GetNote(len); }
406 
407 #ifdef RTP_SUPPORT_SDESPRIV
408 
410 
414  bool SDES_GetNextPrivateValue(uint8_t **prefix,size_t *prefixlen,uint8_t **value,size_t *valuelen) { return SDESinf.GetNextPrivateValue(prefix,prefixlen,value,valuelen); }
415 
420  bool SDES_GetPrivateValue(uint8_t *prefix,size_t prefixlen,uint8_t **value,size_t *valuelen) const { return SDESinf.GetPrivateValue(prefix,prefixlen,value,valuelen); }
421 #endif // RTP_SUPPORT_SDESPRIV
422 
423 #ifdef RTPDEBUG
424  virtual void Dump();
425 #endif // RTPDEBUG
426 protected:
427  std::list<RTPPacket *> packetlist;
428 
429  uint32_t ssrc;
430  bool ownssrc;
431  bool iscsrc;
432  double timestampunit;
433  bool receivedbye;
434  bool validated;
435  bool processedinrtcp;
436  bool issender;
437 
438  RTCPSenderReportInfo SRinf,SRprevinf;
439  RTCPReceiverReportInfo RRinf,RRprevinf;
440  RTPSourceStats stats;
441  RTCPSDESInfo SDESinf;
442 
443  bool isrtpaddrset,isrtcpaddrset;
444  RTPAddress *rtpaddr,*rtcpaddr;
445 
446  RTPTime byetime;
447  uint8_t *byereason;
448  size_t byereasonlen;
449 };
450 
452 {
453  if (!validated)
454  return 0;
455 
456  RTPPacket *p;
457 
458  if (packetlist.empty())
459  return 0;
460  p = *(packetlist.begin());
461  packetlist.pop_front();
462  return p;
463 }
464 
466 {
467  std::list<RTPPacket *>::const_iterator it;
468 
469  for (it = packetlist.begin() ; it != packetlist.end() ; ++it)
470  RTPDelete(*it,GetMemoryManager());
471  packetlist.clear();
472 }
473 #endif // RTPSOURCEDATA_H
474