JRTPLIB  3.11.1
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 
47 namespace jrtplib
48 {
49 
51 class JRTPLIB_IMPORTEXPORT RTPRawPacket : public RTPMemoryObject
52 {
53 public:
61  RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,bool rtp,RTPMemoryManager *mgr = 0);
62  ~RTPRawPacket();
63 
65  uint8_t *GetData() { return packetdata; }
66 
68  size_t GetDataLength() const { return packetdatalength; }
69 
71  RTPTime GetReceiveTime() const { return receivetime; }
72 
74  const RTPAddress *GetSenderAddress() const { return senderaddress; }
75 
77  bool IsRTP() const { return isrtp; }
78 
86  void ZeroData() { packetdata = 0; packetdatalength = 0; }
87 
91  uint8_t *AllocateBytes(bool isrtp, int recvlen) const;
92 
95  void SetData(uint8_t *data, size_t datalen);
96 
99  void SetSenderAddress(RTPAddress *address);
100 private:
101  void DeleteData();
102 
103  uint8_t *packetdata;
104  size_t packetdatalength;
105  RTPTime receivetime;
106  RTPAddress *senderaddress;
107  bool isrtp;
108 };
109 
110 inline RTPRawPacket::RTPRawPacket(uint8_t *data,size_t datalen,RTPAddress *address,RTPTime &recvtime,bool rtp,RTPMemoryManager *mgr):RTPMemoryObject(mgr),receivetime(recvtime)
111 {
112  packetdata = data;
113  packetdatalength = datalen;
114  senderaddress = address;
115  isrtp = rtp;
116 }
117 
118 inline RTPRawPacket::~RTPRawPacket()
119 {
120  DeleteData();
121 }
122 
123 inline void RTPRawPacket::DeleteData()
124 {
125  if (packetdata)
126  RTPDeleteByteArray(packetdata,GetMemoryManager());
127  if (senderaddress)
128  RTPDelete(senderaddress,GetMemoryManager());
129 
130  packetdata = 0;
131  senderaddress = 0;
132 }
133 
134 inline uint8_t *RTPRawPacket::AllocateBytes(bool isrtp, int recvlen) const
135 {
136  JRTPLIB_UNUSED(isrtp); // possibly unused
137  return RTPNew(GetMemoryManager(),(isrtp)?RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET:RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET) uint8_t[recvlen];
138 }
139 
140 inline void RTPRawPacket::SetData(uint8_t *data, size_t datalen)
141 {
142  if (packetdata)
143  RTPDeleteByteArray(packetdata,GetMemoryManager());
144 
145  packetdata = data;
146  packetdatalength = datalen;
147 }
148 
150 {
151  if (senderaddress)
152  RTPDelete(senderaddress, GetMemoryManager());
153 
154  senderaddress = address;
155 }
156 
157 } // end namespace
158 
159 #endif // RTPRAWPACKET_H
160 
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:51
RTPTime GetReceiveTime() const
Returns the time at which this packet was received.
Definition: rtprawpacket.h:71
#define RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET
Buffer to store an incoming RTP packet.
Definition: rtpmemorymanager.h:48
size_t GetDataLength() const
Returns the length of the packet described by this instance.
Definition: rtprawpacket.h:68
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:134
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:50
void ZeroData()
Sets the pointer to the data stored in this packet to zero.
Definition: rtprawpacket.h:86
void SetData(uint8_t *data, size_t datalen)
Deallocates the previously stored data and replaces it with the data that's specified, can be useful when e.g.
Definition: rtprawpacket.h:140
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:110
void SetSenderAddress(RTPAddress *address)
Deallocates the currently stored RTPAddress instance and replaces it with the one that's specified (y...
Definition: rtprawpacket.h:149
const RTPAddress * GetSenderAddress() const
Returns the address stored in this packet.
Definition: rtprawpacket.h:74
Definition: rtpfaketransmitter.h:64
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:84
A memory manager.
Definition: rtpmemorymanager.h:150
uint8_t * GetData()
Returns the pointer to the data which is contained in this packet.
Definition: rtprawpacket.h:65
bool IsRTP() const
Returns true if this data is RTP data, false if it is RTCP data.
Definition: rtprawpacket.h:77
#define RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET
Buffer to store an incoming RTCP packet.
Definition: rtpmemorymanager.h:51