jrtplib  3.6.0
rtppacket.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 RTPPACKET_H
38 
39 #define RTPPACKET_H
40 
41 #include "rtpconfig.h"
42 #include "rtptypes.h"
43 #include "rtptimeutilities.h"
44 #include "rtpmemoryobject.h"
45 
46 class RTPRawPacket;
47 
53 class RTPPacket : public RTPMemoryObject
54 {
55 public:
60  RTPPacket(RTPRawPacket &rawpack,RTPMemoryManager *mgr = 0);
61 
68  RTPPacket(uint8_t payloadtype,const void *payloaddata,size_t payloadlen,uint16_t seqnr,
69  uint32_t timestamp,uint32_t ssrc,bool gotmarker,uint8_t numcsrcs,const uint32_t *csrcs,
70  bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata,
71  size_t maxpacksize, RTPMemoryManager *mgr = 0);
72 
75  RTPPacket(uint8_t payloadtype,const void *payloaddata,size_t payloadlen,uint16_t seqnr,
76  uint32_t timestamp,uint32_t ssrc,bool gotmarker,uint8_t numcsrcs,const uint32_t *csrcs,
77  bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata,
78  void *buffer,size_t buffersize,RTPMemoryManager *mgr = 0);
79 
80  virtual ~RTPPacket() { if (packet && !externalbuffer) RTPDeleteByteArray(packet,GetMemoryManager()); }
81 
83  int GetCreationError() const { return error; }
84 
86  bool HasExtension() const { return hasextension; }
87 
89  bool HasMarker() const { return hasmarker; }
90 
92  int GetCSRCCount() const { return numcsrcs; }
93 
97  uint32_t GetCSRC(int num) const;
98 
100  uint8_t GetPayloadType() const { return payloadtype; }
101 
106  uint32_t GetExtendedSequenceNumber() const { return extseqnr; }
107 
109  uint16_t GetSequenceNumber() const { return (uint16_t)(extseqnr&0x0000FFFF); }
110 
112  void SetExtendedSequenceNumber(uint32_t seq) { extseqnr = seq; }
113 
115  uint32_t GetTimestamp() const { return timestamp; }
116 
118  uint32_t GetSSRC() const { return ssrc; }
119 
121  uint8_t *GetPacketData() const { return packet; }
122 
124  uint8_t *GetPayloadData() const { return payload; }
125 
127  size_t GetPacketLength() const { return packetlength; }
128 
130  size_t GetPayloadLength() const { return payloadlength; }
131 
133  uint16_t GetExtensionID() const { return extid; }
134 
136  uint8_t *GetExtensionData() const { return extension; }
137 
139  size_t GetExtensionLength() const { return extensionlength; }
140 #ifdef RTPDEBUG
141  void Dump();
142 #endif // RTPDEBUG
143 
149  RTPTime GetReceiveTime() const { return receivetime; }
150 private:
151  void Clear();
152  int ParseRawPacket(RTPRawPacket &rawpack);
153  int BuildPacket(uint8_t payloadtype,const void *payloaddata,size_t payloadlen,uint16_t seqnr,
154  uint32_t timestamp,uint32_t ssrc,bool gotmarker,uint8_t numcsrcs,const uint32_t *csrcs,
155  bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata,
156  void *buffer,size_t maxsize);
157 
158  int error;
159 
160  bool hasextension,hasmarker;
161  int numcsrcs;
162 
163  uint8_t payloadtype;
164  uint32_t extseqnr,timestamp,ssrc;
165  uint8_t *packet,*payload;
166  size_t packetlength,payloadlength;
167 
168  uint16_t extid;
169  uint8_t *extension;
170  size_t extensionlength;
171 
172  bool externalbuffer;
173 
174  RTPTime receivetime;
175 };
176 
177 #endif // RTPPACKET_H
178 
int GetCSRCCount() const
Returns the number of CSRCs contained in this packet.
Definition: rtppacket.h:92
uint8_t * GetPayloadData() const
Returns a pointer to the actual payload data.
Definition: rtppacket.h:124
Represents an RTP Packet.
Definition: rtppacket.h:53
uint32_t GetExtendedSequenceNumber() const
Returns the extended sequence number of the packet.
Definition: rtppacket.h:106
A memory manager.
Definition: rtpmemorymanager.h:144
uint16_t GetExtensionID() const
If a header extension is present, this function returns the extension identifier. ...
Definition: rtppacket.h:133
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:48
RTPPacket(RTPRawPacket &rawpack, RTPMemoryManager *mgr=0)
Creates an RTPPacket instance based upon the data in rawpack, optionally installing a memory manager...
bool HasMarker() const
Returns true if the marker bit was set and false otherwise.
Definition: rtppacket.h:89
int GetCreationError() const
If an error occurred in one of the constructors, this function returns the error code.
Definition: rtppacket.h:83
RTPTime GetReceiveTime() const
Returns the time at which this packet was received.
Definition: rtppacket.h:149
void SetExtendedSequenceNumber(uint32_t seq)
Sets the extended sequence number of this packet to seq.
Definition: rtppacket.h:112
uint16_t GetSequenceNumber() const
Returns the sequence number of this packet.
Definition: rtppacket.h:109
uint8_t * GetPacketData() const
Returns a pointer to the data of the entire packet.
Definition: rtppacket.h:121
uint32_t GetSSRC() const
Returns the SSRC identifier stored in this packet.
Definition: rtppacket.h:118
uint32_t GetCSRC(int num) const
Returns a specific CSRC identifier.
uint8_t GetPayloadType() const
Returns the payload type of the packet.
Definition: rtppacket.h:100
bool HasExtension() const
Returns true if the RTP packet has a header extension and false otherwise.
Definition: rtppacket.h:86
size_t GetExtensionLength() const
Returns the length of the header extension data.
Definition: rtppacket.h:139
uint32_t GetTimestamp() const
Returns the timestamp of this packet.
Definition: rtppacket.h:115
size_t GetPacketLength() const
Returns the length of the entire packet.
Definition: rtppacket.h:127
uint8_t * GetExtensionData() const
Returns the length of the header extension data.
Definition: rtppacket.h:136
size_t GetPayloadLength() const
Returns the payload length.
Definition: rtppacket.h:130