jrtplib  3.6.0
rtcpsrpacket.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 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 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 #if ! (defined(WIN32) || defined(_WIN32_WCE))
46  #include <netinet/in.h>
47 #endif // WIN32
48 
49 class RTCPCompoundPacket;
50 
52 class RTCPSRPacket : public RTCPPacket
53 {
54 public:
60  RTCPSRPacket(uint8_t *data,size_t datalength);
61  ~RTCPSRPacket() { }
62 
64  uint32_t GetSenderSSRC() const;
65 
68 
70  uint32_t GetRTPTimestamp() const;
71 
73  uint32_t GetSenderPacketCount() const;
74 
76  uint32_t GetSenderOctetCount() const;
77 
79  int GetReceptionReportCount() const;
80 
85  uint32_t GetSSRC(int index) const;
86 
91  uint8_t GetFractionLost(int index) const;
92 
97  int32_t GetLostPacketCount(int index) const;
98 
103  uint32_t GetExtendedHighestSequenceNumber(int index) const;
104 
109  uint32_t GetJitter(int index) const;
110 
115  uint32_t GetLSR(int index) const;
116 
121  uint32_t GetDLSR(int index) const;
122 
123 #ifdef RTPDEBUG
124  void Dump();
125 #endif // RTPDEBUG
126 private:
127  RTCPReceiverReport *GotoReport(int index) const;
128 };
129 
130 inline uint32_t RTCPSRPacket::GetSenderSSRC() const
131 {
132  if (!knownformat)
133  return 0;
134 
135  uint32_t *ssrcptr = (uint32_t *)(data+sizeof(RTCPCommonHeader));
136  return ntohl(*ssrcptr);
137 }
138 
140 {
141  if (!knownformat)
142  return RTPNTPTime(0,0);
143 
144  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
145  return RTPNTPTime(ntohl(sr->ntptime_msw),ntohl(sr->ntptime_lsw));
146 }
147 
148 inline uint32_t RTCPSRPacket::GetRTPTimestamp() const
149 {
150  if (!knownformat)
151  return 0;
152  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
153  return ntohl(sr->rtptimestamp);
154 }
155 
156 inline uint32_t RTCPSRPacket::GetSenderPacketCount() const
157 {
158  if (!knownformat)
159  return 0;
160  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
161  return ntohl(sr->packetcount);
162 }
163 
164 inline uint32_t RTCPSRPacket::GetSenderOctetCount() const
165 {
166  if (!knownformat)
167  return 0;
168  RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
169  return ntohl(sr->octetcount);
170 }
171 
173 {
174  if (!knownformat)
175  return 0;
176  RTCPCommonHeader *hdr = (RTCPCommonHeader *)data;
177  return ((int)hdr->count);
178 }
179 
180 inline RTCPReceiverReport *RTCPSRPacket::GotoReport(int index) const
181 {
182  RTCPReceiverReport *r = (RTCPReceiverReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)+sizeof(RTCPSenderReport)+index*sizeof(RTCPReceiverReport));
183  return r;
184 }
185 
186 inline uint32_t RTCPSRPacket::GetSSRC(int index) const
187 {
188  if (!knownformat)
189  return 0;
190  RTCPReceiverReport *r = GotoReport(index);
191  return ntohl(r->ssrc);
192 }
193 
194 inline uint8_t RTCPSRPacket::GetFractionLost(int index) const
195 {
196  if (!knownformat)
197  return 0;
198  RTCPReceiverReport *r = GotoReport(index);
199  return r->fractionlost;
200 }
201 
202 inline int32_t RTCPSRPacket::GetLostPacketCount(int index) const
203 {
204  if (!knownformat)
205  return 0;
206  RTCPReceiverReport *r = GotoReport(index);
207  uint32_t count = ((uint32_t)r->packetslost[2])|(((uint32_t)r->packetslost[1])<<8)|(((uint32_t)r->packetslost[0])<<16);
208  if ((count&0x00800000) != 0) // test for negative number
209  count |= 0xFF000000;
210  int32_t *count2 = (int32_t *)(&count);
211  return (*count2);
212 }
213 
214 inline uint32_t RTCPSRPacket::GetExtendedHighestSequenceNumber(int index) const
215 {
216  if (!knownformat)
217  return 0;
218  RTCPReceiverReport *r = GotoReport(index);
219  return ntohl(r->exthighseqnr);
220 }
221 
222 inline uint32_t RTCPSRPacket::GetJitter(int index) const
223 {
224  if (!knownformat)
225  return 0;
226  RTCPReceiverReport *r = GotoReport(index);
227  return ntohl(r->jitter);
228 }
229 
230 inline uint32_t RTCPSRPacket::GetLSR(int index) const
231 {
232  if (!knownformat)
233  return 0;
234  RTCPReceiverReport *r = GotoReport(index);
235  return ntohl(r->lsr);
236 }
237 
238 inline uint32_t RTCPSRPacket::GetDLSR(int index) const
239 {
240  if (!knownformat)
241  return 0;
242  RTCPReceiverReport *r = GotoReport(index);
243  return ntohl(r->dlsr);
244 }
245 
246 #endif // RTCPSRPACKET_H
247 
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:202
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:214
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:230
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:238
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:222
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:47
uint8_t GetFractionLost(int index) const
Returns the `fraction lost' field of the reception report described by index which may have a value f...
Definition: rtcpsrpacket.h:194
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
uint32_t GetSenderOctetCount() const
Returns the sender's octet count contained in the sender report.
Definition: rtcpsrpacket.h:164
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:186
RTPNTPTime GetNTPTimestamp() const
Returns the NTP timestamp contained in the sender report.
Definition: rtcpsrpacket.h:139
int GetReceptionReportCount() const
Returns the number of reception report blocks present in this packet.
Definition: rtcpsrpacket.h:172
uint32_t GetSenderSSRC() const
Returns the SSRC of the participant who sent this packet.
Definition: rtcpsrpacket.h:130
uint32_t GetRTPTimestamp() const
Returns the RTP timestamp contained in the sender report.
Definition: rtcpsrpacket.h:148
Describes an RTCP sender report packet.
Definition: rtcpsrpacket.h:52
RTCPSRPacket(uint8_t *data, size_t datalength)
Creates an instance based on the data in data with length datalen.
uint32_t GetSenderPacketCount() const
Returns the sender's packet count contained in the sender report.
Definition: rtcpsrpacket.h:156
This is a simple wrapper for the most significant word (MSW) and least significant word (LSW) of an N...
Definition: rtptimeutilities.h:58