| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |  This file is a part of JRTPLIB | 
					
						
							|  |  |  |  Copyright (c) 1999-2017 Jori Liesenborgs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  Contact: jori.liesenborgs@gmail.com | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  This library was developed at the Expertise Centre for Digital Media | 
					
						
							|  |  |  |  (http://www.edm.uhasselt.be), a research center of the Hasselt University
 | 
					
						
							|  |  |  |  (http://www.uhasselt.be). The library is based upon work done for
 | 
					
						
							|  |  |  |  my thesis at the School for Knowledge Technology (Belgium/The Netherlands). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  Permission is hereby granted, free of charge, to any person obtaining a | 
					
						
							|  |  |  |  copy of this software and associated documentation files (the "Software"), | 
					
						
							|  |  |  |  to deal in the Software without restriction, including without limitation | 
					
						
							|  |  |  |  the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
					
						
							|  |  |  |  and/or sell copies of the Software, and to permit persons to whom the | 
					
						
							|  |  |  |  Software is furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  The above copyright notice and this permission notice shall be included | 
					
						
							|  |  |  |  in all copies or substantial portions of the Software. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
					
						
							|  |  |  |  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
					
						
							|  |  |  |  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
					
						
							|  |  |  |  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 
					
						
							|  |  |  |  IN THE SOFTWARE. | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * \file rtprawpacket.h | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef RTPRAWPACKET_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define RTPRAWPACKET_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "rtptimeutilities.h"
 | 
					
						
							|  |  |  | #include "rtpaddress.h"
 | 
					
						
							|  |  |  | #include "rtptypes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace qrtplib | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** This class is used by the transmission component to store the incoming RTP and RTCP data in. */ | 
					
						
							| 
									
										
										
										
											2018-02-27 23:26:03 +01:00
										 |  |  | class RTPRawPacket | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     /** Creates an instance which stores data from \c data with length \c datalen.
 | 
					
						
							|  |  |  |      *  Creates an instance which stores data from \c data with length \c datalen. Only the pointer | 
					
						
							|  |  |  |      *  to the data is stored, no actual copy is made! The address from which this packet originated | 
					
						
							|  |  |  |      *  is set to \c address and the time at which the packet was received is set to \c recvtime. | 
					
						
							|  |  |  |      *  The flag which indicates whether this data is RTP or RTCP data is set to \c rtp. A memory | 
					
						
							|  |  |  |      *  manager can be installed as well. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     RTPRawPacket(const uint8_t *data, std::size_t datalen, const RTPAddress& address, RTPTime &recvtime, bool rtp); | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     ~RTPRawPacket(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Returns the pointer to the data which is contained in this packet. */ | 
					
						
							|  |  |  |     uint8_t *GetData() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return packetdata; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Returns the length of the packet described by this instance. */ | 
					
						
							| 
									
										
										
										
											2018-02-28 13:31:44 +01:00
										 |  |  |     std::size_t GetDataLength() const | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return packetdatalength; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Returns the time at which this packet was received. */ | 
					
						
							|  |  |  |     RTPTime GetReceiveTime() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return receivetime; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Returns the address stored in this packet. */ | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     const RTPAddress& GetSenderAddress() const | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return senderaddress; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Returns \c true if this data is RTP data, \c false if it is RTCP data. */ | 
					
						
							|  |  |  |     bool IsRTP() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return isrtp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Deallocates the previously stored data and replaces it with the data that's
 | 
					
						
							|  |  |  |      *  specified, can be useful when e.g. decrypting data in RTPSession::OnChangeIncomingData */ | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     void SetData(const uint8_t *data, std::size_t datalen); | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** Deallocates the currently stored RTPAddress instance and replaces it
 | 
					
						
							|  |  |  |      *  with the one that's specified (you probably don't need this function). */ | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     void SetSenderAddress(const RTPAddress& address); | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     void DeleteData(); | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     uint8_t *packetdata; | 
					
						
							| 
									
										
										
										
											2018-02-28 13:31:44 +01:00
										 |  |  |     std::size_t packetdatalength; | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     RTPTime receivetime; | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     RTPAddress senderaddress; | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     bool isrtp; | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  | inline RTPRawPacket::RTPRawPacket(const uint8_t *data, std::size_t datalen, const RTPAddress& address, RTPTime &recvtime, bool rtp) : | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |         receivetime(recvtime) | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     packetdata = new uint8_t[datalen]; | 
					
						
							|  |  |  |     memcpy(packetdata, data, datalen); | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     packetdatalength = datalen; | 
					
						
							|  |  |  |     senderaddress = address; | 
					
						
							|  |  |  |     isrtp = rtp; | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline RTPRawPacket::~RTPRawPacket() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     DeleteData(); | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline void RTPRawPacket::DeleteData() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     if (packetdata) | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |         delete[] packetdata; | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |         packetdata = 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  | inline void RTPRawPacket::SetData(const uint8_t *data, std::size_t datalen) | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     if (packetdata) { | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |         delete[] packetdata; | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  |     packetdata = new uint8_t[datalen]; | 
					
						
							|  |  |  |     memcpy(packetdata, data, datalen); | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     packetdatalength = datalen; | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 01:17:19 +01:00
										 |  |  | inline void RTPRawPacket::SetSenderAddress(const RTPAddress& address) | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-27 23:05:46 +01:00
										 |  |  |     senderaddress = address; | 
					
						
							| 
									
										
										
										
											2018-02-27 01:35:16 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // end namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // RTPRAWPACKET_H
 | 
					
						
							|  |  |  | 
 |