jrtplib  3.6.0
rtcpbyepacket.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 RTCPBYEPACKET_H
38 
39 #define RTCPBYEPACKET_H
40 
41 #include "rtpconfig.h"
42 #include "rtcppacket.h"
43 #include "rtpstructs.h"
44 #if ! (defined(WIN32) || defined (_WIN32_WCE))
45  #include <netinet/in.h>
46 #endif // WIN32
47 
48 class RTCPCompoundPacket;
49 
51 class RTCPBYEPacket : public RTCPPacket
52 {
53 public:
59  RTCPBYEPacket(uint8_t *data,size_t datalen);
60  ~RTCPBYEPacket() { }
61 
63  int GetSSRCCount() const;
64 
68  uint32_t GetSSRC(int index) const; // note: no check is performed to see if index is valid!
69 
71  bool HasReasonForLeaving() const;
72 
74  size_t GetReasonLength() const;
75 
77  uint8_t *GetReasonData();
78 
79 #ifdef RTPDEBUG
80  void Dump();
81 #endif // RTPDEBUG
82 private:
83  size_t reasonoffset;
84 };
85 
86 inline int RTCPBYEPacket::GetSSRCCount() const
87 {
88  if (!knownformat)
89  return 0;
90 
91  RTCPCommonHeader *hdr = (RTCPCommonHeader *)data;
92  return (int)(hdr->count);
93 }
94 
95 inline uint32_t RTCPBYEPacket::GetSSRC(int index) const
96 {
97  if (!knownformat)
98  return 0;
99  uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)*index);
100  return ntohl(*ssrc);
101 }
102 
104 {
105  if (!knownformat)
106  return false;
107  if (reasonoffset == 0)
108  return false;
109  return true;
110 }
111 
112 inline size_t RTCPBYEPacket::GetReasonLength() const
113 {
114  if (!knownformat)
115  return 0;
116  if (reasonoffset == 0)
117  return 0;
118  uint8_t *reasonlen = (data+reasonoffset);
119  return (size_t)(*reasonlen);
120 }
121 
123 {
124  if (!knownformat)
125  return 0;
126  if (reasonoffset == 0)
127  return 0;
128  uint8_t *reasonlen = (data+reasonoffset);
129  if ((*reasonlen) == 0)
130  return 0;
131  return (data+reasonoffset+1);
132 }
133 
134 #endif // RTCPBYEPACKET_H
135 
Describes an RTCP BYE packet.
Definition: rtcpbyepacket.h:51
RTCPBYEPacket(uint8_t *data, size_t datalen)
Creates an instance based on the data in data with length datalen.
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:47
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
int GetSSRCCount() const
Returns the number of SSRC identifiers present in this BYE packet.
Definition: rtcpbyepacket.h:86
uint32_t GetSSRC(int index) const
Returns the SSRC described by index which may have a value from 0 to GetSSRCCount()-1 (note that no c...
Definition: rtcpbyepacket.h:95
size_t GetReasonLength() const
Returns the length of the string which describes why the source(s) left.
Definition: rtcpbyepacket.h:112
uint8_t * GetReasonData()
Returns the actual reason for leaving data.
Definition: rtcpbyepacket.h:122
bool HasReasonForLeaving() const
Returns true if the BYE packet contains a reason for leaving.
Definition: rtcpbyepacket.h:103