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 RTCPSDESPACKET_H 00038 00039 #define RTCPSDESPACKET_H 00040 00041 #include "rtpconfig.h" 00042 #include "rtcppacket.h" 00043 #include "rtpstructs.h" 00044 #include "rtpdefines.h" 00045 #if ! (defined(WIN32) || defined(_WIN32_WCE)) 00046 #include <netinet/in.h> 00047 #endif // WIN32 00048 00049 class RTCPCompoundPacket; 00050 00052 class RTCPSDESPacket : public RTCPPacket 00053 { 00054 public: 00056 enum ItemType 00057 { 00058 None, 00059 CNAME, 00060 NAME, 00061 EMAIL, 00062 PHONE, 00063 LOC, 00064 TOOL, 00065 NOTE, 00066 PRIV, 00067 Unknown 00068 }; 00069 00075 RTCPSDESPacket(uint8_t *data,size_t datalen); 00076 ~RTCPSDESPacket() { } 00077 00081 int GetChunkCount() const; 00082 00087 bool GotoFirstChunk(); 00088 00093 bool GotoNextChunk(); 00094 00096 uint32_t GetChunkSSRC() const; 00097 00103 bool GotoFirstItem(); 00104 00109 bool GotoNextItem(); 00110 00112 ItemType GetItemType() const; 00113 00115 size_t GetItemLength() const; 00116 00118 uint8_t *GetItemData(); 00119 00120 #ifdef RTP_SUPPORT_SDESPRIV 00121 00124 size_t GetPRIVPrefixLength() const; 00125 00129 uint8_t *GetPRIVPrefixData(); 00130 00134 size_t GetPRIVValueLength() const; 00135 00139 uint8_t *GetPRIVValueData(); 00140 #endif // RTP_SUPPORT_SDESPRIV 00141 00142 #ifdef RTPDEBUG 00143 void Dump(); 00144 #endif // RTPDEBUG 00145 private: 00146 uint8_t *currentchunk; 00147 int curchunknum; 00148 size_t itemoffset; 00149 }; 00150 00151 inline int RTCPSDESPacket::GetChunkCount() const 00152 { 00153 if (!knownformat) 00154 return 0; 00155 RTCPCommonHeader *hdr = (RTCPCommonHeader *)data; 00156 return ((int)hdr->count); 00157 } 00158 00159 inline bool RTCPSDESPacket::GotoFirstChunk() 00160 { 00161 if (GetChunkCount() == 0) 00162 { 00163 currentchunk = 0; 00164 return false; 00165 } 00166 currentchunk = data+sizeof(RTCPCommonHeader); 00167 curchunknum = 1; 00168 itemoffset = sizeof(uint32_t); 00169 return true; 00170 } 00171 00172 inline bool RTCPSDESPacket::GotoNextChunk() 00173 { 00174 if (!knownformat) 00175 return false; 00176 if (currentchunk == 0) 00177 return false; 00178 if (curchunknum == GetChunkCount()) 00179 return false; 00180 00181 size_t offset = sizeof(uint32_t); 00182 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+sizeof(uint32_t)); 00183 00184 while (sdeshdr->sdesid != 0) 00185 { 00186 offset += sizeof(RTCPSDESHeader); 00187 offset += (size_t)(sdeshdr->length); 00188 sdeshdr = (RTCPSDESHeader *)(currentchunk+offset); 00189 } 00190 offset++; // for the zero byte 00191 if ((offset&0x03) != 0) 00192 offset += (4-(offset&0x03)); 00193 currentchunk += offset; 00194 curchunknum++; 00195 itemoffset = sizeof(uint32_t); 00196 return true; 00197 } 00198 00199 inline uint32_t RTCPSDESPacket::GetChunkSSRC() const 00200 { 00201 if (!knownformat) 00202 return 0; 00203 if (currentchunk == 0) 00204 return 0; 00205 uint32_t *ssrc = (uint32_t *)currentchunk; 00206 return ntohl(*ssrc); 00207 } 00208 00209 inline bool RTCPSDESPacket::GotoFirstItem() 00210 { 00211 if (!knownformat) 00212 return false; 00213 if (currentchunk == 0) 00214 return false; 00215 itemoffset = sizeof(uint32_t); 00216 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00217 if (sdeshdr->sdesid == 0) 00218 return false; 00219 return true; 00220 } 00221 00222 inline bool RTCPSDESPacket::GotoNextItem() 00223 { 00224 if (!knownformat) 00225 return false; 00226 if (currentchunk == 0) 00227 return false; 00228 00229 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00230 if (sdeshdr->sdesid == 0) 00231 return false; 00232 00233 size_t offset = itemoffset; 00234 offset += sizeof(RTCPSDESHeader); 00235 offset += (size_t)(sdeshdr->length); 00236 sdeshdr = (RTCPSDESHeader *)(currentchunk+offset); 00237 if (sdeshdr->sdesid == 0) 00238 return false; 00239 itemoffset = offset; 00240 return true; 00241 } 00242 00243 inline RTCPSDESPacket::ItemType RTCPSDESPacket::GetItemType() const 00244 { 00245 if (!knownformat) 00246 return None; 00247 if (currentchunk == 0) 00248 return None; 00249 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00250 switch (sdeshdr->sdesid) 00251 { 00252 case 0: 00253 return None; 00254 case RTCP_SDES_ID_CNAME: 00255 return CNAME; 00256 case RTCP_SDES_ID_NAME: 00257 return NAME; 00258 case RTCP_SDES_ID_EMAIL: 00259 return EMAIL; 00260 case RTCP_SDES_ID_PHONE: 00261 return PHONE; 00262 case RTCP_SDES_ID_LOCATION: 00263 return LOC; 00264 case RTCP_SDES_ID_TOOL: 00265 return TOOL; 00266 case RTCP_SDES_ID_NOTE: 00267 return NOTE; 00268 case RTCP_SDES_ID_PRIVATE: 00269 return PRIV; 00270 default: 00271 return Unknown; 00272 } 00273 return Unknown; 00274 } 00275 00276 inline size_t RTCPSDESPacket::GetItemLength() const 00277 { 00278 if (!knownformat) 00279 return None; 00280 if (currentchunk == 0) 00281 return None; 00282 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00283 if (sdeshdr->sdesid == 0) 00284 return 0; 00285 return (size_t)(sdeshdr->length); 00286 } 00287 00288 inline uint8_t *RTCPSDESPacket::GetItemData() 00289 { 00290 if (!knownformat) 00291 return 0; 00292 if (currentchunk == 0) 00293 return 0; 00294 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00295 if (sdeshdr->sdesid == 0) 00296 return 0; 00297 return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)); 00298 } 00299 00300 #ifdef RTP_SUPPORT_SDESPRIV 00301 inline size_t RTCPSDESPacket::GetPRIVPrefixLength() const 00302 { 00303 if (!knownformat) 00304 return 0; 00305 if (currentchunk == 0) 00306 return 0; 00307 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00308 if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE) 00309 return 0; 00310 if (sdeshdr->length == 0) 00311 return 0; 00312 uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader); 00313 size_t prefixlength = (size_t)(*preflen); 00314 if (prefixlength > (size_t)((sdeshdr->length)-1)) 00315 return 0; 00316 return prefixlength; 00317 } 00318 00319 inline uint8_t *RTCPSDESPacket::GetPRIVPrefixData() 00320 { 00321 if (!knownformat) 00322 return 0; 00323 if (currentchunk == 0) 00324 return 0; 00325 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00326 if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE) 00327 return 0; 00328 if (sdeshdr->length == 0) 00329 return 0; 00330 uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader); 00331 size_t prefixlength = (size_t)(*preflen); 00332 if (prefixlength > (size_t)((sdeshdr->length)-1)) 00333 return 0; 00334 if (prefixlength == 0) 00335 return 0; 00336 return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)+1); 00337 } 00338 00339 inline size_t RTCPSDESPacket::GetPRIVValueLength() const 00340 { 00341 if (!knownformat) 00342 return 0; 00343 if (currentchunk == 0) 00344 return 0; 00345 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00346 if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE) 00347 return 0; 00348 if (sdeshdr->length == 0) 00349 return 0; 00350 uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader); 00351 size_t prefixlength = (size_t)(*preflen); 00352 if (prefixlength > (size_t)((sdeshdr->length)-1)) 00353 return 0; 00354 return ((size_t)(sdeshdr->length))-prefixlength-1; 00355 } 00356 00357 inline uint8_t *RTCPSDESPacket::GetPRIVValueData() 00358 { 00359 if (!knownformat) 00360 return 0; 00361 if (currentchunk == 0) 00362 return 0; 00363 RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *)(currentchunk+itemoffset); 00364 if (sdeshdr->sdesid != RTCP_SDES_ID_PRIVATE) 00365 return 0; 00366 if (sdeshdr->length == 0) 00367 return 0; 00368 uint8_t *preflen = currentchunk+itemoffset+sizeof(RTCPSDESHeader); 00369 size_t prefixlength = (size_t)(*preflen); 00370 if (prefixlength > (size_t)((sdeshdr->length)-1)) 00371 return 0; 00372 size_t valuelen = ((size_t)(sdeshdr->length))-prefixlength-1; 00373 if (valuelen == 0) 00374 return 0; 00375 return (currentchunk+itemoffset+sizeof(RTCPSDESHeader)+1+prefixlength); 00376 } 00377 00378 #endif // RTP_SUPPORT_SDESPRIV 00379 00380 #endif // RTCPSDESPACKET_H 00381