app.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_
  11. #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include "modules/rtp_rtcp/source/rtcp_packet.h"
  15. #include "rtc_base/buffer.h"
  16. namespace webrtc {
  17. namespace rtcp {
  18. class CommonHeader;
  19. class App : public RtcpPacket {
  20. public:
  21. static constexpr uint8_t kPacketType = 204;
  22. App();
  23. App(App&&) = default;
  24. ~App() override;
  25. // Parse assumes header is already parsed and validated.
  26. bool Parse(const CommonHeader& packet);
  27. void SetSubType(uint8_t subtype);
  28. void SetName(uint32_t name) { name_ = name; }
  29. void SetData(const uint8_t* data, size_t data_length);
  30. uint8_t sub_type() const { return sub_type_; }
  31. uint32_t name() const { return name_; }
  32. size_t data_size() const { return data_.size(); }
  33. const uint8_t* data() const { return data_.data(); }
  34. size_t BlockLength() const override;
  35. bool Create(uint8_t* packet,
  36. size_t* index,
  37. size_t max_length,
  38. PacketReadyCallback callback) const override;
  39. static inline constexpr uint32_t NameToInt(const char name[5]) {
  40. return static_cast<uint32_t>(name[0]) << 24 |
  41. static_cast<uint32_t>(name[1]) << 16 |
  42. static_cast<uint32_t>(name[2]) << 8 | static_cast<uint32_t>(name[3]);
  43. }
  44. private:
  45. static constexpr size_t kAppBaseLength = 8; // Ssrc and Name.
  46. static constexpr size_t kMaxDataSize = 0xffff * 4 - kAppBaseLength;
  47. uint8_t sub_type_;
  48. uint32_t name_;
  49. rtc::Buffer data_;
  50. };
  51. } // namespace rtcp
  52. } // namespace webrtc
  53. #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_