JRTPLIB  3.11.2 (development version)
rtprawpacket.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 RTPRAWPACKET_H
38 
39 #define RTPRAWPACKET_H
40 
41 #include "rtpconfig.h"
42 #include "rtptimeutilities.h"
43 #include "rtpaddress.h"
44 #include "rtptypes.h"
45 #include "rtpmemoryobject.h"
46 #include "rtpstructs.h"
47 
48 namespace jrtplib
49 {
50 
52 class JRTPLIB_IMPORTEXPORT RTPRawPacket : public RTPMemoryObject
53 {
54  JRTPLIB_NO_COPY(RTPRawPacket)
55 public:
64  RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,bool rtp,RTPMemoryManager *mgr = 0);
65 
74  RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,RTPMemoryManager *mgr = 0);
75  ~RTPRawPacket();
76 
78  uint8_t *GetData() { return packetdata; }
79 
81  size_t GetDataLength() const { return packetdatalength; }
82 
84  RTPTime GetReceiveTime() const { return receivetime; }
85 
87  const RTPAddress *GetSenderAddress() const { return senderaddress; }
88 
90  bool IsRTP() const { return isrtp; }
91 
99  void ZeroData() { packetdata = 0; packetdatalength = 0; }
100 
104  uint8_t *AllocateBytes(bool isrtp, int recvlen) const;
105 
108  void SetData(uint8_t *data, size_t datalen);
109 
112  void SetSenderAddress(RTPAddress *address);
113 private:
114  void DeleteData();
115 
116  uint8_t *packetdata;
117  size_t packetdatalength;
118  RTPTime receivetime;
119  RTPAddress *senderaddress;
120  bool isrtp;
121 };
122 
123 inline RTPRawPacket::RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,bool rtp,RTPMemoryManager *mgr):RTPMemoryObject(mgr),receivetime(recvtime)
124 {
125  packetdata = data;
126  packetdatalength = datalen;
127  senderaddress = address;
128  isrtp = rtp;
129 }
130 
131 inline RTPRawPacket::RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,RTPMemoryManager *mgr):RTPMemoryObject(mgr),receivetime(recvtime)
132 {
133  packetdata = data;
134  packetdatalength = datalen;
135  senderaddress = address;
136 
137  isrtp = true;
138  if (datalen >= sizeof(RTCPCommonHeader))
139  {
140  RTCPCommonHeader *rtcpheader = (RTCPCommonHeader *)data;
141  uint8_t packettype = rtcpheader->packettype;
142 
143  if (packettype >= 200 && packettype <= 204)
144  isrtp = false;
145  }
146 }
147 
148 inline RTPRawPacket::~RTPRawPacket()
149 {
150  DeleteData();
151 }
152 
153 inline void RTPRawPacket::DeleteData()
154 {
155  if (packetdata)
156  RTPDeleteByteArray(packetdata,GetMemoryManager());
157  if (senderaddress)
158  RTPDelete(senderaddress,GetMemoryManager());
159 
160  packetdata = 0;
161  senderaddress = 0;
162 }
163 
164 inline uint8_t *RTPRawPacket::AllocateBytes(bool isrtp, int recvlen) const
165 {
166  JRTPLIB_UNUSED(isrtp); // possibly unused
167  return RTPNew(GetMemoryManager(),(isrtp)?RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET:RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET) uint8_t[recvlen];
168 }
169 
170 inline void RTPRawPacket::SetData(uint8_t *data, size_t datalen)
171 {
172  if (packetdata)
173  RTPDeleteByteArray(packetdata,GetMemoryManager());
174 
175  packetdata = data;
176  packetdatalength = datalen;
177 }
178 
180 {
181  if (senderaddress)
182  RTPDelete(senderaddress, GetMemoryManager());
183 
184  senderaddress = address;
185 }
186 
187 } // end namespace
188 
189 #endif // RTPRAWPACKET_H
190 
This class is an abstract class which is used to specify destinations, multicast groups etc.
Definition: rtpaddress.h:51
A memory manager.
Definition: rtpmemorymanager.h:151
This class is used by the transmission component to store the incoming RTP and RTCP data in.
Definition: rtprawpacket.h:53
const RTPAddress * GetSenderAddress() const
Returns the address stored in this packet.
Definition: rtprawpacket.h:87
void SetData(uint8_t *data, size_t datalen)
Deallocates the previously stored data and replaces it with the data that's specified,...
Definition: rtprawpacket.h:170
void SetSenderAddress(RTPAddress *address)
Deallocates the currently stored RTPAddress instance and replaces it with the one that's specified (y...
Definition: rtprawpacket.h:179
RTPRawPacket(uint8_t *data, size_t datalen, RTPAddress *address, RTPTime &recvtime, bool rtp, RTPMemoryManager *mgr=0)
Creates an instance which stores data from data with length datalen.
Definition: rtprawpacket.h:123
void ZeroData()
Sets the pointer to the data stored in this packet to zero.
Definition: rtprawpacket.h:99
uint8_t * GetData()
Returns the pointer to the data which is contained in this packet.
Definition: rtprawpacket.h:78
bool IsRTP() const
Returns true if this data is RTP data, false if it is RTCP data.
Definition: rtprawpacket.h:90
RTPTime GetReceiveTime() const
Returns the time at which this packet was received.
Definition: rtprawpacket.h:84
uint8_t * AllocateBytes(bool isrtp, int recvlen) const
Allocates a number of bytes for RTP or RTCP data using the memory manager that was used for this raw ...
Definition: rtprawpacket.h:164
size_t GetDataLength() const
Returns the length of the packet described by this instance.
Definition: rtprawpacket.h:81
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:86
#define RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET
Buffer to store an incoming RTP packet.
Definition: rtpmemorymanager.h:48
#define RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET
Buffer to store an incoming RTCP packet.
Definition: rtpmemorymanager.h:51