rtcpsrpacket.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. This file is a part of JRTPLIB
  3. Copyright (c) 1999-2011 Jori Liesenborgs
  4. Contact: jori.liesenborgs@gmail.com
  5. This library was developed at the Expertise Centre for Digital Media
  6. (http://www.edm.uhasselt.be), a research center of the Hasselt University
  7. (http://www.uhasselt.be). The library is based upon work done for
  8. my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
  9. Permission is hereby granted, free of charge, to any person obtaining a
  10. copy of this software and associated documentation files (the "Software"),
  11. to deal in the Software without restriction, including without limitation
  12. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. and/or sell copies of the Software, and to permit persons to whom the
  14. Software is furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included
  16. in all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  23. IN THE SOFTWARE.
  24. */
  25. #include "rtcpsrpacket.h"
  26. #ifdef RTPDEBUG
  27. #include <iostream>
  28. #endif // RTPDEBUG
  29. #include "rtpdebug.h"
  30. namespace jrtplib
  31. {
  32. RTCPSRPacket::RTCPSRPacket(uint8_t *data,size_t datalength)
  33. : RTCPPacket(SR,data,datalength)
  34. {
  35. knownformat = false;
  36. RTCPCommonHeader *hdr;
  37. size_t len = datalength;
  38. size_t expectedlength;
  39. hdr = (RTCPCommonHeader *)data;
  40. if (hdr->padding)
  41. {
  42. uint8_t padcount = data[datalength-1];
  43. if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37)
  44. return;
  45. if (((size_t)padcount) >= len)
  46. return;
  47. len -= (size_t)padcount;
  48. }
  49. expectedlength = sizeof(RTCPCommonHeader)+sizeof(uint32_t)+sizeof(RTCPSenderReport);
  50. expectedlength += sizeof(RTCPReceiverReport)*((int)hdr->count);
  51. if (expectedlength != len)
  52. return;
  53. knownformat = true;
  54. }
  55. #ifdef RTPDEBUG
  56. void RTCPSRPacket::Dump()
  57. {
  58. RTCPPacket::Dump();
  59. if (!IsKnownFormat())
  60. std::cout << " Unknown format" << std::endl;
  61. else
  62. {
  63. int num = GetReceptionReportCount();
  64. int i;
  65. RTPNTPTime t = GetNTPTimestamp();
  66. std::cout << " SSRC of sender: " << GetSenderSSRC() << std::endl;
  67. std::cout << " Sender info:" << std::endl;
  68. std::cout << " NTP timestamp: " << t.GetMSW() << ":" << t.GetLSW() << std::endl;
  69. std::cout << " RTP timestamp: " << GetRTPTimestamp() << std::endl;
  70. std::cout << " Packet count: " << GetSenderPacketCount() << std::endl;
  71. std::cout << " Octet count: " << GetSenderOctetCount() << std::endl;
  72. for (i = 0 ; i < num ; i++)
  73. {
  74. std::cout << " Report block " << i << std::endl;
  75. std::cout << " SSRC: " << GetSSRC(i) << std::endl;
  76. std::cout << " Fraction lost: " << (uint32_t)GetFractionLost(i) << std::endl;
  77. std::cout << " Packets lost: " << GetLostPacketCount(i) << std::endl;
  78. std::cout << " Seq. nr.: " << GetExtendedHighestSequenceNumber(i) << std::endl;
  79. std::cout << " Jitter: " << GetJitter(i) << std::endl;
  80. std::cout << " LSR: " << GetLSR(i) << std::endl;
  81. std::cout << " DLSR: " << GetDLSR(i) << std::endl;
  82. }
  83. }
  84. }
  85. #endif // RTPDEBUG
  86. } // end namespace