dlrr.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. */
  11. #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_
  12. #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_
  13. #include <stddef.h>
  14. #include <stdint.h>
  15. #include <vector>
  16. namespace webrtc {
  17. namespace rtcp {
  18. struct ReceiveTimeInfo {
  19. // RFC 3611 4.5
  20. ReceiveTimeInfo() : ssrc(0), last_rr(0), delay_since_last_rr(0) {}
  21. ReceiveTimeInfo(uint32_t ssrc, uint32_t last_rr, uint32_t delay)
  22. : ssrc(ssrc), last_rr(last_rr), delay_since_last_rr(delay) {}
  23. uint32_t ssrc;
  24. uint32_t last_rr;
  25. uint32_t delay_since_last_rr;
  26. };
  27. // DLRR Report Block: Delay since the Last Receiver Report (RFC 3611).
  28. class Dlrr {
  29. public:
  30. static const uint8_t kBlockType = 5;
  31. Dlrr();
  32. Dlrr(const Dlrr& other);
  33. ~Dlrr();
  34. Dlrr& operator=(const Dlrr& other) = default;
  35. // Dlrr without items treated same as no dlrr block.
  36. explicit operator bool() const { return !sub_blocks_.empty(); }
  37. // Second parameter is value read from block header,
  38. // i.e. size of block in 32bits excluding block header itself.
  39. bool Parse(const uint8_t* buffer, uint16_t block_length_32bits);
  40. size_t BlockLength() const;
  41. // Fills buffer with the Dlrr.
  42. // Consumes BlockLength() bytes.
  43. void Create(uint8_t* buffer) const;
  44. void ClearItems() { sub_blocks_.clear(); }
  45. void AddDlrrItem(const ReceiveTimeInfo& time_info) {
  46. sub_blocks_.push_back(time_info);
  47. }
  48. const std::vector<ReceiveTimeInfo>& sub_blocks() const { return sub_blocks_; }
  49. private:
  50. static const size_t kBlockHeaderLength = 4;
  51. static const size_t kSubBlockLength = 12;
  52. std::vector<ReceiveTimeInfo> sub_blocks_;
  53. };
  54. } // namespace rtcp
  55. } // namespace webrtc
  56. #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_DLRR_H_