jrtplib
3.7.1
|
00001 /* 00002 00003 This file is a part of JRTPLIB 00004 Copyright (c) 1999-2007 Jori Liesenborgs 00005 00006 Contact: jori.liesenborgs@gmail.com 00007 00008 This library was developed at the "Expertisecentrum Digitale Media" 00009 (http://www.edm.uhasselt.be), a research center of the Hasselt University 00010 (http://www.uhasselt.be). The library is based upon work done for 00011 my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 00012 00013 Permission is hereby granted, free of charge, to any person obtaining a 00014 copy of this software and associated documentation files (the "Software"), 00015 to deal in the Software without restriction, including without limitation 00016 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00017 and/or sell copies of the Software, and to permit persons to whom the 00018 Software is furnished to do so, subject to the following conditions: 00019 00020 The above copyright notice and this permission notice shall be included 00021 in all copies or substantial portions of the Software. 00022 00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00024 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00026 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00028 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 00029 IN THE SOFTWARE. 00030 00031 */ 00032 00037 #ifndef RTPPACKETBUILDER_H 00038 00039 #define RTPPACKETBUILDER_H 00040 00041 #include "rtpconfig.h" 00042 #include "rtperrors.h" 00043 #include "rtpdefines.h" 00044 #include "rtprandom.h" 00045 #include "rtptimeutilities.h" 00046 #include "rtptypes.h" 00047 #include "rtpmemoryobject.h" 00048 00049 class RTPSources; 00050 00054 class RTPPacketBuilder : public RTPMemoryObject 00055 { 00056 public: 00058 RTPPacketBuilder(RTPMemoryManager *mgr = 0); 00059 ~RTPPacketBuilder(); 00060 00062 int Init(size_t maxpacksize); 00063 00065 void Destroy(); 00066 00068 uint32_t GetPacketCount() { if (!init) return 0; return numpackets; } 00069 00071 uint32_t GetPayloadOctetCount() { if (!init) return 0; return numpayloadbytes; } 00072 00074 int SetMaximumPacketSize(size_t maxpacksize); 00075 00077 int AddCSRC(uint32_t csrc); 00078 00080 int DeleteCSRC(uint32_t csrc); 00081 00083 void ClearCSRCList(); 00084 00090 int BuildPacket(const void *data,size_t len); 00091 00097 int BuildPacket(const void *data,size_t len, 00098 uint8_t pt,bool mark,uint32_t timestampinc); 00099 00107 int BuildPacketEx(const void *data,size_t len, 00108 uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords); 00109 00117 int BuildPacketEx(const void *data,size_t len, 00118 uint8_t pt,bool mark,uint32_t timestampinc, 00119 uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords); 00120 00122 uint8_t *GetPacket() { if (!init) return 0; return buffer; } 00123 00125 size_t GetPacketLength() { if (!init) return 0; return packetlength; } 00126 00128 int SetDefaultPayloadType(uint8_t pt); 00129 00131 int SetDefaultMark(bool m); 00132 00134 int SetDefaultTimestampIncrement(uint32_t timestampinc); 00135 00142 int IncrementTimestamp(uint32_t inc); 00143 00151 int IncrementTimestampDefault(); 00152 00157 uint32_t CreateNewSSRC(); 00158 00164 uint32_t CreateNewSSRC(RTPSources &sources); 00165 00167 uint32_t GetSSRC() const { if (!init) return 0; return ssrc; } 00168 00170 uint32_t GetTimestamp() const { if (!init) return 0; return timestamp; } 00171 00173 uint16_t GetSequenceNumber() const { if (!init) return 0; return seqnr; } 00174 00179 RTPTime GetPacketTime() const { if (!init) return RTPTime(0,0); return lastwallclocktime; } 00180 00182 uint32_t GetPacketTimestamp() const { if (!init) return 0; return lastrtptimestamp; } 00183 private: 00184 int PrivateBuildPacket(const void *data,size_t len, 00185 uint8_t pt,bool mark,uint32_t timestampinc,bool gotextension, 00186 uint16_t hdrextID = 0,const void *hdrextdata = 0,size_t numhdrextwords = 0); 00187 00188 RTPRandom rtprnd; 00189 size_t maxpacksize; 00190 uint8_t *buffer; 00191 size_t packetlength; 00192 00193 uint32_t numpayloadbytes; 00194 uint32_t numpackets; 00195 bool init; 00196 00197 uint32_t ssrc; 00198 uint32_t timestamp; 00199 uint16_t seqnr; 00200 00201 uint32_t defaulttimestampinc; 00202 uint8_t defaultpayloadtype; 00203 bool defaultmark; 00204 00205 bool deftsset,defptset,defmarkset; 00206 00207 uint32_t csrcs[RTP_MAXCSRCS]; 00208 int numcsrcs; 00209 00210 RTPTime lastwallclocktime; 00211 uint32_t lastrtptimestamp; 00212 uint32_t prevrtptimestamp; 00213 }; 00214 00215 inline int RTPPacketBuilder::SetDefaultPayloadType(uint8_t pt) 00216 { 00217 if (!init) 00218 return ERR_RTP_PACKBUILD_NOTINIT; 00219 defptset = true; 00220 defaultpayloadtype = pt; 00221 return 0; 00222 } 00223 00224 inline int RTPPacketBuilder::SetDefaultMark(bool m) 00225 { 00226 if (!init) 00227 return ERR_RTP_PACKBUILD_NOTINIT; 00228 defmarkset = true; 00229 defaultmark = m; 00230 return 0; 00231 } 00232 00233 inline int RTPPacketBuilder::SetDefaultTimestampIncrement(uint32_t timestampinc) 00234 { 00235 if (!init) 00236 return ERR_RTP_PACKBUILD_NOTINIT; 00237 deftsset = true; 00238 defaulttimestampinc = timestampinc; 00239 return 0; 00240 } 00241 00242 inline int RTPPacketBuilder::IncrementTimestamp(uint32_t inc) 00243 { 00244 if (!init) 00245 return ERR_RTP_PACKBUILD_NOTINIT; 00246 timestamp += inc; 00247 return 0; 00248 } 00249 00250 inline int RTPPacketBuilder::IncrementTimestampDefault() 00251 { 00252 if (!init) 00253 return ERR_RTP_PACKBUILD_NOTINIT; 00254 if (!deftsset) 00255 return ERR_RTP_PACKBUILD_DEFAULTTSINCNOTSET; 00256 timestamp += defaulttimestampinc; 00257 return 0; 00258 } 00259 00260 #endif // RTPPACKETBUILDER_H 00261