rtcpapppacket.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /**
  26. * \file rtcpapppacket.h
  27. */
  28. #ifndef RTCPAPPPACKET_H
  29. #define RTCPAPPPACKET_H
  30. #include "rtpconfig.h"
  31. #include "rtcppacket.h"
  32. #include "rtpstructs.h"
  33. #if ! (defined(WIN32) || defined(_WIN32_WCE))
  34. #include <netinet/in.h>
  35. #endif // WIN32
  36. namespace jrtplib
  37. {
  38. class RTCPCompoundPacket;
  39. /** Describes an RTCP APP packet. */
  40. class JRTPLIB_IMPORTEXPORT RTCPAPPPacket : public RTCPPacket
  41. {
  42. public:
  43. /** Creates an instance based on the data in \c data with length \c datalen.
  44. * Creates an instance based on the data in \c data with length \c datalen. Since the \c data pointer
  45. * is referenced inside the class (no copy of the data is made) one must make sure that the memory it
  46. * points to is valid as long as the class instance exists.
  47. */
  48. RTCPAPPPacket(uint8_t *data,size_t datalen);
  49. ~RTCPAPPPacket() { }
  50. /** Returns the subtype contained in the APP packet. */
  51. uint8_t GetSubType() const;
  52. /** Returns the SSRC of the source which sent this packet. */
  53. uint32_t GetSSRC() const;
  54. /** Returns the name contained in the APP packet.
  55. * Returns the name contained in the APP packet. This alway consists of four bytes and is not NULL-terminated.
  56. */
  57. uint8_t *GetName();
  58. /** Returns a pointer to the actual data. */
  59. uint8_t *GetAPPData();
  60. /** Returns the length of the actual data. */
  61. size_t GetAPPDataLength() const;
  62. #ifdef RTPDEBUG
  63. void Dump();
  64. #endif // RTPDEBUG
  65. private:
  66. size_t appdatalen;
  67. };
  68. inline uint8_t RTCPAPPPacket::GetSubType() const
  69. {
  70. if (!knownformat)
  71. return 0;
  72. RTCPCommonHeader *hdr = (RTCPCommonHeader *)data;
  73. return hdr->count;
  74. }
  75. inline uint32_t RTCPAPPPacket::GetSSRC() const
  76. {
  77. if (!knownformat)
  78. return 0;
  79. uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader));
  80. return ntohl(*ssrc);
  81. }
  82. inline uint8_t *RTCPAPPPacket::GetName()
  83. {
  84. if (!knownformat)
  85. return 0;
  86. return (data+sizeof(RTCPCommonHeader)+sizeof(uint32_t));
  87. }
  88. inline uint8_t *RTCPAPPPacket::GetAPPData()
  89. {
  90. if (!knownformat)
  91. return 0;
  92. if (appdatalen == 0)
  93. return 0;
  94. return (data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)*2);
  95. }
  96. inline size_t RTCPAPPPacket::GetAPPDataLength() const
  97. {
  98. if (!knownformat)
  99. return 0;
  100. return appdatalen;
  101. }
  102. } // end namespace
  103. #endif // RTCPAPPPACKET_H