JRTPLIB  3.11.1
rtcpsrpacket.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 RTCPSRPACKET_H
38 
39 #define RTCPSRPACKET_H
40 
41 #include "rtpconfig.h"
42 #include "rtcppacket.h"
43 #include "rtptimeutilities.h"
44 #include "rtpstructs.h"
45 #ifdef RTP_SUPPORT_NETINET_IN
46  #include <netinet/in.h>
47 #endif // RTP_SUPPORT_NETINET_IN
48 
49 namespace jrtplib
50 {
51 
52 class RTCPCompoundPacket;
53 
55 class JRTPLIB_IMPORTEXPORT RTCPSRPacket : public RTCPPacket
56 {
57 public:
63  RTCPSRPacket(uint8_t *data,size_t datalength);
64  ~RTCPSRPacket() { }
65 
67  uint32_t GetSenderSSRC() const;
68 
70  RTPNTPTime GetNTPTimestamp() const;
71 
73  uint32_t GetRTPTimestamp() const;
74 
76  uint32_t GetSenderPacketCount() const;
77 
79  uint32_t GetSenderOctetCount() const;
80 
82  int GetReceptionReportCount() const;
83 
88  uint32_t GetSSRC(int index) const;
89 
94  uint8_t GetFractionLost(int index) const;
95 
100  int32_t GetLostPacketCount(int index) const;
101 
106  uint32_t GetExtendedHighestSequenceNumber(int index) const;
107 
112  uint32_t GetJitter(int index) const;
113 
118  uint32_t GetLSR(int index) const;
119 
124  uint32_t GetDLSR(int index) const;
125 
126 #ifdef RTPDEBUG
127  void Dump();
128 #endif // RTPDEBUG
129 private:
130  RTCPReceiverReport *GotoReport(int index) const;
131 };
132 
133 inline uint32_t RTCPSRPacket::GetSenderSSRC() const
134 {
135  if (!knownformat)
136  return 0;
137 
138  uint32_t *ssrcptr = (uint32_t *)(data+sizeof(RTCPCommonHeader));
139  return ntohl(*ssrcptr);
140 }
141 
143 {
144  if (!knownformat)
145  return RTPNTPTime(0,0);
146 
147  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
148  return RTPNTPTime(ntohl(sr->ntptime_msw),ntohl(sr->ntptime_lsw));
149 }
150 
151 inline uint32_t RTCPSRPacket::GetRTPTimestamp() const
152 {
153  if (!knownformat)
154  return 0;
155  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
156  return ntohl(sr->rtptimestamp);
157 }
158 
159 inline uint32_t RTCPSRPacket::GetSenderPacketCount() const
160 {
161  if (!knownformat)
162  return 0;
163  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
164  return ntohl(sr->packetcount);
165 }
166 
167 inline uint32_t RTCPSRPacket::GetSenderOctetCount() const
168 {
169  if (!knownformat)
170  return 0;
171  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
172  return ntohl(sr->octetcount);
173 }
174 
176 {
177  if (!knownformat)
178  return 0;
179  RTCPCommonHeader *hdr = (RTCPCommonHeader *)data;
180  return ((int)hdr->count);
181 }
182 
183 inline RTCPReceiverReport *RTCPSRPacket::GotoReport(int index) const
184 {
185  RTCPReceiverReport *r = (RTCPReceiverReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)+sizeof(RTCPSenderReport)+index*sizeof(RTCPReceiverReport));
186  return r;
187 }
188 
189 inline uint32_t RTCPSRPacket::GetSSRC(int index) const
190 {
191  if (!knownformat)
192  return 0;
193  RTCPReceiverReport *r = GotoReport(index);
194  return ntohl(r->ssrc);
195 }
196 
197 inline uint8_t RTCPSRPacket::GetFractionLost(int index) const
198 {
199  if (!knownformat)
200  return 0;
201  RTCPReceiverReport *r = GotoReport(index);
202  return r->fractionlost;
203 }
204 
205 inline int32_t RTCPSRPacket::GetLostPacketCount(int index) const
206 {
207  if (!knownformat)
208  return 0;
209  RTCPReceiverReport *r = GotoReport(index);
210  uint32_t count = ((uint32_t)r->packetslost[2])|(((uint32_t)r->packetslost[1])<<8)|(((uint32_t)r->packetslost[0])<<16);
211  if ((count&0x00800000) != 0) // test for negative number
212  count |= 0xFF000000;
213  int32_t *count2 = (int32_t *)(&count);
214  return (*count2);
215 }
216 
217 inline uint32_t RTCPSRPacket::GetExtendedHighestSequenceNumber(int index) const
218 {
219  if (!knownformat)
220  return 0;
221  RTCPReceiverReport *r = GotoReport(index);
222  return ntohl(r->exthighseqnr);
223 }
224 
225 inline uint32_t RTCPSRPacket::GetJitter(int index) const
226 {
227  if (!knownformat)
228  return 0;
229  RTCPReceiverReport *r = GotoReport(index);
230  return ntohl(r->jitter);
231 }
232 
233 inline uint32_t RTCPSRPacket::GetLSR(int index) const
234 {
235  if (!knownformat)
236  return 0;
237  RTCPReceiverReport *r = GotoReport(index);
238  return ntohl(r->lsr);
239 }
240 
241 inline uint32_t RTCPSRPacket::GetDLSR(int index) const
242 {
243  if (!knownformat)
244  return 0;
245  RTCPReceiverReport *r = GotoReport(index);
246  return ntohl(r->dlsr);
247 }
248 
249 } // end namespace
250 
251 #endif // RTCPSRPACKET_H
252 
uint32_t GetRTPTimestamp() const
Returns the RTP timestamp contained in the sender report.
Definition: rtcpsrpacket.h:151
uint32_t GetExtendedHighestSequenceNumber(int index) const
Returns the extended highest sequence number of the reception report block described by index which m...
Definition: rtcpsrpacket.h:217
Describes an RTCP sender report packet.
Definition: rtcpsrpacket.h:55
RTPNTPTime GetNTPTimestamp() const
Returns the NTP timestamp contained in the sender report.
Definition: rtcpsrpacket.h:142
This is a simple wrapper for the most significant word (MSW) and least significant word (LSW) of an N...
Definition: rtptimeutilities.h:65
uint32_t GetSSRC(int index) const
Returns the SSRC of the reception report block described by index which may have a value from 0 to Ge...
Definition: rtcpsrpacket.h:189
uint8_t GetFractionLost(int index) const
Returns the `fraction lost&#39; field of the reception report described by index which may have a value f...
Definition: rtcpsrpacket.h:197
uint32_t GetLSR(int index) const
Returns the LSR field of the reception report block described by index which may have a value from 0 ...
Definition: rtcpsrpacket.h:233
uint32_t GetDLSR(int index) const
Returns the DLSR field of the reception report block described by index which may have a value from 0...
Definition: rtcpsrpacket.h:241
uint32_t GetJitter(int index) const
Returns the jitter field of the reception report block described by index which may have a value from...
Definition: rtcpsrpacket.h:225
uint32_t GetSenderOctetCount() const
Returns the sender&#39;s octet count contained in the sender report.
Definition: rtcpsrpacket.h:167
int GetReceptionReportCount() const
Returns the number of reception report blocks present in this packet.
Definition: rtcpsrpacket.h:175
uint32_t GetSenderSSRC() const
Returns the SSRC of the participant who sent this packet.
Definition: rtcpsrpacket.h:133
Definition: rtpfaketransmitter.h:64
uint32_t GetSenderPacketCount() const
Returns the sender&#39;s packet count contained in the sender report.
Definition: rtcpsrpacket.h:159
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:50
int32_t GetLostPacketCount(int index) const
Returns the number of lost packets in the reception report block described by index which may have a ...
Definition: rtcpsrpacket.h:205